1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 22:22:55 +08:00
osu-lazer/osu.Game/Screens/Ranking/Expanded/Statistics/PerformanceStatistic.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.2 KiB
C#
Raw Normal View History

// 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;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Scoring;
namespace osu.Game.Screens.Ranking.Expanded.Statistics
{
public class PerformanceStatistic : StatisticDisplay
{
private readonly ScoreInfo score;
private readonly Bindable<int> performance = new Bindable<int>();
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private RollingCounter<int> counter;
public PerformanceStatistic(ScoreInfo score)
: base(BeatmapsetsStrings.ShowScoreboardHeaderspp)
{
this.score = score;
}
[BackgroundDependencyLoader]
private void load(ScorePerformanceCache performanceCache)
{
if (score.PP.HasValue)
{
setPerformanceValue(score.PP.Value);
}
else
{
performanceCache.CalculatePerformanceAsync(score, cancellationTokenSource.Token)
.ContinueWith(t => Schedule(() => setPerformanceValue(t.GetResultSafely()?.Total)), cancellationTokenSource.Token);
}
2022-01-18 21:57:12 +08:00
}
private void setPerformanceValue(double? pp)
2022-01-18 21:57:12 +08:00
{
if (pp.HasValue)
performance.Value = (int)Math.Round(pp.Value, MidpointRounding.AwayFromZero);
}
public override void Appear()
{
base.Appear();
counter.Current.BindTo(performance);
}
protected override void Dispose(bool isDisposing)
{
2020-09-29 01:05:22 +08:00
cancellationTokenSource?.Cancel();
base.Dispose(isDisposing);
}
protected override Drawable CreateContent() => counter = new StatisticCounter
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre
};
}
}