From f62d957059394c36c45412f1c06b5716c6334d61 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Wed, 4 Sep 2024 03:29:26 -0700 Subject: [PATCH] Add ctrl-F to highlight search; fix flea enter during filter not working --- Patches/FixFleaPatches.cs | 76 ++++++++++++++++++++++++++++++--- Patches/HideoutSearchPatches.cs | 4 +- SearchKeyListener.cs | 20 +++++++++ Settings.cs | 10 +++++ 4 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 SearchKeyListener.cs diff --git a/Patches/FixFleaPatches.cs b/Patches/FixFleaPatches.cs index c2364cf..b178f3b 100644 --- a/Patches/FixFleaPatches.cs +++ b/Patches/FixFleaPatches.cs @@ -1,9 +1,11 @@ -using EFT.UI; +using EFT.HandBook; +using EFT.UI; using EFT.UI.Ragfair; using HarmonyLib; using SPT.Reflection.Patching; using System.Linq; using System.Reflection; +using System.Threading.Tasks; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -12,6 +14,8 @@ namespace UIFixes; public static class FixFleaPatches { + private static Task SearchFilterTask; + public static void Enable() { // These are anal AF @@ -24,7 +28,10 @@ public static class FixFleaPatches new OfferItemFixMaskPatch().Enable(); new OfferViewTweaksPatch().Enable(); + new SearchFilterPatch().Enable(); new SearchPatch().Enable(); + new SearchKeyPatch().Enable(); + new SearchKeyHandbookPatch().Enable(); } public class DoNotToggleOnMouseOverPatch : ModulePatch @@ -125,6 +132,20 @@ public static class FixFleaPatches } } + public class SearchFilterPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(BrowseCategoriesPanel), nameof(BrowseCategoriesPanel.Filter)); + } + + [PatchPostfix] + public static void Postfix(Task __result) + { + SearchFilterTask = __result; + } + } + public class SearchPatch : ModulePatch { protected override MethodBase GetTargetMethod() @@ -145,19 +166,64 @@ public static class FixFleaPatches return true; } + if (SearchFilterTask != null && !SearchFilterTask.IsCompleted) + { + SearchFilterTask.ContinueWith(t => DoSearch(__instance), TaskScheduler.FromCurrentSynchronizationContext()); + return true; + } + if (__instance.FilteredNodes.Values.Sum(node => node.Count) > 0) { return true; } - __instance.Ragfair.CancellableFilters.Clear(); + DoSearch(__instance); + return false; + } - FilterRule filterRule = __instance.Ragfair.method_3(EViewListType.AllOffers); + private static void DoSearch(RagfairCategoriesPanel panel) + { + if (panel.FilteredNodes.Values.Sum(node => node.Count) > 0) + { + return; + } + + panel.Ragfair.CancellableFilters.Clear(); + + FilterRule filterRule = panel.Ragfair.method_3(EViewListType.AllOffers); filterRule.HandbookId = string.Empty; - __instance.Ragfair.AddSearchesInRule(filterRule, true); + panel.Ragfair.AddSearchesInRule(filterRule, true); + } + } - return false; + public class SearchKeyPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(BrowseCategoriesPanel), nameof(BrowseCategoriesPanel.Awake)); + } + + [PatchPostfix] + public static void Postfix(TMP_InputField ___SearchInputField) + { + ___SearchInputField.GetOrAddComponent(); + } + } + + // Have to target HandbookCategoriesPanel specifically because even though it inherits from BrowseCategoriesPanel, + // BSG couldn't be bothered to call base.Awake() + public class SearchKeyHandbookPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(HandbookCategoriesPanel), nameof(HandbookCategoriesPanel.Awake)); + } + + [PatchPostfix] + public static void Postfix(TMP_InputField ___SearchInputField) + { + ___SearchInputField.GetOrAddComponent(); } } diff --git a/Patches/HideoutSearchPatches.cs b/Patches/HideoutSearchPatches.cs index 7e5b730..1198a00 100644 --- a/Patches/HideoutSearchPatches.cs +++ b/Patches/HideoutSearchPatches.cs @@ -7,8 +7,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using TMPro; -using UnityEngine.EventSystems; using UnityEngine.UI; namespace UIFixes; @@ -108,6 +106,8 @@ public static class HideoutSearchPatches areaScreenSubstrate.method_8(); } + ____searchInputField.GetOrAddComponent(); + ____searchInputField.ActivateInputField(); ____searchInputField.Select(); } diff --git a/SearchKeyListener.cs b/SearchKeyListener.cs new file mode 100644 index 0000000..ad73078 --- /dev/null +++ b/SearchKeyListener.cs @@ -0,0 +1,20 @@ +using TMPro; +using UnityEngine; + +namespace UIFixes; + +public class SearchKeyListener : MonoBehaviour +{ + public void Update() + { + if (Settings.SearchKeyBind.Value.IsDown()) + { + TMP_InputField searchField = GetComponent(); + if (searchField != null) + { + searchField.ActivateInputField(); + searchField.Select(); + } + } + } +} \ No newline at end of file diff --git a/Settings.cs b/Settings.cs index ac77f1d..18b9f6a 100644 --- a/Settings.cs +++ b/Settings.cs @@ -106,6 +106,7 @@ internal class Settings public static ConfigEntry LinkedSearchKeyBind { get; set; } public static ConfigEntry AddOfferKeyBind { get; set; } public static ConfigEntry SortingTableKeyBind { get; set; } + public static ConfigEntry SearchKeyBind { get; set; } public static ConfigEntry LimitNonstandardDrags { get; set; } // Advanced public static ConfigEntry ItemContextBlocksTextInputs { get; set; } // Advanced @@ -464,6 +465,15 @@ internal class Settings null, new ConfigurationManagerAttributes { }))); + configEntries.Add(SearchKeyBind = config.Bind( + InputSection, + "Highlight Search Box", + new KeyboardShortcut(KeyCode.F, KeyCode.LeftControl), + new ConfigDescription( + "Keybind to highlight the search box in hideout crafting, handbook, and flea market", + null, + new ConfigurationManagerAttributes { }))); + configEntries.Add(LimitNonstandardDrags = config.Bind( InputSection, "Limit Nonstandard Drags",