Skip to content

Commit 897a994

Browse files
committed
CLIENT: Add accessibility setting for colorblind-safe(r) player colors
1 parent 159dc3a commit 897a994

4 files changed

Lines changed: 93 additions & 22 deletions

File tree

source/client/hud.qc

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,72 @@ string(string img) getImage = {
4545
return strcat(huddir, img);
4646
}
4747

48+
//
49+
// HUD_ResolveTextColorForPlayer(index)
50+
// Returns the color as a vector to use for a
51+
// player of the given index.
52+
//
53+
vector(float index) HUD_ResolveTextColorForPlayer =
54+
{
55+
switch(index) {
56+
case 0:
57+
// White.
58+
return '1 1 1';
59+
case 1:
60+
// Light Blue.
61+
if (cvar("cl_colorblind")) {
62+
return '0.39 0.76 0.93';
63+
} else {
64+
return '0 0.46 0.70';
65+
}
66+
case 2:
67+
// Orange.
68+
if (cvar("cl_colorblind")) {
69+
return '0.93 0.42 0';
70+
} else {
71+
return '0.92 0.74 0';
72+
}
73+
case 3:
74+
// Green.
75+
if (cvar("cl_colorblind")) {
76+
return '0 0.69 0.52';
77+
} else {
78+
return '0 0.90 0.13';
79+
}
80+
case 4:
81+
// Salmon Pink.
82+
if (cvar("cl_colorblind")) {
83+
return '1 0.46 0.54';
84+
} else {
85+
return '1 0.57 0.64';
86+
}
87+
case 5:
88+
// Magenta.
89+
if (cvar("cl_colorblind")) {
90+
return '0.73 0.29 0.54';
91+
} else {
92+
return '0.80 0.20 0.55';
93+
}
94+
case 6:
95+
// Cyan.
96+
if (cvar("cl_colorblind")) {
97+
return '0.36 0.84 0.96';
98+
} else {
99+
return '0.42 0.82 0.82';
100+
}
101+
case 7:
102+
// Yellow.
103+
if (cvar("cl_colorblind")) {
104+
return '0.86 0.78 0.25';
105+
} else {
106+
return '1 0.87 0.13';
107+
}
108+
default:
109+
// White.
110+
return '1 1 1';
111+
}
112+
};
113+
48114
//
49115
// HUD_GetAlphaForWeaponObjects()
50116
// Used for objects on the ammo-corner, where
@@ -336,20 +402,15 @@ void() HUD_Points =
336402
float backwidth = 0.8*g_width;
337403
vector TEXTCOLOR = '0 0 0';
338404

