diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs
index 73121f6e7d..76ccbe0a08 100644
--- a/osu.Game/OsuGame.cs
+++ b/osu.Game/OsuGame.cs
@@ -63,7 +63,7 @@ namespace osu.Game
/// The full osu! experience. Builds on top of to add menus and binding logic
/// for initial components that are generally retrieved via DI.
///
- public class OsuGame : OsuGameBase, IKeyBindingHandler, ILocalUserPlayInfo
+ public class OsuGame : OsuGameBase, IKeyBindingHandler, ILocalUserPlayInfo, IPerformFromScreenRunner
{
///
/// The amount of global offset to apply when a left/right anchored overlay is displayed (ie. settings or notifications).
@@ -586,12 +586,6 @@ namespace osu.Game
private PerformFromMenuRunner performFromMainMenuTask;
- ///
- /// Perform an action only after returning to a specific screen as indicated by .
- /// Eagerly tries to exit the current screen until it succeeds.
- ///
- /// The action to perform once we are in the correct state.
- /// An optional collection of valid screen types. If any of these screens are already current we can perform the action immediately, else the first valid parent will be made current before performing the action. is used if not specified.
public void PerformFromScreen(Action action, IEnumerable validScreens = null)
{
performFromMainMenuTask?.Cancel();
diff --git a/osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs b/osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs
index 117de88166..786401b7a8 100644
--- a/osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs
+++ b/osu.Game/Overlays/Dashboard/CurrentlyPlayingDisplay.cs
@@ -14,6 +14,7 @@ using osu.Game.Database;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Spectator;
+using osu.Game.Screens;
using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.Play;
using osu.Game.Users;
@@ -106,7 +107,7 @@ namespace osu.Game.Overlays.Dashboard
public readonly APIUser User;
[Resolved(canBeNull: true)]
- private OsuGame game { get; set; }
+ private IPerformFromScreenRunner performer { get; set; }
public PlayingUserPanel(APIUser user)
{
@@ -140,7 +141,7 @@ namespace osu.Game.Overlays.Dashboard
Text = "Watch",
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
- Action = () => game?.PerformFromScreen(s => s.Push(new SoloSpectator(User))),
+ Action = () => performer?.PerformFromScreen(s => s.Push(new SoloSpectator(User))),
Enabled = { Value = User.Id != api.LocalUser.Value.Id }
}
}
diff --git a/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs b/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs
index 60540a089e..8833420523 100644
--- a/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs
+++ b/osu.Game/Overlays/Settings/Sections/DebugSettings/GeneralSettings.cs
@@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Screens;
using osu.Game.Localisation;
+using osu.Game.Screens;
using osu.Game.Screens.Import;
namespace osu.Game.Overlays.Settings.Sections.DebugSettings
@@ -16,7 +17,7 @@ namespace osu.Game.Overlays.Settings.Sections.DebugSettings
protected override LocalisableString Header => DebugSettingsStrings.GeneralHeader;
[BackgroundDependencyLoader(true)]
- private void load(FrameworkDebugConfigManager config, FrameworkConfigManager frameworkConfig, OsuGame game)
+ private void load(FrameworkDebugConfigManager config, FrameworkConfigManager frameworkConfig, IPerformFromScreenRunner performer)
{
Children = new Drawable[]
{
@@ -34,7 +35,7 @@ namespace osu.Game.Overlays.Settings.Sections.DebugSettings
Add(new SettingsButton
{
Text = DebugSettingsStrings.ImportFiles,
- Action = () => game?.PerformFromScreen(menu => menu.Push(new FileImportScreen()))
+ Action = () => performer?.PerformFromScreen(menu => menu.Push(new FileImportScreen()))
});
}
}
diff --git a/osu.Game/Overlays/Settings/Sections/Maintenance/StableDirectoryLocationDialog.cs b/osu.Game/Overlays/Settings/Sections/Maintenance/StableDirectoryLocationDialog.cs
index 904c9deaae..b16fd9a5a1 100644
--- a/osu.Game/Overlays/Settings/Sections/Maintenance/StableDirectoryLocationDialog.cs
+++ b/osu.Game/Overlays/Settings/Sections/Maintenance/StableDirectoryLocationDialog.cs
@@ -6,13 +6,14 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Screens;
using osu.Game.Overlays.Dialog;
+using osu.Game.Screens;
namespace osu.Game.Overlays.Settings.Sections.Maintenance
{
public class StableDirectoryLocationDialog : PopupDialog
{
[Resolved]
- private OsuGame game { get; set; }
+ private IPerformFromScreenRunner performer { get; set; }
public StableDirectoryLocationDialog(TaskCompletionSource taskCompletionSource)
{
@@ -25,7 +26,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
new PopupDialogOkButton
{
Text = "Sure! I know where it is located!",
- Action = () => Schedule(() => game.PerformFromScreen(screen => screen.Push(new StableDirectorySelectScreen(taskCompletionSource))))
+ Action = () => Schedule(() => performer.PerformFromScreen(screen => screen.Push(new StableDirectorySelectScreen(taskCompletionSource))))
},
new PopupDialogCancelButton
{
diff --git a/osu.Game/Screens/IPerformFromScreenRunner.cs b/osu.Game/Screens/IPerformFromScreenRunner.cs
new file mode 100644
index 0000000000..655bebdeb0
--- /dev/null
+++ b/osu.Game/Screens/IPerformFromScreenRunner.cs
@@ -0,0 +1,26 @@
+// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence.
+// See the LICENCE file in the repository root for full licence text.
+
+using System;
+using System.Collections.Generic;
+using osu.Framework.Allocation;
+using osu.Framework.Screens;
+using osu.Game.Screens.Menu;
+
+namespace osu.Game.Screens
+{
+ ///
+ /// Manages a global screen stack to allow nested components a guarantee of where work is executed.
+ ///
+ [Cached]
+ public interface IPerformFromScreenRunner
+ {
+ ///
+ /// Perform an action only after returning to a specific screen as indicated by .
+ /// Eagerly tries to exit the current screen until it succeeds.
+ ///
+ /// The action to perform once we are in the correct state.
+ /// An optional collection of valid screen types. If any of these screens are already current we can perform the action immediately, else the first valid parent will be made current before performing the action. is used if not specified.
+ void PerformFromScreen(Action action, IEnumerable validScreens = null);
+ }
+}
diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs
index e2d79b4015..442a536cf9 100644
--- a/osu.Game/Screens/Menu/MainMenu.cs
+++ b/osu.Game/Screens/Menu/MainMenu.cs
@@ -148,14 +148,14 @@ namespace osu.Game.Screens.Menu
}
[Resolved(canBeNull: true)]
- private OsuGame game { get; set; }
+ private IPerformFromScreenRunner performer { get; set; }
private void confirmAndExit()
{
if (exitConfirmed) return;
exitConfirmed = true;
- game?.PerformFromScreen(menu => menu.Exit());
+ performer?.PerformFromScreen(menu => menu.Exit());
}
private void preloadSongSelect()
diff --git a/osu.Game/Skinning/Editor/SkinEditorSceneLibrary.cs b/osu.Game/Skinning/Editor/SkinEditorSceneLibrary.cs
index 0808cd157f..4507526806 100644
--- a/osu.Game/Skinning/Editor/SkinEditorSceneLibrary.cs
+++ b/osu.Game/Skinning/Editor/SkinEditorSceneLibrary.cs
@@ -15,6 +15,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
+using osu.Game.Screens;
using osu.Game.Screens.Play;
using osu.Game.Screens.Select;
using osuTK;
@@ -28,7 +29,7 @@ namespace osu.Game.Skinning.Editor
private const float padding = 10;
[Resolved(canBeNull: true)]
- private OsuGame game { get; set; }
+ private IPerformFromScreenRunner performer { get; set; }
[Resolved]
private IBindable ruleset { get; set; }
@@ -75,7 +76,7 @@ namespace osu.Game.Skinning.Editor
Text = "Song Select",
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
- Action = () => game?.PerformFromScreen(screen =>
+ Action = () => performer?.PerformFromScreen(screen =>
{
if (screen is SongSelect)
return;
@@ -88,7 +89,7 @@ namespace osu.Game.Skinning.Editor
Text = "Gameplay",
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
- Action = () => game?.PerformFromScreen(screen =>
+ Action = () => performer?.PerformFromScreen(screen =>
{
if (screen is Player)
return;