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.
|
|
|
|
|
|
2020-10-11 01:58:06 +08:00
|
|
|
|
using System;
|
2022-01-20 08:39:33 +08:00
|
|
|
|
using System.Linq;
|
2020-09-26 01:15:40 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
2022-01-03 16:31:12 +08:00
|
|
|
|
using osu.Framework.Extensions;
|
2020-11-01 20:25:36 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2022-01-17 18:28:17 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2022-01-18 21:57:12 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-11-01 20:25:36 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-01-17 18:28:17 +08:00
|
|
|
|
using osu.Game.Rulesets.Difficulty;
|
2020-09-26 01:15:40 +08:00
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
|
|
|
|
{
|
2022-01-19 15:33:33 +08:00
|
|
|
|
public class PerformanceStatistic : StatisticDisplay, IHasCustomTooltip<PerformanceBreakdown>
|
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;
|
|
|
|
|
|
2022-01-18 21:57:12 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private ScorePerformanceCache performanceCache { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapDifficultyCache difficultyCache { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapManager beatmapManager { get; set; }
|
|
|
|
|
|
2020-09-26 01:15:40 +08:00
|
|
|
|
public PerformanceStatistic(ScoreInfo score)
|
2020-11-01 20:25:36 +08:00
|
|
|
|
: base("PP")
|
2020-09-26 01:15:40 +08:00
|
|
|
|
{
|
|
|
|
|
this.score = score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-18 21:57:12 +08:00
|
|
|
|
private void load()
|
2020-09-26 01:15:40 +08:00
|
|
|
|
{
|
2022-01-19 15:33:33 +08:00
|
|
|
|
new PerformanceBreakdownCalculator(beatmapManager, difficultyCache, performanceCache)
|
|
|
|
|
.CalculateAsync(score, cancellationTokenSource.Token)
|
|
|
|
|
.ContinueWith(t => setPerformanceValue(t.GetResultSafely()));
|
2022-01-18 21:57:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setPerformanceValue(PerformanceBreakdown breakdown)
|
|
|
|
|
{
|
2022-01-20 08:39:33 +08:00
|
|
|
|
// Don't display the tooltip if "Total" is the only item
|
|
|
|
|
if (breakdown != null && breakdown.Performance.GetAttributesForDisplay().Count() > 1)
|
2022-01-18 21:57:12 +08:00
|
|
|
|
{
|
|
|
|
|
TooltipContent = breakdown;
|
|
|
|
|
performance.Value = (int)Math.Round(breakdown.Performance.Total, MidpointRounding.AwayFromZero);
|
2022-01-17 18:28:17 +08:00
|
|
|
|
}
|
2020-10-13 04:14:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
};
|
2022-01-17 18:28:17 +08:00
|
|
|
|
|
2022-01-18 21:57:12 +08:00
|
|
|
|
public ITooltip<PerformanceBreakdown> GetCustomTooltip() => new PerformanceStatisticTooltip();
|
|
|
|
|
|
|
|
|
|
public PerformanceBreakdown TooltipContent { get; private set; }
|
2020-09-26 01:15:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|