Make sort changes affect request result

This commit is contained in:
Andrei Zavatski 2020-07-14 18:09:09 +03:00
parent c2c80d2a98
commit 3d9e174ae8
4 changed files with 20 additions and 10 deletions

View File

@ -15,6 +15,7 @@ using osu.Game.Rulesets.Catch;
using osu.Framework.Allocation;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Overlays.Rankings;
namespace osu.Game.Tests.Visual.Online
{
@ -105,7 +106,7 @@ namespace osu.Game.Tests.Visual.Online
{
onLoadStarted();
request = new GetSpotlightRankingsRequest(ruleset, spotlight);
request = new GetSpotlightRankingsRequest(ruleset, spotlight, RankingsSortCriteria.All);
((GetSpotlightRankingsRequest)request).Success += rankings => Schedule(() =>
{
var table = new ScoresTable(1, rankings.Users);

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.IO.Network;
using osu.Game.Overlays.Rankings;
using osu.Game.Rulesets;
namespace osu.Game.Online.API.Requests
@ -9,11 +10,13 @@ namespace osu.Game.Online.API.Requests
public class GetSpotlightRankingsRequest : GetRankingsRequest<GetSpotlightRankingsResponse>
{
private readonly int spotlight;
private readonly RankingsSortCriteria sort;
public GetSpotlightRankingsRequest(RulesetInfo ruleset, int spotlight)
public GetSpotlightRankingsRequest(RulesetInfo ruleset, int spotlight, RankingsSortCriteria sort)
: base(ruleset, 1)
{
this.spotlight = spotlight;
this.sort = sort;
}
protected override WebRequest CreateWebRequest()
@ -21,6 +24,7 @@ namespace osu.Game.Online.API.Requests
var req = base.CreateWebRequest();
req.AddParameter("spotlight", spotlight.ToString());
req.AddParameter("filter", sort.ToString().ToLower());
return req;
}

View File

@ -22,10 +22,8 @@ namespace osu.Game.Overlays.Rankings
{
private const int duration = 300;
private readonly Box background;
private readonly SpotlightsDropdown dropdown;
private readonly BindableWithCurrent<APISpotlight> current = new BindableWithCurrent<APISpotlight>();
public readonly Bindable<RankingsSortCriteria> Sort = new Bindable<RankingsSortCriteria>();
public Bindable<APISpotlight> Current
{
@ -41,11 +39,13 @@ namespace osu.Game.Overlays.Rankings
protected override bool StartHidden => true;
private readonly Box background;
private readonly Container content;
private readonly SpotlightsDropdown dropdown;
private readonly InfoColumn startDateColumn;
private readonly InfoColumn endDateColumn;
private readonly InfoColumn mapCountColumn;
private readonly InfoColumn participantsColumn;
private readonly Container content;
public SpotlightSelector()
{
@ -107,7 +107,8 @@ namespace osu.Game.Overlays.Rankings
Child = new RankingsSortTabControl
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight
Origin = Anchor.CentreRight,
Current = Sort
}
}
}

View File

@ -24,6 +24,7 @@ namespace osu.Game.Overlays.Rankings
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
private readonly Bindable<APISpotlight> selectedSpotlight = new Bindable<APISpotlight>();
private readonly Bindable<RankingsSortCriteria> sort = new Bindable<RankingsSortCriteria>();
[Resolved]
private IAPIProvider api { get; set; }
@ -72,6 +73,8 @@ namespace osu.Game.Overlays.Rankings
}
}
};
sort.BindTo(selector.Sort);
}
protected override void LoadComplete()
@ -80,7 +83,8 @@ namespace osu.Game.Overlays.Rankings
selector.Show();
selectedSpotlight.BindValueChanged(onSpotlightChanged);
selectedSpotlight.BindValueChanged(_ => onSpotlightChanged());
sort.BindValueChanged(_ => onSpotlightChanged());
Ruleset.BindValueChanged(onRulesetChanged);
getSpotlights();
@ -101,14 +105,14 @@ namespace osu.Game.Overlays.Rankings
selectedSpotlight.TriggerChange();
}
private void onSpotlightChanged(ValueChangedEvent<APISpotlight> spotlight)
private void onSpotlightChanged()
{
loading.Show();
cancellationToken?.Cancel();
getRankingsRequest?.Cancel();
getRankingsRequest = new GetSpotlightRankingsRequest(Ruleset.Value, spotlight.NewValue.Id);
getRankingsRequest = new GetSpotlightRankingsRequest(Ruleset.Value, selectedSpotlight.Value.Id, sort.Value);
getRankingsRequest.Success += onSuccess;
api.Queue(getRankingsRequest);
}