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

@ -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 readableKeyCombinationProvider;
public RealmKeyBindingStore(RealmContextFactory realmFactory)
public RealmKeyBindingStore(RealmContextFactory realmFactory, ReadableKeyCombinationProvider readableKeyCombinationProvider)
{
this.realmFactory = realmFactory;
this.readableKeyCombinationProvider = readableKeyCombinationProvider;
}
/// <summary>
@ -35,7 +38,7 @@ namespace osu.Game.Input
{
foreach (var action in context.All<RealmKeyBinding>().Where(b => b.RulesetID == null && (GlobalAction)b.ActionInt == globalAction))
{
string str = action.KeyCombination.ReadableString();
string str = readableKeyCombinationProvider.GetReadableString(action.KeyCombination);
// even if found, the readable string may be empty for an unbound action.
if (str.Length > 0)