1 #define HUD_PANEL_MAX 24
2 entity hud_panel[HUD_PANEL_MAX];
3 #define HUD_PANEL_FIRST 0
7 float panel_order[HUD_PANEL_MAX];
8 string hud_panelorder_prev;
10 float hud_draw_maximized;
11 float hud_panel_radar_maximized;
14 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
15 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
16 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
17 entity highlightedPanel;
18 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
20 const float BORDER_MULTIPLIER = 0.25;
21 float scoreboard_bottom;
22 float weapon_accuracy[WEP_MAXCOUNT];
24 float complain_weapon;
25 string complain_weapon_name;
26 float complain_weapon_type;
27 float complain_weapon_time;
29 float ps_primary, ps_secondary;
30 float ts_primary, ts_secondary;
32 float last_switchweapon;
33 float last_activeweapon;
39 float hud_configure_checkcollisions;
40 float hud_configure_prev;
41 noref vector hud_configure_gridSize; // fteqcc sucks
42 noref vector hud_configure_realGridSize; // fteqcc sucks
45 const float S_SHIFT = 1;
46 const float S_CTRL = 2;
47 const float S_ALT = 4;
49 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
50 float menu_enabled_time;
59 var vector progressbar_color;
61 entity highlightedPanel_backup;
62 var vector panel_pos_backup;
63 var vector panel_size_backup;
65 var vector panel_size_copied;
70 .vector current_panel_pos;
71 .vector current_panel_size;
72 .string current_panel_bg;
73 .float current_panel_bg_alpha;
74 .float current_panel_bg_border;
75 .vector current_panel_bg_color;
76 .float current_panel_bg_color_team;
77 .float current_panel_bg_padding;
78 .float current_panel_fg_alpha;
80 var float panel_enabled;
82 var vector panel_size;
84 var string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
85 var vector panel_bg_color;
86 var string panel_bg_color_str;
87 var float panel_bg_color_team;
88 var string panel_bg_color_team_str;
89 var float panel_fg_alpha;
90 var float panel_bg_alpha;
91 var string panel_bg_alpha_str;
92 var float panel_bg_border;
93 var string panel_bg_border_str;
94 var float panel_bg_padding;
95 var string panel_bg_padding_str;
103 HUD_PANEL(WEAPONS , HUD_Weapons , weapons) \
104 HUD_PANEL(AMMO , HUD_Ammo , ammo) \
105 HUD_PANEL(POWERUPS , HUD_Powerups , powerups) \
106 HUD_PANEL(HEALTHARMOR , HUD_HealthArmor , healtharmor) \
107 HUD_PANEL(NOTIFY , HUD_Notify , notify) \
108 HUD_PANEL(TIMER , HUD_Timer , timer) \
109 HUD_PANEL(RADAR , HUD_Radar , radar) \
110 HUD_PANEL(SCORE , HUD_Score , score) \
111 HUD_PANEL(RACETIMER , HUD_RaceTimer , racetimer) \
112 HUD_PANEL(VOTE , HUD_Vote , vote) \
113 HUD_PANEL(MODICONS , HUD_ModIcons , modicons) \
114 HUD_PANEL(PRESSEDKEYS , HUD_PressedKeys , pressedkeys) \
115 HUD_PANEL(CHAT , HUD_Chat , chat) \
116 HUD_PANEL(ENGINEINFO , HUD_EngineInfo , engineinfo) \
117 HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages) \
118 HUD_PANEL(PHYSICS , HUD_Physics , physics) \
119 HUD_PANEL(CENTERPRINT , HUD_CenterPrint , centerprint)
121 #define HUD_PANEL(NAME,draw_func,name) \
122 float HUD_PANEL_##NAME; \
123 void ##draw_func(void); \
124 void RegisterHUD_Panel_##NAME() \
126 HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM; \
127 entity hud_panelent = spawn(); \
128 hud_panel[HUD_PANEL_##NAME] = hud_panelent; \
129 hud_panelent.classname = "hud_panel"; \
130 hud_panelent.panel_name = #name; \
131 hud_panelent.panel_id = HUD_PANEL_##NAME; \
132 hud_panelent.panel_draw = ##draw_func; \
135 ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME);
140 #define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
143 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
144 // ----------------------
145 // MACRO HELL STARTS HERE
146 // ----------------------
147 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
149 #define HUD_Panel_GetProgressBarColor(item) \
150 progressbar_color = stov(cvar_string("hud_progressbar_" #item "_color"))
151 #define HUD_Panel_GetProgressBarColorForString(item) \
153 case "health": HUD_Panel_GetProgressBarColor(health); break;\
154 case "armor": HUD_Panel_GetProgressBarColor(armor); break;\
155 case "strength": HUD_Panel_GetProgressBarColor(strength); break;\
156 case "shield": HUD_Panel_GetProgressBarColor(shield); break;\
157 case "fuel": HUD_Panel_GetProgressBarColor(fuel); break;\
158 case "nexball": HUD_Panel_GetProgressBarColor(nexball); break;\
159 case "speed": HUD_Panel_GetProgressBarColor(speed); break;\
160 case "acceleration": HUD_Panel_GetProgressBarColor(acceleration); break;\
161 case "acceleration_neg": HUD_Panel_GetProgressBarColor(acceleration_neg); break;\
162 } ENDS_WITH_CURLY_BRACE
164 // Get value for panel_bg: if "" fetch default, else use panel_bg_str
165 // comment on last line of macro: // we probably want to see a background in config mode at all times...
166 #define HUD_Panel_GetBg()\
167 if(!autocvar__hud_configure && panel_bg_str == "0") {\
170 if(panel_bg_str == "") {\
171 panel_bg_str = autocvar_hud_panel_bg;\
173 if(panel_bg_str == "0" && !autocvar__hud_configure) {\
176 if (panel_bg_str == "0" && autocvar__hud_configure)\
177 panel_bg_alpha_str = "0";\
178 panel_bg = strcat(hud_skin_path, "/", panel_bg_str);\
179 if(precache_pic(panel_bg) == "") {\
180 panel_bg = strcat(hud_skin_path, "/", "border_default");\
181 if(precache_pic(panel_bg) == "") {\
182 panel_bg = strcat("gfx/hud/default/", "border_default");\
188 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
189 #define HUD_Panel_GetColor()\
190 if((teamplay) && panel_bg_color_team) {\
191 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)\
192 panel_bg_color = '1 0 0' * panel_bg_color_team;\
194 panel_bg_color = myteamcolors * panel_bg_color_team;\
195 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) {\
196 panel_bg_color = '1 0 0' * panel_bg_color_team;\
198 if(panel_bg_color_str == "") {\
199 panel_bg_color = autocvar_hud_panel_bg_color;\
201 if(panel_bg_color_str == "shirt") {\
202 panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player - 1, "colors")) / 16), 0);\
203 } else if(panel_bg_color_str == "pants") {\
204 panel_bg_color = colormapPaletteColor(mod(stof(getplayerkeyvalue(current_player - 1, "colors")), 16), 1);\
206 panel_bg_color = stov(panel_bg_color_str);\
211 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
212 #define HUD_Panel_GetColorTeam()\
213 if(panel_bg_color_team_str == "") {\
214 panel_bg_color_team = autocvar_hud_panel_bg_color_team;\
216 panel_bg_color_team = stof(panel_bg_color_team_str);\
219 // the check doesn't allow to fade this panel when showing the panel-specific menu dialog
220 #define HUD_Panel_ApplyFadeAlpha()\
221 if(!(menu_enabled == 2 && panel == highlightedPanel))\
223 panel_bg_alpha *= hud_fade_alpha;\
224 panel_fg_alpha *= hud_fade_alpha;\
225 } ENDS_WITH_CURLY_BRACE
227 // 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
228 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
229 #define HUD_Panel_GetBgAlpha()\
230 if(panel_bg_alpha_str == "") {\
231 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);\
233 panel_bg_alpha = stof(panel_bg_alpha_str);\
234 if(autocvar__hud_configure) {\
236 panel_bg_alpha = 0.25;\
237 else if(menu_enabled == 2 && panel == highlightedPanel)\
238 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
240 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha);\
243 // Get value for panel_fg_alpha. Also do various minalpha checks
244 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
245 #define HUD_Panel_GetFgAlpha()\
246 panel_fg_alpha = autocvar_hud_panel_fg_alpha;\
247 if(autocvar__hud_configure && !panel_enabled)\
248 panel_fg_alpha = 0.25;\
250 // Get border. See comments above, it's similar.
251 #define HUD_Panel_GetBorder()\
252 if(panel_bg_border_str == "") {\
253 panel_bg_border = autocvar_hud_panel_bg_border;\
255 panel_bg_border = stof(panel_bg_border_str);\
256 } ENDS_WITH_CURLY_BRACE
258 // Scale the pos and size vectors to absolute coordinates
259 #define HUD_Panel_GetScaledVectors()\
260 panel_pos_x *= vid_conwidth;\
261 panel_pos_y *= vid_conheight;\
262 panel_size_x *= vid_conwidth;\
263 panel_size_y *= vid_conheight;
265 // Get padding. See comments above, it's similar.
266 // 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
267 #define HUD_Panel_GetPadding()\
268 if(panel_bg_padding_str == "") {\
269 panel_bg_padding = autocvar_hud_panel_bg_padding;\
271 panel_bg_padding = stof(panel_bg_padding_str);\
273 panel_bg_padding = min(min(panel_size_x, panel_size_y)/2 - 5, panel_bg_padding);
275 // Point to the macros above (stupid max macro length)
276 #define HUD_Panel_GetStringVars()\
278 if (panel_bg != "0") {\
279 HUD_Panel_GetColorTeam()\
280 HUD_Panel_GetColor()\
281 HUD_Panel_GetBgAlpha()\
282 HUD_Panel_GetBorder()\
284 HUD_Panel_GetFgAlpha()\
285 HUD_Panel_GetScaledVectors()\
286 HUD_Panel_GetPadding()
288 // return smoothly faded pos of given panel when a dialog is active
289 var vector menu_enable_panelpos;
290 #define HUD_Panel_GetMenuPos() \
291 if(panel_size_x > panel_size_y)\
292 menu_enable_panelpos = eX * 0.5 * vid_conwidth - eX * 0.5 * panel_size_x + eY * 0.82 * vid_conheight;\
294 menu_enable_panelpos = eY * 0.5 * vid_conheight - eY * 0.5 * panel_size_y + eX * 0.7 * vid_conwidth;\
295 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_panelpos;
297 // return smoothly faded size of given panel when a dialog is active
298 //var vector menu_enable_maxsize;
299 var float menu_enable_maxsize_x;
300 var float menu_enable_maxsize_y;
301 var vector menu_enable_size;
302 #define HUD_Panel_GetMenuSize()\
303 menu_enable_maxsize_x = 0.3 * vid_conwidth;\
304 menu_enable_maxsize_y = 0.18 * vid_conheight;\
305 if(panel_size_x > panel_size_y)\
307 if(panel_size_y > menu_enable_maxsize_y)\
309 menu_enable_size_y = menu_enable_maxsize_y;\
310 menu_enable_size_x = panel_size_x * (menu_enable_maxsize_y/panel_size_y);\
311 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
316 if(panel_size_x > menu_enable_maxsize_x)\
318 menu_enable_size_x = menu_enable_maxsize_x;\
319 menu_enable_size_y = panel_size_y * (menu_enable_maxsize_x/panel_size_x);\
320 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
324 // NOTE: in hud_configure mode cvars must be reloaded every frame
325 #define HUD_Panel_UpdateCvars() \
326 if(panel.update_time <= time) { \
327 if(autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
328 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
329 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
330 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
331 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
332 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
333 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
334 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
335 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
336 HUD_Panel_GetStringVars()\
337 if(menu_enabled == 2 && panel == highlightedPanel) {\
338 HUD_Panel_GetMenuSize()\
339 HUD_Panel_GetMenuPos()\
341 panel.current_panel_pos = panel_pos; \
342 panel.current_panel_size = panel_size; \
343 if(panel.current_panel_bg) \
344 strunzone(panel.current_panel_bg); \
347 /*print(sprintf("^xf08 %s panel: panel_bg is empty\n", panel.panel_name));*/\
350 panel.current_panel_bg = strzone(panel_bg); \
351 panel.current_panel_bg_alpha = panel_bg_alpha; \
352 panel.current_panel_bg_border = panel_bg_border; \
353 panel.current_panel_bg_color = panel_bg_color; \
354 panel.current_panel_bg_color_team = panel_bg_color_team; \
355 panel.current_panel_bg_padding = panel_bg_padding; \
356 panel.current_panel_fg_alpha = panel_fg_alpha; \
357 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
359 panel_pos = panel.current_panel_pos; \
360 panel_size = panel.current_panel_size; \
361 panel_bg = panel.current_panel_bg; \
362 if(panel.current_panel_bg == "")\
364 /*print(sprintf("^xf08 %s panel: panel.current_panel_bg is empty\n", panel.panel_name));*/\
367 panel_bg_alpha = panel.current_panel_bg_alpha; \
368 panel_bg_border = panel.current_panel_bg_border; \
369 panel_bg_color = panel.current_panel_bg_color; \
370 panel_bg_color_team = panel.current_panel_bg_color_team; \
371 panel_bg_padding = panel.current_panel_bg_padding; \
372 panel_fg_alpha = panel.current_panel_fg_alpha; \
373 } ENDS_WITH_CURLY_BRACE
375 #define HUD_Panel_UpdatePosSize() {\
376 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
377 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
378 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
379 HUD_Panel_GetScaledVectors()\
380 if(menu_enabled == 2 && panel == highlightedPanel) {\
381 HUD_Panel_GetMenuSize()\
382 HUD_Panel_GetMenuPos()\
384 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
385 HUD_Panel_GetBorder() \
386 } ENDS_WITH_CURLY_BRACE
389 #define KN_MAX_ENTRIES 10
392 float notify_times[KN_MAX_ENTRIES];
393 string notify_icon[KN_MAX_ENTRIES];
394 string notify_attackers[KN_MAX_ENTRIES];
395 string notify_victims[KN_MAX_ENTRIES];
396 void HUD_Notify_Push(string icon, string attacker, string victim);