]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud.qh
Merge branch 'master' into Mario/lms_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qh
1 float panel_order[HUD_PANEL_NUM];
2 string hud_panelorder_prev;
3
4 float hud_draw_maximized;
5 float hud_panel_radar_maximized;
6
7 vector mousepos;
8 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
9 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
10 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
11 var float highlightedPanel = -1;
12 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
13
14 const float BORDER_MULTIPLIER = 0.25;
15 float scoreboard_bottom;
16 float weapon_accuracy[WEP_MAXCOUNT];
17
18 float complain_weapon;
19 string complain_weapon_name;
20 float complain_weapon_type;
21 float complain_weapon_time;
22
23 float ps_primary, ps_secondary;
24 float ts_primary, ts_secondary;
25
26 float last_switchweapon;
27 float last_activeweapon;
28 float weapontime;
29 float weaponprevtime;
30
31 float teamnagger;
32
33 float hud_configure_checkcollisions;
34 float hud_configure_prev;
35 noref vector hud_configure_gridSize; // fteqcc sucks
36 noref vector hud_configure_realGridSize; // fteqcc sucks
37
38 float hudShiftState;
39 const float S_SHIFT = 1;
40 const float S_CTRL = 2;
41 const float S_ALT = 4;
42
43 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
44 float menu_enabled_time;
45
46 float hud_fade_alpha;
47
48 string hud_skin_path;
49 string hud_skin_prev;
50
51 var vector progressbar_color;
52
53 var float highlightedPanel_backup = -1;
54 var vector panel_pos_backup;
55 var vector panel_size_backup;
56
57 var float highlightedPanel_copied = -1; //this is good only to know if there is something copied
58 var vector panel_size_copied;
59
60 var float hud_configure_active_panel; // this panel has recently referred the UpdateCvars macro
61 var string panel_name;
62 var float panel_enabled;
63 var vector panel_pos;
64 var vector panel_size;
65 var string panel_bg;
66 var string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
67 var vector panel_bg_color;
68 var string panel_bg_color_str;
69 var float panel_bg_color_team;
70 var string panel_bg_color_team_str;
71 var float panel_fg_alpha;
72 var float panel_bg_alpha;
73 var string panel_bg_alpha_str;
74 var float panel_bg_border;
75 var string panel_bg_border_str;
76 var float panel_bg_padding;
77 var string panel_bg_padding_str;
78
79 float current_player;
80
81 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
82 // ----------------------
83 // MACRO HELL STARTS HERE
84 // ----------------------
85 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
86
87 #define HUD_Panel_GetProgressBarColor(item) \
88                 progressbar_color = stov(cvar_string("hud_progressbar_" #item "_color"))
89 #define HUD_Panel_GetProgressBarColorForString(item) \
90 switch(item) {\
91         case "health": HUD_Panel_GetProgressBarColor(health); break;\
92         case "armor": HUD_Panel_GetProgressBarColor(armor); break;\
93         case "strength": HUD_Panel_GetProgressBarColor(strength); break;\
94         case "shield": HUD_Panel_GetProgressBarColor(shield); break;\
95         case "fuel": HUD_Panel_GetProgressBarColor(fuel); break;\
96         case "nexball": HUD_Panel_GetProgressBarColor(nexball); break;\
97         case "speed": HUD_Panel_GetProgressBarColor(speed); break;\
98         case "acceleration": HUD_Panel_GetProgressBarColor(acceleration); break;\
99         case "acceleration_neg": HUD_Panel_GetProgressBarColor(acceleration_neg); break;\
100 } ENDS_WITH_CURLY_BRACE
101
102 // Get value for panel_bg: if "" fetch default, else use panel_bg_str
103 // comment on last line of macro: // we probably want to see a background in config mode at all times...
104 #define HUD_Panel_GetBg()\
105 if(!autocvar__hud_configure && panel_bg_str == "0") {\
106         panel_bg = "0";\
107 } else {\
108         if(panel_bg_str == "") {\
109                 panel_bg_str = autocvar_hud_panel_bg;\
110         }\
111         if(panel_bg_str == "0" && !autocvar__hud_configure) {\
112                         panel_bg = "0";\
113         } else {\
114                 if (panel_bg_str == "0" && autocvar__hud_configure)\
115                         panel_bg_alpha_str = "0";\
116                 panel_bg = strcat(hud_skin_path, "/", panel_bg_str);\
117                 if(precache_pic(panel_bg) == "") {\
118                         panel_bg = strcat(hud_skin_path, "/", "border_default");\
119                         if(precache_pic(panel_bg) == "") {\
120                                 panel_bg = strcat("gfx/hud/default/", "border_default");\
121                         }\
122                 }\
123         }\
124 }
125
126 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
127 #define HUD_Panel_GetColor()\
128 if((teamplay) && panel_bg_color_team) {\
129         panel_bg_color = colormapPaletteColor(myteam, 1) * panel_bg_color_team;\
130 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) {\
131         panel_bg_color = '1 0 0' * panel_bg_color_team;\
132 } else {\
133         if(panel_bg_color_str == "") {\
134                 panel_bg_color = autocvar_hud_panel_bg_color;\
135         } else {\
136                 if(panel_bg_color_str == "shirt") {\
137                         panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player - 1, "colors")) / 16), 0);\
138                 } else if(panel_bg_color_str == "pants") {\
139                         panel_bg_color = colormapPaletteColor(mod(stof(getplayerkeyvalue(current_player - 1, "colors")), 16), 1);\
140                 } else {\
141                         panel_bg_color = stov(panel_bg_color_str);\
142                 }\
143         }\
144 }
145
146 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
147 #define HUD_Panel_GetColorTeam()\
148 if(panel_bg_color_team_str == "") {\
149         panel_bg_color_team = autocvar_hud_panel_bg_color_team;\
150 } else {\
151         panel_bg_color_team = stof(panel_bg_color_team_str);\
152 }
153
154 // the check doesn't allow to fade this panel when showing the panel-specific menu dialog
155 #define HUD_Panel_ApplyFadeAlpha()\
156 if(!(menu_enabled == 2 && highlightedPanel == hud_configure_active_panel))\
157 {\
158         panel_bg_alpha *= hud_fade_alpha;\
159         panel_fg_alpha *= hud_fade_alpha;\
160 } ENDS_WITH_CURLY_BRACE
161
162 // Get value for panel_bg_alpha: if "" fetch default, else use panel_bg_alpha. Also do various menu dialog fadeout/in checks, and minalpha checks
163 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
164 #define HUD_Panel_GetBgAlpha()\
165 if(panel_bg_alpha_str == "") {\
166         panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);\
167 }\
168 panel_bg_alpha = stof(panel_bg_alpha_str);\
169 if(autocvar__hud_configure) {\
170         if(!panel_enabled)\
171                 panel_bg_alpha = 0.25;\
172         else if(menu_enabled == 2 && highlightedPanel == hud_configure_active_panel)\
173                 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
174         else\
175                 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha);\
176 }
177
178 // Get value for panel_fg_alpha. Also do various minalpha checks
179 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
180 #define HUD_Panel_GetFgAlpha()\
181 panel_fg_alpha = autocvar_hud_panel_fg_alpha;\
182 if(autocvar__hud_configure && !panel_enabled)\
183         panel_fg_alpha = 0.25;\
184
185 // Get border. See comments above, it's similar.
186 #define HUD_Panel_GetBorder()\
187 if(panel_bg_border_str == "") {\
188         panel_bg_border = autocvar_hud_panel_bg_border;\
189 } else {\
190         panel_bg_border = stof(panel_bg_border_str);\
191 } ENDS_WITH_CURLY_BRACE
192
193 // Scale the pos and size vectors to absolute coordinates
194 #define HUD_Panel_GetScaledVectors()\
195 panel_pos_x *= vid_conwidth;\
196 panel_pos_y *= vid_conheight;\
197 panel_size_x *= vid_conwidth;\
198 panel_size_y *= vid_conheight;
199
200 // Get padding. See comments above, it's similar.
201 // last line is a port of the old function, basically always make sure the panel contents are at least 5 pixels tall/wide, to disallow extreme padding values
202 #define HUD_Panel_GetPadding()\
203 if(panel_bg_padding_str == "") {\
204         panel_bg_padding = autocvar_hud_panel_bg_padding;\
205 } else {\
206         panel_bg_padding = stof(panel_bg_padding_str);\
207 }\
208 panel_bg_padding = min(min(panel_size_x, panel_size_y)/2 - 5, panel_bg_padding);
209
210 // Point to the macros above (stupid max macro length)
211 #define HUD_Panel_GetStringVars()\
212 HUD_Panel_GetBg()\
213 if (panel_bg != "0") {\
214         HUD_Panel_GetColorTeam()\
215         HUD_Panel_GetColor()\
216         HUD_Panel_GetBgAlpha()\
217         HUD_Panel_GetBorder()\
218 }\
219 HUD_Panel_GetFgAlpha()\
220 HUD_Panel_GetScaledVectors()\
221 HUD_Panel_GetPadding()
222
223 // return smoothly faded pos of given panel when a dialog is active
224 var vector menu_enable_panelpos;
225 #define HUD_Panel_GetMenuPos() \
226 if(panel_size_x > panel_size_y)\
227         menu_enable_panelpos = eX * 0.5 * vid_conwidth - eX * 0.5 * panel_size_x + eY * 0.82 * vid_conheight;\
228 else\
229         menu_enable_panelpos = eY * 0.5 * vid_conheight - eY * 0.5 * panel_size_y + eX * 0.7 * vid_conwidth;\
230 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_panelpos;
231
232 // return smoothly faded size of given panel when a dialog is active
233 //var vector menu_enable_maxsize;
234 var float menu_enable_maxsize_x;
235 var float menu_enable_maxsize_y;
236 var vector menu_enable_size;
237 #define HUD_Panel_GetMenuSize()\
238 menu_enable_maxsize_x = 0.3 * vid_conwidth;\
239 menu_enable_maxsize_y = 0.18 * vid_conheight;\
240 if(panel_size_x > panel_size_y)\
241 {\
242         if(panel_size_y > menu_enable_maxsize_y)\
243         {\
244                 menu_enable_size_y = menu_enable_maxsize_y;\
245                 menu_enable_size_x = panel_size_x * (menu_enable_maxsize_y/panel_size_y);\
246                 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
247         }\
248 }\
249 else\
250 {\
251         if(panel_size_x > menu_enable_maxsize_x)\
252         {\
253                 menu_enable_size_x = menu_enable_maxsize_x;\
254                 menu_enable_size_y = panel_size_y * (menu_enable_maxsize_x/panel_size_x);\
255                 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
256         }\
257 }
258
259 // Update all common cvars of given panel name
260 #define HUD_Panel_UpdateCvars(name) \
261 panel_enabled = autocvar_hud_panel_##name; \
262 panel_pos = stov(cvar_string("hud_panel_" #name "_pos")); \
263 panel_size = stov(cvar_string("hud_panel_" #name "_size")); \
264 panel_bg_str = cvar_string("hud_panel_" #name "_bg"); \
265 panel_bg_color_str = cvar_string("hud_panel_" #name "_bg_color"); \
266 panel_bg_color_team_str = cvar_string("hud_panel_" #name "_bg_color_team"); \
267 panel_bg_alpha_str = cvar_string("hud_panel_" #name "_bg_alpha"); \
268 panel_bg_border_str = cvar_string("hud_panel_" #name "_bg_border"); \
269 panel_bg_padding_str = cvar_string("hud_panel_" #name "_bg_padding"); \
270 HUD_Panel_GetStringVars()\
271 if(menu_enabled == 2 && hud_configure_active_panel == highlightedPanel) {\
272         HUD_Panel_GetMenuSize()\
273         HUD_Panel_GetMenuPos()\
274 } ENDS_WITH_CURLY_BRACE
275
276 // FTEQCC I HATE YOU WHY DO YOU MAKE ME DO THIS??? :(
277 // max macro length is 1024 characters, I must split it up :(
278
279 // Update all common cvars of given panel id
280 #define HUD_Panel_UpdateCvarsForId_Part2(id) \
281 switch(id) { \
282         case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdateCvars(infomessages) break; \
283         case HUD_PANEL_PHYSICS: HUD_Panel_UpdateCvars(physics); break;\
284         case HUD_PANEL_CENTERPRINT: HUD_Panel_UpdateCvars(centerprint); break;\
285 }
286
287 #define HUD_Panel_UpdateCvarsForId(id) \
288 switch(id) { \
289         case HUD_PANEL_WEAPONS: HUD_Panel_UpdateCvars(weapons) break; \
290         case HUD_PANEL_AMMO: HUD_Panel_UpdateCvars(ammo) break; \
291         case HUD_PANEL_POWERUPS: HUD_Panel_UpdateCvars(powerups) break; \
292         case HUD_PANEL_HEALTHARMOR: HUD_Panel_UpdateCvars(healtharmor) break; \
293         case HUD_PANEL_NOTIFY: HUD_Panel_UpdateCvars(notify) break; \
294         case HUD_PANEL_TIMER: HUD_Panel_UpdateCvars(timer) break; \
295         case HUD_PANEL_RADAR: HUD_Panel_UpdateCvars(radar) break; \
296         case HUD_PANEL_SCORE: HUD_Panel_UpdateCvars(score) break; \
297         case HUD_PANEL_RACETIMER: HUD_Panel_UpdateCvars(racetimer) break; \
298         case HUD_PANEL_VOTE: HUD_Panel_UpdateCvars(vote) break; \
299         case HUD_PANEL_MODICONS: HUD_Panel_UpdateCvars(modicons) break; \
300         case HUD_PANEL_PRESSEDKEYS: HUD_Panel_UpdateCvars(pressedkeys) break; \
301         case HUD_PANEL_CHAT: HUD_Panel_UpdateCvars(chat) break; \
302         case HUD_PANEL_ENGINEINFO: HUD_Panel_UpdateCvars(engineinfo) break; \
303         default: HUD_Panel_UpdateCvarsForId_Part2(id)\
304 }
305
306 #define HUD_Panel_UpdatePosSize(name) \
307 panel_pos = stov(cvar_string("hud_panel_" #name "_pos")); \
308 panel_size = stov(cvar_string("hud_panel_" #name "_size")); \
309 HUD_Panel_GetScaledVectors()\
310 if(menu_enabled == 2 && hud_configure_active_panel == highlightedPanel) {\
311         HUD_Panel_GetMenuSize()\
312         HUD_Panel_GetMenuPos()\
313 }\
314 panel_bg_border_str = cvar_string("hud_panel_" #name "_bg_border"); \
315 HUD_Panel_GetBorder()
316
317 // Update pos and size of given panel id
318 #define HUD_Panel_UpdatePosSizeForId_Part2(id) \
319 switch(id) { \
320         case HUD_PANEL_INFOMESSAGES: HUD_Panel_UpdatePosSize(infomessages) break;\
321         case HUD_PANEL_PHYSICS: HUD_Panel_UpdatePosSize(physics); break;\
322         case HUD_PANEL_CENTERPRINT: HUD_Panel_UpdatePosSize(centerprint); break;\
323 }
324
325 #define HUD_Panel_UpdatePosSizeForId(id) \
326 switch(id) { \
327         case HUD_PANEL_WEAPONS: HUD_Panel_UpdatePosSize(weapons) break;\
328         case HUD_PANEL_AMMO: HUD_Panel_UpdatePosSize(ammo) break;\
329         case HUD_PANEL_POWERUPS: HUD_Panel_UpdatePosSize(powerups) break;\
330         case HUD_PANEL_HEALTHARMOR: HUD_Panel_UpdatePosSize(healtharmor) break;\
331         case HUD_PANEL_NOTIFY: HUD_Panel_UpdatePosSize(notify) break;\
332         case HUD_PANEL_TIMER: HUD_Panel_UpdatePosSize(timer) break;\
333         case HUD_PANEL_RADAR: HUD_Panel_UpdatePosSize(radar) break;\
334         case HUD_PANEL_SCORE: HUD_Panel_UpdatePosSize(score) break;\
335         case HUD_PANEL_RACETIMER: HUD_Panel_UpdatePosSize(racetimer) break;\
336         case HUD_PANEL_VOTE: HUD_Panel_UpdatePosSize(vote) break;\
337         case HUD_PANEL_MODICONS: HUD_Panel_UpdatePosSize(modicons) break;\
338         case HUD_PANEL_PRESSEDKEYS: HUD_Panel_UpdatePosSize(pressedkeys) break;\
339         case HUD_PANEL_CHAT: HUD_Panel_UpdatePosSize(chat) break;\
340         case HUD_PANEL_ENGINEINFO: HUD_Panel_UpdatePosSize(engineinfo) break;\
341         default: HUD_Panel_UpdatePosSizeForId_Part2(id)\
342 }
343
344 #define KN_MAX_ENTRIES 10
345
346 float kn_index;
347 float notify_times[KN_MAX_ENTRIES];
348 string notify_icon[KN_MAX_ENTRIES];
349 string notify_attackers[KN_MAX_ENTRIES];
350 string notify_victims[KN_MAX_ENTRIES];
351 void HUD_Notify_Push(string icon, string attacker, string victim);