1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-24 15:13:06 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Skinning/Default/DefaultSwell.cs

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

191 lines
7.2 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 System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.ObjectExtensions;
2022-12-11 09:17:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
2022-12-11 09:17:50 +08:00
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
using osuTK;
2022-12-11 09:17:50 +08:00
using osuTK.Graphics;
namespace osu.Game.Rulesets.Taiko.Skinning.Default
{
public partial class DefaultSwell : Container
2022-12-11 09:17:50 +08:00
{
private const float target_ring_thick_border = 1.4f;
private const float target_ring_thin_border = 1f;
private const float target_ring_scale = 5f;
private const float inner_ring_alpha = 0.65f;
private DrawableSwell drawableSwell = null!;
2022-12-11 09:17:50 +08:00
private readonly Container bodyContainer;
private readonly CircularContainer targetRing;
private readonly CircularContainer expandingRing;
private readonly Drawable centreCircle;
private int numHits;
2022-12-11 09:17:50 +08:00
public DefaultSwell()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
Content.Add(bodyContainer = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2022-12-11 09:17:50 +08:00
RelativeSizeAxes = Axes.Both,
Depth = 1,
2025-01-31 20:48:29 +08:00
Children = new[]
2022-12-11 09:17:50 +08:00
{
expandingRing = new CircularContainer
{
Name = "Expanding ring",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0,
RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive,
Masking = true,
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = inner_ring_alpha,
}
}
},
targetRing = new CircularContainer
{
Name = "Target ring (thick border)",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = target_ring_thick_border,
Blending = BlendingParameters.Additive,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
},
new CircularContainer
{
Name = "Target ring (thin border)",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = target_ring_thin_border,
BorderColour = Color4.White,
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
}
}
}
}
},
centreCircle = CreateCentreCircle(),
2022-12-11 09:17:50 +08:00
}
});
}
[BackgroundDependencyLoader]
private void load(DrawableHitObject hitObject, OsuColour colours)
{
drawableSwell = (DrawableSwell)hitObject;
drawableSwell.UpdateHitProgress += animateSwellProgress;
drawableSwell.ApplyCustomUpdateState += updateStateTransforms;
expandingRing.Colour = colours.YellowLight;
targetRing.BorderColour = colours.YellowDark.Opacity(0.25f);
}
protected virtual Drawable CreateCentreCircle()
{
2025-01-31 20:48:29 +08:00
return new SwellCirclePiece
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
}
private void animateSwellProgress(int numHits)
2022-12-11 09:17:50 +08:00
{
this.numHits = numHits;
2022-12-11 09:17:50 +08:00
float completion = (float)numHits / drawableSwell.HitObject.RequiredHits;
expandingRing.Alpha += Math.Clamp(completion / 16, 0.1f, 0.6f);
}
protected override void Update()
{
base.Update();
2022-12-11 09:17:50 +08:00
float completion = (float)numHits / drawableSwell.HitObject.RequiredHits;
2022-12-11 09:17:50 +08:00
centreCircle.Rotation = (float)Interpolation.DampContinuously(centreCircle.Rotation,
(float)(completion * drawableSwell.HitObject.Duration / 8), 500, Math.Abs(Time.Elapsed));
expandingRing.Scale = new Vector2((float)Interpolation.DampContinuously(expandingRing.Scale.X,
1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 35, Math.Abs(Time.Elapsed)));
expandingRing.Alpha = (float)Interpolation.DampContinuously(expandingRing.Alpha, completion / 16, 250, 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;
Swell swell = drawableSwell.HitObject;
using (BeginAbsoluteSequence(swell.StartTime))
{
if (state == ArmedState.Idle)
expandingRing.FadeTo(0);
const double ring_appear_offset = 100;
2022-12-11 09:17:50 +08:00
targetRing.Delay(ring_appear_offset).ScaleTo(target_ring_scale, 400, Easing.OutQuint);
}
using (BeginAbsoluteSequence(drawableSwell.HitStateUpdateTime))
{
const double transition_duration = 300;
bodyContainer.FadeOut(transition_duration, Easing.OutQuad);
bodyContainer.ScaleTo(1.4f, transition_duration);
centreCircle.FadeOut(transition_duration, Easing.OutQuad);
}
2022-12-11 09:17:50 +08:00
}
protected override void Dispose(bool isDisposing)
2022-12-11 09:17:50 +08:00
{
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
}
}
}