using EFT; using EFT.InventoryLogic; using EFT.UI; using EFT.UI.DragAndDrop; using HarmonyLib; using SPT.Reflection.Patching; using System.Collections.Generic; using System.Linq; using System.Reflection; using TMPro; using UnityEngine; using UnityEngine.UI; namespace UIFixes; public static class FilterOutOfStockPatches { private static bool ShowOutOfStockItems = true; private static GameObject OutOfStockPanel; public static void Enable() { new CreateButtonPatch().Enable(); new ShowButtonPatch().Enable(); new FilterPanelPatch().Enable(); new FilterOutOfStockGridItemsPatch().Enable(); } public class CreateButtonPatch : ModulePatch { protected override MethodBase GetTargetMethod() { return AccessTools.Method(typeof(TraderDealScreen), nameof(TraderDealScreen.Awake)); } [PatchPostfix] public static void Postfix(TraderDealScreen __instance, DefaultUIButton ____updateAssort, TradingGridView ____traderGridView) { OutOfStockPanel = new GameObject("OutOfStockPanel", [typeof(RectTransform)]); OutOfStockPanel.transform.SetParent(__instance.transform.Find("Left Person/Possessions Grid"), false); OutOfStockPanel.transform.SetAsLastSibling(); OutOfStockPanel.SetActive(true); RectTransform panelTranform = OutOfStockPanel.RectTransform(); panelTranform.pivot = new Vector2(1f, 1f); panelTranform.anchorMin = panelTranform.anchorMax = new Vector2(1f, 0f); panelTranform.anchoredPosition = new Vector2(0f, 0f); panelTranform.sizeDelta = new Vector2(200, 30); HorizontalLayoutGroup layoutGroup = OutOfStockPanel.AddComponent(); layoutGroup.childForceExpandHeight = layoutGroup.childForceExpandWidth = false; layoutGroup.childControlHeight = false; layoutGroup.childControlWidth = true; layoutGroup.childAlignment = TextAnchor.MiddleRight; Image checkbox = UnityEngine.Object.Instantiate(__instance.transform.Find("TradeControll/Tabs/FillButton/Default/Icon_Box").GetComponent(), OutOfStockPanel.transform, false); checkbox.RectTransform().sizeDelta = new Vector2(20f, 20f); checkbox.preserveAspect = true; Image check = UnityEngine.Object.Instantiate(__instance.transform.Find("TradeControll/Tabs/FillButton/Checkmark").GetComponent(), checkbox.transform, false); check.RectTransform().anchoredPosition = new Vector2(-2f, 0f); check.RectTransform().sizeDelta = new Vector2(13f, 12f); check.gameObject.SetActive(ShowOutOfStockItems); LocalizedText text = UnityEngine.Object.Instantiate(____updateAssort.transform.Find("TextWhite").GetComponent(), OutOfStockPanel.transform, false); text.LocalizationKey = "OUT OF STOCK"; text.R().StringCase = EStringCase.Upper; TextMeshProUGUI textMesh = text.GetComponent(); textMesh.enableAutoSizing = false; textMesh.fontSize = 14f; Image background = OutOfStockPanel.AddComponent(); background.color = Color.clear; Button button = OutOfStockPanel.AddComponent