Add Open->All context menu option

This commit is contained in:
Tyfon
2024-10-02 16:18:59 -07:00
parent 44518e52d5
commit 1b218179a2
3 changed files with 117 additions and 2 deletions

View File

@@ -0,0 +1,83 @@
using Comfort.Common;
using EFT.UI;
using EFT.UI.DragAndDrop;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace UIFixes;
public class OpenInteractions(ItemContextAbstractClass itemContext, ItemUiContext itemUiContext) : ItemInfoInteractionsAbstractClass<OpenInteractions.Options>(itemUiContext)
{
private readonly ItemContextAbstractClass itemContext = itemContext;
public override void ExecuteInteractionInternal(Options interaction)
{
if (itemContext == null || itemContext.Item is not LootItemClass compoundItem)
{
return;
}
var taskSerializer = itemUiContext_0.gameObject.AddComponent<NestedContainerTaskSerializer>();
taskSerializer.Initialize(GetNestedContainers(itemContext), containerContext =>
{
if (containerContext != null)
{
itemUiContext_0.OpenItem(containerContext.Item as LootItemClass, containerContext, true);
}
return Task.CompletedTask;
});
}
public override bool IsActive(Options button)
{
return true;
}
public override IResult IsInteractive(Options button)
{
return SuccessfulResult.New;
}
public override bool HasIcons
{
get { return false; }
}
public enum Options
{
All
}
private IEnumerable<ItemContextAbstractClass> GetNestedContainers(ItemContextAbstractClass first)
{
var windowRoot = Singleton<PreloaderUI>.Instance;
LootItemClass parent = first.Item as LootItemClass;
yield return first;
while (true)
{
var innerContainers = parent.GetFirstLevelItems()
.Where(i => i != parent)
.Where(i => i is LootItemClass innerContainer && innerContainer.Grids.Any());
if (innerContainers.Count() != 1)
{
yield break;
}
var targetId = innerContainers.First().Id;
var targetItemView = windowRoot.GetComponentsInChildren<GridItemView>().FirstOrDefault(itemView => itemView.Item.Id == targetId);
if (targetItemView == null)
{
yield return null; // Keeps returning null until the window is open
}
parent = targetItemView.Item as LootItemClass;
yield return targetItemView.ItemContext;
}
}
}
public class NestedContainerTaskSerializer : TaskSerializer<ItemContextAbstractClass> { }

View File

@@ -125,9 +125,20 @@ public static class ContextMenuPatches
}
[PatchPostfix]
public static void Postfix(ref IEnumerable<EItemInfoButton> __result)
public static void Postfix(ref IEnumerable<EItemInfoButton> __result, Item ___item_0)
{
__result = __result.Append(EItemInfoButton.Repair).Append(EItemInfoButton.Insure);
if (___item_0 is LootItemClass container && container.Grids.Any())
{
var innerContainers = container.GetFirstLevelItems()
.Where(i => i != container)
.Where(i => i is LootItemClass innerContainer && innerContainer.Grids.Any());
if (innerContainers.Count() == 1)
{
__result = __result.Append(EItemInfoButton.Open);
}
}
}
}
@@ -141,7 +152,12 @@ public static class ContextMenuPatches
}
[PatchPrefix]
public static bool Prefix(EItemInfoButton parentInteraction, ISubInteractions subInteractionsWrapper, Item ___item_0, ItemUiContext ___itemUiContext_1)
public static bool Prefix(
EItemInfoButton parentInteraction,
ISubInteractions subInteractionsWrapper,
Item ___item_0,
ItemContextAbstractClass ___itemContextAbstractClass,
ItemUiContext ___itemUiContext_1)
{
// Clear this, since something else should be active (even a different mouseover of the insurance button)
LoadingInsuranceActions = false;
@@ -179,6 +195,12 @@ public static class ContextMenuPatches
return false;
}
if (Settings.OpenAllContextMenu.Value && parentInteraction == EItemInfoButton.Open)
{
subInteractionsWrapper.SetSubInteractions(new OpenInteractions(___itemContextAbstractClass, ___itemUiContext_1));
return false;
}
return true;
}
}

View File

@@ -139,6 +139,7 @@ internal class Settings
public static ConfigEntry<bool> ContextMenuOnRight { get; set; }
public static ConfigEntry<bool> AddOfferContextMenu { get; set; }
public static ConfigEntry<bool> WishlistContextEverywhere { get; set; }
public static ConfigEntry<bool> OpenAllContextMenu { get; set; }
public static ConfigEntry<bool> ShowGPCurrency { get; set; }
public static ConfigEntry<bool> ShowOutOfStockCheckbox { get; set; }
public static ConfigEntry<SortingTableDisplay> SortingTableButton { get; set; }
@@ -748,6 +749,15 @@ internal class Settings
null,
new ConfigurationManagerAttributes { })));
configEntries.Add(OpenAllContextMenu = config.Bind(
InventorySection,
"Open All Context Flyout",
true,
new ConfigDescription(
"Add a flyout to the Open context menu to recursively open a stack of containers",
null,
new ConfigurationManagerAttributes { })));
configEntries.Add(ShowGPCurrency = config.Bind(
InventorySection,
"Show GP Coins in Currency",