1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 00:22:57 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Skinning/LegacyHitExplosion.cs

101 lines
3.1 KiB
C#
Raw Normal View History

// 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-09-27 22:07:19 +08:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-09-27 22:07:19 +08:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
namespace osu.Game.Rulesets.Taiko.Skinning
{
public class LegacyHitExplosion : CompositeDrawable
{
private readonly Drawable sprite;
private readonly Drawable strongSprite;
2020-09-27 22:07:19 +08:00
private DrawableStrongNestedHit nestedStrongHit;
2020-09-28 22:38:30 +08:00
private bool switchedToStrongSprite;
2020-09-27 22:07:19 +08:00
/// <summary>
/// Creates a new legacy hit explosion.
/// </summary>
/// <remarks>
/// Contrary to stable's, this implementation doesn't require a frame-perfect hit
/// for the strong sprite to be displayed.
/// </remarks>
/// <param name="sprite">The normal legacy explosion sprite.</param>
/// <param name="strongSprite">The strong legacy explosion sprite.</param>
public LegacyHitExplosion(Drawable sprite, Drawable strongSprite = null)
{
this.sprite = sprite;
this.strongSprite = strongSprite;
}
[BackgroundDependencyLoader]
2020-09-27 22:07:19 +08:00
private void load(DrawableHitObject judgedObject)
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
AutoSizeAxes = Axes.Both;
2020-09-28 00:11:12 +08:00
AddInternal(sprite.With(s =>
{
s.Anchor = Anchor.Centre;
s.Origin = Anchor.Centre;
}));
if (strongSprite != null)
2020-09-28 00:11:12 +08:00
{
AddInternal(strongSprite.With(s =>
{
s.Alpha = 0;
s.Anchor = Anchor.Centre;
s.Origin = Anchor.Centre;
}));
}
2020-09-27 22:07:19 +08:00
2020-09-28 22:59:33 +08:00
if (judgedObject is DrawableHit hit)
2020-09-27 22:07:19 +08:00
nestedStrongHit = hit.NestedHitObjects.SingleOrDefault() as DrawableStrongNestedHit;
}
protected override void LoadComplete()
{
base.LoadComplete();
const double animation_time = 120;
this.FadeInFromZero(animation_time).Then().FadeOut(animation_time * 1.5);
this.ScaleTo(0.6f)
.Then().ScaleTo(1.1f, animation_time * 0.8)
.Then().ScaleTo(0.9f, animation_time * 0.4)
.Then().ScaleTo(1f, animation_time * 0.2);
Expire(true);
}
2020-09-27 22:07:19 +08:00
protected override void Update()
{
base.Update();
2020-09-28 22:38:30 +08:00
if (shouldSwitchToStrongSprite() && !switchedToStrongSprite)
2020-09-27 22:07:19 +08:00
{
sprite.FadeOut(50, Easing.OutQuint);
strongSprite.FadeIn(50, Easing.OutQuint);
2020-09-28 22:38:30 +08:00
switchedToStrongSprite = true;
2020-09-27 22:07:19 +08:00
}
}
private bool shouldSwitchToStrongSprite()
{
2020-09-28 22:59:33 +08:00
if (nestedStrongHit == null || strongSprite == null)
2020-09-27 22:07:19 +08:00
return false;
return nestedStrongHit.IsHit;
2020-09-27 22:07:19 +08:00
}
}
}