mirror of
https://github.com/ppy/osu.git
synced 2026-06-05 12:03:46 +08:00
Replace virtual async method with better abstraction
This commit is contained in:
@@ -125,7 +125,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
setPositions(lowerScores, userScore.Position.Value, 1);
|
||||
}
|
||||
|
||||
return await TransformScores(allScores);
|
||||
return await transformScores(allScores);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -190,7 +190,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
setPositions(index, pivot, -1);
|
||||
}
|
||||
|
||||
return await TransformScores(index.Scores, index);
|
||||
return await transformScores(index.Scores);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -203,11 +203,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms returned <see cref="MultiplayerScores"/> into <see cref="ScoreInfo"/>s, ensure the <see cref="ScorePanelList"/> is put into a sane state, and invokes a given success callback.
|
||||
/// Transforms returned <see cref="MultiplayerScores"/> into <see cref="ScoreInfo"/>s.
|
||||
/// </summary>
|
||||
/// <param name="scores">The <see cref="MultiplayerScore"/>s that were retrieved from <see cref="APIRequest"/>s.</param>
|
||||
/// <param name="pivot">An optional pivot around which the scores were retrieved.</param>
|
||||
protected virtual async Task<ScoreInfo[]> TransformScores(List<MultiplayerScore> scores, MultiplayerScores? pivot = null)
|
||||
private async Task<ScoreInfo[]> transformScores(List<MultiplayerScore> scores)
|
||||
{
|
||||
APIBeatmap?[] beatmaps = await beatmapLookupCache.GetBeatmapsAsync(scores.Select(s => s.BeatmapId).Distinct().ToArray());
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Scoring;
|
||||
@@ -31,11 +30,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
protected override APIRequest<MultiplayerScore> CreateScoreRequest() => new ShowPlaylistScoreRequest(RoomId, PlaylistItem.ID, scoreId);
|
||||
|
||||
protected override async Task<ScoreInfo[]> TransformScores(List<MultiplayerScore> scores, MultiplayerScores? pivot = null)
|
||||
protected override void OnScoresAdded(IEnumerable<ScoreInfo> scores)
|
||||
{
|
||||
var scoreInfos = await base.TransformScores(scores, pivot);
|
||||
Schedule(() => SelectedScore.Value ??= scoreInfos.SingleOrDefault(s => s.OnlineID == scoreId));
|
||||
return scoreInfos;
|
||||
base.OnScoresAdded(scores);
|
||||
SelectedScore.Value ??= scores.SingleOrDefault(s => s.OnlineID == scoreId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Scoring;
|
||||
@@ -25,17 +24,12 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
protected override APIRequest<MultiplayerScore> CreateScoreRequest() => new ShowPlaylistUserScoreRequest(RoomId, PlaylistItem.ID, userId);
|
||||
|
||||
protected override async Task<ScoreInfo[]> TransformScores(List<MultiplayerScore> scores, MultiplayerScores? pivot = null)
|
||||
protected override void OnScoresAdded(IEnumerable<ScoreInfo> scores)
|
||||
{
|
||||
var scoreInfos = await base.TransformScores(scores, pivot);
|
||||
base.OnScoresAdded(scores);
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
// Prefer selecting the local user's score, or otherwise default to the first visible score.
|
||||
SelectedScore.Value ??= scoreInfos.FirstOrDefault(s => s.UserID == userId) ?? scoreInfos.FirstOrDefault();
|
||||
});
|
||||
|
||||
return scoreInfos;
|
||||
// Prefer selecting the local user's score, or otherwise default to the first visible score.
|
||||
SelectedScore.Value ??= scores.FirstOrDefault(s => s.UserID == userId) ?? scores.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,8 +357,18 @@ namespace osu.Game.Screens.Ranking
|
||||
// This can happen if for example a beatmap that is part of a playlist hasn't been played yet.
|
||||
VerticalScrollContent.Add(new MessagePlaceholder(LeaderboardStrings.NoRecordsYet));
|
||||
}
|
||||
|
||||
OnScoresAdded(scores);
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Invoked after online scores are fetched and added to the list.
|
||||
/// </summary>
|
||||
/// <param name="scores">The scores that were added.</param>
|
||||
protected virtual void OnScoresAdded(IEnumerable<ScoreInfo> scores)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnEntering(ScreenTransitionEvent e)
|
||||
{
|
||||
base.OnEntering(e);
|
||||
|
||||
Reference in New Issue
Block a user