Some changes to role visibility name text

This commit is contained in:
ang-xd committed 2025-02-13 18:10:42 -05:00
1 parent c7d16f7fc9
commit 4db7605d27
5 files changed
+50 -26

No files matched your search

+5
View File
@@ -18,4 +18,9 @@ public class TeleporterRole : CrewmateRole, ICustomRole
DefaultChance = 73,
DefaultRoleCount = 4,
};
public bool CanLocalPlayerSeeRole(PlayerControl player)
{
return true;
}
}
+27
View File
@@ -0,0 +1,27 @@
using HarmonyLib;
using MiraAPI.Roles;
using UnityEngine;
namespace MiraAPI.Patches.Roles;
/// <summary>
/// Patches the haunt menu to show the actual role name rather then team.
/// </summary>
[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;
}
}
+8 -1
View File
@@ -1,10 +1,11 @@
using HarmonyLib;
using MiraAPI.Roles;
using UnityEngine;
namespace MiraAPI.Patches.Roles;
/// <summary>
/// Set nametag color depending on option
/// Set nametag color depending on visibility.
/// </summary>
[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;
@@ -1,25 +0,0 @@
using HarmonyLib;
using MiraAPI.Roles;
using UnityEngine;
namespace MiraAPI.Patches.Roles;
[HarmonyPatch(typeof(RoleBehaviour))]
public static class RoleBehaviourPatches
{
/// <summary>
/// Update TeamColor text for Launchpad roles
/// </summary>
[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;
}
}
+10
View File
@@ -128,6 +128,16 @@ public interface ICustomRole
Logger<MiraApiPlugin>.Error($"Error getting count configuration for role: {RoleName}");
}
/// <summary>
/// Whether the local player can see this role.
/// </summary>
/// <param name="player">The player with the role.</param>
/// <returns>Whether they can see the role (name color) or not.</returns>
public virtual bool CanLocalPlayerSeeRole(PlayerControl player)
{
return (Team == ModdedRoleTeams.Impostor && player.Data.Role.IsImpostor) || PlayerControl.LocalPlayer.Data.IsDead;
}
/// <summary>
/// This method runs on the HudManager.Update method ONLY when the LOCAL player has this role.
/// </summary>