1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

Merge pull request #26086 from peppy/fix-toolbar-button-lag

Use a realm subscription to avoid overhead when hovering a toolbar button
This commit is contained in:
Dean Herbert 2023-12-24 04:01:04 +09:00 committed by GitHub
commit ee00f7ea1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -157,6 +157,15 @@ namespace osu.Game.Overlays.Toolbar
}; };
} }
[BackgroundDependencyLoader]
private void load()
{
if (Hotkey != null)
{
realm.SubscribeToPropertyChanged(r => r.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetName == null && rkb.ActionInt == (int)Hotkey.Value), kb => kb.KeyCombinationString, updateKeyBindingTooltip);
}
}
protected override bool OnMouseDown(MouseDownEvent e) => false; protected override bool OnMouseDown(MouseDownEvent e) => false;
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
@ -168,8 +177,6 @@ namespace osu.Game.Overlays.Toolbar
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
updateKeyBindingTooltip();
HoverBackground.FadeIn(200); HoverBackground.FadeIn(200);
tooltipContainer.FadeIn(100); tooltipContainer.FadeIn(100);
@ -197,19 +204,13 @@ namespace osu.Game.Overlays.Toolbar
{ {
} }
private void updateKeyBindingTooltip() private void updateKeyBindingTooltip(string keyCombination)
{ {
if (Hotkey == null) return; string keyBindingString = keyCombinationProvider.GetReadableString(keyCombination);
var realmKeyBinding = realm.Realm.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetName == null && rkb.ActionInt == (int)Hotkey.Value); keyBindingTooltip.Text = !string.IsNullOrEmpty(keyBindingString)
? $" ({keyBindingString})"
if (realmKeyBinding != null) : string.Empty;
{
string keyBindingString = keyCombinationProvider.GetReadableString(realmKeyBinding.KeyCombination);
if (!string.IsNullOrEmpty(keyBindingString))
keyBindingTooltip.Text = $" ({keyBindingString})";
}
} }
} }