diff --git a/MultiSelect.cs b/MultiSelect.cs index be3b891..c5798dd 100644 --- a/MultiSelect.cs +++ b/MultiSelect.cs @@ -237,14 +237,30 @@ namespace UIFixes private static bool InteractionAvailable(ItemContextClass itemContext, EItemInfoButton interaction, ItemUiContext itemUiContext) { + // Since itemContext is for "drag", no context actions are allowed. Get the underlying "inventory" context ItemContextAbstractClass innerContext = itemContext.GClass2813_0; if (innerContext == null) { return false; } + bool createdContext = false; + if (innerContext.Item != itemContext.Item) + { + // Actual context went away and we're looking at inventory/stash context + innerContext = innerContext.CreateChild(itemContext.Item); + createdContext = true; + } + var contextInteractions = itemUiContext.GetItemContextInteractions(innerContext, null); - return contextInteractions.IsInteractionAvailable(interaction); + bool result = contextInteractions.IsInteractionAvailable(interaction); + + if (createdContext) + { + innerContext.Dispose(); + } + + return result; } public static void EquipAll(ItemUiContext itemUiContext, bool allOrNothing) @@ -298,6 +314,19 @@ namespace UIFixes UnloadSerializer = null; } + public static void UnpackAll(ItemUiContext itemUiContext, bool allOrNothing) + { + if (!allOrNothing || InteractionCount(EItemInfoButton.Unpack, itemUiContext) == Count) + { + var taskSerializer = itemUiContext.gameObject.AddComponent(); + taskSerializer.Initialize( + SortedItemContexts().Where(ic => InteractionAvailable(ic, EItemInfoButton.Unpack, itemUiContext)), + itemContext => itemUiContext.UnpackItem(itemContext.Item)); + + itemUiContext.Tooltip?.Close(); + } + } + private static void ShowSelection(GridItemView itemView) { GameObject selectedMark = itemView.transform.Find("SelectedMark")?.gameObject; diff --git a/Patches/ContextMenuPatches.cs b/Patches/ContextMenuPatches.cs index 85b1c73..39f2ca0 100644 --- a/Patches/ContextMenuPatches.cs +++ b/Patches/ContextMenuPatches.cs @@ -129,6 +129,15 @@ namespace UIFixes ____text.text += " (x" + count + ")"; } } + else if (caption == EItemInfoButton.Unpack.ToString()) + { + int count = MultiSelect.InteractionCount(EItemInfoButton.Unpack, ItemUiContext.Instance); + if (count > 0) + { + ____text.text += " (x" + count + ")"; + } + + } } } diff --git a/Patches/MultiSelectPatches.cs b/Patches/MultiSelectPatches.cs index f21e868..b4b9bf6 100644 --- a/Patches/MultiSelectPatches.cs +++ b/Patches/MultiSelectPatches.cs @@ -314,6 +314,9 @@ namespace UIFixes case EItemInfoButton.UnloadAmmo: MultiSelect.UnloadAmmoAll(___itemUiContext_1, false); return false; + case EItemInfoButton.Unpack: + MultiSelect.UnpackAll(___itemUiContext_1, false); + return false; default: return true; } diff --git a/TaskSerializer.cs b/TaskSerializer.cs index 01476e9..b5674f1 100644 --- a/TaskSerializer.cs +++ b/TaskSerializer.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using UnityEngine; @@ -21,7 +20,7 @@ namespace UIFixes currentTask = Task.CompletedTask; totalTask = new TaskCompletionSource(); - Update(); + LateUpdate(); return totalTask.Task; } @@ -29,9 +28,10 @@ namespace UIFixes public void Cancel() { totalTask.TrySetCanceled(); + Complete(); } - public void Update() + public void LateUpdate() { if (currentTask.IsCanceled) { @@ -56,7 +56,7 @@ namespace UIFixes private void Complete() { - totalTask.Complete(); + totalTask.TryComplete(); func = null; Destroy(this); }