2019-11-30 00:01:07 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-11-30 00:01:07 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Overlays.Rankings;
|
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
|
using osu.Game.Overlays.Rankings.Tables;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2021-01-18 18:22:50 +00:00
|
|
|
|
public partial class RankingsOverlay : TabbableOnlineOverlay<RankingsOverlayHeader, RankingsScope>
|
2019-11-30 00:01:07 +00:00
|
|
|
|
{
|
2022-07-18 05:40:34 +00:00
|
|
|
|
protected Bindable<CountryCode> Country => Header.Country;
|
2020-02-18 18:26:25 +00:00
|
|
|
|
|
2019-12-05 05:26:36 +00:00
|
|
|
|
private APIRequest lastRequest;
|
2019-11-30 00:01:07 +00:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
|
2021-08-23 10:50:39 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IBindable<RulesetInfo> parentRuleset { get; set; }
|
|
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
|
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
|
|
|
|
|
2019-11-30 00:01:07 +00:00
|
|
|
|
public RankingsOverlay()
|
2021-01-18 07:48:12 +00:00
|
|
|
|
: base(OverlayColourScheme.Green)
|
2019-11-30 00:01:07 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2020-02-18 18:26:25 +00:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2021-08-23 10:50:39 +00:00
|
|
|
|
Header.Ruleset.BindTo(ruleset);
|
|
|
|
|
|
2019-12-05 06:53:25 +00:00
|
|
|
|
Country.BindValueChanged(_ =>
|
2019-12-05 05:07:39 +00:00
|
|
|
|
{
|
|
|
|
|
// if a country is requested, force performance scope.
|
2022-07-16 01:40:37 +00:00
|
|
|
|
if (!Country.IsDefault)
|
2021-02-09 09:42:15 +00:00
|
|
|
|
Header.Current.Value = RankingsScope.Performance;
|
2019-12-05 05:07:39 +00:00
|
|
|
|
|
2021-02-09 09:42:15 +00:00
|
|
|
|
Scheduler.AddOnce(triggerTabChanged);
|
2020-02-18 18:26:25 +00:00
|
|
|
|
});
|
2019-12-05 05:07:39 +00:00
|
|
|
|
|
2021-08-23 10:50:39 +00:00
|
|
|
|
ruleset.BindValueChanged(_ =>
|
2020-02-10 23:35:23 +00:00
|
|
|
|
{
|
2021-02-09 09:42:15 +00:00
|
|
|
|
if (Header.Current.Value == RankingsScope.Spotlights)
|
2020-02-10 23:35:23 +00:00
|
|
|
|
return;
|
2019-12-05 05:07:39 +00:00
|
|
|
|
|
2021-02-09 09:42:15 +00:00
|
|
|
|
Scheduler.AddOnce(triggerTabChanged);
|
2020-02-18 18:26:25 +00:00
|
|
|
|
});
|
2019-11-30 00:01:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 10:50:39 +00:00
|
|
|
|
private bool requiresRulesetUpdate = true;
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
if (requiresRulesetUpdate)
|
|
|
|
|
{
|
|
|
|
|
ruleset.Value = parentRuleset.Value;
|
|
|
|
|
requiresRulesetUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.PopIn();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-09 09:42:15 +00:00
|
|
|
|
protected override void OnTabChanged(RankingsScope tab)
|
|
|
|
|
{
|
|
|
|
|
// country filtering is only valid for performance scope.
|
|
|
|
|
if (Header.Current.Value != RankingsScope.Performance)
|
2022-07-16 01:40:37 +00:00
|
|
|
|
Country.SetDefault();
|
2021-02-09 09:42:15 +00:00
|
|
|
|
|
|
|
|
|
Scheduler.AddOnce(triggerTabChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void triggerTabChanged() => base.OnTabChanged(Header.Current.Value);
|
|
|
|
|
|
2021-01-18 07:48:12 +00:00
|
|
|
|
protected override RankingsOverlayHeader CreateHeader() => new RankingsOverlayHeader();
|
|
|
|
|
|
2022-07-18 05:40:34 +00:00
|
|
|
|
public void ShowCountry(CountryCode requested)
|
2019-11-30 00:01:07 +00:00
|
|
|
|
{
|
2022-07-16 01:40:37 +00:00
|
|
|
|
if (requested == default)
|
2019-11-30 00:01:07 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Show();
|
|
|
|
|
|
2019-12-05 06:53:25 +00:00
|
|
|
|
Country.Value = requested;
|
2019-11-30 00:01:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 18:22:50 +00:00
|
|
|
|
protected override void CreateDisplayToLoad(RankingsScope tab)
|
2019-11-30 00:01:07 +00:00
|
|
|
|
{
|
2019-12-05 05:26:36 +00:00
|
|
|
|
lastRequest?.Cancel();
|
2019-11-30 00:01:07 +00:00
|
|
|
|
|
2021-02-09 09:42:15 +00:00
|
|
|
|
if (Header.Current.Value == RankingsScope.Spotlights)
|
2020-02-10 23:35:23 +00:00
|
|
|
|
{
|
2021-01-18 18:22:50 +00:00
|
|
|
|
LoadDisplay(new SpotlightsLayout
|
2020-02-10 23:35:23 +00:00
|
|
|
|
{
|
2021-08-23 10:50:39 +00:00
|
|
|
|
Ruleset = { BindTarget = ruleset }
|
2020-02-10 23:35:23 +00:00
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-05 05:26:36 +00:00
|
|
|
|
var request = createScopedRequest();
|
|
|
|
|
lastRequest = request;
|
|
|
|
|
|
|
|
|
|
if (request == null)
|
2019-11-30 00:01:07 +00:00
|
|
|
|
{
|
2021-01-18 18:22:50 +00:00
|
|
|
|
LoadDisplay(Empty());
|
2019-12-05 05:26:36 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 18:22:50 +00:00
|
|
|
|
request.Success += () => Schedule(() => LoadDisplay(createTableFromResponse(request)));
|
|
|
|
|
request.Failure += _ => Schedule(() => LoadDisplay(Empty()));
|
2020-02-10 23:35:23 +00:00
|
|
|
|
|
2019-12-05 05:26:36 +00:00
|
|
|
|
api.Queue(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private APIRequest createScopedRequest()
|
|
|
|
|
{
|
2021-02-09 09:42:15 +00:00
|
|
|
|
switch (Header.Current.Value)
|
2019-12-05 05:26:36 +00:00
|
|
|
|
{
|
2019-11-30 00:01:07 +00:00
|
|
|
|
case RankingsScope.Performance:
|
2022-07-18 05:40:34 +00:00
|
|
|
|
return new GetUserRankingsRequest(ruleset.Value, countryCode: Country.Value);
|
2019-11-30 00:01:07 +00:00
|
|
|
|
|
|
|
|
|
case RankingsScope.Country:
|
2021-08-23 10:50:39 +00:00
|
|
|
|
return new GetCountryRankingsRequest(ruleset.Value);
|
2019-11-30 00:01:07 +00:00
|
|
|
|
|
|
|
|
|
case RankingsScope.Score:
|
2021-08-23 10:50:39 +00:00
|
|
|
|
return new GetUserRankingsRequest(ruleset.Value, UserRankingsType.Score);
|
2019-11-30 00:01:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-05 05:26:36 +00:00
|
|
|
|
return null;
|
2019-11-30 00:01:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 23:35:23 +00:00
|
|
|
|
private Drawable createTableFromResponse(APIRequest request)
|
2019-11-30 00:01:07 +00:00
|
|
|
|
{
|
2019-12-05 05:26:36 +00:00
|
|
|
|
switch (request)
|
2019-11-30 00:01:07 +00:00
|
|
|
|
{
|
2019-12-05 05:26:36 +00:00
|
|
|
|
case GetUserRankingsRequest userRequest:
|
2021-10-05 08:59:38 +00:00
|
|
|
|
if (userRequest.Response == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2019-12-05 05:26:36 +00:00
|
|
|
|
switch (userRequest.Type)
|
|
|
|
|
{
|
|
|
|
|
case UserRankingsType.Performance:
|
2021-10-05 05:28:56 +00:00
|
|
|
|
return new PerformanceTable(1, userRequest.Response.Users);
|
2019-11-30 00:01:07 +00:00
|
|
|
|
|
2019-12-05 05:26:36 +00:00
|
|
|
|
case UserRankingsType.Score:
|
2021-10-05 05:28:56 +00:00
|
|
|
|
return new ScoresTable(1, userRequest.Response.Users);
|
2019-12-05 05:26:36 +00:00
|
|
|
|
}
|
2019-11-30 00:01:07 +00:00
|
|
|
|
|
2019-12-05 05:26:36 +00:00
|
|
|
|
return null;
|
2019-11-30 00:01:07 +00:00
|
|
|
|
|
2019-12-05 05:26:36 +00:00
|
|
|
|
case GetCountryRankingsRequest countryRequest:
|
2021-10-05 08:59:38 +00:00
|
|
|
|
{
|
|
|
|
|
if (countryRequest.Response == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2021-10-05 05:28:56 +00:00
|
|
|
|
return new CountriesTable(1, countryRequest.Response.Countries);
|
2021-10-05 08:59:38 +00:00
|
|
|
|
}
|
2020-02-05 20:06:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 18:26:25 +00:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
lastRequest?.Cancel();
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
2019-11-30 00:01:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|