From 3662b72efd6f8e8a3d1693c08d8ec581000bfb23 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Sat, 25 May 2024 01:34:08 -0700 Subject: [PATCH] Autoexpand fixes and clean up --- Patches/FleaPrevSearchPatches.cs | 86 ++++++++++++++++++++------------ Patches/SwapPatches.cs | 2 +- R.cs | 16 ++++++ Settings.cs | 10 ++++ 4 files changed, 80 insertions(+), 34 deletions(-) diff --git a/Patches/FleaPrevSearchPatches.cs b/Patches/FleaPrevSearchPatches.cs index 1cf1c3a..d6ca7b8 100644 --- a/Patches/FleaPrevSearchPatches.cs +++ b/Patches/FleaPrevSearchPatches.cs @@ -115,6 +115,10 @@ namespace UIFixes prevButtonLayout.minWidth = -1; prevButtonLayout.preferredWidth = -1; + // Tighten up the spacing + var layoutGroup = PreviousButton.transform.parent.GetComponent(); + layoutGroup.spacing = 5f; + if (History.Count < 2) { PreviousButton.Interactable = false; @@ -182,23 +186,11 @@ namespace UIFixes } // Using GClass because it's easier + // Copied from RagFairClass.AddSearchesInRule, but actually all of the properties private static void ApplyFullFilter(RagFairClass ragFair, FilterRule filterRule) { - // copied from RagFairClass.AddSearchesInRule, but actually all of the properties - var searches = new List - { - new(EFilterType.Currency, filterRule.CurrencyType, filterRule.CurrencyType != 0), - new(EFilterType.PriceFrom, filterRule.PriceFrom, filterRule.PriceFrom != 0), - new(EFilterType.PriceTo, filterRule.PriceTo, filterRule.PriceTo != 0), - new(EFilterType.QuantityFrom, filterRule.QuantityFrom, filterRule.QuantityFrom != 0), - new(EFilterType.QuantityTo, filterRule.QuantityTo, filterRule.QuantityTo != 0), - new(EFilterType.ConditionFrom, filterRule.ConditionFrom, filterRule.ConditionFrom != 0), - new(EFilterType.ConditionTo, filterRule.ConditionTo, filterRule.ConditionTo != 100), - new(EFilterType.OneHourExpiration, filterRule.OneHourExpiration ? 1 : 0, filterRule.OneHourExpiration), - new(EFilterType.RemoveBartering, filterRule.RemoveBartering ? 1 : 0, filterRule.RemoveBartering), - new(EFilterType.OfferOwnerType, filterRule.OfferOwnerType, filterRule.OfferOwnerType != 0), - new(EFilterType.OnlyFunctional, filterRule.OnlyFunctional ? 1 : 0, filterRule.OnlyFunctional), - }; + // Order impacts the order the filters show in the UI + var searches = new List(); // This part was tricky to figure out. Adding OR removing any of these ID filters will clear the others, so you can only do one of them. // When going to a state with no id filter, you MUST remove something (or all to be safe) @@ -221,6 +213,18 @@ namespace UIFixes searches.Add(new(EFilterType.LinkedSearch, String.Empty, false)); } + searches.Add(new(EFilterType.Currency, filterRule.CurrencyType, filterRule.CurrencyType != 0)); + searches.Add(new(EFilterType.PriceFrom, filterRule.PriceFrom, filterRule.PriceFrom != 0)); + searches.Add(new(EFilterType.PriceTo, filterRule.PriceTo, filterRule.PriceTo != 0)); + searches.Add(new(EFilterType.QuantityFrom, filterRule.QuantityFrom, filterRule.QuantityFrom != 0)); + searches.Add(new(EFilterType.QuantityTo, filterRule.QuantityTo, filterRule.QuantityTo != 0)); + searches.Add(new(EFilterType.ConditionFrom, filterRule.ConditionFrom, filterRule.ConditionFrom != 0)); + searches.Add(new(EFilterType.ConditionTo, filterRule.ConditionTo, filterRule.ConditionTo != 100)); + searches.Add(new(EFilterType.OneHourExpiration, filterRule.OneHourExpiration ? 1 : 0, filterRule.OneHourExpiration)); + searches.Add(new(EFilterType.RemoveBartering, filterRule.RemoveBartering ? 1 : 0, filterRule.RemoveBartering)); + searches.Add(new(EFilterType.OfferOwnerType, filterRule.OfferOwnerType, filterRule.OfferOwnerType != 0)); + searches.Add(new(EFilterType.OnlyFunctional, filterRule.OnlyFunctional ? 1 : 0, filterRule.OnlyFunctional)); + ragFair.method_24(filterRule.ViewListType, [.. searches], false, out FilterRule newRule); // These properties don't consistute a new search, so much as a different view of the same search @@ -331,25 +335,41 @@ namespace UIFixes ____scroller.SetScrollPosition(History.Peek().scrollPosition); } - // Try to auto-expand categories to use available space. Gotta do math to see what fits - const int ListHeight = 780; - const int CategoryHeight = 34; - const int SubcategoryHeight = 25; - - IEnumerable categories = __instance.GetComponentsInChildren(); - int totalHeight = categories.Count() * CategoryHeight; - - while (categories.Any()) + if (Settings.AutoExpandCategories.Value) { - // This is all child categories that have matching *offers* (x.Count), and if they have children themselves they're a category, otherwise a subcategory - int nextHeight = categories.SelectMany(c => c.Node.Children).Where(x => x.Count > 0).Sum(sc => sc.Children.Any() ? CategoryHeight : SubcategoryHeight); - if (totalHeight + nextHeight > ListHeight) - { - break; - } + // Try to auto-expand categories to use available space. Gotta do math to see what fits + const int PanelHeight = 780; + const int CategoryHeight = 34; + const int SubcategoryHeight = 25; - totalHeight += nextHeight; - categories = categories.SelectMany(c => c.OpenCategory()).Where(v => v.gameObject.activeInHierarchy).OfType(); + var wrappedInstance = __instance.R(); + + var activeCategories = __instance.GetComponentsInChildren(); + var activeSubcategories = __instance.GetComponentsInChildren(); + int currentHeight = activeCategories.Length * CategoryHeight + activeSubcategories.Length * SubcategoryHeight; + + var categories = __instance.GetComponentsInChildren() + .Where(cv => cv.transform.childCount > 0) + .Select(cv => cv.transform.GetChild(0).GetComponent()) + .Where(c => c != null && c.gameObject.activeInHierarchy); + + while (categories.Any()) + { + // This is all child categories that aren't already open; have matching *offers* (x.Count); and if they have children themselves they're a category, otherwise a subcategory + int additionalHeight = categories + .Where(c => !c.R().IsOpen && c.Node != null) + .SelectMany(c => c.Node.Children) + .Where(n => n.Count > 0) + .Sum(n => n.Children.Any() ? CategoryHeight : SubcategoryHeight); + + if (currentHeight + additionalHeight > PanelHeight) + { + break; + } + + currentHeight += additionalHeight; + categories = categories.SelectMany(c => c.OpenCategory()).Where(v => v.gameObject.activeInHierarchy).OfType(); + } } } } @@ -361,6 +381,7 @@ namespace UIFixes // one.Page == two.Page && // one.SortType == two.SortType && // one.SortDirection == two.SortDirection && + // one.HandbookId == two.HandbookId && one.CurrencyType == two.CurrencyType && one.PriceFrom == two.PriceFrom && one.PriceTo == two.PriceTo && @@ -372,7 +393,6 @@ namespace UIFixes one.RemoveBartering == two.RemoveBartering && one.OfferOwnerType == two.OfferOwnerType && one.OnlyFunctional == two.OnlyFunctional && - one.HandbookId == two.HandbookId && one.FilterSearchId == two.FilterSearchId && one.LinkedSearchId == two.LinkedSearchId && one.NeededSearchId == two.NeededSearchId; diff --git a/Patches/SwapPatches.cs b/Patches/SwapPatches.cs index d19cb38..f9aecac 100644 --- a/Patches/SwapPatches.cs +++ b/Patches/SwapPatches.cs @@ -159,7 +159,7 @@ namespace UIFixes } [PatchPrefix] - public static void Prefix(ItemView __instance) + public static void Prefix() { SourceContainer = null; } diff --git a/R.cs b/R.cs index f8a278d..8960a6b 100644 --- a/R.cs +++ b/R.cs @@ -41,6 +41,7 @@ namespace UIFixes RagfairScreen.InitTypes(); OfferViewList.InitTypes(); FiltersPanel.InitTypes(); + CategoryView.InitTypes(); QuestCache.InitTypes(); } @@ -347,6 +348,20 @@ namespace UIFixes public EFT.UI.Ragfair.FiltersPanel FiltersPanel { get { return (EFT.UI.Ragfair.FiltersPanel)FiltersPanelField.GetValue(Value); } } } + public class CategoryView(object value) : Wrapper(value) + { + public static Type Type { get; private set; } + private static FieldInfo IsOpenField; + + public static void InitTypes() + { + Type = typeof(EFT.UI.Ragfair.CategoryView); + IsOpenField = AccessTools.Field(Type, "bool_3"); + } + + public bool IsOpen { get { return (bool)IsOpenField.GetValue(Value); } } + } + public class FiltersPanel(object value) : Wrapper(value) { public static Type Type { get; private set; } @@ -410,6 +425,7 @@ namespace UIFixes public static R.ContextMenuButton R(this ContextMenuButton value) => new(value); public static R.RagfairScreen R(this RagfairScreen value) => new(value); public static R.OfferViewList R(this OfferViewList value) => new(value); + public static R.CategoryView R(this CategoryView value) => new(value); public static R.FiltersPanel R(this FiltersPanel value) => new(value); } } diff --git a/Settings.cs b/Settings.cs index c0a9f82..81daf9c 100644 --- a/Settings.cs +++ b/Settings.cs @@ -58,6 +58,7 @@ namespace UIFixes // Flea Market public static ConfigEntry EnableFleaHistory { get; set; } public static ConfigEntry ShowRequiredQuest { get; set; } + public static ConfigEntry AutoExpandCategories { get; set; } // Advanced public static ConfigEntry StyleItemPanel { get; set; } @@ -225,6 +226,15 @@ namespace UIFixes null, new ConfigurationManagerAttributes { }))); + configEntries.Add(AutoExpandCategories = config.Bind( + FleaMarketSection, + "Auto-expand Categories", + true, + new ConfigDescription( + "Searches will auto-expand categories in the left panel if there is room wtihout scrolling", + null, + new ConfigurationManagerAttributes { }))); + configEntries.Add(ShowRequiredQuest = config.Bind( FleaMarketSection, "Show Required Quest for Locked Offers",