From c4bf03e6400d5047d2ebf916a7bd532334fff19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 16 Apr 2024 12:42:12 +0200 Subject: [PATCH 1/3] Add failing test --- .../TestSceneResume.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 osu.Game.Rulesets.Osu.Tests/TestSceneResume.cs diff --git a/osu.Game.Rulesets.Osu.Tests/TestSceneResume.cs b/osu.Game.Rulesets.Osu.Tests/TestSceneResume.cs new file mode 100644 index 0000000000..023016c32d --- /dev/null +++ b/osu.Game.Rulesets.Osu.Tests/TestSceneResume.cs @@ -0,0 +1,69 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Linq; +using NUnit.Framework; +using osu.Framework.Graphics.Containers; +using osu.Framework.Testing; +using osu.Game.Screens.Play; +using osu.Game.Tests.Visual; +using osuTK; +using osuTK.Input; + +namespace osu.Game.Rulesets.Osu.Tests +{ + public partial class TestSceneResume : PlayerTestScene + { + protected override Ruleset CreatePlayerRuleset() => new OsuRuleset(); + + protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(true, false, AllowBackwardsSeeks); + + [Test] + public void TestPauseViaKeyboard() + { + AddStep("move mouse to center", () => InputManager.MoveMouseTo(Player.ScreenSpaceDrawQuad.Centre)); + AddUntilStep("wait for gameplay start", () => Player.LocalUserPlaying.Value); + AddStep("press escape", () => InputManager.PressKey(Key.Escape)); + AddUntilStep("wait for pause overlay", () => Player.ChildrenOfType().Single().State.Value, () => Is.EqualTo(Visibility.Visible)); + AddStep("release escape", () => InputManager.ReleaseKey(Key.Escape)); + AddStep("resume", () => + { + InputManager.Key(Key.Down); + InputManager.Key(Key.Space); + }); + AddUntilStep("pause overlay present", () => Player.DrawableRuleset.ResumeOverlay.State.Value, () => Is.EqualTo(Visibility.Visible)); + } + + [Test] + public void TestPauseViaKeyboardWhenMouseOutsidePlayfield() + { + AddStep("move mouse outside playfield", () => InputManager.MoveMouseTo(Player.DrawableRuleset.Playfield.ScreenSpaceDrawQuad.BottomRight + new Vector2(1))); + AddUntilStep("wait for gameplay start", () => Player.LocalUserPlaying.Value); + AddStep("press escape", () => InputManager.PressKey(Key.Escape)); + AddUntilStep("wait for pause overlay", () => Player.ChildrenOfType().Single().State.Value, () => Is.EqualTo(Visibility.Visible)); + AddStep("release escape", () => InputManager.ReleaseKey(Key.Escape)); + AddStep("resume", () => + { + InputManager.Key(Key.Down); + InputManager.Key(Key.Space); + }); + AddUntilStep("pause overlay present", () => Player.DrawableRuleset.ResumeOverlay.State.Value, () => Is.EqualTo(Visibility.Visible)); + } + + [Test] + public void TestPauseViaKeyboardWhenMouseOutsideScreen() + { + AddStep("move mouse outside playfield", () => InputManager.MoveMouseTo(new Vector2(-20))); + AddUntilStep("wait for gameplay start", () => Player.LocalUserPlaying.Value); + AddStep("press escape", () => InputManager.PressKey(Key.Escape)); + AddUntilStep("wait for pause overlay", () => Player.ChildrenOfType().Single().State.Value, () => Is.EqualTo(Visibility.Visible)); + AddStep("release escape", () => InputManager.ReleaseKey(Key.Escape)); + AddStep("resume", () => + { + InputManager.Key(Key.Down); + InputManager.Key(Key.Space); + }); + AddUntilStep("pause overlay not present", () => Player.DrawableRuleset.ResumeOverlay.State.Value, () => Is.EqualTo(Visibility.Hidden)); + } + } +} From f9873968a5f06fa355b074f834fad8e9579a3ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 16 Apr 2024 13:37:12 +0200 Subject: [PATCH 2/3] Apply NRT in `OsuResumeOverlay` --- osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs b/osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs index adc7bd97ff..19d8a94f0a 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -19,12 +17,12 @@ namespace osu.Game.Rulesets.Osu.UI { public partial class OsuResumeOverlay : ResumeOverlay { - private Container cursorScaleContainer; - private OsuClickToResumeCursor clickToResumeCursor; + private Container cursorScaleContainer = null!; + private OsuClickToResumeCursor clickToResumeCursor = null!; - private OsuCursorContainer localCursorContainer; + private OsuCursorContainer? localCursorContainer; - public override CursorContainer LocalCursor => State.Value == Visibility.Visible ? localCursorContainer : null; + public override CursorContainer? LocalCursor => State.Value == Visibility.Visible ? localCursorContainer : null; protected override LocalisableString Message => "Click the orange cursor to resume"; @@ -71,8 +69,8 @@ namespace osu.Game.Rulesets.Osu.UI { public override bool HandlePositionalInput => true; - public Action ResumeRequested; - private Container scaleTransitionContainer; + public Action? ResumeRequested; + private Container scaleTransitionContainer = null!; public OsuClickToResumeCursor() { From e5e345712efea6467ae895219cad53a461403672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 16 Apr 2024 13:24:30 +0200 Subject: [PATCH 3/3] Fix resume overlay not appearing after pausing inside window but outside of actual playfield area Related to https://github.com/ppy/osu/discussions/27871 (although does not actually fix the issue with the pause button, _if_ it is to be considered an issue - the problem there is that the gameplay cursor gets hidden, so the other condition in the modified check takes over). Regressed in https://github.com/ppy/osu/commit/bce3bd55e5a863e52f41598c306a248a79638843. Reasoning for breakage is silent change in `this` when moving the `Contains()` check (`DrawableRuleset` will encompass screen bounds, while `OsuResumeOverlay` is only as big as the actual playfield). --- osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs b/osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs index 19d8a94f0a..a04ea80640 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs @@ -10,6 +10,7 @@ using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Game.Rulesets.Osu.UI.Cursor; +using osu.Game.Rulesets.UI; using osu.Game.Screens.Play; using osuTK.Graphics; @@ -26,6 +27,9 @@ namespace osu.Game.Rulesets.Osu.UI protected override LocalisableString Message => "Click the orange cursor to resume"; + [Resolved] + private DrawableRuleset? drawableRuleset { get; set; } + [BackgroundDependencyLoader] private void load() { @@ -38,7 +42,7 @@ namespace osu.Game.Rulesets.Osu.UI protected override void PopIn() { // Can't display if the cursor is outside the window. - if (GameplayCursor.LastFrameState == Visibility.Hidden || !Contains(GameplayCursor.ActiveCursor.ScreenSpaceDrawQuad.Centre)) + if (GameplayCursor.LastFrameState == Visibility.Hidden || drawableRuleset?.Contains(GameplayCursor.ActiveCursor.ScreenSpaceDrawQuad.Centre) == false) { Resume(); return;