]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/hud.qc
Whitelist g_casings
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / hud.qc
1 #include "hud.qh"
2
3 #include <client/defs.qh>
4 #include <client/miscfunctions.qh>
5 #include <client/view.qh>
6 #include "panel/scoreboard.qh"
7 #include "hud_config.qh"
8 #include "../mapvoting.qh"
9 #include "../teamradar.qh"
10 #include <common/minigames/cl_minigames.qh>
11 #include <common/t_items.qh>
12 #include <common/deathtypes/all.qh>
13 #include <common/ent_cs.qh>
14 #include <common/items/_mod.qh>
15 #include <common/mapinfo.qh>
16 #include <common/vehicles/all.qh>
17 #include <common/vehicles/vehicle/bumblebee.qh>
18 #include <common/mutators/mutator/waypoints/all.qh>
19 #include <common/stats.qh>
20 #include <lib/csqcmodel/cl_player.qh>
21 #include <lib/csqcmodel/cl_model.qh>
22 #include <common/gamemodes/_mod.qh>
23
24
25 /*
26 ==================
27 Misc HUD functions
28 ==================
29 */
30
31 vector HUD_Get_Num_Color(float hp, float maxvalue, bool blink)
32 {
33         const vector COLOR100 = '0 1 0'; // green
34         const vector COLOR75 = '0.4 0.9 0'; // lightgreen
35         const vector COLOR50 = '1 1 1'; // white
36         const vector COLOR25 = '1 1 0.2'; // lightyellow
37         const vector COLOR10 = '1 0 0'; // red
38         vector color;
39
40         float hp_percent = hp / maxvalue * 100;
41         #define CASE_COLOR_BETWEEN(min, max) \
42                 if(hp_percent > min) \
43                         color = COLOR##min + (COLOR##max - COLOR##min) * ((hp_percent - min) / (max - min))
44
45         if(hp_percent > 100) color = COLOR100;
46         else CASE_COLOR_BETWEEN(75, 100);
47         else CASE_COLOR_BETWEEN(50, 75);
48         else CASE_COLOR_BETWEEN(25, 50);
49         else CASE_COLOR_BETWEEN(10, 25);
50         else color = COLOR10;
51
52         #undef CASE_COLOR_BETWEEN
53
54         if (blink)
55         {
56                 if(hp_percent >= 100)
57                 {
58                         float f = sin(2*M_PI*time);
59                         if (color.x == 0) color.x = f;
60                         if (color.y == 0) color.y = f;
61                         if (color.z == 0) color.z = f;
62                 }
63                 else if(hp_percent < 25)
64                 {
65                         float f = (1 - hp_percent / 25) * sin(2*M_PI*time);
66                         color -= color * f;
67                 }
68         }
69
70         return color;
71 }
72
73 float HUD_GetRowCount(int item_count, vector size, float item_aspect)
74 {
75         TC(int, item_count);
76         float aspect = size_y / size_x;
77         return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count);
78 }
79
80 vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
81 {
82         TC(int, item_count);
83         float columns, rows;
84         float ratio, best_ratio = 0;
85         float best_columns = 1, best_rows = 1;
86         bool vertical = (psize.x / psize.y >= item_aspect);
87         if(vertical)
88         {
89                 psize = eX * psize.y + eY * psize.x;
90                 item_aspect = 1 / item_aspect;
91         }
92
93         rows = ceil(sqrt(item_count));
94         columns = ceil(item_count/rows);
95         while(columns >= 1)
96         {
97                 ratio = (psize.x/columns) / (psize.y/rows);
98                 if(ratio > item_aspect)
99                         ratio = item_aspect * item_aspect / ratio;
100
101                 if(ratio <= best_ratio)
102                         break; // ratio starts decreasing by now, skip next configurations
103
104                 best_columns = columns;
105                 best_rows = rows;
106                 best_ratio = ratio;
107
108                 if(columns == 1)
109                         break;
110
111                 --columns;
112                 rows = ceil(item_count/columns);
113         }
114
115         return (vertical) ? vec2(best_rows, best_columns) : vec2(best_columns, best_rows);
116 }
117
118 /*
119 ==================
120 HUD panels
121 ==================
122 */
123
124 void HUD_Panel_LoadCvars()
125 {
126         // NOTE: in hud_configure mode cvars must be reloaded every frame
127         if (panel.update_time <= time)
128         {
129                 panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos")));
130                 panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size")));
131                 HUD_Panel_ScalePosSize();
132                 panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg"));
133                 panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color"));
134                 panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team"));
135                 panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha"));
136                 panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border"));
137                 panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding"));
138                 HUD_Panel_GetBg();
139                 if (panel.current_panel_bg != "0")
140                 {
141                         HUD_Panel_GetBgAlpha();
142                         HUD_Panel_GetBorder();
143                 }
144                 HUD_Panel_GetColorTeam();
145                 HUD_Panel_GetColor();
146                 HUD_Panel_GetFgAlpha();
147                 HUD_Panel_GetPadding();
148                 panel.current_panel_bg_alpha = panel_bg_alpha;
149                 panel.current_panel_fg_alpha = panel_fg_alpha;
150                 if (hud_configure_menu_open == 2 && panel == highlightedPanel)
151                         HUD_Panel_UpdatePosSize_ForMenu();
152                 else
153                 {
154                         panel_bg_alpha *= hud_fade_alpha * panel_fade_alpha;
155                         panel_fg_alpha *= hud_fade_alpha * panel_fade_alpha;
156                 }
157                 panel.current_panel_pos = panel_pos;
158                 panel.current_panel_size = panel_size;
159                 panel.current_panel_bg_border = panel_bg_border;
160                 panel.current_panel_bg_color = panel_bg_color;
161                 panel.current_panel_bg_color_team = panel_bg_color_team;
162                 panel.current_panel_bg_padding = panel_bg_padding;
163                 panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval;
164                 return;
165         }
166
167         panel_pos = panel.current_panel_pos;
168         panel_size = panel.current_panel_size;
169         panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha * panel_fade_alpha;
170         panel_bg_border = panel.current_panel_bg_border;
171         panel_bg_color = panel.current_panel_bg_color;
172         panel_bg_color_team = panel.current_panel_bg_color_team;
173         panel_bg_padding = panel.current_panel_bg_padding;
174         panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha * panel_fade_alpha;
175 }
176
177 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
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         TC(bool, vertical); TC(int, drawflag);
181         if(!length_ratio || !theAlpha)
182                 return;
183         if(length_ratio > 1)
184                 length_ratio = 1;
185         if (baralign == 3)
186         {
187                 if(length_ratio < -1)
188                         length_ratio = -1;
189         }
190         else if(length_ratio < 0)
191                 return;
192
193         theOrigin = HUD_Shift(theOrigin);
194         theSize = HUD_Scale(theSize);
195
196         vector square;
197         vector width, height;
198         if(vertical) {
199                 pic = strcat(hud_skin_path, "/", pic, "_vertical");
200                 if(precache_pic(pic) == "") {
201                         pic = "gfx/hud/default/progressbar_vertical";
202                 }
203
204         if (baralign == 1) // bottom align
205                         theOrigin.y += (1 - length_ratio) * theSize.y;
206         else if (baralign == 2) // center align
207             theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
208         else if (baralign == 3) // center align, positive values down, negative up
209                 {
210                         theSize.y *= 0.5;
211                         if (length_ratio > 0)
212                                 theOrigin.y += theSize.y;
213                         else
214                         {
215                                 theOrigin.y += (1 + length_ratio) * theSize.y;
216                                 length_ratio = -length_ratio;
217                         }
218                 }
219                 theSize.y *= length_ratio;
220
221                 vector bH;
222                 width = eX * theSize.x;
223                 height = eY * theSize.y;
224                 if(theSize.y <= theSize.x * 2)
225                 {
226                         // button not high enough
227                         // draw just upper and lower part then
228                         square = eY * theSize.y * 0.5;
229                         bH = eY * (0.25 * theSize.y / (theSize.x * 2));
230                         drawsubpic(theOrigin,          square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
231                         drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
232                 }
233                 else
234                 {
235                         square = eY * theSize.x;
236                         drawsubpic(theOrigin,                   width   +     square, pic, '0 0    0', '1 0.25 0', theColor, theAlpha, drawflag);
237                         drawsubpic(theOrigin +          square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5  0', theColor, theAlpha, drawflag);
238                         drawsubpic(theOrigin + height - square, width   +     square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
239                 }
240         } else {
241                 pic = strcat(hud_skin_path, "/", pic);
242                 if(precache_pic(pic) == "") {
243                         pic = "gfx/hud/default/progressbar";
244                 }
245
246                 if (baralign == 1) // right align
247                         theOrigin.x += (1 - length_ratio) * theSize.x;
248         else if (baralign == 2) // center align
249             theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
250         else if (baralign == 3) // center align, positive values on the right, negative on the left
251                 {
252                         theSize.x *= 0.5;
253                         if (length_ratio > 0)
254                                 theOrigin.x += theSize.x;
255                         else
256                         {
257                                 theOrigin.x += (1 + length_ratio) * theSize.x;
258                                 length_ratio = -length_ratio;
259                         }
260                 }
261                 theSize.x *= length_ratio;
262
263                 vector bW;
264                 width = eX * theSize.x;
265                 height = eY * theSize.y;
266                 if(theSize.x <= theSize.y * 2)
267                 {
268                         // button not wide enough
269                         // draw just left and right part then
270                         square = eX * theSize.x * 0.5;
271                         bW = eX * (0.25 * theSize.x / (theSize.y * 2));
272                         drawsubpic(theOrigin,          square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
273                         drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
274                 }
275                 else
276                 {
277                         square = eX * theSize.y;
278                         drawsubpic(theOrigin,                  height  +     square, pic, '0    0 0', '0.25 1 0', theColor, theAlpha, drawflag);
279                         drawsubpic(theOrigin +         square, theSize - 2 * square, pic, '0.25 0 0', '0.5  1 0', theColor, theAlpha, drawflag);
280                         drawsubpic(theOrigin + width - square, height  +     square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
281                 }
282         }
283 }
284
285 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
286 {
287         TC(int, drawflag);
288         if(!theAlpha)
289                 return;
290
291         pos = HUD_Shift(pos);
292         mySize = HUD_Scale(mySize);
293
294         string pic;
295         pic = strcat(hud_skin_path, "/num_leading");
296         if(precache_pic(pic) == "") {
297                 pic = "gfx/hud/default/num_leading";
298         }
299
300         drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
301         if(mySize.x/mySize.y > 2)
302                 drawsubpic(pos + eX * mySize.y, eX * (mySize.x - 2 * mySize.y) + eY * mySize.y, pic, '0.25 0 0', '0.5 1 0', color, theAlpha, drawflag);
303         drawsubpic(pos + eX * mySize.x - eX * min(mySize.x * 0.5, mySize.y), eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0.75 0 0', '0.25 1 0', color, theAlpha, drawflag);
304 }
305
306 void DrawNumIcon_expanding(vector myPos, vector mySize, float theTime, string icon, bool vertical, int icon_right_align, vector color, float theAlpha, float fadelerp)
307 {
308         TC(bool, vertical); TC(int, icon_right_align);
309         vector newPos = '0 0 0', newSize = '0 0 0';
310         vector picpos, numpos;
311
312         if (vertical)
313         {
314                 if(mySize.y/mySize.x > 2)
315                 {
316                         newSize.y = 2 * mySize.x;
317                         newSize.x = mySize.x;
318
319                         newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
320                         newPos.x = myPos.x;
321                 }
322                 else
323                 {
324                         newSize.x = 1/2 * mySize.y;
325                         newSize.y = mySize.y;
326
327                         newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
328                         newPos.y = myPos.y;
329                 }
330
331                 if(icon_right_align)
332                 {
333                         numpos = newPos;
334                         picpos = newPos + eY * newSize.x;
335                 }
336                 else
337                 {
338                         picpos = newPos;
339                         numpos = newPos + eY * newSize.x;
340                 }
341
342                 newSize.y /= 2;
343                 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
344                 // make number smaller than icon, it looks better
345                 // reduce only y to draw numbers with different number of digits with the same y size
346                 numpos.y += newSize.y * ((1 - 0.7) / 2);
347                 newSize.y *= 0.7;
348                 drawstring_aspect(numpos, ftos(theTime), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
349                 return;
350         }
351
352         if(mySize.x/mySize.y > 3)
353         {
354                 newSize.x = 3 * mySize.y;
355                 newSize.y = mySize.y;
356
357                 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
358                 newPos.y = myPos.y;
359         }
360         else
361         {
362                 newSize.y = 1/3 * mySize.x;
363                 newSize.x = mySize.x;
364
365                 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
366                 newPos.x = myPos.x;
367         }
368
369         if(icon_right_align) // right align
370         {
371                 numpos = newPos;
372                 picpos = newPos + eX * 2 * newSize.y;
373         }
374         else // left align
375         {
376                 numpos = newPos + eX * newSize.y;
377                 picpos = newPos;
378         }
379
380         // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
381         // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
382         drawstring_aspect_expanding(numpos, ftos(theTime), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
383         drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
384 }
385
386 void DrawNumIcon(vector myPos, vector mySize, float theTime, string icon, bool vertical, int icon_right_align, vector color, float theAlpha)
387 {
388         TC(bool, vertical); TC(int, icon_right_align);
389         DrawNumIcon_expanding(myPos, mySize, theTime, icon, vertical, icon_right_align, color, theAlpha, 0);
390 }
391
392 /*
393 ==================
394 Main HUD system
395 ==================
396 */
397
398 float lasthud;
399 float vh_notice_time;
400 void HUD_Vehicle()
401 {
402         if(autocvar__hud_configure) return;
403         if(intermission == 2) return;
404
405         if(hud == HUD_BUMBLEBEE_GUN)
406                 CSQC_BUMBLE_GUN_HUD();
407         else {
408                 Vehicle info = REGISTRY_GET(Vehicles, hud);
409                 info.vr_hud(info);
410         }
411
412         if(hud != HUD_NORMAL && lasthud == HUD_NORMAL)
413                 vh_notice_time = time + autocvar_cl_vehicles_notify_time;
414
415         lasthud = hud;
416 }
417
418 void HUD_Panel_Draw(entity panent)
419 {
420         panel = panent;
421         if (autocvar__hud_configure)
422         {
423                 if (!(panel.panel_configflags & PANEL_CONFIG_MAIN))
424                         return;
425                 panel_fade_alpha = 1;
426                 Hud_Panel_GetPanelEnabled();
427                 panel.panel_draw();
428                 return;
429         }
430
431         bool draw_allowed = false;
432         if (scoreboard_fade_alpha && panel.panel_showflags & PANEL_SHOW_WITH_SB)
433         {
434                 draw_allowed = true;
435         }
436         else if (active_minigame && HUD_MinigameMenu_IsOpened())
437         {
438                 if (panel.panel_showflags & PANEL_SHOW_MINIGAME)
439                         draw_allowed = true;
440         }
441         else if(intermission == 2)
442         {
443                 if(panel.panel_showflags & PANEL_SHOW_MAPVOTE)
444                         draw_allowed = true;
445         }
446         else if (panel.panel_showflags & PANEL_SHOW_MAINGAME)
447                 draw_allowed = true;
448
449         if (draw_allowed)
450         {
451                 if (panel.panel_showflags & PANEL_SHOW_WITH_SB)
452                 {
453                         if (scoreboard_fade_alpha && intermission == 2 && !(panel.panel_showflags & PANEL_SHOW_MAPVOTE))
454                                 panel_fade_alpha = scoreboard_fade_alpha;
455                         else
456                                 panel_fade_alpha = 1;
457                 }
458                 else
459                 {
460                         panel_fade_alpha = 1 - scoreboard_fade_alpha;
461                         if(!panel_fade_alpha)
462                                 return;
463                 }
464                 panel.panel_draw();
465         }
466 }
467
468 void HUD_Reset()
469 {
470         // reset gametype specific icons
471         if(gametype.m_modicons_reset)
472                 gametype.m_modicons_reset();
473 }
474
475 float autocvar_hud_dynamic_shake = 1;
476 float autocvar_hud_dynamic_shake_damage_max = 130;
477 float autocvar_hud_dynamic_shake_damage_min = 10;
478 float autocvar_hud_dynamic_shake_scale = 0.2;
479 float hud_dynamic_shake_x[10] = {0,    1, -0.7,  0.5, -0.3,  0.2, -0.1,  0.1,  0.0, 0};
480 float hud_dynamic_shake_y[10] = {0,  0.4,  0.8, -0.2, -0.6,  0.0,  0.3,  0.1, -0.1, 0};
481 bool Hud_Shake_Update()
482 {
483         if(time - hud_dynamic_shake_time < 0)
484                 return false;
485
486         float anim_speed = 17 + 9 * hud_dynamic_shake_factor;
487         float elapsed_time = (time - hud_dynamic_shake_time) * anim_speed;
488         int i = floor(elapsed_time);
489         if(i >= 9)
490                 return false;
491
492         float f = elapsed_time - i;
493         hud_dynamic_shake_realofs.x = (1 - f) * hud_dynamic_shake_x[i] + f * hud_dynamic_shake_x[i+1];
494         hud_dynamic_shake_realofs.y = (1 - f) * hud_dynamic_shake_y[i] + f * hud_dynamic_shake_y[i+1];
495         hud_dynamic_shake_realofs.z = 0;
496         hud_dynamic_shake_realofs *= hud_dynamic_shake_factor * autocvar_hud_dynamic_shake_scale;
497         hud_dynamic_shake_realofs.x = bound(-0.1, hud_dynamic_shake_realofs.x, 0.1) * vid_conwidth;
498         hud_dynamic_shake_realofs.y = bound(-0.1, hud_dynamic_shake_realofs.y, 0.1) * vid_conheight;
499         return true;
500 }
501
502 void Hud_Dynamic_Frame()
503 {
504         vector ofs = '0 0 0';
505         hud_scale_current = '1 1 0';
506         hud_shift_current = '0 0 0';
507
508         if (autocvar_hud_dynamic_follow)
509         {
510                 entity view = CSQCModel_server2csqc(player_localentnum - 1);
511                 calc_followmodel_ofs(view);
512                 ofs = -cl_followmodel_ofs * autocvar_hud_dynamic_follow_scale;
513                 ofs.x *= autocvar_hud_dynamic_follow_scale_xyz.z;
514                 ofs.y *= autocvar_hud_dynamic_follow_scale_xyz.x;
515                 ofs.z *= autocvar_hud_dynamic_follow_scale_xyz.y;
516
517                 if (fabs(ofs.x) < 0.001) ofs.x = 0;
518                 if (fabs(ofs.y) < 0.001) ofs.y = 0;
519                 if (fabs(ofs.z) < 0.001) ofs.z = 0;
520                 ofs.x = bound(-0.1, ofs.x, 0.1);
521                 ofs.y = bound(-0.1, ofs.y, 0.1);
522                 ofs.z = bound(-0.1, ofs.z, 0.1);
523
524                 hud_shift_current.x = ofs.y * vid_conwidth;
525                 hud_shift_current.y = ofs.z * vid_conheight;
526                 hud_shift_current.z = ofs.x;
527
528                 hud_scale_current.x = (1 + hud_shift_current.z);
529                 hud_scale_current.y = hud_scale_current.x;
530         }
531
532         if(autocvar_hud_dynamic_shake > 0)
533         {
534                 static float old_health = 0;
535                 float health = max(-1, STAT(HEALTH));
536                 if(hud_dynamic_shake_factor == -1) // don't allow the effect for this frame
537                 {
538                         hud_dynamic_shake_factor = 0;
539                         old_health = health;
540                 }
541                 else
542                 {
543                         float new_hud_dynamic_shake_factor = 0;
544                         if (old_health - health >= autocvar_hud_dynamic_shake_damage_min
545                                 && autocvar_hud_dynamic_shake_damage_max > autocvar_hud_dynamic_shake_damage_min
546                                 && old_health > 0 && !intermission)
547                         {
548                                 float m = max(autocvar_hud_dynamic_shake_damage_min, 1);
549                                 new_hud_dynamic_shake_factor = (old_health - health - m) / (autocvar_hud_dynamic_shake_damage_max - m);
550                                 if(new_hud_dynamic_shake_factor >= 1)
551                                         new_hud_dynamic_shake_factor = 1;
552                                 if(new_hud_dynamic_shake_factor >= hud_dynamic_shake_factor)
553                                 {
554                                         hud_dynamic_shake_factor = new_hud_dynamic_shake_factor;
555                                         hud_dynamic_shake_time = time;
556                                 }
557                         }
558                         old_health = health;
559                         if(hud_dynamic_shake_factor)
560                                 if(!Hud_Shake_Update())
561                                         hud_dynamic_shake_factor = 0;
562                 }
563
564                 if(hud_dynamic_shake_factor > 0)
565                 {
566                         hud_shift_current.x += hud_dynamic_shake_realofs.x;
567                         hud_shift_current.y += hud_dynamic_shake_realofs.y;
568                 }
569         }
570
571         hud_scale_center.x = 0.5 * vid_conwidth;
572         hud_scale_center.y = 0.5 * vid_conheight;
573
574         HUD_Scale_Disable();
575 }
576
577 bool HUD_WouldShowCursor()
578 {
579         if(autocvar__hud_configure)
580                 return true;
581         if(mv_active)
582                 return true;
583         //entity local_player = ((csqcplayer) ? csqcplayer : CSQCModel_server2csqc(player_localentnum - 1)); // TODO: doesn't use regular cursor handling
584         //if(local_player.viewloc && (local_player.viewloc.spawnflags & VIEWLOC_FREEAIM))
585                 //return true;
586         if(HUD_Radar_Clickable())
587                 return true;
588         if(HUD_MinigameMenu_IsOpened())
589                 return true;
590         if(QuickMenu_IsOpened())
591                 return true;
592         return false;
593 }
594
595 float prev_myteam;
596 void HUD_Main()
597 {
598         int i;
599         if(hud_configure_menu_open == 1)
600                 hud_fade_alpha = 1;
601         else
602                 hud_fade_alpha = 1 - autocvar__menu_alpha;
603
604         if(myteam != prev_myteam)
605         {
606                 myteamcolors = colormapPaletteColor(myteam, 1);
607                 FOREACH(hud_panels, true, it.update_time = time);
608                 prev_myteam = myteam;
609         }
610
611         HUD_Configure_Frame();
612
613         if(scoreboard_fade_alpha == 1)
614                 if(autocvar__menu_alpha == 1)
615                         return;
616
617         // Drawing stuff
618         if (hud_skin_prev != autocvar_hud_skin)
619         {
620                 strcpy(hud_skin_path, strcat("gfx/hud/", autocvar_hud_skin));
621                 strcpy(hud_skin_prev, autocvar_hud_skin);
622         }
623
624         // draw the dock
625         if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
626         {
627                 int f;
628                 vector color;
629                 float hud_dock_color_team = autocvar_hud_dock_color_team;
630                 if((teamplay) && hud_dock_color_team) {
631                         if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
632                                 color = '1 0 0' * hud_dock_color_team;
633                         else
634                                 color = myteamcolors * hud_dock_color_team;
635                 }
636                 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
637                         color = '1 0 0' * hud_dock_color_team;
638                 }
639                 else
640                 {
641                         string hud_dock_color = autocvar_hud_dock_color;
642                         if(hud_dock_color == "shirt") {
643                                 f = entcs_GetClientColors(current_player);
644                                 color = colormapPaletteColor(floor(f / 16), 0);
645                         }
646                         else if(hud_dock_color == "pants") {
647                                 f = entcs_GetClientColors(current_player);
648                                 color = colormapPaletteColor(f % 16, 1);
649                         }
650                         else
651                                 color = stov(hud_dock_color);
652                 }
653
654                 string pic;
655                 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
656                 if(precache_pic(pic) == "") {
657                         pic = strcat(hud_skin_path, "/dock_medium");
658                         if(precache_pic(pic) == "") {
659                                 pic = "gfx/hud/default/dock_medium";
660                         }
661                 }
662                 drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, autocvar_hud_dock_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
663         }
664
665         // cache the panel order into the panel_order array
666         if(autocvar__hud_panelorder != hud_panelorder_prev) {
667                 for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
668                         panel_order[i] = -1;
669                 string s = "";
670                 int p_num;
671                 bool warning = false;
672                 int argc = tokenize_console(autocvar__hud_panelorder);
673                 if (argc > REGISTRY_COUNT(hud_panels))
674                         warning = true;
675                 //first detect wrong/missing panel numbers
676                 for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
677                         p_num = stoi(argv(i));
678                         if (p_num >= 0 && p_num < REGISTRY_COUNT(hud_panels)) { //correct panel number?
679                                 if (panel_order[p_num] == -1) //found for the first time?
680                                         s = strcat(s, ftos(p_num), " ");
681                                 panel_order[p_num] = 1; //mark as found
682                         }
683                         else
684                                 warning = true;
685                 }
686                 for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
687                         if (panel_order[i] == -1) {
688                                 warning = true;
689                                 s = strcat(s, ftos(i), " "); //add missing panel number
690                         }
691                 }
692                 if (warning)
693                         LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder");
694
695                 cvar_set("_hud_panelorder", s);
696                 strcpy(hud_panelorder_prev, s);
697
698                 //now properly set panel_order
699                 tokenize_console(s);
700                 for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
701                         panel_order[i] = stof(argv(i));
702                 }
703         }
704
705         hud_draw_maximized = 0;
706         // draw panels in the order specified by panel_order array
707         for(i = REGISTRY_COUNT(hud_panels) - 1; i >= 0; --i)
708                 HUD_Panel_Draw(REGISTRY_GET(hud_panels, panel_order[i]));
709
710         HUD_Vehicle();
711
712         hud_draw_maximized = 1; // panels that may be maximized must check this var
713         // draw maximized panels on top
714         if(hud_panel_radar_maximized)
715                 HUD_Panel_Draw(HUD_PANEL(RADAR));
716         if(autocvar__con_chat_maximized)
717                 HUD_Panel_Draw(HUD_PANEL(CHAT));
718         if (QuickMenu_IsOpened())
719                 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
720         HUD_Panel_Draw(HUD_PANEL(SCOREBOARD));
721
722         int cursor_active_prev = cursor_active;
723         cursor_active = HUD_WouldShowCursor();
724         if (cursor_active_prev != cursor_active && autocvar_hud_cursormode)
725         {
726                 setcursormode(cursor_active);
727                 // cursor inactive this frame, will be set to 1 the next frame
728                 if (cursor_active)
729                         cursor_active = -1;
730         }
731
732         if (intermission == 2)
733                 HUD_Reset();
734
735         HUD_Configure_PostDraw();
736
737         hud_configure_prev = autocvar__hud_configure;
738 }