1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00

Fix edge cases with score drawable loading

This commit is contained in:
Dean Herbert 2022-01-29 02:12:36 +09:00
parent 0293d95f82
commit d0b74a91fb
2 changed files with 24 additions and 22 deletions

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using JetBrains.Annotations; using JetBrains.Annotations;
@ -43,11 +42,12 @@ namespace osu.Game.Online.Leaderboards
private readonly Container placeholderContainer; private readonly Container placeholderContainer;
private readonly UserTopScoreContainer<TScoreInfo> topScoreContainer; private readonly UserTopScoreContainer<TScoreInfo> topScoreContainer;
private FillFlowContainer<LeaderboardScore> scrollFlow; private FillFlowContainer<LeaderboardScore> scoreFlowContainer;
private readonly LoadingSpinner loading; private readonly LoadingSpinner loading;
private CancellationTokenSource currentFetchCancellationSource; private CancellationTokenSource currentFetchCancellationSource;
private CancellationTokenSource currentScoresAsyncLoadCancellationSource;
private APIRequest fetchScoresRequest; private APIRequest fetchScoresRequest;
@ -64,7 +64,7 @@ namespace osu.Game.Online.Leaderboards
protected set protected set
{ {
scores = value; scores = value;
updateScoresDrawables(); Scheduler.AddOnce(updateScoresDrawables);
} }
} }
@ -239,6 +239,8 @@ namespace osu.Game.Online.Leaderboards
if (value == placeholderState) if (value == placeholderState)
return; return;
loading.Hide();
switch (placeholderState = value) switch (placeholderState = value)
{ {
case PlaceholderState.NetworkFailure: case PlaceholderState.NetworkFailure:
@ -275,40 +277,41 @@ namespace osu.Game.Online.Leaderboards
} }
} }
private void updateScoresDrawables() => Scheduler.Add(() => private void updateScoresDrawables()
{ {
scrollFlow?.FadeOut(fade_duration, Easing.OutQuint).Expire(); currentScoresAsyncLoadCancellationSource?.Cancel();
scrollFlow = null; currentScoresAsyncLoadCancellationSource = new CancellationTokenSource();
scoreFlowContainer?
.FadeOut(fade_duration, Easing.OutQuint)
.Expire();
scoreFlowContainer = null;
loading.Hide();
if (scores?.Any() != true) if (scores?.Any() != true)
{ {
loading.Hide();
PlaceholderState = PlaceholderState.NoScores; PlaceholderState = PlaceholderState.NoScores;
return; return;
} }
Debug.Assert(!currentFetchCancellationSource.IsCancellationRequested);
// ensure placeholder is hidden when displaying scores // ensure placeholder is hidden when displaying scores
PlaceholderState = PlaceholderState.Successful; PlaceholderState = PlaceholderState.Successful;
var scoreFlow = new FillFlowContainer<LeaderboardScore> LoadComponentAsync(new FillFlowContainer<LeaderboardScore>
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Spacing = new Vector2(0f, 5f), Spacing = new Vector2(0f, 5f),
Padding = new MarginPadding { Top = 10, Bottom = 5 }, Padding = new MarginPadding { Top = 10, Bottom = 5 },
ChildrenEnumerable = scores.Select((s, index) => CreateDrawableScore(s, index + 1)) ChildrenEnumerable = scores.Select((s, index) => CreateDrawableScore(s, index + 1))
}; }, newFlow =>
// schedule because we may not be loaded yet (LoadComponentAsync complains).
LoadComponentAsync(scoreFlow, _ =>
{ {
scrollContainer.Add(scrollFlow = scoreFlow); scrollContainer.Add(scoreFlowContainer = newFlow);
int i = 0; int i = 0;
foreach (var s in scrollFlow.Children) foreach (var s in scoreFlowContainer.Children)
{ {
using (s.BeginDelayedSequence(i++ * 50)) using (s.BeginDelayedSequence(i++ * 50))
s.Show(); s.Show();
@ -316,8 +319,8 @@ namespace osu.Game.Online.Leaderboards
scrollContainer.ScrollToStart(false); scrollContainer.ScrollToStart(false);
loading.Hide(); loading.Hide();
}, currentFetchCancellationSource.Token); }, currentScoresAsyncLoadCancellationSource.Token);
}, false); }
private void replacePlaceholder(Placeholder placeholder) private void replacePlaceholder(Placeholder placeholder)
{ {
@ -354,12 +357,12 @@ namespace osu.Game.Online.Leaderboards
if (!scrollContainer.IsScrolledToEnd()) if (!scrollContainer.IsScrolledToEnd())
fadeBottom -= LeaderboardScore.HEIGHT; fadeBottom -= LeaderboardScore.HEIGHT;
if (scrollFlow == null) if (scoreFlowContainer == null)
return; return;
foreach (var c in scrollFlow.Children) foreach (var c in scoreFlowContainer.Children)
{ {
float topY = c.ToSpaceOfOtherDrawable(Vector2.Zero, scrollFlow).Y; float topY = c.ToSpaceOfOtherDrawable(Vector2.Zero, scoreFlowContainer).Y;
float bottomY = topY + LeaderboardScore.HEIGHT; float bottomY = topY + LeaderboardScore.HEIGHT;
bool requireBottomFade = bottomY >= fadeBottom; bool requireBottomFade = bottomY >= fadeBottom;

View File

@ -121,7 +121,6 @@ namespace osu.Game.Screens.Select.Leaderboards
if (Scope == BeatmapLeaderboardScope.Local) if (Scope == BeatmapLeaderboardScope.Local)
{ {
subscribeToLocalScores(cancellationToken); subscribeToLocalScores(cancellationToken);
return null; return null;
} }