1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-07 22:22:59 +08:00

Merge pull request #27414 from Joehuu/spectator-remove-back-button

Move back/quit button from bottom left to fail overlay when spectating
This commit is contained in:
Salman Ahmed 2024-02-29 01:52:44 +03:00 committed by GitHub
commit 21bb3c3bab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 67 additions and 100 deletions

View File

@ -1,9 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -21,10 +18,12 @@ namespace osu.Game.Tests.Visual.Gameplay
[Description("player pause/fail screens")] [Description("player pause/fail screens")]
public partial class TestSceneGameplayMenuOverlay : OsuManualInputManagerTestScene public partial class TestSceneGameplayMenuOverlay : OsuManualInputManagerTestScene
{ {
private FailOverlay failOverlay; private FailOverlay failOverlay = null!;
private PauseOverlay pauseOverlay; private PauseOverlay pauseOverlay = null!;
private GlobalActionContainer globalActionContainer; private GlobalActionContainer globalActionContainer = null!;
private bool triggeredRetryButton;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase game) private void load(OsuGameBase game)
@ -35,12 +34,18 @@ namespace osu.Game.Tests.Visual.Gameplay
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>
{ {
triggeredRetryButton = false;
globalActionContainer.Children = new Drawable[] globalActionContainer.Children = new Drawable[]
{ {
pauseOverlay = new PauseOverlay pauseOverlay = new PauseOverlay
{ {
OnResume = () => Logger.Log(@"Resume"), OnResume = () => Logger.Log(@"Resume"),
OnRetry = () => Logger.Log(@"Retry"), OnRetry = () =>
{
Logger.Log(@"Retry");
triggeredRetryButton = true;
},
OnQuit = () => Logger.Log(@"Quit"), OnQuit = () => Logger.Log(@"Quit"),
}, },
failOverlay = new FailOverlay failOverlay = new FailOverlay
@ -224,17 +229,9 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
showOverlay(); showOverlay();
bool triggered = false; AddStep("Click retry button", () => getButton(1).TriggerClick());
AddStep("Click retry button", () =>
{
var lastAction = pauseOverlay.OnRetry;
pauseOverlay.OnRetry = () => triggered = true;
getButton(1).TriggerClick(); AddAssert("Retry was triggered", () => triggeredRetryButton);
pauseOverlay.OnRetry = lastAction;
});
AddAssert("Action was triggered", () => triggered);
AddAssert("Overlay is closed", () => pauseOverlay.State.Value == Visibility.Hidden); AddAssert("Overlay is closed", () => pauseOverlay.State.Value == Visibility.Hidden);
} }
@ -252,25 +249,9 @@ namespace osu.Game.Tests.Visual.Gameplay
InputManager.Key(Key.Down); InputManager.Key(Key.Down);
}); });
bool triggered = false; AddStep("Press enter", () => InputManager.Key(Key.Enter));
Action lastAction = null;
AddStep("Press enter", () =>
{
lastAction = pauseOverlay.OnRetry;
pauseOverlay.OnRetry = () => triggered = true;
InputManager.Key(Key.Enter);
});
AddAssert("Action was triggered", () => AddAssert("Retry was triggered", () => triggeredRetryButton);
{
if (lastAction != null)
{
pauseOverlay.OnRetry = lastAction;
lastAction = null;
}
return triggered;
});
AddAssert("Overlay is closed", () => pauseOverlay.State.Value == Visibility.Hidden); AddAssert("Overlay is closed", () => pauseOverlay.State.Value == Visibility.Hidden);
} }

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -12,6 +10,7 @@ using osu.Framework.Screens;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Localisation;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
@ -39,13 +38,13 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override bool UseOnlineAPI => true; protected override bool UseOnlineAPI => true;
[Resolved] [Resolved]
private OsuGameBase game { get; set; } private OsuGameBase game { get; set; } = null!;
private TestSpectatorClient spectatorClient => dependenciesScreen.SpectatorClient; private TestSpectatorClient spectatorClient => dependenciesScreen.SpectatorClient;
private DependenciesScreen dependenciesScreen; private DependenciesScreen dependenciesScreen = null!;
private SoloSpectatorScreen spectatorScreen; private SoloSpectatorScreen spectatorScreen = null!;
private BeatmapSetInfo importedBeatmap; private BeatmapSetInfo importedBeatmap = null!;
private int importedBeatmapId; private int importedBeatmapId;
[SetUpSteps] [SetUpSteps]
@ -188,7 +187,7 @@ namespace osu.Game.Tests.Visual.Gameplay
waitForPlayerCurrent(); waitForPlayerCurrent();
Player lastPlayer = null; Player lastPlayer = null!;
AddStep("store first player", () => lastPlayer = player); AddStep("store first player", () => lastPlayer = player);
start(); start();
@ -214,6 +213,11 @@ namespace osu.Game.Tests.Visual.Gameplay
checkPaused(false); // Should continue playing until out of frames checkPaused(false); // Should continue playing until out of frames
checkPaused(true); // And eventually stop after running out of frames and fail. checkPaused(true); // And eventually stop after running out of frames and fail.
// Todo: Should check for + display a failed message. // Todo: Should check for + display a failed message.
AddAssert("fail overlay present", () => player.ChildrenOfType<FailOverlay>().Single().IsPresent);
AddAssert("overlay can only quit", () => player.ChildrenOfType<FailOverlay>().Single().Buttons.Single().Text == GameplayMenuOverlayStrings.Quit);
AddStep("press quit button", () => player.ChildrenOfType<FailOverlay>().Single().Buttons.Single().TriggerClick());
AddAssert("player exited", () => Stack.CurrentScreen is SoloSpectatorScreen);
} }
[Test] [Test]
@ -278,7 +282,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test] [Test]
public void TestFinalFrameInBundleHasHeader() public void TestFinalFrameInBundleHasHeader()
{ {
FrameDataBundle lastBundle = null; FrameDataBundle? lastBundle = null;
AddStep("bind to client", () => spectatorClient.OnNewFrames += (_, bundle) => lastBundle = bundle); AddStep("bind to client", () => spectatorClient.OnNewFrames += (_, bundle) => lastBundle = bundle);
@ -287,8 +291,8 @@ namespace osu.Game.Tests.Visual.Gameplay
finish(); finish();
AddUntilStep("bundle received", () => lastBundle != null); AddUntilStep("bundle received", () => lastBundle != null);
AddAssert("first frame does not have header", () => lastBundle.Frames[0].Header == null); AddAssert("first frame does not have header", () => lastBundle?.Frames[0].Header == null);
AddAssert("last frame has header", () => lastBundle.Frames[^1].Header != null); AddAssert("last frame has header", () => lastBundle?.Frames[^1].Header != null);
} }
[Test] [Test]
@ -383,7 +387,7 @@ namespace osu.Game.Tests.Visual.Gameplay
} }
private OsuFramedReplayInputHandler replayHandler => private OsuFramedReplayInputHandler replayHandler =>
(OsuFramedReplayInputHandler)Stack.ChildrenOfType<OsuInputManager>().First().ReplayInputHandler; (OsuFramedReplayInputHandler)Stack.ChildrenOfType<OsuInputManager>().First().ReplayInputHandler!;
private Player player => this.ChildrenOfType<Player>().Single(); private Player player => this.ChildrenOfType<Player>().Single();

