Add ctrl-F to highlight search; fix flea enter during filter not working

This commit is contained in:
Tyfon
2024-09-04 03:29:26 -07:00
parent 6e96461ad2
commit f62d957059
4 changed files with 103 additions and 7 deletions

View File

@@ -1,9 +1,11 @@
using EFT.UI; using EFT.HandBook;
using EFT.UI;
using EFT.UI.Ragfair; using EFT.UI.Ragfair;
using HarmonyLib; using HarmonyLib;
using SPT.Reflection.Patching; using SPT.Reflection.Patching;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@@ -12,6 +14,8 @@ namespace UIFixes;
public static class FixFleaPatches public static class FixFleaPatches
{ {
private static Task SearchFilterTask;
public static void Enable() public static void Enable()
{ {
// These are anal AF // These are anal AF
@@ -24,7 +28,10 @@ public static class FixFleaPatches
new OfferItemFixMaskPatch().Enable(); new OfferItemFixMaskPatch().Enable();
new OfferViewTweaksPatch().Enable(); new OfferViewTweaksPatch().Enable();
new SearchFilterPatch().Enable();
new SearchPatch().Enable(); new SearchPatch().Enable();
new SearchKeyPatch().Enable();
new SearchKeyHandbookPatch().Enable();
} }
public class DoNotToggleOnMouseOverPatch : ModulePatch 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 public class SearchPatch : ModulePatch
{ {
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
@@ -145,19 +166,64 @@ public static class FixFleaPatches
return true; 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) if (__instance.FilteredNodes.Values.Sum(node => node.Count) > 0)
{ {
return true; 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; 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<SearchKeyListener>();
}
}
// 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<SearchKeyListener>();
} }
} }

View File

@@ -7,8 +7,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using TMPro;
using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
namespace UIFixes; namespace UIFixes;
@@ -108,6 +106,8 @@ public static class HideoutSearchPatches
areaScreenSubstrate.method_8(); areaScreenSubstrate.method_8();
} }
____searchInputField.GetOrAddComponent<SearchKeyListener>();
____searchInputField.ActivateInputField(); ____searchInputField.ActivateInputField();
____searchInputField.Select(); ____searchInputField.Select();
} }

20
SearchKeyListener.cs Normal file
View File

@@ -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<TMP_InputField>();
if (searchField != null)
{
searchField.ActivateInputField();
searchField.Select();
}
}
}
}

View File

@@ -106,6 +106,7 @@ internal class Settings
public static ConfigEntry<KeyboardShortcut> LinkedSearchKeyBind { get; set; } public static ConfigEntry<KeyboardShortcut> LinkedSearchKeyBind { get; set; }
public static ConfigEntry<KeyboardShortcut> AddOfferKeyBind { get; set; } public static ConfigEntry<KeyboardShortcut> AddOfferKeyBind { get; set; }
public static ConfigEntry<KeyboardShortcut> SortingTableKeyBind { get; set; } public static ConfigEntry<KeyboardShortcut> SortingTableKeyBind { get; set; }
public static ConfigEntry<KeyboardShortcut> SearchKeyBind { get; set; }
public static ConfigEntry<bool> LimitNonstandardDrags { get; set; } // Advanced public static ConfigEntry<bool> LimitNonstandardDrags { get; set; } // Advanced
public static ConfigEntry<bool> ItemContextBlocksTextInputs { get; set; } // Advanced public static ConfigEntry<bool> ItemContextBlocksTextInputs { get; set; } // Advanced
@@ -464,6 +465,15 @@ internal class Settings
null, null,
new ConfigurationManagerAttributes { }))); 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( configEntries.Add(LimitNonstandardDrags = config.Bind(
InputSection, InputSection,
"Limit Nonstandard Drags", "Limit Nonstandard Drags",