Use rolling counter for multiplier display

This commit is contained in:
Bartłomiej Dach 2022-02-20 16:02:46 +01:00
parent 78a3b5961e
commit c25d7a1c75
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
1 changed files with 22 additions and 6 deletions

View File

@ -9,8 +9,10 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Mods;
using osuTK;
@ -24,12 +26,15 @@ public Bindable<double> Current
set => current.Current = value;
}
private readonly BindableNumberWithCurrent<double> current = new BindableNumberWithCurrent<double>(1);
private readonly BindableNumberWithCurrent<double> current = new BindableNumberWithCurrent<double>(1)
{
Precision = 0.1
};
private readonly Box underlayBackground;
private readonly Box contentBackground;
private readonly FillFlowContainer multiplierFlow;
private readonly OsuSpriteText multiplierText;
private readonly MultiplierCounter multiplierCounter;
[Resolved]
private OsuColour colours { get; set; }
@ -107,11 +112,11 @@ public DifficultyMultiplierDisplay()
Spacing = new Vector2(2, 0),
Children = new Drawable[]
{
multiplierText = new OsuSpriteText
multiplierCounter = new MultiplierCounter
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
Current = { BindTarget = Current }
},
new SpriteIcon
{
@ -141,12 +146,11 @@ protected override void LoadComplete()
base.LoadComplete();
current.BindValueChanged(_ => updateState(), true);
FinishTransforms(true);
multiplierCounter.StopRolling();
}
private void updateState()
{
multiplierText.Text = current.Value.ToLocalisableString(@"N1");
if (Current.IsDefault)
{
underlayBackground.FadeColour(colourProvider.Background3, transition_duration, Easing.OutQuint);
@ -162,5 +166,17 @@ private void updateState()
multiplierFlow.FadeColour(colourProvider.Background5, transition_duration, Easing.OutQuint);
}
}
private class MultiplierCounter : RollingCounter<double>
{
protected override double RollingDuration => 500;
protected override LocalisableString FormatCount(double count) => count.ToLocalisableString(@"N1");
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
{
Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold)
};
}
}
}