]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/hud.qc
Add a quickmenu command to select a player to spectate
[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 (scoreboard_fade_alpha && panel.panel_showflags & PANEL_SHOW_WITH_SB)
429         {
430                 draw_allowed = true;
431         }
432         else if (active_minigame && HUD_MinigameMenu_IsOpened())
433         {
434                 if (panel.panel_showflags & PANEL_SHOW_MINIGAME)
435                         draw_allowed = true;
436         }
437         else if(intermission == 2)
438         {
439                 if(panel.panel_showflags & PANEL_SHOW_MAPVOTE)
440                         draw_allowed = true;
441         }
442         else if (panel.panel_showflags & PANEL_SHOW_MAINGAME)
443                 draw_allowed = true;
444
445         if (draw_allowed)
446         {
447                 if (panel.panel_showflags & PANEL_SHOW_WITH_SB)
448                 {
449                         if (scoreboard_fade_alpha && intermission == 2 && !(panel.panel_showflags & PANEL_SHOW_MAPVOTE))
450                                 panel_fade_alpha = scoreboard_fade_alpha;
451                         else
452                                 panel_fade_alpha = 1;
453                 }
454                 else
455                 {
456                         panel_fade_alpha = 1 - scoreboard_fade_alpha;
457                         if(!panel_fade_alpha)
458                                 return;
459                 }
460                 panel.panel_draw();
461         }
462 }
463
464 void HUD_Reset()
465 {
466         // reset gametype specific icons
467         if(gametype.m_modicons_reset)
468                 gametype.m_modicons_reset();
469 }
470
471 float autocvar_hud_dynamic_shake = 1;
472 float autocvar_hud_dynamic_shake_damage_max = 130;
473 float autocvar_hud_dynamic_shake_damage_min = 10;
474 float autocvar_hud_dynamic_shake_scale = 0.2;
475 float hud_dynamic_shake_x[10] = {0,    1, -0.7,  0.5, -0.3,  0.2, -0.1,  0.1,  0.0, 0};
476 float hud_dynamic_shake_y[10] = {0,  0.4,  0.8, -0.2, -0.6,  0.0,  0.3,  0.1, -0.1, 0};
477 bool Hud_Shake_Update()
478 {
479         if(time - hud_dynamic_shake_time < 0)
480                 return false;
481
482         float anim_speed = 17 + 9 * hud_dynamic_shake_factor;
483         float elapsed_time = (time - hud_dynamic_shake_time) * anim_speed;
484         int i = floor(elapsed_time);
485         if(i >= 9)
486                 return false;
487
488         float f = elapsed_time - i;
489         hud_dynamic_shake_realofs.x = (1 - f) * hud_dynamic_shake_x[i] + f * hud_dynamic_shake_x[i+1];
490         hud_dynamic_shake_realofs.y = (1 - f) * hud_dynamic_shake_y[i] + f * hud_dynamic_shake_y[i+1];
491         hud_dynamic_shake_realofs.z = 0;
492         hud_dynamic_shake_realofs *= hud_dynamic_shake_factor * autocvar_hud_dynamic_shake_scale;
493         hud_dynamic_shake_realofs.x = bound(-0.1, hud_dynamic_shake_realofs.x, 0.1) * vid_conwidth;
494         hud_dynamic_shake_realofs.y = bound(-0.1, hud_dynamic_shake_realofs.y, 0.1) * vid_conheight;
495         return true;
496 }
497
498 void Hud_Dynamic_Frame()
499 {
500         vector ofs = '0 0 0';
501         hud_scale_current = '1 1 0';
502         hud_shift_current = '0 0 0';
503
504         if (autocvar_hud_dynamic_follow)
505         {
506                 entity view = CSQCModel_server2csqc(player_localentnum - 1);
507                 calc_followmodel_ofs(view);
508                 ofs = -cl_followmodel_ofs * autocvar_hud_dynamic_follow_scale;
509                 ofs.x *= autocvar_hud_dynamic_follow_scale_xyz.z;
510                 ofs.y *= autocvar_hud_dynamic_follow_scale_xyz.x;
511                 ofs.z *= autocvar_hud_dynamic_follow_scale_xyz.y;
512
513                 if (fabs(ofs.x) < 0.001) ofs.x = 0;
514                 if (fabs(ofs.y) < 0.001) ofs.y = 0;
515                 if (fabs(ofs.z) < 0.001) ofs.z = 0;
516                 ofs.x = bound(-0.1, ofs.x, 0.1);
517                 ofs.y = bound(-0.1, ofs.y, 0.1);
518                 ofs.z = bound(-0.1, ofs.z, 0.1);
519
520                 hud_shift_current.x = ofs.y * vid_conwidth;
521                 hud_shift_current.y = ofs.z * vid_conheight;
522                 hud_shift_current.z = ofs.x;
523
524                 hud_scale_current.x = (1 + hud_shift_current.z);
525                 hud_scale_current.y = hud_scale_current.x;
526         }
527
528         if(autocvar_hud_dynamic_shake > 0)
529         {
530                 static float old_health = 0;
531                 float health = max(-1, STAT(HEALTH));
532                 if(hud_dynamic_shake_factor == -1) // don't allow the effect for this frame
533                 {
534                         hud_dynamic_shake_factor = 0;
535                         old_health = health;
536                 }
537                 else
538                 {
539                         float new_hud_dynamic_shake_factor = 0;
540                         if (old_health - health >= autocvar_hud_dynamic_shake_damage_min
541                                 && autocvar_hud_dynamic_shake_damage_max > autocvar_hud_dynamic_shake_damage_min
542                                 && old_health > 0 && !intermission)
543                         {
544                                 float m = max(autocvar_hud_dynamic_shake_damage_min, 1);
545                                 new_hud_dynamic_shake_factor = (old_health - health - m) / (autocvar_hud_dynamic_shake_damage_max - m);
546                                 if(new_hud_dynamic_shake_factor >= 1)
547                                         new_hud_dynamic_shake_factor = 1;
548                                 if(new_hud_dynamic_shake_factor >= hud_dynamic_shake_factor)
549                                 {
550                                         hud_dynamic_shake_factor = new_hud_dynamic_shake_factor;
551                                         hud_dynamic_shake_time = time;
552                                 }
553                         }
554                         old_health = health;
555                         if(hud_dynamic_shake_factor)
556                                 if(!Hud_Shake_Update())
557                                         hud_dynamic_shake_factor = 0;
558                 }
559
560                 if(hud_dynamic_shake_factor > 0)
561                 {
562                         hud_shift_current.x += hud_dynamic_shake_realofs.x;
563                         hud_shift_current.y += hud_dynamic_shake_realofs.y;
564                 }
565         }
566
567         hud_scale_center.x = 0.5 * vid_conwidth;
568         hud_scale_center.y = 0.5 * vid_conheight;
569
570         HUD_Scale_Disable();
571 }
572
573 bool HUD_WouldShowCursor()
574 {
575         if(autocvar__hud_configure)
576                 return true;
577         if(mv_active)
578                 return true;
579         //entity local_player = ((csqcplayer) ? csqcplayer : CSQCModel_server2csqc(player_localentnum - 1)); // TODO: doesn't use regular cursor handling
580         //if(local_player.viewloc && (local_player.viewloc.spawnflags & VIEWLOC_FREEAIM))
581                 //return true;
582         if(HUD_Radar_Clickable())
583                 return true;
584         if(HUD_MinigameMenu_IsOpened())
585                 return true;
586         if(QuickMenu_IsOpened())
587                 return true;
588         return false;
589 }
590
591 void HUD_Main()
592 {
593         int i;
594         if(hud_configure_menu_open == 1)
595                 hud_fade_alpha = 1;
596         else
597                 hud_fade_alpha = 1 - autocvar__menu_alpha;
598
599         HUD_Configure_Frame();
600
601         if(scoreboard_fade_alpha == 1)
602                 if(autocvar__menu_alpha == 1)
603                         return;
604
605         // Drawing stuff
606         if (hud_skin_prev != autocvar_hud_skin)
607         {
608                 strcpy(hud_skin_path, strcat("gfx/hud/", autocvar_hud_skin));
609                 strcpy(hud_skin_prev, autocvar_hud_skin);
610         }
611
612         // draw the dock
613         if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
614         {
615                 int f;
616                 vector color;
617                 float hud_dock_color_team = autocvar_hud_dock_color_team;
618                 if((teamplay) && hud_dock_color_team) {
619                         if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
620                                 color = '1 0 0' * hud_dock_color_team;
621                         else
622                                 color = myteamcolors * hud_dock_color_team;
623                 }
624                 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
625                         color = '1 0 0' * hud_dock_color_team;
626                 }
627                 else
628                 {
629                         string hud_dock_color = autocvar_hud_dock_color;
630                         if(hud_dock_color == "shirt") {
631                                 f = entcs_GetClientColors(current_player);
632                                 color = colormapPaletteColor(floor(f / 16), 0);
633                         }
634                         else if(hud_dock_color == "pants") {
635                                 f = entcs_GetClientColors(current_player);
636                                 color = colormapPaletteColor(f % 16, 1);
637                         }
638                         else
639                                 color = stov(hud_dock_color);
640                 }
641
642                 string pic;
643                 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
644                 if(precache_pic(pic) == "") {
645                         pic = strcat(hud_skin_path, "/dock_medium");
646                         if(precache_pic(pic) == "") {
647                                 pic = "gfx/hud/default/dock_medium";
648                         }
649                 }
650                 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...
651         }
652
653         // cache the panel order into the panel_order array
654         if(autocvar__hud_panelorder != hud_panelorder_prev) {
655                 for(i = 0; i < hud_panels_COUNT; ++i)
656                         panel_order[i] = -1;
657                 string s = "";
658                 int p_num;
659                 bool warning = false;
660                 int argc = tokenize_console(autocvar__hud_panelorder);
661                 if (argc > hud_panels_COUNT)
662                         warning = true;
663                 //first detect wrong/missing panel numbers
664                 for(i = 0; i < hud_panels_COUNT; ++i) {
665                         p_num = stoi(argv(i));
666                         if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
667                                 if (panel_order[p_num] == -1) //found for the first time?
668                                         s = strcat(s, ftos(p_num), " ");
669                                 panel_order[p_num] = 1; //mark as found
670                         }
671                         else
672                                 warning = true;
673                 }
674                 for(i = 0; i < hud_panels_COUNT; ++i) {
675                         if (panel_order[i] == -1) {
676                                 warning = true;
677                                 s = strcat(s, ftos(i), " "); //add missing panel number
678                         }
679                 }
680                 if (warning)
681                         LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder");
682
683                 cvar_set("_hud_panelorder", s);
684                 strcpy(hud_panelorder_prev, s);
685
686                 //now properly set panel_order
687                 tokenize_console(s);
688                 for(i = 0; i < hud_panels_COUNT; ++i) {
689                         panel_order[i] = stof(argv(i));
690                 }
691         }
692
693         hud_draw_maximized = 0;
694         // draw panels in the order specified by panel_order array
695         for(i = hud_panels_COUNT - 1; i >= 0; --i)
696                 HUD_Panel_Draw(hud_panels_from(panel_order[i]));
697
698         HUD_Vehicle();
699
700         hud_draw_maximized = 1; // panels that may be maximized must check this var
701         // draw maximized panels on top
702         if(hud_panel_radar_maximized)
703                 HUD_Panel_Draw(HUD_PANEL(RADAR));
704         if(autocvar__con_chat_maximized)
705                 HUD_Panel_Draw(HUD_PANEL(CHAT));
706         if (QuickMenu_IsOpened())
707                 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
708         HUD_Panel_Draw(HUD_PANEL(SCOREBOARD));
709
710         int cursor_active_prev = cursor_active;
711         cursor_active = HUD_WouldShowCursor();
712         if (cursor_active_prev != cursor_active && autocvar_hud_cursormode)
713         {
714                 setcursormode(cursor_active);
715                 // cursor inactive this frame, will be set to 1 the next frame
716                 if (cursor_active)
717                         cursor_active = -1;
718         }
719
720         if (intermission == 2)
721                 HUD_Reset();
722
723         HUD_Configure_PostDraw();
724
725         hud_configure_prev = autocvar__hud_configure;
726 }