3 #include <common/weapons/_all.qh>
5 bool HUD_Radar_Clickable();
6 void HUD_Radar_Mouse();
8 REGISTRY(hud_panels, BITS(6))
9 #define hud_panels_from(i) _hud_panels_from(i, NULL)
10 REGISTER_REGISTRY(hud_panels)
12 #define REGISTER_HUD_PANEL(id, draw_func, name, configflags, showflags) \
14 REGISTER(hud_panels, HUD_PANEL, id, m_id, new_pure(hud_panel)) { \
15 this.panel_id = this.m_id; \
16 this.panel_draw = draw_func; \
17 this.panel_name = #name; \
18 this.panel_configflags = configflags; \
19 this.panel_showflags = showflags; \
22 #define HUD_PANEL(NAME) HUD_PANEL_##NAME
24 // draw the background/borders
25 #define HUD_Panel_DrawBg(theAlpha) MACRO_BEGIN { \
26 if(panel.current_panel_bg != "0" && panel.current_panel_bg != "") \
28 HUD_Shift(panel_pos - '1 1 0' * panel_bg_border), \
29 panel.current_panel_bg, \
30 HUD_Scale(panel_size + '1 1 0' * 2 * panel_bg_border), \
32 panel_bg_alpha * theAlpha, \
33 HUD_Scale('1 1 0' * (panel_bg_border/BORDER_MULTIPLIER)) \
37 int panel_order[hud_panels_MAX];
38 string hud_panelorder_prev;
40 bool hud_draw_maximized;
41 bool hud_panel_radar_maximized;
42 bool hud_panel_radar_mouse;
43 float hud_panel_radar_bottom;
44 bool hud_panel_radar_temp_hidden;
45 bool chat_panel_modified;
46 bool radar_panel_modified;
48 float HUD_Radar_InputEvent(float bInputType, float nPrimary, float nSecondary);
49 void HUD_Radar_Hide_Maximized();
51 float HUD_GetRowCount(int item_count, vector size, float item_aspect);
52 vector HUD_Get_Num_Color (float x, float maxvalue);
53 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha);
54 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha, float fadelerp);
55 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag);
56 vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect);
61 int race_CheckName(string net_name);
62 string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname);
67 int vote_highlighted; // currently selected vote
69 int vote_active; // is there an active vote?
70 int vote_prev; // previous state of vote_active to check for a change
72 float vote_change; // "time" when vote_active changed
74 float hud_panel_quickmenu;
77 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
78 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
79 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
80 entity highlightedPanel;
81 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
83 const float BORDER_MULTIPLIER = 0.25;
84 float scoreboard_bottom;
85 int weapon_accuracy[Weapons_MAX];
88 float complain_weapon_type;
89 float complain_weapon_time;
91 PlayerScoreField ps_primary, ps_secondary;
92 int ts_primary, ts_secondary;
94 Weapon last_switchweapon;
95 Weapon last_activeweapon;
102 const int S_SHIFT = 1;
103 const int S_CTRL = 2;
106 float hud_fade_alpha;
108 string hud_skin_path;
109 string hud_skin_prev;
113 entity highlightedPanel_backup;
114 vector panel_pos_backup;
115 vector panel_size_backup;
117 vector panel_size_copied;
120 entityclass(HUDPanel);
121 class(HUDPanel) .string panel_name;
122 class(HUDPanel) .int panel_id;
123 class(HUDPanel) .vector current_panel_pos;
124 class(HUDPanel) .vector current_panel_size;
125 class(HUDPanel) .string current_panel_bg;
126 class(HUDPanel) .float current_panel_bg_alpha;
127 class(HUDPanel) .float current_panel_bg_border;
128 class(HUDPanel) .vector current_panel_bg_color;
129 class(HUDPanel) .float current_panel_bg_color_team;
130 class(HUDPanel) .float current_panel_bg_padding;
131 class(HUDPanel) .float current_panel_fg_alpha;
132 class(HUDPanel) .float update_time;
136 string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
137 vector panel_bg_color;
138 string panel_bg_color_str;
139 float panel_bg_color_team;
140 string panel_bg_color_team_str;
141 float panel_fg_alpha;
142 float panel_bg_alpha;
143 string panel_bg_alpha_str;
144 float panel_bg_border;
145 string panel_bg_border_str;
146 float panel_bg_padding;
147 string panel_bg_padding_str;
149 class(HUDPanel) .void() panel_draw;
151 // chat panel can be reduced / moved while the mapvote is active
152 // let know the mapvote panel about chat pos and size
156 float current_player;
158 float autocvar_hud_dynamic_follow;
159 float autocvar_hud_dynamic_follow_scale;
160 vector autocvar_hud_dynamic_follow_scale_xyz;
162 vector hud_dynamic_shake_realofs;
163 float hud_dynamic_shake_factor;
164 float hud_dynamic_shake_time;
166 // shared across viewmodel effects and dynamic hud code
167 vector cl_followmodel_ofs;
168 float cl_followmodel_time;
171 vector hud_scale_current;
173 vector hud_shift_current;
174 vector hud_scale_center;
176 float stringwidth_colors(string s, vector theSize);
177 float stringwidth_nocolors(string s, vector theSize);
178 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag);
180 .int panel_showflags;
181 const int PANEL_SHOW_NEVER = 0x00;
182 const int PANEL_SHOW_MAINGAME = 0x01;
183 const int PANEL_SHOW_MINIGAME = 0x02;
184 const int PANEL_SHOW_MAPVOTE = 0x04;
185 const int PANEL_SHOW_ALWAYS = 0xff;
186 bool HUD_Panel_CheckFlags(int showflags);
188 .int panel_configflags;
189 const int PANEL_CONFIG_NO = 0x00;
190 const int PANEL_CONFIG_MAIN = 0x01;
193 // prev_* vars contain the health/armor at the previous FRAME
194 // set to -1 when player is dead or was not playing
195 int prev_health, prev_armor;
196 float health_damagetime, armor_damagetime;
197 int health_beforedamage, armor_beforedamage;
198 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
199 int old_p_health, old_p_armor;
200 float old_p_healthtime, old_p_armortime;
201 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
202 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
203 int prev_p_health, prev_p_armor;
205 void HUD_ItemsTime();
207 REGISTER_HUD_PANEL(WEAPONS, HUD_Weapons, weapons, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
208 REGISTER_HUD_PANEL(AMMO, HUD_Ammo, ammo, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
209 REGISTER_HUD_PANEL(POWERUPS, HUD_Powerups, powerups, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
210 REGISTER_HUD_PANEL(HEALTHARMOR, HUD_HealthArmor, healtharmor, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
211 REGISTER_HUD_PANEL(NOTIFY, HUD_Notify, notify, PANEL_CONFIG_MAIN, PANEL_SHOW_ALWAYS & ~PANEL_SHOW_MAPVOTE)
212 REGISTER_HUD_PANEL(TIMER, HUD_Timer, timer, PANEL_CONFIG_MAIN, PANEL_SHOW_ALWAYS & ~PANEL_SHOW_MAPVOTE)
213 REGISTER_HUD_PANEL(RADAR, HUD_Radar, radar, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
214 REGISTER_HUD_PANEL(SCORE, HUD_Score, score, PANEL_CONFIG_MAIN, PANEL_SHOW_ALWAYS & ~PANEL_SHOW_MAPVOTE)
215 REGISTER_HUD_PANEL(RACETIMER, HUD_RaceTimer, racetimer, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
216 REGISTER_HUD_PANEL(VOTE, HUD_Vote, vote, PANEL_CONFIG_MAIN, PANEL_SHOW_ALWAYS )
217 REGISTER_HUD_PANEL(MODICONS, HUD_ModIcons, modicons, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
218 REGISTER_HUD_PANEL(PRESSEDKEYS, HUD_PressedKeys, pressedkeys, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
219 REGISTER_HUD_PANEL(CHAT, HUD_Chat, chat, PANEL_CONFIG_MAIN, PANEL_SHOW_ALWAYS )
220 REGISTER_HUD_PANEL(ENGINEINFO, HUD_EngineInfo, engineinfo, PANEL_CONFIG_MAIN, PANEL_SHOW_ALWAYS )
221 REGISTER_HUD_PANEL(INFOMESSAGES, HUD_InfoMessages, infomessages, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
222 REGISTER_HUD_PANEL(PHYSICS, HUD_Physics, physics, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
223 REGISTER_HUD_PANEL(CENTERPRINT, HUD_CenterPrint, centerprint, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
224 REGISTER_HUD_PANEL(MINIGAME_BOARD, HUD_MinigameBoard, minigameboard, PANEL_CONFIG_NO , PANEL_SHOW_MINIGAME)
225 REGISTER_HUD_PANEL(MINIGAME_STATUS, HUD_MinigameStatus, minigamestatus, PANEL_CONFIG_NO , PANEL_SHOW_MINIGAME)
226 REGISTER_HUD_PANEL(MINIGAME_HELP, HUD_MinigameHelp, minigamehelp, PANEL_CONFIG_NO , PANEL_SHOW_MINIGAME)
227 REGISTER_HUD_PANEL(MINIGAME_MENU, HUD_MinigameMenu, minigamemenu, PANEL_CONFIG_NO , PANEL_SHOW_ALWAYS )
228 REGISTER_HUD_PANEL(MAPVOTE, MapVote_Draw, mapvote, PANEL_CONFIG_NO , PANEL_SHOW_MAPVOTE )
229 REGISTER_HUD_PANEL(ITEMSTIME, HUD_ItemsTime, itemstime, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
230 REGISTER_HUD_PANEL(QUICKMENU, HUD_QuickMenu, quickmenu, PANEL_CONFIG_MAIN, PANEL_SHOW_MAINGAME)
231 REGISTER_HUD_PANEL(SCOREBOARD, Scoreboard_Draw, scoreboard, PANEL_CONFIG_NO , PANEL_SHOW_ALWAYS )
232 // always add new panels to the end of list
234 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
235 // ----------------------
236 // MACRO HELL STARTS HERE
237 // ----------------------
238 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
240 // Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str
241 // comment on last line of macro: // we probably want to see a background in config mode at all times...
242 #define HUD_Panel_GetBg() MACRO_BEGIN { \
244 if (!autocvar__hud_configure && panel_bg_str == "0") { \
247 if (panel_bg_str == "") { \
248 panel_bg_str = autocvar_hud_panel_bg; \
250 if (panel_bg_str == "0" && !autocvar__hud_configure) { \
253 if (panel_bg_str == "0" && autocvar__hud_configure) \
254 panel_bg_alpha_str = "0"; \
255 panel_bg = strcat(hud_skin_path, "/", panel_bg_str); \
256 if (precache_pic(panel_bg) == "") { \
257 panel_bg = strcat(hud_skin_path, "/", "border_default"); \
258 if (precache_pic(panel_bg) == "") { \
259 panel_bg = strcat("gfx/hud/default/", "border_default"); \
264 if (panel.current_panel_bg) \
265 strunzone(panel.current_panel_bg); \
266 panel.current_panel_bg = strzone(panel_bg); \
269 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
270 #define HUD_Panel_GetColor() MACRO_BEGIN { \
271 if ((teamplay) && panel_bg_color_team > 0) { \
272 if (autocvar__hud_configure && myteam == NUM_SPECTATOR) \
273 panel_bg_color = '1 0 0' * panel_bg_color_team; \
275 panel_bg_color = myteamcolors * panel_bg_color_team; \
276 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team > 0) { \
277 panel_bg_color = '1 0 0' * panel_bg_color_team; \
279 if (panel_bg_color_str == "") { \
280 panel_bg_color = autocvar_hud_panel_bg_color; \
282 if (panel_bg_color_str == "shirt") { \
283 panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player, "colors")) / 16), 0); \
284 } else if (panel_bg_color_str == "pants") { \
285 panel_bg_color = colormapPaletteColor(stof(getplayerkeyvalue(current_player, "colors")) % 16, 1); \
287 panel_bg_color = stov(panel_bg_color_str); \
293 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
294 #define HUD_Panel_GetColorTeam() MACRO_BEGIN { \
295 if (panel_bg_color_team_str == "") { \
296 panel_bg_color_team = autocvar_hud_panel_bg_color_team; \
298 panel_bg_color_team = stof(panel_bg_color_team_str); \
302 // 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
303 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
304 #define HUD_Panel_GetBgAlpha() MACRO_BEGIN { \
305 if (panel_bg_alpha_str == "") { \
306 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha); \
308 panel_bg_alpha = stof(panel_bg_alpha_str); \
309 if (autocvar__hud_configure) { \
310 if (!panel_enabled) \
311 panel_bg_alpha = 0.25; \
312 else if (hud_configure_menu_open == 2 && panel == highlightedPanel) \
313 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
315 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha); \
319 // Get value for panel_fg_alpha. Also do various minalpha checks
320 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
321 #define HUD_Panel_GetFgAlpha() MACRO_BEGIN { \
322 panel_fg_alpha = autocvar_hud_panel_fg_alpha; \
323 if (autocvar__hud_configure && !panel_enabled) \
324 panel_fg_alpha = 0.25; \
327 // Get border. See comments above, it's similar.
328 #define HUD_Panel_GetBorder() MACRO_BEGIN { \
329 if (panel_bg_border_str == "") { \
330 panel_bg_border = autocvar_hud_panel_bg_border; \
332 panel_bg_border = stof(panel_bg_border_str); \
336 // Get padding. See comments above, it's similar.
337 // 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
338 #define HUD_Panel_GetPadding() MACRO_BEGIN { \
339 if (panel_bg_padding_str == "") { \
340 panel_bg_padding = autocvar_hud_panel_bg_padding; \
342 panel_bg_padding = stof(panel_bg_padding_str); \
344 panel_bg_padding = min(min(panel_size.x, panel_size.y)/2 - 5, panel_bg_padding); \
347 // return smoothly faded pos and size of given panel when a dialog is active
348 // don't center too wide panels, it doesn't work with different resolutions
349 #define HUD_Panel_UpdatePosSize_ForMenu() MACRO_BEGIN { \
350 vector new_size = panel_size; \
351 float max_panel_width = 0.52 * vid_conwidth; \
352 if(panel_size.x > max_panel_width) \
354 new_size.x = max_panel_width; \
355 new_size.y = panel_size.y * (new_size.x / panel_size.x); \
357 vector new_pos = eX * (panel_bg_border + 0.5 * max_panel_width) + eY * 0.5 * vid_conheight - 0.5 * new_size; \
358 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * new_pos; \
359 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * new_size; \
362 // Scale the pos and size vectors to absolute coordinates
363 #define HUD_Panel_ScalePosSize() MACRO_BEGIN { \
364 panel_pos.x *= vid_conwidth; panel_pos.y *= vid_conheight; \
365 panel_size.x *= vid_conwidth; panel_size.y *= vid_conheight; \
368 // NOTE: in hud_configure mode cvars must be reloaded every frame
369 #define HUD_Panel_UpdateCvars() MACRO_BEGIN { \
370 if (panel.update_time <= time) { \
371 if (autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
372 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
373 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
374 HUD_Panel_ScalePosSize(); \
375 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
376 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
377 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
378 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
379 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
380 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
382 if (panel.current_panel_bg != "0") { \
383 HUD_Panel_GetBgAlpha(); \
384 HUD_Panel_GetBorder(); \
386 HUD_Panel_GetColorTeam(); \
387 HUD_Panel_GetColor(); \
388 HUD_Panel_GetFgAlpha(); \
389 HUD_Panel_GetPadding(); \
390 panel.current_panel_bg_alpha = panel_bg_alpha; \
391 panel.current_panel_fg_alpha = panel_fg_alpha; \
392 if (hud_configure_menu_open == 2 && panel == highlightedPanel) { \
393 HUD_Panel_UpdatePosSize_ForMenu(); \
395 panel_bg_alpha *= hud_fade_alpha; \
396 panel_fg_alpha *= hud_fade_alpha; \
398 panel.current_panel_pos = panel_pos; \
399 panel.current_panel_size = panel_size; \
400 panel.current_panel_bg_border = panel_bg_border; \
401 panel.current_panel_bg_color = panel_bg_color; \
402 panel.current_panel_bg_color_team = panel_bg_color_team; \
403 panel.current_panel_bg_padding = panel_bg_padding; \
404 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
406 panel_pos = panel.current_panel_pos; \
407 panel_size = panel.current_panel_size; \
408 panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha; \
409 panel_bg_border = panel.current_panel_bg_border; \
410 panel_bg_color = panel.current_panel_bg_color; \
411 panel_bg_color_team = panel.current_panel_bg_color_team; \
412 panel_bg_padding = panel.current_panel_bg_padding; \
413 panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \
417 #define HUD_Panel_UpdatePosSize() MACRO_BEGIN { \
418 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
419 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
420 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
421 HUD_Panel_ScalePosSize(); \
422 if (hud_configure_menu_open == 2 && panel == highlightedPanel) { \
423 HUD_Panel_UpdatePosSize_ForMenu(); \
425 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
426 HUD_Panel_GetBorder(); \
429 const int NOTIFY_MAX_ENTRIES = 10;
430 const float NOTIFY_ICON_MARGIN = 0.02;
434 float notify_times[NOTIFY_MAX_ENTRIES];
435 string notify_attackers[NOTIFY_MAX_ENTRIES];
436 string notify_victims[NOTIFY_MAX_ENTRIES];
437 string notify_icons[NOTIFY_MAX_ENTRIES];
439 void HUD_Notify_Push(string icon, string attacker, string victim);
441 var void HUD_ModIcons_GameType(vector pos, vector size);
442 void HUD_ModIcons_SetFunc();