From a3668b31501ef358c76956b745a19a98135675af Mon Sep 17 00:00:00 2001 From: Atony <75191600+AtonyGit@users.noreply.github.com> Date: Wed, 19 Aug 2026 13:52:33 -0500 Subject: [PATCH] Add proper support for modded roles in wiki --- MiraAPI/Patches/HudManagerPatches.cs | 29 ++++++++++++++++++++ MiraAPI/Utilities/Extensions.cs | 41 ++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs index 0304e6f..e7ac548 100644 --- a/MiraAPI/Patches/HudManagerPatches.cs +++ b/MiraAPI/Patches/HudManagerPatches.cs @@ -1,9 +1,11 @@ using System.Collections; using System.Collections.Generic; +using System.Globalization; using HarmonyLib; using MiraAPI.Hud; using MiraAPI.Keybinds; using MiraAPI.LocalSettings; +using MiraAPI.Roles; using MiraAPI.Utilities; using Reactor.Utilities; using Reactor.Utilities.Extensions; @@ -215,6 +217,33 @@ public static class HudManagerPatches __instance.SetActiveTab(0); return false; } + [HarmonyPrefix] + [HarmonyPriority(Priority.First)] + [HarmonyPatch(typeof(MatchInfoRolePanel), nameof(MatchInfoRolePanel.SetPanel))] + public static bool SetPanel(MatchInfoRolePanel __instance, RoleBehaviour role, int numPerGame, int chancePerGame) + { + if (role is ICustomRole customRole) + { + __instance.roleName.text = customRole.RoleName; + __instance.roleDescription.text = customRole.RoleDescription; + __instance.roleIcon.sprite = customRole.Configuration.Icon?.LoadAsset(); + } + else + { + __instance.roleName.text = role.NiceName; + __instance.roleDescription.text = role.BlurbMed; + __instance.roleIcon.sprite = role.RoleIconColor; + } + + __instance.roleIcon.SetSizeLimit(0.13f); + __instance.roleCount.text = string.Format(CultureInfo.InvariantCulture, "{0} at {1}%", numPerGame.ToString(CultureInfo.InvariantCulture), chancePerGame); + __instance.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50); + __instance.roleName.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f); + __instance.roleDescription.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f); + __instance.roleCount.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f); + __instance.roleIcon.transform.localScale = new Vector3(4f, 4f, 1f); + return false; + } /// /// Create custom buttons and arrange them on the hud. diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 84bc280..7a219da 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -378,6 +378,47 @@ public static class Extensions } } + /// + /// Resizes a appropriate to the maximum pixel size without messing up ratios. + /// + /// The to adjust. + /// The scale for the sprite to be adjusted to. + public static void SetSizeLimit(this SpriteRenderer sprite, float pixelSize) + { + sprite.drawMode = SpriteDrawMode.Sliced; + if (!sprite.sprite) + { + return; + } + + float spriteWidth = sprite.sprite.rect.width; + float spriteHeight = sprite.sprite.rect.height; + + if (spriteWidth < spriteHeight) + { + sprite.size = new Vector2(pixelSize * spriteWidth / spriteHeight, pixelSize); + } + else + { + sprite.size = new Vector2(pixelSize, pixelSize * spriteHeight / spriteWidth); + } + } + + /// + /// Resizes a appropriate to the maximum pixel size without messing up ratios. + /// + /// The to adjust. + /// The scale for the sprite to be adjusted to. + public static void SetSizeLimit(this GameObject spriteObj, float pixelSize) + { + if (!spriteObj.TryGetComponent(out var sprite)) + { + return; + } + + sprite.SetSizeLimit(pixelSize); + } + /// /// Gets a cache of 's to improve performance. ///