Skip to content

Commit

Permalink
Fix beatmap attributes display in mod select recreating star difficul…
Browse files Browse the repository at this point in the history
…ty bindable every setting change
  • Loading branch information
frenzibyte committed Jul 19, 2024
1 parent 868604c commit 2ad8eeb
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions osu.Game/Overlays/Mods/BeatmapAttributesDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ protected override void LoadComplete()
updateValues();
}, true);

BeatmapInfo.BindValueChanged(_ => updateValues());

Collapsed.BindValueChanged(_ =>
{
// Only start autosize animations on first collapse toggle. This avoids an ugly initial presentation.
Expand All @@ -120,12 +118,32 @@ protected override void LoadComplete()
GameRuleset = game.Ruleset.GetBoundCopy();
GameRuleset.BindValueChanged(_ => updateValues());

BeatmapInfo.BindValueChanged(_ => updateValues());
BeatmapInfo.BindValueChanged(_ =>
{
updateStarDifficultyBindable();
updateValues();
}, true);

updateValues();
updateCollapsedState();
}

private void updateStarDifficultyBindable()
{
cancellationSource?.Cancel();

if (BeatmapInfo.Value == null)
return;

starDifficulty = difficultyCache.GetBindableDifficulty(BeatmapInfo.Value, (cancellationSource = new CancellationTokenSource()).Token);
starDifficulty.BindValueChanged(s =>
{
starRatingDisplay.Current.Value = s.NewValue ?? default;
if (!starRatingDisplay.IsPresent)
starRatingDisplay.FinishTransforms(true);
});
}

protected override bool OnHover(HoverEvent e)
{
startAnimating();
Expand Down Expand Up @@ -154,17 +172,6 @@ private void updateValues() => Scheduler.AddOnce(() =>
if (BeatmapInfo.Value == null)
return;
cancellationSource?.Cancel();
starDifficulty = difficultyCache.GetBindableDifficulty(BeatmapInfo.Value, (cancellationSource = new CancellationTokenSource()).Token);
starDifficulty.BindValueChanged(s =>
{
starRatingDisplay.Current.Value = s.NewValue ?? default;
if (!starRatingDisplay.IsPresent)
starRatingDisplay.FinishTransforms(true);
});
double rate = ModUtils.CalculateRateWithMods(Mods.Value);
bpmDisplay.Current.Value = FormatUtils.RoundBPM(BeatmapInfo.Value.BPM, rate);
Expand Down

0 comments on commit 2ad8eeb

Please sign in to comment.