mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 22:23:32 +08:00
Use localisable format string for comma separator mode
This commit is contained in:
parent
446f091d32
commit
06cce0119c
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.LocalisationExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
@ -14,13 +15,10 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
protected override double RollingDuration => 1000;
|
protected override double RollingDuration => 1000;
|
||||||
protected override Easing RollingEasing => Easing.Out;
|
protected override Easing RollingEasing => Easing.Out;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether comma separators should be displayed.
|
|
||||||
/// </summary>
|
|
||||||
public bool UseCommaSeparator { get; }
|
|
||||||
|
|
||||||
public Bindable<int> RequiredDisplayDigits { get; } = new Bindable<int>();
|
public Bindable<int> RequiredDisplayDigits { get; } = new Bindable<int>();
|
||||||
|
|
||||||
|
private string formatString = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Displays score.
|
/// Displays score.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -28,13 +26,22 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
/// <param name="useCommaSeparator">Whether comma separators should be displayed.</param>
|
/// <param name="useCommaSeparator">Whether comma separators should be displayed.</param>
|
||||||
protected ScoreCounter(int leading = 0, bool useCommaSeparator = false)
|
protected ScoreCounter(int leading = 0, bool useCommaSeparator = false)
|
||||||
{
|
{
|
||||||
UseCommaSeparator = useCommaSeparator;
|
if (useCommaSeparator)
|
||||||
|
{
|
||||||
if (useCommaSeparator && leading > 0)
|
if (leading > 0)
|
||||||
throw new ArgumentException("Should not mix leading zeroes and comma separators as it doesn't make sense");
|
throw new ArgumentException("Should not mix leading zeroes and comma separators as it doesn't make sense");
|
||||||
|
|
||||||
|
formatString = @"N0";
|
||||||
|
}
|
||||||
|
|
||||||
RequiredDisplayDigits.Value = leading;
|
RequiredDisplayDigits.Value = leading;
|
||||||
RequiredDisplayDigits.BindValueChanged(_ => UpdateDisplay());
|
RequiredDisplayDigits.BindValueChanged(displayDigitsChanged, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayDigitsChanged(ValueChangedEvent<int> _)
|
||||||
|
{
|
||||||
|
formatString = new string('0', RequiredDisplayDigits.Value);
|
||||||
|
UpdateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override double GetProportionalDuration(double currentValue, double newValue)
|
protected override double GetProportionalDuration(double currentValue, double newValue)
|
||||||
@ -42,19 +49,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override LocalisableString FormatCount(double count)
|
protected override LocalisableString FormatCount(double count) => ((long)count).ToLocalisableString(formatString);
|
||||||
{
|
|
||||||
string format = new string('0', RequiredDisplayDigits.Value);
|
|
||||||
var output = ((long)count).ToString(format);
|
|
||||||
|
|
||||||
if (UseCommaSeparator)
|
|
||||||
{
|
|
||||||
for (int i = output.Length - 3; i > 0; i -= 3)
|
|
||||||
output = output.Insert(i, @",");
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override OsuSpriteText CreateSpriteText()
|
protected override OsuSpriteText CreateSpriteText()
|
||||||
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(fixedWidth: true));
|
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(fixedWidth: true));
|
||||||
|
@ -11,7 +11,6 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
public class DefaultScoreCounter : GameplayScoreCounter, ISkinnableDrawable
|
public class DefaultScoreCounter : GameplayScoreCounter, ISkinnableDrawable
|
||||||
{
|
{
|
||||||
public DefaultScoreCounter()
|
public DefaultScoreCounter()
|
||||||
: base(6)
|
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopCentre;
|
Anchor = Anchor.TopCentre;
|
||||||
Origin = Anchor.TopCentre;
|
Origin = Anchor.TopCentre;
|
||||||
|
@ -14,8 +14,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
private Bindable<ScoringMode> scoreDisplayMode;
|
private Bindable<ScoringMode> scoreDisplayMode;
|
||||||
|
|
||||||
protected GameplayScoreCounter(int leading = 0, bool useCommaSeparator = false)
|
protected GameplayScoreCounter()
|
||||||
: base(leading, useCommaSeparator)
|
: base(6)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ namespace osu.Game.Skinning
|
|||||||
public bool UsesFixedAnchor { get; set; }
|
public bool UsesFixedAnchor { get; set; }
|
||||||
|
|
||||||
public LegacyScoreCounter()
|
public LegacyScoreCounter()
|
||||||
: base(6)
|
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopRight;
|
Anchor = Anchor.TopRight;
|
||||||
Origin = Anchor.TopRight;
|
Origin = Anchor.TopRight;
|
||||||
|
Loading…
Reference in New Issue
Block a user