mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:52:53 +08:00
Merge pull request #19640 from peppy/mod-preset-column-task-logic
This commit is contained in:
commit
3b79cb6fce
@ -66,7 +66,7 @@ namespace osu.Game.Overlays.Mods
|
||||
private IModHotkeyHandler hotkeyHandler = null!;
|
||||
|
||||
private Task? latestLoadTask;
|
||||
internal bool ItemsLoaded => latestLoadTask == null;
|
||||
internal bool ItemsLoaded => latestLoadTask?.IsCompleted == true;
|
||||
|
||||
public ModColumn(ModType modType, bool allowIncompatibleSelection)
|
||||
{
|
||||
@ -132,18 +132,11 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
var panels = availableMods.Select(mod => CreateModPanel(mod).With(panel => panel.Shear = Vector2.Zero));
|
||||
|
||||
Task? loadTask;
|
||||
|
||||
latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded =>
|
||||
latestLoadTask = LoadComponentsAsync(panels, loaded =>
|
||||
{
|
||||
ItemsFlow.ChildrenEnumerable = loaded;
|
||||
updateState();
|
||||
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
|
||||
loadTask.ContinueWith(_ =>
|
||||
{
|
||||
if (loadTask == latestLoadTask)
|
||||
latestLoadTask = null;
|
||||
});
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
|
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -50,19 +49,18 @@ namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
presetSubscription?.Dispose();
|
||||
presetSubscription = realm.RegisterForNotifications(r =>
|
||||
r.All<ModPreset>()
|
||||
.Filter($"{nameof(ModPreset.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $0"
|
||||
+ $" && {nameof(ModPreset.DeletePending)} == false", ruleset.Value.ShortName)
|
||||
.OrderBy(preset => preset.Name),
|
||||
(presets, _, _) => asyncLoadPanels(presets));
|
||||
r.All<ModPreset>()
|
||||
.Filter($"{nameof(ModPreset.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $0"
|
||||
+ $" && {nameof(ModPreset.DeletePending)} == false", ruleset.Value.ShortName)
|
||||
.OrderBy(preset => preset.Name), asyncLoadPanels);
|
||||
}
|
||||
|
||||
private CancellationTokenSource? cancellationTokenSource;
|
||||
|
||||
private Task? latestLoadTask;
|
||||
internal bool ItemsLoaded => latestLoadTask == null;
|
||||
internal bool ItemsLoaded => latestLoadTask?.IsCompleted == true;
|
||||
|
||||
private void asyncLoadPanels(IReadOnlyList<ModPreset> presets)
|
||||
private void asyncLoadPanels(IRealmCollection<ModPreset> presets, ChangeSet changes, Exception error)
|
||||
{
|
||||
cancellationTokenSource?.Cancel();
|
||||
|
||||
@ -72,23 +70,14 @@ namespace osu.Game.Overlays.Mods
|
||||
return;
|
||||
}
|
||||
|
||||
var panels = presets.Select(preset => new ModPresetPanel(preset.ToLive(realm))
|
||||
latestLoadTask = LoadComponentsAsync(presets.Select(p => new ModPresetPanel(p.ToLive(realm))
|
||||
{
|
||||
Shear = Vector2.Zero
|
||||
});
|
||||
|
||||
Task? loadTask;
|
||||
|
||||
latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded =>
|
||||
}), loaded =>
|
||||
{
|
||||
ItemsFlow.RemoveAll(panel => panel is ModPresetPanel);
|
||||
ItemsFlow.AddRange(loaded);
|
||||
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
|
||||
loadTask.ContinueWith(_ =>
|
||||
{
|
||||
if (loadTask == latestLoadTask)
|
||||
latestLoadTask = null;
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
Loading…
Reference in New Issue
Block a user