Add active event check to task serializer
This commit is contained in:
@@ -37,10 +37,11 @@ namespace UIFixes
|
||||
foreach (ItemContextClass itemContext in MultiSelect.SortedItemContexts())
|
||||
{
|
||||
LocationInGrid location = itemContext.ItemAddress is ItemAddressClass gridAddress ? MultiGrid.GetGridLocation(gridAddress) : null;
|
||||
builder.AppendFormat("x{0} {1} {2}\n",
|
||||
builder.AppendFormat("x{0} {1} {2} {3}\n",
|
||||
itemContext.Item.StackObjectsCount,
|
||||
itemContext.ItemAddress.ContainerName,
|
||||
location != null ? $"({location.x}, {location.y})" : "slot",
|
||||
itemContext.Item.ToString());
|
||||
itemContext.Item.Name.Localized());
|
||||
}
|
||||
|
||||
if (MultiSelect.SecondaryContexts.Any())
|
||||
|
@@ -681,7 +681,8 @@ namespace UIFixes
|
||||
FindOrigin = GetTargetGridAddress(itemContext, ic, hoveredAddress);
|
||||
FindVerticalFirst = ic.ItemRotation == ItemRotation.Vertical;
|
||||
return __instance.AcceptItem(ic, targetItemContext);
|
||||
});
|
||||
},
|
||||
itemContext => __instance.Grid.ParentItem.Owner.SelectEvents(itemContext.Item).All(args => args.Status == CommandStatus.Succeed));
|
||||
|
||||
// Setting the fallback after initializing means it only applies after the first item is already moved
|
||||
GridViewPickTargetPatch.FallbackResult = __instance.Grid.ParentItem;
|
||||
@@ -906,7 +907,10 @@ namespace UIFixes
|
||||
InPatch = true;
|
||||
|
||||
var serializer = __instance.gameObject.AddComponent<MultiSelectItemContextTaskSerializer>();
|
||||
__result = serializer.Initialize(MultiSelect.SortedItemContexts(), itemContext => __instance.AcceptItem(itemContext, targetItemContext));
|
||||
__result = serializer.Initialize(
|
||||
MultiSelect.SortedItemContexts(),
|
||||
itemContext => __instance.AcceptItem(itemContext, targetItemContext),
|
||||
itemContext => __instance.Slot.ParentItem.Owner.SelectEvents(itemContext.Item).All(args => args.Status == CommandStatus.Succeed));
|
||||
|
||||
__result.ContinueWith(_ => { InPatch = false; });
|
||||
|
||||
|
@@ -8,14 +8,16 @@ namespace UIFixes
|
||||
public class TaskSerializer<T> : MonoBehaviour
|
||||
{
|
||||
private Func<T, Task> func;
|
||||
private Func<T, bool> canContinue;
|
||||
private IEnumerator<T> enumerator;
|
||||
private Task currentTask;
|
||||
private TaskCompletionSource totalTask;
|
||||
|
||||
public Task Initialize(IEnumerable<T> items, Func<T, Task> func)
|
||||
public Task Initialize(IEnumerable<T> items, Func<T, Task> func, Func<T, bool> canContinue = null)
|
||||
{
|
||||
this.enumerator = items.GetEnumerator();
|
||||
this.func = func;
|
||||
this.canContinue = canContinue;
|
||||
|
||||
currentTask = Task.CompletedTask;
|
||||
totalTask = new TaskCompletionSource();
|
||||
@@ -52,6 +54,11 @@ namespace UIFixes
|
||||
return;
|
||||
}
|
||||
|
||||
if (canContinue != null && enumerator.Current != null && !canContinue(enumerator.Current))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (enumerator.MoveNext())
|
||||
{
|
||||
currentTask = func(enumerator.Current);
|
||||
|
Reference in New Issue
Block a user