mirror of https://github.com/ppy/osu
Rewrite to reduce code changes and complexities in hit object implementation
This commit is contained in:
parent
a2b3fe180e
commit
d1b01095ee
|
@ -30,21 +30,18 @@ public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables)
|
||||||
{
|
{
|
||||||
if (hitObject is DrawableSpinner spinner)
|
if (hitObject is DrawableSpinner spinner)
|
||||||
{
|
{
|
||||||
spinner.Disc.Enabled = false;
|
spinner.HandleUserInput = false;
|
||||||
spinner.OnUpdate += autoSpin;
|
spinner.OnUpdate += onSpinnerUpdate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void autoSpin(Drawable drawable)
|
private void onSpinnerUpdate(Drawable drawable)
|
||||||
{
|
{
|
||||||
if (drawable is DrawableSpinner spinner)
|
var spinner = (DrawableSpinner)drawable;
|
||||||
{
|
|
||||||
if (spinner.Disc.Valid)
|
spinner.Disc.Tracking = true;
|
||||||
spinner.Disc.Rotate(MathUtils.RadiansToDegrees((float)spinner.Clock.ElapsedFrameTime * 0.03f));
|
spinner.Disc.Rotate(MathUtils.RadiansToDegrees((float)spinner.Clock.ElapsedFrameTime * 0.03f));
|
||||||
if (!spinner.SpmCounter.IsPresent)
|
|
||||||
spinner.SpmCounter.FadeIn(spinner.HitObject.TimeFadeIn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,17 +176,18 @@ protected override void CheckForResult(bool userTriggered, double timeOffset)
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
Disc.Tracking = OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false;
|
|
||||||
if (!SpmCounter.IsPresent && Disc.Tracking)
|
|
||||||
SpmCounter.FadeIn(HitObject.TimeFadeIn);
|
|
||||||
|
|
||||||
base.Update();
|
base.Update();
|
||||||
|
if (HandleUserInput)
|
||||||
|
Disc.Tracking = OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
{
|
{
|
||||||
base.UpdateAfterChildren();
|
base.UpdateAfterChildren();
|
||||||
|
|
||||||
|
if (!SpmCounter.IsPresent && Disc.Tracking)
|
||||||
|
SpmCounter.FadeIn(HitObject.TimeFadeIn);
|
||||||
|
|
||||||
circle.Rotation = Disc.Rotation;
|
circle.Rotation = Disc.Rotation;
|
||||||
Ticks.Rotation = Disc.Rotation;
|
Ticks.Rotation = Disc.Rotation;
|
||||||
SpmCounter.SetRotation(Disc.RotationAbsolute);
|
SpmCounter.SetRotation(Disc.RotationAbsolute);
|
||||||
|
|
|
@ -50,9 +50,9 @@ public bool Tracking
|
||||||
get => tracking;
|
get => tracking;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if ((Enabled && value) == tracking) return;
|
if (value == tracking) return;
|
||||||
|
|
||||||
tracking = Enabled && value;
|
tracking = value;
|
||||||
|
|
||||||
background.FadeTo(tracking ? tracking_alpha : idle_alpha, 100);
|
background.FadeTo(tracking ? tracking_alpha : idle_alpha, 100);
|
||||||
}
|
}
|
||||||
|
@ -73,9 +73,10 @@ public bool Complete
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Valid => spinner.StartTime <= Time.Current && spinner.EndTime > Time.Current;
|
/// <summary>
|
||||||
|
/// Whether currently in the correct time range to allow spinning.
|
||||||
public bool Enabled { get; set; } = true;
|
/// </summary>
|
||||||
|
private bool isSpinnableTime => spinner.StartTime <= Time.Current && spinner.EndTime > Time.Current;
|
||||||
|
|
||||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||||
{
|
{
|
||||||
|
@ -101,7 +102,7 @@ protected override void Update()
|
||||||
|
|
||||||
var delta = thisAngle - lastAngle;
|
var delta = thisAngle - lastAngle;
|
||||||
|
|
||||||
if (Valid && tracking)
|
if (tracking)
|
||||||
Rotate(delta);
|
Rotate(delta);
|
||||||
|
|
||||||
lastAngle = thisAngle;
|
lastAngle = thisAngle;
|
||||||
|
@ -118,8 +119,18 @@ protected override void Update()
|
||||||
Rotation = (float)Interpolation.Lerp(Rotation, currentRotation / 2, Math.Clamp(Math.Abs(Time.Elapsed) / 40, 0, 1));
|
Rotation = (float)Interpolation.Lerp(Rotation, currentRotation / 2, Math.Clamp(Math.Abs(Time.Elapsed) / 40, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rotate the disc by the provided angle (in addition to any existing rotation).
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Will be a no-op if not a valid time to spin.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="angle">The delta angle.</param>
|
||||||
public void Rotate(float angle)
|
public void Rotate(float angle)
|
||||||
{
|
{
|
||||||
|
if (!isSpinnableTime)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!rotationTransferred)
|
if (!rotationTransferred)
|
||||||
{
|
{
|
||||||
currentRotation = Rotation * 2;
|
currentRotation = Rotation * 2;
|
||||||
|
|
Loading…
Reference in New Issue