2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2020-01-09 03:21:13 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|
|
|
|
{
|
|
|
|
|
public class SpinnerDisc : CircularContainer, IHasAccentColour
|
|
|
|
|
{
|
|
|
|
|
private readonly Spinner spinner;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => background.AccentColour;
|
|
|
|
|
set => background.AccentColour = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly SpinnerBackground background;
|
|
|
|
|
|
|
|
|
|
private const float idle_alpha = 0.2f;
|
|
|
|
|
private const float tracking_alpha = 0.4f;
|
|
|
|
|
|
|
|
|
|
public override bool IsPresent => true; // handle input when hidden
|
|
|
|
|
|
|
|
|
|
public SpinnerDisc(Spinner s)
|
|
|
|
|
{
|
|
|
|
|
spinner = s;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new SpinnerBackground { Alpha = idle_alpha },
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private bool tracking;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public bool Tracking
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => tracking;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == tracking) return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
tracking = value;
|
|
|
|
|
|
|
|
|
|
background.FadeTo(tracking ? tracking_alpha : idle_alpha, 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool complete;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public bool Complete
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => complete;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == complete) return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
complete = value;
|
|
|
|
|
|
|
|
|
|
updateCompleteTick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-08 08:59:35 +08:00
|
|
|
|
public bool AutoSpin { get; set; } = false;
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-09-19 19:52:57 +08:00
|
|
|
|
mousePosition = Parent.ToLocalSpace(e.ScreenSpaceMousePosition);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnMouseMove(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector2 mousePosition;
|
|
|
|
|
|
|
|
|
|
private float lastAngle;
|
|
|
|
|
private float currentRotation;
|
2019-09-09 20:35:18 +08:00
|
|
|
|
public float RotationAbsolute;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private int completeTick;
|
|
|
|
|
|
2019-09-09 20:35:18 +08:00
|
|
|
|
private bool updateCompleteTick() => completeTick != (completeTick = (int)(RotationAbsolute / 360));
|
2019-09-08 21:14:14 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private bool rotationTransferred;
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2020-02-08 08:59:35 +08:00
|
|
|
|
bool valid = spinner.StartTime <= Time.Current && spinner.EndTime > Time.Current;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-08 08:59:35 +08:00
|
|
|
|
if (valid && AutoSpin)
|
|
|
|
|
Rotate(6f);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var thisAngle = -MathUtils.RadiansToDegrees(MathF.Atan2(mousePosition.X - DrawSize.X / 2, mousePosition.Y - DrawSize.Y / 2));
|
2020-02-05 14:05:12 +08:00
|
|
|
|
|
2020-02-08 08:59:35 +08:00
|
|
|
|
var delta = thisAngle - lastAngle;
|
2020-02-05 14:23:59 +08:00
|
|
|
|
|
2020-02-08 08:59:35 +08:00
|
|
|
|
if (valid && tracking)
|
|
|
|
|
Rotate(delta);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-08 08:59:35 +08:00
|
|
|
|
lastAngle = thisAngle;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
if (Complete && updateCompleteTick())
|
|
|
|
|
{
|
|
|
|
|
background.FinishTransforms(false, nameof(Alpha));
|
|
|
|
|
background
|
|
|
|
|
.FadeTo(tracking_alpha + 0.2f, 60, Easing.OutExpo)
|
|
|
|
|
.Then()
|
|
|
|
|
.FadeTo(tracking_alpha, 250, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-08 08:59:35 +08:00
|
|
|
|
this.RotateTo(currentRotation / 2, 500, Easing.OutExpo);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2020-02-05 14:23:59 +08:00
|
|
|
|
|
|
|
|
|
public void Rotate(float angle)
|
|
|
|
|
{
|
|
|
|
|
if (!rotationTransferred)
|
|
|
|
|
{
|
|
|
|
|
currentRotation = Rotation * 2;
|
|
|
|
|
rotationTransferred = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (angle > 180)
|
|
|
|
|
{
|
|
|
|
|
lastAngle += 360;
|
|
|
|
|
angle -= 360;
|
|
|
|
|
}
|
|
|
|
|
else if (-angle > 180)
|
|
|
|
|
{
|
|
|
|
|
lastAngle -= 360;
|
|
|
|
|
angle += 360;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentRotation += angle;
|
|
|
|
|
RotationAbsolute += Math.Abs(angle) * Math.Sign(Clock.ElapsedFrameTime);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|