1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 13:22:55 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/ScoreCounter.cs

58 lines
2.0 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.
2018-04-13 17:19:50 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Play.HUD;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Graphics.UserInterface
{
public abstract class ScoreCounter : RollingCounter<double>, IScoreCounter
2018-04-13 17:19:50 +08:00
{
protected override double RollingDuration => 1000;
protected override Easing RollingEasing => Easing.Out;
/// <summary>
/// Whether comma separators should be displayed.
/// </summary>
public bool UseCommaSeparator { get; }
2018-04-13 17:19:50 +08:00
public Bindable<int> RequiredDisplayDigits { get; } = new Bindable<int>();
2018-04-13 17:19:50 +08:00
/// <summary>
/// Displays score.
/// </summary>
/// <param name="leading">How many leading zeroes the counter will have.</param>
/// <param name="useCommaSeparator">Whether comma separators should be displayed.</param>
protected ScoreCounter(int leading = 0, bool useCommaSeparator = false)
2018-04-13 17:19:50 +08:00
{
UseCommaSeparator = useCommaSeparator;
RequiredDisplayDigits.Value = leading;
RequiredDisplayDigits.BindValueChanged(_ => UpdateDisplay());
2018-04-13 17:19:50 +08:00
}
protected override double GetProportionalDuration(double currentValue, double newValue)
{
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
}
protected override string FormatCount(double count)
{
string format = new string('0', RequiredDisplayDigits.Value);
2019-11-11 20:05:36 +08:00
2018-04-13 17:19:50 +08:00
if (UseCommaSeparator)
2019-11-11 19:53:22 +08:00
{
2018-04-13 17:19:50 +08:00
for (int i = format.Length - 3; i > 0; i -= 3)
format = format.Insert(i, @",");
2019-11-11 19:53:22 +08:00
}
2018-04-13 17:19:50 +08:00
return ((long)count).ToString(format);
}
protected override OsuSpriteText CreateSpriteText()
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(fixedWidth: true));
2018-04-13 17:19:50 +08:00
}
}