Merge pull request #22000 from Joehuu/middle-click-replay-pause

Make replays pause with middle mouse button instead of exiting
This commit is contained in:
Bartłomiej Dach 2023-02-02 21:40:24 +01:00 committed by GitHub
commit baf4a3f04e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 7 deletions

View File

@ -4,6 +4,7 @@
#nullable disable
using NUnit.Framework;
using osu.Framework.Screens;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osuTK.Input;
@ -24,13 +25,40 @@ public override void SetUpSteps()
}
[Test]
public void TestPause()
public void TestPauseViaSpace()
{
double? lastTime = null;
AddUntilStep("wait for first hit", () => Player.ScoreProcessor.TotalScore.Value > 0);
AddStep("Pause playback", () => InputManager.Key(Key.Space));
AddStep("Pause playback with space", () => InputManager.Key(Key.Space));
AddAssert("player not exited", () => Player.IsCurrentScreen());
AddUntilStep("Time stopped progressing", () =>
{
double current = Player.GameplayClockContainer.CurrentTime;
bool changed = lastTime != current;
lastTime = current;
return !changed;
});
AddWaitStep("wait some", 10);
AddAssert("Time still stopped", () => lastTime == Player.GameplayClockContainer.CurrentTime);
}
[Test]
public void TestPauseViaMiddleMouse()
{
double? lastTime = null;
AddUntilStep("wait for first hit", () => Player.ScoreProcessor.TotalScore.Value > 0);
AddStep("Pause playback with middle mouse", () => InputManager.Click(MouseButton.Middle));
AddAssert("player not exited", () => Player.IsCurrentScreen());
AddUntilStep("Time stopped progressing", () =>
{

View File

@ -35,6 +35,7 @@ protected override void LoadComplete()
// It is used to decide the order of precedence, with the earlier items having higher precedence.
public override IEnumerable<IKeyBinding> DefaultKeyBindings => GlobalKeyBindings
.Concat(EditorKeyBindings)
.Concat(ReplayKeyBindings)
.Concat(InGameKeyBindings)
.Concat(SongSelectKeyBindings)
.Concat(AudioControlKeyBindings)
@ -112,13 +113,18 @@ protected override void LoadComplete()
new KeyBinding(new[] { InputKey.F4 }, GlobalAction.IncreaseScrollSpeed),
new KeyBinding(new[] { InputKey.Shift, InputKey.Tab }, GlobalAction.ToggleInGameInterface),
new KeyBinding(InputKey.MouseMiddle, GlobalAction.PauseGameplay),
new KeyBinding(InputKey.Space, GlobalAction.TogglePauseReplay),
new KeyBinding(InputKey.Left, GlobalAction.SeekReplayBackward),
new KeyBinding(InputKey.Right, GlobalAction.SeekReplayForward),
new KeyBinding(InputKey.Control, GlobalAction.HoldForHUD),
new KeyBinding(InputKey.Tab, GlobalAction.ToggleChatFocus),
};
public IEnumerable<KeyBinding> ReplayKeyBindings => new[]
{
new KeyBinding(InputKey.Space, GlobalAction.TogglePauseReplay),
new KeyBinding(InputKey.MouseMiddle, GlobalAction.TogglePauseReplay),
new KeyBinding(InputKey.Left, GlobalAction.SeekReplayBackward),
new KeyBinding(InputKey.Right, GlobalAction.SeekReplayForward),
};
public IEnumerable<KeyBinding> SongSelectKeyBindings => new[]
{
new KeyBinding(InputKey.F1, GlobalAction.ToggleModSelection),

View File

@ -34,6 +34,11 @@ public static class InputSettingsStrings
/// </summary>
public static LocalisableString InGameSection => new TranslatableString(getKey(@"in_game_section"), @"In Game");
/// <summary>
/// "Replay"
/// </summary>
public static LocalisableString ReplaySection => new TranslatableString(getKey(@"replay_section"), @"Replay");
/// <summary>
/// "Audio"
/// </summary>

View File

@ -25,6 +25,7 @@ public GlobalKeyBindingsSection(GlobalActionContainer manager)
Add(new AudioControlKeyBindingsSubsection(manager));
Add(new SongSelectKeyBindingSubsection(manager));
Add(new InGameKeyBindingsSubsection(manager));
Add(new ReplayKeyBindingsSubsection(manager));
Add(new EditorKeyBindingsSubsection(manager));
}
@ -72,6 +73,17 @@ public InGameKeyBindingsSubsection(GlobalActionContainer manager)
}
}
private partial class ReplayKeyBindingsSubsection : KeyBindingsSubsection
{
protected override LocalisableString Header => InputSettingsStrings.ReplaySection;
public ReplayKeyBindingsSubsection(GlobalActionContainer manager)
: base(null)
{
Defaults = manager.ReplayKeyBindings;
}
}
private partial class AudioControlKeyBindingsSubsection : KeyBindingsSubsection
{
protected override LocalisableString Header => InputSettingsStrings.AudioSection;

View File

@ -31,6 +31,8 @@ public partial class HoldForMenuButton : FillFlowContainer
public readonly Bindable<bool> IsPaused = new Bindable<bool>();
public readonly Bindable<bool> ReplayLoaded = new Bindable<bool>();
private HoldButton button;
public Action Action { get; set; }
@ -60,6 +62,7 @@ private void load(Player player)
HoverGained = () => text.FadeIn(500, Easing.OutQuint),
HoverLost = () => text.FadeOut(500, Easing.OutQuint),
IsPaused = { BindTarget = IsPaused },
ReplayLoaded = { BindTarget = ReplayLoaded },
Action = () => Action(),
}
};
@ -110,6 +113,8 @@ private partial class HoldButton : HoldToConfirmContainer, IKeyBindingHandler<Gl
public readonly Bindable<bool> IsPaused = new Bindable<bool>();
public readonly Bindable<bool> ReplayLoaded = new Bindable<bool>();
protected override bool AllowMultipleFires => true;
public Action HoverGained;
@ -251,7 +256,14 @@ public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
switch (e.Action)
{
case GlobalAction.Back:
case GlobalAction.PauseGameplay: // in the future this behaviour will differ for replays etc.
if (!pendingAnimation)
BeginConfirm();
return true;
case GlobalAction.PauseGameplay:
// handled by replay player
if (ReplayLoaded.Value) return false;
if (!pendingAnimation)
BeginConfirm();
return true;
@ -265,7 +277,12 @@ public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
switch (e.Action)
{
case GlobalAction.Back:
AbortConfirm();
break;
case GlobalAction.PauseGameplay:
if (ReplayLoaded.Value) return;
AbortConfirm();
break;
}

View File

@ -435,7 +435,8 @@ private Drawable createOverlayComponents(IWorkingBeatmap working)
HoldToQuit =
{
Action = () => PerformExit(true),
IsPaused = { BindTarget = GameplayClockContainer.IsPaused }
IsPaused = { BindTarget = GameplayClockContainer.IsPaused },
ReplayLoaded = { BindTarget = DrawableRuleset.HasReplayLoaded },
},
KeyCounter =
{