From 096e98b5d3aaeebb67c528b65c1aad44756d0597 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 21 Nov 2017 19:44:38 +0530 Subject: [PATCH] Add game mode query to request. - Also update scores when game mode is changed --- .../Online/API/Requests/GetScoresRequest.cs | 44 ++++++++++++++++--- .../Select/Leaderboards/Leaderboard.cs | 14 +++--- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetScoresRequest.cs b/osu.Game/Online/API/Requests/GetScoresRequest.cs index a52db4496a..37b3cc55f1 100644 --- a/osu.Game/Online/API/Requests/GetScoresRequest.cs +++ b/osu.Game/Online/API/Requests/GetScoresRequest.cs @@ -11,6 +11,7 @@ using osu.Game.Users; using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Select.Leaderboards; +using System.Collections.Specialized; namespace osu.Game.Online.API.Requests { @@ -18,14 +19,26 @@ namespace osu.Game.Online.API.Requests { private readonly BeatmapInfo beatmap; private readonly LeaderboardScope scope; + private readonly RulesetInfo ruleset; - public GetScoresRequest(BeatmapInfo beatmap, LeaderboardScope scope = LeaderboardScope.Global) + public GetScoresRequest(BeatmapInfo beatmap) + { + if (!beatmap.OnlineBeatmapID.HasValue) + throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(BeatmapInfo.OnlineBeatmapID)}."); + + this.beatmap = beatmap; + + Success += onSuccess; + } + + public GetScoresRequest(BeatmapInfo beatmap, LeaderboardScope scope, RulesetInfo ruleset) { if (!beatmap.OnlineBeatmapID.HasValue) throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(BeatmapInfo.OnlineBeatmapID)}."); this.beatmap = beatmap; this.scope = scope; + this.ruleset = ruleset; Success += onSuccess; } @@ -41,20 +54,41 @@ namespace osu.Game.Online.API.Requests switch(scope) { case LeaderboardScope.Global: - return @"?type=global"; + return @"type=global"; case LeaderboardScope.Friends: - return @"?type=friend"; + return @"type=friend"; case LeaderboardScope.Country: - return @"?type=country"; + return @"type=country"; default: return String.Empty; } } - protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores{mapScopeToQuery()}"; + private string mapRulesetToQuery() + { + switch(ruleset.Name) + { + case @"osu!": + return @"mode=osu"; + + case @"osu!taiko": + return @"mode=taiko"; + + case @"osu!catch": + return @"mode=catch"; + + case @"osu!mania": + return @"mode=mania"; + + default: + return String.Empty; + } + } + + protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores?{mapScopeToQuery()}&{mapRulesetToQuery()}"; } public class GetScoresResponse diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index 2567110ef6..3bc520e8e6 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -146,6 +146,8 @@ namespace osu.Game.Screens.Select.Leaderboards private BeatmapInfo beatmap; + private OsuGame osuGame; + private ScheduledDelegate pendingBeatmapSwitch; public BeatmapInfo Beatmap @@ -164,9 +166,12 @@ namespace osu.Game.Screens.Select.Leaderboards } [BackgroundDependencyLoader(permitNulls: true)] - private void load(APIAccess api) + private void load(APIAccess api, OsuGame osuGame) { this.api = api; + this.osuGame = osuGame; + + osuGame.Ruleset.ValueChanged += r => updateScores(); } private GetScoresRequest getScoresRequest; @@ -176,7 +181,8 @@ namespace osu.Game.Screens.Select.Leaderboards if (!IsLoaded) return; Scores = null; - getScoresRequest?.Cancel(); + + if (api == null || Beatmap?.OnlineBeatmapID == null) return; if (Scope == LeaderboardScope.Local) { @@ -185,11 +191,9 @@ namespace osu.Game.Screens.Select.Leaderboards return; } - if (api == null || Beatmap?.OnlineBeatmapID == null) return; - loading.Show(); - getScoresRequest = new GetScoresRequest(Beatmap, Scope); + getScoresRequest = new GetScoresRequest(Beatmap, Scope, osuGame.Ruleset.Value); getScoresRequest.Success += r => { Scores = r.Scores;