Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added colour blindness functionality to Spy #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions source/Patches/CrewmateRoles/SpyMod/AddNumbers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using HarmonyLib;
using TownOfUs.Roles;
using UnityEngine;
using Object = UnityEngine.Object;

namespace TownOfUs.Patches.CrewmateRoles.SpyMod {
[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Start))]
public class AddNumbers {

public static void GenNumber(Spy role, PlayerVoteArea voteArea) {
var targetId = voteArea.TargetPlayerId;

var nameText = Object.Instantiate(voteArea.NameText, voteArea.transform);
nameText.transform.localPosition = new Vector3(-1.211f, -0.18f, -0.1f);
nameText.text = GameData.Instance.GetPlayerById(targetId).DefaultOutfit.ColorId.ToString();
role.PlayerNumbers[targetId] = nameText;
}

public static void Postfix(MeetingHud __instance) {
foreach (var role in Role.GetRoles(RoleEnum.Spy)) {
var spy = (Spy)role;
spy.PlayerNumbers.Clear();
}

if (PlayerControl.LocalPlayer.Data.IsDead) return;
if (!PlayerControl.LocalPlayer.Is(RoleEnum.Spy)) return;

var spyRole = Role.GetRole<Spy>(PlayerControl.LocalPlayer);

foreach (var voteArea in __instance.playerStates) {
GenNumber(spyRole, voteArea);
}
}
}
}
17 changes: 17 additions & 0 deletions source/Patches/CrewmateRoles/SpyMod/Admin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using HarmonyLib;
using TMPro;
using UnityEngine;

namespace TownOfUs.CrewmateRoles.SpyMod
Expand All @@ -22,14 +23,30 @@ public static void UpdateBlips(CounterArea area, List<int> colorMapping)
area.UpdateCount(colorMapping.Count);
var icons = area.myIcons.ToArray();
colorMapping.Sort();
var useCompactText = icons.Count > 2 * area.MaxWidth;
for (var i = 0;i < colorMapping.Count;i++)
{
var icon = icons[i];
var sprite = icon.GetComponent<SpriteRenderer>();
var text = icon.GetComponentInChildren<TextMeshPro>(true);
if (sprite != null)
{
PlayerControl.SetPlayerMaterialColors(colorMapping[i], sprite);
}
if (text != null) {
text.gameObject.SetActive(true);
text.text = colorMapping[i].ToString();
// Show first row numbers below player icons
// Show second row numbers above player icons
// show all icons on player icons when there are three rows
if(useCompactText) {
text.transform.localPosition = new Vector3(0, 0, -20);
} else if (i / area.MaxWidth == 0) {
text.transform.localPosition = new Vector3(0, -area.YOffset, -20);
} else {
text.transform.localPosition = new Vector3(0, area.YOffset, -20);
}
}
}
}

Expand Down
26 changes: 25 additions & 1 deletion source/Patches/CrewmateRoles/SpyMod/PooledMapIconPatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HarmonyLib;
using UnityEngine;
using TMPro;

namespace TownOfUs.CrewmateRoles.SpyMod {
[HarmonyPatch(typeof(PooledMapIcon), nameof(PooledMapIcon.Reset))]
Expand All @@ -9,6 +10,29 @@ public static void Postfix(PooledMapIcon __instance) {
if (sprite != null) {
PlayerControl.SetPlayerMaterialColors(new Color(0.8793f, 1, 0, 1), sprite); // Reset Color to default. Fixes Shifted Spy issue
}
var text = __instance.GetComponentInChildren<TextMeshPro>(true);
if (text == null) {
text = new GameObject("Text").AddComponent<TextMeshPro>();
text.transform.SetParent(__instance.transform, false);
text.fontSize = 1.5f;
text.fontSizeMin = 1;
text.fontSizeMax = 1.5f;
text.enableAutoSizing = true;
text.fontStyle = FontStyles.Bold;
text.alignment = TextAlignmentOptions.Center;
text.horizontalAlignment = HorizontalAlignmentOptions.Center;
text.gameObject.layer = 5;
text.fontMaterial.EnableKeyword("OUTLINE_ON");
text.fontMaterial.SetFloat("_OutlineWidth", 0.1745f);
text.fontMaterial.SetFloat("_FaceDilate", 0.151f);
}
text.transform.localPosition = new Vector3(0, 0, -20);
text.text = "";
text.gameObject.SetActive(false);
var sprite = __instance.GetComponent<SpriteRenderer>();
if (sprite != null) {
PlayerControl.SetPlayerMaterialColors(new Color(0.8793f, 1, 0, 1), sprite); // Reset Color to default. Fixes Shifted Spy issue
}
}
}
}
}
3 changes: 3 additions & 0 deletions source/Patches/Roles/Spy.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;

namespace TownOfUs.Roles
{
public class Spy : Role
{
public Dictionary<byte, TMP_Text> PlayerNumbers = new Dictionary<byte, TMP_Text>();
public Spy(PlayerControl player) : base(player)
{
Name = "Spy";
Expand Down