1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-22 05:49:55 +08:00

Simplify and fix naming of statistic class

This commit is contained in:
Dean Herbert
2025-04-23 17:29:37 +09:00
Unverified
parent 9372ba02d1
commit 4290f2d4fd
5 changed files with 54 additions and 32 deletions
@@ -154,7 +154,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2
AddUntilStep($"displayed bpm is {target}", () =>
{
var label = titleWedge.ChildrenOfType<BeatmapTitleWedge.Statistic>().Single(l => l.TooltipText == BeatmapsetsStrings.ShowStatsBpm);
return label.Value == target;
return label.Text == target;
});
}
}
@@ -29,14 +29,22 @@ namespace osu.Game.Tests.Visual.SongSelectV2
public void TestLoading()
{
AddStep("setup", () => CreateThemedContent(OverlayColourScheme.Aquamarine));
AddStep("set loading", () => this.ChildrenOfType<BeatmapTitleWedge.Statistic>().ForEach(s => s.Value = null));
AddStep("set loading", () => this.ChildrenOfType<BeatmapTitleWedge.Statistic>().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",
},
},
@@ -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");
}
}
}
@@ -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);
}
}
}
}
@@ -1,6 +1,7 @@
// 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 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<StatisticPlayCount.Data>
{
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]