mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 21:43:04 +08:00
85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
// 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.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
using osu.Game.Skinning;
|
|
using osuTK;
|
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning
|
|
{
|
|
public abstract class LegacySpinner : CompositeDrawable
|
|
{
|
|
protected const float SPRITE_SCALE = 0.625f;
|
|
|
|
protected DrawableSpinner DrawableSpinner { get; private set; }
|
|
|
|
private Sprite spin;
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(DrawableHitObject drawableHitObject, ISkinSource source)
|
|
{
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
DrawableSpinner = (DrawableSpinner)drawableHitObject;
|
|
|
|
AddRangeInternal(new[]
|
|
{
|
|
spin = new Sprite
|
|
{
|
|
Anchor = Anchor.Centre,
|
|
Origin = Anchor.Centre,
|
|
Depth = float.MinValue,
|
|
Texture = source.GetTexture("spinner-spin"),
|
|
Scale = new Vector2(SPRITE_SCALE),
|
|
Y = 120 - 45 // offset temporarily to avoid overlapping default spin counter
|
|
},
|
|
});
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
|
|
DrawableSpinner.ApplyCustomUpdateState += UpdateStateTransforms;
|
|
UpdateStateTransforms(DrawableSpinner, DrawableSpinner.State.Value);
|
|
}
|
|
|
|
protected virtual void UpdateStateTransforms(DrawableHitObject drawableHitObject, ArmedState state)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
{
|
|
base.Dispose(isDisposing);
|
|
|
|
if (DrawableSpinner != null)
|
|
DrawableSpinner.ApplyCustomUpdateState -= UpdateStateTransforms;
|
|
}
|
|
}
|
|
}
|