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