Skip to content

Commit

Permalink
Merge pull request #27053 from frenzibyte/unranked-pp-placeholder
Browse files Browse the repository at this point in the history
Add support for displaying "unranked PP" placeholder
  • Loading branch information
peppy committed Feb 13, 2024
2 parents 833997b + 2d65dfb commit f7a223f
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 68 deletions.
19 changes: 19 additions & 0 deletions osu.Game.Tests/Visual/Online/TestSceneScoresContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ public void TestUnprocessedPP()
});
}

[Test]
public void TestUnrankedPP()
{
AddStep("Load scores with unranked PP", () =>
{
var allScores = createScores();
allScores.Scores[0].Ranked = false;
allScores.UserScore = createUserBest();
allScores.UserScore.Score.Ranked = false;
scoresContainer.Scores = allScores;
});
}

private ulong onlineID = 1;

private APIScoresCollection createScores()
Expand Down Expand Up @@ -184,6 +197,7 @@ private APIScoresCollection createScores()
MaxCombo = 1234,
TotalScore = 1234567890,
Accuracy = 1,
Ranked = true,
},
new SoloScoreInfo
{
Expand All @@ -206,6 +220,7 @@ private APIScoresCollection createScores()
MaxCombo = 1234,
TotalScore = 1234789,
Accuracy = 0.9997,
Ranked = true,
},
new SoloScoreInfo
{
Expand All @@ -227,6 +242,7 @@ private APIScoresCollection createScores()
MaxCombo = 1234,
TotalScore = 12345678,
Accuracy = 0.9854,
Ranked = true,
},
new SoloScoreInfo
{
Expand All @@ -247,6 +263,7 @@ private APIScoresCollection createScores()
MaxCombo = 1234,
TotalScore = 1234567,
Accuracy = 0.8765,
Ranked = true,
},
new SoloScoreInfo
{
Expand All @@ -263,6 +280,7 @@ private APIScoresCollection createScores()
MaxCombo = 1234,
TotalScore = 123456,
Accuracy = 0.6543,
Ranked = true,
},
}
};
Expand Down Expand Up @@ -309,6 +327,7 @@ private APIScoresCollection createScores()
MaxCombo = 1234,
TotalScore = 123456,
Accuracy = 0.6543,
Ranked = true,
},
Position = 1337,
};
Expand Down
53 changes: 48 additions & 5 deletions osu.Game.Tests/Visual/Online/TestSceneUserProfileScores.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public TestSceneUserProfileScores()
new APIMod { Acronym = new OsuModHardRock().Acronym },
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
},
Accuracy = 0.9813
Accuracy = 0.9813,
Ranked = true,
};

var secondScore = new SoloScoreInfo
Expand All @@ -62,7 +63,8 @@ public TestSceneUserProfileScores()
new APIMod { Acronym = new OsuModHardRock().Acronym },
new APIMod { Acronym = new OsuModDoubleTime().Acronym },
},
Accuracy = 0.998546
Accuracy = 0.998546,
Ranked = true,
};

var thirdScore = new SoloScoreInfo
Expand All @@ -79,7 +81,8 @@ public TestSceneUserProfileScores()
DifficultyName = "Insane"
},
EndedAt = DateTimeOffset.Now,
Accuracy = 0.9726
Accuracy = 0.9726,
Ranked = true,
};

var noPPScore = new SoloScoreInfo
Expand All @@ -95,7 +98,26 @@ public TestSceneUserProfileScores()
DifficultyName = "[4K] Cataclysmic Hypernova"
},
EndedAt = DateTimeOffset.Now,
Accuracy = 0.55879
Accuracy = 0.55879,
Ranked = true,
};

var lovedScore = new SoloScoreInfo
{
Rank = ScoreRank.B,
Beatmap = new APIBeatmap
{
BeatmapSet = new APIBeatmapSet
{
Title = "C18H27NO3(extend)",
Artist = "Team Grimoire",
},
DifficultyName = "[4K] Cataclysmic Hypernova",
Status = BeatmapOnlineStatus.Loved,
},
EndedAt = DateTimeOffset.Now,
Accuracy = 0.55879,
Ranked = true,
};

var unprocessedPPScore = new SoloScoreInfo
Expand All @@ -112,7 +134,26 @@ public TestSceneUserProfileScores()
Status = BeatmapOnlineStatus.Ranked,
},
EndedAt = DateTimeOffset.Now,
Accuracy = 0.55879
Accuracy = 0.55879,
Ranked = true,
};

var unrankedPPScore = new SoloScoreInfo
{
Rank = ScoreRank.B,
Beatmap = new APIBeatmap
{
BeatmapSet = new APIBeatmapSet
{
Title = "C18H27NO3(extend)",
Artist = "Team Grimoire",
},
DifficultyName = "[4K] Cataclysmic Hypernova",
Status = BeatmapOnlineStatus.Ranked,
},
EndedAt = DateTimeOffset.Now,
Accuracy = 0.55879,
Ranked = false,
};

