Change to use ReadableKeyCombinationProvider

Changes all usages of `KeyCombination.ReadableString()` to
`ReadableKeyCombinationProvider.GetReadableString()`.

Subscribing to `KeymapChanged` is only required in `KeyButton`.
All other places query `GetReadableString()` every time.
This commit is contained in:
Susko3
2021-11-08 06:55:26 +01:00
parent f776ff3d8c
commit c3069ad002
5 changed files with 43 additions and 9 deletions

View File

@ -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 readableKeyCombinationProvider { get; set; }
private OsuSpriteText text;
private FillFlowContainer cancelAndClearButtons;
private FillFlowContainer<KeyButton> buttons;
private Bindable<bool> isDefault { get; } = new BindableBool(true);
public IEnumerable<string> FilterTerms => bindings.Select(b => b.KeyCombination.ReadableString()).Prepend(text.Text.ToString());
public IEnumerable<string> FilterTerms => bindings.Select(b => readableKeyCombinationProvider.GetReadableString(b.KeyCombination)).Prepend(text.Text.ToString());
public KeyBindingRow(object action, List<RealmKeyBinding> bindings)
{
@ -422,6 +426,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
[Resolved]
private ReadableKeyCombinationProvider readableKeyCombinationProvider { 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();
readableKeyCombinationProvider.KeymapChanged += updateKeyCombinationText;
updateKeyCombinationText();
}
[BackgroundDependencyLoader]
private void load()
{
@ -508,13 +522,25 @@ namespace osu.Game.Overlays.Settings.Sections.Input
}
}
private void updateKeyCombinationText()
{
Text.Text = readableKeyCombinationProvider.GetReadableString(KeyBinding.KeyCombination);
}
public void UpdateKeyCombination(KeyCombination newCombination)
{
if (KeyBinding.RulesetID != null && !RealmKeyBindingStore.CheckValidForGameplay(newCombination))
return;
KeyBinding.KeyCombination = newCombination;
Text.Text = KeyBinding.KeyCombination.ReadableString();
updateKeyCombinationText();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
readableKeyCombinationProvider.KeymapChanged -= updateKeyCombinationText;
}
}
}