]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/hud.qh
Merge branch 'terencehill/translated_keys' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / hud.qh
1 #pragma once
2
3 #include <common/weapons/_all.qh>
4 #include <common/scores.qh>
5
6 void Hud_Dynamic_Frame();
7
8 bool HUD_Radar_Clickable();
9 void HUD_Radar_Mouse();
10 bool HUD_WouldShowCursor();
11 bool QuickMenu_IsOpened();
12
13 REGISTRY(hud_panels, BITS(6))
14 #define hud_panels_from(i) _hud_panels_from(i, NULL)
15 REGISTER_REGISTRY(hud_panels)
16
17 #define REGISTER_HUD_PANEL(id, draw_func, configflags, showflags) \
18         void draw_func(); \
19         REGISTER(hud_panels, HUD_PANEL, id, m_id, new_pure(hud_panel)) { \
20                 this.panel_id = this.m_id; \
21                 this.panel_draw = draw_func; \
22                 this.panel_name = strzone(strtolower(#id)); \
23                 this.panel_configflags = configflags; \
24                 this.panel_showflags = showflags; \
25         }
26
27 #define HUD_PANEL(NAME) HUD_PANEL_##NAME
28
29 // draw the background/borders
30 #define HUD_Panel_DrawBg() MACRO_BEGIN \
31         if(panel.current_panel_bg != "0" && panel.current_panel_bg != "") \
32                 draw_BorderPicture( \
33                         HUD_Shift(panel_pos - '1 1 0' * panel_bg_border), \
34                         panel.current_panel_bg, \
35                         HUD_Scale(panel_size + '1 1 0' * 2 * panel_bg_border), \
36                         panel_bg_color, panel_bg_alpha, \
37                         HUD_Scale('1 1 0' * BORDER_MULTIPLIER * panel_bg_border) \
38                 ); \
39 MACRO_END
40
41 int panel_order[hud_panels_MAX];
42 string hud_panelorder_prev;
43
44 bool hud_draw_maximized;
45 bool hud_panel_radar_maximized;
46 bool hud_panel_radar_mouse;
47 float hud_panel_radar_bottom;
48 bool hud_panel_radar_temp_hidden;
49 bool chat_panel_modified;
50 bool radar_panel_modified;
51
52 float HUD_Radar_InputEvent(float bInputType, float nPrimary, float nSecondary);
53 void HUD_Radar_Hide_Maximized();
54
55 float HUD_GetRowCount(int item_count, vector size, float item_aspect);
56 vector HUD_Get_Num_Color (float hp, float maxvalue);
57 void DrawNumIcon(vector myPos, vector mySize, float theTime, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha);
58 void DrawNumIcon_expanding(vector myPos, vector mySize, float theTime, string icon, bool vertical, int icon_right_align, vector color, float theAlpha, float fadelerp);
59 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag);
60 vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect);
61
62 void HUD_Reset ();
63 void HUD_Main ();
64
65 int race_CheckName(string net_name);
66 string MakeRaceString(int cp, float mytime, float theirtime, float othertime, float lapdelta, string theirname);
67
68 int vote_yescount;
69 int vote_nocount;
70 int vote_needed;
71 int vote_highlighted; // currently selected vote
72
73 int vote_active; // is there an active vote?
74 int vote_prev; // previous state of vote_active to check for a change
75 float vote_alpha;
76 float vote_change; // "time" when vote_active changed
77
78 vector mousepos;
79 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
80 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
81 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
82 entity highlightedPanel;
83 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
84
85 const float BORDER_MULTIPLIER = 4;
86 float scoreboard_bottom;
87 int weapon_accuracy[Weapons_MAX];
88
89 entity complain_weapon;
90 int complain_weapon_type;
91 float complain_weapon_time;
92
93 PlayerScoreField ps_primary, ps_secondary;
94 int ts_primary, ts_secondary;
95
96 .Weapon last_switchweapon;
97 .Weapon last_activeweapon;
98 float weapontime;
99 float weaponprevtime;
100
101 float teamnagger;
102
103 int hudShiftState;
104 const int S_SHIFT = 1;
105 const int S_CTRL = 2;
106 const int S_ALT = 4;
107
108 float hud_fade_alpha;
109
110 string hud_skin_path;
111 string hud_skin_prev;
112
113 vector myteamcolors;
114
115 entity highlightedPanel_backup;
116 vector panel_pos_backup;
117 vector panel_size_backup;
118
119 vector panel_size_copied;
120
121 entity panel;
122 entityclass(HUDPanel);
123 classfield(HUDPanel) .string panel_name;
124 classfield(HUDPanel) .int panel_id;
125 classfield(HUDPanel) .vector current_panel_pos;
126 classfield(HUDPanel) .vector current_panel_size;
127 classfield(HUDPanel) .string current_panel_bg;
128 classfield(HUDPanel) .float current_panel_bg_alpha;
129 classfield(HUDPanel) .float current_panel_bg_border;
130 classfield(HUDPanel) .vector current_panel_bg_color;
131 classfield(HUDPanel) .float current_panel_bg_color_team;
132 classfield(HUDPanel) .float current_panel_bg_padding;
133 classfield(HUDPanel) .float current_panel_fg_alpha;
134 classfield(HUDPanel) .float update_time;
135 float panel_enabled;
136 vector panel_pos;
137 vector panel_size;
138 string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
139 vector panel_bg_color;
140 string panel_bg_color_str;
141 float panel_bg_color_team;
142 string panel_bg_color_team_str;
143 float panel_fg_alpha;
144 float panel_bg_alpha;
145 string panel_bg_alpha_str;
146 float panel_bg_border;
147 string panel_bg_border_str;
148 float panel_bg_padding;
149 string panel_bg_padding_str;
150
151 classfield(HUDPanel) .void() panel_draw;
152
153 // chat panel can be reduced / moved while the mapvote is active
154 // let know the mapvote panel about chat pos and size
155 float chat_posy;
156 float chat_sizey;
157
158 float current_player;
159
160 float autocvar_hud_dynamic_follow;
161 float autocvar_hud_dynamic_follow_scale;
162 vector autocvar_hud_dynamic_follow_scale_xyz;
163
164 vector hud_dynamic_shake_realofs;
165 float hud_dynamic_shake_factor;
166 float hud_dynamic_shake_time;
167
168 // shared across viewmodel effects and dynamic hud code
169 vector cl_followmodel_ofs;
170 float cl_followmodel_time;
171
172 vector hud_scale;
173 vector hud_scale_current = '1 1 0';
174 vector hud_shift;
175 vector hud_shift_current = '0 0 0';
176 vector hud_scale_center;
177
178 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag);
179
180 .int panel_showflags;
181 const int PANEL_SHOW_MAINGAME = BIT(0); // show in the main HUD
182 const int PANEL_SHOW_MINIGAME = BIT(1); // show when minigames panels are shown
183 const int PANEL_SHOW_MAPVOTE  = BIT(2); // show during map vote
184 const int PANEL_SHOW_WITH_SB  = BIT(3); // show when scoreboard is on
185
186 .int panel_configflags;
187 const int PANEL_CONFIG_NO        = 0x00;
188 const int PANEL_CONFIG_MAIN      = 0x01;
189 const int PANEL_CONFIG_CANBEOFF  = 0x02; // panel can be disabled (if disabled it's displayed with a low alpha)
190
191
192 // prev_* vars contain the health/armor at the previous FRAME
193 // set to -1 when player is dead or was not playing
194 int prev_health, prev_armor;
195 float health_damagetime, armor_damagetime;
196 int health_beforedamage, armor_beforedamage;
197 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
198 int old_p_health, old_p_armor;
199 float old_p_healthtime, old_p_armortime;
200 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
201 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
202 int prev_p_health, prev_p_armor;
203
204 void HUD_ItemsTime();
205
206 REGISTER_HUD_PANEL(WEAPONS,         HUD_Weapons,        PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // WEAPONS
207 REGISTER_HUD_PANEL(AMMO,            HUD_Ammo,           PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // AMMO
208 REGISTER_HUD_PANEL(POWERUPS,        HUD_Powerups,       PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // POWERUPS
209 REGISTER_HUD_PANEL(HEALTHARMOR,     HUD_HealthArmor,    PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // HEALTHARMOR
210 REGISTER_HUD_PANEL(NOTIFY,          HUD_Notify,         PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME                                          ) // NOTIFY
211 REGISTER_HUD_PANEL(TIMER,           HUD_Timer,          PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME                      | PANEL_SHOW_WITH_SB) // TIMER
212 REGISTER_HUD_PANEL(RADAR,           HUD_Radar,          PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // RADAR
213 REGISTER_HUD_PANEL(SCORE,           HUD_Score,          PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME                                          ) // SCORE
214 REGISTER_HUD_PANEL(RACETIMER,       HUD_RaceTimer,      PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // RACETIMER
215 REGISTER_HUD_PANEL(VOTE,            HUD_Vote,           PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME | PANEL_SHOW_MAPVOTE | PANEL_SHOW_WITH_SB) // VOTE
216 REGISTER_HUD_PANEL(MODICONS,        HUD_ModIcons,       PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                            | PANEL_SHOW_WITH_SB) // MODICONS
217 REGISTER_HUD_PANEL(PRESSEDKEYS,     HUD_PressedKeys,    PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // PRESSEDKEYS
218 REGISTER_HUD_PANEL(CHAT,            HUD_Chat,           PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME | PANEL_SHOW_MAPVOTE | PANEL_SHOW_WITH_SB) // CHAT
219 REGISTER_HUD_PANEL(ENGINEINFO,      HUD_EngineInfo,     PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME | PANEL_SHOW_MAPVOTE | PANEL_SHOW_WITH_SB) // ENGINEINFO
220 REGISTER_HUD_PANEL(INFOMESSAGES,    HUD_InfoMessages,   PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // INFOMESSAGES
221 REGISTER_HUD_PANEL(PHYSICS,         HUD_Physics,        PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // PHYSICS
222 REGISTER_HUD_PANEL(CENTERPRINT,     HUD_CenterPrint,    PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                            | PANEL_SHOW_WITH_SB) // CENTERPRINT
223 REGISTER_HUD_PANEL(MINIGAMEBOARD,   HUD_MinigameBoard,  PANEL_CONFIG_NO                          ,                       PANEL_SHOW_MINIGAME                      | PANEL_SHOW_WITH_SB) // MINIGAMEBOARD
224 REGISTER_HUD_PANEL(MINIGAMESTATUS,  HUD_MinigameStatus, PANEL_CONFIG_NO                          ,                       PANEL_SHOW_MINIGAME                      | PANEL_SHOW_WITH_SB) // MINIGAMESTATUS
225 REGISTER_HUD_PANEL(MINIGAMEHELP,    HUD_MinigameHelp,   PANEL_CONFIG_NO                          ,                       PANEL_SHOW_MINIGAME                      | PANEL_SHOW_WITH_SB) // MINIGAMEHELP
226 REGISTER_HUD_PANEL(MINIGAMEMENU,    HUD_MinigameMenu,   PANEL_CONFIG_NO                          , PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME                      | PANEL_SHOW_WITH_SB) // MINIGAMEMENU
227 REGISTER_HUD_PANEL(MAPVOTE,         MapVote_Draw,       PANEL_CONFIG_NO                          ,                                             PANEL_SHOW_MAPVOTE                     ) // MAPVOTE
228 REGISTER_HUD_PANEL(ITEMSTIME,       HUD_ItemsTime,      PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // ITEMSTIME
229 REGISTER_HUD_PANEL(QUICKMENU,       HUD_QuickMenu,      PANEL_CONFIG_MAIN                        , PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME                                          ) // QUICKMENU
230 REGISTER_HUD_PANEL(SCOREBOARD,      Scoreboard_Draw,    PANEL_CONFIG_NO                          , PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME | PANEL_SHOW_MAPVOTE | PANEL_SHOW_WITH_SB) // SCOREBOARD
231 // always add new panels to the end of list
232
233 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
234 // ----------------------
235 // MACRO HELL STARTS HERE
236 // ----------------------
237 // Little help for the poor people who have to make sense of this: Start from the bottom ;)
238
239 // Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str
240 // comment on last line of macro: // we probably want to see a background in config mode at all times...
241 #define HUD_Panel_GetBg() MACRO_BEGIN \
242         string panel_bg; \
243         if (!autocvar__hud_configure && panel_bg_str == "0") { \
244                 panel_bg = "0"; \
245         } else { \
246                 if (panel_bg_str == "") { \
247                         panel_bg_str = autocvar_hud_panel_bg; \
248                 } \
249                 if (panel_bg_str == "0" && !autocvar__hud_configure) { \
250                         panel_bg = "0"; \
251                 } else { \
252                         if (panel_bg_str == "0" && autocvar__hud_configure) \
253                                 panel_bg_alpha_str = "0"; \
254                         panel_bg = strcat(hud_skin_path, "/", panel_bg_str); \
255                         if (precache_pic(panel_bg) == "") { \
256                                 panel_bg = strcat(hud_skin_path, "/", "border_default"); \
257                                 if (precache_pic(panel_bg) == "") { \
258                                         panel_bg = strcat("gfx/hud/default/", "border_default"); \
259                                 } \
260                         } \
261                 } \
262         } \
263         strcpy(panel.current_panel_bg, panel_bg); \
264 MACRO_END
265
266 // Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
267 #define HUD_Panel_GetColor() MACRO_BEGIN \
268         if ((teamplay) && panel_bg_color_team > 0) { \
269                 if (autocvar__hud_configure && myteam == NUM_SPECTATOR) \
270                         panel_bg_color = '1 0 0' * panel_bg_color_team; \
271                 else \
272                         panel_bg_color = myteamcolors * panel_bg_color_team; \
273         } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team > 0) { \
274                 panel_bg_color = '1 0 0' * panel_bg_color_team; \
275         } else { \
276                 if (panel_bg_color_str == "") { \
277                         panel_bg_color = autocvar_hud_panel_bg_color; \
278                 } else { \
279                         if (panel_bg_color_str == "shirt") { \
280                                 panel_bg_color = colormapPaletteColor(floor(entcs_GetClientColors(current_player) / 16), 0); \
281                         } else if (panel_bg_color_str == "pants") { \
282                                 panel_bg_color = colormapPaletteColor(entcs_GetClientColors(current_player) % 16, 1); \
283                         } else { \
284                                 panel_bg_color = stov(panel_bg_color_str); \
285                         } \
286                 } \
287         } \
288 MACRO_END
289
290 // Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
291 #define HUD_Panel_GetColorTeam() MACRO_BEGIN \
292         if (panel_bg_color_team_str == "") { \
293                 panel_bg_color_team = autocvar_hud_panel_bg_color_team; \
294         } else { \
295                 panel_bg_color_team = stof(panel_bg_color_team_str); \
296         } \
297 MACRO_END
298
299 // 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
300 // comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
301 #define HUD_Panel_GetBgAlpha() MACRO_BEGIN \
302         if (panel_bg_alpha_str == "") { \
303                 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha); \
304         } \
305         panel_bg_alpha = stof(panel_bg_alpha_str); \
306         if (autocvar__hud_configure) { \
307                 if (!panel_enabled) \
308                         panel_bg_alpha = 0.25; \
309                 else if (hud_configure_menu_open == 2 && panel == highlightedPanel) \
310                         panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
311                 else \
312                         panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha); \
313         } \
314 MACRO_END
315
316 // Get value for panel_fg_alpha. Also do various minalpha checks
317 // comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
318 #define HUD_Panel_GetFgAlpha() MACRO_BEGIN \
319         panel_fg_alpha = autocvar_hud_panel_fg_alpha; \
320         if (autocvar__hud_configure && !panel_enabled) \
321                 panel_fg_alpha = 0.25; \
322 MACRO_END
323
324 // Get border. See comments above, it's similar.
325 #define HUD_Panel_GetBorder() MACRO_BEGIN \
326         if (panel_bg_border_str == "") { \
327                 panel_bg_border = autocvar_hud_panel_bg_border; \
328         } else { \
329                 panel_bg_border = stof(panel_bg_border_str); \
330         } \
331 MACRO_END
332
333 // Get padding. See comments above, it's similar.
334 // 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
335 #define HUD_Panel_GetPadding() MACRO_BEGIN \
336         if (panel_bg_padding_str == "") { \
337                 panel_bg_padding = autocvar_hud_panel_bg_padding; \
338         } else { \
339                 panel_bg_padding = stof(panel_bg_padding_str); \
340         } \
341         panel_bg_padding = min(min(panel_size.x, panel_size.y)/2 - 5, panel_bg_padding); \
342 MACRO_END
343
344 // return smoothly faded pos and size of given panel when a dialog is active
345 // don't center too wide panels, it doesn't work with different resolutions
346 #define HUD_Panel_UpdatePosSize_ForMenu() MACRO_BEGIN \
347         vector new_size = panel_size; \
348         float max_panel_width = 0.52 * vid_conwidth; \
349         if(panel_size.x > max_panel_width) \
350         { \
351                 new_size.x = max_panel_width; \
352                 new_size.y = panel_size.y * (new_size.x / panel_size.x); \
353         } \
354         vector new_pos = vec2(panel_bg_border + 0.5 * max_panel_width, 0.5 * vid_conheight) - 0.5 * new_size; \
355         panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * new_pos; \
356         panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * new_size; \
357 MACRO_END
358
359 // Scale the pos and size vectors to absolute coordinates
360 #define HUD_Panel_ScalePosSize() MACRO_BEGIN \
361         panel_pos.x *= vid_conwidth; panel_pos.y *= vid_conheight; \
362         panel_size.x *= vid_conwidth; panel_size.y *= vid_conheight; \
363 MACRO_END
364
365 float panel_fade_alpha;
366 void HUD_Panel_LoadCvars();
367
368 #define Hud_Panel_GetPanelEnabled() \
369         panel_enabled = ((panel.panel_configflags & PANEL_CONFIG_CANBEOFF) \
370                                         ? cvar(strcat("hud_panel_", panel.panel_name)) : true)
371
372 #define HUD_Panel_UpdatePosSize() MACRO_BEGIN \
373         Hud_Panel_GetPanelEnabled(); \
374         panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos"))); \
375         panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size"))); \
376         HUD_Panel_ScalePosSize(); \
377         if (hud_configure_menu_open == 2 && panel == highlightedPanel) { \
378                 HUD_Panel_UpdatePosSize_ForMenu(); \
379         } \
380         panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border")); \
381         HUD_Panel_GetBorder(); \
382 MACRO_END
383
384 const int NOTIFY_MAX_ENTRIES = 10;
385 const float NOTIFY_ICON_MARGIN = 0.02;
386
387 int notify_index;
388 int notify_count;
389 float notify_times[NOTIFY_MAX_ENTRIES];
390 string notify_attackers[NOTIFY_MAX_ENTRIES];
391 string notify_victims[NOTIFY_MAX_ENTRIES];
392 string notify_icons[NOTIFY_MAX_ENTRIES];
393
394 void HUD_Notify_Push(string icon, string attacker, string victim);
395
396 var void HUD_ModIcons_GameType(vector pos, vector size);
397 void HUD_ModIcons_SetFunc();