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 void HUD_Reset (void);
21 int vote_highlighted; // currently selected vote
23 int vote_active; // is there an active vote?
24 int vote_prev; // previous state of vote_active to check for a change
26 float vote_change; // "time" when vote_active changed
28 float hud_draw_maximized;
29 float hud_panel_radar_maximized;
30 float chat_panel_modified;
31 float radar_panel_modified;
34 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
35 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
36 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
37 entity highlightedPanel;
38 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
40 const float BORDER_MULTIPLIER = 0.25;
41 float scoreboard_bottom;
42 int weapon_accuracy[WEP_MAXCOUNT];
45 string complain_weapon_name;
46 float complain_weapon_type;
47 float complain_weapon_time;
49 int ps_primary, ps_secondary;
50 int ts_primary, ts_secondary;
52 int last_switchweapon;
53 int last_activeweapon;
59 float hud_configure_checkcollisions;
60 float hud_configure_prev;
61 vector hud_configure_gridSize;
62 vector hud_configure_realGridSize;
65 const int S_SHIFT = 1;
69 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
78 entity highlightedPanel_backup;
79 vector panel_pos_backup;
80 vector panel_size_backup;
82 vector panel_size_copied;
85 entityclass(HUDPanel);
86 class(HUDPanel) .string panel_name;
87 class(HUDPanel) .int panel_id;
88 class(HUDPanel) .vector current_panel_pos;
89 class(HUDPanel) .vector current_panel_size;
90 class(HUDPanel) .string current_panel_bg;
91 class(HUDPanel) .float current_panel_bg_alpha;
92 class(HUDPanel) .float current_panel_bg_border;
93 class(HUDPanel) .vector current_panel_bg_color;
94 class(HUDPanel) .float current_panel_bg_color_team;
95 class(HUDPanel) .float current_panel_bg_padding;
96 class(HUDPanel) .float current_panel_fg_alpha;
97 class(HUDPanel) .float update_time;
101 string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
102 vector panel_bg_color;
103 string panel_bg_color_str;
104 float panel_bg_color_team;
105 string panel_bg_color_team_str;
106 float panel_fg_alpha;
107 float panel_bg_alpha;
108 string panel_bg_alpha_str;
109 float panel_bg_border;
110 string panel_bg_border_str;
111 float panel_bg_padding;
112 string panel_bg_padding_str;
114 class(HUDPanel) .void() panel_draw;
116 float current_player;
118 float GetPlayerColorForce(int i);
120 float stringwidth_colors(string s, vector theSize);
121 int GetPlayerColor(int i);
122 string GetPlayerName(int i);
123 float stringwidth_nocolors(string s, vector theSize);
124 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag);
127 // prev_* vars contain the health/armor at the previous FRAME
128 // set to -1 when player is dead or was not playing
129 int prev_health, prev_armor;
130 float health_damagetime, armor_damagetime;
131 int health_beforedamage, armor_beforedamage;
132 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
133 int old_p_health, old_p_armor;
134 float old_p_healthtime, old_p_armortime;
135 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
136 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
137 int prev_p_health, prev_p_armor;
140 #define HUD_PANELS(HUD_PANEL) \
141 HUD_PANEL(WEAPONS , HUD_Weapons , weapons) \
142 HUD_PANEL(AMMO , HUD_Ammo , ammo) \
143 HUD_PANEL(POWERUPS , HUD_Powerups , powerups) \
144 HUD_PANEL(HEALTHARMOR , HUD_HealthArmor , healtharmor) \
145 HUD_PANEL(NOTIFY , HUD_Notify , notify) \
146 HUD_PANEL(TIMER , HUD_Timer , timer) \
147 HUD_PANEL(RADAR , HUD_Radar , radar) \
148 HUD_PANEL(SCORE , HUD_Score , score) \
149 HUD_PANEL(RACETIMER , HUD_RaceTimer , racetimer) \
150 HUD_PANEL(VOTE , HUD_Vote , vote) \
151 HUD_PANEL(MODICONS , HUD_ModIcons , modicons) \
152 HUD_PANEL(PRESSEDKEYS , HUD_PressedKeys , pressedkeys) \
153 HUD_PANEL(CHAT , HUD_Chat , chat) \
154 HUD_PANEL(ENGINEINFO , HUD_EngineInfo , engineinfo) \
155 HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages) \
156 HUD_PANEL(PHYSICS , HUD_Physics , physics) \
157 HUD_PANEL(CENTERPRINT , HUD_CenterPrint , centerprint) \
158 HUD_PANEL(BUFFS , HUD_Buffs , buffs)
160 #define HUD_PANEL(NAME, draw_func, name) \
161 int HUD_PANEL_##NAME; \
162 void draw_func(void); \
163 void RegisterHUD_Panel_##NAME() { \
164 HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM; \
165 entity hud_panelent = spawn(); \
166 hud_panel[HUD_PANEL_##NAME] = hud_panelent; \
167 hud_panelent.classname = "hud_panel"; \
168 hud_panelent.panel_name = #name; \
169 hud_panelent.panel_id = HUD_PANEL_##NAME; \
170 hud_panelent.panel_draw = draw_func; \
173 ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME);
175 HUD_PANELS(HUD_PANEL)
178 #define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
181 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
182 // ----------------------
183 // MACRO HELL STARTS HERE
184 // ----------------------
185 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
187 // Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str
188 // comment on last line of macro: // we probably want to see a background in config mode at all times...
189 #define HUD_Panel_GetBg() do { \
191 if (!autocvar__hud_configure && panel_bg_str == "0") { \
194 if (panel_bg_str == "") { \
195 panel_bg_str = autocvar_hud_panel_bg; \
197 if (panel_bg_str == "0" && !autocvar__hud_configure) { \
200 if (panel_bg_str == "0" && autocvar__hud_configure) \
201 panel_bg_alpha_str = "0"; \
202 panel_bg = strcat(hud_skin_path, "/", panel_bg_str); \
203 if (precache_pic(panel_bg) == "") { \
204 panel_bg = strcat(hud_skin_path, "/", "border_default"); \
205 if (precache_pic(panel_bg) == "") { \
206 panel_bg = strcat("gfx/hud/default/", "border_default"); \
211 if (panel.current_panel_bg) \
212 strunzone(panel.current_panel_bg); \
213 panel.current_panel_bg = strzone(panel_bg); \
216 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
217 #define HUD_Panel_GetColor() do { \
218 if ((teamplay) && panel_bg_color_team) { \
219 if (autocvar__hud_configure && myteam == NUM_SPECTATOR) \
220 panel_bg_color = '1 0 0' * panel_bg_color_team; \
222 panel_bg_color = myteamcolors * panel_bg_color_team; \
223 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) { \
224 panel_bg_color = '1 0 0' * panel_bg_color_team; \
226 if (panel_bg_color_str == "") { \
227 panel_bg_color = autocvar_hud_panel_bg_color; \
229 if (panel_bg_color_str == "shirt") { \
230 panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player - 1, "colors")) / 16), 0);\
231 } else if (panel_bg_color_str == "pants") { \
232 panel_bg_color = colormapPaletteColor(stof(getplayerkeyvalue(current_player - 1, "colors")) % 16, 1);\
234 panel_bg_color = stov(panel_bg_color_str); \
240 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
241 #define HUD_Panel_GetColorTeam() do { \
242 if (panel_bg_color_team_str == "") { \
243 panel_bg_color_team = autocvar_hud_panel_bg_color_team; \
245 panel_bg_color_team = stof(panel_bg_color_team_str); \
249 // 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
250 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
251 #define HUD_Panel_GetBgAlpha() do { \
252 if (panel_bg_alpha_str == "") { \
253 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha); \
255 panel_bg_alpha = stof(panel_bg_alpha_str); \
256 if (autocvar__hud_configure) { \
257 if (!panel_enabled) \
258 panel_bg_alpha = 0.25; \
259 else if (menu_enabled == 2 && panel == highlightedPanel) \
260 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
262 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha); \
266 // Get value for panel_fg_alpha. Also do various minalpha checks
267 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
268 #define HUD_Panel_GetFgAlpha() do { \
269 panel_fg_alpha = autocvar_hud_panel_fg_alpha; \
270 if (autocvar__hud_configure && !panel_enabled) \
271 panel_fg_alpha = 0.25; \
274 // Get border. See comments above, it's similar.
275 #define HUD_Panel_GetBorder() do { \
276 if (panel_bg_border_str == "") { \
277 panel_bg_border = autocvar_hud_panel_bg_border; \
279 panel_bg_border = stof(panel_bg_border_str); \
283 // Get padding. See comments above, it's similar.
284 // 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
285 #define HUD_Panel_GetPadding() do { \
286 if (panel_bg_padding_str == "") { \
287 panel_bg_padding = autocvar_hud_panel_bg_padding; \
289 panel_bg_padding = stof(panel_bg_padding_str); \
291 panel_bg_padding = min(min(panel_size.x, panel_size.y)/2 - 5, panel_bg_padding); \
294 // return smoothly faded pos and size of given panel when a dialog is active
295 // don't center too wide panels, it doesn't work with different resolutions
296 #define HUD_Panel_UpdatePosSize_ForMenu() do { \
297 vector menu_enable_size = panel_size; \
298 float max_panel_width = 0.52 * vid_conwidth; \
299 if(panel_size.x > max_panel_width) \
301 menu_enable_size.x = max_panel_width; \
302 menu_enable_size.y = panel_size.y * (menu_enable_size.x / panel_size.x); \
304 vector menu_enable_pos = eX * (panel_bg_border + 0.5 * max_panel_width) + eY * 0.5 * vid_conheight - 0.5 * menu_enable_size; \
305 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_pos; \
306 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size; \
309 // Scale the pos and size vectors to absolute coordinates
310 #define HUD_Panel_ScalePosSize() do { \
311 panel_pos.x *= vid_conwidth; panel_pos.y *= vid_conheight; \
312 panel_size.x *= vid_conwidth; panel_size.y *= vid_conheight; \
315 // NOTE: in hud_configure mode cvars must be reloaded every frame
316 #define HUD_Panel_UpdateCvars() do { \
317 if (panel.update_time <= time) { \
318 if (autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
319 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
320 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
321 HUD_Panel_ScalePosSize(); \
322 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
323 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
324 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
325 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
326 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
327 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
329 if (panel.current_panel_bg != "0") { \
330 HUD_Panel_GetColorTeam(); \
331 HUD_Panel_GetColor(); \
332 HUD_Panel_GetBgAlpha(); \
333 HUD_Panel_GetBorder(); \
335 HUD_Panel_GetFgAlpha(); \
336 HUD_Panel_GetPadding(); \
337 panel.current_panel_bg_alpha = panel_bg_alpha; \
338 panel.current_panel_fg_alpha = panel_fg_alpha; \
339 if (menu_enabled == 2 && panel == highlightedPanel) { \
340 HUD_Panel_UpdatePosSize_ForMenu(); \
342 panel_bg_alpha *= hud_fade_alpha; \
343 panel_fg_alpha *= hud_fade_alpha; \
345 panel.current_panel_pos = panel_pos; \
346 panel.current_panel_size = panel_size; \
347 panel.current_panel_bg_border = panel_bg_border; \
348 panel.current_panel_bg_color = panel_bg_color; \
349 panel.current_panel_bg_color_team = panel_bg_color_team; \
350 panel.current_panel_bg_padding = panel_bg_padding; \
351 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
353 panel_pos = panel.current_panel_pos; \
354 panel_size = panel.current_panel_size; \
355 panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha; \
356 panel_bg_border = panel.current_panel_bg_border; \
357 panel_bg_color = panel.current_panel_bg_color; \
358 panel_bg_color_team = panel.current_panel_bg_color_team; \
359 panel_bg_padding = panel.current_panel_bg_padding; \
360 panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \
364 #define HUD_Panel_UpdatePosSize() do { \
365 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
366 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
367 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
368 HUD_Panel_ScalePosSize(); \
369 if (menu_enabled == 2 && panel == highlightedPanel) { \
370 HUD_Panel_UpdatePosSize_ForMenu(); \
372 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
373 HUD_Panel_GetBorder(); \
376 const int NOTIFY_MAX_ENTRIES = 10;
377 const float NOTIFY_ICON_MARGIN = 0.02;
381 float notify_times[NOTIFY_MAX_ENTRIES];
382 string notify_attackers[NOTIFY_MAX_ENTRIES];
383 string notify_victims[NOTIFY_MAX_ENTRIES];
384 string notify_icons[NOTIFY_MAX_ENTRIES];
386 void HUD_Notify_Push(string icon, string attacker, string victim);
388 var void HUD_ModIcons_GameType(vector pos, vector size);
389 void HUD_ModIcons_SetFunc();