diff --git a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs index 0ba3dc9b9a..aab6ed6d74 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs @@ -18,7 +18,6 @@ using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Framework.Localisation; -using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; @@ -37,7 +36,11 @@ namespace osu.Game.Overlays.Settings.Sections.Input /// /// Invoked when the binding of this row is updated with a change being written. /// - public Action? BindingUpdated { get; set; } + public KeyBindingUpdated? BindingUpdated { get; set; } + + public delegate void KeyBindingUpdated(KeyBindingRow sender, KeyBindingUpdatedEventArgs args); + + public record KeyBindingUpdatedEventArgs(Guid KeyBindingID, string KeyCombinationString); /// /// Whether left and right mouse button clicks should be included in the edited bindings. @@ -81,9 +84,6 @@ namespace osu.Game.Overlays.Settings.Sections.Input [Resolved] private ReadableKeyCombinationProvider keyCombinationProvider { get; set; } = null!; - [Resolved] - private RealmAccess realm { get; set; } = null!; - private Container content = null!; private OsuSpriteText text = null!; @@ -220,8 +220,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input { var button = buttons[i++]; button.UpdateKeyCombination(d); - - updateStoreFromButton(button); + finalise(); } isDefault.Value = true; @@ -437,17 +436,16 @@ namespace osu.Game.Overlays.Settings.Sections.Input { if (bindTarget != null) { - updateStoreFromButton(bindTarget); - updateIsDefaultValue(); bindTarget.IsBinding = false; + var args = new KeyBindingUpdatedEventArgs(bindTarget.KeyBinding.Value.ID, bindTarget.KeyBinding.Value.KeyCombinationString); Schedule(() => { // schedule to ensure we don't instantly get focus back on next OnMouseClick (see AcceptFocus impl.) bindTarget = null; if (hasChanged) - BindingUpdated?.Invoke(this); + BindingUpdated?.Invoke(this, args); }); } @@ -486,9 +484,6 @@ namespace osu.Game.Overlays.Settings.Sections.Input if (bindTarget != null) bindTarget.IsBinding = true; } - private void updateStoreFromButton(KeyButton button) => - realm.WriteAsync(r => r.Find(button.KeyBinding.Value.ID)!.KeyCombinationString = button.KeyBinding.Value.KeyCombinationString); - private void updateIsDefaultValue() { isDefault.Value = KeyBindings.Select(b => b.KeyCombination).SequenceEqual(Defaults); diff --git a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingsSubsection.cs b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingsSubsection.cs index f7e36e0dd2..57f6e58058 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingsSubsection.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingsSubsection.cs @@ -27,13 +27,16 @@ namespace osu.Game.Overlays.Settings.Sections.Input protected IEnumerable Defaults { get; init; } = Array.Empty(); + [Resolved] + private RealmAccess realm { get; set; } = null!; + protected KeyBindingsSubsection() { FlowContent.Spacing = new Vector2(0, 3); } [BackgroundDependencyLoader] - private void load(RealmAccess realm) + private void load() { var bindings = realm.Run(r => GetKeyBindings(r).Detach()); @@ -63,8 +66,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input Defaults = defaults.Select(d => d.KeyCombination), }; - private void onBindingUpdated(KeyBindingRow sender) + private void onBindingUpdated(KeyBindingRow sender, KeyBindingRow.KeyBindingUpdatedEventArgs args) { + realm.WriteAsync(r => r.Find(args.KeyBindingID)!.KeyCombinationString = args.KeyCombinationString); + if (AutoAdvanceTarget) { var next = Children.SkipWhile(c => c != sender).Skip(1).FirstOrDefault();