From 4a8295c49dcc6418cf93390ae10965450cd19c42 Mon Sep 17 00:00:00 2001 From: orwenn22 <46846090+orwenn22@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:57:21 +0100 Subject: [PATCH 1/2] Add keybindings for readying and spectating in multi rooms --- .../Input/Bindings/GlobalActionContainer.cs | 17 ++++++++++++ .../GlobalActionKeyBindingStrings.cs | 10 +++++++ osu.Game/Localisation/InputSettingsStrings.cs | 5 ++++ .../Input/GlobalKeyBindingsSection.cs | 1 + .../Multiplayer/Match/MatchStartControl.cs | 27 ++++++++++++++++++- .../Match/MultiplayerSpectateButton.cs | 27 ++++++++++++++++++- 6 files changed, 85 insertions(+), 2 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index 170d2470237c..282aafb9601d 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -36,6 +36,7 @@ public GlobalActionContainer(OsuGameBase? game) .Concat(editorKeyBindings) .Concat(editorTestPlayKeyBindings) .Concat(inGameKeyBindings) + .Concat(multiplayerKeyBindings) .Concat(replayKeyBindings) .Concat(songSelectKeyBindings) .Concat(audioControlKeyBindings) @@ -57,6 +58,9 @@ public static IEnumerable GetDefaultBindingsFor(GlobalActionCategory case GlobalActionCategory.InGame: return inGameKeyBindings; + case GlobalActionCategory.Multiplayer: + return multiplayerKeyBindings; + case GlobalActionCategory.Replay: return replayKeyBindings; @@ -186,6 +190,12 @@ public static IEnumerable GetGlobalActionsFor(GlobalActionCategory new KeyBinding(InputKey.Minus, GlobalAction.DecreaseOffset), }; + private static IEnumerable multiplayerKeyBindings => new[] + { + new KeyBinding(new[] { InputKey.Control, InputKey.R }, GlobalAction.MultiplayerReady), + new KeyBinding(new[] { InputKey.Control, InputKey.S }, GlobalAction.MultiplayerSpectate), + }; + private static IEnumerable replayKeyBindings => new[] { new KeyBinding(InputKey.Space, GlobalAction.TogglePauseReplay), @@ -492,6 +502,12 @@ public enum GlobalAction [LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorSeekToNextBookmark))] EditorSeekToNextBookmark, + + [LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.MultiplayerReady))] + MultiplayerReady, + + [LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.MultiplayerSpectate))] + MultiplayerSpectate, } public enum GlobalActionCategory @@ -499,6 +515,7 @@ public enum GlobalActionCategory General, Editor, InGame, + Multiplayer, Replay, SongSelect, AudioControl, diff --git a/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs b/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs index f9db0461ce29..412eca694955 100644 --- a/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs +++ b/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs @@ -449,6 +449,16 @@ public static class GlobalActionKeyBindingStrings /// public static LocalisableString EditorSeekToNextBookmark => new TranslatableString(getKey(@"editor_seek_to_next_bookmark"), @"Seek to next bookmark"); + /// + /// "Ready" + /// + public static LocalisableString MultiplayerReady => new TranslatableString(getKey(@"multiplayer_ready"), @"Ready"); + + /// + /// "Spectate" + /// + public static LocalisableString MultiplayerSpectate => new TranslatableString(getKey(@"multiplayer_spectate"), @"Spectate"); + private static string getKey(string key) => $@"{prefix}:{key}"; } } diff --git a/osu.Game/Localisation/InputSettingsStrings.cs b/osu.Game/Localisation/InputSettingsStrings.cs index bc1a7e68ab01..3201b5de09e2 100644 --- a/osu.Game/Localisation/InputSettingsStrings.cs +++ b/osu.Game/Localisation/InputSettingsStrings.cs @@ -34,6 +34,11 @@ public static class InputSettingsStrings /// public static LocalisableString InGameSection => new TranslatableString(getKey(@"in_game_section"), @"In Game"); + /// + /// "Multiplayer" + /// + public static LocalisableString MultiplayerSection => new TranslatableString(getKey(@"multiplayer_section"), @"Multiplayer"); + /// /// "Replay" /// diff --git a/osu.Game/Overlays/Settings/Sections/Input/GlobalKeyBindingsSection.cs b/osu.Game/Overlays/Settings/Sections/Input/GlobalKeyBindingsSection.cs index e5bc6cbe8ae7..1d5599e02299 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/GlobalKeyBindingsSection.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/GlobalKeyBindingsSection.cs @@ -29,6 +29,7 @@ private void load() new GlobalKeyBindingsSubsection(InputSettingsStrings.AudioSection, GlobalActionCategory.AudioControl), new GlobalKeyBindingsSubsection(InputSettingsStrings.SongSelectSection, GlobalActionCategory.SongSelect), new GlobalKeyBindingsSubsection(InputSettingsStrings.InGameSection, GlobalActionCategory.InGame), + new GlobalKeyBindingsSubsection(InputSettingsStrings.MultiplayerSection, GlobalActionCategory.Multiplayer), new GlobalKeyBindingsSubsection(InputSettingsStrings.ReplaySection, GlobalActionCategory.Replay), new GlobalKeyBindingsSubsection(InputSettingsStrings.EditorSection, GlobalActionCategory.Editor), new GlobalKeyBindingsSubsection(InputSettingsStrings.EditorTestPlaySection, GlobalActionCategory.EditorTestPlay), diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MatchStartControl.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MatchStartControl.cs index 0d90d44496fd..c812dbd1a700 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MatchStartControl.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MatchStartControl.cs @@ -11,7 +11,10 @@ using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Input.Bindings; +using osu.Framework.Input.Events; using osu.Framework.Threading; +using osu.Game.Input.Bindings; using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer.Countdown; using osu.Game.Online.Rooms; @@ -21,7 +24,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match { - public partial class MatchStartControl : CompositeDrawable + public partial class MatchStartControl : CompositeDrawable, IKeyBindingHandler { public required Bindable SelectedItem { @@ -251,6 +254,28 @@ private void updateState() }); } + public bool OnPressed(KeyBindingPressEvent e) + { + if (!readyButton.Enabled.Value) + { + return false; + } + + switch (e.Action) + { + case GlobalAction.MultiplayerReady: + onReadyButtonClick(); + return true; + + default: + return false; + } + } + + public void OnReleased(KeyBindingReleaseEvent e) + { + } + protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerSpectateButton.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerSpectateButton.cs index 3186cf89a432..5f7ced4ed3d1 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerSpectateButton.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerSpectateButton.cs @@ -8,18 +8,21 @@ using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Input.Bindings; +using osu.Framework.Input.Events; using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.UserInterfaceV2; +using osu.Game.Input.Bindings; using osu.Game.Online.Multiplayer; using osu.Game.Online.Rooms; using osuTK; namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match { - public partial class MultiplayerSpectateButton : CompositeDrawable + public partial class MultiplayerSpectateButton : CompositeDrawable, IKeyBindingHandler { public required Bindable SelectedItem { @@ -104,6 +107,28 @@ private void updateState() Scheduler.AddOnce(checkForAutomaticDownload); } + public bool OnPressed(KeyBindingPressEvent e) + { + if (operationInProgress.Value) + { + return false; + } + + switch (e.Action) + { + case GlobalAction.MultiplayerSpectate: + onClick(); + return true; + + default: + return false; + } + } + + public void OnReleased(KeyBindingReleaseEvent e) + { + } + #region Automatic download handling [Resolved] From e56aac170dca1d1d35514fb897292567b0259a70 Mon Sep 17 00:00:00 2001 From: orwenn22 <46846090+orwenn22@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:11:17 +0100 Subject: [PATCH 2/2] Improve keybindings handling in multiplayer room --- .../Screens/OnlinePlay/Multiplayer/Match/MatchStartControl.cs | 4 ++-- .../OnlinePlay/Multiplayer/Match/MultiplayerSpectateButton.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MatchStartControl.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MatchStartControl.cs index c812dbd1a700..203321522bb3 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MatchStartControl.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MatchStartControl.cs @@ -256,7 +256,7 @@ private void updateState() public bool OnPressed(KeyBindingPressEvent e) { - if (!readyButton.Enabled.Value) + if (e.Repeat) { return false; } @@ -264,7 +264,7 @@ public bool OnPressed(KeyBindingPressEvent e) switch (e.Action) { case GlobalAction.MultiplayerReady: - onReadyButtonClick(); + readyButton.TriggerClick(); return true; default: diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerSpectateButton.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerSpectateButton.cs index 5f7ced4ed3d1..ae6ae01d8688 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerSpectateButton.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerSpectateButton.cs @@ -109,7 +109,7 @@ private void updateState() public bool OnPressed(KeyBindingPressEvent e) { - if (operationInProgress.Value) + if (e.Repeat) { return false; } @@ -117,7 +117,7 @@ public bool OnPressed(KeyBindingPressEvent e) switch (e.Action) { case GlobalAction.MultiplayerSpectate: - onClick(); + button.TriggerClick(); return true; default: