From 69526f25bb9743bb3fdca14a4c105bbd9d8465b7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Jun 2023 20:43:33 +0900 Subject: [PATCH] Add hotkey to save replay Defaults to `F2` aka stable. --- .../Input/Bindings/GlobalActionContainer.cs | 4 ++++ .../GlobalActionKeyBindingStrings.cs | 5 +++++ .../Screens/Play/SaveFailedScoreButton.cs | 21 ++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index fdd96d3890..0ae29ebc8e 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -119,6 +119,7 @@ protected override void LoadComplete() new KeyBinding(InputKey.MouseMiddle, GlobalAction.PauseGameplay), new KeyBinding(InputKey.Control, GlobalAction.HoldForHUD), new KeyBinding(InputKey.Tab, GlobalAction.ToggleChatFocus), + new KeyBinding(InputKey.F2, GlobalAction.SaveReplay), }; public IEnumerable ReplayKeyBindings => new[] @@ -366,5 +367,8 @@ public enum GlobalAction [LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorCycleNextBeatSnapDivisor))] EditorCycleNextBeatSnapDivisor, + + [LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.SaveReplay))] + SaveReplay, } } diff --git a/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs b/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs index aa608a603b..708fdaa174 100644 --- a/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs +++ b/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs @@ -324,6 +324,11 @@ public static class GlobalActionKeyBindingStrings /// public static LocalisableString ToggleChatFocus => new TranslatableString(getKey(@"toggle_chat_focus"), @"Toggle chat focus"); + /// + /// "Save replay" + /// + public static LocalisableString SaveReplay => new TranslatableString(getKey(@"save_replay"), @"Save replay"); + private static string getKey(string key) => $@"{prefix}:{key}"; } } diff --git a/osu.Game/Screens/Play/SaveFailedScoreButton.cs b/osu.Game/Screens/Play/SaveFailedScoreButton.cs index 20d2130e76..c5bb265dcb 100644 --- a/osu.Game/Screens/Play/SaveFailedScoreButton.cs +++ b/osu.Game/Screens/Play/SaveFailedScoreButton.cs @@ -8,15 +8,18 @@ using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Input.Bindings; +using osu.Framework.Input.Events; using osu.Game.Database; using osu.Game.Scoring; using osu.Game.Graphics.UserInterface; +using osu.Game.Input.Bindings; using osu.Game.Online; using osuTK; namespace osu.Game.Screens.Play { - public partial class SaveFailedScoreButton : CompositeDrawable + public partial class SaveFailedScoreButton : CompositeDrawable, IKeyBindingHandler { private readonly Bindable state = new Bindable(); @@ -87,5 +90,21 @@ private void load(OsuGame? game, Player? player, RealmAccess realm) } }, true); } + + public bool OnPressed(KeyBindingPressEvent e) + { + switch (e.Action) + { + case GlobalAction.SaveReplay: + button.TriggerClick(); + return true; + } + + return false; + } + + public void OnReleased(KeyBindingReleaseEvent e) + { + } } }