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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.7 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
2022-06-17 15:37:17 +08:00
#nullable disable
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
2016-10-14 06:13:20 +08:00
using osu.Framework.Graphics;
2021-07-24 04:37:08 +08:00
using osu.Framework.Localisation;
using osu.Game.Graphics.Sprites;
2018-04-13 17:19:50 +08:00
2016-10-07 15:05:02 +08:00
namespace osu.Game.Graphics.UserInterface
{
2022-11-07 06:59:27 +08:00
public abstract partial class ScoreCounter : RollingCounter<long>
2016-10-07 15:05:02 +08:00
{
2016-10-18 10:40:50 +08:00
protected override double RollingDuration => 1000;
2017-07-23 02:50:25 +08:00
protected override Easing RollingEasing => Easing.Out;
2018-04-13 17:19:50 +08:00
public Bindable<int> RequiredDisplayDigits { get; } = new Bindable<int>();
2018-04-13 17:19:50 +08:00
private string formatString;
/// <summary>
/// Displays score.
/// </summary>
/// <param name="leading">How many leading zeroes the counter will have.</param>
protected ScoreCounter(int leading = 0)
2016-10-13 03:33:04 +08:00
{
RequiredDisplayDigits.Value = leading;
RequiredDisplayDigits.BindValueChanged(displayDigitsChanged, true);
2016-10-13 03:33:04 +08:00
}
2018-04-13 17:19:50 +08:00
private void displayDigitsChanged(ValueChangedEvent<int> _)
2016-10-14 06:13:20 +08:00
{
formatString = new string('0', RequiredDisplayDigits.Value);
UpdateDisplay();
2016-10-14 06:13:20 +08:00
}
2018-04-13 17:19:50 +08:00
2022-11-07 06:59:27 +08:00
protected override double GetProportionalDuration(long currentValue, long newValue) =>
currentValue > newValue ? currentValue - newValue : newValue - currentValue;
2018-04-13 17:19:50 +08:00
2022-11-07 06:59:27 +08:00
protected override LocalisableString FormatCount(long count) => count.ToLocalisableString(formatString);
protected override OsuSpriteText CreateSpriteText()
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(fixedWidth: true));
2016-10-07 15:05:02 +08:00
}
}