1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 09:42:54 +08:00

Rewrite to reduce code changes and complexities in hit object implementation

This commit is contained in:
Dean Herbert 2020-03-29 14:31:03 +09:00
parent a2b3fe180e
commit d1b01095ee
3 changed files with 29 additions and 20 deletions

View File

@ -30,21 +30,18 @@ namespace osu.Game.Rulesets.Osu.Mods
{
if (hitObject is DrawableSpinner spinner)
{
spinner.Disc.Enabled = false;
spinner.OnUpdate += autoSpin;
spinner.HandleUserInput = false;
spinner.OnUpdate += onSpinnerUpdate;
}
}
}
private void autoSpin(Drawable drawable)
private void onSpinnerUpdate(Drawable drawable)
{
if (drawable is DrawableSpinner spinner)
{
if (spinner.Disc.Valid)
spinner.Disc.Rotate(MathUtils.RadiansToDegrees((float)spinner.Clock.ElapsedFrameTime * 0.03f));
if (!spinner.SpmCounter.IsPresent)
spinner.SpmCounter.FadeIn(spinner.HitObject.TimeFadeIn);
}
var spinner = (DrawableSpinner)drawable;
spinner.Disc.Tracking = true;
spinner.Disc.Rotate(MathUtils.RadiansToDegrees((float)spinner.Clock.ElapsedFrameTime * 0.03f));
}
}
}

View File

@ -176,17 +176,18 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
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();
if (HandleUserInput)
Disc.Tracking = OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false;
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
if (!SpmCounter.IsPresent && Disc.Tracking)
SpmCounter.FadeIn(HitObject.TimeFadeIn);
circle.Rotation = Disc.Rotation;
Ticks.Rotation = Disc.Rotation;
SpmCounter.SetRotation(Disc.RotationAbsolute);

View File

@ -50,9 +50,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
get => tracking;
set
{
if ((Enabled && value) == tracking) return;
if (value == tracking) return;
tracking = Enabled && value;
tracking = value;
background.FadeTo(tracking ? tracking_alpha : idle_alpha, 100);
}
@ -73,9 +73,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
}
}
public bool Valid => spinner.StartTime <= Time.Current && spinner.EndTime > Time.Current;
public bool Enabled { get; set; } = true;
/// <summary>
/// Whether currently in the correct time range to allow spinning.
/// </summary>
private bool isSpinnableTime => spinner.StartTime <= Time.Current && spinner.EndTime > Time.Current;
protected override bool OnMouseMove(MouseMoveEvent e)
{
@ -101,7 +102,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
var delta = thisAngle - lastAngle;
if (Valid && tracking)
if (tracking)
Rotate(delta);
lastAngle = thisAngle;
@ -118,8 +119,18 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
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)
{
if (!isSpinnableTime)
return;
if (!rotationTransferred)
{
currentRotation = Rotation * 2;