From cd0266a2a944dfd1a532c2c3e387a717f81c78d5 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Sat, 22 Jun 2024 17:12:23 -0700 Subject: [PATCH] deselect items that go into mags, allow partial moves when all items are the same and stackable --- MultiSelect.cs | 42 +++++++++++++++---------------- Patches/GridWindowButtonsPatch.cs | 2 +- Patches/MultiSelectPatches.cs | 8 ++++++ 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/MultiSelect.cs b/MultiSelect.cs index b72c596..c44e419 100644 --- a/MultiSelect.cs +++ b/MultiSelect.cs @@ -213,25 +213,19 @@ namespace UIFixes public static int InteractionCount(EItemInfoButton interaction, ItemUiContext itemUiContext) { - int count = 0; - foreach (ItemContextClass selectedItemContext in SortedItemContexts()) + return ItemContexts.Count(ic => InteractionAvailable(ic, interaction, itemUiContext)); + } + + private static bool InteractionAvailable(ItemContextClass itemContext, EItemInfoButton interaction, ItemUiContext itemUiContext) + { + ItemContextAbstractClass innerContext = itemContext.GClass2813_0; + if (innerContext == null) { - ItemContextAbstractClass innerContext = selectedItemContext.GClass2813_0; - if (innerContext == null) - { - continue; - } - - var contextInteractions = itemUiContext.GetItemContextInteractions(innerContext, null); - if (!contextInteractions.IsInteractionAvailable(interaction)) - { - continue; - } - - ++count; + return false; } - return count; + var contextInteractions = itemUiContext.GetItemContextInteractions(innerContext, null); + return contextInteractions.IsInteractionAvailable(interaction); } public static void EquipAll(ItemUiContext itemUiContext, bool allOrNothing) @@ -239,7 +233,9 @@ namespace UIFixes if (!allOrNothing || InteractionCount(EItemInfoButton.Equip, itemUiContext) == Count) { var taskSerializer = itemUiContext.gameObject.AddComponent(); - taskSerializer.Initialize(SortedItemContexts(), itemContext => itemUiContext.QuickEquip(itemContext.Item)); + taskSerializer.Initialize( + SortedItemContexts().Where(ic => InteractionAvailable(ic, EItemInfoButton.Equip, itemUiContext)), + itemContext => itemUiContext.QuickEquip(itemContext.Item)); itemUiContext.Tooltip?.Close(); } } @@ -249,7 +245,9 @@ namespace UIFixes if (!allOrNothing || InteractionCount(EItemInfoButton.Unequip, itemUiContext) == Count) { var taskSerializer = itemUiContext.gameObject.AddComponent(); - taskSerializer.Initialize(SortedItemContexts(), itemContext => itemUiContext.Uninstall(itemContext.GClass2813_0)); + taskSerializer.Initialize( + SortedItemContexts().Where(ic => InteractionAvailable(ic, EItemInfoButton.Unequip, itemUiContext)), + itemContext => itemUiContext.Uninstall(itemContext.GClass2813_0)); itemUiContext.Tooltip?.Close(); } } @@ -261,7 +259,9 @@ namespace UIFixes { // Call Initialize() before setting UnloadSerializer so that the initial synchronous call to StopProcesses()->StopUnloading() doesn't immediately cancel this var taskSerializer = itemUiContext.gameObject.AddComponent(); - taskSerializer.Initialize(SortedItemContexts(), itemContext => itemUiContext.UnloadAmmo(itemContext.Item)); + taskSerializer.Initialize( + SortedItemContexts().Where(ic => InteractionAvailable(ic, EItemInfoButton.UnloadAmmo, itemUiContext)), + itemContext => itemUiContext.UnloadAmmo(itemContext.Item)); UnloadSerializer = taskSerializer; itemUiContext.Tooltip?.Close(); @@ -341,9 +341,9 @@ namespace UIFixes private void OnParentDispose() { - if (Item.CurrentAddress == null) + if (Item.CurrentAddress == null || Item.CurrentAddress.Container.ParentItem is MagazineClass) { - // This item is gone! + // This item was entirely merged away, or went into a magazine MultiSelect.Deselect(this); } } diff --git a/Patches/GridWindowButtonsPatch.cs b/Patches/GridWindowButtonsPatch.cs index 8e62e80..356cb0c 100644 --- a/Patches/GridWindowButtonsPatch.cs +++ b/Patches/GridWindowButtonsPatch.cs @@ -19,7 +19,7 @@ namespace UIFixes public static void Postfix(GridWindow __instance) { var wrappedInstance = __instance.R(); - if (Settings.AddContainerButtons.Value && wrappedInstance.LootItem.Int32_0 > 2) // Greater than 2 cells wide + if (Settings.AddContainerButtons.Value && wrappedInstance.LootItem.Int32_0 > 3) // Greater than 3 cells wide { Transform closeButton = __instance.transform.Find("Caption Panel/Close Button"); Image sortBackground = __instance.transform.Find("Caption Panel/Sort Button")?.GetComponent(); diff --git a/Patches/MultiSelectPatches.cs b/Patches/MultiSelectPatches.cs index fca4875..79e02a7 100644 --- a/Patches/MultiSelectPatches.cs +++ b/Patches/MultiSelectPatches.cs @@ -478,6 +478,9 @@ namespace UIFixes DisableMerge = targetItem == null; bool isGridPlacement = targetItem == null; + // If everything selected is the same type and is a stackable type, allow partial success + bool allowPartialSuccess = targetItem != null && itemContext.Item is GClass2735 && MultiSelect.ItemContexts.All(ic => ic.Item.TemplateId == itemContext.Item.TemplateId); + Stack operations = new(); foreach (ItemContextClass selectedItemContext in MultiSelect.SortedItemContexts(itemContext)) { @@ -583,6 +586,11 @@ namespace UIFixes DisableMerge = false; + if (allowPartialSuccess && operations.Any()) + { + __result = true; + } + if (!__result) { HidePreviews();