2020-11-05 17:00:26 +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.
|
|
|
|
|
2020-11-05 17:12:13 +08:00
|
|
|
using System;
|
2020-11-05 17:00:26 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-11-05 18:35:32 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-11-05 17:00:26 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-11-05 17:12:13 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2020-11-05 17:00:26 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2020-11-05 17:12:13 +08:00
|
|
|
using osu.Game.Skinning;
|
2020-11-05 18:05:59 +08:00
|
|
|
using osuTK;
|
2020-11-05 17:00:26 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning
|
|
|
|
{
|
|
|
|
public abstract class LegacySpinner : CompositeDrawable
|
|
|
|
{
|
2020-11-05 18:05:59 +08:00
|
|
|
protected const float SPRITE_SCALE = 0.625f;
|
|
|
|
|
2020-11-05 17:00:26 +08:00
|
|
|
protected DrawableSpinner DrawableSpinner { get; private set; }
|
|
|
|
|
2020-11-05 17:12:13 +08:00
|
|
|
private Sprite spin;
|
2020-11-05 18:35:32 +08:00
|
|
|
private Sprite clear;
|
2020-11-05 17:12:13 +08:00
|
|
|
|
2020-11-05 17:00:26 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2020-11-05 17:12:13 +08:00
|
|
|
private void load(DrawableHitObject drawableHitObject, ISkinSource source)
|
2020-11-05 17:00:26 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
DrawableSpinner = (DrawableSpinner)drawableHitObject;
|
2020-11-05 17:12:13 +08:00
|
|
|
|
|
|
|
AddRangeInternal(new[]
|
|
|
|
{
|
|
|
|
spin = new Sprite
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Depth = float.MinValue,
|
|
|
|
Texture = source.GetTexture("spinner-spin"),
|
2020-11-05 18:05:59 +08:00
|
|
|
Scale = new Vector2(SPRITE_SCALE),
|
2020-11-05 18:16:47 +08:00
|
|
|
Y = 120 - 45 // offset temporarily to avoid overlapping default spin counter
|
2020-11-05 17:12:13 +08:00
|
|
|
},
|
2020-11-05 18:35:32 +08:00
|
|
|
clear = new Sprite
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Depth = float.MinValue,
|
|
|
|
Alpha = 0,
|
|
|
|
Texture = source.GetTexture("spinner-clear"),
|
|
|
|
Scale = new Vector2(SPRITE_SCALE),
|
|
|
|
Y = -60
|
|
|
|
},
|
2020-11-05 17:12:13 +08:00
|
|
|
});
|
2020-11-05 17:00:26 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 18:35:32 +08:00
|
|
|
private readonly Bindable<bool> completed = new Bindable<bool>();
|
|
|
|
|
2020-11-05 17:00:26 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-11-05 18:35:32 +08:00
|
|
|
completed.BindValueChanged(onCompletedChanged, true);
|
|
|
|
|
2020-11-05 17:00:26 +08:00
|
|
|
DrawableSpinner.ApplyCustomUpdateState += UpdateStateTransforms;
|
|
|
|
UpdateStateTransforms(DrawableSpinner, DrawableSpinner.State.Value);
|
|
|
|
}
|
|
|
|
|
2020-11-05 18:35:32 +08:00
|
|
|
private void onCompletedChanged(ValueChangedEvent<bool> completed)
|
|
|
|
{
|
|
|
|
if (completed.NewValue)
|
|
|
|
{
|
2020-11-05 18:44:34 +08:00
|
|
|
double startTime = Math.Min(Time.Current, DrawableSpinner.HitStateUpdateTime - 400);
|
|
|
|
|
|
|
|
using (BeginAbsoluteSequence(startTime, true))
|
|
|
|
{
|
|
|
|
clear.FadeInFromZero(400, Easing.Out);
|
|
|
|
|
|
|
|
clear.ScaleTo(SPRITE_SCALE * 2)
|
|
|
|
.Then().ScaleTo(SPRITE_SCALE * 0.8f, 240, Easing.Out)
|
|
|
|
.Then().ScaleTo(SPRITE_SCALE, 160);
|
|
|
|
}
|
2020-11-05 18:35:32 +08:00
|
|
|
|
|
|
|
const double fade_out_duration = 50;
|
|
|
|
using (BeginAbsoluteSequence(DrawableSpinner.HitStateUpdateTime - fade_out_duration, true))
|
|
|
|
clear.FadeOut(fade_out_duration);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clear.ClearTransforms();
|
|
|
|
clear.Alpha = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-15 05:42:19 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
completed.Value = Time.Current >= DrawableSpinner.Result.TimeCompleted;
|
|
|
|
}
|
|
|
|
|
2020-11-05 17:00:26 +08:00
|
|
|
protected virtual void UpdateStateTransforms(DrawableHitObject drawableHitObject, ArmedState state)
|
|
|
|
{
|
2020-11-05 17:12:13 +08:00
|
|
|
switch (drawableHitObject)
|
|
|
|
{
|
|
|
|
case DrawableSpinner d:
|
|
|
|
double fadeOutLength = Math.Min(400, d.HitObject.Duration);
|
|
|
|
|
|
|
|
using (BeginAbsoluteSequence(drawableHitObject.HitStateUpdateTime - fadeOutLength, true))
|
|
|
|
spin.FadeOutFromOne(fadeOutLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DrawableSpinnerTick d:
|
|
|
|
if (state == ArmedState.Hit)
|
|
|
|
{
|
|
|
|
using (BeginAbsoluteSequence(d.HitStateUpdateTime, true))
|
|
|
|
spin.FadeOut(300);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-11-05 17:00:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (DrawableSpinner != null)
|
|
|
|
DrawableSpinner.ApplyCustomUpdateState -= UpdateStateTransforms;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|