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.
|
|
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
|
|
|
|
{
|
2020-09-27 15:37:57 +08:00
|
|
|
|
public class PerformanceStatistic : CounterStatistic
|
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();
|
|
|
|
|
|
|
|
|
|
public PerformanceStatistic(ScoreInfo score)
|
2020-09-27 15:37:57 +08:00
|
|
|
|
: base("PP", 0)
|
2020-09-26 01:15:40 +08:00
|
|
|
|
{
|
|
|
|
|
this.score = score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-09-27 18:44:29 +08:00
|
|
|
|
private void load(ScorePerformanceManager performanceManager)
|
2020-09-26 01:15:40 +08:00
|
|
|
|
{
|
2020-09-29 01:05:22 +08:00
|
|
|
|
if (score.PP.HasValue)
|
|
|
|
|
{
|
|
|
|
|
performance.Value = (int)score.PP.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
performanceManager.CalculatePerformanceAsync(score, cancellationTokenSource.Token)
|
|
|
|
|
.ContinueWith(t => Schedule(() => performance.Value = (int)t.Result), cancellationTokenSource.Token);
|
|
|
|
|
}
|
2020-09-26 01:15:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Appear()
|
|
|
|
|
{
|
|
|
|
|
base.Appear();
|
2020-09-27 15:37:57 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|