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