Factor in total score calculation time in results screen load

This commit is contained in:
smoogipoo 2021-09-07 15:18:59 +09:00
parent c9325cc419
commit 4658577b1d
2 changed files with 26 additions and 20 deletions

View File

@ -32,6 +32,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private ScoreManager scoreManager { get; set; }
public PlaylistsResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem, bool allowRetry, bool allowWatchingReplay = true)
: base(score, allowRetry, allowWatchingReplay)
{
@ -166,23 +169,28 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
/// <param name="pivot">An optional pivot around which the scores were retrieved.</param>
private void performSuccessCallback([NotNull] Action<IEnumerable<ScoreInfo>> callback, [NotNull] List<MultiplayerScore> scores, [CanBeNull] MultiplayerScores pivot = null)
{
var scoreInfos = new List<ScoreInfo>(scores.Select(s => s.CreateScoreInfo(playlistItem)));
var scoreInfos = scores.Select(s => s.CreateScoreInfo(playlistItem)).ToArray();
// Select a score if we don't already have one selected.
// Note: This is done before the callback so that the panel list centres on the selected score before panels are added (eliminating initial scroll).
if (SelectedScore.Value == null)
// Score panels calculate total score before displaying, which can take some time. In order to count that calculation as part of the loading spinner display duration,
// calculate the total scores locally before invoking the success callback.
scoreManager.OrderByTotalScoreAsync(scoreInfos).ContinueWith(_ => Schedule(() =>
{
Schedule(() =>
// Select a score if we don't already have one selected.
// Note: This is done before the callback so that the panel list centres on the selected score before panels are added (eliminating initial scroll).
if (SelectedScore.Value == null)
{
// Prefer selecting the local user's score, or otherwise default to the first visible score.
SelectedScore.Value = scoreInfos.FirstOrDefault(s => s.User.Id == api.LocalUser.Value.Id) ?? scoreInfos.FirstOrDefault();
});
}
Schedule(() =>
{
// Prefer selecting the local user's score, or otherwise default to the first visible score.
SelectedScore.Value = scoreInfos.FirstOrDefault(s => s.User.Id == api.LocalUser.Value.Id) ?? scoreInfos.FirstOrDefault();
});
}
// Invoke callback to add the scores. Exclude the user's current score which was added previously.
callback.Invoke(scoreInfos.Where(s => s.OnlineScoreID != Score?.OnlineScoreID));
// Invoke callback to add the scores. Exclude the user's current score which was added previously.
callback.Invoke(scoreInfos.Where(s => s.OnlineScoreID != Score?.OnlineScoreID));
hideLoadingSpinners(pivot);
hideLoadingSpinners(pivot);
}));
}
private void hideLoadingSpinners([CanBeNull] MultiplayerScores pivot = null)

View File

@ -52,8 +52,7 @@ namespace osu.Game.Screens.Ranking
private Drawable bottomPanel;
private Container<ScorePanel> detachedPanelContainer;
private bool fetchedInitialScores;
private APIRequest nextPageRequest;
private bool lastFetchCompleted;
private readonly bool allowRetry;
private readonly bool allowWatchingReplay;
@ -191,8 +190,10 @@ namespace osu.Game.Screens.Ranking
{
base.Update();
if (fetchedInitialScores && nextPageRequest == null)
if (lastFetchCompleted)
{
APIRequest nextPageRequest = null;
if (ScorePanelList.IsScrolledToStart)
nextPageRequest = FetchNextPage(-1, fetchScoresCallback);
else if (ScorePanelList.IsScrolledToEnd)
@ -200,10 +201,7 @@ namespace osu.Game.Screens.Ranking
if (nextPageRequest != null)
{
// Scheduled after children to give the list a chance to update its scroll position and not potentially trigger a second request too early.
nextPageRequest.Success += () => ScheduleAfterChildren(() => nextPageRequest = null);
nextPageRequest.Failure += _ => ScheduleAfterChildren(() => nextPageRequest = null);
lastFetchCompleted = false;
api.Queue(nextPageRequest);
}
}
@ -229,7 +227,7 @@ namespace osu.Game.Screens.Ranking
foreach (var s in scores)
addScore(s);
fetchedInitialScores = true;
lastFetchCompleted = true;
});
public override void OnEntering(IScreen last)