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