mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 08:22:56 +08:00
Remove humanized number dependency
This commit is contained in:
parent
5b09daef1a
commit
ff477cd56c
@ -1,58 +0,0 @@
|
||||
// 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.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneMetricNumbers : OsuTestScene
|
||||
{
|
||||
public TestSceneMetricNumbers()
|
||||
{
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new DrawableNumber(0),
|
||||
new DrawableNumber(1001),
|
||||
new DrawableNumber(999_999),
|
||||
new DrawableNumber(1_000_000),
|
||||
new DrawableNumber(845_006_456),
|
||||
new DrawableNumber(999_999_999),
|
||||
new DrawableNumber(1_000_000_000),
|
||||
new DrawableNumber(7_875_454_545),
|
||||
new DrawableNumber(999_999_999_999),
|
||||
new DrawableNumber(1_000_000_000_000),
|
||||
new DrawableNumber(687_545_454_554_545),
|
||||
new DrawableNumber(999_999_999_999_999),
|
||||
new DrawableNumber(1_000_000_000_000_000),
|
||||
new DrawableNumber(587_545_454_554_545_455),
|
||||
new DrawableNumber(999_999_999_999_999_999),
|
||||
new DrawableNumber(1_000_000_000_000_000_000),
|
||||
new DrawableNumber(long.MaxValue),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private class DrawableNumber : SpriteText, IHasTooltip
|
||||
{
|
||||
public string TooltipText => value.ToString("F0");
|
||||
|
||||
private readonly long value;
|
||||
|
||||
public DrawableNumber(long value)
|
||||
{
|
||||
this.value = value;
|
||||
Text = HumanizerUtils.ToReadableString(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -50,22 +50,33 @@ namespace osu.Game.Overlays.Rankings.Tables
|
||||
Size = new Vector2(20, 13),
|
||||
ShowPlaceholderOnNull = false,
|
||||
},
|
||||
new OsuSpriteText
|
||||
new RowText
|
||||
{
|
||||
Text = $@"{item.Country.FullName}",
|
||||
Font = OsuFont.GetFont(size: TEXT_SIZE),
|
||||
}
|
||||
}
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.ActiveUsers:N0}",
|
||||
},
|
||||
new ColoredMetricNumber(item.PlayCount),
|
||||
new ColoredMetricNumber(item.RankedScore),
|
||||
new ColoredMetricNumber(item.RankedScore / Math.Max(item.ActiveUsers, 1)),
|
||||
new MetricNumber(item.Performance),
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.PlayCount:N0}",
|
||||
},
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.RankedScore:N0}",
|
||||
},
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.RankedScore / Math.Max(item.ActiveUsers, 1):N0}",
|
||||
},
|
||||
new RowText
|
||||
{
|
||||
Text = $@"{item.Performance:N0}",
|
||||
},
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.Performance / Math.Max(item.ActiveUsers, 1):N0}",
|
||||
}
|
||||
|
@ -63,28 +63,27 @@ namespace osu.Game.Overlays.Rankings.Tables
|
||||
username
|
||||
}
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.Accuracy:F2}%",
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.PlayCount:N0}",
|
||||
},
|
||||
new OsuSpriteText
|
||||
new RowText
|
||||
{
|
||||
Text = $@"{item.PP:N0}",
|
||||
Font = OsuFont.GetFont(size: TEXT_SIZE),
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.GradesCount.SS + item.GradesCount.SSPlus:N0}",
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.GradesCount.S + item.GradesCount.SPlus:N0}",
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.GradesCount.A:N0}",
|
||||
},
|
||||
|
@ -10,8 +10,6 @@ using osu.Framework.Extensions;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Overlays.Rankings.Tables
|
||||
{
|
||||
@ -88,42 +86,16 @@ namespace osu.Game.Overlays.Rankings.Tables
|
||||
}
|
||||
}
|
||||
|
||||
protected class MetricNumber : OsuSpriteText, IHasTooltip
|
||||
protected class RowText : OsuSpriteText
|
||||
{
|
||||
public string TooltipText => $"{value:N0}";
|
||||
|
||||
private readonly long value;
|
||||
|
||||
public MetricNumber(long value)
|
||||
public RowText()
|
||||
{
|
||||
this.value = value;
|
||||
|
||||
Text = HumanizerUtils.ToReadableString(value);
|
||||
Font = OsuFont.GetFont(size: TEXT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
protected class ColoredMetricNumber : MetricNumber
|
||||
protected class ColoredRowText : RowText
|
||||
{
|
||||
public ColoredMetricNumber(long value)
|
||||
: base(value)
|
||||
{
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
Colour = colours.GreySeafoamLighter;
|
||||
}
|
||||
}
|
||||
|
||||
protected class ColoredText : OsuSpriteText
|
||||
{
|
||||
public ColoredText()
|
||||
{
|
||||
Font = OsuFont.GetFont(size: TEXT_SIZE);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
|
@ -64,25 +64,31 @@ namespace osu.Game.Overlays.Rankings.Tables
|
||||
username
|
||||
}
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.Accuracy:F2}%",
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.PlayCount:N0}",
|
||||
},
|
||||
new ColoredMetricNumber(item.TotalScore),
|
||||
new MetricNumber(item.RankedScore),
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.TotalScore:N0}",
|
||||
},
|
||||
new RowText
|
||||
{
|
||||
Text = $@"{item.RankedScore:N0}",
|
||||
},
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.GradesCount.SS + item.GradesCount.SSPlus:N0}",
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.GradesCount.S + item.GradesCount.SPlus:N0}",
|
||||
},
|
||||
new ColoredText
|
||||
new ColoredRowText
|
||||
{
|
||||
Text = $@"{item.GradesCount.A:N0}",
|
||||
},
|
||||
|
@ -26,32 +26,5 @@ namespace osu.Game.Utils
|
||||
return input.Humanize(culture: new CultureInfo("en-US"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns the current or provided big number into a readable string.
|
||||
/// </summary>
|
||||
/// <param name="input">The number to be humanized.</param>
|
||||
/// <returns>Simplified number with a suffix.</returns>
|
||||
public static string ToReadableString(long input)
|
||||
{
|
||||
const int k = 1000;
|
||||
|
||||
if (input < k)
|
||||
return input.ToString();
|
||||
|
||||
int i = (int)Math.Floor(Math.Round(Math.Log(input, k)));
|
||||
return $"{input / Math.Pow(k, i):F} {suffixes[i]}";
|
||||
}
|
||||
|
||||
private static readonly string[] suffixes =
|
||||
{
|
||||
"",
|
||||
"k",
|
||||
"million",
|
||||
"billion",
|
||||
"trillion",
|
||||
"quadrillion",
|
||||
"quintillion",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user