clear filters on searchbar enter

This commit is contained in:
Tyfon
2024-07-18 15:07:53 -07:00
parent b748eb96ba
commit fea43bcada
2 changed files with 45 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
using EFT.UI.Ragfair; using EFT.UI;
using EFT.UI.Ragfair;
using HarmonyLib; using HarmonyLib;
using SPT.Reflection.Patching; using SPT.Reflection.Patching;
using System.Reflection; using System.Reflection;
@@ -18,6 +19,8 @@ public static class FixFleaPatches
new OfferItemFixMaskPatch().Enable(); new OfferItemFixMaskPatch().Enable();
new OfferViewTweaksPatch().Enable(); new OfferViewTweaksPatch().Enable();
new SearchPatch().Enable();
} }
public class DoNotToggleOnMouseOverPatch : ModulePatch public class DoNotToggleOnMouseOverPatch : ModulePatch
@@ -95,4 +98,35 @@ public static class FixFleaPatches
timeLeft.childControlWidth = false; timeLeft.childControlWidth = false;
} }
} }
public class SearchPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(RagfairCategoriesPanel), nameof(RagfairCategoriesPanel.method_9));
}
[PatchPrefix]
public static bool Prefix(RagfairCategoriesPanel __instance, string arg)
{
if (!Settings.ClearFiltersOnSearch.Value)
{
return true;
}
if (arg.StartsWith("#") || __instance.Ragfair == null || __instance.EViewListType_0 != EViewListType.AllOffers)
{
return true;
}
__instance.Ragfair.CancellableFilters.Clear();
FilterRule filterRule = __instance.Ragfair.method_3(EViewListType.AllOffers);
filterRule.HandbookId = string.Empty;
__instance.Ragfair.AddSearchesInRule(filterRule, true);
return false;
}
}
} }

View File

@@ -117,6 +117,7 @@ internal class Settings
public static ConfigEntry<bool> EnableSlotSearch { get; set; } public static ConfigEntry<bool> EnableSlotSearch { get; set; }
public static ConfigEntry<bool> ShowRequiredQuest { get; set; } public static ConfigEntry<bool> ShowRequiredQuest { get; set; }
public static ConfigEntry<bool> AutoExpandCategories { get; set; } public static ConfigEntry<bool> AutoExpandCategories { get; set; }
public static ConfigEntry<bool> ClearFiltersOnSearch { get; set; }
public static ConfigEntry<bool> KeepAddOfferOpen { get; set; } public static ConfigEntry<bool> KeepAddOfferOpen { get; set; }
public static ConfigEntry<KeyboardShortcut> PurchaseAllKeybind { get; set; } public static ConfigEntry<KeyboardShortcut> PurchaseAllKeybind { get; set; }
public static ConfigEntry<bool> KeepAddOfferOpenIgnoreMaxOffers { get; set; } // Advanced public static ConfigEntry<bool> KeepAddOfferOpenIgnoreMaxOffers { get; set; } // Advanced
@@ -663,6 +664,15 @@ internal class Settings
null, null,
new ConfigurationManagerAttributes { }))); new ConfigurationManagerAttributes { })));
configEntries.Add(ClearFiltersOnSearch = config.Bind(
FleaMarketSection,
"Clear Filters on Search",
true,
new ConfigDescription(
"Pressing Enter after typing in the flea search bar will clear non-default filters",
null,
new ConfigurationManagerAttributes { })));
configEntries.Add(ShowRequiredQuest = config.Bind( configEntries.Add(ShowRequiredQuest = config.Bind(
FleaMarketSection, FleaMarketSection,
"Show Required Quest for Locked Offers", "Show Required Quest for Locked Offers",