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

Merge pull request #22079 from Joehuu/fix-pause-gameplay-action-not-closing

Make pause overlay close with pause gameplay action
This commit is contained in:
Dean Herbert 2023-01-17 18:19:41 +09:00 committed by GitHub
commit 3f2077a527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 24 deletions

View File

@ -5,6 +5,7 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -34,6 +35,12 @@ namespace osu.Game.Tests.Visual.Gameplay
base.Content.Add(content = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both });
}
[BackgroundDependencyLoader]
private void load()
{
LocalConfig.SetValue(OsuSetting.UIHoldActivationDelay, 0.0);
}
[SetUpSteps]
public override void SetUpSteps()
{
@ -43,6 +50,22 @@ namespace osu.Game.Tests.Visual.Gameplay
confirmClockRunning(true);
}
[Test]
public void TestTogglePauseViaBackAction()
{
pauseViaBackAction();
pauseViaBackAction();
confirmPausedWithNoOverlay();
}
[Test]
public void TestTogglePauseViaPauseGameplayAction()
{
pauseViaPauseGameplayAction();
pauseViaPauseGameplayAction();
confirmPausedWithNoOverlay();
}
[Test]
public void TestPauseWithLargeOffset()
{
@ -144,7 +167,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
AddStep("disable pause support", () => Player.Configuration.AllowPause = false);
pauseFromUserExitKey();
pauseViaBackAction();
confirmExited();
}
@ -156,7 +179,7 @@ namespace osu.Game.Tests.Visual.Gameplay
pauseAndConfirm();
resume();
pauseFromUserExitKey();
pauseViaBackAction();
confirmResumed();
confirmNotExited();
@ -170,7 +193,7 @@ namespace osu.Game.Tests.Visual.Gameplay
pauseAndConfirm();
resume();
AddStep("pause via exit key", () => Player.ExitViaQuickExit());
exitViaQuickExitAction();
confirmResumed();
AddAssert("exited", () => !Player.IsCurrentScreen());
@ -214,7 +237,7 @@ namespace osu.Game.Tests.Visual.Gameplay
confirmClockRunning(false);
AddStep("exit via user pause", () => Player.ExitViaPause());
pauseViaBackAction();
confirmExited();
}
@ -224,11 +247,11 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
// will finish the fail animation and show the fail/pause screen.
AddStep("attempt exit via pause key", () => Player.ExitViaPause());
pauseViaBackAction();
AddAssert("fail overlay shown", () => Player.FailOverlayVisible);
// will actually exit.
AddStep("exit via pause key", () => Player.ExitViaPause());
pauseViaBackAction();
confirmExited();
}
@ -245,7 +268,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public void TestQuickExitFromFailedGameplay()
{
AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddStep("quick exit", () => Player.GameplayClockContainer.ChildrenOfType<HotkeyExitOverlay>().First().Action?.Invoke());
exitViaQuickExitAction();
confirmExited();
}
@ -261,7 +284,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test]
public void TestQuickExitFromGameplay()
{
AddStep("quick exit", () => Player.GameplayClockContainer.ChildrenOfType<HotkeyExitOverlay>().First().Action?.Invoke());
exitViaQuickExitAction();
confirmExited();
}
@ -327,7 +350,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private void pauseAndConfirm()
{
pauseFromUserExitKey();
pauseViaBackAction();
confirmPaused();
}
@ -374,7 +397,17 @@ namespace osu.Game.Tests.Visual.Gameplay
}
private void restart() => AddStep("restart", () => Player.Restart());
private void pauseFromUserExitKey() => AddStep("user pause", () => Player.ExitViaPause());
private void pauseViaBackAction() => AddStep("press escape", () => InputManager.Key(Key.Escape));
private void pauseViaPauseGameplayAction() => AddStep("press middle mouse", () => InputManager.Click(MouseButton.Middle));
private void exitViaQuickExitAction() => AddStep("press ctrl-tilde", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.PressKey(Key.Tilde);
InputManager.ReleaseKey(Key.Tilde);
InputManager.ReleaseKey(Key.ControlLeft);
});
private void resume() => AddStep("resume", () => Player.Resume());
private void confirmPauseOverlayShown(bool isShown) =>
@ -405,10 +438,6 @@ namespace osu.Game.Tests.Visual.Gameplay
public bool PauseOverlayVisible => PauseOverlay.State.Value == Visibility.Visible;
public void ExitViaPause() => PerformExit(true);
public void ExitViaQuickExit() => PerformExit(false);
public override void OnEntering(ScreenTransitionEvent e)
{
base.OnEntering(e);

View File

@ -5,6 +5,7 @@
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
@ -14,6 +15,7 @@ using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osuTK;
using osuTK.Input;
namespace osu.Game.Graphics.UserInterfaceV2
{
@ -58,6 +60,14 @@ namespace osu.Game.Graphics.UserInterfaceV2
this.FadeOut(fade_duration, Easing.OutQuint);
}
protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.Key == Key.Escape)
return false; // disable the framework-level handling of escape key for conformity (we use GlobalAction.Back).
return base.OnKeyDown(e);
}
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat)
@ -68,7 +78,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
if (e.Action == GlobalAction.Back)
{
Hide();
this.HidePopover();
return true;
}

