Don't recreate explosion counter each increment

This commit is contained in:
Dean Herbert 2020-09-22 12:24:26 +09:00
parent f629c33dc0
commit a27a65bf03
1 changed files with 22 additions and 37 deletions

View File

@ -16,19 +16,14 @@ namespace osu.Game.Rulesets.Catch.Skinning
/// </summary>
public class LegacyComboCounter : CompositeDrawable, ICatchComboCounter
{
private readonly ISkin skin;
private readonly string fontName;
private readonly float fontOverlap;
private readonly LegacyRollingCounter counter;
private readonly LegacyRollingCounter explosion;
public LegacyComboCounter(ISkin skin)
{
this.skin = skin;
fontName = skin.GetConfig<LegacySetting, string>(LegacySetting.ComboPrefix)?.Value ?? "score";
fontOverlap = skin.GetConfig<LegacySetting, float>(LegacySetting.ComboOverlap)?.Value ?? -2f;
var fontName = skin.GetConfig<LegacySetting, string>(LegacySetting.ComboPrefix)?.Value ?? "score";
var fontOverlap = skin.GetConfig<LegacySetting, float>(LegacySetting.ComboOverlap)?.Value ?? -2f;
AutoSizeAxes = Axes.Both;
@ -37,18 +32,27 @@ public LegacyComboCounter(ISkin skin)
Origin = Anchor.Centre;
Scale = new Vector2(0.8f);
InternalChild = counter = new LegacyRollingCounter(skin, fontName, fontOverlap)
InternalChildren = new Drawable[]
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
explosion = new LegacyRollingCounter(skin, fontName, fontOverlap)
{
Alpha = 0.65f,
Blending = BlendingParameters.Additive,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1.5f),
},
counter = new LegacyRollingCounter(skin, fontName, fontOverlap)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
};
}
public void DisplayInitialCombo(int combo) => updateCombo(combo, null, true);
public void UpdateCombo(int combo, Color4? hitObjectColour) => updateCombo(combo, hitObjectColour, false);
private LegacyRollingCounter lastExplosion;
private void updateCombo(int combo, Color4? hitObjectColour, bool immediate)
{
// There may still be existing transforms to the counter (including value change after 250ms),
@ -59,17 +63,12 @@ private void updateCombo(int combo, Color4? hitObjectColour, bool immediate)
if (combo == 0)
{
counter.Current.Value = 0;
if (lastExplosion != null)
lastExplosion.Current.Value = 0;
explosion.Current.Value = 0;
this.FadeOut(immediate ? 0.0 : 400.0, Easing.Out);
return;
}
// Remove last explosion to not conflict with the upcoming one.
if (lastExplosion != null)
RemoveInternal(lastExplosion);
this.FadeIn().Delay(1000.0).FadeOut(300.0);
// For simplicity, in the case of rewinding we'll just set the counter to the current combo value.
@ -86,25 +85,11 @@ private void updateCombo(int combo, Color4? hitObjectColour, bool immediate)
counter.Delay(250.0).ScaleTo(1f).ScaleTo(1.1f, 60.0).Then().ScaleTo(1f, 30.0);
var explosion = new LegacyRollingCounter(skin, fontName, fontOverlap)
{
Alpha = 0.65f,
Blending = BlendingParameters.Additive,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1.5f),
Colour = hitObjectColour ?? Color4.White,
Depth = 1f,
};
AddInternal(explosion);
explosion.Colour = hitObjectColour ?? Color4.White;
explosion.SetCountWithoutRolling(combo);
explosion.ScaleTo(1.9f, 400.0, Easing.Out)
.FadeOut(400.0)
.Expire(true);
lastExplosion = explosion;
explosion.ScaleTo(1.5f).ScaleTo(1.9f, 400.0, Easing.Out)
.FadeOutFromOne(400.0);
}
}
}