1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-21 08:52:54 +08:00

Asyncify statistics load

This commit is contained in:
smoogipoo 2020-06-19 19:12:55 +09:00
parent d3e4e63258
commit a3ff25177a

View File

@ -1,10 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Threading;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Placeholders; using osu.Game.Online.Placeholders;
using osu.Game.Scoring; using osu.Game.Scoring;
using osuTK; using osuTK;
@ -20,6 +22,7 @@ namespace osu.Game.Screens.Ranking.Statistics
protected override bool StartHidden => true; protected override bool StartHidden => true;
private readonly Container content; private readonly Container content;
private readonly LoadingSpinner spinner;
public StatisticsPanel() public StatisticsPanel()
{ {
@ -33,7 +36,11 @@ namespace osu.Game.Screens.Ranking.Statistics
Top = SIDE_PADDING, Top = SIDE_PADDING,
Bottom = 50 // Approximate padding to the bottom of the score panel. Bottom = 50 // Approximate padding to the bottom of the score panel.
}, },
Child = content = new Container { RelativeSizeAxes = Axes.Both }, Children = new Drawable[]
{
content = new Container { RelativeSizeAxes = Axes.Both },
spinner = new LoadingSpinner()
}
}; };
} }
@ -43,8 +50,12 @@ namespace osu.Game.Screens.Ranking.Statistics
Score.BindValueChanged(populateStatistics, true); Score.BindValueChanged(populateStatistics, true);
} }
private CancellationTokenSource loadCancellation;
private void populateStatistics(ValueChangedEvent<ScoreInfo> score) private void populateStatistics(ValueChangedEvent<ScoreInfo> score)
{ {
loadCancellation?.Cancel();
foreach (var child in content) foreach (var child in content)
child.FadeOut(150).Expire(); child.FadeOut(150).Expire();
@ -54,6 +65,8 @@ namespace osu.Game.Screens.Ranking.Statistics
content.Add(new MessagePlaceholder("Score has no statistics :(")); content.Add(new MessagePlaceholder("Score has no statistics :("));
else else
{ {
spinner.Show();
var rows = new FillFlowContainer var rows = new FillFlowContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -73,7 +86,14 @@ namespace osu.Game.Screens.Ranking.Statistics
}); });
} }
content.Add(rows); LoadComponentAsync(rows, d =>
{
if (Score.Value != newScore)
return;
spinner.Hide();
content.Add(d);
}, (loadCancellation = new CancellationTokenSource()).Token);
} }
} }