From 71138c7bbe69781a6fca59f56126676828de8f73 Mon Sep 17 00:00:00 2001 From: Atony <75191600+AtonyGit@users.noreply.github.com> Date: Thu, 22 Oct 2026 01:17:21 -0500 Subject: [PATCH] Display current role and modifiers at top --- MiraAPI/Patches/RoleGuidePatches.cs | 34 ++++++++++++++++---- MiraAPI/Utilities/BasicGuideComparer.cs | 41 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 MiraAPI/Utilities/BasicGuideComparer.cs diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs index e9aaf24a..7f50492f 100644 --- a/MiraAPI/Patches/RoleGuidePatches.cs +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -754,7 +754,8 @@ public static class RoleGuidePatches modifier.ModifierCategoryTitle, modifier.ParentMod.MiraPlugin.GetAbbreviatedModName(), null, - modifier)); + modifier, + modifier.TypeId)); } } @@ -790,7 +791,8 @@ public static class RoleGuidePatches roleBehaviour.GetCategoryTitle(), modId, roleBehaviour, - null)); + null, + (uint)roleBehaviour.Role)); } _roleEntriesMode = activeModeType; @@ -928,7 +930,7 @@ public static class RoleGuidePatches } } - private sealed class DetailedPanel(string title, string category, string modId, RoleBehaviour? role, GameModifier? modifier) + private sealed class DetailedPanel(string title, string category, string modId, RoleBehaviour? role, GameModifier? modifier, uint typeId) { public MatchInfoRolePanel? Panel { get; set; } public string Title { get; } = title; @@ -936,6 +938,7 @@ public static class RoleGuidePatches public string ModId { get; } = modId; public RoleBehaviour? Role { get; } = role; public GameModifier? Modifier { get; } = modifier; + public uint TypeId { get; } = typeId; public int Amount { get; set; } public int Chance { get; set; } public float Likelihood { get; set; } @@ -1186,14 +1189,33 @@ public static class RoleGuidePatches private static List SortEntries(List entries, string searchText) { + var activeModifiers = PlayerControl.LocalPlayer.GetModifiers().Select(x => x.TypeId); + List comparisons = activeModifiers.ToList(); + + var curRole = PlayerControl.LocalPlayer.Data.Role.Role; + + comparisons.Add((ushort)curRole); + + if (PlayerControl.LocalPlayer && PlayerControl.LocalPlayer.Data && PlayerControl.LocalPlayer.Data.IsDead && + !comparisons.Contains((ushort)PlayerControl.LocalPlayer.Data.RoleWhenAlive.Value)) + { + comparisons.Add((ushort)PlayerControl.LocalPlayer.Data.RoleWhenAlive.Value); + } + + var comparer = new BasicGuideComparer(comparisons); + 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 + p.Category.Contains(searchText, StringComparison.OrdinalIgnoreCase)) + .ThenBy(x => x.Modifier != null ? x.Modifier.TypeId : (uint)x.Role!.Role, comparer); + return + [ + .. _sortMethod is SortingMethod.Alphabetical ? sorted.ThenBy(p => p.GetSortKey(_sortGrouping)) - : sorted.ThenByDescending(p => p.GetSortKey(_sortGrouping))]; + : sorted.ThenByDescending(p => p.GetSortKey(_sortGrouping)) + ]; } private static bool MatchesSearch(DetailedPanel entry, string searchText) diff --git a/MiraAPI/Utilities/BasicGuideComparer.cs b/MiraAPI/Utilities/BasicGuideComparer.cs new file mode 100644 index 00000000..2ca80412 --- /dev/null +++ b/MiraAPI/Utilities/BasicGuideComparer.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MiraAPI.Utilities; + +public class BasicGuideComparer(IEnumerable activeIds) : IComparer +{ + public int Compare(uint x, uint y) + { + if (x == null && y == null) + { + return 0; + } + + if (x == null) + { + return -1; + } + + if (y == null) + { + return 1; + } + + var xActive = activeIds.Contains(x); + var yActive = activeIds.Contains(y); + + if (xActive && !yActive) + { + return -1; + } + + if (!xActive && yActive) + { + return 1; + } + + return 0; + } +} \ No newline at end of file