2020-03-17 16:25:24 +08: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.
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
2020-09-25 19:22:59 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-03-17 16:25:24 +08:00
|
|
|
using osu.Game.Graphics;
|
2020-08-04 01:14:17 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-03-17 16:25:24 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Screens.Ranking.Expanded.Accuracy;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
|
|
|
{
|
2020-03-17 16:34:16 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A <see cref="StatisticDisplay"/> to display general numeric values.
|
|
|
|
/// </summary>
|
2020-03-17 16:25:24 +08:00
|
|
|
public class CounterStatistic : StatisticDisplay
|
|
|
|
{
|
|
|
|
private readonly int count;
|
2020-09-25 19:22:59 +08:00
|
|
|
private readonly int? maxCount;
|
2020-03-17 16:25:24 +08:00
|
|
|
|
|
|
|
private RollingCounter<int> counter;
|
|
|
|
|
2020-03-17 16:34:16 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="CounterStatistic"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="header">The name of the statistic.</param>
|
|
|
|
/// <param name="count">The value to display.</param>
|
2020-09-25 19:22:59 +08:00
|
|
|
/// <param name="maxCount">The maximum value of <paramref name="count"/>. Not displayed if null.</param>
|
|
|
|
public CounterStatistic(string header, int count, int? maxCount = null)
|
2020-03-17 16:25:24 +08:00
|
|
|
: base(header)
|
|
|
|
{
|
|
|
|
this.count = count;
|
2020-09-25 19:22:59 +08:00
|
|
|
this.maxCount = maxCount;
|
2020-03-17 16:25:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Appear()
|
|
|
|
{
|
|
|
|
base.Appear();
|
|
|
|
counter.Current.Value = count;
|
|
|
|
}
|
|
|
|
|
2020-09-25 19:22:59 +08:00
|
|
|
protected override Drawable CreateContent()
|
|
|
|
{
|
|
|
|
var container = new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Child = counter = new Counter
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (maxCount != null)
|
|
|
|
{
|
|
|
|
container.Add(new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Font = OsuFont.Torus.With(size: 12, fixedWidth: true),
|
|
|
|
Spacing = new Vector2(-2, 0),
|
|
|
|
Text = $"/{maxCount}"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return container;
|
|
|
|
}
|
2020-03-17 16:25:24 +08:00
|
|
|
|
|
|
|
private class Counter : RollingCounter<int>
|
|
|
|
{
|
|
|
|
protected override double RollingDuration => AccuracyCircle.ACCURACY_TRANSFORM_DURATION;
|
|
|
|
|
|
|
|
protected override Easing RollingEasing => AccuracyCircle.ACCURACY_TRANSFORM_EASING;
|
|
|
|
|
2020-08-19 12:47:02 +08:00
|
|
|
protected override OsuSpriteText CreateSpriteText() => base.CreateSpriteText().With(s =>
|
2020-03-17 16:25:24 +08:00
|
|
|
{
|
2020-08-19 12:47:02 +08:00
|
|
|
s.Font = OsuFont.Torus.With(size: 20, fixedWidth: true);
|
|
|
|
s.Spacing = new Vector2(-2, 0);
|
|
|
|
});
|
2020-03-17 16:25:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|