From 6f36aa91a53faf4da4911d7f4998040b189a169f Mon Sep 17 00:00:00 2001 From: neilmjain <69025896+neilmjain@users.noreply.github.com> Date: Tue, 13 Oct 2026 22:44:20 -0400 Subject: [PATCH] also add filtering/hiding of entries not pertaining to search --- MiraAPI/Patches/RoleGuidePatches.cs | 101 ++++++++++++++++++++++++---- 1 file changed, 88 insertions(+), 13 deletions(-) diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs index 92080e8..c0081a4 100644 --- a/MiraAPI/Patches/RoleGuidePatches.cs +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -7,6 +7,7 @@ using System.Linq; using AmongUs.GameOptions; using HarmonyLib; using Innersloth.Assets; +using MiraAPI.LocalSettings; using MiraAPI.Modifiers; using MiraAPI.Modifiers.Types; using MiraAPI.Roles; @@ -28,7 +29,9 @@ public static class RoleGuidePatches { private const int RolesTabIndex = 2; private const int ModifiersTabIndex = 3; - private const float SearchDebounceSeconds = 0.3f; + private const float MinGuideScaleFactor = 0.5f; + private const float MaxGuideScaleFactor = 1f; + private const float SearchDebounceSeconds = 0.05f; private static readonly List RoleEntries = []; private static readonly List ModifierEntries = []; @@ -113,13 +116,29 @@ public static class RoleGuidePatches [HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.Awake))] public static void Awake(MatchInfoGuide __instance) { - __instance.transitionOpen.targetSize = 1.3f; + __instance.transitionOpen.targetSize = Helpers.MatchInfoGuideBaseScale; if (_guide != __instance) { ResetState(); } } + public static void ApplyGuideScale(MatchInfoGuide instance, float scaleFactor) + { + if (!instance || !instance.transitionOpen) + { + return; + } + + var targetSize = Helpers.MatchInfoGuideBaseScale * + Mathf.Clamp(scaleFactor, MinGuideScaleFactor, MaxGuideScaleFactor); + instance.transitionOpen.targetSize = targetSize; + if (instance.MatchInfoParent.activeSelf) + { + instance.transitionOpen.transform.localScale = Vector3.one * targetSize; + } + } + /// /// Clears all cached state tied to a previous instance. /// Every game spawns a fresh guide, so anything we cached from the old one is a destroyed Unity object. @@ -171,6 +190,7 @@ public static class RoleGuidePatches [HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.Awake))] private static void AwakePostfix(MatchInfoGuide __instance) { + ApplyGuideScale(__instance, LocalSettingsTabSingleton.Instance.MatchInfoGuideScaleFactor.Value); Coroutines.Start(CoPreload(__instance)); } @@ -232,6 +252,8 @@ public static class RoleGuidePatches return false; } + ApplyGuideScale(__instance, LocalSettingsTabSingleton.Instance.MatchInfoGuideScaleFactor.Value); + if (Minigame.Instance != null) { Minigame.Instance.Close(); @@ -746,6 +768,8 @@ public static class RoleGuidePatches public int Amount { get; set; } public int Chance { get; set; } public float Likelihood { get; set; } + public bool CanShow { get; set; } + public bool CountsReady { get; set; } public bool Visible { get; set; } public string GetSortKey(SortingGroups grouping) @@ -935,14 +959,18 @@ public static class RoleGuidePatches entry.Amount = amount; entry.Chance = chance; entry.Likelihood = amount * chance; - entry.Visible = ShouldShowPanel(forceShow, amount == 0 || chance == 0, isHidden); + entry.CanShow = ShouldShowPanel(forceShow, amount == 0 || chance == 0, isHidden); + entry.CountsReady = true; + entry.Visible = entry.CanShow; } private static List UpdateEntries(List entries, bool modifiers) { + var searchText = GetSearchText(); foreach (var entry in entries) { ComputeCounts(entry); + entry.Visible = entry.CanShow && (modifiers || MatchesSearch(entry, searchText)); if (entry.Panel) { SetPanelCount(entry.Panel!, entry.Amount, entry.Chance, entry.ModId); @@ -953,16 +981,7 @@ public static class RoleGuidePatches } } - var searchText = GetSearchText(); - var sorted = entries.Where(p => p.Visible) - .OrderByDescending(p => p.Title.Equals(searchText, StringComparison.OrdinalIgnoreCase)) - .ThenByDescending(p => - p.Title.Contains(searchText, StringComparison.OrdinalIgnoreCase) || - p.Category.Contains(searchText, StringComparison.OrdinalIgnoreCase)); - var shown = (_sortMethod is SortingMethod.Alphabetical - ? sorted.ThenBy(p => p.GetSortKey(_sortGrouping)) - : sorted.ThenByDescending(p => p.GetSortKey(_sortGrouping))) - .ToList(); + var shown = SortEntries(entries, searchText); var instance = MatchInfoGuide.Instance; if (modifiers) @@ -979,6 +998,26 @@ public static class RoleGuidePatches return shown; } + private static List SortEntries(List entries, string searchText) + { + var sorted = entries.Where(p => p.Visible) + .OrderByDescending(p => p.Title.Equals(searchText, StringComparison.OrdinalIgnoreCase)) + .ThenByDescending(p => + p.Title.Contains(searchText, StringComparison.OrdinalIgnoreCase) || + p.Category.Contains(searchText, StringComparison.OrdinalIgnoreCase)); + return (_sortMethod is SortingMethod.Alphabetical + ? sorted.ThenBy(p => p.GetSortKey(_sortGrouping)) + : sorted.ThenByDescending(p => p.GetSortKey(_sortGrouping))) + .ToList(); + } + + private static bool MatchesSearch(DetailedPanel entry, string searchText) + { + return searchText.Length == 0 || + entry.Title.Contains(searchText, StringComparison.OrdinalIgnoreCase) || + entry.Category.Contains(searchText, StringComparison.OrdinalIgnoreCase); + } + private static void RefreshActiveTab(bool scrollToTop) { StartPopulate(); @@ -1009,9 +1048,45 @@ public static class RoleGuidePatches } _appliedSearch = text; + if (TryRefreshRoleSearch(text)) + { + yield break; + } + RefreshActiveTab(true); } + private static bool TryRefreshRoleSearch(string searchText) + { + var guide = MatchInfoGuide.Instance; + if (!_guide || guide != _guide || guide.activeTabIndex != RolesTabIndex || + _populate != null || RoleEntries.Count == 0 || + RoleEntries.Any(entry => !entry.CountsReady || !entry.Panel)) + { + return false; + } + + foreach (var entry in RoleEntries) + { + entry.Visible = entry.CanShow && MatchesSearch(entry, searchText); + if (entry.Panel!.gameObject.activeSelf != entry.Visible) + { + entry.Panel.gameObject.SetActive(entry.Visible); + } + } + + var shown = SortEntries(RoleEntries, searchText); + foreach (var entry in shown) + { + entry.Panel!.transform.SetAsLastSibling(); + } + + guide.MatchInfoRoleScroller.SetYBoundsMax(GetGridScrollBounds(shown.Count)); + guide.rolesEnabledMessage.SetActive(shown.Count == 0); + _rolesScroller.ScrollToTop(); + return true; + } + private static void ResetSearchBox() { if (_searchDebounce != null)