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

Only load panels asynchronously outside of BDL

This commit is contained in:
Bartłomiej Dach 2022-05-06 17:33:32 +02:00
parent 9f96dd47d1
commit 9514a5cef7
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -275,30 +275,25 @@ namespace osu.Game.Overlays.Mods
return;
localAvailableMods = newMods;
loadPanels();
if (!IsLoaded)
// if we're coming from BDL, perform the first load synchronously to make sure everything is in place as early as possible.
onPanelsLoaded(createPanels());
else
asyncLoadPanels();
}
private CancellationTokenSource? cancellationTokenSource;
private void loadPanels()
private void asyncLoadPanels()
{
cancellationTokenSource?.Cancel();
var panels = localAvailableMods.Select(mod => CreateModPanel(mod).With(panel => panel.Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0)));
var panels = createPanels();
Task? loadTask;
latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded =>
{
panelFlow.ChildrenEnumerable = loaded;
updateState();
foreach (var panel in panelFlow)
{
panel.Active.BindValueChanged(_ => panelStateChanged(panel));
}
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
latestLoadTask = loadTask = LoadComponentsAsync(panels, onPanelsLoaded, (cancellationTokenSource = new CancellationTokenSource()).Token);
loadTask.ContinueWith(_ =>
{
if (loadTask == latestLoadTask)
@ -306,6 +301,24 @@ namespace osu.Game.Overlays.Mods
});
}
private IEnumerable<ModPanel> createPanels()
{
var panels = localAvailableMods.Select(mod => CreateModPanel(mod).With(panel => panel.Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0)));
return panels;
}
private void onPanelsLoaded(IEnumerable<ModPanel> loaded)
{
panelFlow.ChildrenEnumerable = loaded;
updateState();
foreach (var panel in panelFlow)
{
panel.Active.BindValueChanged(_ => panelStateChanged(panel));
}
}
private void updateState()
{
foreach (var panel in panelFlow)