Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add highest rank tooltip to global rank display #27107

Merged
merged 7 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this class keeps growing and growing and growing and growing.........


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
Loading