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 float hud_draw_maximized;
16 float hud_panel_radar_maximized;
17 float chat_panel_modified;
18 float radar_panel_modified;
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 int weapon_accuracy[WEP_MAXCOUNT];
32 string complain_weapon_name;
33 float complain_weapon_type;
34 float complain_weapon_time;
36 int ps_primary, ps_secondary;
37 int ts_primary, ts_secondary;
39 float last_switchweapon;
40 float last_activeweapon;
46 float hud_configure_checkcollisions;
47 float hud_configure_prev;
48 vector hud_configure_gridSize;
49 vector hud_configure_realGridSize;
52 const int S_SHIFT = 1;
56 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
65 entity highlightedPanel_backup;
66 vector panel_pos_backup;
67 vector panel_size_backup;
69 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;
87 string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
88 vector panel_bg_color;
89 string panel_bg_color_str;
90 float panel_bg_color_team;
91 string panel_bg_color_team_str;
94 string panel_bg_alpha_str;
95 float panel_bg_border;
96 string panel_bg_border_str;
97 float panel_bg_padding;
98 string panel_bg_padding_str;
102 float current_player;
104 float GetPlayerColorForce(float i);
107 #define HUD_PANELS(HUD_PANEL) \
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) \
125 HUD_PANEL(BUFFS , HUD_Buffs , buffs)
127 #define HUD_PANEL(NAME, draw_func, name) \
128 int HUD_PANEL_##NAME; \
129 void draw_func(void); \
130 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);
142 HUD_PANELS(HUD_PANEL)
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() do { \
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); \
183 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
184 #define HUD_Panel_GetColor() do { \
185 if ((teamplay) && panel_bg_color_team) { \
186 if (autocvar__hud_configure && myteam == NUM_SPECTATOR) \
187 panel_bg_color = '1 0 0' * panel_bg_color_team; \
189 panel_bg_color = myteamcolors * panel_bg_color_team; \
190 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) { \
191 panel_bg_color = '1 0 0' * panel_bg_color_team; \
193 if (panel_bg_color_str == "") { \
194 panel_bg_color = autocvar_hud_panel_bg_color; \
196 if (panel_bg_color_str == "shirt") { \
197 panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player - 1, "colors")) / 16), 0);\
198 } else if (panel_bg_color_str == "pants") { \
199 panel_bg_color = colormapPaletteColor(stof(getplayerkeyvalue(current_player - 1, "colors")) % 16, 1);\
201 panel_bg_color = stov(panel_bg_color_str); \
207 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
208 #define HUD_Panel_GetColorTeam() do { \
209 if (panel_bg_color_team_str == "") { \
210 panel_bg_color_team = autocvar_hud_panel_bg_color_team; \
212 panel_bg_color_team = stof(panel_bg_color_team_str); \
216 // 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
217 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
218 #define HUD_Panel_GetBgAlpha() do { \
219 if (panel_bg_alpha_str == "") { \
220 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha); \
222 panel_bg_alpha = stof(panel_bg_alpha_str); \
223 if (autocvar__hud_configure) { \
224 if (!panel_enabled) \
225 panel_bg_alpha = 0.25; \
226 else if (menu_enabled == 2 && panel == highlightedPanel) \
227 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
229 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha); \
233 // Get value for panel_fg_alpha. Also do various minalpha checks
234 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
235 #define HUD_Panel_GetFgAlpha() do { \
236 panel_fg_alpha = autocvar_hud_panel_fg_alpha; \
237 if (autocvar__hud_configure && !panel_enabled) \
238 panel_fg_alpha = 0.25; \
241 // Get border. See comments above, it's similar.
242 #define HUD_Panel_GetBorder() do { \
243 if (panel_bg_border_str == "") { \
244 panel_bg_border = autocvar_hud_panel_bg_border; \
246 panel_bg_border = stof(panel_bg_border_str); \
250 // Get padding. See comments above, it's similar.
251 // 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
252 #define HUD_Panel_GetPadding() do { \
253 if (panel_bg_padding_str == "") { \
254 panel_bg_padding = autocvar_hud_panel_bg_padding; \
256 panel_bg_padding = stof(panel_bg_padding_str); \
258 panel_bg_padding = min(min(panel_size_x, panel_size_y)/2 - 5, panel_bg_padding); \
261 // return smoothly faded pos and size of given panel when a dialog is active
262 #define HUD_Panel_UpdatePosSize_ForMenu() do { \
263 vector menu_enable_pos; \
264 vector menu_enable_size = '0 0 0'; \
265 float menu_enable_maxsize_x = 0.3 * vid_conwidth; \
266 float menu_enable_maxsize_y = 0.18 * vid_conheight; \
267 if (panel_size_x > panel_size_y) { \
268 if (panel_size_y > menu_enable_maxsize_y) { \
269 menu_enable_size_y = menu_enable_maxsize_y; \
270 menu_enable_size_x = panel_size_x * (menu_enable_maxsize_y/panel_size_y); \
271 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size; \
273 menu_enable_pos = eX * 0.5 * vid_conwidth - eX * 0.5 * panel_size_x + eY * (vid_conheight - menu_enable_maxsize_y);\
275 if (panel_size_x > menu_enable_maxsize_x) { \
276 menu_enable_size_x = menu_enable_maxsize_x; \
277 menu_enable_size_y = panel_size_y * (menu_enable_maxsize_x/panel_size_x); \
278 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size; \
280 menu_enable_pos = eY * 0.5 * vid_conheight - eY * 0.5 * panel_size_y + eX * (vid_conwidth - menu_enable_maxsize_x);\
282 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_pos; \
285 // Scale the pos and size vectors to absolute coordinates
286 #define HUD_Panel_ScalePosSize() do { \
287 panel_pos_x *= vid_conwidth; panel_pos_y *= vid_conheight; \
288 panel_size_x *= vid_conwidth; panel_size_y *= vid_conheight; \
291 // NOTE: in hud_configure mode cvars must be reloaded every frame
292 #define HUD_Panel_UpdateCvars() do { \
293 if (panel.update_time <= time) { \
294 if (autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
295 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
296 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
297 HUD_Panel_ScalePosSize(); \
298 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
299 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
300 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
301 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
302 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
303 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
305 if (panel.current_panel_bg != "0") { \
306 HUD_Panel_GetColorTeam(); \
307 HUD_Panel_GetColor(); \
308 HUD_Panel_GetBgAlpha(); \
309 HUD_Panel_GetBorder(); \
311 HUD_Panel_GetFgAlpha(); \
312 HUD_Panel_GetPadding(); \
313 panel.current_panel_bg_alpha = panel_bg_alpha; \
314 panel.current_panel_fg_alpha = panel_fg_alpha; \
315 if (menu_enabled == 2 && panel == highlightedPanel) { \
316 HUD_Panel_UpdatePosSize_ForMenu(); \
318 panel_bg_alpha *= hud_fade_alpha; \
319 panel_fg_alpha *= hud_fade_alpha; \
321 panel.current_panel_pos = panel_pos; \
322 panel.current_panel_size = panel_size; \
323 panel.current_panel_bg_border = panel_bg_border; \
324 panel.current_panel_bg_color = panel_bg_color; \
325 panel.current_panel_bg_color_team = panel_bg_color_team; \
326 panel.current_panel_bg_padding = panel_bg_padding; \
327 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
329 panel_pos = panel.current_panel_pos; \
330 panel_size = panel.current_panel_size; \
331 panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha; \
332 panel_bg_border = panel.current_panel_bg_border; \
333 panel_bg_color = panel.current_panel_bg_color; \
334 panel_bg_color_team = panel.current_panel_bg_color_team; \
335 panel_bg_padding = panel.current_panel_bg_padding; \
336 panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \
340 #define HUD_Panel_UpdatePosSize() do { \
341 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
342 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
343 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
344 HUD_Panel_ScalePosSize(); \
345 if (menu_enabled == 2 && panel == highlightedPanel) { \
346 HUD_Panel_UpdatePosSize_ForMenu(); \
348 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
349 HUD_Panel_GetBorder(); \
352 const int NOTIFY_MAX_ENTRIES = 10;
353 const int NOTIFY_ICON_MARGIN = 0.02;
357 float notify_times[NOTIFY_MAX_ENTRIES];
358 string notify_attackers[NOTIFY_MAX_ENTRIES];
359 string notify_victims[NOTIFY_MAX_ENTRIES];
360 string notify_icons[NOTIFY_MAX_ENTRIES];
362 void HUD_Notify_Push(string icon, string attacker, string victim);
364 var void HUD_ModIcons_GameType(vector pos, vector size);
365 void HUD_ModIcons_SetFunc();