1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 23:57:25 +08:00

Remove casting

This commit is contained in:
Dean Herbert 2018-07-06 17:45:39 +09:00
parent dffe6af5d9
commit 54db287791

View File

@ -22,7 +22,9 @@ namespace osu.Game.Graphics.Cursor
private readonly IBindable<bool> screenshotCursorVisibility = new Bindable<bool>(true); private readonly IBindable<bool> screenshotCursorVisibility = new Bindable<bool>(true);
public override bool IsPresent => screenshotCursorVisibility.Value && base.IsPresent; public override bool IsPresent => screenshotCursorVisibility.Value && base.IsPresent;
protected override Drawable CreateCursor() => new Cursor(); protected override Drawable CreateCursor() => activeCursor = new Cursor();
private Cursor activeCursor;
private Bindable<bool> cursorRotate; private Bindable<bool> cursorRotate;
private DragRotationState dragRotationState; private DragRotationState dragRotationState;
@ -54,12 +56,12 @@ namespace osu.Game.Graphics.Cursor
float degrees = (float)MathHelper.RadiansToDegrees(Math.Atan2(-offset.X, offset.Y)) + 24.3f; float degrees = (float)MathHelper.RadiansToDegrees(Math.Atan2(-offset.X, offset.Y)) + 24.3f;
// Always rotate in the direction of least distance // Always rotate in the direction of least distance
float diff = (degrees - ActiveCursor.Rotation) % 360; float diff = (degrees - activeCursor.Rotation) % 360;
if (diff < -180) diff += 360; if (diff < -180) diff += 360;
if (diff > 180) diff -= 360; if (diff > 180) diff -= 360;
degrees = ActiveCursor.Rotation + diff; degrees = activeCursor.Rotation + diff;
ActiveCursor.RotateTo(degrees, 600, Easing.OutQuint); activeCursor.RotateTo(degrees, 600, Easing.OutQuint);
} }
} }
@ -71,11 +73,11 @@ namespace osu.Game.Graphics.Cursor
// only trigger animation for main mouse buttons // only trigger animation for main mouse buttons
if (args.Button <= MouseButton.Right) if (args.Button <= MouseButton.Right)
{ {
ActiveCursor.Scale = new Vector2(1); activeCursor.Scale = new Vector2(1);
ActiveCursor.ScaleTo(0.90f, 800, Easing.OutQuint); activeCursor.ScaleTo(0.90f, 800, Easing.OutQuint);
((Cursor)ActiveCursor).AdditiveLayer.Alpha = 0; activeCursor.AdditiveLayer.Alpha = 0;
((Cursor)ActiveCursor).AdditiveLayer.FadeInFromZero(800, Easing.OutQuint); activeCursor.AdditiveLayer.FadeInFromZero(800, Easing.OutQuint);
} }
if (args.Button == MouseButton.Left && cursorRotate) if (args.Button == MouseButton.Left && cursorRotate)
@ -90,14 +92,14 @@ namespace osu.Game.Graphics.Cursor
{ {
if (!state.Mouse.HasMainButtonPressed) if (!state.Mouse.HasMainButtonPressed)
{ {
((Cursor)ActiveCursor).AdditiveLayer.FadeOutFromOne(500, Easing.OutQuint); activeCursor.AdditiveLayer.FadeOutFromOne(500, Easing.OutQuint);
ActiveCursor.ScaleTo(1, 500, Easing.OutElastic); activeCursor.ScaleTo(1, 500, Easing.OutElastic);
} }
if (args.Button == MouseButton.Left) if (args.Button == MouseButton.Left)
{ {
if (dragRotationState == DragRotationState.Rotating) if (dragRotationState == DragRotationState.Rotating)
ActiveCursor.RotateTo(0, 600 * (1 + Math.Abs(ActiveCursor.Rotation / 720)), Easing.OutElasticHalf); activeCursor.RotateTo(0, 600 * (1 + Math.Abs(activeCursor.Rotation / 720)), Easing.OutElasticHalf);
dragRotationState = DragRotationState.NotDragging; dragRotationState = DragRotationState.NotDragging;
} }
return base.OnMouseUp(state, args); return base.OnMouseUp(state, args);
@ -105,14 +107,14 @@ namespace osu.Game.Graphics.Cursor
protected override void PopIn() protected override void PopIn()
{ {
ActiveCursor.FadeTo(1, 250, Easing.OutQuint); activeCursor.FadeTo(1, 250, Easing.OutQuint);
ActiveCursor.ScaleTo(1, 400, Easing.OutQuint); activeCursor.ScaleTo(1, 400, Easing.OutQuint);
} }
protected override void PopOut() protected override void PopOut()
{ {
ActiveCursor.FadeTo(0, 250, Easing.OutQuint); activeCursor.FadeTo(0, 250, Easing.OutQuint);
ActiveCursor.ScaleTo(0.6f, 250, Easing.In); activeCursor.ScaleTo(0.6f, 250, Easing.In);
} }
public class Cursor : Container public class Cursor : Container