2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-14 17:55:54 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input;
|
2017-02-15 22:24:08 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
2017-02-14 17:55:54 +08:00
|
|
|
|
{
|
2017-08-18 15:16:00 +08:00
|
|
|
|
public class SpinnerDisc : CircularContainer, IHasAccentColour
|
2017-02-14 17:55:54 +08:00
|
|
|
|
{
|
2017-05-18 18:40:20 +08:00
|
|
|
|
private readonly Spinner spinner;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
2017-05-18 18:40:20 +08:00
|
|
|
|
public Color4 AccentColour
|
2017-02-14 17:55:54 +08:00
|
|
|
|
{
|
2017-05-18 18:40:20 +08:00
|
|
|
|
get { return background.AccentColour; }
|
|
|
|
|
set { background.AccentColour = value; }
|
2017-02-14 17:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 18:40:20 +08:00
|
|
|
|
private readonly SpinnerBackground background;
|
2017-02-15 22:24:08 +08:00
|
|
|
|
|
2017-05-18 20:38:19 +08:00
|
|
|
|
private const float idle_alpha = 0.2f;
|
|
|
|
|
private const float tracking_alpha = 0.4f;
|
2017-02-15 22:24:08 +08:00
|
|
|
|
|
2017-12-27 00:25:18 +08:00
|
|
|
|
public override bool IsPresent => true; // handle input when hidden
|
|
|
|
|
|
2017-05-18 18:40:20 +08:00
|
|
|
|
public SpinnerDisc(Spinner s)
|
2017-02-14 17:55:54 +08:00
|
|
|
|
{
|
2017-05-18 18:40:20 +08:00
|
|
|
|
spinner = s;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-18 18:40:20 +08:00
|
|
|
|
background = new SpinnerBackground { Alpha = idle_alpha },
|
2017-02-14 17:55:54 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-30 14:54:03 +08:00
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
2017-06-24 00:02:24 +08:00
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private bool tracking;
|
2017-02-14 17:55:54 +08:00
|
|
|
|
public bool Tracking
|
|
|
|
|
{
|
|
|
|
|
get { return tracking; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == tracking) return;
|
|
|
|
|
tracking = value;
|
|
|
|
|
|
2017-05-18 18:40:20 +08:00
|
|
|
|
background.FadeTo(tracking ? tracking_alpha : idle_alpha, 100);
|
2017-02-14 17:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private bool complete;
|
2017-02-15 22:24:08 +08:00
|
|
|
|
public bool Complete
|
|
|
|
|
{
|
|
|
|
|
get { return complete; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == complete) return;
|
|
|
|
|
complete = value;
|
|
|
|
|
|
|
|
|
|
updateCompleteTick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 17:55:54 +08:00
|
|
|
|
protected override bool OnMouseMove(InputState state)
|
|
|
|
|
{
|
2017-05-18 18:40:20 +08:00
|
|
|
|
mousePosition = Parent.ToLocalSpace(state.Mouse.NativeState.Position);
|
2017-02-14 17:55:54 +08:00
|
|
|
|
return base.OnMouseMove(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector2 mousePosition;
|
|
|
|
|
|
|
|
|
|
private float lastAngle;
|
|
|
|
|
private float currentRotation;
|
|
|
|
|
public float RotationAbsolute;
|
2017-02-15 22:24:08 +08:00
|
|
|
|
private int completeTick;
|
|
|
|
|
|
2017-02-22 17:08:31 +08:00
|
|
|
|
private bool updateCompleteTick() => completeTick != (completeTick = (int)(RotationAbsolute / 360));
|
2017-02-15 22:24:08 +08:00
|
|
|
|
|
2017-05-18 18:40:20 +08:00
|
|
|
|
private bool rotationTransferred;
|
|
|
|
|
|
2017-02-14 17:55:54 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
var thisAngle = -(float)MathHelper.RadiansToDegrees(Math.Atan2(mousePosition.X - DrawSize.X / 2, mousePosition.Y - DrawSize.Y / 2));
|
2017-05-18 18:40:20 +08:00
|
|
|
|
|
|
|
|
|
bool validAndTracking = tracking && spinner.StartTime <= Time.Current && spinner.EndTime > Time.Current;
|
|
|
|
|
|
|
|
|
|
if (validAndTracking)
|
2017-02-14 17:55:54 +08:00
|
|
|
|
{
|
2017-05-18 18:40:20 +08:00
|
|
|
|
if (!rotationTransferred)
|
|
|
|
|
{
|
|
|
|
|
currentRotation = Rotation * 2;
|
|
|
|
|
rotationTransferred = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 17:55:54 +08:00
|
|
|
|
if (thisAngle - lastAngle > 180)
|
|
|
|
|
lastAngle += 360;
|
|
|
|
|
else if (lastAngle - thisAngle > 180)
|
|
|
|
|
lastAngle -= 360;
|
|
|
|
|
|
|
|
|
|
currentRotation += thisAngle - lastAngle;
|
|
|
|
|
RotationAbsolute += Math.Abs(thisAngle - lastAngle);
|
|
|
|
|
}
|
2017-05-18 18:40:20 +08:00
|
|
|
|
|
2017-02-14 17:55:54 +08:00
|
|
|
|
lastAngle = thisAngle;
|
|
|
|
|
|
2017-02-15 22:24:08 +08:00
|
|
|
|
if (Complete && updateCompleteTick())
|
|
|
|
|
{
|
2017-07-21 23:24:09 +08:00
|
|
|
|
background.FinishTransforms(false, nameof(Alpha));
|
2017-07-17 22:05:24 +08:00
|
|
|
|
background
|
2017-07-23 02:50:25 +08:00
|
|
|
|
.FadeTo(tracking_alpha + 0.2f, 60, Easing.OutExpo)
|
2017-07-17 22:05:24 +08:00
|
|
|
|
.Then()
|
2017-07-23 02:50:25 +08:00
|
|
|
|
.FadeTo(tracking_alpha, 250, Easing.OutQuint);
|
2017-02-15 22:24:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
this.RotateTo(currentRotation / 2, validAndTracking ? 500 : 1500, Easing.OutExpo);
|
2017-02-14 17:55:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|