1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 11:27:24 +08:00

Fix the star rating display at song select flashing to zero when changing mods

Due to the use of bindable flow provided by `BeatmapDifficultyCache` in
this usage, the display would briefly flash to zero while difficulty
calculation was still running (as there is no way for a consumer of the
provided bindable to know whether the returned 0 is an actual 0 SR or a
"pending" calculation).

While I hope to fix this by making the bindable flow return nullable
values, I think this particular use case works better with non-bindable
flow so have switched across to that.
This commit is contained in:
Dean Herbert 2021-02-25 16:05:08 +09:00
parent a9aed0eef4
commit 9f3ceb99eb

View File

@ -15,6 +15,7 @@ using System.Collections.Generic;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Configuration; using osu.Game.Configuration;
@ -137,8 +138,6 @@ namespace osu.Game.Screens.Select.Details
updateStarDifficulty(); updateStarDifficulty();
} }
private IBindable<StarDifficulty> normalStarDifficulty;
private IBindable<StarDifficulty> moddedStarDifficulty;
private CancellationTokenSource starDifficultyCancellationSource; private CancellationTokenSource starDifficultyCancellationSource;
private void updateStarDifficulty() private void updateStarDifficulty()
@ -150,13 +149,13 @@ namespace osu.Game.Screens.Select.Details
starDifficultyCancellationSource = new CancellationTokenSource(); starDifficultyCancellationSource = new CancellationTokenSource();
normalStarDifficulty = difficultyCache.GetBindableDifficulty(Beatmap, ruleset.Value, null, starDifficultyCancellationSource.Token); var normalStarDifficulty = difficultyCache.GetDifficultyAsync(Beatmap, ruleset.Value, null, starDifficultyCancellationSource.Token);
moddedStarDifficulty = difficultyCache.GetBindableDifficulty(Beatmap, ruleset.Value, mods.Value, starDifficultyCancellationSource.Token); var moddedStarDifficulty = difficultyCache.GetDifficultyAsync(Beatmap, ruleset.Value, mods.Value, starDifficultyCancellationSource.Token);
normalStarDifficulty.BindValueChanged(_ => updateDisplay()); Task.WhenAll(normalStarDifficulty, moddedStarDifficulty).ContinueWith(_ => Schedule(() =>
moddedStarDifficulty.BindValueChanged(_ => updateDisplay(), true); {
starDifficulty.Value = ((float)normalStarDifficulty.Result.Stars, (float)moddedStarDifficulty.Result.Stars);
void updateDisplay() => starDifficulty.Value = ((float)normalStarDifficulty.Value.Stars, (float)moddedStarDifficulty.Value.Stars); }), starDifficultyCancellationSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)