1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-24 15:42:11 +08:00

Move key binding string retrieval to RealmKeyBindingStore

This commit is contained in:
Dean Herbert
2025-04-09 15:23:55 +09:00
Unverified
parent 5fc80dbddb
commit 9e90f80ab5
9 changed files with 41 additions and 37 deletions
+3 -8
View File
@@ -34,11 +34,6 @@ namespace osu.Game.Configuration
Migrate();
}
/// <summary>
/// For a given <see cref="GlobalAction"/>, return a human-readable string representing the bindings bound to the action.
/// </summary>
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<Guid, string> LookupSkinNameFunc { private get; set; } = _ => @"unknown";
public Func<GlobalAction, LocalisableString> LookupKeyBindingsFunc { private get; set; } = _ => @"unknown";
public Func<Guid, string> LookupSkinName { private get; set; } = _ => @"unknown";
public Func<GlobalAction, LocalisableString> LookupKeyBindings { private get; set; } = _ => @"unknown";
IBindable<float> IGameplaySettings.ComboColourNormalisationAmount => GetOriginalBindable<float>(OsuSetting.ComboColourNormalisationAmount);
IBindable<float> IGameplaySettings.PositionalHitsoundsLevel => GetOriginalBindable<float>(OsuSetting.PositionalHitsoundsLevel);
+15
View File
@@ -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;
}
/// <summary>
/// For a given <see cref="GlobalAction"/>, return a human-readable string representing the bindings bound to the action.
/// </summary>
public LocalisableString GetBindingsStringFor(GlobalAction globalAction)
{
var combinations = GetReadableKeyCombinationsFor(globalAction);
if (combinations.Count == 0)
return ToastStrings.NoKeyBound;
return string.Join(" / ", combinations);
}
/// <summary>
/// Retrieve all user-defined key combinations (in a format that can be displayed) for a specific action.
/// </summary>
+2 -10
View File
@@ -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);
@@ -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();
}
}
}
+3 -3
View File
@@ -1,7 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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))
{
}
}
@@ -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<double> change) => change.NewValue - change.OldValue > 0
@@ -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.
+3 -2
View File
@@ -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))
});
}
@@ -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<IReadOnlyList<Mod>> 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;
}
}