Fix disappearing categories by delay setting the handbookId; auto-expand categories
This commit is contained in:
@@ -25,6 +25,7 @@ namespace UIFixes
|
|||||||
|
|
||||||
private static bool FirstFilter = true;
|
private static bool FirstFilter = true;
|
||||||
private static bool GoingBack = false;
|
private static bool GoingBack = false;
|
||||||
|
private static string DelayedHandbookId = string.Empty;
|
||||||
|
|
||||||
private static DefaultUIButton PreviousButton;
|
private static DefaultUIButton PreviousButton;
|
||||||
|
|
||||||
@@ -124,8 +125,9 @@ namespace UIFixes
|
|||||||
|
|
||||||
private static void OnFilterRuleChanged(RagfairScreen ragScreen, ISession session)
|
private static void OnFilterRuleChanged(RagfairScreen ragScreen, ISession session)
|
||||||
{
|
{
|
||||||
if (GoingBack ||
|
if (FirstFilter ||
|
||||||
FirstFilter ||
|
GoingBack ||
|
||||||
|
!String.IsNullOrEmpty(DelayedHandbookId) ||
|
||||||
session.RagFair.FilterRule.ViewListType != EViewListType.AllOffers)
|
session.RagFair.FilterRule.ViewListType != EViewListType.AllOffers)
|
||||||
{
|
{
|
||||||
FirstFilter = false;
|
FirstFilter = false;
|
||||||
@@ -226,10 +228,10 @@ namespace UIFixes
|
|||||||
newRule.SortType = filterRule.SortType;
|
newRule.SortType = filterRule.SortType;
|
||||||
newRule.SortDirection = filterRule.SortDirection;
|
newRule.SortDirection = filterRule.SortDirection;
|
||||||
|
|
||||||
// Treat HandbookId as a new search, since it feels like a new view
|
// We can't set handbookId yet - it limits the result set and that in turn limits what categories even display
|
||||||
newRule.HandbookId = filterRule.HandbookId;
|
DelayedHandbookId = filterRule.HandbookId;
|
||||||
|
|
||||||
ragFair.SetFilterRule(newRule, true, !newRule.AnyIdSearch);
|
ragFair.SetFilterRule(newRule, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateColumnHeaders(FiltersPanel filtersPanel, ESortType sortType, bool sortDirection)
|
private static void UpdateColumnHeaders(FiltersPanel filtersPanel, ESortType sortType, bool sortDirection)
|
||||||
@@ -304,14 +306,51 @@ namespace UIFixes
|
|||||||
}
|
}
|
||||||
|
|
||||||
[PatchPostfix]
|
[PatchPostfix]
|
||||||
public static async void Postfix(Task __result, LightScroller ____scroller)
|
public static async void Postfix(OfferViewList __instance, Task __result, LightScroller ____scroller, EViewListType ___eviewListType_0)
|
||||||
{
|
{
|
||||||
await __result;
|
await __result;
|
||||||
|
|
||||||
|
if (___eviewListType_0 != EViewListType.AllOffers)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(DelayedHandbookId))
|
||||||
|
{
|
||||||
|
// Super important to clear DelayedHandbookId *before* calling method_10, or infinite loops can occur!
|
||||||
|
string newHandbookId = DelayedHandbookId;
|
||||||
|
DelayedHandbookId = string.Empty;
|
||||||
|
|
||||||
|
__instance.method_10(newHandbookId, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore scroll position now that the we're loaded
|
||||||
if (History.Any())
|
if (History.Any())
|
||||||
{
|
{
|
||||||
____scroller.SetScrollPosition(History.Peek().scrollPosition);
|
____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())
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalHeight += nextHeight;
|
||||||
|
categories = categories.SelectMany(c => c.OpenCategory()).Where(v => v.gameObject.activeInHierarchy).OfType<CategoryView>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user