339-
for (int i = 3; i >= 0; i = i - 1)
405+
for (int i = 7; i >= 0; i = i - 1)
340406
{
341407
float player_number = getplayerkeyfloat(i, "client_index");
342408
entity client = findfloat(world, playernum, player_number);
343409

344410
if ((client == world || !client.classname) && !client.is_spectator)
345411
continue;
346412

347-
switch(i) {
348-
case 1: TEXTCOLOR = TEXT_LIGHTBLUE; break;
349-
case 2: TEXTCOLOR = TEXT_ORANGE; break;
350-
case 3: TEXTCOLOR = TEXT_GREEN; break;
351-
default: TEXTCOLOR = [1, 1, 1]; break;
352-
}
413+
TEXTCOLOR = HUD_ResolveTextColorForPlayer(i);
353414

354415
pointwidth = getTextWidth(ftos(client.points), 12);
355416
x = (99 - pointwidth)/2 + GetUltraWideOffset();
@@ -1657,12 +1718,7 @@ void() HUD_Scores =
16571718
if ((client == world || !client.classname) && !client.is_spectator)
16581719
continue;
16591720

1660-
switch(i) {
1661-
case 1: TEXTCOLOR = TEXT_LIGHTBLUE; break;
1662-
case 2: TEXTCOLOR = TEXT_ORANGE; break;
1663-
case 3: TEXTCOLOR = TEXT_GREEN; break;
1664-
default: TEXTCOLOR = [1, 1, 1]; break;
1665-
}
1721+
TEXTCOLOR = HUD_ResolveTextColorForPlayer(i);
16661722

16671723
float y_pos = (scoreboard_text_size + 5) * i;
16681724

@@ -1990,7 +2046,7 @@ void() HUD_Spectator =
19902046

19912047
void() HUD_PlayerNames =
19922048
{
1993-
for (float i = 3; i >= 0; i = i - 1) {
2049+
for (float i = 7; i >= 0; i = i - 1) {
19942050
float player_number = getplayerkeyfloat(i, "client_index");
19952051

19962052
if (player_number == getstatf(STAT_PLAYERNUM))
@@ -2018,13 +2074,7 @@ void() HUD_PlayerNames =
20182074
continue;
20192075

20202076
screen_position_x -= getTextWidth(text, 8)/2;
2021-
2022-
switch(i) {
2023-
case 1: text_color = TEXT_LIGHTBLUE; break;
2024-
case 2: text_color = TEXT_ORANGE; break;
2025-
case 3: text_color = TEXT_GREEN; break;
2026-
default: break;
2027-
}
2077+
text_color = HUD_ResolveTextColorForPlayer(i);
20282078

20292079
if (screen_position_z > 0) {
20302080
HUD_DrawStringWithBackdrop(screen_position, text, [8, 8], text_color, 1, 0);

source/client/main.qc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ noref void(float apiver, string enginename, float enginever) CSQC_Init =
163163
autocvar(in_aimassist, 0);
164164
autocvar(cl_hitmarkers, 1);
165165
autocvar(cl_textopacity, 0.20);
166+
autocvar(cl_colorblind, 0);
166167

167168
autocvar(scr_playerdebuginfo, 0);
168169
autocvar(scr_playerdebuginfo_x, 64);

source/menu/main.qc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ void() m_init =
220220
autocvar(vid_ultrawide_limiter, 0);
221221
autocvar(cl_hitmarkers, 1);
222222
autocvar(cl_textopacity, 0.20);
223+
autocvar(cl_colorblind, 0);
223224

224225
music_duration_time = 0;
225226
menu_changetime = 0;

source/menu/menu_aces.qc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
string menu_accesibility_buttons[4] = {"ac_hitm", "ac_text", "ac_apply", "ac_back"};
1+
string menu_accesibility_buttons[5] = {"ac_hitm", "ac_text", "ac_color", "ac_apply", "ac_back"};
22

33
float menu_accessibility_init;
44

55
float current_hitmarker;
6+
float current_colorblind;
67

78
string(string prev_id) Menu_Accessibility_GetNextButton =
89
{
@@ -47,6 +48,7 @@ string(string next_id) Menu_Accessibility_GetPreviousButton =
4748
void() Menu_Accessibility_StoreCurrentSettings =
4849
{
4950
current_hitmarker = cvar("cl_hitmarkers");
51+
current_colorblind = cvar("cl_colorblind");
5052
}
5153

5254
void() Menu_Accessibility_ApplySettings =
@@ -68,6 +70,13 @@ void() Menu_Accessibility_UpdateHitmarkers =
6870
cvar_set("cl_hitmarkers", ftos(current_hitmarker));
6971
};
7072

73+
void() Menu_Accessibility_UpdateColorblindFilter =
74+
{
75+
Menu_PlaySound(MENU_SND_ENTER);
76+
current_colorblind = !current_colorblind;
77+
cvar_set("cl_colorblind", ftos(current_colorblind));
78+
}
79+
7180
void() Menu_Accessibility =
7281
{
7382
if (!menu_accessibility_init)
@@ -90,6 +99,16 @@ void() Menu_Accessibility =
9099
Menu_Button(2, "ac_text", "TEXT BACKDROP", "Opacity of backdrop for text elements on HUD.") ? 0 : 0;
91100
Menu_CvarSlider(2, [0, 1, 20], "cl_textopacity", false, false);
92101

102+
// Accessible Colors
103+
Menu_Button(3, "ac_color", "ACCESSIBLE COLORS", "Uses enhanced Player colors to improve visibilty.") ? Menu_Accessibility_UpdateColorblindFilter() : 0;
104+
string colorblind_string = "";
105+
switch(current_colorblind) {
106+
case 0: colorblind_string = "DISABLED"; break;
107+
case 1: colorblind_string = "ENABLED"; break;
108+
default: break;
109+
}
110+
Menu_DrawOptionValue(3, colorblind_string);
111+
93112
Menu_DrawDivider(12.25);
94113
Menu_Button(-2, "ac_apply", "APPLY", "Save & Apply Settings.") ? Menu_Accessibility_ApplySettings() : 0;
95114
Menu_Button(-1, "ac_back", "BACK", "Return to Configuration Menu.") ? current_menu = MENU_OPTIONS : 0;

0 commit comments

Comments
 (0)