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
39 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
40 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
41 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
42 entity highlightedPanel;
43 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
45 const float BORDER_MULTIPLIER = 0.25;
46 float scoreboard_bottom;
47 int weapon_accuracy[WEP_MAXCOUNT];
50 string complain_weapon_name;
51 float complain_weapon_type;
52 float complain_weapon_time;
54 int ps_primary, ps_secondary;
55 int ts_primary, ts_secondary;
57 int last_switchweapon;
58 int last_activeweapon;
64 float hud_configure_checkcollisions;
65 float hud_configure_prev;
66 vector hud_configure_gridSize;
67 vector hud_configure_realGridSize;
70 const int S_SHIFT = 1;
74 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
83 entity highlightedPanel_backup;
84 vector panel_pos_backup;
85 vector panel_size_backup;
87 vector panel_size_copied;
90 entityclass(HUDPanel);
91 class(HUDPanel) .string panel_name;
92 class(HUDPanel) .int panel_id;
93 class(HUDPanel) .vector current_panel_pos;
94 class(HUDPanel) .vector current_panel_size;
95 class(HUDPanel) .string current_panel_bg;
96 class(HUDPanel) .float current_panel_bg_alpha;
97 class(HUDPanel) .float current_panel_bg_border;
98 class(HUDPanel) .vector current_panel_bg_color;
99 class(HUDPanel) .float current_panel_bg_color_team;
100 class(HUDPanel) .float current_panel_bg_padding;
101 class(HUDPanel) .float current_panel_fg_alpha;
102 class(HUDPanel) .float update_time;
106 string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
107 vector panel_bg_color;
108 string panel_bg_color_str;
109 float panel_bg_color_team;
110 string panel_bg_color_team_str;
111 float panel_fg_alpha;
112 float panel_bg_alpha;
113 string panel_bg_alpha_str;
114 float panel_bg_border;
115 string panel_bg_border_str;
116 float panel_bg_padding;
117 string panel_bg_padding_str;
119 class(HUDPanel) .void() panel_draw;
121 // chat panel can be reduced / moved while the mapvote is active
122 // let know the mapvote panel about chat pos and size
126 float current_player;
128 float GetPlayerColorForce(int i);
130 float stringwidth_colors(string s, vector theSize);
131 int GetPlayerColor(int i);
132 string GetPlayerName(int i);
133 float stringwidth_nocolors(string s, vector theSize);
134 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag);
137 // prev_* vars contain the health/armor at the previous FRAME
138 // set to -1 when player is dead or was not playing
139 int prev_health, prev_armor;
140 float health_damagetime, armor_damagetime;
141 int health_beforedamage, armor_beforedamage;
142 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
143 int old_p_health, old_p_armor;
144 float old_p_healthtime, old_p_armortime;
145 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
146 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
147 int prev_p_health, prev_p_armor;
150 #define HUD_PANELS(HUD_PANEL) \
151 HUD_PANEL(WEAPONS , HUD_Weapons , weapons) \
152 HUD_PANEL(AMMO , HUD_Ammo , ammo) \
153 HUD_PANEL(POWERUPS , HUD_Powerups , powerups) \
154 HUD_PANEL(HEALTHARMOR , HUD_HealthArmor , healtharmor) \
155 HUD_PANEL(NOTIFY , HUD_Notify , notify) \
156 HUD_PANEL(TIMER , HUD_Timer , timer) \
157 HUD_PANEL(RADAR , HUD_Radar , radar) \
158 HUD_PANEL(SCORE , HUD_Score , score) \
159 HUD_PANEL(RACETIMER , HUD_RaceTimer , racetimer) \
160 HUD_PANEL(VOTE , HUD_Vote , vote) \
161 HUD_PANEL(MODICONS , HUD_ModIcons , modicons) \
162 HUD_PANEL(PRESSEDKEYS , HUD_PressedKeys , pressedkeys) \
163 HUD_PANEL(CHAT , HUD_Chat , chat) \
164 HUD_PANEL(ENGINEINFO , HUD_EngineInfo , engineinfo) \
165 HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages) \
166 HUD_PANEL(PHYSICS , HUD_Physics , physics) \
167 HUD_PANEL(CENTERPRINT , HUD_CenterPrint , centerprint) \
168 HUD_PANEL(MAPVOTE , MapVote_Draw , mapvote) \
169 HUD_PANEL(ITEMSTIME , HUD_ItemsTime , itemstime) \
170 // always add new panels to the end of list
172 #define HUD_PANEL(NAME, draw_func, name) \
173 int HUD_PANEL_##NAME; \
174 void draw_func(void); \
175 void RegisterHUD_Panel_##NAME() { \
176 HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM; \
177 entity hud_panelent = spawn(); \
178 hud_panel[HUD_PANEL_##NAME] = hud_panelent; \
179 hud_panelent.classname = "hud_panel"; \
180 hud_panelent.panel_name = #name; \
181 hud_panelent.panel_id = HUD_PANEL_##NAME; \
182 hud_panelent.panel_draw = draw_func; \
185 ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME);
187 HUD_PANELS(HUD_PANEL)
190 #define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
193 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
194 // ----------------------
195 // MACRO HELL STARTS HERE
196 // ----------------------
197 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
199 // Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str
200 // comment on last line of macro: // we probably want to see a background in config mode at all times...
201 #define HUD_Panel_GetBg() do { \
203 if (!autocvar__hud_configure && panel_bg_str == "0") { \
206 if (panel_bg_str == "") { \
207 panel_bg_str = autocvar_hud_panel_bg; \
209 if (panel_bg_str == "0" && !autocvar__hud_configure) { \
212 if (panel_bg_str == "0" && autocvar__hud_configure) \
213 panel_bg_alpha_str = "0"; \
214 panel_bg = strcat(hud_skin_path, "/", panel_bg_str); \
215 if (precache_pic(panel_bg) == "") { \
216 panel_bg = strcat(hud_skin_path, "/", "border_default"); \
217 if (precache_pic(panel_bg) == "") { \
218 panel_bg = strcat("gfx/hud/default/", "border_default"); \
223 if (panel.current_panel_bg) \
224 strunzone(panel.current_panel_bg); \
225 panel.current_panel_bg = strzone(panel_bg); \
228 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
229 #define HUD_Panel_GetColor() do { \
230 if ((teamplay) && panel_bg_color_team) { \
231 if (autocvar__hud_configure && myteam == NUM_SPECTATOR) \
232 panel_bg_color = '1 0 0' * panel_bg_color_team; \
234 panel_bg_color = myteamcolors * panel_bg_color_team; \
235 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) { \
236 panel_bg_color = '1 0 0' * panel_bg_color_team; \
238 if (panel_bg_color_str == "") { \
239 panel_bg_color = autocvar_hud_panel_bg_color; \
241 if (panel_bg_color_str == "shirt") { \
242 panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player, "colors")) / 16), 0); \
243 } else if (panel_bg_color_str == "pants") { \
244 panel_bg_color = colormapPaletteColor(stof(getplayerkeyvalue(current_player, "colors")) % 16, 1); \
246 panel_bg_color = stov(panel_bg_color_str); \
252 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
253 #define HUD_Panel_GetColorTeam() do { \
254 if (panel_bg_color_team_str == "") { \
255 panel_bg_color_team = autocvar_hud_panel_bg_color_team; \
257 panel_bg_color_team = stof(panel_bg_color_team_str); \
261 // 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
262 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
263 #define HUD_Panel_GetBgAlpha() do { \
264 if (panel_bg_alpha_str == "") { \
265 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha); \
267 panel_bg_alpha = stof(panel_bg_alpha_str); \
268 if (autocvar__hud_configure) { \
269 if (!panel_enabled) \
270 panel_bg_alpha = 0.25; \
271 else if (menu_enabled == 2 && panel == highlightedPanel) \
272 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
274 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha); \
278 // Get value for panel_fg_alpha. Also do various minalpha checks
279 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
280 #define HUD_Panel_GetFgAlpha() do { \
281 panel_fg_alpha = autocvar_hud_panel_fg_alpha; \
282 if (autocvar__hud_configure && !panel_enabled) \
283 panel_fg_alpha = 0.25; \
286 // Get border. See comments above, it's similar.
287 #define HUD_Panel_GetBorder() do { \
288 if (panel_bg_border_str == "") { \
289 panel_bg_border = autocvar_hud_panel_bg_border; \
291 panel_bg_border = stof(panel_bg_border_str); \
295 // Get padding. See comments above, it's similar.
296 // 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
297 #define HUD_Panel_GetPadding() do { \
298 if (panel_bg_padding_str == "") { \
299 panel_bg_padding = autocvar_hud_panel_bg_padding; \
301 panel_bg_padding = stof(panel_bg_padding_str); \
303 panel_bg_padding = min(min(panel_size.x, panel_size.y)/2 - 5, panel_bg_padding); \
306 // return smoothly faded pos and size of given panel when a dialog is active
307 // don't center too wide panels, it doesn't work with different resolutions
308 #define HUD_Panel_UpdatePosSize_ForMenu() do { \
309 vector menu_enable_size = panel_size; \
310 float max_panel_width = 0.52 * vid_conwidth; \
311 if(panel_size.x > max_panel_width) \
313 menu_enable_size.x = max_panel_width; \
314 menu_enable_size.y = panel_size.y * (menu_enable_size.x / panel_size.x); \
316 vector menu_enable_pos = eX * (panel_bg_border + 0.5 * max_panel_width) + eY * 0.5 * vid_conheight - 0.5 * menu_enable_size; \
317 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_pos; \
318 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size; \
321 // Scale the pos and size vectors to absolute coordinates
322 #define HUD_Panel_ScalePosSize() do { \
323 panel_pos.x *= vid_conwidth; panel_pos.y *= vid_conheight; \
324 panel_size.x *= vid_conwidth; panel_size.y *= vid_conheight; \
327 // NOTE: in hud_configure mode cvars must be reloaded every frame
328 #define HUD_Panel_UpdateCvars() do { \
329 if (panel.update_time <= time) { \
330 if (autocvar__hud_configure) 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 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
335 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
336 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
337 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
338 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
339 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
341 if (panel.current_panel_bg != "0") { \
342 HUD_Panel_GetColorTeam(); \
343 HUD_Panel_GetColor(); \
344 HUD_Panel_GetBgAlpha(); \
345 HUD_Panel_GetBorder(); \
347 HUD_Panel_GetFgAlpha(); \
348 HUD_Panel_GetPadding(); \
349 panel.current_panel_bg_alpha = panel_bg_alpha; \
350 panel.current_panel_fg_alpha = panel_fg_alpha; \
351 if (menu_enabled == 2 && panel == highlightedPanel) { \
352 HUD_Panel_UpdatePosSize_ForMenu(); \
354 panel_bg_alpha *= hud_fade_alpha; \
355 panel_fg_alpha *= hud_fade_alpha; \
357 panel.current_panel_pos = panel_pos; \
358 panel.current_panel_size = panel_size; \
359 panel.current_panel_bg_border = panel_bg_border; \
360 panel.current_panel_bg_color = panel_bg_color; \
361 panel.current_panel_bg_color_team = panel_bg_color_team; \
362 panel.current_panel_bg_padding = panel_bg_padding; \
363 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
365 panel_pos = panel.current_panel_pos; \
366 panel_size = panel.current_panel_size; \
367 panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha; \
368 panel_bg_border = panel.current_panel_bg_border; \
369 panel_bg_color = panel.current_panel_bg_color; \
370 panel_bg_color_team = panel.current_panel_bg_color_team; \
371 panel_bg_padding = panel.current_panel_bg_padding; \
372 panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \
376 #define HUD_Panel_UpdatePosSize() do { \
377 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
378 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
379 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
380 HUD_Panel_ScalePosSize(); \
381 if (menu_enabled == 2 && panel == highlightedPanel) { \
382 HUD_Panel_UpdatePosSize_ForMenu(); \
384 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
385 HUD_Panel_GetBorder(); \
388 const int NOTIFY_MAX_ENTRIES = 10;
389 const float NOTIFY_ICON_MARGIN = 0.02;
393 float notify_times[NOTIFY_MAX_ENTRIES];
394 string notify_attackers[NOTIFY_MAX_ENTRIES];
395 string notify_victims[NOTIFY_MAX_ENTRIES];
396 string notify_icons[NOTIFY_MAX_ENTRIES];
398 void HUD_Notify_Push(string icon, string attacker, string victim);
400 var void HUD_ModIcons_GameType(vector pos, vector size);
401 void HUD_ModIcons_SetFunc();