4 #include "../common/weapons/all.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();
25 void HUD_Reset (void);
31 int vote_highlighted; // currently selected vote
33 int vote_active; // is there an active vote?
34 int vote_prev; // previous state of vote_active to check for a change
36 float vote_change; // "time" when vote_active changed
38 float hud_panel_quickmenu;
41 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
42 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
43 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
44 entity highlightedPanel;
45 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
47 const float BORDER_MULTIPLIER = 0.25;
48 float scoreboard_bottom;
49 int weapon_accuracy[WEP_MAXCOUNT];
52 string complain_weapon_name;
53 float complain_weapon_type;
54 float complain_weapon_time;
56 int ps_primary, ps_secondary;
57 int ts_primary, ts_secondary;
59 int last_switchweapon;
60 int last_activeweapon;
66 float hud_configure_checkcollisions;
67 float hud_configure_prev;
68 vector hud_configure_gridSize;
69 vector hud_configure_realGridSize;
72 const int S_SHIFT = 1;
76 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
85 entity highlightedPanel_backup;
86 vector panel_pos_backup;
87 vector panel_size_backup;
89 vector panel_size_copied;
92 entityclass(HUDPanel);
93 class(HUDPanel) .string panel_name;
94 class(HUDPanel) .int panel_id;
95 class(HUDPanel) .vector current_panel_pos;
96 class(HUDPanel) .vector current_panel_size;
97 class(HUDPanel) .string current_panel_bg;
98 class(HUDPanel) .float current_panel_bg_alpha;
99 class(HUDPanel) .float current_panel_bg_border;
100 class(HUDPanel) .vector current_panel_bg_color;
101 class(HUDPanel) .float current_panel_bg_color_team;
102 class(HUDPanel) .float current_panel_bg_padding;
103 class(HUDPanel) .float current_panel_fg_alpha;
104 class(HUDPanel) .float update_time;
108 string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
109 vector panel_bg_color;
110 string panel_bg_color_str;
111 float panel_bg_color_team;
112 string panel_bg_color_team_str;
113 float panel_fg_alpha;
114 float panel_bg_alpha;
115 string panel_bg_alpha_str;
116 float panel_bg_border;
117 string panel_bg_border_str;
118 float panel_bg_padding;
119 string panel_bg_padding_str;
121 class(HUDPanel) .void() panel_draw;
123 // chat panel can be reduced / moved while the mapvote is active
124 // let know the mapvote panel about chat pos and size
128 float current_player;
130 float stringwidth_colors(string s, vector theSize);
131 float stringwidth_nocolors(string s, vector theSize);
132 float GetPlayerColorForce(int i);
133 int GetPlayerColor(int i);
134 string GetPlayerName(int i);
135 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag);
137 .int panel_showflags;
138 const int PANEL_SHOW_NEVER = 0x00;
139 const int PANEL_SHOW_MAINGAME = 0x01;
140 const int PANEL_SHOW_MINIGAME = 0x02;
141 const int PANEL_SHOW_ALWAYS = 0xff;
142 bool HUD_Panel_CheckFlags(int showflags);
145 // prev_* vars contain the health/armor at the previous FRAME
146 // set to -1 when player is dead or was not playing
147 int prev_health, prev_armor;
148 float health_damagetime, armor_damagetime;
149 int health_beforedamage, armor_beforedamage;
150 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
151 int old_p_health, old_p_armor;
152 float old_p_healthtime, old_p_armortime;
153 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
154 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
155 int prev_p_health, prev_p_armor;
157 void HUD_ItemsTime();
159 #define HUD_PANELS(HUD_PANEL) \
160 HUD_PANEL(WEAPONS , HUD_Weapons , weapons, PANEL_SHOW_MAINGAME ) \
161 HUD_PANEL(AMMO , HUD_Ammo , ammo, PANEL_SHOW_MAINGAME ) \
162 HUD_PANEL(POWERUPS , HUD_Powerups , powerups, PANEL_SHOW_MAINGAME ) \
163 HUD_PANEL(HEALTHARMOR , HUD_HealthArmor , healtharmor, PANEL_SHOW_MAINGAME ) \
164 HUD_PANEL(NOTIFY , HUD_Notify , notify, PANEL_SHOW_ALWAYS ) \
165 HUD_PANEL(TIMER , HUD_Timer , timer, PANEL_SHOW_ALWAYS ) \
166 HUD_PANEL(RADAR , HUD_Radar , radar, PANEL_SHOW_MAINGAME ) \
167 HUD_PANEL(SCORE , HUD_Score , score, PANEL_SHOW_ALWAYS ) \
168 HUD_PANEL(RACETIMER , HUD_RaceTimer , racetimer, PANEL_SHOW_MAINGAME ) \
169 HUD_PANEL(VOTE , HUD_Vote , vote, PANEL_SHOW_ALWAYS ) \
170 HUD_PANEL(MODICONS , HUD_ModIcons , modicons, PANEL_SHOW_MAINGAME ) \
171 HUD_PANEL(PRESSEDKEYS , HUD_PressedKeys , pressedkeys, PANEL_SHOW_MAINGAME ) \
172 HUD_PANEL(CHAT , HUD_Chat , chat, PANEL_SHOW_ALWAYS ) \
173 HUD_PANEL(ENGINEINFO , HUD_EngineInfo , engineinfo, PANEL_SHOW_ALWAYS ) \
174 HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages, PANEL_SHOW_MAINGAME ) \
175 HUD_PANEL(PHYSICS , HUD_Physics , physics, PANEL_SHOW_MAINGAME ) \
176 HUD_PANEL(CENTERPRINT , HUD_CenterPrint , centerprint, PANEL_SHOW_MAINGAME ) \
177 HUD_PANEL(MINIGAME_BOARD, HUD_MinigameBoard ,minigameboard, PANEL_SHOW_MINIGAME ) \
178 HUD_PANEL(MINIGAME_STATUS,HUD_MinigameStatus,minigamestatus,PANEL_SHOW_MINIGAME ) \
179 HUD_PANEL(MINIGAME_HELP, HUD_MinigameHelp ,minigamehelp, PANEL_SHOW_MINIGAME ) \
180 HUD_PANEL(MINIGAME_MENU, HUD_MinigameMenu ,minigamemenu, PANEL_SHOW_ALWAYS ) \
181 HUD_PANEL(MAPVOTE , MapVote_Draw ,mapvote, PANEL_SHOW_ALWAYS ) \
182 HUD_PANEL(ITEMSTIME , HUD_ItemsTime ,itemstime, PANEL_SHOW_MAINGAME ) \
183 HUD_PANEL(QUICKMENU , HUD_QuickMenu , quickmenu, PANEL_SHOW_MAINGAME ) \
184 // always add new panels to the end of list
187 #define HUD_PANEL(NAME, draw_func, name, showflags) \
188 int HUD_PANEL_##NAME; \
189 void draw_func(void); \
190 void RegisterHUD_Panel_##NAME() { \
191 HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM; \
192 entity hud_panelent = spawn(); \
193 hud_panel[HUD_PANEL_##NAME] = hud_panelent; \
194 hud_panelent.classname = "hud_panel"; \
195 hud_panelent.panel_name = #name; \
196 hud_panelent.panel_id = HUD_PANEL_##NAME; \
197 hud_panelent.panel_draw = draw_func; \
198 hud_panelent.panel_showflags = showflags; \
201 ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME);
203 HUD_PANELS(HUD_PANEL)
206 #define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
209 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
210 // ----------------------
211 // MACRO HELL STARTS HERE
212 // ----------------------
213 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
215 // Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str
216 // comment on last line of macro: // we probably want to see a background in config mode at all times...
217 #define HUD_Panel_GetBg() do { \
219 if (!autocvar__hud_configure && panel_bg_str == "0") { \
222 if (panel_bg_str == "") { \
223 panel_bg_str = autocvar_hud_panel_bg; \
225 if (panel_bg_str == "0" && !autocvar__hud_configure) { \
228 if (panel_bg_str == "0" && autocvar__hud_configure) \
229 panel_bg_alpha_str = "0"; \
230 panel_bg = strcat(hud_skin_path, "/", panel_bg_str); \
231 if (precache_pic(panel_bg) == "") { \
232 panel_bg = strcat(hud_skin_path, "/", "border_default"); \
233 if (precache_pic(panel_bg) == "") { \
234 panel_bg = strcat("gfx/hud/default/", "border_default"); \
239 if (panel.current_panel_bg) \
240 strunzone(panel.current_panel_bg); \
241 panel.current_panel_bg = strzone(panel_bg); \
244 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
245 #define HUD_Panel_GetColor() do { \
246 if ((teamplay) && panel_bg_color_team) { \
247 if (autocvar__hud_configure && myteam == NUM_SPECTATOR) \
248 panel_bg_color = '1 0 0' * panel_bg_color_team; \
250 panel_bg_color = myteamcolors * panel_bg_color_team; \
251 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) { \
252 panel_bg_color = '1 0 0' * panel_bg_color_team; \
254 if (panel_bg_color_str == "") { \
255 panel_bg_color = autocvar_hud_panel_bg_color; \
257 if (panel_bg_color_str == "shirt") { \
258 panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player, "colors")) / 16), 0); \
259 } else if (panel_bg_color_str == "pants") { \
260 panel_bg_color = colormapPaletteColor(stof(getplayerkeyvalue(current_player, "colors")) % 16, 1); \
262 panel_bg_color = stov(panel_bg_color_str); \
268 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
269 #define HUD_Panel_GetColorTeam() do { \
270 if (panel_bg_color_team_str == "") { \
271 panel_bg_color_team = autocvar_hud_panel_bg_color_team; \
273 panel_bg_color_team = stof(panel_bg_color_team_str); \
277 // 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
278 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
279 #define HUD_Panel_GetBgAlpha() do { \
280 if (panel_bg_alpha_str == "") { \
281 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha); \
283 panel_bg_alpha = stof(panel_bg_alpha_str); \
284 if (autocvar__hud_configure) { \
285 if (!panel_enabled) \
286 panel_bg_alpha = 0.25; \
287 else if (menu_enabled == 2 && panel == highlightedPanel) \
288 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
290 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha); \
294 // Get value for panel_fg_alpha. Also do various minalpha checks
295 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
296 #define HUD_Panel_GetFgAlpha() do { \
297 panel_fg_alpha = autocvar_hud_panel_fg_alpha; \
298 if (autocvar__hud_configure && !panel_enabled) \
299 panel_fg_alpha = 0.25; \
302 // Get border. See comments above, it's similar.
303 #define HUD_Panel_GetBorder() do { \
304 if (panel_bg_border_str == "") { \
305 panel_bg_border = autocvar_hud_panel_bg_border; \
307 panel_bg_border = stof(panel_bg_border_str); \
311 // Get padding. See comments above, it's similar.
312 // 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
313 #define HUD_Panel_GetPadding() do { \
314 if (panel_bg_padding_str == "") { \
315 panel_bg_padding = autocvar_hud_panel_bg_padding; \
317 panel_bg_padding = stof(panel_bg_padding_str); \
319 panel_bg_padding = min(min(panel_size.x, panel_size.y)/2 - 5, panel_bg_padding); \
322 // return smoothly faded pos and size of given panel when a dialog is active
323 // don't center too wide panels, it doesn't work with different resolutions
324 #define HUD_Panel_UpdatePosSize_ForMenu() do { \
325 vector menu_enable_size = panel_size; \
326 float max_panel_width = 0.52 * vid_conwidth; \
327 if(panel_size.x > max_panel_width) \
329 menu_enable_size.x = max_panel_width; \
330 menu_enable_size.y = panel_size.y * (menu_enable_size.x / panel_size.x); \
332 vector menu_enable_pos = eX * (panel_bg_border + 0.5 * max_panel_width) + eY * 0.5 * vid_conheight - 0.5 * menu_enable_size; \
333 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_pos; \
334 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size; \
337 // Scale the pos and size vectors to absolute coordinates
338 #define HUD_Panel_ScalePosSize() do { \
339 panel_pos.x *= vid_conwidth; panel_pos.y *= vid_conheight; \
340 panel_size.x *= vid_conwidth; panel_size.y *= vid_conheight; \
343 // NOTE: in hud_configure mode cvars must be reloaded every frame
344 #define HUD_Panel_UpdateCvars() do { \
345 if (panel.update_time <= time) { \
346 if (autocvar__hud_configure) 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 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
351 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
352 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
353 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
354 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
355 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
357 if (panel.current_panel_bg != "0") { \
358 HUD_Panel_GetColorTeam(); \
359 HUD_Panel_GetColor(); \
360 HUD_Panel_GetBgAlpha(); \
361 HUD_Panel_GetBorder(); \
363 HUD_Panel_GetFgAlpha(); \
364 HUD_Panel_GetPadding(); \
365 panel.current_panel_bg_alpha = panel_bg_alpha; \
366 panel.current_panel_fg_alpha = panel_fg_alpha; \
367 if (menu_enabled == 2 && panel == highlightedPanel) { \
368 HUD_Panel_UpdatePosSize_ForMenu(); \
370 panel_bg_alpha *= hud_fade_alpha; \
371 panel_fg_alpha *= hud_fade_alpha; \
373 panel.current_panel_pos = panel_pos; \
374 panel.current_panel_size = panel_size; \
375 panel.current_panel_bg_border = panel_bg_border; \
376 panel.current_panel_bg_color = panel_bg_color; \
377 panel.current_panel_bg_color_team = panel_bg_color_team; \
378 panel.current_panel_bg_padding = panel_bg_padding; \
379 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
381 panel_pos = panel.current_panel_pos; \
382 panel_size = panel.current_panel_size; \
383 panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha; \
384 panel_bg_border = panel.current_panel_bg_border; \
385 panel_bg_color = panel.current_panel_bg_color; \
386 panel_bg_color_team = panel.current_panel_bg_color_team; \
387 panel_bg_padding = panel.current_panel_bg_padding; \
388 panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \
392 #define HUD_Panel_UpdatePosSize() do { \
393 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
394 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
395 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
396 HUD_Panel_ScalePosSize(); \
397 if (menu_enabled == 2 && panel == highlightedPanel) { \
398 HUD_Panel_UpdatePosSize_ForMenu(); \
400 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
401 HUD_Panel_GetBorder(); \
404 const int NOTIFY_MAX_ENTRIES = 10;
405 const float NOTIFY_ICON_MARGIN = 0.02;
409 float notify_times[NOTIFY_MAX_ENTRIES];
410 string notify_attackers[NOTIFY_MAX_ENTRIES];
411 string notify_victims[NOTIFY_MAX_ENTRIES];
412 string notify_icons[NOTIFY_MAX_ENTRIES];
414 void HUD_Notify_Push(string icon, string attacker, string victim);
416 var void HUD_ModIcons_GameType(vector pos, vector size);
417 void HUD_ModIcons_SetFunc();