View File

@ -155,9 +155,9 @@ namespace osu.Game.Localisation
public static LocalisableString ToggleProfile => new TranslatableString(getKey(@"toggle_profile"), @"Toggle profile");
/// <summary>
/// "Pause gameplay"
/// "Pause / resume gameplay"
/// </summary>
public static LocalisableString PauseGameplay => new TranslatableString(getKey(@"pause_gameplay"), @"Pause gameplay");
public static LocalisableString PauseGameplay => new TranslatableString(getKey(@"pause_gameplay"), @"Pause / resume gameplay");
/// <summary>
/// "Setup mode"

View File

@ -44,7 +44,7 @@ namespace osu.Game.Screens.Play
/// <summary>
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
/// </summary>
protected virtual Action BackAction => () => InternalButtons.Children.LastOrDefault()?.TriggerClick();
protected virtual Action BackAction => () => InternalButtons.LastOrDefault()?.TriggerClick();
/// <summary>
/// Action that is invoked when <see cref="GlobalAction.Select"/> is triggered.
@ -189,7 +189,7 @@ namespace osu.Game.Screens.Play
InternalButtons.Add(button);
}
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
switch (e.Action)
{

View File

@ -8,8 +8,10 @@ using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Audio;
using osu.Game.Graphics;
using osu.Game.Input.Bindings;
using osu.Game.Skinning;
using osuTK.Graphics;
@ -26,7 +28,7 @@ namespace osu.Game.Screens.Play
private SkinnableSound pauseLoop;
protected override Action BackAction => () => InternalButtons.Children.First().TriggerClick();
protected override Action BackAction => () => InternalButtons.First().TriggerClick();
[BackgroundDependencyLoader]
private void load(OsuColour colours)
@ -56,5 +58,17 @@ namespace osu.Game.Screens.Play
pauseLoop.VolumeTo(0, TRANSITION_DURATION, Easing.OutQuad).Finally(_ => pauseLoop.Stop());
}
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
switch (e.Action)
{
case GlobalAction.PauseGameplay:
InternalButtons.First().TriggerClick();
return true;
}
return base.OnPressed(e);
}
}
}

View File

@ -50,17 +50,16 @@ namespace osu.Game.Tests.Visual
{
var cursorDisplay = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both };
cursorDisplay.Add(new OsuTooltipContainer(cursorDisplay.MenuCursor)
cursorDisplay.Add(content = new OsuTooltipContainer(cursorDisplay.MenuCursor)
{
RelativeSizeAxes = Axes.Both,
Child = mainContent
});
mainContent = cursorDisplay;
mainContent.Add(cursorDisplay);
}
if (CreateNestedActionContainer)
mainContent = new GlobalActionContainer(null).WithChild(mainContent);
mainContent.Add(new GlobalActionContainer(null));
base.Content.AddRange(new Drawable[]
{