Debian Codegraph @

prboom2/src/dsda/text_color.c

raw
1 //
2 // Copyright(C) 2023 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Text Color
16 //
17
18 #include "doomdef.h"
19 #include "hu_lib.h"
20 #include "lprintf.h"
21 #include "w_wad.h"
22 #include "v_video.h"
23
24 #include "dsda/utility.h"
25
26 #include "text_color.h"
27
28 typedef struct {
29 const char* key;
30 int color_range;
31 char color_str[3];
32 } dsda_text_color_t;
33
34 dsda_text_color_t dsda_text_colors[] = {
35 [dsda_tc_exhud_time_label] = { "exhud_time_label", CR_GRAY },
36 [dsda_tc_exhud_level_time] = { "exhud_level_time", CR_GREEN },
37 [dsda_tc_exhud_total_time] = { "exhud_total_time", CR_GOLD },
38 [dsda_tc_exhud_demo_length] = { "exhud_demo_length", CR_BROWN },
39 [dsda_tc_exhud_armor_zero] = { "exhud_armor_zero", CR_GRAY },
40 [dsda_tc_exhud_armor_one] = { "exhud_armor_one", CR_GREEN },
41 [dsda_tc_exhud_armor_two] = { "exhud_armor_two", CR_LIGHTBLUE },
42 [dsda_tc_exhud_command_entry] = { "exhud_command_entry", CR_GRAY },
43 [dsda_tc_exhud_command_queue] = { "exhud_command_queue", CR_GOLD },
44 [dsda_tc_exhud_coords_base] = { "exhud_coords_base", CR_GREEN },
45 [dsda_tc_exhud_coords_mf50] = { "exhud_coords_mf50", CR_GRAY },
46 [dsda_tc_exhud_coords_sr40] = { "exhud_coords_sr40", CR_GREEN },
47 [dsda_tc_exhud_coords_sr50] = { "exhud_coords_sr50", CR_LIGHTBLUE },
48 [dsda_tc_exhud_coords_fast] = { "exhud_coords_fast", CR_RED },
49 [dsda_tc_exhud_fps_bad] = { "exhud_fps_bad", CR_RED },
50 [dsda_tc_exhud_fps_fine] = { "exhud_fps_fine", CR_GRAY },
51 [dsda_tc_exhud_health_bad] = { "exhud_health_bad", CR_RED },
52 [dsda_tc_exhud_health_warning] = { "exhud_health_warning", CR_GOLD },
53 [dsda_tc_exhud_health_ok] = { "exhud_health_ok", CR_GREEN },
54 [dsda_tc_exhud_health_super] = { "exhud_health_super", CR_LIGHTBLUE },
55 [dsda_tc_exhud_line_close] = { "exhud_line_close", CR_GREEN },
56 [dsda_tc_exhud_line_far] = { "exhud_line_far", CR_GRAY },
57 [dsda_tc_exhud_line_special] = { "exhud_line_special", CR_GREEN },
58 [dsda_tc_exhud_line_normal] = { "exhud_line_normal", CR_GRAY },
59 [dsda_tc_exhud_mobj_alive] = { "exhud_mobj_alive", CR_GREEN },
60 [dsda_tc_exhud_mobj_dead] = { "exhud_mobj_dead", CR_GRAY },
61 [dsda_tc_exhud_player_damage] = { "exhud_player_damage", CR_GREEN },
62 [dsda_tc_exhud_player_neutral] = { "exhud_player_neutral", CR_GRAY },
63 [dsda_tc_exhud_ammo_label] = { "exhud_ammo_label", CR_GRAY },
64 [dsda_tc_exhud_ammo_mana1] = { "exhud_ammo_mana1", CR_LIGHTBLUE },
65 [dsda_tc_exhud_ammo_mana2] = { "exhud_ammo_mana2", CR_GREEN },
66 [dsda_tc_exhud_ammo_value] = { "exhud_ammo_value", CR_GRAY },
67 [dsda_tc_exhud_ammo_bad] = { "exhud_ammo_bad", CR_RED },
68 [dsda_tc_exhud_ammo_warning] = { "exhud_ammo_warning", CR_GOLD },
69 [dsda_tc_exhud_ammo_ok] = { "exhud_ammo_ok", CR_GREEN },
70 [dsda_tc_exhud_ammo_full] = { "exhud_ammo_full", CR_LIGHTBLUE },
71 [dsda_tc_exhud_render_label] = { "exhud_render_label", CR_GRAY },
72 [dsda_tc_exhud_render_good] = { "exhud_render_good", CR_GOLD },
73 [dsda_tc_exhud_render_bad] = { "exhud_render_bad", CR_RED },
74 [dsda_tc_exhud_sector_active] = { "exhud_sector_active", CR_RED },
75 [dsda_tc_exhud_sector_special] = { "exhud_sector_special", CR_GREEN },
76 [dsda_tc_exhud_sector_normal] = { "exhud_sector_normal", CR_GRAY },
77 [dsda_tc_exhud_speed_label] = { "exhud_speed_label", CR_GRAY },
78 [dsda_tc_exhud_speed_slow] = { "exhud_speed_slow", CR_GOLD },
79 [dsda_tc_exhud_speed_normal] = { "exhud_speed_normal", CR_GREEN },
80 [dsda_tc_exhud_speed_fast] = { "exhud_speed_fast", CR_LIGHTBLUE },
81 [dsda_tc_exhud_totals_label] = { "exhud_totals_label", CR_RED },
82 [dsda_tc_exhud_totals_value] = { "exhud_totals_value", CR_GOLD },
83 [dsda_tc_exhud_totals_max] = { "exhud_totals_max", CR_LIGHTBLUE },
84 [dsda_tc_exhud_weapon_label] = { "exhud_weapon_label", CR_GRAY },
85 [dsda_tc_exhud_weapon_owned] = { "exhud_weapon_owned", CR_GREEN },
86 [dsda_tc_exhud_weapon_berserk] = { "exhud_weapon_berserk", CR_LIGHTBLUE },
87 [dsda_tc_exhud_attempts] = { "exhud_attempts", CR_GRAY },
88 [dsda_tc_exhud_event_split] = { "exhud_event_split", CR_GRAY },
89 [dsda_tc_exhud_line_activation] = { "exhud_line_activation", CR_GRAY },
90 [dsda_tc_exhud_local_time] = { "exhud_local_time", CR_GRAY },
91 [dsda_tc_exhud_free_text] = { "exhud_free_text", CR_GRAY },
92 [dsda_tc_hud_message] = { "hud_message", CR_DEFAULT },
93 [dsda_tc_hud_secret_message] = { "hud_secret_message", CR_GOLD },
94 [dsda_tc_map_coords] = { "map_coords", CR_GREEN },
95 [dsda_tc_map_time_level] = { "map_time_level", CR_GRAY },
96 [dsda_tc_map_time_total] = { "map_time_total", CR_GRAY },
97 [dsda_tc_map_title] = { "map_title", CR_GOLD },
98 [dsda_tc_map_totals_label] = { "map_totals_label", CR_RED },
99 [dsda_tc_map_totals_value] = { "map_totals_value", CR_GRAY },
100 [dsda_tc_map_totals_max] = { "map_totals_max", CR_LIGHTBLUE },
101 [dsda_tc_inter_split_normal] = { "inter_split_normal", CR_GRAY },
102 [dsda_tc_inter_split_good] = { "inter_split_good", CR_GREEN },
103 [dsda_tc_inter_split_best] = { "inter_split_best", CR_GOLD },
104 [dsda_tc_menu_title] = { "menu_title", CR_GOLD },
105 [dsda_tc_menu_tab] = { "menu_tab", CR_TAN },
106 [dsda_tc_menu_tab_highlight] = { "menu_tab_highlight", CR_GOLD },
107 [dsda_tc_menu_label] = { "menu_label", CR_RED },
108 [dsda_tc_menu_label_highlight] = { "menu_label_highlight", CR_BRICK },
109 [dsda_tc_menu_label_edit] = { "menu_label_edit", CR_GRAY },
110 [dsda_tc_menu_value] = { "menu_value", CR_GREEN },
111 [dsda_tc_menu_value_highlight] = { "menu_value_highlight", CR_BRICK },
112 [dsda_tc_menu_value_edit] = { "menu_value_edit", CR_GRAY },
113 [dsda_tc_menu_info_highlight] = { "menu_info_highlight", CR_BRICK },
114 [dsda_tc_menu_info_edit] = { "menu_info_edit", CR_GRAY },
115 [dsda_tc_menu_warning] = { "menu_warning", CR_RED },
116 [dsda_tc_menu_scrollbar] = { "menu_scrollbar", CR_TAN },
117 [dsda_tc_stbar_health_bad] = { "stbar_health_bad", CR_RED },
118 [dsda_tc_stbar_health_warning] = { "stbar_health_warning", CR_GOLD },
119 [dsda_tc_stbar_health_ok] = { "stbar_health_ok", CR_GREEN },
120 [dsda_tc_stbar_health_super] = { "stbar_health_super", CR_BLUE },
121 [dsda_tc_stbar_armor_zero] = { "stbar_armor_zero", CR_GRAY },
122 [dsda_tc_stbar_armor_one] = { "stbar_armor_one", CR_GREEN },
123 [dsda_tc_stbar_armor_two] = { "stbar_armor_two", CR_BLUE },
124 [dsda_tc_stbar_ammo_bad] = { "stbar_ammo_bad", CR_RED },
125 [dsda_tc_stbar_ammo_warning] = { "stbar_ammo_warning", CR_GOLD },
126 [dsda_tc_stbar_ammo_ok] = { "stbar_ammo_ok", CR_GREEN },
127 [dsda_tc_stbar_ammo_full] = { "stbar_ammo_full", CR_BLUE },
128 { NULL },
129 };
130
131 const char* dsda_TextColor(dsda_text_color_index_t i) {
132 return dsda_text_colors[i].color_str;
133 }
134
135 int dsda_TextCR(dsda_text_color_index_t i) {
136 return dsda_text_colors[i].color_range;
137 }
138
139 void dsda_LoadTextColor(void) {
140 char* lump;
141 char** lines;
142 const char* line;
143 int line_i;
144 int color_range;
145 char key[33] = { 0 };
146 dsda_text_color_t* p;
147
148 lump = W_ReadLumpToString(W_GetNumForName("DSDATC"));
149
150 lines = dsda_SplitString(lump, "\n\r");
151
152 for (line_i = 0; lines[line_i]; ++line_i) {
153 line = lines[line_i];
154
155 if (!line[0] || line[0] == '/')
156 continue;
157
158 if (sscanf(line, "%32s %d", key, &color_range) != 2)
159 I_Error("DSDATC lump has unknown format! (%s)", line);
160
161 for (p = dsda_text_colors; p->key; p++)
162 if (!strcasecmp(key, p->key)) {
163 p->color_range = color_range;
164 break;
165 }
166
167 if (!p->key)
168 I_Error("DSDATC lump has unknown key %s!", key);
169 }
170
171 for (p = dsda_text_colors; p->key; p++) {
172 p->color_str[0] = '\x1b';
173 p->color_str[1] = HUlib_Color(p->color_range);
174 }
175
176 Z_Free(lines);
177 Z_Free(lump);
178 }
179
180 static const char* color_name_to_index[CR_HUD_LIMIT] = {
181 "",
182 "brick",
183 "tan",
184 "gray",
185 "green",
186 "brown",
187 "gold",
188 "red",
189 "blue",
190 "orange",
191 "yellow",
192 "light blue",
193 "black",
194 "purple",
195 "white",
196 };
197
198 int dsda_ColorNameToIndex(const char* name) {
199 int i;
200
201 if (!name)
202 return CR_DEFAULT;
203
204 for (i = CR_DEFAULT + 1; i < CR_HUD_LIMIT; ++i)
205 if (!stricmp(color_name_to_index[i], name))
206 return i;
207
208 return CR_DEFAULT;
209 }