Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 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,13 @@ 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})";
}
keyBindingTooltip.Text = !string.IsNullOrEmpty(keyBindingString)
? $" ({keyBindingString})"
: string.Empty;
}
}

Expand Down
Loading