mirror of
https://github.com/ppy/osu.git
synced 2025-03-22 21:00:33 +08:00
Hoist database update to subsection level
The end goal here is to be able to better coordinate deconfliction of bindings at the subsection level rather than try to jam that logic into individual rows somehow. The flipside is that this is going to require a flow to update the individual rows after the subsection's intervention, but that's what the previous commit was for.
This commit is contained in:
parent
5f0b1d69a5
commit
aa8dbd742e
@ -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
|
||||
/// <summary>
|
||||
/// Invoked when the binding of this row is updated with a change being written.
|
||||
/// </summary>
|
||||
public Action<KeyBindingRow>? BindingUpdated { get; set; }
|
||||
public KeyBindingUpdated? BindingUpdated { get; set; }
|
||||
|
||||
public delegate void KeyBindingUpdated(KeyBindingRow sender, KeyBindingUpdatedEventArgs args);
|
||||
|
||||
public record KeyBindingUpdatedEventArgs(Guid KeyBindingID, string KeyCombinationString);
|
||||
|
||||
/// <summary>
|
||||
/// 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<RealmKeyBinding>(button.KeyBinding.Value.ID)!.KeyCombinationString = button.KeyBinding.Value.KeyCombinationString);
|
||||
|
||||
private void updateIsDefaultValue()
|
||||
{
|
||||
isDefault.Value = KeyBindings.Select(b => b.KeyCombination).SequenceEqual(Defaults);
|
||||
|
@ -27,13 +27,16 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
||||
|
||||
protected IEnumerable<KeyBinding> Defaults { get; init; } = Array.Empty<KeyBinding>();
|
||||
|
||||
[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<RealmKeyBinding>(args.KeyBindingID)!.KeyCombinationString = args.KeyCombinationString);
|
||||
|
||||
if (AutoAdvanceTarget)
|
||||
{
|
||||
var next = Children.SkipWhile(c => c != sender).Skip(1).FirstOrDefault();
|
||||
|
Loading…
x
Reference in New Issue
Block a user