Bind `UserRankPanel` values to `Statistics` bindable in `APIAccess`

This commit is contained in:
StanR 2024-01-03 14:32:32 +06:00
parent c4be6fa974
commit 3df7430d2e
2 changed files with 33 additions and 2 deletions

View File

@ -9,6 +9,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
@ -157,6 +158,23 @@ public void TestUserActivityChange()
AddAssert("visit message is not visible", () => !boundPanel2.LastVisitMessage.IsPresent);
}
[Test]
public void TestUserStatisticsChange()
{
AddStep("update statistics", () =>
{
API.UpdateStatistics(new UserStatistics
{
GlobalRank = RNG.Next(100000),
CountryRank = RNG.Next(100000)
});
});
AddStep("set statistics to empty", () =>
{
API.UpdateStatistics(new UserStatistics());
});
}
private UserActivity soloGameStatusForRuleset(int rulesetId) => new UserActivity.InSoloGame(new BeatmapInfo(), rulesetStore.GetRuleset(rulesetId)!);
private ScoreInfo createScore(string name) => new ScoreInfo(new TestBeatmap(Ruleset.Value).BeatmapInfo)

View File

@ -7,6 +7,7 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Profile.Header.Components;
using osu.Game.Resources.Localisation.Web;
@ -23,6 +24,12 @@ public partial class UserRankPanel : UserPanel
private const int padding = 10;
private const int main_content_height = 80;
[Resolved]
private IAPIProvider api { get; set; } = null!;
private ProfileValueDisplay globalRankDisplay = null!;
private ProfileValueDisplay countryRankDisplay = null!;
public UserRankPanel(APIUser user)
: base(user)
{
@ -34,6 +41,12 @@ public UserRankPanel(APIUser user)
private void load()
{
BorderColour = ColourProvider?.Light1 ?? Colours.GreyVioletLighter;
api.Statistics.ValueChanged += e =>
{
globalRankDisplay.Content = e.NewValue?.GlobalRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-";
countryRankDisplay.Content = e.NewValue?.CountryRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-";
};
}
protected override Drawable CreateLayout()
@ -166,12 +179,12 @@ protected override Drawable CreateLayout()
{
new Drawable[]
{
new ProfileValueDisplay(true)
globalRankDisplay = new ProfileValueDisplay(true)
{
Title = UsersStrings.ShowRankGlobalSimple,
Content = User.Statistics?.GlobalRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-"
},
new ProfileValueDisplay(true)
countryRankDisplay = new ProfileValueDisplay(true)
{
Title = UsersStrings.ShowRankCountrySimple,
Content = User.Statistics?.CountryRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-"