Remove humanized number dependency

This commit is contained in:
Andrei Zavatski
2019-10-01 14:12:03 +03:00
parent 5b09daef1a
commit ff477cd56c
6 changed files with 41 additions and 138 deletions

View File

@ -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);
}
}
}
}

View File

@ -50,22 +50,33 @@ namespace osu.Game.Overlays.Rankings.Tables
Size = new Vector2(20, 13), Size = new Vector2(20, 13),
ShowPlaceholderOnNull = false, ShowPlaceholderOnNull = false,
}, },
new OsuSpriteText new RowText
{ {
Text = $@"{item.Country.FullName}", Text = $@"{item.Country.FullName}",
Font = OsuFont.GetFont(size: TEXT_SIZE),
} }
} }
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.ActiveUsers:N0}", Text = $@"{item.ActiveUsers:N0}",
}, },
new ColoredMetricNumber(item.PlayCount), new ColoredRowText
new ColoredMetricNumber(item.RankedScore), {
new ColoredMetricNumber(item.RankedScore / Math.Max(item.ActiveUsers, 1)), Text = $@"{item.PlayCount:N0}",
new MetricNumber(item.Performance), },
new ColoredText 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}", Text = $@"{item.Performance / Math.Max(item.ActiveUsers, 1):N0}",
} }

View File

@ -63,28 +63,27 @@ namespace osu.Game.Overlays.Rankings.Tables
username username
} }
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.Accuracy:F2}%", Text = $@"{item.Accuracy:F2}%",
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.PlayCount:N0}", Text = $@"{item.PlayCount:N0}",
}, },
new OsuSpriteText new RowText
{ {
Text = $@"{item.PP:N0}", Text = $@"{item.PP:N0}",
Font = OsuFont.GetFont(size: TEXT_SIZE),
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.GradesCount.SS + item.GradesCount.SSPlus:N0}", Text = $@"{item.GradesCount.SS + item.GradesCount.SSPlus:N0}",
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.GradesCount.S + item.GradesCount.SPlus:N0}", Text = $@"{item.GradesCount.S + item.GradesCount.SPlus:N0}",
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.GradesCount.A:N0}", Text = $@"{item.GradesCount.A:N0}",
}, },

View File

@ -10,8 +10,6 @@ using osu.Framework.Extensions;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics.Cursor;
using osu.Game.Utils;
namespace osu.Game.Overlays.Rankings.Tables 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}"; public RowText()
private readonly long value;
public MetricNumber(long value)
{ {
this.value = value;
Text = HumanizerUtils.ToReadableString(value);
Font = OsuFont.GetFont(size: TEXT_SIZE); 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] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {

View File

@ -64,25 +64,31 @@ namespace osu.Game.Overlays.Rankings.Tables
username username
} }
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.Accuracy:F2}%", Text = $@"{item.Accuracy:F2}%",
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.PlayCount:N0}", Text = $@"{item.PlayCount:N0}",
}, },
new ColoredMetricNumber(item.TotalScore), new ColoredRowText
new MetricNumber(item.RankedScore), {
new ColoredText Text = $@"{item.TotalScore:N0}",
},
new RowText
{
Text = $@"{item.RankedScore:N0}",
},
new ColoredRowText
{ {
Text = $@"{item.GradesCount.SS + item.GradesCount.SSPlus:N0}", Text = $@"{item.GradesCount.SS + item.GradesCount.SSPlus:N0}",
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.GradesCount.S + item.GradesCount.SPlus:N0}", Text = $@"{item.GradesCount.S + item.GradesCount.SPlus:N0}",
}, },
new ColoredText new ColoredRowText
{ {
Text = $@"{item.GradesCount.A:N0}", Text = $@"{item.GradesCount.A:N0}",
}, },

View File

@ -26,32 +26,5 @@ namespace osu.Game.Utils
return input.Humanize(culture: new CultureInfo("en-US")); 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",
};
} }
} }