mirror of
https://github.com/ppy/osu.git
synced 2025-02-07 11:32:54 +08:00
implement pagination for rankings overlay
This commit is contained in:
parent
d72a0b04b8
commit
55ec3b13b1
@ -59,14 +59,24 @@ namespace osu.Game.Tests.Visual.Online
|
||||
AddStep("Show US", () => rankingsOverlay.ShowCountry(CountryCode.US));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPageSelection()
|
||||
{
|
||||
AddStep("Set score to performance", () => scope.Value = RankingsScope.Performance);
|
||||
AddStep("Move to next page", () => rankingsOverlay.Header.CurrentPage.Value += 1);
|
||||
AddStep("Switch to another scope", () => scope.Value = RankingsScope.Score);
|
||||
AddAssert("Check page is first one", () => rankingsOverlay.Header.CurrentPage.Value == 0);
|
||||
}
|
||||
|
||||
private void loadRankingsOverlay()
|
||||
{
|
||||
Child = rankingsOverlay = new TestRankingsOverlay
|
||||
{
|
||||
Country = { BindTarget = countryBindable },
|
||||
Header = { Current = { BindTarget = scope } },
|
||||
State = { Value = Visibility.Visible },
|
||||
};
|
||||
|
||||
countryBindable.BindTo(rankingsOverlay.Country);
|
||||
scope.BindTo(rankingsOverlay.Header.Current);
|
||||
}
|
||||
|
||||
private partial class TestRankingsOverlay : RankingsOverlay
|
||||
|
32
osu.Game/Overlays/PageableTabbleOnlineOverlay.cs
Normal file
32
osu.Game/Overlays/PageableTabbleOnlineOverlay.cs
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public abstract partial class PageableTabbleOnlineOverlay<THeader, TEnum> : TabbableOnlineOverlay<THeader, TEnum>
|
||||
where THeader : PagedTabControlOverlayHeader<TEnum>
|
||||
{
|
||||
protected PageableTabbleOnlineOverlay(OverlayColourScheme colourScheme)
|
||||
: base(colourScheme)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
Header.CurrentPage.BindValueChanged(page => OnPageChanged(page.NewValue));
|
||||
}
|
||||
|
||||
protected override void OnTabChanged(TEnum tab)
|
||||
{
|
||||
// Go back to first page if we switch to another tab
|
||||
Header.CurrentPage.SetDefault();
|
||||
base.OnTabChanged(tab);
|
||||
}
|
||||
|
||||
protected virtual void OnPageChanged(int page)
|
||||
{
|
||||
base.OnTabChanged(Header.Current.Value);
|
||||
}
|
||||
}
|
||||
}
|
39
osu.Game/Overlays/PagedTabControlOverlayHeader.cs
Normal file
39
osu.Game/Overlays/PagedTabControlOverlayHeader.cs
Normal file
@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.UserInterface.PageSelector;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// An extended overlay header that add a pagination support for a <see cref="TabControlOverlayHeader{T}" />
|
||||
/// </summary>
|
||||
/// <typeparam name="TEnum"></typeparam>
|
||||
public abstract partial class PagedTabControlOverlayHeader<TEnum> : TabControlOverlayHeader<TEnum>
|
||||
{
|
||||
private readonly PageSelector pageSelector;
|
||||
|
||||
public BindableInt CurrentPage => pageSelector.CurrentPage;
|
||||
public BindableInt AvailablesPages => pageSelector.AvailablePages;
|
||||
|
||||
protected PagedTabControlOverlayHeader()
|
||||
{
|
||||
HeaderInfo.Add(
|
||||
pageSelector = new PageSelector
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
Margin = new MarginPadding { Vertical = 15 },
|
||||
});
|
||||
}
|
||||
|
||||
public void ShowPageSelector() => pageSelector.Show();
|
||||
|
||||
public void HidePageSelector() => pageSelector.Hide();
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Rankings
|
||||
{
|
||||
public partial class RankingsOverlayHeader : TabControlOverlayHeader<RankingsScope>
|
||||
public partial class RankingsOverlayHeader : PagedTabControlOverlayHeader<RankingsScope>
|
||||
{
|
||||
public Bindable<RulesetInfo> Ruleset => rulesetSelector.Current;
|
||||
|
||||
|
@ -15,10 +15,13 @@ using osu.Game.Overlays.Rankings.Tables;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public partial class RankingsOverlay : TabbableOnlineOverlay<RankingsOverlayHeader, RankingsScope>
|
||||
public partial class RankingsOverlay : PageableTabbleOnlineOverlay<RankingsOverlayHeader, RankingsScope>
|
||||
{
|
||||
protected Bindable<CountryCode> Country => Header.Country;
|
||||
|
||||
// First page is 0, need to apply +1 to get the right data actually.
|
||||
private int currentPage => Header.CurrentPage.Value + 1;
|
||||
|
||||
private APIRequest lastRequest;
|
||||
|
||||
[Resolved]
|
||||
@ -45,7 +48,11 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
// if a country is requested, force performance scope.
|
||||
if (!Country.IsDefault)
|
||||
{
|
||||
Header.Current.Value = RankingsScope.Performance;
|
||||
Header.HidePageSelector();
|
||||
}
|
||||
else Header.ShowPageSelector();
|
||||
|
||||
Scheduler.AddOnce(triggerTabChanged);
|
||||
});
|
||||
@ -83,7 +90,10 @@ namespace osu.Game.Overlays
|
||||
|
||||
private void triggerTabChanged() => base.OnTabChanged(Header.Current.Value);
|
||||
|
||||
protected override RankingsOverlayHeader CreateHeader() => new RankingsOverlayHeader();
|
||||
protected override RankingsOverlayHeader CreateHeader() => new RankingsOverlayHeader
|
||||
{
|
||||
AvailablesPages = { Value = 200 }
|
||||
};
|
||||
|
||||
public void ShowCountry(CountryCode requested)
|
||||
{
|
||||
@ -128,16 +138,16 @@ namespace osu.Game.Overlays
|
||||
switch (Header.Current.Value)
|
||||
{
|
||||
case RankingsScope.Performance:
|
||||
return new GetUserRankingsRequest(ruleset.Value, countryCode: Country.Value);
|
||||
return new GetUserRankingsRequest(ruleset.Value, page: currentPage, countryCode: Country.Value);
|
||||
|
||||
case RankingsScope.Country:
|
||||
return new GetCountryRankingsRequest(ruleset.Value);
|
||||
return new GetCountryRankingsRequest(ruleset.Value, page: currentPage);
|
||||
|
||||
case RankingsScope.Score:
|
||||
return new GetUserRankingsRequest(ruleset.Value, UserRankingsType.Score);
|
||||
return new GetUserRankingsRequest(ruleset.Value, UserRankingsType.Score, page: currentPage);
|
||||
|
||||
case RankingsScope.Kudosu:
|
||||
return new GetKudosuRankingsRequest();
|
||||
return new GetKudosuRankingsRequest(page: currentPage);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -154,10 +164,10 @@ namespace osu.Game.Overlays
|
||||
switch (userRequest.Type)
|
||||
{
|
||||
case UserRankingsType.Performance:
|
||||
return new PerformanceTable(1, userRequest.Response.Users);
|
||||
return new PerformanceTable(currentPage, userRequest.Response.Users);
|
||||
|
||||
case UserRankingsType.Score:
|
||||
return new ScoresTable(1, userRequest.Response.Users);
|
||||
return new ScoresTable(currentPage, userRequest.Response.Users);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -167,14 +177,14 @@ namespace osu.Game.Overlays
|
||||
if (countryRequest.Response == null)
|
||||
return null;
|
||||
|
||||
return new CountriesTable(1, countryRequest.Response.Countries);
|
||||
return new CountriesTable(currentPage, countryRequest.Response.Countries);
|
||||
}
|
||||
|
||||
case GetKudosuRankingsRequest kudosuRequest:
|
||||
if (kudosuRequest.Response == null)
|
||||
return null;
|
||||
|
||||
return new KudosuTable(1, kudosuRequest.Response.Users);
|
||||
return new KudosuTable(currentPage, kudosuRequest.Response.Users);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user