From 1c4a91c4f853ec10f1a70de07b18e4efaa79b627 Mon Sep 17 00:00:00 2001
From: FruitieX <fruitiex@gmail.com>
Date: Wed, 13 Apr 2011 18:42:01 +0300
Subject: [PATCH] allow decolorization as an option, enable by default in
 teamgames similar to how the old cl_shownames did it. Can be forced on in
 non-teamgames too.

---
 defaultXonotic.cfg            |  1 +
 qcsrc/client/autocvars.qh     |  1 +
 qcsrc/client/miscfunctions.qc | 27 +++++++++++++++++++++++++++
 qcsrc/client/progs.src        |  1 +
 qcsrc/client/shownames.qc     |  3 +++
 qcsrc/client/teamplay.qc      |  3 ---
 6 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg
index 089c11a62..ccb04f6c1 100644
--- a/defaultXonotic.cfg
+++ b/defaultXonotic.cfg
@@ -1487,6 +1487,7 @@ seta hud_shownames_status 2 "1 = draw health/armor status of teammates, 2 = same
 seta hud_shownames_height 15 "height of icons"
 seta hud_shownames_aspect 8 "aspect ratio of total drawing area per name"
 seta hud_shownames_fontsize 8 "font size"
+seta hud_shownames_decolorize 1 "1 = decolorize name in team games, 2 = decolorize always"
 seta hud_shownames_alpha 0.7 "alpha"
 seta hud_shownames_resize 1 "enable resizing of the names, then the size cvars will correspond to the maximum size"
 seta hud_shownames_mindistance 1000 "start fading alpha/size at this distance"
diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh
index fc3c1f8e1..d06c31a12 100644
--- a/qcsrc/client/autocvars.qh
+++ b/qcsrc/client/autocvars.qh
@@ -278,6 +278,7 @@ float autocvar_hud_shownames_status;
 float autocvar_hud_shownames_height;
 float autocvar_hud_shownames_aspect;
 float autocvar_hud_shownames_fontsize;
+float autocvar_hud_shownames_decolorize;
 float autocvar_hud_shownames_alpha;
 float autocvar_hud_shownames_resize;
 float autocvar_hud_shownames_mindistance;
diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc
index 1ee799a77..4588ebb6c 100644
--- a/qcsrc/client/miscfunctions.qc
+++ b/qcsrc/client/miscfunctions.qc
@@ -375,6 +375,33 @@ string ColorTranslateRGB(string s)
 		return s;
 }
 
+string Team_ColorCode(float teamid)
+{
+    if (teamid == COLOR_TEAM1)
+        return "^1";
+    else if (teamid == COLOR_TEAM2)
+        return "^4";
+    else if (teamid == COLOR_TEAM3)
+        return "^3";
+    else if (teamid == COLOR_TEAM4)
+        return "^6";
+    else
+        return "^7";
+}
+
+// decolorizes and team colors the player name when needed
+string playername(string thename, float teamid)
+{
+    string t;
+    if (teamplay)
+    {
+        t = Team_ColorCode(teamid);
+        return strcat(t, strdecolorize(thename));
+    }
+    else
+        return strdecolorize(thename);
+}
+
 float cvar_or(string cv, float v)
 {
 	string s;
diff --git a/qcsrc/client/progs.src b/qcsrc/client/progs.src
index ba35ee2a9..4219eef16 100644
--- a/qcsrc/client/progs.src
+++ b/qcsrc/client/progs.src
@@ -29,6 +29,7 @@ movetypes.qh
 prandom.qh
 bgmscript.qh
 noise.qh
+teamplay.qh
 
 main.qh
 
diff --git a/qcsrc/client/shownames.qc b/qcsrc/client/shownames.qc
index 66391197a..5cbcfcea4 100644
--- a/qcsrc/client/shownames.qc
+++ b/qcsrc/client/shownames.qc
@@ -111,6 +111,9 @@ void Draw_ShowNames()
 
             string s;
             s = GetPlayerName(self.the_entnum-1);
+            if((autocvar_hud_shownames_decolorize == 1 && teamplay) || autocvar_hud_shownames_decolorize == 2)
+                s = playername(s, GetPlayerColor(self.the_entnum-1));
+
             drawfontscale = '1 1 0' * resize;
             s = textShortenToWidth(s, namesize, '1 1 0' * autocvar_hud_shownames_fontsize, stringwidth_colors);
 
diff --git a/qcsrc/client/teamplay.qc b/qcsrc/client/teamplay.qc
index 7d5031fb8..0c52f29d0 100644
--- a/qcsrc/client/teamplay.qc
+++ b/qcsrc/client/teamplay.qc
@@ -1,6 +1,3 @@
-float teamplay;
-float myteam;
-
 float TeamByColor(float color)
 {
 	switch(color)
-- 
2.39.5