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

Fix SelectionBox buttons freezing when button is triggered via key event #30206

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 16 additions & 4 deletions osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,25 @@ protected override bool OnKeyDown(KeyDownEvent e)
switch (e.Key)
{
case Key.G:
return CanReverse && reverseButton?.TriggerClick() == true;
if (!CanReverse || reverseButton == null)
return false;

reverseButton.TriggerAction();
return true;

case Key.Comma:
return canRotate.Value && rotateCounterClockwiseButton?.TriggerClick() == true;
if (!canRotate.Value || rotateCounterClockwiseButton == null)
return false;

rotateCounterClockwiseButton.TriggerAction();
return true;

case Key.Period:
return canRotate.Value && rotateClockwiseButton?.TriggerClick() == true;
if (!canRotate.Value || rotateClockwiseButton == null)
return false;

rotateClockwiseButton.TriggerAction();
return true;
}

return base.OnKeyDown(e);
Expand Down Expand Up @@ -285,7 +297,7 @@ private SelectionBoxButton addButton(IconUsage icon, string tooltip, Action acti
Action = action
};

button.OperationStarted += freezeButtonPosition;
button.Clicked += freezeButtonPosition;
button.HoverLost += unfreezeButtonPosition;

button.OperationStarted += operationStarted;
Expand Down
18 changes: 14 additions & 4 deletions osu.Game/Screens/Edit/Compose/Components/SelectionBoxButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public sealed partial class SelectionBoxButton : SelectionBoxControl, IHasToolti

public Action? Action;

public event Action? Clicked;

public event Action? HoverLost;

public SelectionBoxButton(IconUsage iconUsage, string tooltip)
Expand Down Expand Up @@ -49,11 +51,10 @@ private void load()

protected override bool OnClick(ClickEvent e)
{
Circle.FlashColour(Colours.GrayF, 300);
Clicked?.Invoke();

TriggerAction();

TriggerOperationStarted();
Action?.Invoke();
TriggerOperationEnded();
return true;
}

Expand All @@ -71,5 +72,14 @@ protected override void OnHoverLost(HoverLostEvent e)
}

public LocalisableString TooltipText { get; }

public void TriggerAction()
{
Circle.FlashColour(Colours.GrayF, 300);

TriggerOperationStarted();
Action?.Invoke();
TriggerOperationEnded();
}
}
}
Loading