1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 08:07:24 +08:00

Merge pull request #15021 from peppy/tournament-comma-separators

Use comma separator for tournament score displays
This commit is contained in:
Dean Herbert 2021-10-11 10:43:34 +09:00 committed by GitHub
commit 2eb29ed0de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 33 deletions

View File

@ -127,7 +127,7 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
score2Text.X = Math.Max(5 + score2Text.DrawWidth / 2, score2Bar.DrawWidth);
}
private class MatchScoreCounter : ScoreCounter
private class MatchScoreCounter : CommaSeparatedScoreCounter
{
private OsuSpriteText displayedSpriteText;

View File

@ -0,0 +1,24 @@
// 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.
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 CommaSeparatedScoreCounter : RollingCounter<double>
{
protected override double RollingDuration => 1000;
protected override Easing RollingEasing => Easing.Out;
protected override double GetProportionalDuration(double currentValue, double newValue) =>
currentValue > newValue ? currentValue - newValue : newValue - currentValue;
protected override LocalisableString FormatCount(double count) => ((long)count).ToLocalisableString(@"N0");
protected override OsuSpriteText CreateSpriteText()
=> base.CreateSpriteText().With(s => s.Font = s.Font.With(fixedWidth: true));
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Graphics.Sprites;
@ -13,43 +14,30 @@ namespace osu.Game.Graphics.UserInterface
protected override double RollingDuration => 1000;
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>();
private string formatString;
/// <summary>
/// Displays score.
/// </summary>
/// <param name="leading">How many leading zeroes the counter will have.</param>
/// <param name="useCommaSeparator">Whether comma separators should be displayed.</param>
protected ScoreCounter(int leading = 0, bool useCommaSeparator = false)
protected ScoreCounter(int leading = 0)
{
UseCommaSeparator = useCommaSeparator;
RequiredDisplayDigits.Value = leading;
RequiredDisplayDigits.BindValueChanged(_ => UpdateDisplay());
RequiredDisplayDigits.BindValueChanged(displayDigitsChanged, true);
}
protected override double GetProportionalDuration(double currentValue, double newValue)
private void displayDigitsChanged(ValueChangedEvent<int> _)
{
return currentValue > newValue ? currentValue - newValue : newValue - currentValue;
formatString = new string('0', RequiredDisplayDigits.Value);
UpdateDisplay();
}
protected override LocalisableString FormatCount(double count)
{
string format = new string('0', RequiredDisplayDigits.Value);
protected override double GetProportionalDuration(double currentValue, double newValue) =>
currentValue > newValue ? currentValue - newValue : newValue - currentValue;
if (UseCommaSeparator)
{
for (int i = format.Length - 3; i > 0; i -= 3)
format = format.Insert(i, @",");
}
return ((long)count).ToString(format);
}
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));

View File

@ -11,7 +11,6 @@ namespace osu.Game.Screens.Play.HUD
public class DefaultScoreCounter : GameplayScoreCounter, ISkinnableDrawable
{
public DefaultScoreCounter()
: base(6)
{
Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre;

View File

@ -14,8 +14,8 @@ namespace osu.Game.Screens.Play.HUD
{
private Bindable<ScoringMode> scoreDisplayMode;
protected GameplayScoreCounter(int leading = 0, bool useCommaSeparator = false)
: base(leading, useCommaSeparator)
protected GameplayScoreCounter()
: base(6)
{
}

View File

@ -4,11 +4,9 @@
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
@ -148,7 +146,7 @@ namespace osu.Game.Screens.Play.HUD
Score2Text.X = Math.Max(5 + Score2Text.DrawWidth / 2, score2Bar.DrawWidth);
}
protected class MatchScoreCounter : ScoreCounter
protected class MatchScoreCounter : CommaSeparatedScoreCounter
{
private OsuSpriteText displayedSpriteText;
@ -173,8 +171,6 @@ namespace osu.Game.Screens.Play.HUD
=> displayedSpriteText.Font = winning
? OsuFont.Torus.With(weight: FontWeight.Bold, size: font_size, fixedWidth: true)
: OsuFont.Torus.With(weight: FontWeight.Regular, size: font_size * 0.8f, fixedWidth: true);
protected override LocalisableString FormatCount(double count) => count.ToLocalisableString(@"N0");
}
}
}

View File

@ -16,7 +16,6 @@ namespace osu.Game.Skinning
public bool UsesFixedAnchor { get; set; }
public LegacyScoreCounter()
: base(6)
{
Anchor = Anchor.TopRight;
Origin = Anchor.TopRight;