1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-25 04:15:37 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Skinning/Legacy/LegacySwell.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

203 lines
7.9 KiB
C#
Raw Normal View History

2022-12-11 09:17:50 +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.
using osu.Framework.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Game.Skinning;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects;
using osu.Framework.Audio.Sample;
using osu.Game.Audio;
using osuTK;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Framework.Extensions.ObjectExtensions;
using System;
using System.Globalization;
2025-02-12 17:55:57 +08:00
using osu.Framework.Utils;
2022-12-11 09:17:50 +08:00
namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
{
public partial class LegacySwell : Container
2022-12-11 09:17:50 +08:00
{
2025-02-12 17:55:57 +08:00
private const float scale_adjust = 768f / 480;
private static readonly Vector2 swell_display_position = new Vector2(250f, 100f);
2025-02-12 17:55:57 +08:00
private DrawableSwell drawableSwell = null!;
2022-12-11 09:17:50 +08:00
private Container bodyContainer = null!;
private Sprite warning = null!;
2022-12-11 09:17:50 +08:00
private Sprite spinnerCircle = null!;
private Sprite approachCircle = null!;
2022-12-11 09:17:50 +08:00
private Sprite clearAnimation = null!;
private ISample? clearSample;
private LegacySpriteText remainingHitsText = null!;
2022-12-11 09:17:50 +08:00
private bool samplePlayed;
private int numHits;
2022-12-11 09:17:50 +08:00
public LegacySwell()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(DrawableHitObject hitObject, ISkinSource skin)
2022-12-11 09:17:50 +08:00
{
Children = new Drawable[]
2022-12-11 09:17:50 +08:00
{
warning = new Sprite
2022-12-11 09:17:50 +08:00
{
Texture = skin.GetTexture("spinner-warning"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = skin.GetTexture("spinner-warning") != null ? Vector2.One : new Vector2(0.18f),
},
new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = swell_display_position, // ballparked to be horizontally centred on 4:3 resolution
2022-12-11 09:17:50 +08:00
Children = new Drawable[]
{
bodyContainer = new Container
2022-12-11 09:17:50 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0,
Children = new Drawable[]
{
spinnerCircle = new Sprite
{
Texture = skin.GetTexture("spinner-circle"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.8f),
},
approachCircle = new Sprite
{
Texture = skin.GetTexture("spinner-approachcircle"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1.86f * 0.8f),
2025-02-12 17:55:57 +08:00
Alpha = 0.8f,
},
2025-02-12 17:55:57 +08:00
remainingHitsText = new LegacySpriteText(LegacyFont.Score)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2025-02-12 17:55:57 +08:00
Position = new Vector2(0f, 130f),
Scale = Vector2.One,
},
}
},
clearAnimation = new Sprite
{
Texture = skin.GetTexture("spinner-osu"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0,
2025-02-12 17:55:57 +08:00
Y = -40,
},
2022-12-11 09:17:50 +08:00
},
},
2022-12-11 09:17:50 +08:00
};
drawableSwell = (DrawableSwell)hitObject;
drawableSwell.UpdateHitProgress += animateSwellProgress;
drawableSwell.ApplyCustomUpdateState += updateStateTransforms;
2022-12-11 09:17:50 +08:00
clearSample = skin.GetSample(new SampleInfo("spinner-osu"));
}
private void animateSwellProgress(int numHits)
{
this.numHits = numHits;
remainingHitsText.Text = (drawableSwell.HitObject.RequiredHits - numHits).ToString(CultureInfo.InvariantCulture);
spinnerCircle.Scale = new Vector2(Math.Min(0.94f, spinnerCircle.Scale.X + 0.02f));
}
protected override void Update()
2022-12-11 09:17:50 +08:00
{
base.Update();
int requiredHits = drawableSwell.HitObject.RequiredHits;
int remainingHits = requiredHits - numHits;
remainingHitsText.Scale = new Vector2((float)Interpolation.DampContinuously(
remainingHitsText.Scale.X, 1.6f - (0.6f * ((float)remainingHits / requiredHits)), 17.5, Math.Abs(Time.Elapsed)));
spinnerCircle.Rotation = (float)Interpolation.DampContinuously(spinnerCircle.Rotation, 180f * numHits, 130, Math.Abs(Time.Elapsed));
spinnerCircle.Scale = new Vector2((float)Interpolation.DampContinuously(
spinnerCircle.Scale.X, 0.8f, 120, Math.Abs(Time.Elapsed)));
2022-12-11 09:17:50 +08:00
}
private void updateStateTransforms(DrawableHitObject drawableHitObject, ArmedState state)
2022-12-11 09:17:50 +08:00
{
2025-01-31 20:48:29 +08:00
if (!(drawableHitObject is DrawableSwell))
return;
2022-12-11 09:17:50 +08:00
Swell swell = drawableSwell.HitObject;
2022-12-11 09:17:50 +08:00
using (BeginAbsoluteSequence(swell.StartTime))
2022-12-11 09:17:50 +08:00
{
if (state == ArmedState.Idle)
2022-12-11 09:17:50 +08:00
{
remainingHitsText.Text = $"{swell.RequiredHits}";
samplePlayed = false;
2022-12-11 09:17:50 +08:00
}
const double body_transition_duration = 200;
warning.MoveTo(swell_display_position, body_transition_duration)
.ScaleTo(3, body_transition_duration, Easing.Out)
.FadeOut(body_transition_duration);
bodyContainer.FadeIn(body_transition_duration);
approachCircle.ResizeTo(0.1f * 0.8f, swell.Duration);
2022-12-11 09:17:50 +08:00
}
using (BeginAbsoluteSequence(drawableSwell.HitStateUpdateTime))
2022-12-11 09:17:50 +08:00
{
const double clear_transition_duration = 300;
const double clear_fade_in = 120;
bodyContainer.FadeOut(clear_transition_duration, Easing.OutQuad);
spinnerCircle.ScaleTo(spinnerCircle.Scale.X + 0.05f, clear_transition_duration, Easing.OutQuad);
if (state == ArmedState.Hit)
{
if (!samplePlayed)
{
clearSample?.Play();
samplePlayed = true;
}
clearAnimation
2025-02-12 17:55:57 +08:00
.MoveToOffset(new Vector2(0, -90 * scale_adjust), clear_fade_in * 2, Easing.Out)
.ScaleTo(0.4f)
.ScaleTo(1f, clear_fade_in * 2, Easing.Out)
2025-02-12 17:55:57 +08:00
.FadeIn()
.Delay(clear_fade_in * 3)
.FadeOut(clear_fade_in * 2.5);
}
2022-12-11 09:17:50 +08:00
}
}
2022-12-11 09:17:50 +08:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
2022-12-11 09:17:50 +08:00
if (drawableSwell.IsNotNull())
{
drawableSwell.UpdateHitProgress -= animateSwellProgress;
drawableSwell.ApplyCustomUpdateState -= updateStateTransforms;
}
2022-12-11 09:17:50 +08:00
}
}
}