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

Use a realm subscription to avoid overhead when hovering a toolbar button

Addresses https://github.com/ppy/osu/discussions/26018.
This commit is contained in:
Dean Herbert 2023-12-24 03:20:42 +09:00
parent d72ec81684
commit 5b03dc8d0b
No known key found for this signature in database

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 OnClick(ClickEvent e)
@ -168,8 +177,6 @@ namespace osu.Game.Overlays.Toolbar
protected override bool OnHover(HoverEvent e)
{
updateKeyBindingTooltip();
HoverBackground.FadeIn(200);
tooltipContainer.FadeIn(100);
@ -197,21 +204,14 @@ namespace osu.Game.Overlays.Toolbar
{
}
private void updateKeyBindingTooltip()
private void updateKeyBindingTooltip(string keyCombination)
{
if (Hotkey == null) return;
var realmKeyBinding = realm.Realm.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetName == null && rkb.ActionInt == (int)Hotkey.Value);
if (realmKeyBinding != null)
{
string keyBindingString = keyCombinationProvider.GetReadableString(realmKeyBinding.KeyCombination);
string keyBindingString = keyCombinationProvider.GetReadableString(keyCombination);
if (!string.IsNullOrEmpty(keyBindingString))
keyBindingTooltip.Text = $" ({keyBindingString})";
}
}
}
public partial class OpaqueBackground : Container
{