mirror of
https://github.com/ppy/osu
synced 2024-12-22 06:50:42 +00:00
Add the ability for PerformFromMenuRunner to inspect nested screen stacks
This commit is contained in:
parent
1701d69a60
commit
362e4802f7
@ -13,6 +13,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Dialog;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Menu;
|
||||
|
||||
namespace osu.Game
|
||||
@ -81,27 +82,41 @@ namespace osu.Game
|
||||
|
||||
game?.CloseAllOverlays(false);
|
||||
|
||||
// we may already be at the target screen type.
|
||||
findValidTarget(current);
|
||||
}
|
||||
|
||||
private bool findValidTarget(IScreen current)
|
||||
{
|
||||
var type = current.GetType();
|
||||
|
||||
// check if we are already at a valid target screen.
|
||||
if (validScreens.Any(t => t.IsAssignableFrom(type)) && !beatmap.Disabled)
|
||||
{
|
||||
finalAction(current);
|
||||
Cancel();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
while (current != null)
|
||||
{
|
||||
// if this has a sub stack, recursively check the screens within it.
|
||||
if (current is IHasSubScreenStack currentSubScreen)
|
||||
{
|
||||
if (findValidTarget(currentSubScreen.SubScreenStack.CurrentScreen))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (validScreens.Any(t => t.IsAssignableFrom(type)))
|
||||
{
|
||||
current.MakeCurrent();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
current = current.GetParentScreen();
|
||||
type = current?.GetType();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
15
osu.Game/Screens/IHasSubScreenStack.cs
Normal file
15
osu.Game/Screens/IHasSubScreenStack.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Screens;
|
||||
|
||||
namespace osu.Game.Screens
|
||||
{
|
||||
/// <summary>
|
||||
/// A screen which manages a nested stack of screens within itself.
|
||||
/// </summary>
|
||||
public interface IHasSubScreenStack
|
||||
{
|
||||
ScreenStack SubScreenStack { get; }
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ using osuTK;
|
||||
namespace osu.Game.Screens.OnlinePlay
|
||||
{
|
||||
[Cached]
|
||||
public abstract class OnlinePlayScreen : OsuScreen
|
||||
public abstract class OnlinePlayScreen : OsuScreen, IHasSubScreenStack
|
||||
{
|
||||
public override bool CursorVisible => (screenStack.CurrentScreen as IOnlinePlaySubScreen)?.CursorVisible ?? true;
|
||||
|
||||
@ -355,5 +355,7 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
protected override double TransformDuration => 200;
|
||||
}
|
||||
}
|
||||
|
||||
ScreenStack IHasSubScreenStack.SubScreenStack => screenStack;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user