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 chat_panel_modified;
13 float radar_panel_modified;
16 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
17 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
18 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
19 entity highlightedPanel;
20 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
22 const float BORDER_MULTIPLIER = 0.25;
23 float scoreboard_bottom;
24 float weapon_accuracy[WEP_MAXCOUNT];
26 float complain_weapon;
27 string complain_weapon_name;
28 float complain_weapon_type;
29 float complain_weapon_time;
31 float ps_primary, ps_secondary;
32 float ts_primary, ts_secondary;
34 float last_switchweapon;
35 float last_activeweapon;
41 float hud_configure_checkcollisions;
42 float hud_configure_prev;
43 noref vector hud_configure_gridSize; // fteqcc sucks
44 noref vector hud_configure_realGridSize; // fteqcc sucks
47 const float S_SHIFT = 1;
48 const float S_CTRL = 2;
49 const float S_ALT = 4;
51 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
60 entity highlightedPanel_backup;
61 var vector panel_pos_backup;
62 var vector panel_size_backup;
64 var vector panel_size_copied;
69 .vector current_panel_pos;
70 .vector current_panel_size;
71 .string current_panel_bg;
72 .float current_panel_bg_alpha;
73 .float current_panel_bg_border;
74 .vector current_panel_bg_color;
75 .float current_panel_bg_color_team;
76 .float current_panel_bg_padding;
77 .float current_panel_fg_alpha;
79 var float panel_enabled;
81 var vector panel_size;
82 var string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
83 var vector panel_bg_color;
84 var string panel_bg_color_str;
85 var float panel_bg_color_team;
86 var string panel_bg_color_team_str;
87 var float panel_fg_alpha;
88 var float panel_bg_alpha;
89 var string panel_bg_alpha_str;
90 var float panel_bg_border;
91 var string panel_bg_border_str;
92 var float panel_bg_padding;
93 var string panel_bg_padding_str;
101 HUD_PANEL(WEAPONS , HUD_Weapons , weapons) \
102 HUD_PANEL(AMMO , HUD_Ammo , ammo) \
103 HUD_PANEL(POWERUPS , HUD_Powerups , powerups) \
104 HUD_PANEL(HEALTHARMOR , HUD_HealthArmor , healtharmor) \
105 HUD_PANEL(NOTIFY , HUD_Notify , notify) \
106 HUD_PANEL(TIMER , HUD_Timer , timer) \
107 HUD_PANEL(RADAR , HUD_Radar , radar) \
108 HUD_PANEL(SCORE , HUD_Score , score) \
109 HUD_PANEL(RACETIMER , HUD_RaceTimer , racetimer) \
110 HUD_PANEL(VOTE , HUD_Vote , vote) \
111 HUD_PANEL(MODICONS , HUD_ModIcons , modicons) \
112 HUD_PANEL(PRESSEDKEYS , HUD_PressedKeys , pressedkeys) \
113 HUD_PANEL(CHAT , HUD_Chat , chat) \
114 HUD_PANEL(ENGINEINFO , HUD_EngineInfo , engineinfo) \
115 HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages) \
116 HUD_PANEL(PHYSICS , HUD_Physics , physics) \
117 HUD_PANEL(CENTERPRINT , HUD_CenterPrint , centerprint) \
118 HUD_PANEL(BUFFS , HUD_Buffs , buffs)
120 #define HUD_PANEL(NAME,draw_func,name) \
121 float HUD_PANEL_##NAME; \
122 void draw_func(void); \
123 void RegisterHUD_Panel_##NAME() \
125 HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM; \
126 entity hud_panelent = spawn(); \
127 hud_panel[HUD_PANEL_##NAME] = hud_panelent; \
128 hud_panelent.classname = "hud_panel"; \
129 hud_panelent.panel_name = #name; \
130 hud_panelent.panel_id = HUD_PANEL_##NAME; \
131 hud_panelent.panel_draw = draw_func; \
134 ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME);
139 #define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
142 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
143 // ----------------------
144 // MACRO HELL STARTS HERE
145 // ----------------------
146 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
148 // Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str
149 // comment on last line of macro: // we probably want to see a background in config mode at all times...
150 #define HUD_Panel_GetBg()\
152 if(!autocvar__hud_configure && panel_bg_str == "0") {\
155 if(panel_bg_str == "") {\
156 panel_bg_str = autocvar_hud_panel_bg;\
158 if(panel_bg_str == "0" && !autocvar__hud_configure) {\
161 if (panel_bg_str == "0" && autocvar__hud_configure)\
162 panel_bg_alpha_str = "0";\
163 panel_bg = strcat(hud_skin_path, "/", panel_bg_str);\
164 if(precache_pic(panel_bg) == "") {\
165 panel_bg = strcat(hud_skin_path, "/", "border_default");\
166 if(precache_pic(panel_bg) == "") {\
167 panel_bg = strcat("gfx/hud/default/", "border_default");\
172 if(panel.current_panel_bg)\
173 strunzone(panel.current_panel_bg);\
174 panel.current_panel_bg = strzone(panel_bg);
176 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
177 #define HUD_Panel_GetColor()\
178 if((teamplay) && panel_bg_color_team) {\
179 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)\
180 panel_bg_color = '1 0 0' * panel_bg_color_team;\
182 panel_bg_color = myteamcolors * panel_bg_color_team;\
183 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) {\
184 panel_bg_color = '1 0 0' * panel_bg_color_team;\
186 if(panel_bg_color_str == "") {\
187 panel_bg_color = autocvar_hud_panel_bg_color;\
189 if(panel_bg_color_str == "shirt") {\
190 panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player - 1, "colors")) / 16), 0);\
191 } else if(panel_bg_color_str == "pants") {\
192 panel_bg_color = colormapPaletteColor(mod(stof(getplayerkeyvalue(current_player - 1, "colors")), 16), 1);\
194 panel_bg_color = stov(panel_bg_color_str);\
199 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
200 #define HUD_Panel_GetColorTeam()\
201 if(panel_bg_color_team_str == "") {\
202 panel_bg_color_team = autocvar_hud_panel_bg_color_team;\
204 panel_bg_color_team = stof(panel_bg_color_team_str);\
207 // 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
208 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
209 #define HUD_Panel_GetBgAlpha()\
210 if(panel_bg_alpha_str == "") {\
211 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);\
213 panel_bg_alpha = stof(panel_bg_alpha_str);\
214 if(autocvar__hud_configure) {\
216 panel_bg_alpha = 0.25;\
217 else if(menu_enabled == 2 && panel == highlightedPanel)\
218 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
220 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha);\
223 // Get value for panel_fg_alpha. Also do various minalpha checks
224 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
225 #define HUD_Panel_GetFgAlpha()\
226 panel_fg_alpha = autocvar_hud_panel_fg_alpha;\
227 if(autocvar__hud_configure && !panel_enabled)\
228 panel_fg_alpha = 0.25;\
230 // Get border. See comments above, it's similar.
231 #define HUD_Panel_GetBorder()\
232 if(panel_bg_border_str == "") {\
233 panel_bg_border = autocvar_hud_panel_bg_border;\
235 panel_bg_border = stof(panel_bg_border_str);\
236 } ENDS_WITH_CURLY_BRACE
238 // Get padding. See comments above, it's similar.
239 // 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
240 #define HUD_Panel_GetPadding()\
241 if(panel_bg_padding_str == "") {\
242 panel_bg_padding = autocvar_hud_panel_bg_padding;\
244 panel_bg_padding = stof(panel_bg_padding_str);\
246 panel_bg_padding = min(min(panel_size_x, panel_size_y)/2 - 5, panel_bg_padding);
248 // return smoothly faded pos and size of given panel when a dialog is active
249 #define HUD_Panel_UpdatePosSize_ForMenu()\
250 vector menu_enable_pos;\
251 vector menu_enable_size = '0 0 0';\
252 float menu_enable_maxsize_x = 0.3 * vid_conwidth;\
253 float menu_enable_maxsize_y = 0.18 * vid_conheight;\
254 if(panel_size_x > panel_size_y)\
256 if(panel_size_y > menu_enable_maxsize_y)\
258 menu_enable_size_y = menu_enable_maxsize_y;\
259 menu_enable_size_x = panel_size_x * (menu_enable_maxsize_y/panel_size_y);\
260 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
262 menu_enable_pos = eX * 0.5 * vid_conwidth - eX * 0.5 * panel_size_x + eY * (vid_conheight - menu_enable_maxsize_y);\
266 if(panel_size_x > menu_enable_maxsize_x)\
268 menu_enable_size_x = menu_enable_maxsize_x;\
269 menu_enable_size_y = panel_size_y * (menu_enable_maxsize_x/panel_size_x);\
270 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
272 menu_enable_pos = eY * 0.5 * vid_conheight - eY * 0.5 * panel_size_y + eX * (vid_conwidth - menu_enable_maxsize_x);\
274 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_pos;
276 // Scale the pos and size vectors to absolute coordinates
277 #define HUD_Panel_ScalePosSize()\
278 panel_pos_x *= vid_conwidth; panel_pos_y *= vid_conheight;\
279 panel_size_x *= vid_conwidth; panel_size_y *= vid_conheight;
281 // NOTE: in hud_configure mode cvars must be reloaded every frame
282 #define HUD_Panel_UpdateCvars() \
283 if(panel.update_time <= time) { \
284 if(autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
285 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
286 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
287 HUD_Panel_ScalePosSize() \
288 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
289 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
290 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
291 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
292 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
293 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
295 if (panel.current_panel_bg != "0") {\
296 HUD_Panel_GetColorTeam()\
297 HUD_Panel_GetColor()\
298 HUD_Panel_GetBgAlpha()\
299 HUD_Panel_GetBorder()\
301 HUD_Panel_GetFgAlpha()\
302 HUD_Panel_GetPadding()\
303 panel.current_panel_bg_alpha = panel_bg_alpha; \
304 panel.current_panel_fg_alpha = panel_fg_alpha; \
305 if(menu_enabled == 2 && panel == highlightedPanel) {\
306 HUD_Panel_UpdatePosSize_ForMenu()\
308 panel_bg_alpha *= hud_fade_alpha;\
309 panel_fg_alpha *= hud_fade_alpha;\
311 panel.current_panel_pos = panel_pos; \
312 panel.current_panel_size = panel_size; \
313 panel.current_panel_bg_border = panel_bg_border; \
314 panel.current_panel_bg_color = panel_bg_color; \
315 panel.current_panel_bg_color_team = panel_bg_color_team; \
316 panel.current_panel_bg_padding = panel_bg_padding; \
317 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
319 panel_pos = panel.current_panel_pos; \
320 panel_size = panel.current_panel_size; \
321 panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha; \
322 panel_bg_border = panel.current_panel_bg_border; \
323 panel_bg_color = panel.current_panel_bg_color; \
324 panel_bg_color_team = panel.current_panel_bg_color_team; \
325 panel_bg_padding = panel.current_panel_bg_padding; \
326 panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \
327 } ENDS_WITH_CURLY_BRACE
329 #define HUD_Panel_UpdatePosSize() {\
330 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
331 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
332 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
333 HUD_Panel_ScalePosSize()\
334 if(menu_enabled == 2 && panel == highlightedPanel) {\
335 HUD_Panel_UpdatePosSize_ForMenu()\
337 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
338 HUD_Panel_GetBorder() \
339 } ENDS_WITH_CURLY_BRACE
341 #define NOTIFY_MAX_ENTRIES 10
342 #define NOTIFY_ICON_MARGIN 0.02
346 float notify_times[NOTIFY_MAX_ENTRIES];
347 string notify_attackers[NOTIFY_MAX_ENTRIES];
348 string notify_victims[NOTIFY_MAX_ENTRIES];
349 string notify_icons[NOTIFY_MAX_ENTRIES];
351 void HUD_Notify_Push(string icon, string attacker, string victim);
353 var void HUD_ModIcons_GameType(vector pos, vector size);
354 void HUD_ModIcons_SetFunc();