Add the ability for PerformFromMenuRunner to inspect nested screen stacks

This commit is contained in:
Dean Herbert 2021-02-19 17:58:04 +09:00
parent 1701d69a60
commit 362e4802f7
3 changed files with 36 additions and 4 deletions

View File

@ -13,6 +13,7 @@
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 @@ private void checkCanComplete()
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>

View 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; }
}
}

View File

@ -28,7 +28,7 @@
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 @@ private class BackgroundSprite : UpdateableBeatmapBackgroundSprite
protected override double TransformDuration => 200;
}
}
ScreenStack IHasSubScreenStack.SubScreenStack => screenStack;
}
}