Skip to content

Commit

Permalink
Use a realm subscription to avoid overhead when hovering a toolbar bu…
Browse files Browse the repository at this point in the history
…tton

Addresses #26018.
  • Loading branch information
peppy committed Dec 23, 2023
1 parent d72ec81 commit 5b03dc8
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions osu.Game/Overlays/Toolbar/ToolbarButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ protected ToolbarButton()
};
}

[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)
Expand All @@ -168,8 +177,6 @@ protected override bool OnClick(ClickEvent e)

protected override bool OnHover(HoverEvent e)
{
updateKeyBindingTooltip();

HoverBackground.FadeIn(200);
tooltipContainer.FadeIn(100);

Expand Down Expand Up @@ -197,19 +204,12 @@ public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}

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);
string keyBindingString = keyCombinationProvider.GetReadableString(keyCombination);

if (realmKeyBinding != null)
{
string keyBindingString = keyCombinationProvider.GetReadableString(realmKeyBinding.KeyCombination);

if (!string.IsNullOrEmpty(keyBindingString))
keyBindingTooltip.Text = $" ({keyBindingString})";
}
if (!string.IsNullOrEmpty(keyBindingString))
keyBindingTooltip.Text = $" ({keyBindingString})";
}
}

Expand Down

0 comments on commit 5b03dc8

Please sign in to comment.