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:
commit
bc8e67ad7c
@ -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>
|
||||
|
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