Merge branch 'master' into i-notification-overlay

This commit is contained in:
Dan Balasescu 2022-04-19 06:03:56 +09:00 committed by GitHub
commit bb8b94f8ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 48 additions and 24 deletions

View File

@ -49,7 +49,7 @@ private void load(OsuColour colours)
Dependencies.Cache(chatManager);
Dependencies.Cache(new ChatOverlay());
Dependencies.Cache(dialogOverlay);
Dependencies.CacheAs<IDialogOverlay>(dialogOverlay);
}
[SetUp]

View File

@ -97,7 +97,7 @@ private void load()
Depth = -1
});
Dependencies.Cache(dialogOverlay);
Dependencies.CacheAs<IDialogOverlay>(dialogOverlay);
}
}
}

View File

@ -31,7 +31,7 @@ public class TestSceneBeatmapLeaderboard : OsuTestScene
{
private readonly FailableLeaderboard leaderboard;
[Cached]
[Cached(typeof(IDialogOverlay))]
private readonly DialogOverlay dialogOverlay;
private ScoreManager scoreManager;

View File

@ -19,7 +19,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{
public class TestSceneUserTopScoreContainer : OsuTestScene
{
[Cached]
[Cached(typeof(IDialogOverlay))]
private readonly DialogOverlay dialogOverlay;
public TestSceneUserTopScoreContainer()

View File

@ -63,7 +63,7 @@ namespace osu.Game
/// The full osu! experience. Builds on top of <see cref="OsuGameBase"/> to add menus and binding logic
/// for initial components that are generally retrieved via DI.
/// </summary>
public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>, ILocalUserPlayInfo
public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>, ILocalUserPlayInfo, IPerformFromScreenRunner
{
/// <summary>
/// The amount of global offset to apply when a left/right anchored overlay is displayed (ie. settings or notifications).
@ -586,12 +586,6 @@ private void modsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
private PerformFromMenuRunner performFromMainMenuTask;
/// <summary>
/// Perform an action only after returning to a specific screen as indicated by <paramref name="validScreens"/>.
/// Eagerly tries to exit the current screen until it succeeds.
/// </summary>
/// <param name="action">The action to perform once we are in the correct state.</param>
/// <param name="validScreens">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. <see cref="MainMenu"/> is used if not specified.</param>
public void PerformFromScreen(Action<IScreen> action, IEnumerable<Type> validScreens = null)
{
performFromMainMenuTask?.Cancel();

View File

@ -14,6 +14,7 @@
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 @@ private class PlayingUserPanel : CompositeDrawable
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 @@ private void load(IAPIProvider api)
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 }
}
}

View File

@ -216,7 +216,7 @@ protected PopupDialog()
};
// It's important we start in a visible state so our state fires on hide, even before load.
// This is used by the IDialogOverlay to know when the dialog was dismissed.
// This is used by the dialog overlay to know when the dialog was dismissed.
Show();
}

View File

@ -11,7 +11,7 @@ namespace osu.Game.Overlays
/// <summary>
/// A global overlay that can show popup dialogs.
/// </summary>
[Cached]
[Cached(typeof(IDialogOverlay))]
public interface IDialogOverlay
{
/// <summary>

View File

@ -7,6 +7,7 @@
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 @@ public class GeneralSettings : SettingsSubsection
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 @@ private void load(FrameworkDebugConfigManager config, FrameworkConfigManager fra
Add(new SettingsButton
{
Text = DebugSettingsStrings.ImportFiles,
Action = () => game?.PerformFromScreen(menu => menu.Push(new FileImportScreen()))
Action = () => performer?.PerformFromScreen(menu => menu.Push(new FileImportScreen()))
});
}
}

View File

@ -6,13 +6,14 @@
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<string> taskCompletionSource)
{
@ -25,7 +26,7 @@ public StableDirectoryLocationDialog(TaskCompletionSource<string> taskCompletion
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
{

View File

@ -0,0 +1,26 @@
// 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 System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Screens;
using osu.Game.Screens.Menu;
namespace osu.Game.Screens
{
/// <summary>
/// Manages a global screen stack to allow nested components a guarantee of where work is executed.
/// </summary>
[Cached]
public interface IPerformFromScreenRunner
{
/// <summary>
/// Perform an action only after returning to a specific screen as indicated by <paramref name="validScreens"/>.
/// Eagerly tries to exit the current screen until it succeeds.
/// </summary>
/// <param name="action">The action to perform once we are in the correct state.</param>
/// <param name="validScreens">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. <see cref="MainMenu"/> is used if not specified.</param>
void PerformFromScreen(Action<IScreen> action, IEnumerable<Type> validScreens = null);
}
}

View File

@ -148,14 +148,14 @@ private void load(BeatmapListingOverlay beatmapListing, SettingsOverlay settings
}
[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()

View File

@ -15,6 +15,7 @@
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 @@ public class SkinEditorSceneLibrary : CompositeDrawable
private const float padding = 10;
[Resolved(canBeNull: true)]
private OsuGame game { get; set; }
private IPerformFromScreenRunner performer { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
@ -75,7 +76,7 @@ private void load(OverlayColourProvider overlayColourProvider)
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 @@ private void load(OverlayColourProvider overlayColourProvider)
Text = "Gameplay",
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Action = () => game?.PerformFromScreen(screen =>
Action = () => performer?.PerformFromScreen(screen =>
{
if (screen is Player)
return;