1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:07:44 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Skinning/LegacyOldStyleSpinner.cs

115 lines
3.6 KiB
C#
Raw Normal View History

2020-07-29 21:31:18 +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-07-30 11:32:19 +08:00
using System;
2020-07-29 21:31:18 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
2020-07-30 11:32:19 +08:00
using osu.Framework.Utils;
2020-07-29 21:31:18 +08:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Skinning;
2020-07-30 11:08:04 +08:00
using osuTK;
2020-07-29 21:31:18 +08:00
namespace osu.Game.Rulesets.Osu.Skinning
{
2020-07-30 09:35:48 +08:00
/// <summary>
/// Legacy skinned spinner with one main spinning layer and a background layer.
/// </summary>
2020-07-29 21:31:18 +08:00
public class LegacyOldStyleSpinner : CompositeDrawable
{
private DrawableSpinner drawableSpinner;
private Sprite disc;
2020-07-30 11:32:19 +08:00
private Container metre;
2020-07-29 21:31:18 +08:00
2020-07-30 11:50:27 +08:00
private const float background_y_offset = 20;
private const float sprite_scale = 1 / 1.6f;
2020-07-29 21:31:18 +08:00
[BackgroundDependencyLoader]
private void load(ISkinSource source, DrawableHitObject drawableObject)
{
drawableSpinner = (DrawableSpinner)drawableObject;
2020-07-30 11:32:19 +08:00
RelativeSizeAxes = Axes.Both;
2020-07-30 11:08:04 +08:00
2020-07-29 21:31:18 +08:00
InternalChildren = new Drawable[]
{
new Sprite
{
2020-07-30 11:32:19 +08:00
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Texture = source.GetTexture("spinner-background"),
2020-07-30 11:50:27 +08:00
Y = background_y_offset,
Scale = new Vector2(sprite_scale)
2020-07-29 21:31:18 +08:00
},
disc = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-07-30 11:32:19 +08:00
Texture = source.GetTexture("spinner-circle"),
2020-07-30 11:50:27 +08:00
Scale = new Vector2(sprite_scale)
2020-07-30 11:32:19 +08:00
},
metre = new Container
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
2020-07-30 11:50:27 +08:00
Y = background_y_offset,
2020-07-30 11:32:19 +08:00
Masking = true,
Child = new Sprite
{
Texture = source.GetTexture("spinner-metre"),
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
},
Scale = new Vector2(0.625f)
2020-07-29 21:31:18 +08:00
}
};
}
2020-07-30 11:32:19 +08:00
private Vector2 metreFinalSize;
2020-07-29 21:31:18 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
this.FadeOut();
drawableSpinner.State.BindValueChanged(updateStateTransforms, true);
2020-07-30 11:32:19 +08:00
metreFinalSize = metre.Size = metre.Child.Size;
2020-07-29 21:31:18 +08:00
}
private void updateStateTransforms(ValueChangedEvent<ArmedState> state)
{
var spinner = drawableSpinner.HitObject;
using (BeginAbsoluteSequence(spinner.StartTime - spinner.TimeFadeIn / 2, true))
this.FadeInFromZero(spinner.TimeFadeIn / 2);
2020-07-29 21:31:18 +08:00
}
protected override void Update()
{
base.Update();
disc.Rotation = drawableSpinner.RotationTracker.Rotation;
2020-07-30 11:32:19 +08:00
metre.Height = getMetreHeight(drawableSpinner.Progress);
}
private const int total_bars = 10;
private float getMetreHeight(float progress)
{
progress = Math.Min(99, progress * 100);
int barCount = (int)progress / 10;
// todo: add SpinnerNoBlink support
if (RNG.NextBool(((int)progress % 10) / 10f))
barCount++;
return (float)barCount / total_bars * metreFinalSize.Y;
2020-07-29 21:31:18 +08:00
}
}
}