2020-07-29 13:31:18 +00: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 03:32:19 +00:00
|
|
|
using System;
|
2020-07-29 13:31:18 +00: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 03:32:19 +00:00
|
|
|
using osu.Framework.Utils;
|
2020-07-29 13:31:18 +00:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
|
|
using osu.Game.Skinning;
|
2020-07-30 03:08:04 +00:00
|
|
|
using osuTK;
|
2020-07-29 13:31:18 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning
|
|
|
|
{
|
2020-07-30 01:35:48 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Legacy skinned spinner with one main spinning layer and a background layer.
|
|
|
|
/// </summary>
|
2020-07-29 13:31:18 +00:00
|
|
|
public class LegacyOldStyleSpinner : CompositeDrawable
|
|
|
|
{
|
|
|
|
private DrawableSpinner drawableSpinner;
|
|
|
|
private Sprite disc;
|
2020-08-29 21:29:29 +00:00
|
|
|
private Sprite metreSprite;
|
2020-07-30 03:32:19 +00:00
|
|
|
private Container metre;
|
2020-07-29 13:31:18 +00:00
|
|
|
|
2020-09-28 10:21:43 +00:00
|
|
|
private bool spinnerBlink;
|
2020-09-26 14:25:57 +00:00
|
|
|
|
2020-07-30 03:50:27 +00:00
|
|
|
private const float sprite_scale = 1 / 1.6f;
|
2020-08-29 21:29:29 +00:00
|
|
|
private const float final_metre_height = 692 * sprite_scale;
|
2020-07-30 03:50:27 +00:00
|
|
|
|
2020-07-29 13:31:18 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource source, DrawableHitObject drawableObject)
|
|
|
|
{
|
2020-10-01 10:41:44 +00:00
|
|
|
spinnerBlink = !(source.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.SpinnerNoBlink)?.Value) ?? true;
|
2020-09-26 14:25:57 +00:00
|
|
|
|
2020-07-29 13:31:18 +00:00
|
|
|
drawableSpinner = (DrawableSpinner)drawableObject;
|
|
|
|
|
2020-07-30 03:32:19 +00:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2020-07-30 03:08:04 +00:00
|
|
|
|
2020-08-29 21:29:29 +00:00
|
|
|
InternalChild = new Container
|
2020-07-29 13:31:18 +00:00
|
|
|
{
|
2020-08-29 21:29:29 +00:00
|
|
|
// the old-style spinner relied heavily on absolute screen-space coordinate values.
|
|
|
|
// wrap everything in a container simulating absolute coords to preserve alignment
|
|
|
|
// as there are skins that depend on it.
|
|
|
|
Width = 640,
|
|
|
|
Height = 480,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Children = new Drawable[]
|
2020-07-30 03:32:19 +00:00
|
|
|
{
|
2020-08-29 21:29:29 +00:00
|
|
|
new Sprite
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Texture = source.GetTexture("spinner-background"),
|
|
|
|
Scale = new Vector2(sprite_scale)
|
|
|
|
},
|
|
|
|
disc = new Sprite
|
2020-07-30 03:32:19 +00:00
|
|
|
{
|
2020-08-29 21:29:29 +00:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Texture = source.GetTexture("spinner-circle"),
|
|
|
|
Scale = new Vector2(sprite_scale)
|
2020-07-30 03:32:19 +00:00
|
|
|
},
|
2020-08-29 21:29:29 +00:00
|
|
|
metre = new Container
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
// this anchor makes no sense, but that's what stable uses.
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
// adjustment for stable (metre has additional offset)
|
|
|
|
Margin = new MarginPadding { Top = 20 },
|
|
|
|
Masking = true,
|
|
|
|
Child = metreSprite = new Sprite
|
|
|
|
{
|
|
|
|
Texture = source.GetTexture("spinner-metre"),
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
Scale = new Vector2(0.625f)
|
|
|
|
}
|
|
|
|
}
|
2020-07-29 13:31:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
this.FadeOut();
|
|
|
|
drawableSpinner.State.BindValueChanged(updateStateTransforms, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateStateTransforms(ValueChangedEvent<ArmedState> state)
|
|
|
|
{
|
|
|
|
var spinner = drawableSpinner.HitObject;
|
|
|
|
|
2020-08-13 09:20:45 +00:00
|
|
|
using (BeginAbsoluteSequence(spinner.StartTime - spinner.TimeFadeIn / 2, true))
|
|
|
|
this.FadeInFromZero(spinner.TimeFadeIn / 2);
|
2020-07-29 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
disc.Rotation = drawableSpinner.RotationTracker.Rotation;
|
2020-08-29 21:29:29 +00:00
|
|
|
|
|
|
|
// careful: need to call this exactly once for all calculations in a frame
|
|
|
|
// as the function has a random factor in it
|
|
|
|
var metreHeight = getMetreHeight(drawableSpinner.Progress);
|
|
|
|
|
|
|
|
// hack to make the metre blink up from below than down from above.
|
|
|
|
// move down the container to be able to apply masking for the metre,
|
|
|
|
// and then move the sprite back up the same amount to keep its position absolute.
|
|
|
|
metre.Y = final_metre_height - metreHeight;
|
|
|
|
metreSprite.Y = -metre.Y;
|
2020-07-30 03:32:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private const int total_bars = 10;
|
|
|
|
|
|
|
|
private float getMetreHeight(float progress)
|
|
|
|
{
|
2020-09-26 14:25:57 +00:00
|
|
|
progress *= 100;
|
|
|
|
|
|
|
|
// the spinner should still blink at 100% progress.
|
2020-09-28 10:21:43 +00:00
|
|
|
if (spinnerBlink)
|
2020-09-26 14:25:57 +00:00
|
|
|
progress = Math.Min(99, progress);
|
2020-07-30 03:32:19 +00:00
|
|
|
|
|
|
|
int barCount = (int)progress / 10;
|
|
|
|
|
2020-09-28 10:21:43 +00:00
|
|
|
if (spinnerBlink && RNG.NextBool(((int)progress % 10) / 10f))
|
2020-07-30 03:32:19 +00:00
|
|
|
barCount++;
|
|
|
|
|
2020-08-29 21:29:29 +00:00
|
|
|
return (float)barCount / total_bars * final_metre_height;
|
2020-07-29 13:31:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|