From 9e90f80ab533e538cefdb6fb08bf6d5e811ffe60 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 9 Apr 2025 15:23:55 +0900 Subject: [PATCH] Move key binding string retrieval to `RealmKeyBindingStore` --- osu.Game/Configuration/OsuConfigManager.cs | 11 +++-------- osu.Game/Input/RealmKeyBindingStore.cs | 15 +++++++++++++++ osu.Game/OsuGameBase.cs | 12 ++---------- osu.Game/Overlays/Music/MusicKeyBindingHandler.cs | 6 +++--- osu.Game/Overlays/OSD/SpeedChangeToast.cs | 6 +++--- .../Rulesets/Edit/ComposerDistanceSnapProvider.cs | 6 +++--- .../OnlinePlay/Multiplayer/GameplayChatDisplay.cs | 10 +++++----- osu.Game/Screens/Play/HUDOverlay.cs | 5 +++-- osu.Game/Screens/Select/ModSpeedHotkeyHandler.cs | 7 ++++--- 9 files changed, 41 insertions(+), 37 deletions(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index d464c97621..0399f50ded 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -34,11 +34,6 @@ namespace osu.Game.Configuration Migrate(); } - /// - /// For a given , return a human-readable string representing the bindings bound to the action. - /// - public LocalisableString LookupKeyBindings(GlobalAction action) => LookupKeyBindingsFunc(action); - protected override void InitialiseDefaults() { // UI/selection defaults @@ -308,7 +303,7 @@ namespace osu.Game.Configuration string skinName = string.Empty; if (Guid.TryParse(skin, out var id)) - skinName = LookupSkinNameFunc(id); + skinName = LookupSkinName(id); return new SettingDescription( rawValue: skinName, @@ -329,8 +324,8 @@ namespace osu.Game.Configuration }; } - public Func LookupSkinNameFunc { private get; set; } = _ => @"unknown"; - public Func LookupKeyBindingsFunc { private get; set; } = _ => @"unknown"; + public Func LookupSkinName { private get; set; } = _ => @"unknown"; + public Func LookupKeyBindings { private get; set; } = _ => @"unknown"; IBindable IGameplaySettings.ComboColourNormalisationAmount => GetOriginalBindable(OsuSetting.ComboColourNormalisationAmount); IBindable IGameplaySettings.PositionalHitsoundsLevel => GetOriginalBindable(OsuSetting.PositionalHitsoundsLevel); diff --git a/osu.Game/Input/RealmKeyBindingStore.cs b/osu.Game/Input/RealmKeyBindingStore.cs index 48ace58235..7209d3851b 100644 --- a/osu.Game/Input/RealmKeyBindingStore.cs +++ b/osu.Game/Input/RealmKeyBindingStore.cs @@ -5,8 +5,10 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Input; using osu.Framework.Input.Bindings; +using osu.Framework.Localisation; using osu.Game.Database; using osu.Game.Input.Bindings; +using osu.Game.Localisation; using osu.Game.Rulesets; using Realms; @@ -23,6 +25,19 @@ namespace osu.Game.Input this.keyCombinationProvider = keyCombinationProvider; } + /// + /// For a given , return a human-readable string representing the bindings bound to the action. + /// + public LocalisableString GetBindingsStringFor(GlobalAction globalAction) + { + var combinations = GetReadableKeyCombinationsFor(globalAction); + + if (combinations.Count == 0) + return ToastStrings.NoKeyBound; + + return string.Join(" / ", combinations); + } + /// /// Retrieve all user-defined key combinations (in a format that can be displayed) for a specific action. /// diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 28a02e0dc2..3eaabd9d2a 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -424,16 +424,8 @@ namespace osu.Game // make config aware of how to lookup skins for on-screen display purposes. // if this becomes a more common thing, tracked settings should be reconsidered to allow local DI. - LocalConfig.LookupSkinNameFunc = id => SkinManager.Query(s => s.ID == id)?.ToString() ?? "Unknown"; - LocalConfig.LookupKeyBindingsFunc = l => - { - var combinations = KeyBindingStore.GetReadableKeyCombinationsFor(l); - - if (combinations.Count == 0) - return ToastStrings.NoKeyBound; - - return string.Join(" / ", combinations); - }; + LocalConfig.LookupSkinName = id => SkinManager.Query(s => s.ID == id)?.ToString() ?? "Unknown"; + LocalConfig.LookupKeyBindings = l => KeyBindingStore.GetBindingsStringFor(l); } private void updateLanguage() => CurrentLanguage.Value = LanguageExtensions.GetLanguageFor(frameworkLocale.Value, localisationParameters.Value); diff --git a/osu.Game/Overlays/Music/MusicKeyBindingHandler.cs b/osu.Game/Overlays/Music/MusicKeyBindingHandler.cs index 78de76b981..8cec85b748 100644 --- a/osu.Game/Overlays/Music/MusicKeyBindingHandler.cs +++ b/osu.Game/Overlays/Music/MusicKeyBindingHandler.cs @@ -9,7 +9,7 @@ using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Game.Beatmaps; -using osu.Game.Configuration; +using osu.Game.Input; using osu.Game.Input.Bindings; using osu.Game.Localisation; using osu.Game.Overlays.OSD; @@ -92,9 +92,9 @@ namespace osu.Game.Overlays.Music } [BackgroundDependencyLoader] - private void load(OsuConfigManager config) + private void load(RealmKeyBindingStore keyBindingStore) { - ShortcutText.Text = config.LookupKeyBindings(action).ToUpper(); + ShortcutText.Text = keyBindingStore.GetBindingsStringFor(action).ToUpper(); } } } diff --git a/osu.Game/Overlays/OSD/SpeedChangeToast.cs b/osu.Game/Overlays/OSD/SpeedChangeToast.cs index 49d3985b04..652c043357 100644 --- a/osu.Game/Overlays/OSD/SpeedChangeToast.cs +++ b/osu.Game/Overlays/OSD/SpeedChangeToast.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Game.Configuration; +using osu.Game.Input; using osu.Game.Input.Bindings; using osu.Game.Localisation; @@ -9,8 +9,8 @@ namespace osu.Game.Overlays.OSD { public partial class SpeedChangeToast : Toast { - public SpeedChangeToast(OsuConfigManager config, double newSpeed) - : base(ModSelectOverlayStrings.ModCustomisation, ToastStrings.SpeedChangedTo(newSpeed), config.LookupKeyBindings(GlobalAction.IncreaseModSpeed) + " / " + config.LookupKeyBindings(GlobalAction.DecreaseModSpeed)) + public SpeedChangeToast(RealmKeyBindingStore keyBindingStore, double newSpeed) + : base(ModSelectOverlayStrings.ModCustomisation, ToastStrings.SpeedChangedTo(newSpeed), keyBindingStore.GetBindingsStringFor(GlobalAction.IncreaseModSpeed) + " / " + keyBindingStore.GetBindingsStringFor(GlobalAction.DecreaseModSpeed)) { } } diff --git a/osu.Game/Rulesets/Edit/ComposerDistanceSnapProvider.cs b/osu.Game/Rulesets/Edit/ComposerDistanceSnapProvider.cs index 4129a6fb2c..2d6e09b3fd 100644 --- a/osu.Game/Rulesets/Edit/ComposerDistanceSnapProvider.cs +++ b/osu.Game/Rulesets/Edit/ComposerDistanceSnapProvider.cs @@ -14,9 +14,9 @@ using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Framework.Utils; -using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; +using osu.Game.Input; using osu.Game.Input.Bindings; using osu.Game.Overlays; using osu.Game.Overlays.OSD; @@ -312,9 +312,9 @@ namespace osu.Game.Rulesets.Edit } [BackgroundDependencyLoader] - private void load(OsuConfigManager config) + private void load(RealmKeyBindingStore keyBindingStore) { - ShortcutText.Text = config.LookupKeyBindings(getAction(change)).ToUpper(); + ShortcutText.Text = keyBindingStore.GetBindingsStringFor(getAction(change)).ToUpper(); } private static GlobalAction getAction(ValueChangedEvent change) => change.NewValue - change.OldValue > 0 diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/GameplayChatDisplay.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/GameplayChatDisplay.cs index 7b9a4d34ca..65f667b929 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/GameplayChatDisplay.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/GameplayChatDisplay.cs @@ -6,10 +6,10 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; -using osu.Game.Configuration; +using osu.Game.Input; using osu.Game.Input.Bindings; -using osu.Game.Localisation; using osu.Game.Online.Rooms; +using osu.Game.Resources.Localisation.Web; using osu.Game.Screens.OnlinePlay.Match.Components; using osu.Game.Screens.Play; @@ -42,17 +42,17 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer } [BackgroundDependencyLoader] - private void load(OsuConfigManager config) + private void load(RealmKeyBindingStore keyBindingStore) { resetPlaceholderText(); - TextBox.Focus = () => TextBox.PlaceholderText = Resources.Localisation.Web.ChatStrings.InputPlaceholder; + TextBox.Focus = () => TextBox.PlaceholderText = ChatStrings.InputPlaceholder; TextBox.FocusLost = () => { resetPlaceholderText(); expandedFromTextBoxFocus.Value = false; }; - void resetPlaceholderText() => TextBox.PlaceholderText = ChatStrings.InGameInputPlaceholder(config.LookupKeyBindings(GlobalAction.ToggleChatFocus)); + void resetPlaceholderText() => TextBox.PlaceholderText = Localisation.ChatStrings.InGameInputPlaceholder(keyBindingStore.GetBindingsStringFor(GlobalAction.ToggleChatFocus)); } protected override bool OnHover(HoverEvent e) => true; // use UI mouse cursor. diff --git a/osu.Game/Screens/Play/HUDOverlay.cs b/osu.Game/Screens/Play/HUDOverlay.cs index 75a28a4240..733675dfb1 100644 --- a/osu.Game/Screens/Play/HUDOverlay.cs +++ b/osu.Game/Screens/Play/HUDOverlay.cs @@ -14,6 +14,7 @@ using osu.Framework.Graphics.Primitives; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Game.Configuration; +using osu.Game.Input; using osu.Game.Input.Bindings; using osu.Game.Localisation; using osu.Game.Overlays; @@ -195,7 +196,7 @@ namespace osu.Game.Screens.Play } [BackgroundDependencyLoader(true)] - private void load(OsuConfigManager config, INotificationOverlay notificationOverlay) + private void load(OsuConfigManager config, RealmKeyBindingStore keyBindingStore, INotificationOverlay notificationOverlay) { if (drawableRuleset != null) { @@ -214,7 +215,7 @@ namespace osu.Game.Screens.Play notificationOverlay?.Post(new SimpleNotification { - Text = NotificationsStrings.ScoreOverlayDisabled(config.LookupKeyBindings(GlobalAction.ToggleInGameInterface)) + Text = NotificationsStrings.ScoreOverlayDisabled(keyBindingStore.GetBindingsStringFor(GlobalAction.ToggleInGameInterface)) }); } diff --git a/osu.Game/Screens/Select/ModSpeedHotkeyHandler.cs b/osu.Game/Screens/Select/ModSpeedHotkeyHandler.cs index c4cd44705e..998f94849c 100644 --- a/osu.Game/Screens/Select/ModSpeedHotkeyHandler.cs +++ b/osu.Game/Screens/Select/ModSpeedHotkeyHandler.cs @@ -8,6 +8,7 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Utils; using osu.Game.Configuration; +using osu.Game.Input; using osu.Game.Overlays; using osu.Game.Overlays.OSD; using osu.Game.Rulesets.Mods; @@ -21,7 +22,7 @@ namespace osu.Game.Screens.Select private Bindable> selectedMods { get; set; } = null!; [Resolved] - private OsuConfigManager config { get; set; } = null!; + private RealmKeyBindingStore keyBindingStore { get; set; } = null!; [Resolved] private OnScreenDisplay? onScreenDisplay { get; set; } @@ -55,7 +56,7 @@ namespace osu.Game.Screens.Select if (Precision.AlmostEquals(targetSpeed, 1, 0.005)) { selectedMods.Value = selectedMods.Value.Where(m => m is not ModRateAdjust).ToList(); - onScreenDisplay?.Display(new SpeedChangeToast(config, targetSpeed)); + onScreenDisplay?.Display(new SpeedChangeToast(keyBindingStore, targetSpeed)); return true; } @@ -108,7 +109,7 @@ namespace osu.Game.Screens.Select return false; selectedMods.Value = intendedMods; - onScreenDisplay?.Display(new SpeedChangeToast(config, targetMod.SpeedChange.Value)); + onScreenDisplay?.Display(new SpeedChangeToast(keyBindingStore, targetMod.SpeedChange.Value)); return true; } }