View File

@ -1,15 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -22,26 +18,13 @@ namespace osu.Game.Screens.Play
{ {
public partial class FailOverlay : GameplayMenuOverlay public partial class FailOverlay : GameplayMenuOverlay
{ {
public Func<Task<ScoreInfo>> SaveReplay; public Func<Task<ScoreInfo>>? SaveReplay;
public override LocalisableString Header => GameplayMenuOverlayStrings.FailedHeader; public override LocalisableString Header => GameplayMenuOverlayStrings.FailedHeader;
private readonly bool showButtons;
public FailOverlay(bool showButtons = true)
{
this.showButtons = showButtons;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load()
{ {
if (showButtons)
{
AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry?.Invoke());
AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
}
// from #10339 maybe this is a better visual effect // from #10339 maybe this is a better visual effect
Add(new Container Add(new Container
{ {

View File

@ -38,8 +38,9 @@ namespace osu.Game.Screens.Play
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true; public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
public Action? OnRetry; public Action? OnResume { get; init; }
public Action? OnQuit; public Action? OnRetry { get; init; }
public Action? OnQuit { get; init; }
/// <summary> /// <summary>
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered. /// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
@ -129,6 +130,15 @@ namespace osu.Game.Screens.Play
}, },
}; };
if (OnResume != null)
AddButton(GameplayMenuOverlayStrings.Continue, colours.Green, () => OnResume.Invoke());
if (OnRetry != null)
AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry.Invoke());
if (OnQuit != null)
AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit.Invoke());
State.ValueChanged += _ => InternalButtons.Deselect(); State.ValueChanged += _ => InternalButtons.Deselect();
updateInfoText(); updateInfoText();

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -11,23 +9,19 @@ using osu.Framework.Graphics;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Graphics;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK.Graphics;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public partial class PauseOverlay : GameplayMenuOverlay public partial class PauseOverlay : GameplayMenuOverlay
{ {
public Action OnResume;
public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying; public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying;
public override LocalisableString Header => GameplayMenuOverlayStrings.PausedHeader; public override LocalisableString Header => GameplayMenuOverlayStrings.PausedHeader;
private SkinnableSound pauseLoop; private SkinnableSound pauseLoop = null!;
protected override Action BackAction => () => protected override Action BackAction => () =>
{ {
@ -38,12 +32,8 @@ namespace osu.Game.Screens.Play
}; };
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load()
{ {
AddButton(GameplayMenuOverlayStrings.Continue, colours.Green, () => OnResume?.Invoke());
AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry?.Invoke());
AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("Gameplay/pause-loop")) AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("Gameplay/pause-loop"))
{ {
Looping = true, Looping = true,

View File

@ -278,10 +278,10 @@ namespace osu.Game.Screens.Play
createGameplayComponents(Beatmap.Value) createGameplayComponents(Beatmap.Value)
} }
}, },
FailOverlay = new FailOverlay(Configuration.AllowUserInteraction) FailOverlay = new FailOverlay
{ {
SaveReplay = async () => await prepareAndImportScoreAsync(true).ConfigureAwait(false), SaveReplay = async () => await prepareAndImportScoreAsync(true).ConfigureAwait(false),
OnRetry = () => Restart(), OnRetry = Configuration.AllowUserInteraction ? () => Restart() : null,
OnQuit = () => PerformExit(true), OnQuit = () => PerformExit(true),
}, },
new HotkeyExitOverlay new HotkeyExitOverlay

View File

@ -30,13 +30,13 @@ namespace osu.Game.Screens.Play
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>(); private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
private readonly Func<Task<ScoreInfo>> importFailedScore; private readonly Func<Task<ScoreInfo>>? importFailedScore;
private ScoreInfo? importedScore; private ScoreInfo? importedScore;
private DownloadButton button = null!; private DownloadButton button = null!;
public SaveFailedScoreButton(Func<Task<ScoreInfo>> importFailedScore) public SaveFailedScoreButton(Func<Task<ScoreInfo>>? importFailedScore)
{ {
Size = new Vector2(50, 30); Size = new Vector2(50, 30);
@ -60,11 +60,16 @@ namespace osu.Game.Screens.Play
case DownloadState.NotDownloaded: case DownloadState.NotDownloaded:
state.Value = DownloadState.Importing; state.Value = DownloadState.Importing;
if (importFailedScore != null)
{
Task.Run(importFailedScore).ContinueWith(t => Task.Run(importFailedScore).ContinueWith(t =>
{ {
importedScore = realm.Run(r => r.Find<ScoreInfo>(t.GetResultSafely().ID)?.Detach()); importedScore = realm.Run(r => r.Find<ScoreInfo>(t.GetResultSafely().ID)?.Detach());
Schedule(() => state.Value = importedScore != null ? DownloadState.LocallyAvailable : DownloadState.NotDownloaded); Schedule(() => state.Value = importedScore != null ? DownloadState.LocallyAvailable : DownloadState.NotDownloaded);
}).FireAndForget(); }).FireAndForget();
}
break; break;
} }
} }

View File

@ -1,9 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Scoring; using osu.Game.Scoring;
@ -50,7 +49,7 @@ namespace osu.Game.Screens.Play
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (SpectatorClient != null) if (SpectatorClient.IsNotNull())
SpectatorClient.OnUserBeganPlaying -= userBeganPlaying; SpectatorClient.OnUserBeganPlaying -= userBeganPlaying;
} }
} }

