mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 15:22:55 +08:00
Merge pull request #21270 from peppy/auto-advance-bindings
Auto-advance binding for ruleset key bindings
This commit is contained in:
commit
e4fc14faee
@ -33,6 +33,11 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
public class KeyBindingRow : Container, IFilterable
|
public class KeyBindingRow : Container, IFilterable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked when the binding of this row is updated with a change being written.
|
||||||
|
/// </summary>
|
||||||
|
public Action<KeyBindingRow> BindingUpdated { get; set; }
|
||||||
|
|
||||||
private readonly object action;
|
private readonly object action;
|
||||||
private readonly IEnumerable<RealmKeyBinding> bindings;
|
private readonly IEnumerable<RealmKeyBinding> bindings;
|
||||||
|
|
||||||
@ -153,7 +158,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
Spacing = new Vector2(5),
|
Spacing = new Vector2(5),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new CancelButton { Action = finalise },
|
new CancelButton { Action = () => finalise(false) },
|
||||||
new ClearButton { Action = clear },
|
new ClearButton { Action = clear },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -240,7 +245,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bindTarget.IsHovered)
|
if (bindTarget.IsHovered)
|
||||||
finalise();
|
finalise(false);
|
||||||
// prevent updating bind target before clear button's action
|
// prevent updating bind target before clear button's action
|
||||||
else if (!cancelAndClearButtons.Any(b => b.IsHovered))
|
else if (!cancelAndClearButtons.Any(b => b.IsHovered))
|
||||||
updateBindTarget();
|
updateBindTarget();
|
||||||
@ -377,10 +382,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
bindTarget.UpdateKeyCombination(InputKey.None);
|
bindTarget.UpdateKeyCombination(InputKey.None);
|
||||||
finalise();
|
finalise(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finalise()
|
private void finalise(bool hasChanged = true)
|
||||||
{
|
{
|
||||||
if (bindTarget != null)
|
if (bindTarget != null)
|
||||||
{
|
{
|
||||||
@ -393,6 +398,8 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
// schedule to ensure we don't instantly get focus back on next OnMouseClick (see AcceptFocus impl.)
|
// schedule to ensure we don't instantly get focus back on next OnMouseClick (see AcceptFocus impl.)
|
||||||
bindTarget = null;
|
bindTarget = null;
|
||||||
|
if (hasChanged)
|
||||||
|
BindingUpdated?.Invoke(this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,7 +424,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
|
|
||||||
protected override void OnFocusLost(FocusLostEvent e)
|
protected override void OnFocusLost(FocusLostEvent e)
|
||||||
{
|
{
|
||||||
finalise();
|
finalise(false);
|
||||||
base.OnFocusLost(e);
|
base.OnFocusLost(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,12 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
public abstract class KeyBindingsSubsection : SettingsSubsection
|
public abstract class KeyBindingsSubsection : SettingsSubsection
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// After a successful binding, automatically select the next binding row to make quickly
|
||||||
|
/// binding a large set of keys easier on the user.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual bool AutoAdvanceTarget => false;
|
||||||
|
|
||||||
protected IEnumerable<Framework.Input.Bindings.KeyBinding> Defaults;
|
protected IEnumerable<Framework.Input.Bindings.KeyBinding> Defaults;
|
||||||
|
|
||||||
public RulesetInfo Ruleset { get; protected set; }
|
public RulesetInfo Ruleset { get; protected set; }
|
||||||
@ -49,7 +55,8 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
Add(new KeyBindingRow(defaultGroup.Key, bindings.Where(b => b.ActionInt.Equals(intKey)).ToList())
|
Add(new KeyBindingRow(defaultGroup.Key, bindings.Where(b => b.ActionInt.Equals(intKey)).ToList())
|
||||||
{
|
{
|
||||||
AllowMainMouseButtons = Ruleset != null,
|
AllowMainMouseButtons = Ruleset != null,
|
||||||
Defaults = defaultGroup.Select(d => d.KeyCombination)
|
Defaults = defaultGroup.Select(d => d.KeyCombination),
|
||||||
|
BindingUpdated = onBindingUpdated
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +65,16 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
Action = () => Children.OfType<KeyBindingRow>().ForEach(k => k.RestoreDefaults())
|
Action = () => Children.OfType<KeyBindingRow>().ForEach(k => k.RestoreDefaults())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onBindingUpdated(KeyBindingRow sender)
|
||||||
|
{
|
||||||
|
if (AutoAdvanceTarget)
|
||||||
|
{
|
||||||
|
var next = Children.SkipWhile(c => c != sender).Skip(1).FirstOrDefault();
|
||||||
|
if (next != null)
|
||||||
|
GetContainingInputManager().ChangeFocus(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ResetButton : DangerousSettingsButton
|
public class ResetButton : DangerousSettingsButton
|
||||||
|
@ -8,6 +8,8 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
public class VariantBindingsSubsection : KeyBindingsSubsection
|
public class VariantBindingsSubsection : KeyBindingsSubsection
|
||||||
{
|
{
|
||||||
|
protected override bool AutoAdvanceTarget => true;
|
||||||
|
|
||||||
protected override LocalisableString Header { get; }
|
protected override LocalisableString Header { get; }
|
||||||
|
|
||||||
public VariantBindingsSubsection(RulesetInfo ruleset, int variant)
|
public VariantBindingsSubsection(RulesetInfo ruleset, int variant)
|
||||||
|
Loading…
Reference in New Issue
Block a user