1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Merge pull request #11834 from peppy/perform-from-subscreen-support

Add the ability for PerformFromMenuRunner to inspect nested screen stacks
This commit is contained in:
Dan Balasescu 2021-02-22 12:24:08 +09:00 committed by GitHub
commit bc8e67ad7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 4 deletions

View File

@ -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,45 @@ 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))
{
// should be correct in theory, but currently untested/unused in existing implementations.
current.MakeCurrent();
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 @@ 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;
}
}