1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 16:13:34 +08:00

Add a visual effect when keyboard shortcuts are used to trigger selection box buttons

This commit is contained in:
Dean Herbert 2023-06-27 17:01:06 +09:00
parent 9b08aaf93f
commit 7ddbf4eaa7
3 changed files with 15 additions and 20 deletions

View File

@ -32,6 +32,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
public Action OperationStarted;
public Action OperationEnded;
private SelectionBoxButton reverseButton;
private bool canReverse;
/// <summary>
@ -166,19 +168,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (e.Repeat || !e.ControlPressed)
return false;
bool runOperationFromHotkey(Func<bool> operation)
{
operationStarted();
bool result = operation?.Invoke() ?? false;
operationEnded();
return result;
}
switch (e.Key)
{
case Key.G:
return CanReverse && runOperationFromHotkey(OnReverse);
return reverseButton?.TriggerClick() ?? false;
}
return base.OnKeyDown(e);
@ -256,7 +249,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (CanFlipX) addXFlipComponents();
if (CanFlipY) addYFlipComponents();
if (CanRotate) addRotationComponents();
if (CanReverse) addButton(FontAwesome.Solid.Backward, "Reverse pattern (Ctrl-G)", () => OnReverse?.Invoke());
if (CanReverse) reverseButton = addButton(FontAwesome.Solid.Backward, "Reverse pattern (Ctrl-G)", () => OnReverse?.Invoke());
}
private void addRotationComponents()
@ -300,7 +293,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
addButton(FontAwesome.Solid.ArrowsAltV, "Flip vertically", () => OnFlip?.Invoke(Direction.Vertical, false));
}
private void addButton(IconUsage icon, string tooltip, Action action)
private SelectionBoxButton addButton(IconUsage icon, string tooltip, Action action)
{
var button = new SelectionBoxButton(icon, tooltip)
{
@ -310,6 +303,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
button.OperationStarted += operationStarted;
button.OperationEnded += operationEnded;
buttons.Add(button);
return button;
}
private void addScaleHandle(Anchor anchor)

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
@ -17,11 +15,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
public sealed partial class SelectionBoxButton : SelectionBoxControl, IHasTooltip
{
private SpriteIcon icon;
private SpriteIcon icon = null!;
private readonly IconUsage iconUsage;
public Action Action;
public Action? Action;
public SelectionBoxButton(IconUsage iconUsage, string tooltip)
{
@ -49,6 +47,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected override bool OnClick(ClickEvent e)
{
Circle.FlashColour(Colours.GrayF, 300);
TriggerOperationStarted();
Action?.Invoke();
TriggerOperationEnded();

View File

@ -24,7 +24,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
public event Action OperationStarted;
public event Action OperationEnded;
private Circle circle;
protected Circle Circle { get; private set; }
/// <summary>
/// Whether the user is currently holding the control with mouse.
@ -41,7 +41,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
InternalChildren = new Drawable[]
{
circle = new Circle
Circle = new Circle
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
@ -85,9 +85,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected virtual void UpdateHoverState()
{
if (IsHeld)
circle.FadeColour(Colours.GrayF, TRANSFORM_DURATION, Easing.OutQuint);
Circle.FadeColour(Colours.GrayF, TRANSFORM_DURATION, Easing.OutQuint);
else
circle.FadeColour(IsHovered ? Colours.Red : Colours.YellowDark, TRANSFORM_DURATION, Easing.OutQuint);
Circle.FadeColour(IsHovered ? Colours.Red : Colours.YellowDark, TRANSFORM_DURATION, Easing.OutQuint);
this.ScaleTo(IsHeld || IsHovered ? 1.5f : 1, TRANSFORM_DURATION, Easing.OutQuint);
}