2020-08-26 04:43:23 +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;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Ranking.Statistics
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a simple statistic item (one that only needs textual display).
|
|
|
|
/// Richer visualisations should be done with <see cref="StatisticItem"/>s.
|
|
|
|
/// </summary>
|
|
|
|
public abstract class SimpleStatisticItem : Container
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The text to display as the statistic's value.
|
|
|
|
/// </summary>
|
|
|
|
protected string Value
|
|
|
|
{
|
|
|
|
set => this.value.Text = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly OsuSpriteText value;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new simple statistic item.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">The name of the statistic.</param>
|
|
|
|
protected SimpleStatisticItem(string name)
|
|
|
|
{
|
|
|
|
Name = name;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
AddRange(new[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = Name,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
2020-08-27 03:43:33 +08:00
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Font = OsuFont.GetFont(size: 14)
|
2020-08-26 04:43:23 +08:00
|
|
|
},
|
|
|
|
value = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
2020-08-27 03:43:33 +08:00
|
|
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold)
|
2020-08-26 04:43:23 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Strongly-typed generic specialisation for <see cref="SimpleStatisticItem"/>.
|
|
|
|
/// </summary>
|
|
|
|
public class SimpleStatisticItem<TValue> : SimpleStatisticItem
|
|
|
|
{
|
2020-08-31 20:28:45 +08:00
|
|
|
private TValue value;
|
|
|
|
|
2020-08-26 04:43:23 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The statistic's value to be displayed.
|
|
|
|
/// </summary>
|
|
|
|
public new TValue Value
|
|
|
|
{
|
2020-08-31 20:28:45 +08:00
|
|
|
get => value;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
this.value = value;
|
|
|
|
base.Value = DisplayValue(value);
|
|
|
|
}
|
2020-08-26 04:43:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Used to convert <see cref="Value"/> to a text representation.
|
|
|
|
/// Defaults to using <see cref="object.ToString"/>.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual string DisplayValue(TValue value) => value.ToString();
|
|
|
|
|
|
|
|
public SimpleStatisticItem(string name)
|
|
|
|
: base(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|