1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 00:03:08 +08:00

Merge pull request #31084 from NicholasChin28/mania-profile-overlay-tooltip

Add missing mania tooltip overlay for 4k and 7k
This commit is contained in:
Bartłomiej Dach 2024-12-16 14:22:41 +09:00 committed by GitHub
commit d72a0b04b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 106 additions and 6 deletions

View File

@ -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;
@ -162,18 +164,77 @@ namespace osu.Game.Overlays.Profile.Header.Components
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;
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;
LocalisableString? result = null;
if (variants?.Count > 0)
{
foreach (var variant in variants)
{
if (variant.GlobalRank != null)
{
var variantText = LocalisableString.Interpolate($"{variant.VariantType.GetLocalisableDescription()}: {variant.GlobalRank.ToLocalisableString("\\##,##0")}");
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
{
private readonly OsuSpriteText rankCount;

View File

@ -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;
@ -74,6 +79,10 @@ namespace osu.Game.Users
[JsonProperty(@"grade_counts")]
public Grades GradesCount;
[JsonProperty(@"variants")]
[CanBeNull]
public List<Variant> Variants;
public struct Grades
{
[JsonProperty(@"ssh")]
@ -118,5 +127,35 @@ namespace osu.Game.Users
}
}
}
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;
}
}
}