Autoexpand fixes and clean up

This commit is contained in:
Tyfon
2024-05-25 01:34:08 -07:00
parent a544ae37f8
commit 3662b72efd
4 changed files with 80 additions and 34 deletions

View File

@@ -115,6 +115,10 @@ namespace UIFixes
prevButtonLayout.minWidth = -1;
prevButtonLayout.preferredWidth = -1;
// Tighten up the spacing
var layoutGroup = PreviousButton.transform.parent.GetComponent<HorizontalLayoutGroup>();
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<GClass3196>
{
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<GClass3196>();
// 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<CategoryView> categories = __instance.GetComponentsInChildren<CategoryView>();
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<CategoryView>();
var wrappedInstance = __instance.R();
var activeCategories = __instance.GetComponentsInChildren<CategoryView>();
var activeSubcategories = __instance.GetComponentsInChildren<SubcategoryView>();
int currentHeight = activeCategories.Length * CategoryHeight + activeSubcategories.Length * SubcategoryHeight;
var categories = __instance.GetComponentsInChildren<CombinedView>()
.Where(cv => cv.transform.childCount > 0)
.Select(cv => cv.transform.GetChild(0).GetComponent<CategoryView>())
.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<CategoryView>();
}
}
}
}
@@ -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;

View File

@@ -159,7 +159,7 @@ namespace UIFixes
}
[PatchPrefix]
public static void Prefix(ItemView __instance)
public static void Prefix()
{
SourceContainer = null;
}

16
R.cs
View File

@@ -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);
}
}

View File

@@ -58,6 +58,7 @@ namespace UIFixes
// Flea Market
public static ConfigEntry<bool> EnableFleaHistory { get; set; }
public static ConfigEntry<bool> ShowRequiredQuest { get; set; }
public static ConfigEntry<bool> AutoExpandCategories { get; set; }
// Advanced
public static ConfigEntry<bool> 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",