]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud.qh
Merge branch 'master' into terencehill/ca_ft_fixes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qh
1 #define HUD_PANEL_MAX 24
2 entity hud_panel[HUD_PANEL_MAX];
3 #define HUD_PANEL_FIRST 0
4 float HUD_PANEL_NUM;
5 float HUD_PANEL_LAST;
6
7 float panel_order[HUD_PANEL_MAX];
8 string hud_panelorder_prev;
9
10 float hud_draw_maximized;
11 float hud_panel_radar_maximized;
12
13 vector mousepos;
14 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
15 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
16 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
17 entity highlightedPanel;
18 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
19
20 const float BORDER_MULTIPLIER = 0.25;
21 float scoreboard_bottom;
22 float weapon_accuracy[WEP_MAXCOUNT];
23
24 float complain_weapon;
25 string complain_weapon_name;
26 float complain_weapon_type;
27 float complain_weapon_time;
28
29 float ps_primary, ps_secondary;
30 float ts_primary, ts_secondary;
31
32 float last_switchweapon;
33 float last_activeweapon;
34 float weapontime;
35 float weaponprevtime;
36
37 float teamnagger;
38
39 float hud_configure_checkcollisions;
40 float hud_configure_prev;
41 noref vector hud_configure_gridSize; // fteqcc sucks
42 noref vector hud_configure_realGridSize; // fteqcc sucks
43
44 float hudShiftState;
45 const float S_SHIFT = 1;
46 const float S_CTRL = 2;
47 const float S_ALT = 4;
48
49 float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
50 float menu_enabled_time;
51
52 float hud_fade_alpha;
53
54 string hud_skin_path;
55 string hud_skin_prev;
56
57 vector myteamcolors;
58
59 var vector progressbar_color;
60
61 entity highlightedPanel_backup;
62 var vector panel_pos_backup;
63 var vector panel_size_backup;
64
65 var vector panel_size_copied;
66
67 entity panel;
68 .string panel_name;
69 .float panel_id;
70 .vector current_panel_pos;
71 .vector current_panel_size;
72 .string current_panel_bg;
73 .float current_panel_bg_alpha;
74 .float current_panel_bg_border;
75 .vector current_panel_bg_color;
76 .float current_panel_bg_color_team;
77 .float current_panel_bg_padding;
78 .float current_panel_fg_alpha;
79 .float update_time;
80 var float panel_enabled;
81 var vector panel_pos;
82 var vector panel_size;
83 var string panel_bg;
84 var string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
85 var vector panel_bg_color;
86 var string panel_bg_color_str;
87 var float panel_bg_color_team;
88 var string panel_bg_color_team_str;
89 var float panel_fg_alpha;
90 var float panel_bg_alpha;
91 var string panel_bg_alpha_str;
92 var float panel_bg_border;
93 var string panel_bg_border_str;
94 var float panel_bg_padding;
95 var string panel_bg_padding_str;
96
97 .void() panel_draw;
98
99 float current_player;
100
101
102 #define HUD_PANELS \
103         HUD_PANEL(WEAPONS      , HUD_Weapons      , weapons) \
104         HUD_PANEL(AMMO         , HUD_Ammo         , ammo) \
105         HUD_PANEL(POWERUPS     , HUD_Powerups     , powerups) \
106         HUD_PANEL(HEALTHARMOR  , HUD_HealthArmor  , healtharmor) \
107         HUD_PANEL(NOTIFY       , HUD_Notify       , notify) \
108         HUD_PANEL(TIMER        , HUD_Timer        , timer) \
109         HUD_PANEL(RADAR        , HUD_Radar        , radar) \
110         HUD_PANEL(SCORE        , HUD_Score        , score) \
111         HUD_PANEL(RACETIMER    , HUD_RaceTimer    , racetimer) \
112         HUD_PANEL(VOTE         , HUD_Vote         , vote) \
113         HUD_PANEL(MODICONS     , HUD_ModIcons     , modicons) \
114         HUD_PANEL(PRESSEDKEYS  , HUD_PressedKeys  , pressedkeys) \
115         HUD_PANEL(CHAT         , HUD_Chat         , chat) \
116         HUD_PANEL(ENGINEINFO   , HUD_EngineInfo   , engineinfo) \
117         HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages) \
118         HUD_PANEL(PHYSICS      , HUD_Physics      , physics) \
119         HUD_PANEL(CENTERPRINT  , HUD_CenterPrint  , centerprint)
120
121 #define HUD_PANEL(NAME,draw_func,name) \
122         float HUD_PANEL_##NAME; \
123         void ##draw_func(void); \
124         void RegisterHUD_Panel_##NAME() \
125         { \
126                 HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM; \
127                 entity hud_panelent = spawn(); \
128                 hud_panel[HUD_PANEL_##NAME] = hud_panelent; \
129                 hud_panelent.classname = "hud_panel"; \
130                 hud_panelent.panel_name = #name; \
131                 hud_panelent.panel_id = HUD_PANEL_##NAME; \
132                 hud_panelent.panel_draw = ##draw_func; \
133                 ++HUD_PANEL_NUM; \
134         } \
135         ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME);
136
137 HUD_PANELS
138 #undef HUD_PANEL
139
140 #define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
141
142
143 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
144 // ----------------------
145 // MACRO HELL STARTS HERE
146 // ----------------------
147 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
148
149 #define HUD_Panel_GetProgressBarColor(item) \
150                 progressbar_color = stov(cvar_string("hud_progressbar_" #item "_color"))
151 #define HUD_Panel_GetProgressBarColorForString(item) \
152 switch(item) {\
153         case "health": HUD_Panel_GetProgressBarColor(health); break;\
154         case "armor": HUD_Panel_GetProgressBarColor(armor); break;\
155         case "strength": HUD_Panel_GetProgressBarColor(strength); break;\
156         case "shield": HUD_Panel_GetProgressBarColor(shield); break;\
157         case "fuel": HUD_Panel_GetProgressBarColor(fuel); break;\
158         case "nexball": HUD_Panel_GetProgressBarColor(nexball); break;\
159         case "speed": HUD_Panel_GetProgressBarColor(speed); break;\
160         case "acceleration": HUD_Panel_GetProgressBarColor(acceleration); break;\
161         case "acceleration_neg": HUD_Panel_GetProgressBarColor(acceleration_neg); break;\
162 } ENDS_WITH_CURLY_BRACE
163
164 // Get value for panel_bg: if "" fetch default, else use panel_bg_str
165 // comment on last line of macro: // we probably want to see a background in config mode at all times...
166 #define HUD_Panel_GetBg()\
167 if(!autocvar__hud_configure && panel_bg_str == "0") {\
168         panel_bg = "0";\
169 } else {\
170         if(panel_bg_str == "") {\
171                 panel_bg_str = autocvar_hud_panel_bg;\
172         }\
173         if(panel_bg_str == "0" && !autocvar__hud_configure) {\
174                         panel_bg = "0";\
175         } else {\
176                 if (panel_bg_str == "0" && autocvar__hud_configure)\
177                         panel_bg_alpha_str = "0";\
178                 panel_bg = strcat(hud_skin_path, "/", panel_bg_str);\
179                 if(precache_pic(panel_bg) == "") {\
180                         panel_bg = strcat(hud_skin_path, "/", "border_default");\
181                         if(precache_pic(panel_bg) == "") {\
182                                 panel_bg = strcat("gfx/hud/default/", "border_default");\
183                         }\
184                 }\
185         }\
186 }
187
188 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
189 #define HUD_Panel_GetColor()\
190 if((teamplay) && panel_bg_color_team) {\
191         if(autocvar__hud_configure && myteam == NUM_SPECTATOR)\
192                 panel_bg_color = '1 0 0' * panel_bg_color_team;\
193         else\
194                 panel_bg_color = myteamcolors * panel_bg_color_team;\
195 } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) {\
196         panel_bg_color = '1 0 0' * panel_bg_color_team;\
197 } else {\
198         if(panel_bg_color_str == "") {\
199                 panel_bg_color = autocvar_hud_panel_bg_color;\
200         } else {\
201                 if(panel_bg_color_str == "shirt") {\
202                         panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player - 1, "colors")) / 16), 0);\
203                 } else if(panel_bg_color_str == "pants") {\
204                         panel_bg_color = colormapPaletteColor(mod(stof(getplayerkeyvalue(current_player - 1, "colors")), 16), 1);\
205                 } else {\
206                         panel_bg_color = stov(panel_bg_color_str);\
207                 }\
208         }\
209 }
210
211 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
212 #define HUD_Panel_GetColorTeam()\
213 if(panel_bg_color_team_str == "") {\
214         panel_bg_color_team = autocvar_hud_panel_bg_color_team;\
215 } else {\
216         panel_bg_color_team = stof(panel_bg_color_team_str);\
217 }
218
219 // the check doesn't allow to fade this panel when showing the panel-specific menu dialog
220 #define HUD_Panel_ApplyFadeAlpha()\
221 if(!(menu_enabled == 2 && panel == highlightedPanel))\
222 {\
223         panel_bg_alpha *= hud_fade_alpha;\
224         panel_fg_alpha *= hud_fade_alpha;\
225 } ENDS_WITH_CURLY_BRACE
226
227 // 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
228 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
229 #define HUD_Panel_GetBgAlpha()\
230 if(panel_bg_alpha_str == "") {\
231         panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);\
232 }\
233 panel_bg_alpha = stof(panel_bg_alpha_str);\
234 if(autocvar__hud_configure) {\
235         if(!panel_enabled)\
236                 panel_bg_alpha = 0.25;\
237         else if(menu_enabled == 2 && panel == highlightedPanel)\
238                 panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
239         else\
240                 panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha);\
241 }
242
243 // Get value for panel_fg_alpha. Also do various minalpha checks
244 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
245 #define HUD_Panel_GetFgAlpha()\
246 panel_fg_alpha = autocvar_hud_panel_fg_alpha;\
247 if(autocvar__hud_configure && !panel_enabled)\
248         panel_fg_alpha = 0.25;\
249
250 // Get border. See comments above, it's similar.
251 #define HUD_Panel_GetBorder()\
252 if(panel_bg_border_str == "") {\
253         panel_bg_border = autocvar_hud_panel_bg_border;\
254 } else {\
255         panel_bg_border = stof(panel_bg_border_str);\
256 } ENDS_WITH_CURLY_BRACE
257
258 // Scale the pos and size vectors to absolute coordinates
259 #define HUD_Panel_GetScaledVectors()\
260 panel_pos_x *= vid_conwidth;\
261 panel_pos_y *= vid_conheight;\
262 panel_size_x *= vid_conwidth;\
263 panel_size_y *= vid_conheight;
264
265 // Get padding. See comments above, it's similar.
266 // 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
267 #define HUD_Panel_GetPadding()\
268 if(panel_bg_padding_str == "") {\
269         panel_bg_padding = autocvar_hud_panel_bg_padding;\
270 } else {\
271         panel_bg_padding = stof(panel_bg_padding_str);\
272 }\
273 panel_bg_padding = min(min(panel_size_x, panel_size_y)/2 - 5, panel_bg_padding);
274
275 // Point to the macros above (stupid max macro length)
276 #define HUD_Panel_GetStringVars()\
277 HUD_Panel_GetBg()\
278 if (panel_bg != "0") {\
279         HUD_Panel_GetColorTeam()\
280         HUD_Panel_GetColor()\
281         HUD_Panel_GetBgAlpha()\
282         HUD_Panel_GetBorder()\
283 }\
284 HUD_Panel_GetFgAlpha()\
285 HUD_Panel_GetScaledVectors()\
286 HUD_Panel_GetPadding()
287
288 // return smoothly faded pos of given panel when a dialog is active
289 var vector menu_enable_panelpos;
290 #define HUD_Panel_GetMenuPos() \
291 if(panel_size_x > panel_size_y)\
292         menu_enable_panelpos = eX * 0.5 * vid_conwidth - eX * 0.5 * panel_size_x + eY * 0.82 * vid_conheight;\
293 else\
294         menu_enable_panelpos = eY * 0.5 * vid_conheight - eY * 0.5 * panel_size_y + eX * 0.7 * vid_conwidth;\
295 panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_panelpos;
296
297 // return smoothly faded size of given panel when a dialog is active
298 //var vector menu_enable_maxsize;
299 var float menu_enable_maxsize_x;
300 var float menu_enable_maxsize_y;
301 var vector menu_enable_size;
302 #define HUD_Panel_GetMenuSize()\
303 menu_enable_maxsize_x = 0.3 * vid_conwidth;\
304 menu_enable_maxsize_y = 0.18 * vid_conheight;\
305 if(panel_size_x > panel_size_y)\
306 {\
307         if(panel_size_y > menu_enable_maxsize_y)\
308         {\
309                 menu_enable_size_y = menu_enable_maxsize_y;\
310                 menu_enable_size_x = panel_size_x * (menu_enable_maxsize_y/panel_size_y);\
311                 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
312         }\
313 }\
314 else\
315 {\
316         if(panel_size_x > menu_enable_maxsize_x)\
317         {\
318                 menu_enable_size_x = menu_enable_maxsize_x;\
319                 menu_enable_size_y = panel_size_y * (menu_enable_maxsize_x/panel_size_x);\
320                 panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size;\
321         }\
322 }
323
324 // NOTE: in hud_configure mode cvars must be reloaded every frame
325 #define HUD_Panel_UpdateCvars() \
326 if(panel.update_time <= time) { \
327         if(autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
328         panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
329         panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
330         panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg")); \
331         panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color")); \
332         panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team")); \
333         panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha")); \
334         panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
335         panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding")); \
336         HUD_Panel_GetStringVars()\
337         if(menu_enabled == 2 && panel == highlightedPanel) {\
338                 HUD_Panel_GetMenuSize()\
339                 HUD_Panel_GetMenuPos()\
340         } \
341         panel.current_panel_pos = panel_pos; \
342         panel.current_panel_size = panel_size; \
343         if(panel.current_panel_bg) \
344                 strunzone(panel.current_panel_bg); \
345         if(panel_bg == "")\
346         {\
347                 /*printf("^xf08 %s panel: panel_bg is empty\n", panel.panel_name);*/\
348                 panel_bg = "0";\
349         }\
350         panel.current_panel_bg = strzone(panel_bg); \
351         panel.current_panel_bg_alpha = panel_bg_alpha; \
352         panel.current_panel_bg_border = panel_bg_border; \
353         panel.current_panel_bg_color = panel_bg_color; \
354         panel.current_panel_bg_color_team = panel_bg_color_team; \
355         panel.current_panel_bg_padding = panel_bg_padding; \
356         panel.current_panel_fg_alpha = panel_fg_alpha; \
357         panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval; \
358 } else { \
359         panel_pos = panel.current_panel_pos; \
360         panel_size = panel.current_panel_size; \
361         panel_bg = panel.current_panel_bg; \
362         if(panel.current_panel_bg == "")\
363         {\
364                 /*printf("^xf08 %s panel: panel.current_panel_bg is empty\n", panel.panel_name);*/\
365                 panel_bg = "0";\
366         }\
367         panel_bg_alpha = panel.current_panel_bg_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; \
373 } ENDS_WITH_CURLY_BRACE
374
375 #define HUD_Panel_UpdatePosSize() {\
376 panel_enabled = cvar(strcat("hud_panel_", panel.panel_name)); \
377 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
378 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
379 HUD_Panel_GetScaledVectors()\
380 if(menu_enabled == 2 && panel == highlightedPanel) {\
381         HUD_Panel_GetMenuSize()\
382         HUD_Panel_GetMenuPos()\
383 }\
384 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
385 HUD_Panel_GetBorder() \
386 } ENDS_WITH_CURLY_BRACE
387
388
389 #define KN_MAX_ENTRIES 10
390
391 float kn_index;
392 float notify_times[KN_MAX_ENTRIES];
393 string notify_icon[KN_MAX_ENTRIES];
394 string notify_attackers[KN_MAX_ENTRIES];
395 string notify_victims[KN_MAX_ENTRIES];
396 void HUD_Notify_Push(string icon, string attacker, string victim);