Skip to content

Commit

Permalink
Merge pull request ppy#31084 from NicholasChin28/mania-profile-overla…
Browse files Browse the repository at this point in the history
…y-tooltip

Add missing mania tooltip overlay for 4k and 7k
  • Loading branch information
bdach authored Dec 16, 2024
2 parents 8a2f161 + ecb7a80 commit d72a0b0
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 5 deletions.
71 changes: 66 additions & 5 deletions osu.Game/Overlays/Profile/Header/Components/MainDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Leaderboards;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Scoring;
Expand Down Expand Up @@ -162,16 +164,75 @@ private void updateDisplay(UserProfileData? data)
scoreRankInfo.Value.RankCount = user?.Statistics?.GradesCount[scoreRankInfo.Key] ?? 0;

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

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

rankGraph.Statistics.Value = user?.Statistics;
}

private static LocalisableString getGlobalRankTooltipText(APIUser? user)
{
var rankHighest = user?.RankHighest;
var variants = user?.Statistics?.Variants;

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

detailCountryRank.Content = user?.Statistics?.CountryRank?.ToLocalisableString("\\##,##0") ?? (LocalisableString)"-";
if (variants?.Count > 0)
{
foreach (var variant in variants)
{
if (variant.GlobalRank != null)
{
var variantText = LocalisableString.Interpolate($"{variant.VariantType.GetLocalisableDescription()}: {variant.GlobalRank.ToLocalisableString("\\##,##0")}");

rankGraph.Statistics.Value = user?.Statistics;
if (result == null)
result = variantText;
else
result = LocalisableString.Interpolate($"{result}\n{variantText}");
}
}
}

if (rankHighest != null)
{
var rankHighestText = UsersStrings.ShowRankHighest(
rankHighest.Rank.ToLocalisableString("\\##,##0"),
rankHighest.UpdatedAt.ToLocalisableString(@"d MMM yyyy"));

if (result == null)
result = rankHighestText;
else
result = LocalisableString.Interpolate($"{result}\n{rankHighestText}");
}

return result ?? default;
}

private static LocalisableString getCountryRankTooltipText(APIUser? user)
{
var variants = user?.Statistics?.Variants;

LocalisableString? result = null;

if (variants?.Count > 0)
{
foreach (var variant in variants)
{
if (variant.CountryRank != null)
{
var variantText = LocalisableString.Interpolate($"{variant.VariantType.GetLocalisableDescription()}: {variant.CountryRank.ToLocalisableString("\\##,##0")}");

if (result == null)
result = variantText;
else
result = LocalisableString.Interpolate($"{result}\n{variantText}");
}
}
}

return result ?? default;
}

private partial class ScoreRankInfo : CompositeDrawable
Expand Down
39 changes: 39 additions & 0 deletions osu.Game/Users/UserStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
#nullable disable

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using osu.Framework.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Scoring;
using osu.Game.Utils;

Expand Down Expand Up @@ -74,6 +79,10 @@ public struct LevelInfo
[JsonProperty(@"grade_counts")]
public Grades GradesCount;

[JsonProperty(@"variants")]
[CanBeNull]
public List<Variant> Variants;

public struct Grades
{
[JsonProperty(@"ssh")]
Expand Down Expand Up @@ -118,5 +127,35 @@ public int this[ScoreRank rank]
}
}
}

public enum RulesetVariant
{
[EnumMember(Value = "4k")]
[LocalisableDescription(typeof(BeatmapsStrings), nameof(BeatmapsStrings.VariantMania4k))]
FourKey,

[EnumMember(Value = "7k")]
[LocalisableDescription(typeof(BeatmapsStrings), nameof(BeatmapsStrings.VariantMania7k))]
SevenKey
}

public class Variant
{
[JsonProperty("country_rank")]
public int? CountryRank;

[JsonProperty("global_rank")]
public int? GlobalRank;

[JsonProperty("mode")]
public string Mode;

[JsonProperty("pp")]
public decimal PP;

[JsonProperty("variant")]
[JsonConverter(typeof(StringEnumConverter))]
public RulesetVariant VariantType;
}
}
}

0 comments on commit d72a0b0

Please sign in to comment.