1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:17:51 +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.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
@ -21,10 +18,12 @@ namespace osu.Game.Tests.Visual.Gameplay
[Description("player pause/fail screens")]
public partial class TestSceneGameplayMenuOverlay : OsuManualInputManagerTestScene
{
private FailOverlay failOverlay;
private PauseOverlay pauseOverlay;
private FailOverlay failOverlay = null!;
private PauseOverlay pauseOverlay = null!;
private GlobalActionContainer globalActionContainer;
private GlobalActionContainer globalActionContainer = null!;
private bool triggeredRetryButton;
[BackgroundDependencyLoader]
private void load(OsuGameBase game)
@ -35,12 +34,18 @@ namespace osu.Game.Tests.Visual.Gameplay
[SetUp]
public void SetUp() => Schedule(() =>
{
triggeredRetryButton = false;
globalActionContainer.Children = new Drawable[]
{
pauseOverlay = new PauseOverlay
{
OnResume = () => Logger.Log(@"Resume"),
OnRetry = () => Logger.Log(@"Retry"),
OnRetry = () =>
{
Logger.Log(@"Retry");
triggeredRetryButton = true;
},
OnQuit = () => Logger.Log(@"Quit"),
},
failOverlay = new FailOverlay
@ -224,17 +229,9 @@ namespace osu.Game.Tests.Visual.Gameplay
{
showOverlay();
bool triggered = false;
AddStep("Click retry button", () =>
{
var lastAction = pauseOverlay.OnRetry;
pauseOverlay.OnRetry = () => triggered = true;
AddStep("Click retry button", () => getButton(1).TriggerClick());
getButton(1).TriggerClick();
pauseOverlay.OnRetry = lastAction;
});
AddAssert("Action was triggered", () => triggered);
AddAssert("Retry was triggered", () => triggeredRetryButton);
AddAssert("Overlay is closed", () => pauseOverlay.State.Value == Visibility.Hidden);
}
@ -252,25 +249,9 @@ namespace osu.Game.Tests.Visual.Gameplay
InputManager.Key(Key.Down);
});
bool triggered = false;
Action lastAction = null;
AddStep("Press enter", () =>
{
lastAction = pauseOverlay.OnRetry;
pauseOverlay.OnRetry = () => triggered = true;
InputManager.Key(Key.Enter);
});
AddStep("Press enter", () => InputManager.Key(Key.Enter));
AddAssert("Action was triggered", () =>
{
if (lastAction != null)
{
pauseOverlay.OnRetry = lastAction;
lastAction = null;
}
return triggered;
});
AddAssert("Retry was triggered", () => triggeredRetryButton);
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.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
@ -12,6 +10,7 @@ using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Spectator;
using osu.Game.Rulesets.Osu;
@ -39,13 +38,13 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override bool UseOnlineAPI => true;
[Resolved]
private OsuGameBase game { get; set; }
private OsuGameBase game { get; set; } = null!;
private TestSpectatorClient spectatorClient => dependenciesScreen.SpectatorClient;
private DependenciesScreen dependenciesScreen;
private SoloSpectatorScreen spectatorScreen;
private DependenciesScreen dependenciesScreen = null!;
private SoloSpectatorScreen spectatorScreen = null!;
private BeatmapSetInfo importedBeatmap;
private BeatmapSetInfo importedBeatmap = null!;
private int importedBeatmapId;
[SetUpSteps]
@ -188,7 +187,7 @@ namespace osu.Game.Tests.Visual.Gameplay
waitForPlayerCurrent();
Player lastPlayer = null;
Player lastPlayer = null!;
AddStep("store first player", () => lastPlayer = player);
start();
@ -214,6 +213,11 @@ namespace osu.Game.Tests.Visual.Gameplay
checkPaused(false); // Should continue playing until out of frames
checkPaused(true); // And eventually stop after running out of frames and fail.
// 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]
@ -278,7 +282,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestFinalFrameInBundleHasHeader()
{
FrameDataBundle lastBundle = null;
FrameDataBundle? lastBundle = null;
AddStep("bind to client", () => spectatorClient.OnNewFrames += (_, bundle) => lastBundle = bundle);
@ -287,8 +291,8 @@ namespace osu.Game.Tests.Visual.Gameplay
finish();
AddUntilStep("bundle received", () => lastBundle != null);
AddAssert("first frame does not have header", () => lastBundle.Frames[0].Header == null);
AddAssert("last frame has header", () => lastBundle.Frames[^1].Header != null);
AddAssert("first frame does not have header", () => lastBundle?.Frames[0].Header == null);
AddAssert("last frame has header", () => lastBundle?.Frames[^1].Header != null);
}
[Test]
@ -383,7 +387,7 @@ namespace osu.Game.Tests.Visual.Gameplay
}
private OsuFramedReplayInputHandler replayHandler =>
(OsuFramedReplayInputHandler)Stack.ChildrenOfType<OsuInputManager>().First().ReplayInputHandler;
(OsuFramedReplayInputHandler)Stack.ChildrenOfType<OsuInputManager>().First().ReplayInputHandler!;
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.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Threading.Tasks;
using osu.Game.Scoring;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
@ -22,26 +18,13 @@ namespace osu.Game.Screens.Play
{
public partial class FailOverlay : GameplayMenuOverlay
{
public Func<Task<ScoreInfo>> SaveReplay;
public Func<Task<ScoreInfo>>? SaveReplay;
public override LocalisableString Header => GameplayMenuOverlayStrings.FailedHeader;
private readonly bool showButtons;
public FailOverlay(bool showButtons = true)
{
this.showButtons = showButtons;
}
[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
Add(new Container
{

View File

@ -38,8 +38,9 @@ namespace osu.Game.Screens.Play
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
public Action? OnRetry;
public Action? OnQuit;
public Action? OnResume { get; init; }
public Action? OnRetry { get; init; }
public Action? OnQuit { get; init; }
/// <summary>
/// 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();
updateInfoText();

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using System.Linq;
using osu.Framework.Allocation;
@ -11,23 +9,19 @@ using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Audio;
using osu.Game.Graphics;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osu.Game.Skinning;
using osuTK.Graphics;
namespace osu.Game.Screens.Play
{
public partial class PauseOverlay : GameplayMenuOverlay
{
public Action OnResume;
public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying;
public override LocalisableString Header => GameplayMenuOverlayStrings.PausedHeader;
private SkinnableSound pauseLoop;
private SkinnableSound pauseLoop = null!;
protected override Action BackAction => () =>
{
@ -38,12 +32,8 @@ namespace osu.Game.Screens.Play
};
[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"))
{
Looping = true,

View File

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

View File

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

View File

@ -1,9 +1,8 @@
// 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.
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Screens;
using osu.Game.Online.Spectator;
using osu.Game.Scoring;
@ -50,7 +49,7 @@ namespace osu.Game.Screens.Play
{
base.Dispose(isDisposing);
if (SpectatorClient != null)
if (SpectatorClient.IsNotNull())
SpectatorClient.OnUserBeganPlaying -= userBeganPlaying;
}
}

View File

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