Add(new FillFlowContainer
Expand All @@ -128,7 +169,9 @@ public TestSceneUserProfileScores()
new ColourProvidedContainer(OverlayColourScheme.Green, new DrawableProfileScore(firstScore)),
new ColourProvidedContainer(OverlayColourScheme.Green, new DrawableProfileScore(secondScore)),
new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileScore(noPPScore)),
new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileScore(lovedScore)),
new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileScore(unprocessedPPScore)),
new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileScore(unrankedPPScore)),
new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileWeightedScore(firstScore, 0.97)),
new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileWeightedScore(secondScore, 0.85)),
new ColourProvidedContainer(OverlayColourScheme.Pink, new DrawableProfileWeightedScore(thirdScore, 0.66)),
Expand Down
17 changes: 17 additions & 0 deletions osu.Game/Graphics/Sprites/SpriteIconWithTooltip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;

namespace osu.Game.Graphics.Sprites
{
/// <summary>
/// A <see cref="SpriteIcon"/> with a publicly settable tooltip text.
/// </summary>
public partial class SpriteIconWithTooltip : SpriteIcon, IHasTooltip
{
public LocalisableString TooltipText { get; set; }
}
}
16 changes: 16 additions & 0 deletions osu.Game/Graphics/Sprites/SpriteTextWithTooltip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;

namespace osu.Game.Graphics.Sprites
{
/// <summary>
/// An <see cref="OsuSpriteText"/> with a publicly settable tooltip text.
/// </summary>
internal partial class SpriteTextWithTooltip : OsuSpriteText, IHasTooltip
{
public LocalisableString TooltipText { get; set; }
}
}
4 changes: 4 additions & 0 deletions osu.Game/Online/API/Requests/Responses/SoloScoreInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public class SoloScoreInfo : IScoreInfo
[JsonProperty("has_replay")]
public bool HasReplay { get; set; }

[JsonProperty("ranked")]
public bool Ranked { get; set; }

// These properties are calculated or not relevant to any external usage.
public bool ShouldSerializeID() => false;
public bool ShouldSerializeUser() => false;
Expand Down Expand Up @@ -213,6 +216,7 @@ public ScoreInfo ToScoreInfo(Mod[] mods, IBeatmapInfo? beatmap = null)
HasOnlineReplay = HasReplay,
Mods = mods,
PP = PP,
Ranked = Ranked,
};

if (beatmap is BeatmapInfo realmBeatmap)
Expand Down
24 changes: 20 additions & 4 deletions osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
using osu.Framework.Localisation;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring.Drawables;

namespace osu.Game.Overlays.BeatmapSet.Scores
{
Expand Down Expand Up @@ -180,10 +180,26 @@ private Drawable[] createContent(int index, ScoreInfo score)

if (showPerformancePoints)
{
if (score.PP != null)
content.Add(new StatisticText(score.PP, format: @"N0"));
if (!score.Ranked)
{
content.Add(new SpriteTextWithTooltip
{
Text = "-",
Font = OsuFont.GetFont(size: text_size),
TooltipText = ScoresStrings.StatusNoPp
});
}
else if (score.PP == null)
{
content.Add(new SpriteIconWithTooltip
{
Icon = FontAwesome.Solid.Sync,
Size = new Vector2(text_size),
TooltipText = ScoresStrings.StatusProcessing,
});
}
else
content.Add(new UnprocessedPerformancePointsPlaceholder { Size = new Vector2(text_size) });
content.Add(new StatisticText(score.PP, format: @"N0"));
}

content.Add(new ScoreboardTime(score.Date, text_size)
Expand Down
23 changes: 19 additions & 4 deletions osu.Game/Overlays/BeatmapSet/Scores/TopScoreStatisticsSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Scoring.Drawables;
using osuTK;

namespace osu.Game.Overlays.BeatmapSet.Scores
Expand Down Expand Up @@ -125,10 +124,26 @@ public ScoreInfo Score

ppColumn.Alpha = value.BeatmapInfo!.Status.GrantsPerformancePoints() ? 1 : 0;

if (value.PP is double pp)
ppColumn.Text = pp.ToLocalisableString(@"N0");
if (!value.Ranked)
{
ppColumn.Drawable = new SpriteTextWithTooltip
{
Text = "-",
Font = smallFont,
TooltipText = ScoresStrings.StatusNoPp
};
}
else if (value.PP is not double pp)
{
ppColumn.Drawable = new SpriteIconWithTooltip
{
Icon = FontAwesome.Solid.Sync,
Size = new Vector2(smallFont.Size),
TooltipText = ScoresStrings.StatusProcessing,
};
}
else
ppColumn.Drawable = new UnprocessedPerformancePointsPlaceholder { Size = new Vector2(smallFont.Size) };
ppColumn.Text = pp.ToLocalisableString(@"N0");

statisticsColumns.ChildrenEnumerable = value.GetStatisticsForDisplay().Select(createStatisticsColumn);
modsColumn.Mods = value.Mods;
Expand Down

0 comments on commit f7a223f

Please sign in to comment.