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

Add FormatStarRating() method util

This commit is contained in:
Joseph Madamba 2024-12-10 15:04:06 -08:00
parent 3035e8435d
commit e95dc2b308
No known key found for this signature in database
GPG Key ID: 8B746C7BDDF0BD76
5 changed files with 13 additions and 5 deletions

View File

@ -15,6 +15,7 @@ using osu.Game.Graphics;
using osu.Game.Models; using osu.Game.Models;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osu.Game.Utils;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -207,7 +208,7 @@ namespace osu.Game.Tournament.Components
Children = new Drawable[] Children = new Drawable[]
{ {
new DiffPiece(stats), new DiffPiece(stats),
new DiffPiece(("Star Rating", $"{beatmap.StarRating:0.00}{srExtra}")) new DiffPiece(("Star Rating", $"{beatmap.StarRating.FormatStarRating()}{srExtra}"))
} }
}, },
new FillFlowContainer new FillFlowContainer

View File

@ -5,7 +5,6 @@ using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
@ -14,6 +13,7 @@ using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Utils;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -156,7 +156,7 @@ namespace osu.Game.Beatmaps.Drawables
displayedStars.BindValueChanged(s => displayedStars.BindValueChanged(s =>
{ {
starsText.Text = s.NewValue < 0 ? "-" : s.NewValue.ToLocalisableString("0.00"); starsText.Text = s.NewValue < 0 ? "-" : s.NewValue.FormatStarRating();
background.Colour = colours.ForStarDifficulty(s.NewValue); background.Colour = colours.ForStarDifficulty(s.NewValue);

View File

@ -21,6 +21,7 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Utils;
using osuTK; using osuTK;
namespace osu.Game.Overlays.BeatmapSet namespace osu.Game.Overlays.BeatmapSet
@ -185,7 +186,7 @@ namespace osu.Game.Overlays.BeatmapSet
OnHovered = beatmap => OnHovered = beatmap =>
{ {
showBeatmap(beatmap); showBeatmap(beatmap);
starRating.Text = beatmap.StarRating.ToLocalisableString(@"0.00"); starRating.Text = beatmap.StarRating.FormatStarRating();
starRatingContainer.FadeIn(100); starRatingContainer.FadeIn(100);
}, },
OnClicked = beatmap => { Beatmap.Value = beatmap; }, OnClicked = beatmap => { Beatmap.Value = beatmap; },

View File

@ -226,7 +226,7 @@ namespace osu.Game.Skinning.Components
return computeDifficulty().ApproachRate.ToLocalisableString(@"0.##"); return computeDifficulty().ApproachRate.ToLocalisableString(@"0.##");
case BeatmapAttribute.StarRating: case BeatmapAttribute.StarRating:
return (starDifficulty?.Stars ?? 0).ToLocalisableString(@"F2"); return (starDifficulty?.Stars ?? 0).FormatStarRating();
case BeatmapAttribute.MaxPP: case BeatmapAttribute.MaxPP:
return Math.Round(starDifficulty?.PerformanceAttributes?.Total ?? 0, MidpointRounding.AwayFromZero).ToLocalisableString(); return Math.Round(starDifficulty?.PerformanceAttributes?.Total ?? 0, MidpointRounding.AwayFromZero).ToLocalisableString();

View File

@ -32,6 +32,12 @@ namespace osu.Game.Utils
/// <param name="rank">The rank/position to be formatted.</param> /// <param name="rank">The rank/position to be formatted.</param>
public static string FormatRank(this int rank) => rank.ToMetric(decimals: rank < 100_000 ? 1 : 0); public static string FormatRank(this int rank) => rank.ToMetric(decimals: rank < 100_000 ? 1 : 0);
/// <summary>
/// Formats the supplied star rating in a consistent, simplified way.
/// </summary>
/// <param name="starRating">The star rating to be formatted.</param>
public static LocalisableString FormatStarRating(this double starRating) => starRating.ToLocalisableString("0.00");
/// <summary> /// <summary>
/// Finds the number of digits after the decimal. /// Finds the number of digits after the decimal.
/// </summary> /// </summary>