Skip to content

Commit

Permalink
Merge pull request #27107 from Joehuu/rank-highest-tooltip
Browse files Browse the repository at this point in the history
Add highest rank tooltip to global rank display
  • Loading branch information
bdach authored Feb 22, 2024
2 parents d82b398 + 2ff8667 commit 57bb0b8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
5 changes: 5 additions & 0 deletions osu.Game.Tests/Visual/Online/TestSceneUserProfileOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public void TestLogin()
@"top_ranks",
@"medals"
},
RankHighest = new APIUser.UserRankHighest
{
Rank = 1,
UpdatedAt = DateTimeOffset.Now,
},
Statistics = new UserStatistics
{
IsRanked = true,
Expand Down
13 changes: 13 additions & 0 deletions osu.Game/Online/API/Requests/Responses/APIUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public class APIUser : IEquatable<APIUser>, IUser
[JsonProperty(@"previous_usernames")]
public string[] PreviousUsernames;

[JsonProperty(@"rank_highest")]
[CanBeNull]
public UserRankHighest RankHighest;

public class UserRankHighest
{
[JsonProperty(@"rank")]
public int Rank;

[JsonProperty(@"updated_at")]
public DateTimeOffset UpdatedAt;
}

[JsonProperty(@"country_code")]
private string countryCodeString;

Expand Down
7 changes: 7 additions & 0 deletions osu.Game/Overlays/Profile/Header/Components/MainDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ private void updateDisplay(UserProfileData? data)
scoreRankInfo.Value.RankCount = user?.Statistics?.GradesCount[scoreRankInfo.Key] ?? 0;

detailGlobalRank.Content = user?.Statistics?.GlobalRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-";

var rankHighest = user?.RankHighest;

detailGlobalRank.ContentTooltipText = rankHighest != null
? UsersStrings.ShowRankHighest(rankHighest.Rank.ToLocalisableString("\\##,##0"), rankHighest.UpdatedAt.ToLocalisableString(@"d MMM yyyy"))
: string.Empty;

detailCountryRank.Content = user?.Statistics?.CountryRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-";

rankGraph.Statistics.Value = user?.Statistics;
Expand Down
17 changes: 14 additions & 3 deletions osu.Game/Overlays/Profile/Header/Components/ProfileValueDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
Expand All @@ -13,7 +14,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
public partial class ProfileValueDisplay : CompositeDrawable
{
private readonly OsuSpriteText title;
private readonly OsuSpriteText content;
private readonly ContentText content;

public LocalisableString Title
{
Expand All @@ -25,6 +26,11 @@ public LocalisableString Content
set => content.Text = value;
}

public LocalisableString ContentTooltipText
{
set => content.TooltipText = value;
}

public ProfileValueDisplay(bool big = false, int minimumWidth = 60)
{
AutoSizeAxes = Axes.Both;
Expand All @@ -38,9 +44,9 @@ public ProfileValueDisplay(bool big = false, int minimumWidth = 60)
{
Font = OsuFont.GetFont(size: 12)
},
content = new OsuSpriteText
content = new ContentText
{
Font = OsuFont.GetFont(size: big ? 30 : 20, weight: FontWeight.Light)
Font = OsuFont.GetFont(size: big ? 30 : 20, weight: FontWeight.Light),
},
new Container // Add a minimum size to the FillFlowContainer
{
Expand All @@ -56,5 +62,10 @@ private void load(OverlayColourProvider colourProvider)
title.Colour = colourProvider.Content1;
content.Colour = colourProvider.Content2;
}

private partial class ContentText : OsuSpriteText, IHasTooltip
{
public LocalisableString TooltipText { get; set; }
}
}
}
11 changes: 3 additions & 8 deletions osu.Game/Overlays/Profile/Header/Components/TotalPlayTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;

namespace osu.Game.Overlays.Profile.Header.Components
{
public partial class TotalPlayTime : CompositeDrawable, IHasTooltip
public partial class TotalPlayTime : CompositeDrawable
{
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();

public LocalisableString TooltipText { get; set; }

private ProfileValueDisplay info = null!;

public TotalPlayTime()
{
AutoSizeAxes = Axes.Both;

TooltipText = "0 hours";
}

[BackgroundDependencyLoader]
Expand All @@ -32,6 +26,7 @@ private void load()
InternalChild = info = new ProfileValueDisplay(minimumWidth: 140)
{
Title = UsersStrings.ShowStatsPlayTime,
ContentTooltipText = "0 hours",
};

User.BindValueChanged(updateTime, true);
Expand All @@ -40,7 +35,7 @@ private void load()
private void updateTime(ValueChangedEvent<UserProfileData?> user)
{
int? playTime = user.NewValue?.User.Statistics?.PlayTime;
TooltipText = (playTime ?? 0) / 3600 + " hours";
info.ContentTooltipText = (playTime ?? 0) / 3600 + " hours";
info.Content = formatTime(playTime);
}

Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Users/UserRankPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ protected override Drawable CreateLayout()
globalRankDisplay = new ProfileValueDisplay(true)
{
Title = UsersStrings.ShowRankGlobalSimple,
// TODO: implement highest rank tooltip
// `RankHighest` resides in `APIUser`, but `api.LocalUser` doesn't update
// maybe move to `UserStatistics` in api, so `SoloStatisticsWatcher` can update the value
},
countryRankDisplay = new ProfileValueDisplay(true)
{
Expand Down

0 comments on commit 57bb0b8

Please sign in to comment.