diff --git a/MiraAPI.Example/Roles/TeleporterRole.cs b/MiraAPI.Example/Roles/TeleporterRole.cs index 9877f84..5b00f63 100644 --- a/MiraAPI.Example/Roles/TeleporterRole.cs +++ b/MiraAPI.Example/Roles/TeleporterRole.cs @@ -18,4 +18,9 @@ public class TeleporterRole : CrewmateRole, ICustomRole DefaultChance = 73, DefaultRoleCount = 4, }; + + public bool CanLocalPlayerSeeRole(PlayerControl player) + { + return true; + } } diff --git a/MiraAPI/Patches/Roles/HauntMenuPatch.cs b/MiraAPI/Patches/Roles/HauntMenuPatch.cs new file mode 100644 index 0000000..b174165 --- /dev/null +++ b/MiraAPI/Patches/Roles/HauntMenuPatch.cs @@ -0,0 +1,27 @@ +using HarmonyLib; +using MiraAPI.Roles; +using UnityEngine; + +namespace MiraAPI.Patches.Roles; + +/// +/// Patches the haunt menu to show the actual role name rather then team. +/// +[HarmonyPatch(typeof(HauntMenuMinigame), nameof(HauntMenuMinigame.SetFilterText))] +public static class HauntMenuMinigamePatch +{ + public static void Postfix(HauntMenuMinigame __instance) + { + if (__instance.HauntTarget.Data.IsDead) + { + __instance.FilterText.color = Color.white; + return; + } + + var role = __instance.HauntTarget.Data.Role; + var color = role is ICustomRole custom ? custom.RoleColor : role.TeamColor; + + __instance.FilterText.text = role.NiceName; + __instance.FilterText.color = color; + } +} \ No newline at end of file diff --git a/MiraAPI/Patches/Roles/NameTagPatch.cs b/MiraAPI/Patches/Roles/NameTagPatch.cs index 821db1c..7974351 100644 --- a/MiraAPI/Patches/Roles/NameTagPatch.cs +++ b/MiraAPI/Patches/Roles/NameTagPatch.cs @@ -1,10 +1,11 @@ using HarmonyLib; +using MiraAPI.Roles; using UnityEngine; namespace MiraAPI.Patches.Roles; /// -/// Set nametag color depending on option +/// Set nametag color depending on visibility. /// [HarmonyPatch(typeof(PlayerNameColor))] public static class NameTagPatch @@ -13,6 +14,12 @@ public static class NameTagPatch [HarmonyPatch(nameof(PlayerNameColor.Get), typeof(RoleBehaviour))] public static bool GetPatch([HarmonyArgument(0)] RoleBehaviour otherPlayerRole, ref Color __result) { + if (otherPlayerRole is ICustomRole customRole && customRole.CanLocalPlayerSeeRole(otherPlayerRole.Player)) + { + __result = customRole.RoleColor; + return false; + } + if (PlayerControl.LocalPlayer.Data.Role.IsImpostor && otherPlayerRole.IsImpostor) { return true; diff --git a/MiraAPI/Patches/Roles/RoleBehaviourPatches.cs b/MiraAPI/Patches/Roles/RoleBehaviourPatches.cs deleted file mode 100644 index 98cb5e6..0000000 --- a/MiraAPI/Patches/Roles/RoleBehaviourPatches.cs +++ /dev/null @@ -1,25 +0,0 @@ -using HarmonyLib; -using MiraAPI.Roles; -using UnityEngine; - -namespace MiraAPI.Patches.Roles; - -[HarmonyPatch(typeof(RoleBehaviour))] -public static class RoleBehaviourPatches -{ - /// - /// Update TeamColor text for Launchpad roles - /// - [HarmonyPrefix] - [HarmonyPatch(nameof(RoleBehaviour.TeamColor), MethodType.Getter)] - public static bool PrefixTeamColorGetter(RoleBehaviour __instance, ref Color __result) - { - if (__instance is not ICustomRole behaviour) - { - return true; - } - - __result = behaviour.RoleColor; - return false; - } -} diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index a28bed9..63642cb 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -128,6 +128,16 @@ public interface ICustomRole Logger.Error($"Error getting count configuration for role: {RoleName}"); } + /// + /// Whether the local player can see this role. + /// + /// The player with the role. + /// Whether they can see the role (name color) or not. + public virtual bool CanLocalPlayerSeeRole(PlayerControl player) + { + return (Team == ModdedRoleTeams.Impostor && player.Data.Role.IsImpostor) || PlayerControl.LocalPlayer.Data.IsDead; + } + /// /// This method runs on the HudManager.Update method ONLY when the LOCAL player has this role. ///