From 29b6094b206b142e8a9bc0f2e3caaa44f0a97a87 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:06:24 -0700 Subject: [PATCH] old sorting table button; fix auto-sorting table open on scav screen --- .vscode/tasks.json | 23 ++++++++ Patches/MoveSortingTablePatches.cs | 90 ++++++++++++++++++++++++++++++ Patches/MultiSelectPatches.cs | 2 +- Patches/OpenSortingTablePatch.cs | 11 +++- Plugin.cs | 1 + R.cs | 34 ++++++++++- Settings.cs | 19 ++++++- 7 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 .vscode/tasks.json create mode 100644 Patches/MoveSortingTablePatches.cs diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..0b4d6cd --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "dotnet", + "task": "build", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [], + "label": "dotnet: build", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + } + ] +} diff --git a/Patches/MoveSortingTablePatches.cs b/Patches/MoveSortingTablePatches.cs new file mode 100644 index 0000000..3e72cf6 --- /dev/null +++ b/Patches/MoveSortingTablePatches.cs @@ -0,0 +1,90 @@ +using Comfort.Common; +using EFT.UI; +using HarmonyLib; +using SPT.Reflection.Patching; +using System.Reflection; +using UnityEngine; + +namespace UIFixes; + +public static class MoveSortingTablePatches +{ + private static Transform SelectedBackground; + + public static void Enable() + { + new ButtonsPatch().Enable(); + new ToggleBackgroundPatch().Enable(); + } + + public class ButtonsPatch : ModulePatch + { + private static Tab OldSortingTableTab; + + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(SimpleStashPanel), nameof(SimpleStashPanel.Show)); + } + + [PatchPostfix] + public static void Postfix(SimpleStashPanel __instance, ItemUiContext ___itemUiContext_0, Tab ____sortingTableTab, LootItemClass ___lootItemClass) + { + if (Settings.SortingTableButton.Value == SortingTableDisplay.New || ____sortingTableTab == null || ___itemUiContext_0.ContextType != EItemUiContextType.InventoryScreen) + { + return; + } + + if (___lootItemClass.Parent.GetOwner() is not InventoryControllerClass inventoryController) + { + return; + } + + if (OldSortingTableTab == null) + { + Transform scavScreenSortingTableButton = Singleton.Instance.transform.Find("Common UI/Scavenger Inventory Screen/Items Panel/Stash Panel/Simple Panel/Sorting Panel/SortTableButton"); + OldSortingTableTab = UnityEngine.Object.Instantiate(scavScreenSortingTableButton.GetComponent(), ____sortingTableTab.transform.parent, false); + OldSortingTableTab.transform.SetAsFirstSibling(); + + OldSortingTableTab.OnSelectionChanged += __instance.method_1; + + SelectedBackground = OldSortingTableTab.transform.Find("Selected"); + if (!inventoryController.SortingTableActive) + { + SelectedBackground.gameObject.SetActive(false); + } + + __instance.R().UI.AddDisposable(() => + { + OldSortingTableTab.OnSelectionChanged -= __instance.method_1; + UnityEngine.Object.Destroy(OldSortingTableTab.gameObject); + OldSortingTableTab = null; + SelectedBackground = null; + }); + } + + OldSortingTableTab.gameObject.SetActive(____sortingTableTab.isActiveAndEnabled); + + if (Settings.SortingTableButton.Value == SortingTableDisplay.Old) + { + ____sortingTableTab.gameObject.SetActive(false); + } + } + } + + public class ToggleBackgroundPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(SimpleStashPanel), nameof(SimpleStashPanel.ChangeSortingTableTabState)); + } + + [PatchPostfix] + public static void Postfix(bool isVisible) + { + if (SelectedBackground?.gameObject != null) + { + SelectedBackground.gameObject.SetActive(isVisible); + } + } + } +} \ No newline at end of file diff --git a/Patches/MultiSelectPatches.cs b/Patches/MultiSelectPatches.cs index f188dfd..3275533 100644 --- a/Patches/MultiSelectPatches.cs +++ b/Patches/MultiSelectPatches.cs @@ -323,7 +323,7 @@ namespace UIFixes if (__instance.Profile == PatchConstants.BackEndSession.Profile) { MultiSelect.StopLoading(); - } + } } } diff --git a/Patches/OpenSortingTablePatch.cs b/Patches/OpenSortingTablePatch.cs index 65401b2..9ada574 100644 --- a/Patches/OpenSortingTablePatch.cs +++ b/Patches/OpenSortingTablePatch.cs @@ -35,7 +35,16 @@ namespace UIFixes SortingTableClass sortingTable = __instance.R().InventoryController.Inventory.SortingTable; if (sortingTable != null && !sortingTable.IsVisible) { - Singleton.Instance.InventoryScreen.method_6(); + if (__instance.ContextType == EItemUiContextType.InventoryScreen) + { + Singleton.Instance.InventoryScreen.method_6(); + Singleton.Instance.InventoryScreen.R().SimpleStashPanel.ChangeSortingTableTabState(true); + } + else if (__instance.ContextType == EItemUiContextType.ScavengerInventoryScreen) + { + Singleton.Instance.ScavengerInventoryScreen.method_7(); + Singleton.Instance.ScavengerInventoryScreen.R().SimpleStashPanel.ChangeSortingTableTabState(true); + } } } } diff --git a/Plugin.cs b/Plugin.cs index aed606a..e5c5597 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -62,6 +62,7 @@ namespace UIFixes NoRandomGrenadesPatch.Init(); GPCoinPatches.Enable(); FleaSlotSearchPatches.Enable(); + MoveSortingTablePatches.Enable(); } public static bool InRaid() diff --git a/R.cs b/R.cs index 9c5b12e..6090874 100644 --- a/R.cs +++ b/R.cs @@ -63,6 +63,8 @@ namespace UIFixes InventoryInteractions.InitTypes(); TradingInteractions.InitTypes(); TransferInteractions.InitTypes(); + InventoryScreen.InitTypes(); + ScavengerInventoryScreen.InitTypes(); } public abstract class Wrapper(object value) @@ -781,7 +783,7 @@ namespace UIFixes ItemField = AccessTools.Field(Type, "item_0"); } - public Item Item { get { return (Item) ItemField.GetValue(Value); } } + public Item Item { get { return (Item)ItemField.GetValue(Value); } } } public class TransferInteractions(object value) : Wrapper(value) @@ -817,6 +819,34 @@ namespace UIFixes }); } } + + public class InventoryScreen(object value) : UIInputNode(value) + { + public static Type Type { get; private set; } + private static FieldInfo SimpleStashPanelField; + + public static void InitTypes() + { + Type = typeof(EFT.UI.InventoryScreen); + SimpleStashPanelField = AccessTools.Field(Type, "_simpleStashPanel"); + } + + public SimpleStashPanel SimpleStashPanel { get { return (SimpleStashPanel)SimpleStashPanelField.GetValue(Value); } } + } + + public class ScavengerInventoryScreen(object value) : UIInputNode(value) + { + public static Type Type { get; private set; } + private static FieldInfo SimpleStashPanelField; + + public static void InitTypes() + { + Type = typeof(EFT.UI.ScavengerInventoryScreen); + SimpleStashPanelField = AccessTools.Field(Type, "_simpleStashPanel"); + } + + public SimpleStashPanel SimpleStashPanel { get { return (SimpleStashPanel)SimpleStashPanelField.GetValue(Value); } } + } } public static class RExtentensions @@ -845,5 +875,7 @@ namespace UIFixes public static R.MessageWindow R(this MessageWindow value) => new(value); public static R.RagfairNewOfferItemView R(this RagfairNewOfferItemView value) => new(value); public static R.TradingTableGridView R(this TradingTableGridView value) => new(value); + public static R.InventoryScreen R(this InventoryScreen value) => new(value); + public static R.ScavengerInventoryScreen R(this ScavengerInventoryScreen value) => new(value); } } diff --git a/Settings.cs b/Settings.cs index bfac63a..7b1a7f8 100644 --- a/Settings.cs +++ b/Settings.cs @@ -30,6 +30,13 @@ namespace UIFixes OriginalSpacing } + internal enum SortingTableDisplay + { + New, + Old, + Both + } + internal class Settings { // Categories @@ -85,6 +92,7 @@ namespace UIFixes public static ConfigEntry AutoOpenSortingTable { get; set; } public static ConfigEntry ContextMenuOnRight { get; set; } public static ConfigEntry ShowGPCurrency { get; set; } + public static ConfigEntry SortingTableButton { get; set; } public static ConfigEntry LoadMagPresetOnBullets { get; set; } // Advanced // Inspect Panels @@ -479,6 +487,15 @@ namespace UIFixes null, new ConfigurationManagerAttributes { }))); + configEntries.Add(SortingTableButton = config.Bind( + InventorySection, + "Sorting Table Button", + SortingTableDisplay.New, + new ConfigDescription( + "What position to show the sorting table button", + null, + new ConfigurationManagerAttributes { }))); + configEntries.Add(LoadMagPresetOnBullets = config.Bind( InventorySection, "Mag Presets Context Menu on Bullets", @@ -709,7 +726,7 @@ namespace UIFixes if (allowSecondaryToDisablePrimary) { priorityConfig.Value = false; - } + } else if (priorityConfig.Value) { secondaryConfig.Value = false;