Restructure explosion to ensure proper lifetime bounds

This commit is contained in:
Bartłomiej Dach
2021-08-07 18:19:29 +02:00
parent 8c8a64fe6e
commit 4bcbe6ac90
4 changed files with 32 additions and 34 deletions

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -15,11 +14,8 @@ using osuTK.Graphics;
namespace osu.Game.Rulesets.Catch.Skinning.Default namespace osu.Game.Rulesets.Catch.Skinning.Default
{ {
public class DefaultHitExplosion : CompositeDrawable public class DefaultHitExplosion : CompositeDrawable, IHitExplosion
{ {
[Resolved]
private Bindable<HitExplosionEntry> entryBindable { get; set; }
private CircularContainer largeFaint; private CircularContainer largeFaint;
private CircularContainer smallFaint; private CircularContainer smallFaint;
private CircularContainer directionalGlow1; private CircularContainer directionalGlow1;
@ -74,14 +70,7 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
}; };
} }
protected override void LoadComplete() public void Animate(HitExplosionEntry entry)
{
base.LoadComplete();
entryBindable.BindValueChanged(entry => apply(entry.NewValue), true);
}
private void apply(HitExplosionEntry entry)
{ {
if (entry == null) if (entry == null)
return; return;
@ -110,7 +99,7 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
directionalGlow1.Rotation = StatelessRNG.NextSingle(-angle_variangle, angle_variangle, randomSeed, 4); directionalGlow1.Rotation = StatelessRNG.NextSingle(-angle_variangle, angle_variangle, randomSeed, 4);
directionalGlow2.Rotation = StatelessRNG.NextSingle(-angle_variangle, angle_variangle, randomSeed, 5); directionalGlow2.Rotation = StatelessRNG.NextSingle(-angle_variangle, angle_variangle, randomSeed, 5);
this.FadeInFromZero(50).Then().FadeOut(duration, Easing.Out).Expire(); this.FadeInFromZero(50).Then().FadeOut(duration, Easing.Out);
} }
private void setColour(Color4 objectColour) private void setColour(Color4 objectColour)

View File

@ -3,7 +3,6 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
@ -14,14 +13,11 @@ using osuTK;
namespace osu.Game.Rulesets.Catch.Skinning.Legacy namespace osu.Game.Rulesets.Catch.Skinning.Legacy
{ {
public class LegacyHitExplosion : CompositeDrawable public class LegacyHitExplosion : CompositeDrawable, IHitExplosion
{ {
[Resolved] [Resolved]
private Catcher catcher { get; set; } private Catcher catcher { get; set; }
[Resolved]
private Bindable<HitExplosionEntry> entryBindable { get; set; }
private const float catch_margin = (1 - Catcher.ALLOWED_CATCH_RANGE) / 2; private const float catch_margin = (1 - Catcher.ALLOWED_CATCH_RANGE) / 2;
private readonly Sprite explosion1; private readonly Sprite explosion1;
@ -62,14 +58,7 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
explosion2.Texture = defaultLegacySkin.GetTexture("scoreboard-explosion-1"); explosion2.Texture = defaultLegacySkin.GetTexture("scoreboard-explosion-1");
} }
protected override void LoadComplete() public void Animate(HitExplosionEntry entry)
{
base.LoadComplete();
entryBindable.BindValueChanged(entry => apply(entry.NewValue), true);
}
private void apply(HitExplosionEntry entry)
{ {
if (entry == null) if (entry == null)
return; return;
@ -88,15 +77,17 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
explosion1.Scale = new Vector2(1, 0.9f); explosion1.Scale = new Vector2(1, 0.9f);
explosion1.Position = new Vector2(explosionOffset, 0); explosion1.Position = new Vector2(explosionOffset, 0);
explosion1.FadeOut(300); explosion1.FadeOutFromOne(300);
explosion1.ScaleTo(new Vector2(20 * scale, 1.1f), 160, Easing.Out); explosion1.ScaleTo(new Vector2(20 * scale, 1.1f), 160, Easing.Out);
} }
explosion2.Scale = new Vector2(0.9f, 1); explosion2.Scale = new Vector2(0.9f, 1);
explosion2.Position = new Vector2(explosionOffset, 0); explosion2.Position = new Vector2(explosionOffset, 0);
explosion2.FadeOut(700); explosion2.FadeOutFromOne(700);
explosion2.ScaleTo(new Vector2(0.9f, 1.3f), 500, Easing.Out); explosion2.ScaleTo(new Vector2(0.9f, 1.3f), 500, Easing.Out);
this.Delay(700).FadeOutFromOne();
} }
} }
} }

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch.Skinning.Default; using osu.Game.Rulesets.Catch.Skinning.Default;
using osu.Game.Rulesets.Objects.Pooling; using osu.Game.Rulesets.Objects.Pooling;
@ -12,8 +11,7 @@ namespace osu.Game.Rulesets.Catch.UI
{ {
public class HitExplosion : PoolableDrawableWithLifetime<HitExplosionEntry> public class HitExplosion : PoolableDrawableWithLifetime<HitExplosionEntry>
{ {
[Cached] private SkinnableDrawable skinnableExplosion;
private Bindable<HitExplosionEntry> bindableEntry { get; set; } = new Bindable<HitExplosionEntry>();
public HitExplosion() public HitExplosion()
{ {
@ -25,7 +23,7 @@ namespace osu.Game.Rulesets.Catch.UI
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
InternalChild = new SkinnableDrawable(new CatchSkinComponent(CatchSkinComponents.HitExplosion), _ => new DefaultHitExplosion()) InternalChild = skinnableExplosion = new SkinnableDrawable(new CatchSkinComponent(CatchSkinComponents.HitExplosion), _ => new DefaultHitExplosion())
{ {
CentreComponent = false, CentreComponent = false,
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
@ -37,7 +35,11 @@ namespace osu.Game.Rulesets.Catch.UI
{ {
base.OnApply(entry); base.OnApply(entry);
bindableEntry.Value = entry; ApplyTransformsAt(double.MinValue, true);
ClearTransforms(true);
(skinnableExplosion.Drawable as IHitExplosion)?.Animate(entry);
LifetimeEnd = skinnableExplosion.Drawable.LatestTransformEndTime;
} }
} }
} }

View File

@ -0,0 +1,16 @@
// 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.
namespace osu.Game.Rulesets.Catch.UI
{
/// <summary>
/// Common interface for all hit explosion skinnables.
/// </summary>
public interface IHitExplosion
{
/// <summary>
/// Begins animating this <see cref="IHitExplosion"/>.
/// </summary>
void Animate(HitExplosionEntry entry);
}
}