mirror of
https://github.com/osukey/osukey.git
synced 2025-05-17 03:27:21 +09: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 IModHotkeyHandler hotkeyHandler = null!;
|
||||||
|
|
||||||
private Task? latestLoadTask;
|
private Task? latestLoadTask;
|
||||||
internal bool ItemsLoaded => latestLoadTask == null;
|
internal bool ItemsLoaded => latestLoadTask?.IsCompleted == true;
|
||||||
|
|
||||||
public ModColumn(ModType modType, bool allowIncompatibleSelection)
|
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));
|
var panels = availableMods.Select(mod => CreateModPanel(mod).With(panel => panel.Shear = Vector2.Zero));
|
||||||
|
|
||||||
Task? loadTask;
|
latestLoadTask = LoadComponentsAsync(panels, loaded =>
|
||||||
|
|
||||||
latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded =>
|
|
||||||
{
|
{
|
||||||
ItemsFlow.ChildrenEnumerable = loaded;
|
ItemsFlow.ChildrenEnumerable = loaded;
|
||||||
updateState();
|
updateState();
|
||||||
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
|
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
|
||||||
loadTask.ContinueWith(_ =>
|
|
||||||
{
|
|
||||||
if (loadTask == latestLoadTask)
|
|
||||||
latestLoadTask = null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateState()
|
private void updateState()
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -50,19 +49,18 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
presetSubscription?.Dispose();
|
presetSubscription?.Dispose();
|
||||||
presetSubscription = realm.RegisterForNotifications(r =>
|
presetSubscription = realm.RegisterForNotifications(r =>
|
||||||
r.All<ModPreset>()
|
r.All<ModPreset>()
|
||||||
.Filter($"{nameof(ModPreset.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $0"
|
.Filter($"{nameof(ModPreset.Ruleset)}.{nameof(RulesetInfo.ShortName)} == $0"
|
||||||
+ $" && {nameof(ModPreset.DeletePending)} == false", ruleset.Value.ShortName)
|
+ $" && {nameof(ModPreset.DeletePending)} == false", ruleset.Value.ShortName)
|
||||||
.OrderBy(preset => preset.Name),
|
.OrderBy(preset => preset.Name), asyncLoadPanels);
|
||||||
(presets, _, _) => asyncLoadPanels(presets));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CancellationTokenSource? cancellationTokenSource;
|
private CancellationTokenSource? cancellationTokenSource;
|
||||||
|
|
||||||
private Task? latestLoadTask;
|
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();
|
cancellationTokenSource?.Cancel();
|
||||||
|
|
||||||
@ -72,23 +70,14 @@ namespace osu.Game.Overlays.Mods
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var panels = presets.Select(preset => new ModPresetPanel(preset.ToLive(realm))
|
latestLoadTask = LoadComponentsAsync(presets.Select(p => new ModPresetPanel(p.ToLive(realm))
|
||||||
{
|
{
|
||||||
Shear = Vector2.Zero
|
Shear = Vector2.Zero
|
||||||
});
|
}), loaded =>
|
||||||
|
|
||||||
Task? loadTask;
|
|
||||||
|
|
||||||
latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded =>
|
|
||||||
{
|
{
|
||||||
ItemsFlow.RemoveAll(panel => panel is ModPresetPanel);
|
ItemsFlow.RemoveAll(panel => panel is ModPresetPanel);
|
||||||
ItemsFlow.AddRange(loaded);
|
ItemsFlow.AddRange(loaded);
|
||||||
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
|
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
|
||||||
loadTask.ContinueWith(_ =>
|
|
||||||
{
|
|
||||||
if (loadTask == latestLoadTask)
|
|
||||||
latestLoadTask = null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user