diff --git a/osu.Game/Online/Multiplayer/IndexPlaylistScoresRequest.cs b/osu.Game/Online/Multiplayer/IndexPlaylistScoresRequest.cs index 7273c0eea6..67793df344 100644 --- a/osu.Game/Online/Multiplayer/IndexPlaylistScoresRequest.cs +++ b/osu.Game/Online/Multiplayer/IndexPlaylistScoresRequest.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using JetBrains.Annotations; using osu.Framework.IO.Network; using osu.Game.Extensions; using osu.Game.Online.API; @@ -16,31 +17,31 @@ namespace osu.Game.Online.Multiplayer private readonly int roomId; private readonly int playlistItemId; private readonly Cursor cursor; - private readonly MultiplayerScoresSort? sort; + private readonly IndexScoresParams indexParams; - public IndexPlaylistScoresRequest(int roomId, int playlistItemId, Cursor cursor = null, MultiplayerScoresSort? sort = null) + public IndexPlaylistScoresRequest(int roomId, int playlistItemId) { this.roomId = roomId; this.playlistItemId = playlistItemId; + } + + public IndexPlaylistScoresRequest(int roomId, int playlistItemId, [NotNull] Cursor cursor, [NotNull] IndexScoresParams indexParams) + : this(roomId, playlistItemId) + { this.cursor = cursor; - this.sort = sort; + this.indexParams = indexParams; } protected override WebRequest CreateWebRequest() { var req = base.CreateWebRequest(); - req.AddCursor(cursor); - - switch (sort) + if (cursor != null) { - case MultiplayerScoresSort.Ascending: - req.AddParameter("sort", "score_asc"); - break; + req.AddCursor(cursor); - case MultiplayerScoresSort.Descending: - req.AddParameter("sort", "score_desc"); - break; + foreach (var (key, value) in indexParams.Properties) + req.AddParameter(key, value.ToString()); } return req; diff --git a/osu.Game/Online/Multiplayer/IndexScoresParams.cs b/osu.Game/Online/Multiplayer/IndexScoresParams.cs new file mode 100644 index 0000000000..8160dfefaf --- /dev/null +++ b/osu.Game/Online/Multiplayer/IndexScoresParams.cs @@ -0,0 +1,20 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using JetBrains.Annotations; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace osu.Game.Online.Multiplayer +{ + /// + /// A collection of parameters which should be passed to the index endpoint to fetch the next page. + /// + public class IndexScoresParams + { + [UsedImplicitly] + [JsonExtensionData] + public IDictionary Properties; + } +} diff --git a/osu.Game/Online/Multiplayer/MultiplayerScores.cs b/osu.Game/Online/Multiplayer/MultiplayerScores.cs index 6f74fc8984..2d0f98e032 100644 --- a/osu.Game/Online/Multiplayer/MultiplayerScores.cs +++ b/osu.Game/Online/Multiplayer/MultiplayerScores.cs @@ -29,5 +29,11 @@ namespace osu.Game.Online.Multiplayer /// [JsonProperty("user_score")] public MultiplayerScore UserScore { get; set; } + + /// + /// The parameters to be used to fetch the next page. + /// + [JsonProperty("params")] + public IndexScoresParams Params { get; set; } } } diff --git a/osu.Game/Screens/Multi/Ranking/TimeshiftResultsScreen.cs b/osu.Game/Screens/Multi/Ranking/TimeshiftResultsScreen.cs index 75a61b92ee..648bee385c 100644 --- a/osu.Game/Screens/Multi/Ranking/TimeshiftResultsScreen.cs +++ b/osu.Game/Screens/Multi/Ranking/TimeshiftResultsScreen.cs @@ -10,7 +10,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; -using osu.Game.Online.API.Requests; using osu.Game.Online.Multiplayer; using osu.Game.Scoring; using osu.Game.Screens.Ranking; @@ -23,8 +22,8 @@ namespace osu.Game.Screens.Multi.Ranking private readonly PlaylistItem playlistItem; private LoadingSpinner loadingLayer; - private Cursor higherScoresCursor; - private Cursor lowerScoresCursor; + private MultiplayerScores higherScores; + private MultiplayerScores lowerScores; [Resolved] private IAPIProvider api { get; set; } @@ -52,8 +51,8 @@ namespace osu.Game.Screens.Multi.Ranking protected override APIRequest FetchScores(Action> scoresCallback) { // This performs two requests: - // 1. A request to show the user's score. - // 2. If (1) fails, a request to index the room. + // 1. A request to show the user's score (and scores around). + // 2. If that fails, a request to index the room starting from the highest score. var userScoreReq = new ShowPlaylistUserScoreRequest(roomId, playlistItem.ID, api.LocalUser.Value.Id); @@ -64,13 +63,13 @@ namespace osu.Game.Screens.Multi.Ranking if (userScore.ScoresAround?.Higher != null) { allScores.AddRange(userScore.ScoresAround.Higher.Scores); - higherScoresCursor = userScore.ScoresAround.Higher.Cursor; + higherScores = userScore.ScoresAround.Higher; } if (userScore.ScoresAround?.Lower != null) { allScores.AddRange(userScore.ScoresAround.Lower.Scores); - lowerScoresCursor = userScore.ScoresAround.Lower.Cursor; + lowerScores = userScore.ScoresAround.Lower; } performSuccessCallback(scoresCallback, allScores); @@ -84,7 +83,7 @@ namespace osu.Game.Screens.Multi.Ranking indexReq.Success += r => { performSuccessCallback(scoresCallback, r.Scores); - lowerScoresCursor = r.Cursor; + lowerScores = r; }; indexReq.Failure += __ => loadingLayer.Hide(); @@ -99,39 +98,19 @@ namespace osu.Game.Screens.Multi.Ranking { Debug.Assert(direction == 1 || direction == -1); - Cursor cursor; - MultiplayerScoresSort sort; + MultiplayerScores pivot = direction == -1 ? higherScores : lowerScores; - switch (direction) - { - case -1: - cursor = higherScoresCursor; - sort = MultiplayerScoresSort.Ascending; - break; - - default: - cursor = lowerScoresCursor; - sort = MultiplayerScoresSort.Descending; - break; - } - - if (cursor == null) + if (pivot?.Cursor == null) return null; - var indexReq = new IndexPlaylistScoresRequest(roomId, playlistItem.ID, cursor, sort); + var indexReq = new IndexPlaylistScoresRequest(roomId, playlistItem.ID, pivot.Cursor, pivot.Params); indexReq.Success += r => { - switch (direction) - { - case -1: - higherScoresCursor = r.Cursor; - break; - - default: - lowerScoresCursor = r.Cursor; - break; - } + if (direction == -1) + higherScores = r; + else + lowerScores = r; performSuccessCallback(scoresCallback, r.Scores); };