4 #include "../common/weapons/weapons.qh"
6 const int HUD_PANEL_MAX = 24;
7 entity hud_panel[HUD_PANEL_MAX];
8 const int HUD_PANEL_FIRST = 0;
12 int panel_order[HUD_PANEL_MAX];
13 string hud_panelorder_prev;
15 bool hud_draw_maximized;
16 bool hud_panel_radar_maximized;
17 bool hud_panel_radar_mouse;
18 float hud_panel_radar_bottom;
19 bool hud_panel_radar_temp_hidden;
20 bool chat_panel_modified;
21 bool radar_panel_modified;
23 void HUD_Radar_Hide_Maximized();
26 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
27 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
28 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
29 entity highlightedPanel;
30 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
32 const float BORDER_MULTIPLIER = 0.25;
33 float scoreboard_bottom;
34 int weapon_accuracy[WEP_MAXCOUNT];
37 string complain_weapon_name;
38 float complain_weapon_type;
39 float complain_weapon_time;
41 int ps_primary, ps_secondary;
42 int ts_primary, ts_secondary;
44 int last_switchweapon;
45 int last_activeweapon;
51 float hud_configure_checkcollisions;
52 float hud_configure_prev;
53 vector hud_configure_gridSize;
54 vector hud_configure_realGridSize;
57 const int S_SHIFT = 1;
61 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
70 entity highlightedPanel_backup;
71 vector panel_pos_backup;
72 vector panel_size_backup;
74 vector panel_size_copied;
79 .vector current_panel_pos;
80 .vector current_panel_size;
81 .string current_panel_bg;
82 .float current_panel_bg_alpha;
83 .float current_panel_bg_border;
84 .vector current_panel_bg_color;
85 .float current_panel_bg_color_team;
86 .float current_panel_bg_padding;
87 .float current_panel_fg_alpha;
92 string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
93 vector panel_bg_color;
94 string panel_bg_color_str;
95 float panel_bg_color_team;
96 string panel_bg_color_team_str;
99 string panel_bg_alpha_str;
100 float panel_bg_border;
101 string panel_bg_border_str;
102 float panel_bg_padding;
103 string panel_bg_padding_str;
107 float current_player;
109 float GetPlayerColorForce(int i);
112 #define HUD_PANELS(HUD_PANEL) \
113 HUD_PANEL(WEAPONS , HUD_Weapons , weapons) \
114 HUD_PANEL(AMMO , HUD_Ammo , ammo) \
115 HUD_PANEL(POWERUPS , HUD_Powerups , powerups) \
116 HUD_PANEL(HEALTHARMOR , HUD_HealthArmor , healtharmor) \
117 HUD_PANEL(NOTIFY , HUD_Notify , notify) \
118 HUD_PANEL(TIMER , HUD_Timer , timer) \
119 HUD_PANEL(RADAR , HUD_Radar , radar) \
120 HUD_PANEL(SCORE , HUD_Score , score) \
121 HUD_PANEL(RACETIMER , HUD_RaceTimer , racetimer) \
122 HUD_PANEL(VOTE , HUD_Vote , vote) \
123 HUD_PANEL(MODICONS , HUD_ModIcons , modicons) \
124 HUD_PANEL(PRESSEDKEYS , HUD_PressedKeys , pressedkeys) \
125 HUD_PANEL(CHAT , HUD_Chat , chat) \
126 HUD_PANEL(ENGINEINFO , HUD_EngineInfo , engineinfo) \
127 HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages) \
128 HUD_PANEL(PHYSICS , HUD_Physics , physics) \
129 HUD_PANEL(CENTERPRINT , HUD_CenterPrint , centerprint) \
130 HUD_PANEL(BUFFS , HUD_Buffs , buffs)
132 #define HUD_PANEL(NAME, draw_func, name) \
133 int HUD_PANEL_##NAME; \
134 void draw_func(void); \
135 void RegisterHUD_Panel_##NAME() { \
136 HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM; \
137 entity hud_panelent = spawn(); \
138 hud_panel[HUD_PANEL_##NAME] = hud_panelent; \
139 hud_panelent.classname = "hud_panel"; \
140 hud_panelent.panel_name = #name; \
141 hud_panelent.panel_id = HUD_PANEL_##NAME; \
142 hud_panelent.panel_draw = draw_func; \
145 ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME);
147 HUD_PANELS(HUD_PANEL)
150 #define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
153 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
154 // ----------------------
155 // MACRO HELL STARTS HERE
156 // ----------------------
157 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
159 // Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str
160 // comment on last line of macro: // we probably want to see a background in config mode at all times...
161 #define HUD_Panel_GetBg() do { \
163 if (!autocvar__hud_configure && panel_bg_str == "0") { \
166 if (panel_bg_str == "") { \
167 panel_bg_str = autocvar_hud_panel_bg; \
169 if (panel_bg_str == "0" && !autocvar__hud_configure) { \
172 if (panel_bg_str == "0" && autocvar__hud_configure) \
173 panel_bg_alpha_str = "0"; \
174 panel_bg = strcat(hud_skin_path, "/", panel_bg_str); \
175 if (precache_pic(panel_bg) == "") { \
176 panel_bg = strcat(hud_skin_path, "/", "border_default"); \
177 if (precache_pic(panel_bg) == "") { \
178 panel_bg = strcat("gfx/hud/default/", "border_default"); \
183 if (panel.current_panel_bg) \
184 strunzone(panel.current_panel_bg); \
185 panel.current_panel_bg = strzone(panel_bg); \
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() do { \
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(stof(getplayerkeyvalue(current_player - 1, "colors")) % 16, 1);\
206 panel_bg_color = stov(panel_bg_color_str); \
212 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
213 #define HUD_Panel_GetColorTeam() do { \
214 if (panel_bg_color_team_str == "") { \
215 panel_bg_color_team = autocvar_hud_panel_bg_color_team; \
217 panel_bg_color_team = stof(panel_bg_color_team_str); \
221 // 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
222 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
223 #define HUD_Panel_GetBgAlpha() do { \
224 if (panel_bg_alpha_str == "") { \
225 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha); \
227 panel_bg_alpha = stof(panel_bg_alpha_str); \
228 if (autocvar__hud_configure) { \
229 if (!panel_enabled) \
230 panel_bg_alpha = 0.25; \
231 else if (menu_enabled == 2 && panel == highlightedPanel) \
232 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
234 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha); \
238 // Get value for panel_fg_alpha. Also do various minalpha checks
239 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
240 #define HUD_Panel_GetFgAlpha() do { \
241 panel_fg_alpha = autocvar_hud_panel_fg_alpha; \
242 if (autocvar__hud_configure && !panel_enabled) \
243 panel_fg_alpha = 0.25; \
246 // Get border. See comments above, it's similar.
247 #define HUD_Panel_GetBorder() do { \
248 if (panel_bg_border_str == "") { \
249 panel_bg_border = autocvar_hud_panel_bg_border; \
251 panel_bg_border = stof(panel_bg_border_str); \
255 // Get padding. See comments above, it's similar.
256 // 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
257 #define HUD_Panel_GetPadding() do { \
258 if (panel_bg_padding_str == "") { \
259 panel_bg_padding = autocvar_hud_panel_bg_padding; \
261 panel_bg_padding = stof(panel_bg_padding_str); \
263 panel_bg_padding = min(min(panel_size.x, panel_size.y)/2 - 5, panel_bg_padding); \
266 // return smoothly faded pos and size of given panel when a dialog is active
267 #define HUD_Panel_UpdatePosSize_ForMenu() do { \
268 vector menu_enable_pos; \
269 vector menu_enable_size = '0 0 0'; \
270 float menu_enable_maxsize_x = 0.3 * vid_conwidth; \
271 float menu_enable_maxsize_y = 0.18 * vid_conheight; \
272 if (panel_size.x > panel_size.y) { \
273 if (panel_size.y > menu_enable_maxsize_y) { \
274 menu_enable_size.y = menu_enable_maxsize_y; \
275 menu_enable_size.x = panel_size.x * (menu_enable_maxsize_y/panel_size.y); \
276 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size; \
278 menu_enable_pos = eX * 0.5 * vid_conwidth - eX * 0.5 * panel_size.x + eY * (vid_conheight - menu_enable_maxsize_y);\
280 if (panel_size.x > menu_enable_maxsize_x) { \
281 menu_enable_size.x = menu_enable_maxsize_x; \
282 menu_enable_size.y = panel_size.y * (menu_enable_maxsize_x/panel_size.x); \
283 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size; \
285 menu_enable_pos = eY * 0.5 * vid_conheight - eY * 0.5 * panel_size.y + eX * (vid_conwidth - menu_enable_maxsize_x);\
287 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_pos; \
290 // Scale the pos and size vectors to absolute coordinates
291 #define HUD_Panel_ScalePosSize() do { \
292 panel_pos.x *= vid_conwidth; panel_pos.y *= vid_conheight; \
293 panel_size.x *= vid_conwidth; panel_size.y *= vid_conheight; \
296 // NOTE: in hud_configure mode cvars must be reloaded every frame
297 #define HUD_Panel_UpdateCvars() do { \
298 if (panel.update_time <= time) { \
299 if (autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
300 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
301 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
302 HUD_Panel_ScalePosSize(); \
303 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
304 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
305 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
306 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
307 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
308 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
310 if (panel.current_panel_bg != "0") { \
311 HUD_Panel_GetColorTeam(); \
312 HUD_Panel_GetColor(); \
313 HUD_Panel_GetBgAlpha(); \
314 HUD_Panel_GetBorder(); \
316 HUD_Panel_GetFgAlpha(); \
317 HUD_Panel_GetPadding(); \
318 panel.current_panel_bg_alpha = panel_bg_alpha; \
319 panel.current_panel_fg_alpha = panel_fg_alpha; \
320 if (menu_enabled == 2 && panel == highlightedPanel) { \
321 HUD_Panel_UpdatePosSize_ForMenu(); \
323 panel_bg_alpha *= hud_fade_alpha; \
324 panel_fg_alpha *= hud_fade_alpha; \
326 panel.current_panel_pos = panel_pos; \
327 panel.current_panel_size = panel_size; \
328 panel.current_panel_bg_border = panel_bg_border; \
329 panel.current_panel_bg_color = panel_bg_color; \
330 panel.current_panel_bg_color_team = panel_bg_color_team; \
331 panel.current_panel_bg_padding = panel_bg_padding; \
332 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
334 panel_pos = panel.current_panel_pos; \
335 panel_size = panel.current_panel_size; \
336 panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha; \
337 panel_bg_border = panel.current_panel_bg_border; \
338 panel_bg_color = panel.current_panel_bg_color; \
339 panel_bg_color_team = panel.current_panel_bg_color_team; \
340 panel_bg_padding = panel.current_panel_bg_padding; \
341 panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \
345 #define HUD_Panel_UpdatePosSize() do { \
346 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
347 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
348 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
349 HUD_Panel_ScalePosSize(); \
350 if (menu_enabled == 2 && panel == highlightedPanel) { \
351 HUD_Panel_UpdatePosSize_ForMenu(); \
353 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
354 HUD_Panel_GetBorder(); \
357 const int NOTIFY_MAX_ENTRIES = 10;
358 const float NOTIFY_ICON_MARGIN = 0.02;
362 float notify_times[NOTIFY_MAX_ENTRIES];
363 string notify_attackers[NOTIFY_MAX_ENTRIES];
364 string notify_victims[NOTIFY_MAX_ENTRIES];
365 string notify_icons[NOTIFY_MAX_ENTRIES];
367 void HUD_Notify_Push(string icon, string attacker, string victim);
369 var void HUD_ModIcons_GameType(vector pos, vector size);
370 void HUD_ModIcons_SetFunc();