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.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;
|
2020-11-05 14:25:20 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2020-07-29 21:31:18 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
|
|
using osu.Game.Skinning;
|
2020-07-30 11:08:04 +08:00
|
|
|
using osuTK;
|
2021-06-15 21:17:05 +08:00
|
|
|
using osuTK.Graphics;
|
2020-07-29 21:31:18 +08:00
|
|
|
|
2020-12-04 19:21:53 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
2020-07-29 21:31:18 +08:00
|
|
|
{
|
2020-07-30 09:35:48 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Legacy skinned spinner with one main spinning layer and a background layer.
|
|
|
|
/// </summary>
|
2020-11-05 17:00:26 +08:00
|
|
|
public class LegacyOldStyleSpinner : LegacySpinner
|
2020-07-29 21:31:18 +08:00
|
|
|
{
|
|
|
|
private Sprite disc;
|
2020-08-30 05:29:29 +08:00
|
|
|
private Sprite metreSprite;
|
2020-07-30 11:32:19 +08:00
|
|
|
private Container metre;
|
2020-07-29 21:31:18 +08:00
|
|
|
|
2020-09-28 18:21:43 +08:00
|
|
|
private bool spinnerBlink;
|
2020-09-26 22:25:57 +08:00
|
|
|
|
2020-11-05 18:05:59 +08:00
|
|
|
private const float final_metre_height = 692 * SPRITE_SCALE;
|
2020-07-30 11:50:27 +08:00
|
|
|
|
2020-07-29 21:31:18 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2020-11-05 17:00:26 +08:00
|
|
|
private void load(ISkinSource source)
|
2020-07-29 21:31:18 +08:00
|
|
|
{
|
2020-10-01 19:09:09 +08:00
|
|
|
spinnerBlink = source.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.SpinnerNoBlink)?.Value != true;
|
2020-09-26 22:25:57 +08:00
|
|
|
|
2021-03-01 02:41:11 +08:00
|
|
|
AddRangeInternal(new Drawable[]
|
2020-07-29 21:31:18 +08:00
|
|
|
{
|
2021-03-01 02:41:11 +08:00
|
|
|
new Sprite
|
2020-07-30 11:32:19 +08:00
|
|
|
{
|
2021-03-09 13:55:32 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
2021-03-01 02:41:11 +08:00
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Texture = source.GetTexture("spinner-background"),
|
2021-06-15 21:17:05 +08:00
|
|
|
Colour = source.GetConfig<OsuSkinColour, Color4>(OsuSkinColour.SpinnerBackground)?.Value ?? new Color4(100, 100, 100, 255),
|
2021-03-09 13:55:32 +08:00
|
|
|
Scale = new Vector2(SPRITE_SCALE),
|
|
|
|
Y = SPINNER_Y_CENTRE,
|
2021-03-01 02:41:11 +08:00
|
|
|
},
|
|
|
|
disc = new Sprite
|
|
|
|
{
|
2021-03-09 13:55:32 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
2021-03-01 02:41:11 +08:00
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Texture = source.GetTexture("spinner-circle"),
|
2021-03-09 13:55:32 +08:00
|
|
|
Scale = new Vector2(SPRITE_SCALE),
|
|
|
|
Y = SPINNER_Y_CENTRE,
|
2021-03-01 02:41:11 +08:00
|
|
|
},
|
2021-03-09 13:55:32 +08:00
|
|
|
metre = new Container
|
2021-03-01 02:41:11 +08:00
|
|
|
{
|
2021-03-09 13:55:32 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
// this anchor makes no sense, but that's what stable uses.
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
Margin = new MarginPadding { Top = SPINNER_TOP_OFFSET },
|
|
|
|
Masking = true,
|
|
|
|
Child = metreSprite = new Sprite
|
2020-08-30 05:29:29 +08:00
|
|
|
{
|
2021-03-09 13:55:32 +08:00
|
|
|
Texture = source.GetTexture("spinner-metre"),
|
2020-08-30 05:29:29 +08:00
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Origin = Anchor.TopLeft,
|
2021-03-09 13:55:32 +08:00
|
|
|
Scale = new Vector2(SPRITE_SCALE)
|
2020-08-30 05:29:29 +08:00
|
|
|
}
|
2020-07-29 21:31:18 +08:00
|
|
|
}
|
2020-11-05 17:03:24 +08:00
|
|
|
});
|
2020-07-29 21:31:18 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 17:00:26 +08:00
|
|
|
protected override void UpdateStateTransforms(DrawableHitObject drawableHitObject, ArmedState state)
|
2020-07-29 21:31:18 +08:00
|
|
|
{
|
2020-11-05 17:00:26 +08:00
|
|
|
base.UpdateStateTransforms(drawableHitObject, state);
|
2020-07-29 21:31:18 +08:00
|
|
|
|
2020-11-05 14:25:20 +08:00
|
|
|
if (!(drawableHitObject is DrawableSpinner d))
|
2020-10-01 19:38:47 +08:00
|
|
|
return;
|
|
|
|
|
2020-11-05 14:25:20 +08:00
|
|
|
Spinner spinner = d.HitObject;
|
|
|
|
|
|
|
|
using (BeginAbsoluteSequence(spinner.StartTime - spinner.TimePreempt, true))
|
2020-10-02 15:17:57 +08:00
|
|
|
this.FadeOut();
|
|
|
|
|
2020-11-05 14:25:20 +08:00
|
|
|
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();
|
2020-11-05 17:00:26 +08:00
|
|
|
disc.Rotation = DrawableSpinner.RotationTracker.Rotation;
|
2020-08-30 05:29:29 +08:00
|
|
|
|
|
|
|
// careful: need to call this exactly once for all calculations in a frame
|
|
|
|
// as the function has a random factor in it
|
2020-11-05 17:00:26 +08:00
|
|
|
var metreHeight = getMetreHeight(DrawableSpinner.Progress);
|
2020-08-30 05:29:29 +08:00
|
|
|
|
|
|
|
// 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 11:32:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private const int total_bars = 10;
|
|
|
|
|
|
|
|
private float getMetreHeight(float progress)
|
|
|
|
{
|
2020-09-26 22:25:57 +08:00
|
|
|
progress *= 100;
|
|
|
|
|
|
|
|
// the spinner should still blink at 100% progress.
|
2020-09-28 18:21:43 +08:00
|
|
|
if (spinnerBlink)
|
2020-09-26 22:25:57 +08:00
|
|
|
progress = Math.Min(99, progress);
|
2020-07-30 11:32:19 +08:00
|
|
|
|
|
|
|
int barCount = (int)progress / 10;
|
|
|
|
|
2020-09-28 18:21:43 +08:00
|
|
|
if (spinnerBlink && RNG.NextBool(((int)progress % 10) / 10f))
|
2020-07-30 11:32:19 +08:00
|
|
|
barCount++;
|
|
|
|
|
2020-08-30 05:29:29 +08:00
|
|
|
return (float)barCount / total_bars * final_metre_height;
|
2020-07-29 21:31:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|