diff --git a/osu.Game.Tests/Visual/Ranking/TestSceneExpandedPanelMiddleContent.cs b/osu.Game.Tests/Visual/Ranking/TestSceneExpandedPanelMiddleContent.cs index d97946a1d5..9f7726313a 100644 --- a/osu.Game.Tests/Visual/Ranking/TestSceneExpandedPanelMiddleContent.cs +++ b/osu.Game.Tests/Visual/Ranking/TestSceneExpandedPanelMiddleContent.cs @@ -14,13 +14,16 @@ using osu.Framework.Graphics.Shapes; using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Graphics.Sprites; +using osu.Game.Localisation; using osu.Game.Models; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu; +using osu.Game.Rulesets.Osu.Mods; using osu.Game.Scoring; using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking.Expanded; +using osu.Game.Screens.Ranking.Expanded.Statistics; using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Resources; using osuTK; @@ -67,6 +70,40 @@ namespace osu.Game.Tests.Visual.Ranking AddAssert("play time displayed", () => this.ChildrenOfType().Any()); } + [Test] + public void TestPPShownAsProvisionalWhenBeatmapHasNoLeaderboard() + { + AddStep("show example score", () => + { + var beatmap = createTestBeatmap(new RealmUser()); + beatmap.Status = BeatmapOnlineStatus.Graveyard; + showPanel(TestResources.CreateTestScoreInfo(beatmap)); + }); + + AddAssert("pp display faded out", () => + { + var ppDisplay = this.ChildrenOfType().Single(); + return ppDisplay.Alpha == 0.5 && ppDisplay.TooltipText == ResultsScreenStrings.NoPPForUnrankedBeatmaps; + }); + } + + [Test] + public void TestPPShownAsProvisionalWhenUnrankedModsArePresent() + { + AddStep("show example score", () => + { + var score = TestResources.CreateTestScoreInfo(createTestBeatmap(new RealmUser())); + score.Mods = score.Mods.Append(new OsuModDifficultyAdjust()).ToArray(); + showPanel(score); + }); + + AddAssert("pp display faded out", () => + { + var ppDisplay = this.ChildrenOfType().Single(); + return ppDisplay.Alpha == 0.5 && ppDisplay.TooltipText == ResultsScreenStrings.NoPPForUnrankedMods; + }); + } + [Test] public void TestWithDefaultDate() { diff --git a/osu.Game/Localisation/ResultsScreenStrings.cs b/osu.Game/Localisation/ResultsScreenStrings.cs new file mode 100644 index 0000000000..54e7717af9 --- /dev/null +++ b/osu.Game/Localisation/ResultsScreenStrings.cs @@ -0,0 +1,24 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Localisation; + +namespace osu.Game.Localisation +{ + public static class ResultsScreenStrings + { + private const string prefix = @"osu.Game.Resources.Localisation.ResultsScreen"; + + /// + /// "Performance points are not granted for this score because the beatmap is not ranked." + /// + public static LocalisableString NoPPForUnrankedBeatmaps => new TranslatableString(getKey(@"no_pp_for_unranked_beatmaps"), @"Performance points are not granted for this score because the beatmap is not ranked."); + + /// + /// "Performance points are not granted for this score because of unranked mods." + /// + public static LocalisableString NoPPForUnrankedMods => new TranslatableString(getKey(@"no_pp_for_unranked_mods"), @"Performance points are not granted for this score because of unranked mods."); + + private static string getKey(string key) => $@"{prefix}:{key}"; + } +} diff --git a/osu.Game/Screens/Ranking/Expanded/Statistics/PerformanceStatistic.cs b/osu.Game/Screens/Ranking/Expanded/Statistics/PerformanceStatistic.cs index 22c1e26d43..0a9c68eafc 100644 --- a/osu.Game/Screens/Ranking/Expanded/Statistics/PerformanceStatistic.cs +++ b/osu.Game/Screens/Ranking/Expanded/Statistics/PerformanceStatistic.cs @@ -4,20 +4,26 @@ #nullable disable using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Cursor; +using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Graphics.UserInterface; using osu.Game.Resources.Localisation.Web; using osu.Game.Scoring; +using osu.Game.Localisation; namespace osu.Game.Screens.Ranking.Expanded.Statistics { - public partial class PerformanceStatistic : StatisticDisplay + public partial class PerformanceStatistic : StatisticDisplay, IHasTooltip { + public LocalisableString TooltipText { get; private set; } + private readonly ScoreInfo score; private readonly Bindable performance = new Bindable(); @@ -37,7 +43,7 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics { if (score.PP.HasValue) { - setPerformanceValue(score.PP.Value); + setPerformanceValue(score, score.PP.Value); } else { @@ -52,15 +58,33 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics var result = await performanceCalculator.CalculateAsync(score, attributes.Value.Attributes, cancellationToken ?? default).ConfigureAwait(false); - Schedule(() => setPerformanceValue(result.Total)); + Schedule(() => setPerformanceValue(score, result.Total)); }, cancellationToken ?? default); } } - private void setPerformanceValue(double? pp) + private void setPerformanceValue(ScoreInfo scoreInfo, double? pp) { if (pp.HasValue) + { performance.Value = (int)Math.Round(pp.Value, MidpointRounding.AwayFromZero); + + if (!scoreInfo.BeatmapInfo!.Status.GrantsPerformancePoints()) + { + Alpha = 0.5f; + TooltipText = ResultsScreenStrings.NoPPForUnrankedBeatmaps; + } + else if (scoreInfo.Mods.Any(m => !m.Ranked)) + { + Alpha = 0.5f; + TooltipText = ResultsScreenStrings.NoPPForUnrankedMods; + } + else + { + Alpha = 1f; + TooltipText = default; + } + } } public override void Appear()