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