1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Update beatmap details SR on ruleset/mod changes

This commit is contained in:
smoogipoo 2020-07-16 21:08:08 +09:00
parent 3191bb506f
commit 24f14751ce

View File

@ -14,10 +14,13 @@ using osu.Framework.Bindables;
using System.Collections.Generic;
using osu.Game.Rulesets.Mods;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Threading;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets;
namespace osu.Game.Screens.Select.Details
{
@ -26,6 +29,12 @@ namespace osu.Game.Screens.Select.Details
[Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
[Resolved]
private BeatmapDifficultyManager difficultyManager { get; set; }
protected readonly StatisticRow FirstValue, HpDrain, Accuracy, ApproachRate;
private readonly StatisticRow starDifficulty;
@ -71,6 +80,7 @@ namespace osu.Game.Screens.Select.Details
{
base.LoadComplete();
ruleset.BindValueChanged(_ => updateStatistics());
mods.BindValueChanged(modsChanged, true);
}
@ -132,11 +142,33 @@ namespace osu.Game.Screens.Select.Details
break;
}
starDifficulty.Value = ((float)(Beatmap?.StarDifficulty ?? 0), null);
HpDrain.Value = (baseDifficulty?.DrainRate ?? 0, adjustedDifficulty?.DrainRate);
Accuracy.Value = (baseDifficulty?.OverallDifficulty ?? 0, adjustedDifficulty?.OverallDifficulty);
ApproachRate.Value = (baseDifficulty?.ApproachRate ?? 0, adjustedDifficulty?.ApproachRate);
updateStarDifficulty();
}
private CancellationTokenSource starDifficultyCancellationSource;
private void updateStarDifficulty()
{
starDifficultyCancellationSource?.Cancel();
if (Beatmap == null)
return;
var ourSource = starDifficultyCancellationSource = new CancellationTokenSource();
Task.WhenAll(difficultyManager.GetDifficultyAsync(Beatmap, ruleset.Value, cancellationToken: ourSource.Token),
difficultyManager.GetDifficultyAsync(Beatmap, ruleset.Value, mods.Value, ourSource.Token)).ContinueWith(t =>
{
Schedule(() =>
{
if (!ourSource.IsCancellationRequested)
starDifficulty.Value = ((float)t.Result[0], (float)t.Result[1]);
});
}, ourSource.Token);
}
public class StatisticRow : Container, IHasAccentColour