diff --git a/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapTitleWedge.cs b/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapTitleWedge.cs index c97af5a835..6a14ddc147 100644 --- a/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapTitleWedge.cs +++ b/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapTitleWedge.cs @@ -154,7 +154,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2 AddUntilStep($"displayed bpm is {target}", () => { var label = titleWedge.ChildrenOfType().Single(l => l.TooltipText == BeatmapsetsStrings.ShowStatsBpm); - return label.Value == target; + return label.Text == target; }); } } diff --git a/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapTitleWedgeStatistic.cs b/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapTitleWedgeStatistic.cs index 96eab3e8ec..6bf9469021 100644 --- a/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapTitleWedgeStatistic.cs +++ b/osu.Game.Tests/Visual/SongSelectV2/TestSceneBeatmapTitleWedgeStatistic.cs @@ -29,14 +29,22 @@ namespace osu.Game.Tests.Visual.SongSelectV2 public void TestLoading() { AddStep("setup", () => CreateThemedContent(OverlayColourScheme.Aquamarine)); - AddStep("set loading", () => this.ChildrenOfType().ForEach(s => s.Value = null)); + AddStep("set loading", () => this.ChildrenOfType().ForEach(s => s.Text = null)); AddWaitStep("wait", 3); AddStep("set values", () => { playCount.Value = new BeatmapTitleWedge.StatisticPlayCount.Data(1234, 12); - statistic2.Value = "3,234"; - statistic3.Value = "12:34"; - statistic4.Value = "123"; + statistic2.Text = "3,234"; + statistic3.Text = "12:34"; + statistic4.Text = "123"; + }); + + AddStep("set large values", () => + { + playCount.Value = new BeatmapTitleWedge.StatisticPlayCount.Data(134587921, 502); + statistic2.Text = "1,048,576"; + statistic3.Text = "2:50:23"; + statistic4.Text = "1238014"; }); } @@ -54,18 +62,18 @@ namespace osu.Game.Tests.Visual.SongSelectV2 }, statistic2 = new BeatmapTitleWedge.Statistic(OsuIcon.Clock, true, minSize: 30) { - Value = "3,234", + Text = "3,234", TooltipText = "Statistic 2", }, statistic3 = new BeatmapTitleWedge.Statistic(OsuIcon.Metronome) { - Value = "12:34", + Text = "12:34", Margin = new MarginPadding { Right = 10f }, TooltipText = "Statistic 3", }, statistic4 = new BeatmapTitleWedge.Statistic(OsuIcon.Graphics) { - Value = "123", + Text = "123", TooltipText = "Statistic 4", }, }, diff --git a/osu.Game/Screens/SelectV2/BeatmapTitleWedge.cs b/osu.Game/Screens/SelectV2/BeatmapTitleWedge.cs index 4de896d777..d892fcb485 100644 --- a/osu.Game/Screens/SelectV2/BeatmapTitleWedge.cs +++ b/osu.Game/Screens/SelectV2/BeatmapTitleWedge.cs @@ -260,10 +260,10 @@ namespace osu.Game.Screens.SelectV2 double drainLength = Math.Round(beatmap.Value.Beatmap.CalculateDrainLength() / rate); double hitLength = Math.Round(beatmapInfo.Length / rate); - lengthStatistic.Value = hitLength.ToFormattedDuration(); + lengthStatistic.Text = hitLength.ToFormattedDuration(); lengthStatistic.TooltipText = BeatmapsetsStrings.ShowStatsTotalLength(drainLength.ToFormattedDuration()); - bpmStatistic.Value = bpmMin == bpmMax + bpmStatistic.Text = bpmMin == bpmMax ? $"{bpmMin}" : $"{bpmMin}-{bpmMax} (mostly {mostCommonBPM})"; } @@ -296,12 +296,12 @@ namespace osu.Game.Screens.SelectV2 if (currentRequest?.CompletionState == APIRequestCompletionState.Waiting) { playCount.Value = null; - favouritesStatistic.Value = null; + favouritesStatistic.Text = null; } else if (currentOnlineBeatmapSet == null) { playCount.Value = new StatisticPlayCount.Data(-1, -1); - favouritesStatistic.Value = "-"; + favouritesStatistic.Text = "-"; } else { @@ -320,7 +320,7 @@ namespace osu.Game.Screens.SelectV2 } favouritesStatistic.FadeIn(300, Easing.OutQuint); - favouritesStatistic.Value = onlineBeatmapSet.FavouriteCount.ToLocalisableString(@"N0"); + favouritesStatistic.Text = onlineBeatmapSet.FavouriteCount.ToLocalisableString(@"N0"); } } } diff --git a/osu.Game/Screens/SelectV2/BeatmapTitleWedge_Statistic.cs b/osu.Game/Screens/SelectV2/BeatmapTitleWedge_Statistic.cs index b4ec72761f..85a0382360 100644 --- a/osu.Game/Screens/SelectV2/BeatmapTitleWedge_Statistic.cs +++ b/osu.Game/Screens/SelectV2/BeatmapTitleWedge_Statistic.cs @@ -29,27 +29,15 @@ namespace osu.Game.Screens.SelectV2 private OsuSpriteText valueText = null!; private LoadingSpinner loading = null!; - private LocalisableString? value; + private LocalisableString? text; - public LocalisableString? Value + public LocalisableString? Text { - get => value; + get => text; set { - this.value = value; - - Schedule(() => - { - loading.State.Value = value != null ? Visibility.Hidden : Visibility.Visible; - - if (value != null) - { - valueText.Text = value.Value; - valueText.FadeIn(120, Easing.OutQuint); - } - else - valueText.FadeOut(120, Easing.OutQuint); - }); + text = value; + Scheduler.AddOnce(updateDisplay); } } @@ -146,6 +134,25 @@ namespace osu.Game.Screens.SelectV2 } }; } + + protected override void LoadComplete() + { + base.LoadComplete(); + Scheduler.AddOnce(updateDisplay); + } + + private void updateDisplay() + { + loading.State.Value = text != null ? Visibility.Hidden : Visibility.Visible; + + if (text != null) + { + valueText.Text = text.Value; + valueText.FadeIn(120, Easing.OutQuint); + } + else + valueText.FadeOut(120, Easing.OutQuint); + } } } } diff --git a/osu.Game/Screens/SelectV2/BeatmapTitleWedge_StatisticPlayCount.cs b/osu.Game/Screens/SelectV2/BeatmapTitleWedge_StatisticPlayCount.cs index 2d480ad5f4..87f7c30d17 100644 --- a/osu.Game/Screens/SelectV2/BeatmapTitleWedge_StatisticPlayCount.cs +++ b/osu.Game/Screens/SelectV2/BeatmapTitleWedge_StatisticPlayCount.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.LocalisationExtensions; @@ -9,6 +10,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Overlays; @@ -21,15 +23,20 @@ namespace osu.Game.Screens.SelectV2 { public partial class StatisticPlayCount : Statistic, IHasCustomTooltip { - public new Data? Value + public Data? Value { set { - base.Value = value?.Total < 0 ? "-" : value?.Total.ToLocalisableString("N0"); + base.Text = value?.Total < 0 ? "-" : value?.Total.ToLocalisableString("N0"); TooltipContent = value; } } + public new LocalisableString? Text + { + set => throw new InvalidOperationException($"Use {nameof(Value)} instead."); + } + public Data? TooltipContent { get; private set; } [Resolved]