// Copyright (c) ppy Pty Ltd . 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 { /// /// Represents a simple statistic item (one that only needs textual display). /// Richer visualisations should be done with s. /// public abstract partial class SimpleStatisticItem : Container { /// /// The text to display as the statistic's value. /// protected string Value { set => this.value.Text = value; } private readonly OsuSpriteText value; /// /// Creates a new simple statistic item. /// /// The name of the statistic. protected SimpleStatisticItem(string name) { Name = name; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; AddRange(new[] { new OsuSpriteText { Text = Name, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Font = OsuFont.GetFont(size: StatisticItem.FONT_SIZE) }, value = new OsuSpriteText { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, Font = OsuFont.GetFont(size: StatisticItem.FONT_SIZE, weight: FontWeight.Bold) } }); } } /// /// Strongly-typed generic specialisation for . /// public partial class SimpleStatisticItem : SimpleStatisticItem { private TValue value = default!; /// /// The statistic's value to be displayed. /// public new TValue Value { get => value; set { this.value = value; base.Value = DisplayValue(value); } } /// /// Used to convert to a text representation. /// Defaults to using . /// protected virtual string DisplayValue(TValue value) => value!.ToString() ?? string.Empty; public SimpleStatisticItem(string name) : base(name) { } } }