2020-09-26 01:15:40 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-10-11 01:58:06 +08:00
|
|
|
|
using System;
|
2024-04-15 17:53:03 +08:00
|
|
|
|
using System.Collections.Generic;
|
2024-03-29 18:16:31 +08:00
|
|
|
|
using System.Linq;
|
2020-09-26 01:15:40 +08:00
|
|
|
|
using System.Threading;
|
2024-01-29 14:15:10 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2020-09-26 01:15:40 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
2020-11-01 20:25:36 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2024-03-29 18:16:31 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
|
using osu.Framework.Localisation;
|
2024-01-29 14:15:10 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-11-01 20:25:36 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-01-28 12:53:48 +08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2020-09-26 01:15:40 +08:00
|
|
|
|
using osu.Game.Scoring;
|
2024-03-29 18:16:31 +08:00
|
|
|
|
using osu.Game.Localisation;
|
2024-04-15 17:53:03 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2020-09-26 01:15:40 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
|
|
|
|
{
|
2024-03-29 18:16:31 +08:00
|
|
|
|
public partial class PerformanceStatistic : StatisticDisplay, IHasTooltip
|
2020-09-26 01:15:40 +08:00
|
|
|
|
{
|
2024-03-29 18:16:31 +08:00
|
|
|
|
public LocalisableString TooltipText { get; private set; }
|
|
|
|
|
|
2020-09-26 01:15:40 +08:00
|
|
|
|
private readonly ScoreInfo score;
|
|
|
|
|
|
|
|
|
|
private readonly Bindable<int> performance = new Bindable<int>();
|
|
|
|
|
|
|
|
|
|
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
|
|
2020-11-01 20:25:36 +08:00
|
|
|
|
private RollingCounter<int> counter;
|
|
|
|
|
|
2020-09-26 01:15:40 +08:00
|
|
|
|
public PerformanceStatistic(ScoreInfo score)
|
2022-01-28 12:53:48 +08:00
|
|
|
|
: base(BeatmapsetsStrings.ShowScoreboardHeaderspp)
|
2020-09-26 01:15:40 +08:00
|
|
|
|
{
|
|
|
|
|
this.score = score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2024-01-29 14:15:10 +08:00
|
|
|
|
private void load(BeatmapDifficultyCache difficultyCache, CancellationToken? cancellationToken)
|
2020-09-26 01:15:40 +08:00
|
|
|
|
{
|
2022-02-05 21:18:23 +08:00
|
|
|
|
if (score.PP.HasValue)
|
|
|
|
|
{
|
2024-03-29 18:16:31 +08:00
|
|
|
|
setPerformanceValue(score, score.PP.Value);
|
2022-02-05 21:18:23 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-01-29 14:15:10 +08:00
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
var attributes = await difficultyCache.GetDifficultyAsync(score.BeatmapInfo!, score.Ruleset, score.Mods, cancellationToken ?? default).ConfigureAwait(false);
|
|
|
|
|
var performanceCalculator = score.Ruleset.CreateInstance().CreatePerformanceCalculator();
|
|
|
|
|
|
|
|
|
|
// Performance calculation requires the beatmap and ruleset to be locally available. If not, return a default value.
|
|
|
|
|
if (attributes?.Attributes == null || performanceCalculator == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var result = await performanceCalculator.CalculateAsync(score, attributes.Value.Attributes, cancellationToken ?? default).ConfigureAwait(false);
|
|
|
|
|
|
2024-03-29 18:16:31 +08:00
|
|
|
|
Schedule(() => setPerformanceValue(score, result.Total));
|
2024-01-29 14:15:10 +08:00
|
|
|
|
}, cancellationToken ?? default);
|
2022-02-05 21:18:23 +08:00
|
|
|
|
}
|
2022-01-18 21:57:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 18:16:31 +08:00
|
|
|
|
private void setPerformanceValue(ScoreInfo scoreInfo, double? pp)
|
2022-01-18 21:57:12 +08:00
|
|
|
|
{
|
2022-02-05 21:18:23 +08:00
|
|
|
|
if (pp.HasValue)
|
2024-03-29 18:16:31 +08:00
|
|
|
|
{
|
2022-02-05 21:18:23 +08:00
|
|
|
|
performance.Value = (int)Math.Round(pp.Value, MidpointRounding.AwayFromZero);
|
2024-03-29 18:16:31 +08:00
|
|
|
|
|
|
|
|
|
if (!scoreInfo.BeatmapInfo!.Status.GrantsPerformancePoints())
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0.5f;
|
|
|
|
|
TooltipText = ResultsScreenStrings.NoPPForUnrankedBeatmaps;
|
|
|
|
|
}
|
2024-04-15 17:53:03 +08:00
|
|
|
|
else if (hasUnrankedMods(scoreInfo))
|
2024-03-29 18:16:31 +08:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0.5f;
|
|
|
|
|
TooltipText = ResultsScreenStrings.NoPPForUnrankedMods;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Alpha = 1f;
|
|
|
|
|
TooltipText = default;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-13 04:14:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-15 17:53:03 +08:00
|
|
|
|
private static bool hasUnrankedMods(ScoreInfo scoreInfo)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<Mod> modsToCheck = scoreInfo.Mods;
|
|
|
|
|
|
|
|
|
|
if (scoreInfo.IsLegacyScore)
|
|
|
|
|
modsToCheck = modsToCheck.Where(m => m is not ModClassic);
|
|
|
|
|
|
|
|
|
|
return modsToCheck.Any(m => !m.Ranked);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-26 01:15:40 +08:00
|
|
|
|
public override void Appear()
|
|
|
|
|
{
|
|
|
|
|
base.Appear();
|
2020-11-01 20:25:36 +08:00
|
|
|
|
counter.Current.BindTo(performance);
|
2020-09-26 01:15:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
2020-09-29 01:05:22 +08:00
|
|
|
|
cancellationTokenSource?.Cancel();
|
2020-09-26 01:15:40 +08:00
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
2020-11-01 20:25:36 +08:00
|
|
|
|
|
|
|
|
|
protected override Drawable CreateContent() => counter = new StatisticCounter
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre
|
|
|
|
|
};
|
2020-09-26 01:15:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|