diff --git a/osu.Android.props b/osu.Android.props index 4f9f83f199..752eb160ed 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -52,7 +52,7 @@ - + diff --git a/osu.Game.Tests/Database/TestRealmKeyBindingStore.cs b/osu.Game.Tests/Database/TestRealmKeyBindingStore.cs index f10b11733e..860828ae81 100644 --- a/osu.Game.Tests/Database/TestRealmKeyBindingStore.cs +++ b/osu.Game.Tests/Database/TestRealmKeyBindingStore.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using NUnit.Framework; +using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Platform; using osu.Game.Database; @@ -33,7 +34,7 @@ namespace osu.Game.Tests.Database storage = new NativeStorage(directory.FullName); realmContextFactory = new RealmContextFactory(storage, "test"); - keyBindingStore = new RealmKeyBindingStore(realmContextFactory); + keyBindingStore = new RealmKeyBindingStore(realmContextFactory, new ReadableKeyCombinationProvider()); } [Test] diff --git a/osu.Game/Input/RealmKeyBindingStore.cs b/osu.Game/Input/RealmKeyBindingStore.cs index c65e36e478..046969579c 100644 --- a/osu.Game/Input/RealmKeyBindingStore.cs +++ b/osu.Game/Input/RealmKeyBindingStore.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; +using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Game.Database; using osu.Game.Input.Bindings; @@ -16,10 +17,12 @@ namespace osu.Game.Input public class RealmKeyBindingStore { private readonly RealmContextFactory realmFactory; + private readonly ReadableKeyCombinationProvider keyCombinationProvider; - public RealmKeyBindingStore(RealmContextFactory realmFactory) + public RealmKeyBindingStore(RealmContextFactory realmFactory, ReadableKeyCombinationProvider keyCombinationProvider) { this.realmFactory = realmFactory; + this.keyCombinationProvider = keyCombinationProvider; } /// @@ -35,7 +38,7 @@ namespace osu.Game.Input { foreach (var action in context.All().Where(b => b.RulesetID == null && (GlobalAction)b.ActionInt == globalAction)) { - string str = action.KeyCombination.ReadableString(); + string str = keyCombinationProvider.GetReadableString(action.KeyCombination); // even if found, the readable string may be empty for an unbound action. if (str.Length > 0) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 7911e843d1..10166daf00 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -170,7 +170,7 @@ namespace osu.Game } [BackgroundDependencyLoader] - private void load() + private void load(ReadableKeyCombinationProvider keyCombinationProvider) { try { @@ -309,7 +309,7 @@ namespace osu.Game base.Content.Add(CreateScalingContainer().WithChildren(mainContent)); - KeyBindingStore = new RealmKeyBindingStore(realmFactory); + KeyBindingStore = new RealmKeyBindingStore(realmFactory, keyCombinationProvider); KeyBindingStore.Register(globalBindings, RulesetStore.AvailableRulesets); dependencies.Cache(globalBindings); diff --git a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs index f44f02d0ed..e6472dffeb 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs @@ -12,6 +12,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; +using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Game.Database; @@ -57,13 +58,16 @@ namespace osu.Game.Overlays.Settings.Sections.Input public bool FilteringActive { get; set; } + [Resolved] + private ReadableKeyCombinationProvider keyCombinationProvider { get; set; } + private OsuSpriteText text; private FillFlowContainer cancelAndClearButtons; private FillFlowContainer buttons; private Bindable isDefault { get; } = new BindableBool(true); - public IEnumerable FilterTerms => bindings.Select(b => b.KeyCombination.ReadableString()).Prepend(text.Text.ToString()); + public IEnumerable FilterTerms => bindings.Select(b => keyCombinationProvider.GetReadableString(b.KeyCombination)).Prepend(text.Text.ToString()); public KeyBindingRow(object action, List bindings) { @@ -422,6 +426,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input [Resolved] private OverlayColourProvider colourProvider { get; set; } + [Resolved] + private ReadableKeyCombinationProvider keyCombinationProvider { get; set; } + private bool isBinding; public bool IsBinding @@ -470,12 +477,19 @@ namespace osu.Game.Overlays.Settings.Sections.Input Margin = new MarginPadding(5), Anchor = Anchor.Centre, Origin = Anchor.Centre, - Text = keyBinding.KeyCombination.ReadableString(), }, new HoverSounds() }; } + protected override void LoadComplete() + { + base.LoadComplete(); + + keyCombinationProvider.KeymapChanged += updateKeyCombinationText; + updateKeyCombinationText(); + } + [BackgroundDependencyLoader] private void load() { @@ -514,7 +528,22 @@ namespace osu.Game.Overlays.Settings.Sections.Input return; KeyBinding.KeyCombination = newCombination; - Text.Text = KeyBinding.KeyCombination.ReadableString(); + updateKeyCombinationText(); + } + + private void updateKeyCombinationText() + { + Scheduler.AddOnce(updateText); + + void updateText() => Text.Text = keyCombinationProvider.GetReadableString(KeyBinding.KeyCombination); + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + if (keyCombinationProvider != null) + keyCombinationProvider.KeymapChanged -= updateKeyCombinationText; } } } diff --git a/osu.Game/Overlays/Toolbar/ToolbarButton.cs b/osu.Game/Overlays/Toolbar/ToolbarButton.cs index ab37b3b355..b2252a5575 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarButton.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarButton.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; +using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Game.Database; @@ -39,6 +40,9 @@ namespace osu.Game.Overlays.Toolbar [Resolved] private TextureStore textures { get; set; } + [Resolved] + private ReadableKeyCombinationProvider keyCombinationProvider { get; set; } + public void SetIcon(string texture) => SetIcon(new Sprite { @@ -207,7 +211,7 @@ namespace osu.Game.Overlays.Toolbar if (realmKeyBinding != null) { - string keyBindingString = realmKeyBinding.KeyCombination.ReadableString(); + string keyBindingString = keyCombinationProvider.GetReadableString(realmKeyBinding.KeyCombination); if (!string.IsNullOrEmpty(keyBindingString)) keyBindingTooltip.Text = $" ({keyBindingString})"; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 7811de5764..df3c9b355a 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -36,7 +36,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/osu.iOS.props b/osu.iOS.props index 9d95b7c765..1852957e87 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -70,7 +70,7 @@ - + @@ -93,7 +93,7 @@ - +