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