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