empty slot linked search

This commit is contained in:
Tyfon
2024-07-10 17:31:33 -07:00
parent 395108eda8
commit 90a197afc9
10 changed files with 295 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
using Comfort.Common;
using EFT.InventoryLogic;
using EFT.UI;
using EFT.UI.DragAndDrop;
using HarmonyLib;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
@@ -9,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using TMPro;
using UIFixes.ContextMenus;
using UnityEngine;
namespace UIFixes
@@ -81,6 +83,9 @@ namespace UIFixes
new EnableInsureInnerItemsPatch().Enable();
new DisableLoadPresetOnBulletsPatch().Enable();
new EmptySlotMenuPatch().Enable();
new EmptySlotMenuRemovePatch().Enable();
}
public class ContextMenuNamesPatch : ModulePatch
@@ -422,6 +427,44 @@ namespace UIFixes
}
}
public class EmptySlotMenuPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.DeclaredMethod(typeof(ModSlotView), nameof(ModSlotView.Show));
}
[PatchPostfix]
public static void Postfix(ModSlotView __instance, Slot slot, ItemContextAbstractClass parentItemContext, ItemUiContext itemUiContext)
{
if (!Settings.EnableSlotSearch.Value || slot.ContainedItem != null)
{
return;
}
EmptySlotMenuTrigger menuTrigger = __instance.GetOrAddComponent<EmptySlotMenuTrigger>();
menuTrigger.Init(slot, parentItemContext, itemUiContext);
}
}
public class EmptySlotMenuRemovePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.DeclaredMethod(typeof(ModSlotView), nameof(ModSlotView.SetupItemView));
}
[PatchPostfix]
public static void Postfix(ModSlotView __instance)
{
EmptySlotMenuTrigger menuTrigger = __instance.GetComponent<EmptySlotMenuTrigger>();
if (menuTrigger != null)
{
UnityEngine.Object.Destroy(menuTrigger);
}
}
}
public class PositionSubMenuPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()