From d101add1591599c53f860c21e31901cbed220060 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Mon, 8 Feb 2021 21:14:12 +0300 Subject: [PATCH] Display user global rank for selected ruleset in participants panel --- .../Participants/ParticipantPanel.cs | 21 ++++++++++++------- osu.Game/Users/UserStatistics.cs | 8 +++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs index 0ee1b6d684..f69a21918a 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantPanel.cs @@ -35,9 +35,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants [Resolved] private RulesetStore rulesets { get; set; } + private SpriteIcon crown; + private OsuSpriteText userRankText; private ModDisplay userModsDisplay; private StateDisplay userStateDisplay; - private SpriteIcon crown; public ParticipantPanel(MultiplayerRoomUser user) { @@ -119,12 +120,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 18), Text = user?.Username }, - new OsuSpriteText + userRankText = new OsuSpriteText { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Font = OsuFont.GetFont(size: 14), - Text = user?.CurrentModeRank != null ? $"#{user.CurrentModeRank}" : string.Empty } } }, @@ -162,6 +162,15 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants const double fade_time = 50; + var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID); + + var currentModeRank = User.User?.GetStatisticsFor(ruleset)?.GlobalRank; + + // fallback to current mode rank for testing purposes. + currentModeRank ??= User.User?.CurrentModeRank; + + userRankText.Text = currentModeRank != null ? $"#{currentModeRank.Value:N0}" : string.Empty; + userStateDisplay.Status = User.State; if (Room.Host?.Equals(User) == true) @@ -171,11 +180,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants // If the mods are updated at the end of the frame, the flow container will skip a reflow cycle: https://github.com/ppy/osu-framework/issues/4187 // This looks particularly jarring here, so re-schedule the update to that start of our frame as a fix. - Schedule(() => - { - var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID).CreateInstance(); - userModsDisplay.Current.Value = User.Mods.Select(m => m.ToMod(ruleset)).ToList(); - }); + Schedule(() => userModsDisplay.Current.Value = User.Mods.Select(m => m.ToMod(ruleset.CreateInstance())).ToList()); } public MenuItem[] ContextMenuItems diff --git a/osu.Game/Users/UserStatistics.cs b/osu.Game/Users/UserStatistics.cs index 8b7699d0ad..6c069f674e 100644 --- a/osu.Game/Users/UserStatistics.cs +++ b/osu.Game/Users/UserStatistics.cs @@ -3,6 +3,7 @@ using System; using Newtonsoft.Json; +using osu.Game.Online.API.Requests; using osu.Game.Scoring; using osu.Game.Utils; using static osu.Game.Users.User; @@ -26,6 +27,13 @@ namespace osu.Game.Users public int Progress; } + /// + /// This must only be used when coming from condensed user responses (e.g. from ), otherwise use Ranks.Global. + /// + // todo: this should likely be moved to a separate UserStatisticsCompact class at some point. + [JsonProperty(@"global_rank")] + public int? GlobalRank; + [JsonProperty(@"pp")] public decimal? PP;