1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:18:22 +08:00

Merge pull request #22554 from Walavouchey/ranking-accuracycircle-readability

Improve readability of `AccuracyCircle`
This commit is contained in:
Dean Herbert 2023-02-10 17:03:46 +09:00 committed by GitHub
commit eccde923e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 161 additions and 52 deletions

View File

@ -24,17 +24,26 @@ namespace osu.Game.Tests.Visual.Ranking
{
public partial class TestSceneAccuracyCircle : OsuTestScene
{
[TestCase(0.2, ScoreRank.D)]
[TestCase(0.5, ScoreRank.D)]
[TestCase(0.75, ScoreRank.C)]
[TestCase(0.85, ScoreRank.B)]
[TestCase(0.925, ScoreRank.A)]
[TestCase(0.975, ScoreRank.S)]
[TestCase(0.9999, ScoreRank.S)]
[TestCase(1, ScoreRank.X)]
public void TestRank(double accuracy, ScoreRank rank)
[TestCase(0)]
[TestCase(0.2)]
[TestCase(0.5)]
[TestCase(0.6999)]
[TestCase(0.7)]
[TestCase(0.75)]
[TestCase(0.7999)]
[TestCase(0.8)]
[TestCase(0.85)]
[TestCase(0.8999)]
[TestCase(0.9)]
[TestCase(0.925)]
[TestCase(0.9499)]
[TestCase(0.95)]
[TestCase(0.975)]
[TestCase(0.9999)]
[TestCase(1)]
public void TestRank(double accuracy)
{
var score = createScore(accuracy, rank);
var score = createScore(accuracy, ScoreProcessor.RankFromAccuracy(accuracy));
addCircleStep(score);
}

View File

@ -7,21 +7,28 @@ using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Localisation;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Extensions;
using osu.Game.Localisation;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Replays;
using osu.Game.Scoring;
using osu.Framework.Localisation;
using osu.Game.Localisation;
namespace osu.Game.Rulesets.Scoring
{
public partial class ScoreProcessor : JudgementProcessor
{
private const double accuracy_cutoff_x = 1;
private const double accuracy_cutoff_s = 0.95;
private const double accuracy_cutoff_a = 0.9;
private const double accuracy_cutoff_b = 0.8;
private const double accuracy_cutoff_c = 0.7;
private const double accuracy_cutoff_d = 0;
private const double max_score = 1000000;
/// <summary>
@ -160,7 +167,7 @@ namespace osu.Game.Rulesets.Scoring
Combo.ValueChanged += combo => HighestCombo.Value = Math.Max(HighestCombo.Value, combo.NewValue);
Accuracy.ValueChanged += accuracy =>
{
Rank.Value = rankFrom(accuracy.NewValue);
Rank.Value = RankFromAccuracy(accuracy.NewValue);
foreach (var mod in Mods.Value.OfType<IApplicableToScoreProcessor>())
Rank.Value = mod.AdjustRank(Rank.Value, accuracy.NewValue);
};
@ -369,22 +376,6 @@ namespace osu.Game.Rulesets.Scoring
}
}
private ScoreRank rankFrom(double acc)
{
if (acc == 1)
return ScoreRank.X;
if (acc >= 0.95)
return ScoreRank.S;
if (acc >= 0.9)
return ScoreRank.A;
if (acc >= 0.8)
return ScoreRank.B;
if (acc >= 0.7)
return ScoreRank.C;
return ScoreRank.D;
}
/// <summary>
/// Resets this ScoreProcessor to a default state.
/// </summary>
@ -583,6 +574,62 @@ namespace osu.Game.Rulesets.Scoring
hitEvents.Clear();
}
#region Static helper methods
/// <summary>
/// Given an accuracy (0..1), return the correct <see cref="ScoreRank"/>.
/// </summary>
public static ScoreRank RankFromAccuracy(double accuracy)
{
if (accuracy == accuracy_cutoff_x)
return ScoreRank.X;
if (accuracy >= accuracy_cutoff_s)
return ScoreRank.S;
if (accuracy >= accuracy_cutoff_a)
return ScoreRank.A;
if (accuracy >= accuracy_cutoff_b)
return ScoreRank.B;
if (accuracy >= accuracy_cutoff_c)
return ScoreRank.C;
return ScoreRank.D;
}
/// <summary>
/// Given a <see cref="ScoreRank"/>, return the cutoff accuracy (0..1).
/// Accuracy must be greater than or equal to the cutoff to qualify for the provided rank.
/// </summary>
public static double AccuracyCutoffFromRank(ScoreRank rank)
{
switch (rank)
{
case ScoreRank.X:
case ScoreRank.XH:
return accuracy_cutoff_x;
case ScoreRank.S:
case ScoreRank.SH:
return accuracy_cutoff_s;
case ScoreRank.A:
return accuracy_cutoff_a;
case ScoreRank.B:
return accuracy_cutoff_b;
case ScoreRank.C:
return accuracy_cutoff_c;
case ScoreRank.D:
return accuracy_cutoff_d;
default:
throw new ArgumentOutOfRangeException(nameof(rank), rank, null);
}
}
#endregion
/// <summary>
/// Stores the required scoring data that fulfils the minimum requirements for a <see cref="ScoreProcessor"/> to calculate score.
/// </summary>

View File

@ -17,6 +17,7 @@ using osu.Framework.Utils;
using osu.Game.Audio;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Skinning;
using osuTK;
@ -28,6 +29,13 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
/// </summary>
public partial class AccuracyCircle : CompositeDrawable
{
private static readonly double accuracy_x = ScoreProcessor.AccuracyCutoffFromRank(ScoreRank.X);
private static readonly double accuracy_s = ScoreProcessor.AccuracyCutoffFromRank(ScoreRank.S);
private static readonly double accuracy_a = ScoreProcessor.AccuracyCutoffFromRank(ScoreRank.A);
private static readonly double accuracy_b = ScoreProcessor.AccuracyCutoffFromRank(ScoreRank.B);
private static readonly double accuracy_c = ScoreProcessor.AccuracyCutoffFromRank(ScoreRank.C);
private static readonly double accuracy_d = ScoreProcessor.AccuracyCutoffFromRank(ScoreRank.D);
/// <summary>
/// Duration for the transforms causing this component to appear.
/// </summary>
@ -73,6 +81,11 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
/// </summary>
private const double virtual_ss_percentage = 0.01;
/// <summary>
/// The width of a <see cref="RankNotch"/> in terms of accuracy.
/// </summary>
public const double NOTCH_WIDTH_PERCENTAGE = 1.0 / 360;
/// <summary>
/// The easing for the circle filling transforms.
/// </summary>
@ -145,49 +158,49 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.ForRank(ScoreRank.X),
InnerRadius = RANK_CIRCLE_RADIUS,
Current = { Value = 1 }
Current = { Value = accuracy_x }
},
new CircularProgress
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.ForRank(ScoreRank.S),
InnerRadius = RANK_CIRCLE_RADIUS,
Current = { Value = 1 - virtual_ss_percentage }
Current = { Value = accuracy_x - virtual_ss_percentage }
},
new CircularProgress
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.ForRank(ScoreRank.A),
InnerRadius = RANK_CIRCLE_RADIUS,
Current = { Value = 0.95f }
Current = { Value = accuracy_s }
},
new CircularProgress
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.ForRank(ScoreRank.B),
InnerRadius = RANK_CIRCLE_RADIUS,
Current = { Value = 0.9f }
Current = { Value = accuracy_a }
},
new CircularProgress
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.ForRank(ScoreRank.C),
InnerRadius = RANK_CIRCLE_RADIUS,
Current = { Value = 0.8f }
Current = { Value = accuracy_b }
},
new CircularProgress
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.ForRank(ScoreRank.D),
InnerRadius = RANK_CIRCLE_RADIUS,
Current = { Value = 0.7f }
Current = { Value = accuracy_c }
},
new RankNotch(0),
new RankNotch((float)(1 - virtual_ss_percentage)),
new RankNotch(0.95f),
new RankNotch(0.9f),
new RankNotch(0.8f),
new RankNotch(0.7f),
new RankNotch((float)accuracy_x),
new RankNotch((float)(accuracy_x - virtual_ss_percentage)),
new RankNotch((float)accuracy_s),
new RankNotch((float)accuracy_a),
new RankNotch((float)accuracy_b),
new RankNotch((float)accuracy_c),
new BufferedContainer
{
Name = "Graded circle mask",
@ -215,12 +228,13 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
Padding = new MarginPadding { Vertical = -15, Horizontal = -20 },
Children = new[]
{
new RankBadge(1, getRank(ScoreRank.X)),
new RankBadge(0.95, getRank(ScoreRank.S)),
new RankBadge(0.9, getRank(ScoreRank.A)),
new RankBadge(0.8, getRank(ScoreRank.B)),
new RankBadge(0.7, getRank(ScoreRank.C)),
new RankBadge(0.35, getRank(ScoreRank.D)),
// The S and A badges are moved down slightly to prevent collision with the SS badge.
new RankBadge(accuracy_x, accuracy_x, getRank(ScoreRank.X)),
new RankBadge(accuracy_s, Interpolation.Lerp(accuracy_s, (accuracy_x - virtual_ss_percentage), 0.25), getRank(ScoreRank.S)),
new RankBadge(accuracy_a, Interpolation.Lerp(accuracy_a, accuracy_s, 0.25), getRank(ScoreRank.A)),
new RankBadge(accuracy_b, Interpolation.Lerp(accuracy_b, accuracy_a, 0.5), getRank(ScoreRank.B)),
new RankBadge(accuracy_c, Interpolation.Lerp(accuracy_c, accuracy_b, 0.5), getRank(ScoreRank.C)),
new RankBadge(accuracy_d, Interpolation.Lerp(accuracy_d, accuracy_c, 0.5), getRank(ScoreRank.D)),
}
},
rankText = new RankText(score.Rank)
@ -263,7 +277,39 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
using (BeginDelayedSequence(ACCURACY_TRANSFORM_DELAY))
{
double targetAccuracy = score.Rank == ScoreRank.X || score.Rank == ScoreRank.XH ? 1 : Math.Min(1 - virtual_ss_percentage, score.Accuracy);
double targetAccuracy = score.Accuracy;
double[] notchPercentages =
{
accuracy_s,
accuracy_a,
accuracy_b,
accuracy_c,
};
// Ensure the gauge overshoots or undershoots a bit so it doesn't land in the gaps of the inner graded circle (caused by `RankNotch`es),
// to prevent ambiguity on what grade it's pointing at.
foreach (double p in notchPercentages)
{
if (Precision.AlmostEquals(p, targetAccuracy, NOTCH_WIDTH_PERCENTAGE / 2))
{
int tippingDirection = targetAccuracy - p >= 0 ? 1 : -1; // We "round up" here to match rank criteria
targetAccuracy = p + tippingDirection * (NOTCH_WIDTH_PERCENTAGE / 2);
break;
}
}
// The final gap between 99.999...% (S) and 100% (SS) is exaggerated by `virtual_ss_percentage`. We don't want to land there either.
if (score.Rank == ScoreRank.X || score.Rank == ScoreRank.XH)
targetAccuracy = 1;
else
targetAccuracy = Math.Min(accuracy_x - virtual_ss_percentage - NOTCH_WIDTH_PERCENTAGE / 2, targetAccuracy);
// The accuracy circle gauge visually fills up a bit too much.
// This wouldn't normally matter but we want it to align properly with the inner graded circle in the above cases.
const double visual_alignment_offset = 0.001;
if (targetAccuracy < 1 && targetAccuracy >= visual_alignment_offset)
targetAccuracy -= visual_alignment_offset;
accuracyCircle.FillTo(targetAccuracy, ACCURACY_TRANSFORM_DURATION, ACCURACY_TRANSFORM_EASING);
@ -293,7 +339,7 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
if (badge.Accuracy > score.Accuracy)
continue;
using (BeginDelayedSequence(inverseEasing(ACCURACY_TRANSFORM_EASING, Math.Min(1 - virtual_ss_percentage, badge.Accuracy) / targetAccuracy) * ACCURACY_TRANSFORM_DURATION))
using (BeginDelayedSequence(inverseEasing(ACCURACY_TRANSFORM_EASING, Math.Min(accuracy_x - virtual_ss_percentage, badge.Accuracy) / targetAccuracy) * ACCURACY_TRANSFORM_DURATION))
{
badge.Appear();

View File

@ -27,6 +27,11 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
/// </summary>
public readonly double Accuracy;
/// <summary>
/// The position around the <see cref="AccuracyCircle"/> to display this badge.
/// </summary>
private readonly double displayPosition;
private readonly ScoreRank rank;
private Drawable rankContainer;
@ -36,10 +41,12 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
/// Creates a new <see cref="RankBadge"/>.
/// </summary>
/// <param name="accuracy">The accuracy value corresponding to <paramref name="rank"/>.</param>
/// <param name="position">The position around the <see cref="AccuracyCircle"/> to display this badge.</param>
/// <param name="rank">The <see cref="ScoreRank"/> to be displayed in this <see cref="RankBadge"/>.</param>
public RankBadge(double accuracy, ScoreRank rank)
public RankBadge(double accuracy, double position, ScoreRank rank)
{
Accuracy = accuracy;
displayPosition = position;
this.rank = rank;
RelativeSizeAxes = Axes.Both;
@ -92,7 +99,7 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
base.Update();
// Starts at -90deg (top) and moves counter-clockwise by the accuracy
rankContainer.Position = circlePosition(-MathF.PI / 2 - (1 - (float)Accuracy) * MathF.PI * 2);
rankContainer.Position = circlePosition(-MathF.PI / 2 - (1 - (float)displayPosition) * MathF.PI * 2);
}
private Vector2 circlePosition(float t)

View File

@ -41,7 +41,7 @@ namespace osu.Game.Screens.Ranking.Expanded.Accuracy
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Y,
Height = AccuracyCircle.RANK_CIRCLE_RADIUS,
Width = 1f,
Width = (float)AccuracyCircle.NOTCH_WIDTH_PERCENTAGE * 360f,
Colour = OsuColour.Gray(0.3f),
EdgeSmoothness = new Vector2(1f)
}