From 11700376146c557f484888782b547d81d5a9deb4 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Fri, 12 Jul 2024 23:33:08 -0700 Subject: [PATCH] out of stock checkbox --- ExtraProperties.cs | 13 +++ Patches/FilterOutOfStockPatches.cs | 143 +++++++++++++++++++++++++++++ Plugin.cs | 1 + R.cs | 21 +++++ Settings.cs | 10 ++ 5 files changed, 188 insertions(+) create mode 100644 Patches/FilterOutOfStockPatches.cs diff --git a/ExtraProperties.cs b/ExtraProperties.cs index bcdcdc7..ce4cdf4 100644 --- a/ExtraProperties.cs +++ b/ExtraProperties.cs @@ -29,3 +29,16 @@ public static class ExtraTemplatedGridsViewProperties public static bool GetReordered(this TemplatedGridsView gridsView) => properties.GetOrCreateValue(gridsView).Reordered; public static void SetReordered(this TemplatedGridsView gridsView, bool value) => properties.GetOrCreateValue(gridsView).Reordered = value; } + +public static class ExtraTradingGridProperties +{ + private static readonly ConditionalWeakTable properties = new(); + + private class Properties + { + public bool ShowOutOfStock = true; + } + + public static bool GetShowOutOfStock(this TradingGridView gridView) => properties.GetOrCreateValue(gridView).ShowOutOfStock; + public static void SetShowOutOfStock(this TradingGridView gridView, bool value) => properties.GetOrCreateValue(gridView).ShowOutOfStock = value; +} diff --git a/Patches/FilterOutOfStockPatches.cs b/Patches/FilterOutOfStockPatches.cs new file mode 100644 index 0000000..8d18496 --- /dev/null +++ b/Patches/FilterOutOfStockPatches.cs @@ -0,0 +1,143 @@ +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.parent = __instance.transform.Find("Left Person/Possessions Grid"); + 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 = layoutGroup.childControlWidth = false; + layoutGroup.childAlignment = TextAnchor.MiddleRight; + + Image checkbox = UnityEngine.Object.Instantiate(__instance.transform.Find("TradeControll/Tabs/FillButton/Default/Icon_Box").GetComponent(), OutOfStockPanel.transform, false); + checkbox.SetNativeSize(); + Image check = UnityEngine.Object.Instantiate(__instance.transform.Find("TradeControll/Tabs/FillButton/Checkmark").GetComponent(), checkbox.transform, false); + check.SetNativeSize(); + check.RectTransform().anchoredPosition = Vector2.zero; + check.transform.localScale = new Vector3(.7f, .7f, .7f); + 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 = 18f; + + Image background = OutOfStockPanel.AddComponent(); + background.color = Color.clear; + + Button button = OutOfStockPanel.AddComponent