// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Bindables; using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics; using osu.Framework.Localisation; using osu.Game.Graphics.Sprites; namespace osu.Game.Graphics.UserInterface { public abstract class ScoreCounter : RollingCounter { protected override double RollingDuration => 1000; protected override Easing RollingEasing => Easing.Out; public Bindable RequiredDisplayDigits { get; } = new Bindable(); private string formatString = string.Empty; /// /// Displays score. /// /// How many leading zeroes the counter will have. /// Whether comma separators should be displayed. protected ScoreCounter(int leading = 0, bool useCommaSeparator = false) { if (useCommaSeparator) { if (leading > 0) throw new ArgumentException("Should not mix leading zeroes and comma separators as it doesn't make sense"); formatString = @"N0"; } RequiredDisplayDigits.Value = leading; RequiredDisplayDigits.BindValueChanged(displayDigitsChanged, true); } private void displayDigitsChanged(ValueChangedEvent _) { formatString = new string('0', RequiredDisplayDigits.Value); UpdateDisplay(); } protected override double GetProportionalDuration(double currentValue, double newValue) { return currentValue > newValue ? currentValue - newValue : newValue - currentValue; } protected override LocalisableString FormatCount(double count) => ((long)count).ToLocalisableString(formatString); protected override OsuSpriteText CreateSpriteText() => base.CreateSpriteText().With(s => s.Font = s.Font.With(fixedWidth: true)); } }