View File

@ -1,10 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Diagnostics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -21,12 +19,10 @@ namespace osu.Game.Screens.Play
public abstract partial class SpectatorPlayer : Player public abstract partial class SpectatorPlayer : Player
{ {
[Resolved] [Resolved]
protected SpectatorClient SpectatorClient { get; private set; } protected SpectatorClient SpectatorClient { get; private set; } = null!;
private readonly Score score; private readonly Score score;
public override bool AllowBackButton => true;
protected override bool CheckModsAllowFailure() protected override bool CheckModsAllowFailure()
{ {
if (!allowFail) if (!allowFail)
@ -37,7 +33,7 @@ namespace osu.Game.Screens.Play
private bool allowFail; private bool allowFail;
protected SpectatorPlayer(Score score, PlayerConfiguration configuration = null) protected SpectatorPlayer(Score score, PlayerConfiguration? configuration = null)
: base(configuration) : base(configuration)
{ {
this.score = score; this.score = score;
@ -100,8 +96,7 @@ namespace osu.Game.Screens.Play
foreach (var frame in bundle.Frames) foreach (var frame in bundle.Frames)
{ {
IConvertibleReplayFrame convertibleFrame = GameplayState.Ruleset.CreateConvertibleReplayFrame(); IConvertibleReplayFrame convertibleFrame = GameplayState.Ruleset.CreateConvertibleReplayFrame()!;
Debug.Assert(convertibleFrame != null);
convertibleFrame.FromLegacy(frame, GameplayState.Beatmap); convertibleFrame.FromLegacy(frame, GameplayState.Beatmap);
var convertedFrame = (ReplayFrame)convertibleFrame; var convertedFrame = (ReplayFrame)convertibleFrame;
@ -136,7 +131,7 @@ namespace osu.Game.Screens.Play
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (SpectatorClient != null) if (SpectatorClient.IsNotNull())
SpectatorClient.OnNewFrames -= userSentFrames; SpectatorClient.OnNewFrames -= userSentFrames;
} }
} }