1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-01 00:12:56 +08:00

Add dynamic pp calculation to score panels for local scores

This commit is contained in:
Lucas A 2020-09-25 19:15:40 +02:00
parent 4d743f64f5
commit 77a9d92f42
3 changed files with 77 additions and 2 deletions

View File

@ -133,7 +133,6 @@ namespace osu.Game.Beatmaps
var total = calculator.Calculate(null);
return total;
}, token, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
}

View File

@ -61,7 +61,7 @@ namespace osu.Game.Screens.Ranking.Expanded
{
new AccuracyStatistic(score.Accuracy),
new ComboStatistic(score.MaxCombo, !score.Statistics.TryGetValue(HitResult.Miss, out var missCount) || missCount == 0),
new CounterStatistic("pp", (int)(score.PP ?? 0)),
new PerformanceStatistic(score),
};
var bottomStatistics = new List<StatisticDisplay>();

View File

@ -0,0 +1,76 @@
// 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.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Expanded.Accuracy;
using osuTK;
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("PP")
{
this.score = score;
}
[BackgroundDependencyLoader]
private void load(BeatmapManager beatmapManager, BeatmapDifficultyManager difficultyManager)
{
if (score.PP.HasValue)
{
performance.Value = (int)score.PP.Value;
}
else
{
var beatmap = beatmapManager.GetWorkingBeatmap(score.Beatmap);
difficultyManager.CalculateScorePerformance(beatmap, score, cancellationTokenSource.Token)
.ContinueWith(t => Schedule(() => performance.Value = (int)t.Result), cancellationTokenSource.Token);
}
}
public override void Appear()
{
base.Appear();
counter.Current.BindTo(performance);
}
protected override Drawable CreateContent() => counter = new Counter();
private class Counter : RollingCounter<int>
{
protected override double RollingDuration => AccuracyCircle.ACCURACY_TRANSFORM_DURATION;
protected override Easing RollingEasing => AccuracyCircle.ACCURACY_TRANSFORM_EASING;
protected override OsuSpriteText CreateSpriteText() => base.CreateSpriteText().With(s =>
{
s.Font = OsuFont.Torus.With(size: 20, fixedWidth: true);
s.Spacing = new Vector2(-2, 0);
});
}
protected override void Dispose(bool isDisposing)
{
cancellationTokenSource.Cancel();
base.Dispose(isDisposing);
}
}
}