Allow switching between legacy sprites

This commit is contained in:
Bartłomiej Dach 2020-09-27 16:07:19 +02:00
parent eb62ad4e55
commit 2f7c0b4934
1 changed files with 32 additions and 1 deletions

View File

@ -1,9 +1,12 @@
// 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.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
namespace osu.Game.Rulesets.Taiko.Skinning
{
@ -12,6 +15,9 @@ public class LegacyHitExplosion : CompositeDrawable
private readonly Drawable sprite;
private readonly Drawable strongSprite;
private DrawableHit hit;
private DrawableStrongNestedHit nestedStrongHit;
/// <summary>
/// Creates a new legacy hit explosion.
/// </summary>
@ -28,7 +34,7 @@ public LegacyHitExplosion(Drawable sprite, Drawable strongSprite = null)
}
[BackgroundDependencyLoader]
private void load()
private void load(DrawableHitObject judgedObject)
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
@ -39,6 +45,12 @@ private void load()
if (strongSprite != null)
AddInternal(strongSprite.With(s => s.Alpha = 0));
if (judgedObject is DrawableHit h)
{
hit = h;
nestedStrongHit = hit.NestedHitObjects.SingleOrDefault() as DrawableStrongNestedHit;
}
}
protected override void LoadComplete()
@ -56,5 +68,24 @@ protected override void LoadComplete()
Expire(true);
}
protected override void Update()
{
base.Update();
if (shouldSwitchToStrongSprite() && strongSprite != null)
{
sprite.FadeOut(50, Easing.OutQuint);
strongSprite.FadeIn(50, Easing.OutQuint);
}
}
private bool shouldSwitchToStrongSprite()
{
if (hit == null || nestedStrongHit == null)
return false;
return hit.Result.Type == nestedStrongHit.Result.Type;
}
}
}