1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:52:55 +08:00

Fix code quality issues and avoid updating bindable twice per operation

This commit is contained in:
Dean Herbert 2023-04-08 10:40:36 +09:00
parent c827c2810b
commit f72dd86b42

View File

@ -15,7 +15,6 @@ using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osuTK;
using osuTK.Graphics;
using Key = osuTK.Input.Key;
namespace osu.Game.Screens.Edit.Compose.Components
@ -28,8 +27,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
private SpriteIcon icon;
private const float snapStep = 15;
private float rawCumulativeRotation = 0;
private const float snap_step = 15;
private readonly Bindable<float?> cumulativeRotation = new Bindable<float?>();
[Resolved]
@ -66,6 +65,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
icon.FadeColour(!IsHeld && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint);
}
private float rawCumulativeRotation;
protected override bool OnDragStart(DragStartEvent e)
{
bool handle = base.OnDragStart(e);
@ -125,17 +126,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
float oldRotation = cumulativeRotation.Value ?? 0;
if (shouldSnap)
{
cumulativeRotation.Value = snap(rawCumulativeRotation, snapStep);
}
else
{
cumulativeRotation.Value = rawCumulativeRotation;
}
cumulativeRotation.Value = (cumulativeRotation.Value - 180) % 360 + 180;
float newRotation = shouldSnap ? snap(rawCumulativeRotation, snap_step) : rawCumulativeRotation;
newRotation = (newRotation - 180) % 360 + 180;
cumulativeRotation.Value = newRotation;
HandleRotate?.Invoke((float)cumulativeRotation.Value - oldRotation);
}