2019-09-28 00:33:52 +08: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.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Overlays.Rankings.Tables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
|
using osu.Game.Rulesets.Mania;
|
|
|
|
|
using osu.Game.Rulesets.Taiko;
|
|
|
|
|
using osu.Game.Rulesets.Catch;
|
|
|
|
|
using osu.Framework.Allocation;
|
2020-02-21 14:31:40 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-02-04 02:22:37 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2019-09-28 00:33:52 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Online
|
|
|
|
|
{
|
|
|
|
|
public class TestSceneRankingsTables : OsuTestScene
|
|
|
|
|
{
|
|
|
|
|
protected override bool UseOnlineAPI => true;
|
|
|
|
|
|
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
|
|
|
|
{
|
|
|
|
|
typeof(PerformanceTable),
|
|
|
|
|
typeof(ScoresTable),
|
|
|
|
|
typeof(CountriesTable),
|
|
|
|
|
typeof(TableRowBackground),
|
2019-11-28 04:35:02 +08:00
|
|
|
|
typeof(UserBasedTable),
|
2019-11-27 23:32:31 +08:00
|
|
|
|
typeof(RankingsTable<>)
|
2019-09-28 00:33:52 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; }
|
|
|
|
|
|
2020-02-04 02:22:37 +08:00
|
|
|
|
[Cached]
|
|
|
|
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
|
|
|
|
|
|
2019-09-28 00:33:52 +08:00
|
|
|
|
private readonly BasicScrollContainer scrollFlow;
|
2020-02-21 14:31:40 +08:00
|
|
|
|
private readonly LoadingLayer loading;
|
2019-09-28 00:33:52 +08:00
|
|
|
|
private CancellationTokenSource cancellationToken;
|
|
|
|
|
private APIRequest request;
|
|
|
|
|
|
|
|
|
|
public TestSceneRankingsTables()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
scrollFlow = new BasicScrollContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0.8f,
|
|
|
|
|
},
|
2020-02-21 14:31:40 +08:00
|
|
|
|
loading = new LoadingLayer(),
|
2019-09-28 00:33:52 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
AddStep("Osu performance", () => createPerformanceTable(new OsuRuleset().RulesetInfo, null));
|
|
|
|
|
AddStep("Mania scores", () => createScoreTable(new ManiaRuleset().RulesetInfo));
|
|
|
|
|
AddStep("Taiko country scores", () => createCountryTable(new TaikoRuleset().RulesetInfo));
|
|
|
|
|
AddStep("Catch US performance page 10", () => createPerformanceTable(new CatchRuleset().RulesetInfo, "US", 10));
|
2020-02-05 02:03:17 +08:00
|
|
|
|
AddStep("Osu spotlight table (chart 271)", () => createSpotlightTable(new OsuRuleset().RulesetInfo, 271));
|
2019-09-28 00:33:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createCountryTable(RulesetInfo ruleset, int page = 1)
|
|
|
|
|
{
|
2019-11-28 04:40:52 +08:00
|
|
|
|
onLoadStarted();
|
2019-09-28 00:33:52 +08:00
|
|
|
|
|
|
|
|
|
request = new GetCountryRankingsRequest(ruleset, page);
|
|
|
|
|
((GetCountryRankingsRequest)request).Success += rankings => Schedule(() =>
|
|
|
|
|
{
|
2019-11-29 01:09:05 +08:00
|
|
|
|
var table = new CountriesTable(page, rankings.Countries);
|
2019-11-28 04:40:52 +08:00
|
|
|
|
loadTable(table);
|
2019-09-28 00:33:52 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
api.Queue(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createPerformanceTable(RulesetInfo ruleset, string country, int page = 1)
|
|
|
|
|
{
|
2019-11-28 04:40:52 +08:00
|
|
|
|
onLoadStarted();
|
2019-09-28 00:33:52 +08:00
|
|
|
|
|
|
|
|
|
request = new GetUserRankingsRequest(ruleset, country: country, page: page);
|
|
|
|
|
((GetUserRankingsRequest)request).Success += rankings => Schedule(() =>
|
|
|
|
|
{
|
2019-11-29 01:09:05 +08:00
|
|
|
|
var table = new PerformanceTable(page, rankings.Users);
|
2019-11-28 04:40:52 +08:00
|
|
|
|
loadTable(table);
|
2019-09-28 00:33:52 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
api.Queue(request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void createScoreTable(RulesetInfo ruleset, int page = 1)
|
|
|
|
|
{
|
2019-11-28 04:40:52 +08:00
|
|
|
|
onLoadStarted();
|
2019-09-28 00:33:52 +08:00
|
|
|
|
|
|
|
|
|
request = new GetUserRankingsRequest(ruleset, UserRankingsType.Score, page);
|
|
|
|
|
((GetUserRankingsRequest)request).Success += rankings => Schedule(() =>
|
|
|
|
|
{
|
2019-11-29 01:09:05 +08:00
|
|
|
|
var table = new ScoresTable(page, rankings.Users);
|
2019-11-28 04:40:52 +08:00
|
|
|
|
loadTable(table);
|
2019-09-28 00:33:52 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
api.Queue(request);
|
|
|
|
|
}
|
2019-11-28 04:40:52 +08:00
|
|
|
|
|
2020-02-04 21:20:15 +08:00
|
|
|
|
private void createSpotlightTable(RulesetInfo ruleset, int spotlight)
|
|
|
|
|
{
|
|
|
|
|
onLoadStarted();
|
|
|
|
|
|
|
|
|
|
request = new GetSpotlightRankingsRequest(ruleset, spotlight);
|
|
|
|
|
((GetSpotlightRankingsRequest)request).Success += rankings => Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
var table = new ScoresTable(1, rankings.Users);
|
|
|
|
|
loadTable(table);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
api.Queue(request);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 04:40:52 +08:00
|
|
|
|
private void onLoadStarted()
|
|
|
|
|
{
|
|
|
|
|
loading.Show();
|
|
|
|
|
request?.Cancel();
|
|
|
|
|
cancellationToken?.Cancel();
|
|
|
|
|
cancellationToken = new CancellationTokenSource();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadTable(Drawable table)
|
|
|
|
|
{
|
|
|
|
|
LoadComponentAsync(table, t =>
|
|
|
|
|
{
|
|
|
|
|
scrollFlow.Clear();
|
|
|
|
|
scrollFlow.Add(t);
|
|
|
|
|
loading.Hide();
|
|
|
|
|
}, cancellationToken.Token);
|
|
|
|
|
}
|
2019-09-28 00:33:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|