2020-07-29 19:01:01 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|
|
|
{
|
|
|
|
public class DefaultSpinnerDisc : CompositeDrawable
|
|
|
|
{
|
|
|
|
private DrawableSpinner drawableSpinner;
|
|
|
|
|
|
|
|
private Spinner spinner;
|
|
|
|
|
|
|
|
private const float idle_alpha = 0.2f;
|
|
|
|
private const float tracking_alpha = 0.4f;
|
|
|
|
|
|
|
|
private Color4 normalColour;
|
|
|
|
private Color4 completeColour;
|
|
|
|
|
|
|
|
private SpinnerTicks ticks;
|
|
|
|
|
2020-07-31 08:03:29 +08:00
|
|
|
private int wholeRotationCount;
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
private SpinnerFill fill;
|
|
|
|
private Container mainContainer;
|
|
|
|
private SpinnerCentreLayer centre;
|
|
|
|
private SpinnerBackgroundLayer background;
|
|
|
|
|
|
|
|
public DefaultSpinnerDisc()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2020-07-30 10:50:13 +08:00
|
|
|
// we are slightly bigger than our parent, to clip the top and bottom of the circle
|
|
|
|
// this should probably be revisited when scaled spinners are a thing.
|
|
|
|
Scale = new Vector2(1.3f);
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours, DrawableHitObject drawableHitObject)
|
|
|
|
{
|
|
|
|
drawableSpinner = (DrawableSpinner)drawableHitObject;
|
|
|
|
spinner = (Spinner)drawableSpinner.HitObject;
|
|
|
|
|
|
|
|
normalColour = colours.BlueDark;
|
|
|
|
completeColour = colours.YellowLight;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
mainContainer = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
background = new SpinnerBackgroundLayer(),
|
|
|
|
fill = new SpinnerFill
|
|
|
|
{
|
|
|
|
Alpha = idle_alpha,
|
|
|
|
AccentColour = normalColour
|
|
|
|
},
|
|
|
|
ticks = new SpinnerTicks
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
AccentColour = normalColour
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
centre = new SpinnerCentreLayer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
drawableSpinner.RotationTracker.Complete.BindValueChanged(complete => updateComplete(complete.NewValue, 200));
|
|
|
|
drawableSpinner.State.BindValueChanged(updateStateTransforms, true);
|
|
|
|
}
|
|
|
|
|
2020-07-31 08:04:20 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2020-07-31 23:27:00 +08:00
|
|
|
if (drawableSpinner.RotationTracker.Complete.Value)
|
2020-07-31 08:04:20 +08:00
|
|
|
{
|
2020-07-31 23:27:00 +08:00
|
|
|
if (checkNewRotationCount)
|
|
|
|
{
|
|
|
|
fill.FinishTransforms(false, nameof(Alpha));
|
|
|
|
fill
|
|
|
|
.FadeTo(tracking_alpha + 0.2f, 60, Easing.OutExpo)
|
|
|
|
.Then()
|
|
|
|
.FadeTo(tracking_alpha, 250, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-31 23:39:04 +08:00
|
|
|
fill.Alpha = (float)Interpolation.Damp(fill.Alpha, drawableSpinner.RotationTracker.Tracking ? tracking_alpha : idle_alpha, 0.98f, (float)Math.Abs(Clock.ElapsedFrameTime));
|
2020-07-31 08:04:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const float initial_scale = 0.2f;
|
|
|
|
float targetScale = initial_scale + (1 - initial_scale) * drawableSpinner.Progress;
|
|
|
|
|
|
|
|
fill.Scale = new Vector2((float)Interpolation.Lerp(fill.Scale.X, targetScale, Math.Clamp(Math.Abs(Time.Elapsed) / 100, 0, 1)));
|
|
|
|
mainContainer.Rotation = drawableSpinner.RotationTracker.Rotation;
|
|
|
|
}
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
private void updateStateTransforms(ValueChangedEvent<ArmedState> state)
|
|
|
|
{
|
2020-07-30 10:25:49 +08:00
|
|
|
centre.ScaleTo(0);
|
|
|
|
mainContainer.ScaleTo(0);
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
using (BeginAbsoluteSequence(spinner.StartTime - spinner.TimePreempt / 2, true))
|
|
|
|
{
|
2020-07-30 10:50:13 +08:00
|
|
|
// constant ambient rotation to give the spinner "spinning" character.
|
2020-07-29 19:01:01 +08:00
|
|
|
this.RotateTo((float)(25 * spinner.Duration / 2000), spinner.TimePreempt + spinner.Duration);
|
|
|
|
|
2020-07-30 10:50:13 +08:00
|
|
|
centre.ScaleTo(0.3f, spinner.TimePreempt / 4, Easing.OutQuint);
|
|
|
|
mainContainer.ScaleTo(0.2f, spinner.TimePreempt / 4, Easing.OutQuint);
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
using (BeginDelayedSequence(spinner.TimePreempt / 2, true))
|
|
|
|
{
|
2020-07-30 10:50:13 +08:00
|
|
|
centre.ScaleTo(0.5f, spinner.TimePreempt / 2, Easing.OutQuint);
|
2020-07-29 19:01:01 +08:00
|
|
|
mainContainer.ScaleTo(1, spinner.TimePreempt / 2, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// transforms we have from completing the spinner will be rolled back, so reapply immediately.
|
|
|
|
updateComplete(state.NewValue == ArmedState.Hit, 0);
|
|
|
|
|
|
|
|
using (BeginDelayedSequence(spinner.Duration, true))
|
|
|
|
{
|
|
|
|
switch (state.NewValue)
|
|
|
|
{
|
|
|
|
case ArmedState.Hit:
|
|
|
|
this.ScaleTo(Scale * 1.2f, 320, Easing.Out);
|
|
|
|
this.RotateTo(mainContainer.Rotation + 180, 320);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ArmedState.Miss:
|
|
|
|
this.ScaleTo(Scale * 0.8f, 320, Easing.In);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateComplete(bool complete, double duration)
|
|
|
|
{
|
|
|
|
var colour = complete ? completeColour : normalColour;
|
|
|
|
|
|
|
|
ticks.FadeAccent(colour.Darken(1), duration);
|
|
|
|
fill.FadeAccent(colour.Darken(1), duration);
|
|
|
|
|
|
|
|
background.FadeAccent(colour, duration);
|
|
|
|
centre.FadeAccent(colour, duration);
|
|
|
|
}
|
|
|
|
|
2020-07-31 08:03:29 +08:00
|
|
|
private bool checkNewRotationCount
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
int rotations = (int)(drawableSpinner.RotationTracker.CumulativeRotation / 360);
|
|
|
|
|
|
|
|
if (wholeRotationCount == rotations) return false;
|
|
|
|
|
|
|
|
wholeRotationCount = rotations;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-07-29 19:01:01 +08:00
|
|
|
}
|
|
|
|
}
|