1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 16:47:46 +08:00

Centralise global rank display logic to new class

This commit is contained in:
Joseph Madamba 2024-02-09 15:33:49 -08:00
parent 8d1d65a469
commit ae89b89928
3 changed files with 37 additions and 10 deletions

View 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.
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Users;
namespace osu.Game.Overlays.Profile.Header.Components
{
public partial class GlobalRankDisplay : ProfileValueDisplay
{
public readonly Bindable<UserStatistics?> UserStatistics = new Bindable<UserStatistics?>();
public GlobalRankDisplay()
: base(true)
{
Title = UsersStrings.ShowRankGlobalSimple;
}
protected override void LoadComplete()
{
base.LoadComplete();
UserStatistics.BindValueChanged(s =>
{
Content = s.NewValue?.GlobalRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-";
}, true);
}
}
}

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
private readonly Dictionary<ScoreRank, ScoreRankInfo> scoreRankInfos = new Dictionary<ScoreRank, ScoreRankInfo>(); private readonly Dictionary<ScoreRank, ScoreRankInfo> scoreRankInfos = new Dictionary<ScoreRank, ScoreRankInfo>();
private ProfileValueDisplay medalInfo = null!; private ProfileValueDisplay medalInfo = null!;
private ProfileValueDisplay ppInfo = null!; private ProfileValueDisplay ppInfo = null!;
private ProfileValueDisplay detailGlobalRank = null!; private GlobalRankDisplay detailGlobalRank = null!;
private ProfileValueDisplay detailCountryRank = null!; private ProfileValueDisplay detailCountryRank = null!;
private RankGraph rankGraph = null!; private RankGraph rankGraph = null!;
@ -52,10 +52,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
Spacing = new Vector2(20), Spacing = new Vector2(20),
Children = new Drawable[] Children = new Drawable[]
{ {
detailGlobalRank = new ProfileValueDisplay(true) detailGlobalRank = new GlobalRankDisplay(),
{
Title = UsersStrings.ShowRankGlobalSimple,
},
detailCountryRank = new ProfileValueDisplay(true) detailCountryRank = new ProfileValueDisplay(true)
{ {
Title = UsersStrings.ShowRankCountrySimple, Title = UsersStrings.ShowRankCountrySimple,
@ -142,7 +139,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
foreach (var scoreRankInfo in scoreRankInfos) foreach (var scoreRankInfo in scoreRankInfos)
scoreRankInfo.Value.RankCount = user?.Statistics?.GradesCount[scoreRankInfo.Key] ?? 0; scoreRankInfo.Value.RankCount = user?.Statistics?.GradesCount[scoreRankInfo.Key] ?? 0;
detailGlobalRank.Content = user?.Statistics?.GlobalRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-"; detailGlobalRank.UserStatistics.Value = user?.Statistics;
detailCountryRank.Content = user?.Statistics?.CountryRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-"; detailCountryRank.Content = user?.Statistics?.CountryRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-";
rankGraph.Statistics.Value = user?.Statistics; rankGraph.Statistics.Value = user?.Statistics;

View File

@ -27,7 +27,6 @@ namespace osu.Game.Users
[Resolved] [Resolved]
private IAPIProvider api { get; set; } = null!; private IAPIProvider api { get; set; } = null!;
private ProfileValueDisplay globalRankDisplay = null!;
private ProfileValueDisplay countryRankDisplay = null!; private ProfileValueDisplay countryRankDisplay = null!;
private readonly IBindable<UserStatistics?> statistics = new Bindable<UserStatistics?>(); private readonly IBindable<UserStatistics?> statistics = new Bindable<UserStatistics?>();
@ -47,7 +46,6 @@ namespace osu.Game.Users
statistics.BindTo(api.Statistics); statistics.BindTo(api.Statistics);
statistics.BindValueChanged(stats => statistics.BindValueChanged(stats =>
{ {
globalRankDisplay.Content = stats.NewValue?.GlobalRank?.ToLocalisableString("\\##,##0") ?? "-";
countryRankDisplay.Content = stats.NewValue?.CountryRank?.ToLocalisableString("\\##,##0") ?? "-"; countryRankDisplay.Content = stats.NewValue?.CountryRank?.ToLocalisableString("\\##,##0") ?? "-";
}, true); }, true);
} }
@ -163,9 +161,9 @@ namespace osu.Game.Users
{ {
new Drawable[] new Drawable[]
{ {
globalRankDisplay = new ProfileValueDisplay(true) new GlobalRankDisplay
{ {
Title = UsersStrings.ShowRankGlobalSimple, UserStatistics = { BindTarget = statistics },
}, },
countryRankDisplay = new ProfileValueDisplay(true) countryRankDisplay = new ProfileValueDisplay(true)
{ {