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