2019-01-24 16:43:03 +08:00
|
|
|
|
// 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
|
|
|
|
|
2018-11-16 04:37:21 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class ScoreCounter : RollingCounter<double>
|
|
|
|
|
{
|
|
|
|
|
protected override double RollingDuration => 1000;
|
|
|
|
|
protected override Easing RollingEasing => Easing.Out;
|
|
|
|
|
|
|
|
|
|
public bool UseCommaSeparator;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// How many leading zeroes the counter has.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public uint LeadingZeroes
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
protected set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays score.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="leading">How many leading zeroes the counter will have.</param>
|
|
|
|
|
public ScoreCounter(uint leading = 0)
|
|
|
|
|
{
|
2019-02-20 18:32:30 +08:00
|
|
|
|
DisplayedCountSpriteText.Font = DisplayedCountSpriteText.Font.With(fixedWidth: true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
LeadingZeroes = leading;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-16 04:37:21 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours) => AccentColour = colours.BlueLighter;
|
|
|
|
|
|
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', (int)LeadingZeroes);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Increment(double amount)
|
|
|
|
|
{
|
2019-11-12 17:56:38 +08:00
|
|
|
|
Current.Value += amount;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|