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_radar_mouse;
13 float hud_panel_radar_bottom;
14 float hud_panel_radar_temp_hidden;
15 float chat_panel_modified;
16 float radar_panel_modified;
18 void HUD_Radar_Hide_Maximized();
21 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
22 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
23 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
24 entity highlightedPanel;
25 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
27 const float BORDER_MULTIPLIER = 0.25;
28 float scoreboard_bottom;
29 float weapon_accuracy[WEP_MAXCOUNT];
31 float complain_weapon;
32 string complain_weapon_name;
33 float complain_weapon_type;
34 float complain_weapon_time;
36 float ps_primary, ps_secondary;
37 float ts_primary, ts_secondary;
39 float last_switchweapon;
40 float last_activeweapon;
46 float hud_configure_checkcollisions;
47 float hud_configure_prev;
48 noref vector hud_configure_gridSize; // fteqcc sucks
49 noref vector hud_configure_realGridSize; // fteqcc sucks
52 const float S_SHIFT = 1;
53 const float S_CTRL = 2;
54 const float S_ALT = 4;
56 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
65 entity highlightedPanel_backup;
66 var vector panel_pos_backup;
67 var vector panel_size_backup;
69 var vector panel_size_copied;
74 .vector current_panel_pos;
75 .vector current_panel_size;
76 .string current_panel_bg;
77 .float current_panel_bg_alpha;
78 .float current_panel_bg_border;
79 .vector current_panel_bg_color;
80 .float current_panel_bg_color_team;
81 .float current_panel_bg_padding;
82 .float current_panel_fg_alpha;
84 var float panel_enabled;
86 var vector panel_size;
87 var string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
88 var vector panel_bg_color;
89 var string panel_bg_color_str;
90 var float panel_bg_color_team;
91 var string panel_bg_color_team_str;
92 var float panel_fg_alpha;
93 var float panel_bg_alpha;
94 var string panel_bg_alpha_str;
95 var float panel_bg_border;
96 var string panel_bg_border_str;
97 var float panel_bg_padding;
98 var string panel_bg_padding_str;
102 float current_player;
108 HUD_PANEL(WEAPONS , HUD_Weapons , weapons) \
109 HUD_PANEL(AMMO , HUD_Ammo , ammo) \
110 HUD_PANEL(POWERUPS , HUD_Powerups , powerups) \
111 HUD_PANEL(HEALTHARMOR , HUD_HealthArmor , healtharmor) \
112 HUD_PANEL(NOTIFY , HUD_Notify , notify) \
113 HUD_PANEL(TIMER , HUD_Timer , timer) \
114 HUD_PANEL(RADAR , HUD_Radar , radar) \
115 HUD_PANEL(SCORE , HUD_Score , score) \
116 HUD_PANEL(RACETIMER , HUD_RaceTimer , racetimer) \
117 HUD_PANEL(VOTE , HUD_Vote , vote) \
118 HUD_PANEL(MODICONS , HUD_ModIcons , modicons) \
119 HUD_PANEL(PRESSEDKEYS , HUD_PressedKeys , pressedkeys) \
120 HUD_PANEL(CHAT , HUD_Chat , chat) \
121 HUD_PANEL(ENGINEINFO , HUD_EngineInfo , engineinfo) \
122 HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages) \
123 HUD_PANEL(PHYSICS , HUD_Physics , physics) \
124 HUD_PANEL(CENTERPRINT , HUD_CenterPrint , centerprint)
126 #define HUD_PANEL(NAME,draw_func,name) \
127 float HUD_PANEL_##NAME; \
128 void draw_func(void); \
129 void RegisterHUD_Panel_##NAME() \
131 HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM; \
132 entity hud_panelent = spawn(); \
133 hud_panel[HUD_PANEL_##NAME] = hud_panelent; \
134 hud_panelent.classname = "hud_panel"; \
135 hud_panelent.panel_name = #name; \
136 hud_panelent.panel_id = HUD_PANEL_##NAME; \
137 hud_panelent.panel_draw = draw_func; \
140 ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME);
145 #define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
148 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
149 // ----------------------
150 // MACRO HELL STARTS HERE
151 // ----------------------
152 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
154 // Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str
155 // comment on last line of macro: // we probably want to see a background in config mode at all times...
156 #define HUD_Panel_GetBg()\
158 if(!autocvar__hud_configure && panel_bg_str == "0") {\
161 if(panel_bg_str == "") {\
162 panel_bg_str = autocvar_hud_panel_bg;\
164 if(panel_bg_str == "0" && !autocvar__hud_configure) {\
167 if (panel_bg_str == "0" && autocvar__hud_configure)\
168 panel_bg_alpha_str = "0";\
169 panel_bg = strcat(hud_skin_path, "/", panel_bg_str);\
170 if(precache_pic(panel_bg) == "") {\
171 panel_bg = strcat(hud_skin_path, "/", "border_default");\
172 if(precache_pic(panel_bg) == "") {\
173 panel_bg = strcat("gfx/hud/default/", "border_default");\
178 if(panel.current_panel_bg)\
179 strunzone(panel.current_panel_bg);\
180 panel.current_panel_bg = strzone(panel_bg);
182 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
183 #define HUD_Panel_GetColor()\
184 if((teamplay) && panel_bg_color_team) {\
185 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)\
186 panel_bg_color = '1 0 0' * panel_bg_color_team;\
188 panel_bg_color = myteamcolors * panel_bg_color_team;\
189 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) {\
190 panel_bg_color = '1 0 0' * panel_bg_color_team;\
192 if(panel_bg_color_str == "") {\
193 panel_bg_color = autocvar_hud_panel_bg_color;\
195 if(panel_bg_color_str == "shirt") {\
196 panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player - 1, "colors")) / 16), 0);\
197 } else if(panel_bg_color_str == "pants") {\
198 panel_bg_color = colormapPaletteColor(mod(stof(getplayerkeyvalue(current_player - 1, "colors")), 16), 1);\
200 panel_bg_color = stov(panel_bg_color_str);\
205 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
206 #define HUD_Panel_GetColorTeam()\
207 if(panel_bg_color_team_str == "") {\
208 panel_bg_color_team = autocvar_hud_panel_bg_color_team;\
210 panel_bg_color_team = stof(panel_bg_color_team_str);\
213 // 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
214 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
215 #define HUD_Panel_GetBgAlpha()\
216 if(panel_bg_alpha_str == "") {\
217 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);\
219 panel_bg_alpha = stof(panel_bg_alpha_str);\
220 if(autocvar__hud_configure) {\
222 panel_bg_alpha = 0.25;\
223 else if(menu_enabled == 2 && panel == highlightedPanel)\
224 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
226 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha);\
229 // Get value for panel_fg_alpha. Also do various minalpha checks
230 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
231 #define HUD_Panel_GetFgAlpha()\
232 panel_fg_alpha = autocvar_hud_panel_fg_alpha;\
233 if(autocvar__hud_configure && !panel_enabled)\
234 panel_fg_alpha = 0.25;\
236 // Get border. See comments above, it's similar.
237 #define HUD_Panel_GetBorder()\
238 if(panel_bg_border_str == "") {\
239 panel_bg_border = autocvar_hud_panel_bg_border;\
241 panel_bg_border = stof(panel_bg_border_str);\
242 } ENDS_WITH_CURLY_BRACE
244 // Get padding. See comments above, it's similar.
245 // 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
246 #define HUD_Panel_GetPadding()\
247 if(panel_bg_padding_str == "") {\
248 panel_bg_padding = autocvar_hud_panel_bg_padding;\
250 panel_bg_padding = stof(panel_bg_padding_str);\
252 panel_bg_padding = min(min(panel_size_x, panel_size_y)/2 - 5, panel_bg_padding);
254 // return smoothly faded pos and size of given panel when a dialog is active
255 #define HUD_Panel_UpdatePosSize_ForMenu()\
256 vector menu_enable_pos;\
257 vector menu_enable_size = '0 0 0';\
258 float menu_enable_maxsize_x = 0.3 * vid_conwidth;\
259 float menu_enable_maxsize_y = 0.18 * vid_conheight;\
260 if(panel_size_x > panel_size_y)\
262 if(panel_size_y > menu_enable_maxsize_y)\
264 menu_enable_size_y = menu_enable_maxsize_y;\
265 menu_enable_size_x = panel_size_x * (menu_enable_maxsize_y/panel_size_y);\
266 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
268 menu_enable_pos = eX * 0.5 * vid_conwidth - eX * 0.5 * panel_size_x + eY * (vid_conheight - menu_enable_maxsize_y);\
272 if(panel_size_x > menu_enable_maxsize_x)\
274 menu_enable_size_x = menu_enable_maxsize_x;\
275 menu_enable_size_y = panel_size_y * (menu_enable_maxsize_x/panel_size_x);\
276 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
278 menu_enable_pos = eY * 0.5 * vid_conheight - eY * 0.5 * panel_size_y + eX * (vid_conwidth - menu_enable_maxsize_x);\
280 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_pos;
282 // Scale the pos and size vectors to absolute coordinates
283 #define HUD_Panel_ScalePosSize()\
284 panel_pos_x *= vid_conwidth; panel_pos_y *= vid_conheight;\
285 panel_size_x *= vid_conwidth; panel_size_y *= vid_conheight;
287 // NOTE: in hud_configure mode cvars must be reloaded every frame
288 #define HUD_Panel_UpdateCvars() \
289 if(panel.update_time <= time) { \
290 if(autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
291 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
292 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
293 HUD_Panel_ScalePosSize() \
294 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
295 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
296 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
297 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
298 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
299 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
301 if (panel.current_panel_bg != "0") {\
302 HUD_Panel_GetColorTeam()\
303 HUD_Panel_GetColor()\
304 HUD_Panel_GetBgAlpha()\
305 HUD_Panel_GetBorder()\
307 HUD_Panel_GetFgAlpha()\
308 HUD_Panel_GetPadding()\
309 panel.current_panel_bg_alpha = panel_bg_alpha; \
310 panel.current_panel_fg_alpha = panel_fg_alpha; \
311 if(menu_enabled == 2 && panel == highlightedPanel) {\
312 HUD_Panel_UpdatePosSize_ForMenu()\
314 panel_bg_alpha *= hud_fade_alpha;\
315 panel_fg_alpha *= hud_fade_alpha;\
317 panel.current_panel_pos = panel_pos; \
318 panel.current_panel_size = panel_size; \
319 panel.current_panel_bg_border = panel_bg_border; \
320 panel.current_panel_bg_color = panel_bg_color; \
321 panel.current_panel_bg_color_team = panel_bg_color_team; \
322 panel.current_panel_bg_padding = panel_bg_padding; \
323 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
325 panel_pos = panel.current_panel_pos; \
326 panel_size = panel.current_panel_size; \
327 panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha; \
328 panel_bg_border = panel.current_panel_bg_border; \
329 panel_bg_color = panel.current_panel_bg_color; \
330 panel_bg_color_team = panel.current_panel_bg_color_team; \
331 panel_bg_padding = panel.current_panel_bg_padding; \
332 panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \
333 } ENDS_WITH_CURLY_BRACE
335 #define HUD_Panel_UpdatePosSize() {\
336 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
337 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
338 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
339 HUD_Panel_ScalePosSize()\
340 if(menu_enabled == 2 && panel == highlightedPanel) {\
341 HUD_Panel_UpdatePosSize_ForMenu()\
343 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
344 HUD_Panel_GetBorder() \
345 } ENDS_WITH_CURLY_BRACE
348 #define KN_MAX_ENTRIES 10
351 float notify_times[KN_MAX_ENTRIES];
352 string notify_icon[KN_MAX_ENTRIES];
353 string notify_attackers[KN_MAX_ENTRIES];
354 string notify_victims[KN_MAX_ENTRIES];
355 void HUD_Notify_Push(string icon, string attacker, string victim);
357 var void HUD_ModIcons_GameType(vector pos, vector size);
358 void HUD_ModIcons_SetFunc();