4 #include "hud_config.qh"
5 #include "mapvoting.qh"
6 #include "scoreboard.qh"
8 #include "teamradar.qh"
11 #include "../dpdefs/keycodes.qh"
13 #include "../common/buffs.qh"
14 #include "../common/constants.qh"
15 #include "../common/counting.qh"
16 #include "../common/deathtypes.qh"
17 #include "../common/items/all.qc"
18 #include "../common/mapinfo.qh"
19 #include "../common/nades.qh"
21 #include "../server/mutators/gamemode_ctf.qh"
23 #include "../common/stats.qh"
25 #include "../csqcmodellib/cl_player.qh"
27 #include "../warpzonelib/mathlib.qh"
35 // a border picture is a texture containing nine parts:
36 // 1/4 width: left part
37 // 1/2 width: middle part (stretched)
38 // 1/4 width: right part
40 // 1/4 height: top part
41 // 1/2 height: middle part (stretched)
42 // 1/4 height: bottom part
43 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
45 if (theBorderSize.x < 0 && theBorderSize.y < 0) // draw whole image as it is
47 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
50 if (theBorderSize.x == 0 && theBorderSize.y == 0) // no border
52 // draw only the central part
53 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
60 //pic = draw_UseSkinFor(pic);
61 width = eX * theSize.x;
62 height = eY * theSize.y;
63 if(theSize.x <= theBorderSize.x * 2)
65 // not wide enough... draw just left and right then
66 bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2));
67 if(theSize.y <= theBorderSize.y * 2)
69 // not high enough... draw just corners
70 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
71 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
72 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
73 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
74 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
78 dY = theBorderSize.x * eY;
79 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
80 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
81 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
82 drawsubpic(theOrigin + width * 0.5 + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0' + eX - bW, '0 0.5 0' + bW, theColor, theAlpha, 0);
83 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
84 drawsubpic(theOrigin + width * 0.5 + height - dY, width * 0.5 + dY, pic, '0 0.75 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
89 if(theSize.y <= theBorderSize.y * 2)
91 // not high enough... draw just top and bottom then
92 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
93 dX = theBorderSize.x * eX;
94 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
95 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
96 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
97 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
98 drawsubpic(theOrigin + dX + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5 0 0' + bH, theColor, theAlpha, 0);
99 drawsubpic(theOrigin + width - dX + height * 0.5, dX + height * 0.5, pic, '0.75 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
103 dX = theBorderSize.x * eX;
104 dY = theBorderSize.x * eY;
105 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
106 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
107 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
108 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
109 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
110 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
111 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
112 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
113 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
118 vector HUD_Get_Num_Color (float x, float maxvalue)
123 color.x = sin(2*M_PI*time);
125 color.z = sin(2*M_PI*time);
127 else if(x > maxvalue * 0.75) {
128 color.x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
129 color.y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
132 else if(x > maxvalue * 0.5) {
133 color.x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
134 color.y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
135 color.z = 1 - (x-100)*0.02; // blue value between 1 -> 0
137 else if(x > maxvalue * 0.25) {
140 color.z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
142 else if(x > maxvalue * 0.1) {
144 color.y = (x-20)*90/27/100; // green value between 0 -> 1
145 color.z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
153 blinkingamt = (1 - x/maxvalue/0.25);
156 color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time);
157 color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time);
158 color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time);
163 float HUD_GetRowCount(int item_count, vector size, float item_aspect)
165 float aspect = size_y / size_x;
166 return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count);
169 vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
172 float ratio, best_ratio = 0;
173 float best_columns = 1, best_rows = 1;
174 bool vertical = (psize.x / psize.y >= item_aspect);
177 psize = eX * psize.y + eY * psize.x;
178 item_aspect = 1 / item_aspect;
181 rows = ceil(sqrt(item_count));
182 columns = ceil(item_count/rows);
185 ratio = (psize.x/columns) / (psize.y/rows);
186 if(ratio > item_aspect)
187 ratio = item_aspect * item_aspect / ratio;
189 if(ratio <= best_ratio)
190 break; // ratio starts decreasing by now, skip next configurations
192 best_columns = columns;
200 rows = ceil(item_count/columns);
204 return eX * best_rows + eY * best_columns;
206 return eX * best_columns + eY * best_rows;
209 float stringwidth_colors(string s, vector theSize)
211 return stringwidth(s, true, theSize);
214 float stringwidth_nocolors(string s, vector theSize)
216 return stringwidth(s, false, theSize);
219 void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
221 position.x -= 2 / 3 * strlen(text) * theScale.x;
222 drawstring(position, text, theScale, rgb, theAlpha, flag);
225 void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
227 position.x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale.x);
228 drawstring(position, text, theScale, rgb, theAlpha, flag);
231 // return the string of the onscreen race timer
232 string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname)
240 if(theirtime == 0) // goal hit
244 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
254 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
260 lapstr = sprintf(_(" (-%dL)"), lapdelta);
263 else if(lapdelta < 0)
265 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
269 else if(theirtime > 0) // anticipation
271 if(mytime >= theirtime)
272 timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
274 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
284 cpname = _("Start line");
286 cpname = _("Finish line");
288 cpname = sprintf(_("Intermediate %d"), cp);
290 cpname = _("Finish line");
293 return strcat(col, cpname);
294 else if(theirname == "")
295 return strcat(col, sprintf("%s (%s)", cpname, timestr));
297 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(theirname, col, lapstr)));
300 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
301 int race_CheckName(string net_name)
304 for (i=RANKINGS_CNT-1;i>=0;--i)
305 if(grecordholder[i] == net_name)
310 int GetPlayerColorForce(int i)
315 return stof(getplayerkeyvalue(i, "colors")) & 15;
318 int GetPlayerColor(int i)
320 if(!playerslots[i].gotscores) // unconnected
321 return NUM_SPECTATOR;
322 else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR)
323 return NUM_SPECTATOR;
325 return GetPlayerColorForce(i);
328 string GetPlayerName(int i)
330 return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
340 // draw the background/borders
341 #define HUD_Panel_DrawBg(theAlpha) do { \
342 if(panel.current_panel_bg != "0" && panel.current_panel_bg != "") \
343 draw_BorderPicture(panel_pos - '1 1 0' * panel_bg_border, panel.current_panel_bg, panel_size + '1 1 0' * 2 * panel_bg_border, panel_bg_color, panel_bg_alpha * theAlpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER));\
346 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
347 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
349 if(!length_ratio || !theAlpha)
355 if(length_ratio < -1)
358 else if(length_ratio < 0)
362 vector width, height;
364 pic = strcat(hud_skin_path, "/", pic, "_vertical");
365 if(precache_pic(pic) == "") {
366 pic = "gfx/hud/default/progressbar_vertical";
369 if (baralign == 1) // bottom align
370 theOrigin.y += (1 - length_ratio) * theSize.y;
371 else if (baralign == 2) // center align
372 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
373 else if (baralign == 3) // center align, positive values down, negative up
376 if (length_ratio > 0)
377 theOrigin.y += theSize.y;
380 theOrigin.y += (1 + length_ratio) * theSize.y;
381 length_ratio = -length_ratio;
384 theSize.y *= length_ratio;
387 width = eX * theSize.x;
388 height = eY * theSize.y;
389 if(theSize.y <= theSize.x * 2)
391 // button not high enough
392 // draw just upper and lower part then
393 square = eY * theSize.y * 0.5;
394 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
395 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
396 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
400 square = eY * theSize.x;
401 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
402 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
403 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
406 pic = strcat(hud_skin_path, "/", pic);
407 if(precache_pic(pic) == "") {
408 pic = "gfx/hud/default/progressbar";
411 if (baralign == 1) // right align
412 theOrigin.x += (1 - length_ratio) * theSize.x;
413 else if (baralign == 2) // center align
414 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
415 else if (baralign == 3) // center align, positive values on the right, negative on the left
418 if (length_ratio > 0)
419 theOrigin.x += theSize.x;
422 theOrigin.x += (1 + length_ratio) * theSize.x;
423 length_ratio = -length_ratio;
426 theSize.x *= length_ratio;
429 width = eX * theSize.x;
430 height = eY * theSize.y;
431 if(theSize.x <= theSize.y * 2)
433 // button not wide enough
434 // draw just left and right part then
435 square = eX * theSize.x * 0.5;
436 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
437 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
438 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
442 square = eX * theSize.y;
443 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
444 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
445 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
450 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
456 pic = strcat(hud_skin_path, "/num_leading");
457 if(precache_pic(pic) == "") {
458 pic = "gfx/hud/default/num_leading";
461 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
462 if(mySize.x/mySize.y > 2)
463 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);
464 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);
469 entity weaponorder[WEP_MAXCOUNT];
470 void weaponorder_swap(int i, int j, entity pass)
472 entity h = weaponorder[i];
473 weaponorder[i] = weaponorder[j];
477 string weaponorder_cmp_str;
478 int weaponorder_cmp(int i, int j, entity pass)
481 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
482 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
483 return aj - ai; // the string is in REVERSE order (higher prio at the right is what we want, but higher prio first is the string)
486 void HUD_Weapons(void)
489 WepSet weapons_stat = WepSet_GetFromStat();
493 vector center = '0 0 0';
494 int weapon_count, weapon_id;
495 int row, column, rows = 0, columns = 0;
496 bool vertical_order = true;
497 float aspect = autocvar_hud_panel_weapons_aspect;
499 float timeout = autocvar_hud_panel_weapons_timeout;
500 float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
501 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
503 vector barsize = '0 0 0', baroffset = '0 0 0';
504 vector ammo_color = '1 0 1';
505 float ammo_alpha = 1;
507 float when = max(1, autocvar_hud_panel_weapons_complainbubble_time);
508 float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime);
510 vector weapon_pos, weapon_size = '0 0 0';
513 // check to see if we want to continue
514 if(intermission == 2) return;
515 if(hud != HUD_NORMAL) return;
517 if(!autocvar__hud_configure)
519 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
521 if(timeout && time >= weapontime + timeout + timeout_effect_length)
522 if(autocvar_hud_panel_weapons_timeout_effect == 3 || (autocvar_hud_panel_weapons_timeout_effect == 1 && !(autocvar_hud_panel_weapons_timeout_fadebgmin + autocvar_hud_panel_weapons_timeout_fadefgmin)))
524 weaponprevtime = time;
529 // update generic hud functions
530 HUD_Panel_UpdateCvars();
532 // figure out weapon order (how the weapons are sorted) // TODO make this configurable
533 if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
536 if(weaponorder_bypriority)
537 strunzone(weaponorder_bypriority);
538 if(weaponorder_byimpulse)
539 strunzone(weaponorder_byimpulse);
541 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
542 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
543 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
546 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
548 self = get_weaponinfo(i);
549 if(self.impulse >= 0)
551 weaponorder[weapon_cnt] = self;
555 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
556 weaponorder[i] = world;
557 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
559 weaponorder_cmp_str = string_null;
562 if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime)
565 if(autocvar__hud_configure)
568 for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5))
569 weapons_stat |= WepSet_FromWeapon(i);
575 weapons_stat = '0 0 0';
576 float countw = 1 + floor((floor(time * cvar("wep_add"))) % WEP_COUNT);
577 for(i = WEP_FIRST; i <= countw; ++i)
578 weapons_stat |= WepSet_FromWeapon(i);
583 // determine which weapons are going to be shown
584 if (autocvar_hud_panel_weapons_onlyowned)
586 if(autocvar__hud_configure)
588 if(menu_enabled != 2)
589 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
592 // do we own this weapon?
594 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
595 if((weapons_stat & WepSet_FromWeapon(weaponorder[i].weapon)) || (weaponorder[i].weapon == complain_weapon))
599 // might as well commit suicide now, no reason to live ;)
600 if (weapon_count == 0)
603 vector old_panel_size = panel_size;
604 vector padded_panel_size = panel_size - '2 2 0' * panel_bg_padding;
606 // get the all-weapons layout
607 vector table_size = HUD_GetTableSize_BestItemAR(WEP_COUNT, padded_panel_size, aspect);
608 columns = table_size.x;
610 weapon_size.x = padded_panel_size.x / columns;
611 weapon_size.y = padded_panel_size.y / rows;
613 // NOTE: although weapons should aways look the same even if onlyowned is enabled,
614 // we enlarge them a bit when possible to better match the desired aspect ratio
615 if(padded_panel_size.x / padded_panel_size.y < aspect)
617 // maximum number of rows that allows to display items with the desired aspect ratio
618 int max_rows = floor(padded_panel_size.y / (weapon_size.x / aspect));
619 columns = min(columns, ceil(weapon_count / max_rows));
620 rows = ceil(weapon_count / columns);
621 weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
622 weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
623 vertical_order = false;
627 int max_columns = floor(padded_panel_size.x / (weapon_size.y * aspect));
628 rows = min(rows, ceil(weapon_count / max_columns));
629 columns = ceil(weapon_count / rows);
630 weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
631 weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
632 vertical_order = true;
635 // reduce size of the panel
636 panel_size.x = columns * weapon_size.x;
637 panel_size.y = rows * weapon_size.y;
638 panel_size += '2 2 0' * panel_bg_padding;
640 // center the resized panel, or snap it to the screen edge when close enough
641 if(panel_pos.x > vid_conwidth * 0.001)
643 if(panel_pos.x + old_panel_size.x > vid_conwidth * 0.999)
644 panel_pos.x += old_panel_size.x - panel_size.x;
646 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
648 else if(old_panel_size.x > vid_conwidth * 0.999)
649 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
651 if(panel_pos.y > vid_conheight * 0.001)
653 if(panel_pos.y + old_panel_size.y > vid_conheight * 0.999)
654 panel_pos.y += old_panel_size.y - panel_size.y;
656 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
658 else if(old_panel_size.y > vid_conheight * 0.999)
659 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
662 weapon_count = WEP_COUNT;
664 // animation for fading in/out the panel respectively when not in use
665 if(!autocvar__hud_configure)
667 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
669 f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
671 // fade the panel alpha
672 if(autocvar_hud_panel_weapons_timeout_effect == 1)
674 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
675 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
677 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
679 panel_bg_alpha *= (1 - f);
680 panel_fg_alpha *= (1 - f);
683 // move the panel off the screen
684 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
686 f *= f; // for a cooler movement
687 center.x = panel_pos.x + panel_size.x/2;
688 center.y = panel_pos.y + panel_size.y/2;
689 screen_ar = vid_conwidth/vid_conheight;
690 if (center.x/center.y < screen_ar) //bottom left
692 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
693 panel_pos.y += f * (vid_conheight - panel_pos.y);
695 panel_pos.x -= f * (panel_pos.x + panel_size.x);
699 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
700 panel_pos.x += f * (vid_conwidth - panel_pos.x);
702 panel_pos.y -= f * (panel_pos.y + panel_size.y);
705 center.x = -1; // mark the panel as off screen
707 weaponprevtime = time - (1 - f) * timein_effect_length;
709 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
711 f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
713 // fade the panel alpha
714 if(autocvar_hud_panel_weapons_timeout_effect == 1)
716 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
717 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
719 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
721 panel_bg_alpha *= (f);
722 panel_fg_alpha *= (f);
725 // move the panel back on screen
726 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
728 f *= f; // for a cooler movement
730 center.x = panel_pos.x + panel_size.x/2;
731 center.y = panel_pos.y + panel_size.y/2;
732 screen_ar = vid_conwidth/vid_conheight;
733 if (center.x/center.y < screen_ar) //bottom left
735 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
736 panel_pos.y += f * (vid_conheight - panel_pos.y);
738 panel_pos.x -= f * (panel_pos.x + panel_size.x);
742 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
743 panel_pos.x += f * (vid_conwidth - panel_pos.x);
745 panel_pos.y -= f * (panel_pos.y + panel_size.y);
751 // draw the background, then change the virtual size of it to better fit other items inside
759 panel_pos += '1 1 0' * panel_bg_padding;
760 panel_size -= '2 2 0' * panel_bg_padding;
763 // after the sizing and animations are done, update the other values
765 if(!rows) // if rows is > 0 onlyowned code has already updated these vars
767 vector table_size = HUD_GetTableSize_BestItemAR(WEP_COUNT, panel_size, aspect);
768 columns = table_size.x;
770 weapon_size.x = panel_size.x / columns;
771 weapon_size.y = panel_size.y / rows;
772 vertical_order = (panel_size.x / panel_size.y >= aspect);
775 // calculate position/size for visual bar displaying ammount of ammo status
776 if (autocvar_hud_panel_weapons_ammo)
778 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
779 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
781 if(weapon_size.x/weapon_size.y > aspect)
783 barsize.x = aspect * weapon_size.y;
784 barsize.y = weapon_size.y;
785 baroffset.x = (weapon_size.x - barsize.x) / 2;
789 barsize.y = 1/aspect * weapon_size.x;
790 barsize.x = weapon_size.x;
791 baroffset.y = (weapon_size.y - barsize.y) / 2;
794 if(autocvar_hud_panel_weapons_accuracy)
795 Accuracy_LoadColors();
799 vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
800 vector noncurrent_pos = '0 0 0';
801 vector noncurrent_size = weapon_size * bound(0, autocvar_hud_panel_weapons_noncurrent_scale, 1);
802 float noncurrent_alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_weapons_noncurrent_alpha, 1);
805 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
807 // retrieve information about the current weapon to be drawn
808 self = weaponorder[i];
809 weapon_id = self.impulse;
810 isCurrent = (self.weapon == switchweapon);
812 // skip if this weapon doesn't exist
813 if(!self || weapon_id < 0) { continue; }
815 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
816 if(autocvar_hud_panel_weapons_onlyowned)
817 if (!((weapons_stat & WepSet_FromWeapon(self.weapon)) || (self.weapon == complain_weapon)))
820 // figure out the drawing position of weapon
821 weapon_pos = (panel_pos + eX * column * weapon_size.x + eY * row * weapon_size.y);
822 noncurrent_pos.x = weapon_pos.x + (weapon_size.x - noncurrent_size.x) / 2;
823 noncurrent_pos.y = weapon_pos.y + (weapon_size.y - noncurrent_size.y) / 2;
825 // draw background behind currently selected weapon
827 drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
829 // draw the weapon accuracy
830 if(autocvar_hud_panel_weapons_accuracy)
832 float panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
833 if(panel_weapon_accuracy >= 0)
835 color = Accuracy_GetColor(panel_weapon_accuracy);
836 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
840 // drawing all the weapon items
841 if(weapons_stat & WepSet_FromWeapon(self.weapon))
843 // draw the weapon image
845 drawpic_aspect_skin(weapon_pos, self.model2, weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
847 drawpic_aspect_skin(noncurrent_pos, self.model2, noncurrent_size, '1 1 1', noncurrent_alpha, DRAWFLAG_NORMAL);
849 // draw weapon label string
850 switch(autocvar_hud_panel_weapons_label)
852 case 1: // weapon number
853 drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
857 drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
860 case 3: // weapon name
861 drawstring(weapon_pos, strtolower(self.message), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
868 // draw ammo status bar
869 if(autocvar_hud_panel_weapons_ammo && (self.ammo_field != ammo_none))
872 a = getstati(GetAmmoStat(self.ammo_field)); // how much ammo do we have?
876 switch(self.ammo_field)
878 case ammo_shells: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
879 case ammo_nails: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
880 case ammo_rockets: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
881 case ammo_cells: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
882 case ammo_plasma: ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma; break;
883 case ammo_fuel: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
884 default: ammo_full = 60;
888 weapon_pos.x + baroffset.x,
889 weapon_pos.y + baroffset.y,
890 barsize.x * bound(0, a/ammo_full, 1),
907 else // draw a "ghost weapon icon" if you don't have the weapon
909 drawpic_aspect_skin(noncurrent_pos, self.model2, noncurrent_size, '0.2 0.2 0.2', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
912 // draw the complain message
913 if(self.weapon == complain_weapon)
916 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
918 a = ((complain_weapon_time + when > time) ? 1 : 0);
921 if(complain_weapon_type == 0) {
922 s = _("Out of ammo");
923 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
925 else if(complain_weapon_type == 1) {
927 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
930 s = _("Unavailable");
931 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
933 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
934 drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
935 drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
940 if(!autocvar_hud_panel_weapons_onlyowned)
942 drawfill(weapon_pos + '1 1 0', weapon_size - '2 2 0', '1 1 1', panel_fg_alpha * 0.2, DRAWFLAG_NORMAL);
943 drawstring(weapon_pos, ftos(i + 1), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
947 // continue with new position for the next weapon
951 if(column >= columns)
970 void DrawNadeProgressBar(vector myPos, vector mySize, float progress, vector color)
972 HUD_Panel_DrawProgressBar(
973 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
974 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
975 autocvar_hud_panel_ammo_progressbar_name,
976 progress, 0, 0, color,
977 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
980 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time)
982 float bonusNades = getstatf(STAT_NADE_BONUS);
983 float bonusProgress = getstatf(STAT_NADE_BONUS_SCORE);
984 float bonusType = getstati(STAT_NADE_BONUS_TYPE);
985 vector nadeColor = NADES[bonusType].m_color;
986 string nadeIcon = NADES[bonusType].m_icon;
988 vector iconPos, textPos;
990 if(autocvar_hud_panel_ammo_iconalign)
992 iconPos = myPos + eX * 2 * mySize.y;
998 textPos = myPos + eX * mySize.y;
1001 if(bonusNades > 0 || bonusProgress > 0)
1003 DrawNadeProgressBar(myPos, mySize, bonusProgress, nadeColor);
1005 if(autocvar_hud_panel_ammo_text)
1006 drawstring_aspect(textPos, ftos(bonusNades), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1009 drawpic_aspect_skin_expanding(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, expand_time);
1011 drawpic_aspect_skin(iconPos, nadeIcon, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1015 void DrawAmmoItem(vector myPos, vector mySize, .int ammoType, bool isCurrent, bool isInfinite)
1017 if(ammoType == ammo_none)
1020 // Initialize variables
1023 if(autocvar__hud_configure)
1025 isCurrent = (ammoType == ammo_rockets); // Rockets always current
1029 ammo = getstati(GetAmmoStat(ammoType));
1033 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
1034 myPos = myPos + (mySize - mySize * scale) * 0.5;
1035 mySize = mySize * scale;
1038 vector iconPos, textPos;
1039 if(autocvar_hud_panel_ammo_iconalign)
1041 iconPos = myPos + eX * 2 * mySize.y;
1047 textPos = myPos + eX * mySize.y;
1050 bool isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
1052 vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
1055 textColor = '0.2 0.95 0';
1057 textColor = '0 0 0';
1059 textColor = '0.8 0.04 0';
1061 textColor = '1 1 1';
1065 alpha = panel_fg_alpha;
1067 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
1069 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
1071 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
1076 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1078 if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
1079 HUD_Panel_DrawProgressBar(myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x, mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x, autocvar_hud_panel_ammo_progressbar_name, ammo/autocvar_hud_panel_ammo_maxammo, 0, 0, textColor, autocvar_hud_progressbar_alpha * alpha, DRAWFLAG_NORMAL);
1081 if(autocvar_hud_panel_ammo_text)
1082 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
1084 drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
1087 int nade_prevstatus;
1089 float nade_statuschange_time;
1092 if(intermission == 2) return;
1093 if(hud != HUD_NORMAL) return;
1094 if(!autocvar__hud_configure)
1096 if(!autocvar_hud_panel_ammo) return;
1097 if(spectatee_status == -1) return;
1100 HUD_Panel_UpdateCvars();
1102 draw_beginBoldFont();
1106 mySize = panel_size;
1108 HUD_Panel_DrawBg(1);
1109 if(panel_bg_padding)
1111 pos += '1 1 0' * panel_bg_padding;
1112 mySize -= '2 2 0' * panel_bg_padding;
1115 int rows = 0, columns, row, column;
1116 float nade_cnt = getstatf(STAT_NADE_BONUS), nade_score = getstatf(STAT_NADE_BONUS_SCORE);
1117 bool draw_nades = (nade_cnt > 0 || nade_score > 0);
1118 float nade_statuschange_elapsedtime;
1119 int total_ammo_count;
1122 if (autocvar_hud_panel_ammo_onlycurrent)
1123 total_ammo_count = 1;
1125 total_ammo_count = AMMO_COUNT;
1130 if (nade_cnt != nade_prevframe)
1132 nade_statuschange_time = time;
1133 nade_prevstatus = nade_prevframe;
1134 nade_prevframe = nade_cnt;
1138 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
1140 rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
1141 columns = ceil((total_ammo_count)/rows);
1142 ammo_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
1144 vector offset = '0 0 0'; // fteqcc sucks
1146 if(ammo_size.x/ammo_size.y > 3)
1148 newSize = 3 * ammo_size.y;
1149 offset.x = ammo_size.x - newSize;
1150 pos.x += offset.x/2;
1151 ammo_size.x = newSize;
1155 newSize = 1/3 * ammo_size.x;
1156 offset.y = ammo_size.y - newSize;
1157 pos.y += offset.y/2;
1158 ammo_size.y = newSize;
1162 bool infinite_ammo = (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_WEAPON_AMMO);
1164 if(autocvar_hud_panel_ammo_onlycurrent)
1166 if(autocvar__hud_configure)
1168 DrawAmmoItem(pos, ammo_size, ammo_rockets, true, false);
1175 (get_weaponinfo(switchweapon)).ammo_field,
1185 column = column + 1;
1192 for(i = 0; i < AMMO_COUNT; ++i)
1194 ammotype = GetAmmoFieldFromNum(i);
1196 pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y),
1199 ((get_weaponinfo(switchweapon)).ammo_field == ammotype),
1207 column = column + 1;
1214 nade_statuschange_elapsedtime = time - nade_statuschange_time;
1216 float f = bound(0, nade_statuschange_elapsedtime*2, 1);
1218 DrawAmmoNades(pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y), ammo_size, nade_prevstatus < nade_cnt && nade_cnt != 0 && f < 1, f);
1224 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha, float fadelerp)
1226 vector newPos = '0 0 0', newSize = '0 0 0';
1227 vector picpos, numpos;
1231 if(mySize.y/mySize.x > 2)
1233 newSize.y = 2 * mySize.x;
1234 newSize.x = mySize.x;
1236 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
1241 newSize.x = 1/2 * mySize.y;
1242 newSize.y = mySize.y;
1244 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
1248 if(icon_right_align)
1251 picpos = newPos + eY * newSize.x;
1256 numpos = newPos + eY * newSize.x;
1260 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1261 // make number smaller than icon, it looks better
1262 // reduce only y to draw numbers with different number of digits with the same y size
1263 numpos.y += newSize.y * ((1 - 0.7) / 2);
1265 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1269 if(mySize.x/mySize.y > 3)
1271 newSize.x = 3 * mySize.y;
1272 newSize.y = mySize.y;
1274 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
1279 newSize.y = 1/3 * mySize.x;
1280 newSize.x = mySize.x;
1282 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
1286 if(icon_right_align) // right align
1289 picpos = newPos + eX * 2 * newSize.y;
1293 numpos = newPos + eX * newSize.y;
1297 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
1298 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
1299 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1300 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1303 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha)
1305 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
1311 // Powerup item fields (reusing existing fields)
1312 .string message; // Human readable name
1313 .string netname; // Icon name
1314 .vector colormod; // Color
1315 .float count; // Time left
1316 .float lifetime; // Maximum time
1318 entity powerupItems;
1319 int powerupItemsCount;
1321 void resetPowerupItems()
1324 for(item = powerupItems; item; item = item.chain)
1327 powerupItemsCount = 0;
1330 void addPowerupItem(string name, string icon, vector color, float currentTime, float lifeTime)
1333 powerupItems = spawn();
1336 for(item = powerupItems; item.count; item = item.chain)
1338 item.chain = spawn();
1340 item.message = name;
1341 item.netname = icon;
1342 item.colormod = color;
1343 item.count = currentTime;
1344 item.lifetime = lifeTime;
1346 ++powerupItemsCount;
1349 int getPowerupItemAlign(int align, int column, int row, int columns, int rows, bool isVertical)
1354 bool isTop = isVertical && rows > 1 && row == 0;
1355 bool isBottom = isVertical && rows > 1 && row == rows-1;
1356 bool isLeft = !isVertical && columns > 1 && column == 0;
1357 bool isRight = !isVertical && columns > 1 && column == columns-1;
1359 if(isTop || isLeft) return (align == 2) ? 1 : 0;
1360 if(isBottom || isRight) return (align == 2) ? 0 : 1;
1367 if(intermission == 2) return;
1369 int allItems = getstati(STAT_ITEMS, 0, 24);
1370 int allBuffs = getstati(STAT_BUFFS, 0, 24);
1371 int strengthTime, shieldTime, superTime;
1374 if(!autocvar__hud_configure)
1376 if(!autocvar_hud_panel_powerups) return;
1377 if(spectatee_status == -1) return;
1378 if(getstati(STAT_HEALTH) <= 0) return;
1379 if(!(allItems & (ITEM_Strength.m_itemid | ITEM_Shield.m_itemid | IT_SUPERWEAPON)) && !allBuffs) return;
1381 strengthTime = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1382 shieldTime = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1383 superTime = bound(0, getstatf(STAT_SUPERWEAPONS_FINISHED) - time, 99);
1385 if(allItems & IT_UNLIMITED_SUPERWEAPONS)
1388 // Prevent stuff to show up on mismatch that will be fixed next frame
1389 if(!(allItems & IT_SUPERWEAPON))
1400 // Add items to linked list
1401 resetPowerupItems();
1404 addPowerupItem("Strength", "strength", autocvar_hud_progressbar_strength_color, strengthTime, 30);
1406 addPowerupItem("Shield", "shield", autocvar_hud_progressbar_shield_color, shieldTime, 30);
1408 addPowerupItem("Superweapons", "superweapons", autocvar_hud_progressbar_superweapons_color, superTime, 30);
1410 FOREACH(BUFFS, it.m_itemid & allBuffs, LAMBDA(
1411 addPowerupItem(it.m_prettyName, strcat("buff_", it.m_name), it.m_color, bound(0, getstatf(STAT_BUFF_TIME) - time, 99), 60);
1414 if(!powerupItemsCount)
1417 // Draw panel background
1418 HUD_Panel_UpdateCvars();
1419 HUD_Panel_DrawBg(1);
1422 vector pos = panel_pos;
1423 vector size = panel_size;
1424 bool isVertical = size.y > size.x;
1426 if(panel_bg_padding)
1428 pos += '1 1 0' * panel_bg_padding;
1429 size -= '2 2 0' * panel_bg_padding;
1432 // Find best partitioning of the drawing area
1433 const float DESIRED_ASPECT = 6;
1434 float aspect = 0, a;
1441 c = floor(powerupItemsCount / i);
1442 r = ceil(powerupItemsCount / c);
1443 a = isVertical ? (size.y/r) / (size.x/c) : (size.x/c) / (size.y/r);
1445 if(i == 1 || fabs(DESIRED_ASPECT - a) < fabs(DESIRED_ASPECT - aspect))
1452 while(++i <= powerupItemsCount);
1454 // Prevent single items from getting too wide
1455 if(powerupItemsCount == 1 && aspect > DESIRED_ASPECT)
1460 pos.y += size.y * 0.5;
1465 pos.x += size.x * 0.5;
1469 // Draw items from linked list
1470 vector itemPos = pos;
1471 vector itemSize = eX * (size.x / columns) + eY * (size.y / rows);
1472 vector textColor = '1 1 1';
1474 int fullSeconds = 0;
1479 draw_beginBoldFont();
1480 for(entity item = powerupItems; item.count; item = item.chain)
1482 itemPos = eX * (pos.x + column * itemSize.x) + eY * (pos.y + row * itemSize.y);
1485 if(autocvar_hud_panel_powerups_progressbar)
1487 align = getPowerupItemAlign(autocvar_hud_panel_powerups_baralign, column, row, columns, rows, isVertical);
1488 HUD_Panel_DrawProgressBar(itemPos, itemSize, "progressbar", item.count / item.lifetime, isVertical, align, item.colormod, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1491 // Draw icon and text
1492 if(autocvar_hud_panel_powerups_text)
1494 align = getPowerupItemAlign(autocvar_hud_panel_powerups_iconalign, column, row, columns, rows, isVertical);
1495 fullSeconds = ceil(item.count);
1496 textColor = '0.6 0.6 0.6' + (item.colormod * 0.4);
1499 DrawNumIcon(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha);
1501 DrawNumIcon_expanding(itemPos, itemSize, fullSeconds, item.netname, isVertical, align, textColor, panel_fg_alpha, bound(0, (fullSeconds - item.count) / 0.5, 1));
1504 // Determine next section
1507 if(++column >= columns)
1525 // Health/armor (#3)
1529 void HUD_HealthArmor(void)
1531 int armor, health, fuel;
1532 if(intermission == 2) return;
1533 if(!autocvar__hud_configure)
1535 if(!autocvar_hud_panel_healtharmor) return;
1536 if(hud != HUD_NORMAL) return;
1537 if(spectatee_status == -1) return;
1539 health = getstati(STAT_HEALTH);
1545 armor = getstati(STAT_ARMOR);
1547 // code to check for spectatee_status changes is in Ent_ClientData()
1548 // prev_p_health and prev_health can be set to -1 there
1550 if (prev_p_health == -1)
1553 health_beforedamage = 0;
1554 armor_beforedamage = 0;
1555 health_damagetime = 0;
1556 armor_damagetime = 0;
1557 prev_health = health;
1559 old_p_health = health;
1560 old_p_armor = armor;
1561 prev_p_health = health;
1562 prev_p_armor = armor;
1564 else if (prev_health == -1)
1566 //start the load effect
1567 health_damagetime = 0;
1568 armor_damagetime = 0;
1572 fuel = getstati(STAT_FUEL);
1581 HUD_Panel_UpdateCvars();
1583 draw_beginBoldFont();
1587 mySize = panel_size;
1589 HUD_Panel_DrawBg(1);
1590 if(panel_bg_padding)
1592 pos += '1 1 0' * panel_bg_padding;
1593 mySize -= '2 2 0' * panel_bg_padding;
1596 int baralign = autocvar_hud_panel_healtharmor_baralign;
1597 int iconalign = autocvar_hud_panel_healtharmor_iconalign;
1599 int maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1600 int maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1601 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1604 v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON);
1609 float maxtotal = maxhealth + maxarmor;
1611 if(v.z) // NOT fully armored
1613 biggercount = "health";
1614 if(autocvar_hud_panel_healtharmor_progressbar)
1615 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, x/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1617 if(autocvar_hud_panel_healtharmor_text)
1618 drawpic_aspect_skin(pos + eX * mySize.x - eX * 0.5 * mySize.y, "armor", '0.5 0.5 0' * mySize.y, '1 1 1', panel_fg_alpha * armor / health, DRAWFLAG_NORMAL);
1622 biggercount = "armor";
1623 if(autocvar_hud_panel_healtharmor_progressbar)
1624 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, x/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1626 if(autocvar_hud_panel_healtharmor_text)
1627 drawpic_aspect_skin(pos + eX * mySize.x - eX * 0.5 * mySize.y, "health", '0.5 0.5 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1629 if(autocvar_hud_panel_healtharmor_text)
1630 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1633 HUD_Panel_DrawProgressBar(pos, eX * mySize.x + eY * 0.2 * mySize.y, "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1637 float panel_ar = mySize.x/mySize.y;
1638 bool is_vertical = (panel_ar < 1);
1639 vector health_offset = '0 0 0', armor_offset = '0 0 0';
1640 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1643 if (autocvar_hud_panel_healtharmor_flip)
1644 health_offset.x = mySize.x;
1646 armor_offset.x = mySize.x;
1651 if (autocvar_hud_panel_healtharmor_flip)
1652 health_offset.y = mySize.y;
1654 armor_offset.y = mySize.y;
1657 bool health_baralign, armor_baralign, fuel_baralign;
1658 bool health_iconalign, armor_iconalign;
1659 if (autocvar_hud_panel_healtharmor_flip)
1661 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1662 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1663 fuel_baralign = health_baralign;
1664 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1665 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1669 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1670 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1671 fuel_baralign = armor_baralign;
1672 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1673 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1678 if(autocvar_hud_panel_healtharmor_progressbar)
1680 float p_health, pain_health_alpha;
1682 pain_health_alpha = 1;
1683 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1685 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1687 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1689 if (time - old_p_healthtime < 1)
1690 old_p_health = prev_p_health;
1692 old_p_health = prev_health;
1693 old_p_healthtime = time;
1695 if (time - old_p_healthtime < 1)
1697 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1698 prev_p_health = p_health;
1701 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1703 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1705 if (time - health_damagetime >= 1)
1706 health_beforedamage = prev_health;
1707 health_damagetime = time;
1709 if (time - health_damagetime < 1)
1711 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1712 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL);
1715 prev_health = health;
1717 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1719 float BLINK_FACTOR = 0.15;
1720 float BLINK_BASE = 0.85;
1721 float BLINK_FREQ = 9;
1722 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1725 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL);
1727 if(autocvar_hud_panel_healtharmor_text)
1728 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1733 if(autocvar_hud_panel_healtharmor_progressbar)
1737 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1739 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1741 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1743 if (time - old_p_armortime < 1)
1744 old_p_armor = prev_p_armor;
1746 old_p_armor = prev_armor;
1747 old_p_armortime = time;
1749 if (time - old_p_armortime < 1)
1751 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1752 prev_p_armor = p_armor;
1755 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1757 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1759 if (time - armor_damagetime >= 1)
1760 armor_beforedamage = prev_armor;
1761 armor_damagetime = time;
1763 if (time - armor_damagetime < 1)
1765 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1766 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL);
1771 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1773 if(autocvar_hud_panel_healtharmor_text)
1774 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1780 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1784 mySize.x *= 2; //restore full panel size
1785 else if (panel_ar < 1/4)
1786 mySize.y *= 2; //restore full panel size
1787 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1794 // Notification area (#4)
1797 void HUD_Notify_Push(string icon, string attacker, string victim)
1805 if (notify_index == -1)
1806 notify_index = NOTIFY_MAX_ENTRIES-1;
1809 if (notify_attackers[notify_index])
1810 strunzone(notify_attackers[notify_index]);
1812 if (notify_victims[notify_index])
1813 strunzone(notify_victims[notify_index]);
1815 if (notify_icons[notify_index])
1816 strunzone(notify_icons[notify_index]);
1818 // Allocate new strings
1821 notify_attackers[notify_index] = strzone(attacker);
1822 notify_victims[notify_index] = strzone(victim);
1826 // In case of a notification without a victim, the attacker
1827 // is displayed on the victim's side. Instead of special
1828 // treatment later on, we can simply switch them here.
1829 notify_attackers[notify_index] = string_null;
1830 notify_victims[notify_index] = strzone(attacker);
1833 notify_icons[notify_index] = strzone(icon);
1834 notify_times[notify_index] = time;
1837 void HUD_Notify(void)
1839 if(intermission == 2) return;
1840 if (!autocvar__hud_configure)
1841 if (!autocvar_hud_panel_notify)
1844 HUD_Panel_UpdateCvars();
1845 HUD_Panel_DrawBg(1);
1847 if (!autocvar__hud_configure)
1848 if (notify_count == 0)
1855 if (panel_bg_padding)
1857 pos += '1 1 0' * panel_bg_padding;
1858 size -= '2 2 0' * panel_bg_padding;
1861 float fade_start = max(0, autocvar_hud_panel_notify_time);
1862 float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
1863 float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
1865 int entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
1866 float entry_height = size.y / entry_count;
1868 float panel_width_half = size.x * 0.5;
1869 float icon_width_half = entry_height * icon_aspect / 2;
1870 float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
1872 vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
1873 vector icon_size = (eX * icon_aspect + eY) * entry_height;
1874 vector icon_left = eX * (panel_width_half - icon_width_half);
1875 vector attacker_right = eX * name_maxwidth;
1876 vector victim_left = eX * (size.x - name_maxwidth);
1878 vector attacker_pos, victim_pos, icon_pos;
1879 string attacker, victim, icon;
1880 int i, j, count, step, limit;
1883 if (autocvar_hud_panel_notify_flip)
1885 // Order items from the top down
1888 limit = entry_count;
1892 // Order items from the bottom up
1893 i = entry_count - 1;
1898 for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
1900 if(autocvar__hud_configure)
1902 attacker = sprintf(_("Player %d"), count + 1);
1903 victim = sprintf(_("Player %d"), count + 2);
1904 icon = get_weaponinfo(min(WEP_FIRST + count * 2, WEP_LAST)).model2;
1905 alpha = bound(0, 1.2 - count / entry_count, 1);
1909 if (j == NOTIFY_MAX_ENTRIES)
1912 if (notify_times[j] + fade_start > time)
1914 else if (fade_time != 0)
1916 alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
1923 attacker = notify_attackers[j];
1924 victim = notify_victims[j];
1925 icon = notify_icons[j];
1928 if (icon != "" && victim != "")
1930 vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
1932 icon_pos = pos + icon_left + eY * i * entry_height;
1933 drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1935 victim = textShortenToWidth(victim, name_maxwidth, font_size, stringwidth_colors);
1936 victim_pos = pos + victim_left + name_top;
1937 drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1941 attacker = textShortenToWidth(attacker, name_maxwidth, font_size, stringwidth_colors);
1942 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
1943 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1948 notify_count = count;
1954 string seconds_tostring(float sec)
1957 minutes = floor(sec / 60);
1959 sec -= minutes * 60;
1960 return sprintf("%d:%02d", minutes, sec);
1963 void HUD_Timer(void)
1965 if(intermission == 2) return;
1966 if(!autocvar__hud_configure)
1968 if(!autocvar_hud_panel_timer) return;
1971 HUD_Panel_UpdateCvars();
1973 draw_beginBoldFont();
1977 mySize = panel_size;
1979 HUD_Panel_DrawBg(1);
1980 if(panel_bg_padding)
1982 pos += '1 1 0' * panel_bg_padding;
1983 mySize -= '2 2 0' * panel_bg_padding;
1987 float timelimit, elapsedTime, timeleft, minutesLeft;
1989 timelimit = getstatf(STAT_TIMELIMIT);
1991 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1992 timeleft = ceil(timeleft);
1994 minutesLeft = floor(timeleft / 60);
1997 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
1998 timer_color = '1 1 1'; //white
1999 else if(minutesLeft >= 1)
2000 timer_color = '1 1 0'; //yellow
2002 timer_color = '1 0 0'; //red
2004 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
2005 if (time < getstatf(STAT_GAMESTARTTIME)) {
2006 //while restart is still active, show 00:00
2007 timer = seconds_tostring(0);
2009 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2010 timer = seconds_tostring(elapsedTime);
2013 timer = seconds_tostring(timeleft);
2016 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2024 float HUD_Radar_Clickable()
2026 return hud_panel_radar_mouse && !hud_panel_radar_temp_hidden;
2029 void HUD_Radar_Show_Maximized(bool doshow,float clickable)
2031 hud_panel_radar_maximized = doshow;
2032 hud_panel_radar_temp_hidden = 0;
2038 if(autocvar_hud_cursormode)
2040 hud_panel_radar_mouse = 1;
2043 else if ( hud_panel_radar_mouse )
2045 hud_panel_radar_mouse = 0;
2047 if(autocvar_hud_cursormode)
2052 void HUD_Radar_Hide_Maximized()
2054 HUD_Radar_Show_Maximized(false,false);
2058 float HUD_Radar_InputEvent(float bInputType, float nPrimary, float nSecondary)
2060 if(!hud_panel_radar_maximized || !hud_panel_radar_mouse ||
2061 autocvar__hud_configure || mv_active)
2066 mousepos_x = nPrimary;
2067 mousepos_y = nSecondary;
2071 if(nPrimary == K_MOUSE1)
2073 if(bInputType == 0) // key pressed
2074 mouseClicked |= S_MOUSE1;
2075 else if(bInputType == 1) // key released
2076 mouseClicked -= (mouseClicked & S_MOUSE1);
2078 else if(nPrimary == K_MOUSE2)
2080 if(bInputType == 0) // key pressed
2081 mouseClicked |= S_MOUSE2;
2082 else if(bInputType == 1) // key released
2083 mouseClicked -= (mouseClicked & S_MOUSE2);
2085 else if ( nPrimary == K_ESCAPE && bInputType == 0 )
2087 HUD_Radar_Hide_Maximized();
2091 // allow console/use binds to work without hiding the map
2095 con_keys = strcat(findkeysforcommand("toggleconsole", 0)," ",findkeysforcommand("+use", 0)) ;
2096 keys = tokenize(con_keys); // findkeysforcommand returns data for this
2097 for (i = 0; i < keys; ++i)
2099 if(nPrimary == stof(argv(i)))
2103 if ( getstati(STAT_HEALTH) <= 0 )
2106 if ( bInputType < 2 )
2108 con_keys = findkeysforcommand("+showscores", 0);
2109 keys = tokenize(con_keys);
2110 for (i = 0; i < keys; ++i)
2112 if ( nPrimary == stof(argv(i)) )
2114 hud_panel_radar_temp_hidden = bInputType == 0;
2120 else if ( bInputType == 0 )
2121 HUD_Radar_Hide_Maximized();
2129 void HUD_Radar_Mouse()
2131 if ( !hud_panel_radar_mouse ) return;
2132 if(mv_active) return;
2136 HUD_Radar_Hide_Maximized();
2140 if(mouseClicked & S_MOUSE2)
2142 HUD_Radar_Hide_Maximized();
2146 if(!autocvar_hud_cursormode)
2148 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
2150 mousepos_x = bound(0, mousepos_x, vid_conwidth);
2151 mousepos_y = bound(0, mousepos_y, vid_conheight);
2154 HUD_Panel_UpdateCvars();
2157 panel_size = autocvar_hud_panel_radar_maximized_size;
2158 panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
2159 panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
2160 panel_pos_x = (vid_conwidth - panel_size_x) / 2;
2161 panel_pos_y = (vid_conheight - panel_size_y) / 2;
2163 if(mouseClicked & S_MOUSE1)
2166 if ( mousepos_x < panel_pos_x || mousepos_x > panel_pos_x + panel_size_x ||
2167 mousepos_y < panel_pos_y || mousepos_y > panel_pos_y + panel_size_y )
2169 HUD_Radar_Hide_Maximized();
2172 vector pos = teamradar_texcoord_to_3dcoord(teamradar_2dcoord_to_texcoord(mousepos),view_origin_z);
2173 localcmd(sprintf("cmd ons_spawn %f %f %f",pos_x,pos_y,pos_z));
2175 HUD_Radar_Hide_Maximized();
2180 const vector cursor_size = '32 32 0';
2181 drawpic(mousepos-'8 4 0', strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursor_size, '1 1 1', 0.8, DRAWFLAG_NORMAL);
2184 void HUD_Radar(void)
2186 if(intermission == 2) return;
2187 if (!autocvar__hud_configure)
2189 if (hud_panel_radar_maximized)
2191 if (!hud_draw_maximized) return;
2195 if (autocvar_hud_panel_radar == 0) return;
2196 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
2197 if(radar_panel_modified)
2199 panel.update_time = time; // forces reload of panel attributes
2200 radar_panel_modified = false;
2205 if ( hud_panel_radar_temp_hidden )
2208 HUD_Panel_UpdateCvars();
2212 if (hud_panel_radar_maximized && !autocvar__hud_configure)
2214 panel_size = autocvar_hud_panel_radar_maximized_size;
2215 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
2216 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
2217 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
2218 panel_pos.y = (vid_conheight - panel_size.y) / 2;
2221 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
2222 if(precache_pic(panel_bg) == "")
2223 panel_bg = "gfx/hud/default/border_default"; // fallback
2224 if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
2225 radar_panel_modified = true;
2226 if(panel.current_panel_bg)
2227 strunzone(panel.current_panel_bg);
2228 panel.current_panel_bg = strzone(panel_bg);
2230 switch(hud_panel_radar_maximized_zoommode)
2234 f = current_zoomfraction;
2237 f = 1 - current_zoomfraction;
2247 switch(hud_panel_radar_maximized_rotation)
2250 teamradar_angle = view_angles.y - 90;
2253 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
2257 if (!hud_panel_radar_maximized && !autocvar__hud_configure)
2259 switch(hud_panel_radar_zoommode)
2263 f = current_zoomfraction;
2266 f = 1 - current_zoomfraction;
2276 switch(hud_panel_radar_rotation)
2279 teamradar_angle = view_angles.y - 90;
2282 teamradar_angle = 90 * hud_panel_radar_rotation;
2289 mySize = panel_size;
2291 HUD_Panel_DrawBg(1);
2292 if(panel_bg_padding)
2294 pos += '1 1 0' * panel_bg_padding;
2295 mySize -= '2 2 0' * panel_bg_padding;
2300 float scale2d, normalsize, bigsize;
2302 teamradar_origin2d = pos + 0.5 * mySize;
2303 teamradar_size2d = mySize;
2305 if(minimapname == "")
2308 teamradar_loadcvars();
2310 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2311 teamradar_size2d = mySize;
2313 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2315 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2316 if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
2318 // max-min distance must fit the radar in any rotation
2319 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2323 vector c0, c1, c2, c3, span;
2324 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2325 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2326 c2 = rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
2327 c3 = rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
2329 span.x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
2330 span.y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
2332 // max-min distance must fit the radar in x=x, y=y
2334 teamradar_size2d.x * scale2d / (1.05 * span.x),
2335 teamradar_size2d.y * scale2d / (1.05 * span.y)
2339 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2340 if(bigsize > normalsize)
2341 normalsize = bigsize;
2345 + (1 - f) * normalsize;
2346 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2348 + (1 - f) * view_origin);
2357 draw_teamradar_background(hud_panel_radar_foreground_alpha);
2359 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2360 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2364 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2366 if ( hud_panel_radar_mouse )
2367 if ( tm.health > 0 )
2368 if ( tm.team == myteam+1 )
2370 coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(tm.origin));
2371 if ( vlen(mousepos-coord) < 8 )
2373 brightcolor_x = min(1,tm.teamradar_color_x*1.5);
2374 brightcolor_y = min(1,tm.teamradar_color_y*1.5);
2375 brightcolor_z = min(1,tm.teamradar_color_z*1.5);
2376 drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
2380 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2382 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2384 color2 = GetPlayerColor(tm.sv_entnum);
2385 //if(color == NUM_SPECTATOR || color == color2)
2386 draw_teamradar_player(tm.origin, tm.angles, Team_ColorRGB(color2));
2388 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2390 drawresetcliparea();
2392 if ( hud_panel_radar_mouse )
2394 string message = "Click to select teleport destination";
2396 if ( getstati(STAT_HEALTH) <= 0 )
2398 message = "Click to select spawn location";
2401 drawcolorcodedstring(pos + '0.5 0 0' * (mySize_x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize_y * 2,
2402 message, hud_fontsize, hud_panel_radar_foreground_alpha, DRAWFLAG_NORMAL);
2404 hud_panel_radar_bottom = pos_y + mySize_y + hud_fontsize_y;
2410 void HUD_UpdatePlayerTeams();
2411 void HUD_Score_Rankings(vector pos, vector mySize, entity me)
2414 entity tm = world, pl;
2415 int SCOREPANEL_MAX_ENTRIES = 6;
2416 float SCOREPANEL_ASPECTRATIO = 2;
2417 int entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize.y/mySize.x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2418 vector fontsize = '1 1 0' * (mySize.y/entries);
2420 vector rgb, score_color;
2422 score_color = '1 1 1';
2424 float name_size = mySize.x*0.75;
2425 float spacing_size = mySize.x*0.04;
2426 const float highlight_alpha = 0.2;
2427 int i = 0, first_pl = 0;
2428 bool me_printed = false;
2430 if (autocvar__hud_configure)
2432 float players_per_team = 0;
2435 // show team scores in the first line
2436 float score_size = mySize.x / team_count;
2437 players_per_team = max(2, ceil((entries - 1) / team_count));
2438 for(i=0; i<team_count; ++i) {
2439 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2440 HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2441 drawstring_aspect(pos + eX * score_size * i, ftos(175 - 23*i), eX * score_size + eY * fontsize.y, Team_ColorRGB(ColorByTeam(i)) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2444 pos.y += fontsize.y;
2446 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2447 for (i=first_pl; i<entries; ++i)
2449 //simulate my score is lower than all displayed players,
2450 //so that I don't appear at all showing pure rankings.
2451 //This is to better show the difference between the 2 ranking views
2452 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2455 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2456 s = GetPlayerName(player_localnum);
2461 s = sprintf(_("Player %d"), i + 1 - first_pl);
2466 score_color = Team_ColorRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2467 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2468 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2469 drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2470 pos.y += fontsize.y;
2475 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2476 HUD_UpdatePlayerTeams();
2479 // show team scores in the first line
2480 float score_size = mySize.x / team_count;
2481 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2482 if(tm.team == NUM_SPECTATOR)
2484 if (tm.team == myteam)
2485 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2486 drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores[ts_primary])), eX * score_size + eY * fontsize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2490 pos.y += fontsize.y;
2491 tm = teams.sort_next;
2496 for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2498 if ((team_count && pl.team != tm.team) || pl.team == NUM_SPECTATOR)
2501 if (i == entries-1 && !me_printed && pl != me)
2502 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2504 for (pl = me.sort_next; pl; pl = pl.sort_next)
2505 if (pl.team != NUM_SPECTATOR)
2509 rgb = '1 1 0'; //not last but not among the leading players: yellow
2511 rgb = '1 0 0'; //last: red
2518 rgb = '0 1 0'; //first: green
2520 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2523 score_color = Team_ColorRGB(pl.team) * 0.8;
2524 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2525 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2526 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2527 pos.y += fontsize.y;
2530 while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != NUM_SPECTATOR || (tm = tm.sort_next)));
2533 void HUD_Score(void)
2535 if(intermission == 2) return;
2536 if(!autocvar__hud_configure)
2538 if(!autocvar_hud_panel_score) return;
2539 if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2542 HUD_Panel_UpdateCvars();
2545 mySize = panel_size;
2547 HUD_Panel_DrawBg(1);
2548 if(panel_bg_padding)
2550 pos += '1 1 0' * panel_bg_padding;
2551 mySize -= '2 2 0' * panel_bg_padding;
2554 float score, distribution = 0;
2556 vector distribution_color;
2559 me = playerslots[current_player];
2561 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2562 string timer, distrtimer;
2564 pl = players.sort_next;
2567 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2568 if(pl.scores[ps_primary] == 0)
2571 score = me.(scores[ps_primary]);
2572 timer = TIME_ENCODED_TOSTRING(score);
2574 draw_beginBoldFont();
2575 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2576 // distribution display
2577 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2579 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2581 if (distribution <= 0) {
2582 distribution_color = '0 1 0';
2586 distribution_color = '1 0 0';
2589 drawstring_aspect(pos + eX * 0.75 * mySize.x, strcat(sign, distrtimer), eX * 0.25 * mySize.x + eY * (1/3) * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2591 // race record display
2592 if (distribution <= 0)
2593 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2594 drawstring_aspect(pos, timer, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2596 } else if (!teamplay) { // non-teamgames
2597 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2599 HUD_Score_Rankings(pos, mySize, me);
2602 // me vector := [team/connected frags id]
2603 pl = players.sort_next;
2607 if(autocvar__hud_configure)
2610 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2614 score = me.(scores[ps_primary]);
2615 if(autocvar__hud_configure)
2618 if(distribution >= 5)
2619 distribution_color = eY;
2620 else if(distribution >= 0)
2621 distribution_color = '1 1 1';
2622 else if(distribution >= -5)
2623 distribution_color = '1 1 0';
2625 distribution_color = eX;
2627 string distribution_str;
2628 distribution_str = ftos(distribution);
2629 draw_beginBoldFont();
2630 if (distribution >= 0)
2632 if (distribution > 0)
2633 distribution_str = strcat("+", distribution_str);
2634 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2636 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2637 drawstring_aspect(pos + eX * 0.75 * mySize.x, distribution_str, eX * 0.25 * mySize.x + eY * (1/3) * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2639 } else { // teamgames
2640 float row, column, rows = 0, columns = 0;
2641 vector offset = '0 0 0';
2642 vector score_pos, score_size; //for scores other than myteam
2643 if(autocvar_hud_panel_score_rankings)
2645 HUD_Score_Rankings(pos, mySize, me);
2648 if(spectatee_status == -1)
2650 rows = HUD_GetRowCount(team_count, mySize, 3);
2651 columns = ceil(team_count/rows);
2652 score_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
2655 if(score_size.x/score_size.y > 3)
2657 newSize = 3 * score_size.y;
2658 offset.x = score_size.x - newSize;
2659 pos.x += offset.x/2;
2660 score_size.x = newSize;
2664 newSize = 1/3 * score_size.x;
2665 offset.y = score_size.y - newSize;
2666 pos.y += offset.y/2;
2667 score_size.y = newSize;
2671 score_size = eX * mySize.x*(1/4) + eY * mySize.y*(1/3);
2673 float max_fragcount;
2674 max_fragcount = -99;
2675 draw_beginBoldFont();
2677 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2678 if(tm.team == NUM_SPECTATOR)
2680 score = tm.(teamscores[ts_primary]);
2681 if(autocvar__hud_configure)
2684 if (score > max_fragcount)
2685 max_fragcount = score;
2687 if (spectatee_status == -1)
2689 score_pos = pos + eX * column * (score_size.x + offset.x) + eY * row * (score_size.y + offset.y);
2690 if (max_fragcount == score)
2691 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2692 drawstring_aspect(score_pos, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2700 else if(tm.team == myteam) {
2701 if (max_fragcount == score)
2702 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2703 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2705 if (max_fragcount == score)
2706 HUD_Panel_DrawHighlight(pos + eX * 0.75 * mySize.x + eY * (1/3) * rows * mySize.y, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2707 drawstring_aspect(pos + eX * 0.75 * mySize.x + eY * (1/3) * rows * mySize.y, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2717 void HUD_RaceTimer (void)
2719 if(intermission == 2) return;
2720 if(!autocvar__hud_configure)
2722 if(!autocvar_hud_panel_racetimer) return;
2723 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2724 if(spectatee_status == -1) return;
2727 HUD_Panel_UpdateCvars();
2731 mySize = panel_size;
2733 HUD_Panel_DrawBg(1);
2734 if(panel_bg_padding)
2736 pos += '1 1 0' * panel_bg_padding;
2737 mySize -= '2 2 0' * panel_bg_padding;
2740 // always force 4:1 aspect
2741 vector newSize = '0 0 0';
2742 if(mySize.x/mySize.y > 4)
2744 newSize.x = 4 * mySize.y;
2745 newSize.y = mySize.y;
2747 pos.x = pos.x + (mySize.x - newSize.x) / 2;
2751 newSize.y = 1/4 * mySize.x;
2752 newSize.x = mySize.x;
2754 pos.y = pos.y + (mySize.y - newSize.y) / 2;
2759 string s, forcetime;
2761 if(autocvar__hud_configure)
2764 draw_beginBoldFont();
2765 drawstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, false, '0.60 0.60 0' * mySize.y), s, '0.60 0.60 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2767 s = _("^1Intermediate 1 (+15.42)");
2768 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.20 * mySize.y) + eY * 0.60 * mySize.y, s, '1 1 0' * 0.20 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
2769 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
2770 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.20 * mySize.y) + eY * 0.80 * mySize.y, s, '1 1 0' * 0.20 * mySize.y, panel_fg_alpha, DRAWFLAG_NORMAL);
2772 else if(race_checkpointtime)
2774 a = bound(0, 2 - (time - race_checkpointtime), 1);
2777 if(a > 0) // just hit a checkpoint?
2779 if(race_checkpoint != 254)
2781 if(race_time && race_previousbesttime)
2782 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2784 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2786 forcetime = TIME_ENCODED_TOSTRING(race_time);
2791 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2793 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2794 if(a > 0) // next one?
2796 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2801 if(s != "" && a > 0)
2803 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2806 if(race_penaltytime)
2808 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2811 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
2812 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.8 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2816 draw_beginBoldFont();
2820 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2821 drawstring_expanding(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(forcetime, false, '1 1 0' * 0.6 * mySize.y), forcetime, '1 1 0' * 0.6 * mySize.y, '1 1 1', panel_fg_alpha, 0, a);
2826 if(race_laptime && race_checkpoint != 255)
2828 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2829 drawstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, false, '0.6 0.6 0' * mySize.y), s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2836 if(race_mycheckpointtime)
2838 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2839 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
2840 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2842 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2844 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2845 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
2846 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2849 if(race_penaltytime && !race_penaltyaccumulator)
2851 t = race_penaltytime * 0.1 + race_penaltyeventtime;
2852 a = bound(0, (1 + t - time), 1);
2856 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
2858 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
2859 drawcolorcodedstring(pos + eX * 0.5 * mySize.x - '0.5 0 0' * stringwidth(s, true, '1 1 0' * 0.2 * mySize.y) + eY * 0.6 * mySize.y, s, '1 1 0' * 0.2 * mySize.y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2870 if(intermission == 2) return;
2871 if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS)))
2874 if (autocvar__hud_configure)
2878 print(_("^1You must answer before entering hud configure mode\n"));
2879 cvar_set("_hud_configure", "0");
2881 if(vote_called_vote)
2882 strunzone(vote_called_vote);
2883 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
2884 uid2name_dialog = 1;
2887 if(!autocvar__hud_configure)
2889 if(!autocvar_hud_panel_vote) return;
2891 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
2892 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
2894 if(panel_bg_alpha_str == "") {
2895 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
2897 panel_bg_alpha = stof(panel_bg_alpha_str);
2908 if(vote_active != vote_prev) {
2910 vote_prev = vote_active;
2913 if(vote_active || autocvar__hud_configure)
2914 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2916 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2921 HUD_Panel_UpdateCvars();
2925 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
2926 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
2929 // these must be below above block
2932 mySize = panel_size;
2934 a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
2935 HUD_Panel_DrawBg(a);
2936 a = panel_fg_alpha * a;
2938 if(panel_bg_padding)
2940 pos += '1 1 0' * panel_bg_padding;
2941 mySize -= '2 2 0' * panel_bg_padding;
2944 // always force 3:1 aspect
2945 vector newSize = '0 0 0';
2946 if(mySize.x/mySize.y > 3)
2948 newSize.x = 3 * mySize.y;
2949 newSize.y = mySize.y;
2951 pos.x = pos.x + (mySize.x - newSize.x) / 2;
2955 newSize.y = 1/3 * mySize.x;
2956 newSize.x = mySize.x;
2958 pos.y = pos.y + (mySize.y - newSize.y) / 2;
2962 s = _("A vote has been called for:");
2964 s = _("Allow servers to store and display your name?");
2965 drawstring_aspect(pos, s, eX * mySize.x + eY * (2/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2966 s = textShortenToWidth(vote_called_vote, mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
2967 if(autocvar__hud_configure)
2968 s = _("^1Configure the HUD");
2969 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, eX * mySize.x + eY * (1.75/8) * mySize.y, a, DRAWFLAG_NORMAL);
2971 // print the yes/no counts
2972 s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
2973 drawstring_aspect(pos + eY * (4/8) * mySize.y, s, eX * 0.5 * mySize.x + eY * (1.5/8) * mySize.y, '0 1 0', a, DRAWFLAG_NORMAL);
2974 s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
2975 drawstring_aspect(pos + eX * 0.5 * mySize.x + eY * (4/8) * mySize.y, s, eX * 0.5 * mySize.x + eY * (1.5/8) * mySize.y, '1 0 0', a, DRAWFLAG_NORMAL);
2977 // draw the progress bar backgrounds
2978 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_back", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2980 // draw the highlights
2981 if(vote_highlighted == 1) {
2982 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
2983 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2985 else if(vote_highlighted == -1) {
2986 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
2987 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2990 // draw the progress bars
2991 if(vote_yescount && vote_needed)
2993 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
2994 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2997 if(vote_nocount && vote_needed)
2999 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
3000 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
3003 drawresetcliparea();
3006 // Mod icons panel (#10)
3009 bool mod_active; // is there any active mod icon?
3011 void DrawCAItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
3015 vector color = '0 0 0';
3019 stat = getstati(STAT_REDALIVE);
3020 pic = "player_red.tga";
3024 stat = getstati(STAT_BLUEALIVE);
3025 pic = "player_blue.tga";
3029 stat = getstati(STAT_YELLOWALIVE);
3030 pic = "player_yellow.tga";
3035 stat = getstati(STAT_PINKALIVE);
3036 pic = "player_pink.tga";
3041 if(mySize.x/mySize.y > aspect_ratio)
3043 i = aspect_ratio * mySize.y;
3044 myPos.x = myPos.x + (mySize.x - i) / 2;
3049 i = 1/aspect_ratio * mySize.x;
3050 myPos.y = myPos.y + (mySize.y - i) / 2;
3056 drawpic_aspect_skin(myPos, pic, eX * 0.7 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3057 drawstring_aspect(myPos + eX * 0.7 * mySize.x, ftos(stat), eX * 0.3 * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3060 drawstring_aspect(myPos, ftos(stat), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3063 // Clan Arena and Freeze Tag HUD modicons
3064 void HUD_Mod_CA(vector myPos, vector mySize)
3066 mod_active = 1; // required in each mod function that always shows something
3069 if(gametype == MAPINFO_TYPE_CA)
3070 layout = autocvar_hud_panel_modicons_ca_layout;
3071 else //if(gametype == MAPINFO_TYPE_FREEZETAG)
3072 layout = autocvar_hud_panel_modicons_freezetag_layout;
3075 aspect_ratio = (layout) ? 2 : 1;
3076 rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
3077 columns = ceil(team_count/rows);
3080 float row = 0, column = 0;
3081 vector pos, itemSize;
3082 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
3083 for(i=0; i<team_count; ++i)
3085 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
3087 DrawCAItem(pos, itemSize, aspect_ratio, layout, i);
3098 // CTF HUD modicon section
3099 int redflag_prevframe, blueflag_prevframe, yellowflag_prevframe, pinkflag_prevframe, neutralflag_prevframe; // status during previous frame
3100 int redflag_prevstatus, blueflag_prevstatus, yellowflag_prevstatus, pinkflag_prevstatus, neutralflag_prevstatus; // last remembered status
3101 float redflag_statuschange_time, blueflag_statuschange_time, yellowflag_statuschange_time, pinkflag_statuschange_time, neutralflag_statuschange_time; // time when the status changed
3103 void HUD_Mod_CTF_Reset(void)
3105 redflag_prevstatus = blueflag_prevstatus = yellowflag_prevstatus = pinkflag_prevstatus = neutralflag_prevstatus = 0;
3106 redflag_prevframe = blueflag_prevframe = yellowflag_prevframe = pinkflag_prevframe = neutralflag_prevframe = 0;
3107 redflag_statuschange_time = blueflag_statuschange_time = yellowflag_statuschange_time = pinkflag_statuschange_time = neutralflag_statuschange_time = 0;
3110 void HUD_Mod_CTF(vector pos, vector mySize)
3112 vector redflag_pos, blueflag_pos, yellowflag_pos, pinkflag_pos, neutralflag_pos;
3114 float f; // every function should have that
3116 int redflag, blueflag, yellowflag, pinkflag, neutralflag; // current status
3117 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime, yellowflag_statuschange_elapsedtime, pinkflag_statuschange_elapsedtime, neutralflag_statuschange_elapsedtime; // time since the status changed
3118 bool ctf_oneflag; // one-flag CTF mode enabled/disabled
3119 int stat_items = getstati(STAT_CTF_FLAGSTATUS, 0, 24);
3120 float fs, fs2, fs3, size1, size2;
3123 redflag = (stat_items/CTF_RED_FLAG_TAKEN) & 3;
3124 blueflag = (stat_items/CTF_BLUE_FLAG_TAKEN) & 3;
3125 yellowflag = (stat_items/CTF_YELLOW_FLAG_TAKEN) & 3;
3126 pinkflag = (stat_items/CTF_PINK_FLAG_TAKEN) & 3;
3127 neutralflag = (stat_items/CTF_NEUTRAL_FLAG_TAKEN) & 3;
3129 ctf_oneflag = (stat_items & CTF_FLAG_NEUTRAL);
3131 mod_active = (redflag || blueflag || yellowflag || pinkflag || neutralflag);
3133 if (autocvar__hud_configure) {
3136 if (team_count >= 3)
3138 if (team_count >= 4)
3140 ctf_oneflag = neutralflag = 0; // disable neutral flag in hud editor?
3143 // when status CHANGES, set old status into prevstatus and current status into status
3144 #define X(team) do { \
3145 if (team##flag != team##flag_prevframe) { \
3146 team##flag_statuschange_time = time; \
3147 team##flag_prevstatus = team##flag_prevframe; \
3148 team##flag_prevframe = team##flag; \
3150 team##flag_statuschange_elapsedtime = time - team##flag_statuschange_time; \
3159 const float BLINK_FACTOR = 0.15;
3160 const float BLINK_BASE = 0.85;
3162 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3164 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3166 const float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3168 #define X(team, cond) \
3169 string team##_icon, team##_icon_prevstatus; \
3170 int team##_alpha, team##_alpha_prevstatus; \
3171 team##_alpha = team##_alpha_prevstatus = 1; \
3173 switch (team##flag) { \
3174 case 1: team##_icon = "flag_" #team "_taken"; break; \
3175 case 2: team##_icon = "flag_" #team "_lost"; break; \
3176 case 3: team##_icon = "flag_" #team "_carrying"; team##_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break; \
3178 if ((stat_items & CTF_SHIELDED) && (cond)) { \
3179 team##_icon = "flag_" #team "_shielded"; \
3181 team##_icon = string_null; \
3185 switch (team##flag_prevstatus) { \
3186 case 1: team##_icon_prevstatus = "flag_" #team "_taken"; break; \
3187 case 2: team##_icon_prevstatus = "flag_" #team "_lost"; break; \
3188 case 3: team##_icon_prevstatus = "flag_" #team "_carrying"; team##_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break; \
3190 if (team##flag == 3) { \
3191 team##_icon_prevstatus = "flag_" #team "_carrying"; /* make it more visible */\
3192 } else if((stat_items & CTF_SHIELDED) && (cond)) { \
3193 team##_icon_prevstatus = "flag_" #team "_shielded"; \
3195 team##_icon_prevstatus = string_null; \
3200 X(red, myteam != NUM_TEAM_1);
3201 X(blue, myteam != NUM_TEAM_2);
3202 X(yellow, myteam != NUM_TEAM_3);
3203 X(pink, myteam != NUM_TEAM_4);
3208 // hacky, but these aren't needed
3209 red_icon = red_icon_prevstatus = blue_icon = blue_icon_prevstatus = yellow_icon = yellow_icon_prevstatus = pink_icon = pink_icon_prevstatus = string_null;
3211 } else switch (team_count) {
3213 case 2: fs = 0.5; fs2 = 0.5; fs3 = 0.5; break;
3214 case 3: fs = 1; fs2 = 0.35; fs3 = 0.35; break;
3215 case 4: fs = 0.75; fs2 = 0.25; fs3 = 0.5; break;
3218 if (mySize_x > mySize_y) {
3234 blueflag_pos = pos + eX * fs2 * size1;
3235 yellowflag_pos = pos - eX * fs2 * size1;
3236 pinkflag_pos = pos + eX * fs3 * size1;
3240 redflag_pos = pos + eX * fs2 * size1;
3242 yellowflag_pos = pos - eX * fs2 * size1;
3243 pinkflag_pos = pos + eX * fs3 * size1;
3247 redflag_pos = pos + eX * fs3 * size1;
3248 blueflag_pos = pos - eX * fs2 * size1;
3249 yellowflag_pos = pos;
3250 pinkflag_pos = pos + eX * fs2 * size1;
3254 redflag_pos = pos - eX * fs2 * size1;
3255 blueflag_pos = pos + eX * fs3 * size1;
3256 yellowflag_pos = pos + eX * fs2 * size1;
3261 neutralflag_pos = pos;
3262 flag_size = e1 * fs * size1 + e2 * size2;
3264 #define X(team) do { \
3265 f = bound(0, team##flag_statuschange_elapsedtime * 2, 1); \
3266 if (team##_icon_prevstatus && f < 1) \
3267 drawpic_aspect_skin_expanding(team##flag_pos, team##_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * team##_alpha_prevstatus, DRAWFLAG_NORMAL, f); \
3269 drawpic_aspect_skin(team##flag_pos, team##_icon, flag_size, '1 1 1', panel_fg_alpha * team##_alpha * f, DRAWFLAG_NORMAL); \
3279 // Keyhunt HUD modicon section
3282 void HUD_Mod_KH(vector pos, vector mySize)
3284 mod_active = 1; // keyhunt should never hide the mod icons panel
3286 // Read current state
3288 int state = getstati(STAT_KH_KEYS);
3290 int all_keys, team1_keys, team2_keys, team3_keys, team4_keys, dropped_keys, carrying_keys;
3291 all_keys = team1_keys = team2_keys = team3_keys = team4_keys = dropped_keys = carrying_keys = 0;
3293 for(i = 0; i < 4; ++i)
3295 key_state = (bitshift(state, i * -5) & 31) - 1;
3308 case NUM_TEAM_1: ++team1_keys; break;
3309 case NUM_TEAM_2: ++team2_keys; break;
3310 case NUM_TEAM_3: ++team3_keys; break;
3311 case NUM_TEAM_4: ++team4_keys; break;
3312 case 29: ++dropped_keys; break;
3318 // Calculate slot measurements
3322 if(all_keys == 4 && mySize.x * 0.5 < mySize.y && mySize.y * 0.5 < mySize.x)
3324 // Quadratic arrangement
3325 slot_size = eX * mySize.x * 0.5 + eY * mySize.y * 0.5;
3327 KH_SLOTS[1] = pos + eX * slot_size.x;
3328 KH_SLOTS[2] = pos + eY * slot_size.y;
3329 KH_SLOTS[3] = pos + eX * slot_size.x + eY * slot_size.y;
3333 if(mySize.x > mySize.y)
3335 // Horizontal arrangement
3336 slot_size = eX * mySize.x / all_keys + eY * mySize.y;
3337 for(i = 0; i < all_keys; ++i)
3338 KH_SLOTS[i] = pos + eX * slot_size.x * i;
3342 // Vertical arrangement
3343 slot_size = eX * mySize.x + eY * mySize.y / all_keys;
3344 for(i = 0; i < all_keys; ++i)
3345 KH_SLOTS[i] = pos + eY * slot_size.y * i;
3349 // Make icons blink in case of RUN HERE
3351 float blink = 0.6 + sin(2*M_PI*time) / 2.5; // Oscillate between 0.2 and 1
3358 case NUM_TEAM_1: if(team1_keys == all_keys) alpha = blink; break;
3359 case NUM_TEAM_2: if(team2_keys == all_keys) alpha = blink; break;
3360 case NUM_TEAM_3: if(team3_keys == all_keys) alpha = blink; break;
3361 case NUM_TEAM_4: if(team4_keys == all_keys) alpha = blink; break;
3369 if(myteam == NUM_TEAM_1 && carrying_keys)
3371 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3375 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3378 if(myteam == NUM_TEAM_2 && carrying_keys)
3380 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3384 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3387 if(myteam == NUM_TEAM_3 && carrying_keys)
3389 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3393 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3396 if(myteam == NUM_TEAM_4 && carrying_keys)
3398 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3402 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3404 while(dropped_keys--)
3405 drawpic_aspect_skin(KH_SLOTS[i++], "kh_dropped", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3408 // Keepaway HUD mod icon
3409 int kaball_prevstatus; // last remembered status
3410 float kaball_statuschange_time; // time when the status changed
3412 // we don't need to reset for keepaway since it immediately
3413 // autocorrects prevstatus as to if the player has the ball or not
3415 void HUD_Mod_Keepaway(vector pos, vector mySize)
3417 mod_active = 1; // keepaway should always show the mod HUD
3419 float BLINK_FACTOR = 0.15;
3420 float BLINK_BASE = 0.85;
3421 float BLINK_FREQ = 5;
3422 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
3424 int stat_items = getstati(STAT_ITEMS, 0, 24);
3425 int kaball = (stat_items/IT_KEY1) & 1;
3427 if(kaball != kaball_prevstatus)
3429 kaball_statuschange_time = time;
3430 kaball_prevstatus = kaball;
3433 vector kaball_pos, kaball_size;
3435 if(mySize.x > mySize.y) {
3436 kaball_pos = pos + eX * 0.25 * mySize.x;
3437 kaball_size = eX * 0.5 * mySize.x + eY * mySize.y;
3439 kaball_pos = pos + eY * 0.25 * mySize.y;
3440 kaball_size = eY * 0.5 * mySize.y + eX * mySize.x;
3443 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
3444 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
3446 if(kaball_prevstatus && f < 1)
3447 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
3450 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
3454 // Nexball HUD mod icon
3455 void HUD_Mod_NexBall(vector pos, vector mySize)
3457 float nb_pb_starttime, dt, p;
3460 stat_items = getstati(STAT_ITEMS, 0, 24);
3461 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3463 if (stat_items & IT_KEY1)
3468 //Manage the progress bar if any
3469 if (nb_pb_starttime > 0)
3471 dt = (time - nb_pb_starttime) % nb_pb_period;
3472 // one period of positive triangle
3473 p = 2 * dt / nb_pb_period;
3477 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, (mySize.x <= mySize.y), 0, autocvar_hud_progressbar_nexball_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3480 if (stat_items & IT_KEY1)
3481 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3484 // Race/CTS HUD mod icons
3485 float crecordtime_prev; // last remembered crecordtime
3486 float crecordtime_change_time; // time when crecordtime last changed
3487 float srecordtime_prev; // last remembered srecordtime
3488 float srecordtime_change_time; // time when srecordtime last changed
3490 float race_status_time;
3491 int race_status_prev;
3492 string race_status_name_prev;
3493 void HUD_Mod_Race(vector pos, vector mySize)
3495 mod_active = 1; // race should never hide the mod icons panel
3497 me = playerslots[player_localnum];
3499 float f; // yet another function has this
3500 score = me.(scores[ps_primary]);
3502 if(!(scores_flags[ps_primary] & SFL_TIME) || teamplay) // race/cts record display on HUD
3503 return; // no records in the actual race
3505 // clientside personal record
3507 if(gametype == MAPINFO_TYPE_CTS)
3511 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3513 if(score && (score < t || !t)) {
3514 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3515 if(autocvar_cl_autodemo_delete_keeprecords)
3517 f = autocvar_cl_autodemo_delete;
3519 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3523 if(t != crecordtime_prev) {
3524 crecordtime_prev = t;
3525 crecordtime_change_time = time;
3528 vector textPos, medalPos;
3530 if(mySize.x > mySize.y) {
3531 // text on left side
3532 squareSize = min(mySize.y, mySize.x/2);
3533 textPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eY * 0.5 * (mySize.y - squareSize);
3534 medalPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eX * 0.5 * mySize.x + eY * 0.5 * (mySize.y - squareSize);
3537 squareSize = min(mySize.x, mySize.y/2);
3538 textPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eX * 0.5 * (mySize.x - squareSize);
3539 medalPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eY * 0.5 * mySize.y + eX * 0.5 * (mySize.x - squareSize);
3542 f = time - crecordtime_change_time;
3545 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3546 drawstring_aspect(textPos + eY * 0.25 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3548 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3549 drawstring_aspect(textPos + eY * 0.25 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3550 drawstring_aspect_expanding(pos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3551 drawstring_aspect_expanding(pos + eY * 0.25 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3555 t = race_server_record;
3556 if(t != srecordtime_prev) {
3557 srecordtime_prev = t;
3558 srecordtime_change_time = time;
3560 f = time - srecordtime_change_time;
3563 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3564 drawstring_aspect(textPos + eY * 0.75 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3566 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3567 drawstring_aspect(textPos + eY * 0.75 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3568 drawstring_aspect_expanding(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3569 drawstring_aspect_expanding(textPos + eY * 0.75 * squareSize, TIME_ENCODED_TOSTRING(t), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3572 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3573 race_status_time = time + 5;
3574 race_status_prev = race_status;
3575 if (race_status_name_prev)
3576 strunzone(race_status_name_prev);
3577 race_status_name_prev = strzone(race_status_name);
3582 a = bound(0, race_status_time - time, 1);
3585 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
3589 rank = race_CheckName(race_status_name);
3593 rankname = count_ordinal(rank);
3596 namepos = medalPos + '0 0.8 0' * squareSize;
3598 rankpos = medalPos + '0 0.15 0' * squareSize;
3600 if(race_status == 0)
3601 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3602 else if(race_status == 1) {
3603 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newtime", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3604 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3605 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3606 } else if(race_status == 2) {
3607 if(race_status_name == GetPlayerName(player_localnum) || !race_myrank || race_myrank < rank)
3608 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankgreen", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3610 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankyellow", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3611 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3612 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3613 } else if(race_status == 3) {
3614 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrecordserver", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3615 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3616 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3619 if (race_status_time - time <= 0) {
3620 race_status_prev = -1;
3622 if(race_status_name)
3623 strunzone(race_status_name);
3624 race_status_name = string_null;
3625 if(race_status_name_prev)
3626 strunzone(race_status_name_prev);
3627 race_status_name_prev = string_null;
3631 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
3635 vector color = '0 0 0';
3639 stat = getstatf(STAT_DOM_PPS_RED);
3640 pic = "dom_icon_red";
3644 stat = getstatf(STAT_DOM_PPS_BLUE);
3645 pic = "dom_icon_blue";
3649 stat = getstatf(STAT_DOM_PPS_YELLOW);
3650 pic = "dom_icon_yellow";
3655 stat = getstatf(STAT_DOM_PPS_PINK);
3656 pic = "dom_icon_pink";
3660 float pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
3662 if(mySize.x/mySize.y > aspect_ratio)
3664 i = aspect_ratio * mySize.y;
3665 myPos.x = myPos.x + (mySize.x - i) / 2;
3670 i = 1/aspect_ratio * mySize.x;
3671 myPos.y = myPos.y + (mySize.y - i) / 2;
3675 if (layout) // show text too
3678 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
3679 if (layout == 2) // average pps
3680 drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), eX * (2/3) * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3681 else // percentage of average pps
3682 drawstring_aspect(myPos + eX * mySize.y, strcat( ftos(floor(pps_ratio*100 + 0.5)), "%" ), eX * (2/3) * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3686 drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3689 drawsetcliparea(myPos.x, myPos.y + mySize.y * (1 - pps_ratio), mySize.y, mySize.y * pps_ratio);
3690 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3691 drawresetcliparea();
3695 void HUD_Mod_Dom(vector myPos, vector mySize)
3697 mod_active = 1; // required in each mod function that always shows something
3699 int layout = autocvar_hud_panel_modicons_dom_layout;
3702 aspect_ratio = (layout) ? 3 : 1;
3703 rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
3704 columns = ceil(team_count/rows);
3707 float row = 0, column = 0;
3708 vector pos, itemSize;
3709 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
3710 for(i=0; i<team_count; ++i)
3712 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
3714 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
3725 void HUD_ModIcons_SetFunc()
3729 case MAPINFO_TYPE_KEYHUNT: HUD_ModIcons_GameType = HUD_Mod_KH; break;
3730 case MAPINFO_TYPE_CTF: HUD_ModIcons_GameType = HUD_Mod_CTF; break;
3731 case MAPINFO_TYPE_NEXBALL: HUD_ModIcons_GameType = HUD_Mod_NexBall; break;
3732 case MAPINFO_TYPE_CTS:
3733 case MAPINFO_TYPE_RACE: HUD_ModIcons_GameType = HUD_Mod_Race; break;
3734 case MAPINFO_TYPE_CA:
3735 case MAPINFO_TYPE_FREEZETAG: HUD_ModIcons_GameType = HUD_Mod_CA; break;
3736 case MAPINFO_TYPE_DOMINATION: HUD_ModIcons_GameType = HUD_Mod_Dom; break;
3737 case MAPINFO_TYPE_KEEPAWAY: HUD_ModIcons_GameType = HUD_Mod_Keepaway; break;
3741 int mod_prev; // previous state of mod_active to check for a change
3743 float mod_change; // "time" when mod_active changed
3745 void HUD_ModIcons(void)
3747 if(intermission == 2) return;
3748 if(!autocvar__hud_configure)
3750 if(!autocvar_hud_panel_modicons) return;
3751 if(!HUD_ModIcons_GameType) return;
3754 HUD_Panel_UpdateCvars();
3756 draw_beginBoldFont();
3758 if(mod_active != mod_prev) {
3760 mod_prev = mod_active;
3763 if(mod_active || autocvar__hud_configure)
3764 mod_alpha = bound(0, (time - mod_change) * 2, 1);
3766 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
3769 HUD_Panel_DrawBg(mod_alpha);
3771 if(panel_bg_padding)
3773 panel_pos += '1 1 0' * panel_bg_padding;
3774 panel_size -= '2 2 0' * panel_bg_padding;
3777 if(autocvar__hud_configure)
3778 HUD_Mod_CTF(panel_pos, panel_size);
3780 HUD_ModIcons_GameType(panel_pos, panel_size);
3785 // Draw pressed keys (#11)
3787 void HUD_PressedKeys(void)
3789 if(intermission == 2) return;
3790 if(!autocvar__hud_configure)
3792 if(!autocvar_hud_panel_pressedkeys) return;
3793 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
3796 HUD_Panel_UpdateCvars();
3799 mySize = panel_size;
3801 HUD_Panel_DrawBg(1);
3802 if(panel_bg_padding)
3804 pos += '1 1 0' * panel_bg_padding;
3805 mySize -= '2 2 0' * panel_bg_padding;
3808 // force custom aspect
3809 float aspect = autocvar_hud_panel_pressedkeys_aspect;
3812 vector newSize = '0 0 0';
3813 if(mySize.x/mySize.y > aspect)
3815 newSize.x = aspect * mySize.y;
3816 newSize.y = mySize.y;
3818 pos.x = pos.x + (mySize.x - newSize.x) / 2;
3822 newSize.y = 1/aspect * mySize.x;
3823 newSize.x = mySize.x;
3825 pos.y = pos.y + (mySize.y - newSize.y) / 2;
3831 keysize = eX * mySize.x * (1/3.0) + eY * mySize.y * (1/(3.0 - !autocvar_hud_panel_pressedkeys_attack));
3833 pressedkeys = getstatf(STAT_PRESSED_KEYS);
3835 if(autocvar_hud_panel_pressedkeys_attack)
3837 drawpic_aspect_skin(pos + eX * keysize.x * 0.5, ((pressedkeys & KEY_ATCK) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3838 drawpic_aspect_skin(pos + eX * keysize.x * 1.5, ((pressedkeys & KEY_ATCK2) ? "key_atck_inv.tga" : "key_atck.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3842 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3843 drawpic_aspect_skin(pos + eX * keysize.x, ((pressedkeys & KEY_FORWARD) ? "key_forward_inv.tga" : "key_forward.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3844 drawpic_aspect_skin(pos + eX * keysize.x * 2, ((pressedkeys & KEY_JUMP) ? "key_jump_inv.tga" : "key_jump.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3846 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3847 drawpic_aspect_skin(pos + eX * keysize.x, ((pressedkeys & KEY_BACKWARD) ? "key_backward_inv.tga" : "key_backward.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3848 drawpic_aspect_skin(pos + eX * keysize.x * 2, ((pressedkeys & KEY_RIGHT) ? "key_right_inv.tga" : "key_right.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3851 // Handle chat as a panel (#12)
3855 if(!autocvar__hud_configure)
3857 if (!autocvar_hud_panel_chat)
3859 if (!autocvar_con_chatrect)
3860 cvar_set("con_chatrect", "0");
3863 if(autocvar__con_chat_maximized)
3865 if(!hud_draw_maximized) return;
3867 else if(chat_panel_modified)
3869 panel.update_time = time; // forces reload of panel attributes
3870 chat_panel_modified = false;
3874 HUD_Panel_UpdateCvars();
3876 if(intermission == 2)
3878 // reserve some more space to the mapvote panel
3879 // by resizing and moving chat panel to the bottom
3880 panel_size.y = min(panel_size.y, vid_conheight * 0.2);
3881 panel_pos.y = vid_conheight - panel_size.y - panel_bg_border * 2;
3882 chat_posy = panel_pos.y;
3883 chat_sizey = panel_size.y;
3885 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
3887 panel_pos.y = panel_bg_border;
3888 panel_size.y = vid_conheight - panel_bg_border * 2;
3889 if(panel.current_panel_bg == "0") // force a border when maximized
3892 panel_bg = strcat(hud_skin_path, "/border_default");
3893 if(precache_pic(panel_bg) == "")
3894 panel_bg = "gfx/hud/default/border_default";
3895 if(panel.current_panel_bg)
3896 strunzone(panel.current_panel_bg);
3897 panel.current_panel_bg = strzone(panel_bg);
3898 chat_panel_modified = true;
3900 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an theAlpha of at least 0.75
3905 mySize = panel_size;
3907 HUD_Panel_DrawBg(1);
3909 if(panel_bg_padding)
3911 pos += '1 1 0' * panel_bg_padding;
3912 mySize -= '2 2 0' * panel_bg_padding;
3915 if (!autocvar_con_chatrect)
3916 cvar_set("con_chatrect", "1");
3918 cvar_set("con_chatrect_x", ftos(pos.x/vid_conwidth));
3919 cvar_set("con_chatrect_y", ftos(pos.y/vid_conheight));
3921 cvar_set("con_chatwidth", ftos(mySize.x/vid_conwidth));
3922 cvar_set("con_chat", ftos(floor(mySize.y/autocvar_con_chatsize - 0.5)));
3924 if(autocvar__hud_configure)
3927 chatsize = '1 1 0' * autocvar_con_chatsize;
3928 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over theAlpha and such
3930 for(i = 0; i < autocvar_con_chat; ++i)
3932 if(i == autocvar_con_chat - 1)
3935 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
3936 drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
3937 pos.y += chatsize.y;
3942 // Engine info panel (#13)
3949 float frametimeavg1; // 1 frame ago
3950 float frametimeavg2; // 2 frames ago
3951 void HUD_EngineInfo(void)
3953 //if(intermission == 2) return;
3954 if(!autocvar__hud_configure)
3956 if(!autocvar_hud_panel_engineinfo) return;
3959 HUD_Panel_UpdateCvars();
3962 mySize = panel_size;
3964 HUD_Panel_DrawBg(1);
3965 if(panel_bg_padding)
3967 pos += '1 1 0' * panel_bg_padding;
3968 mySize -= '2 2 0' * panel_bg_padding;
3971 float currentTime = gettime(GETTIME_REALTIME);
3972 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
3974 float currentframetime = currentTime - prevfps_time;
3975 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
3976 frametimeavg2 = frametimeavg1;
3977 frametimeavg1 = frametimeavg;
3980 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
3981 if(currentframetime > 0.0001) // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter.
3983 if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/currentframetime) to make big updates instant
3984 prevfps = (1/currentframetime);
3985 prevfps = (1 - weight) * prevfps + weight * (1/frametimeavg); // framecounter just used so there's no need for a new variable, think of it as "frametime average"
3987 prevfps_time = currentTime;
3992 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
3994 prevfps = framecounter/(currentTime - prevfps_time);
3996 prevfps_time = currentTime;
4001 color = HUD_Get_Num_Color (prevfps, 100);
4002 drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
4005 // Info messages panel (#14)
4007 #define drawInfoMessage(s) do { \
4008 if(autocvar_hud_panel_infomessages_flip) \
4009 o.x = pos.x + mySize.x - stringwidth(s, true, fontsize); \
4010 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL); \
4011 o.y += fontsize.y; \
4013 void HUD_InfoMessages(void)
4015 if(intermission == 2) return;
4016 if(!autocvar__hud_configure)
4018 if(!autocvar_hud_panel_infomessages) return;
4021 HUD_Panel_UpdateCvars();
4024 mySize = panel_size;
4026 HUD_Panel_DrawBg(1);
4027 if(panel_bg_padding)
4029 pos += '1 1 0' * panel_bg_padding;
4030 mySize -= '2 2 0' * panel_bg_padding;
4033 // always force 5:1 aspect
4034 vector newSize = '0 0 0';
4035 if(mySize.x/mySize.y > 5)
4037 newSize.x = 5 * mySize.y;
4038 newSize.y = mySize.y;
4040 pos.x = pos.x + (mySize.x - newSize.x) / 2;
4044 newSize.y = 1/5 * mySize.x;
4045 newSize.x = mySize.x;
4047 pos.y = pos.y + (mySize.y - newSize.y) / 2;
4056 fontsize = '0.20 0.20 0' * mySize.y;
4062 if(!autocvar__hud_configure)
4064 if(spectatee_status && !intermission)
4067 if(spectatee_status == -1)
4068 s = _("^1Observing");
4070 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(current_player));
4073 if(spectatee_status == -1)
4074 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
4076 s = sprintf(_("^1Press ^3%s^1 or ^3%s^1 for next or previous player"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4079 if(spectatee_status == -1)
4080 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4082 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
4085 s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
4088 if(gametype == MAPINFO_TYPE_LMS)
4091 sk = playerslots[player_localnum];
4092 if(sk.(scores[ps_primary]) >= 666)
4093 s = _("^1Match has already begun");
4094 else if(sk.(scores[ps_primary]) > 0)
4095 s = _("^1You have no more lives left");
4097 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4100 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4103 //show restart countdown:
4104 if (time < getstatf(STAT_GAMESTARTTIME)) {
4106 //we need to ceil, otherwise the countdown would be off by .5 when using round()
4107 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
4108 s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
4109 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
4113 if(warmup_stage && !intermission)
4115 s = _("^2Currently in ^1warmup^2 stage!");
4125 if(ready_waiting && !intermission && !spectatee_status)
4127 if(ready_waiting_for_me)
4130 s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4132 s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4137 s = _("^2Waiting for others to ready up to end warmup...");
4139 s = _("^2Waiting for others to ready up...");
4143 else if(warmup_stage && !intermission && !spectatee_status)
4145 s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
4149 if(teamplay && !intermission && !spectatee_status && gametype != MAPINFO_TYPE_CA && teamnagger)
4151 float ts_min = 0, ts_max = 0;
4152 tm = teams.sort_next;
4155 for (; tm.sort_next; tm = tm.sort_next)
4157 if(!tm.team_size || tm.team == NUM_SPECTATOR)
4159 if(!ts_min) ts_min = tm.team_size;
4160 else ts_min = min(ts_min, tm.team_size);
4161 if(!ts_max) ts_max = tm.team_size;
4162 else ts_max = max(ts_max, tm.team_size);
4164 if ((ts_max - ts_min) > 1)
4166 s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
4167 tm = GetTeam(myteam, false);
4169 if (tm.team != NUM_SPECTATOR)
4170 if (tm.team_size == ts_max)
4171 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
4179 s = _("^7Press ^3ESC ^7to show HUD options.");
4181 s = _("^3Doubleclick ^7a panel for panel-specific options.");
4183 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
4185 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
4190 // Physics panel (#15)
4192 vector acc_prevspeed;
4193 float acc_prevtime, acc_avg, top_speed, top_speed_time;
4194 float physics_update_time, discrete_speed, discrete_acceleration;
4195 void HUD_Physics(void)
4197 if(intermission == 2) return;
4198 if(!autocvar__hud_configure)
4200 if(!autocvar_hud_panel_physics) return;
4201 if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
4202 if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
4205 HUD_Panel_UpdateCvars();
4207 draw_beginBoldFont();
4209 HUD_Panel_DrawBg(1);
4210 if(panel_bg_padding)
4212 panel_pos += '1 1 0' * panel_bg_padding;
4213 panel_size -= '2 2 0' * panel_bg_padding;
4216 float acceleration_progressbar_scale = 0;
4217 if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1)
4218 acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
4221 if (autocvar_hud_panel_physics_text_scale <= 0)
4224 text_scale = min(autocvar_hud_panel_physics_text_scale, 1);
4227 float speed, conversion_factor;
4230 switch(autocvar_hud_panel_physics_speed_unit)
4235 conversion_factor = 1.0;
4239 conversion_factor = 0.0254;
4243 conversion_factor = 0.0254 * 3.6;
4247 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4251 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4255 vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel);
4257 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
4258 if (autocvar__hud_configure)
4259 speed = floor( max_speed * 0.65 + 0.5 );
4260 else if(autocvar_hud_panel_physics_speed_vertical)
4261 speed = floor( vlen(vel) * conversion_factor + 0.5 );
4263 speed = floor( vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5 );
4265 //compute acceleration
4266 float acceleration, f;
4267 if (autocvar__hud_configure)
4268 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
4271 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
4272 f = time - acc_prevtime;
4273 if(autocvar_hud_panel_physics_acceleration_vertical)
4274 acceleration = (vlen(vel) - vlen(acc_prevspeed));
4276 acceleration = (vlen(vel - '0 0 1' * vel.z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed.z));
4278 acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665);
4280 acc_prevspeed = vel;
4281 acc_prevtime = time;
4283 if(autocvar_hud_panel_physics_acceleration_movingaverage)
4285 f = bound(0, f * 10, 1);
4286 acc_avg = acc_avg * (1 - f) + acceleration * f;
4287 acceleration = acc_avg;
4291 int acc_decimals = 2;
4292 if(time > physics_update_time)
4294 // workaround for ftos_decimals returning a negative 0
4295 if(discrete_acceleration > -1 / pow(10, acc_decimals) && discrete_acceleration < 0)
4296 discrete_acceleration = 0;
4297 discrete_acceleration = acceleration;
4298 discrete_speed = speed;
4299 physics_update_time += autocvar_hud_panel_physics_update_interval;
4303 float panel_ar = panel_size.x/panel_size.y;
4304 vector speed_offset = '0 0 0', acceleration_offset = '0 0 0';
4305 if (panel_ar >= 5 && !acceleration_progressbar_scale)
4307 panel_size.x *= 0.5;
4308 if (autocvar_hud_panel_physics_flip)
4309 speed_offset.x = panel_size.x;
4311 acceleration_offset.x = panel_size.x;
4315 panel_size.y *= 0.5;
4316 if (autocvar_hud_panel_physics_flip)
4317 speed_offset.y = panel_size.y;
4319 acceleration_offset.y = panel_size.y;
4321 int speed_baralign, acceleration_baralign;
4322 if (autocvar_hud_panel_physics_baralign == 1)
4323 acceleration_baralign = speed_baralign = 1;
4324 else if(autocvar_hud_panel_physics_baralign == 4)
4325 acceleration_baralign = speed_baralign = 2;
4326 else if (autocvar_hud_panel_physics_flip)
4328 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
4329 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
4333 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
4334 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
4336 if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
4337 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
4341 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4342 HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, autocvar_hud_progressbar_speed_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4343 vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
4344 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4346 tmp_size.x = panel_size.x * 0.75;
4347 tmp_size.y = panel_size.y * text_scale;
4349 tmp_offset.x = panel_size.x - tmp_size.x;
4352 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
4353 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(discrete_speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4359 tmp_offset.x = tmp_size.x;
4360 if (autocvar_hud_panel_physics_speed_unit_show)
4363 tmp_size.x = panel_size.x * (1 - 0.75);
4364 tmp_size.y = panel_size.y * 0.4 * text_scale;
4365 tmp_offset.y = (panel_size.y * 0.4 - tmp_size.y) / 2;
4366 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4370 //compute and draw top speed
4371 if (autocvar_hud_panel_physics_topspeed)
4372 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4374 if (autocvar__hud_configure)
4376 top_speed = floor( max_speed * 0.75 + 0.5 );
4381 if (speed >= top_speed)
4384 top_speed_time = time;
4388 f = max(1, autocvar_hud_panel_physics_topspeed_time);
4389 // divide by f to make it start from 1
4390 f = cos( ((time - top_speed_time) / f) * PI/2 );
4392 else //hide top speed 0, it would be stupid
4397 //top speed progressbar peak
4398 if(speed < top_speed)
4399 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4402 vector peak_size = '0 0 0';
4403 if (speed_baralign == 0)
4404 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x;
4405 else if (speed_baralign == 1)
4406 peak_offsetX = (1 - min(top_speed, max_speed)/max_speed) * panel_size.x;
4407 else // if (speed_baralign == 2)
4408 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x * 0.5;
4409 peak_size.x = floor(panel_size.x * 0.01 + 1.5);
4410 peak_size.y = panel_size.y;
4411 if (speed_baralign == 2) // draw two peaks, on both sides
4413 drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x + peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4414 drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size.x - peak_offsetX + peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4417 drawfill(panel_pos + speed_offset + eX * (peak_offsetX - peak_size.x), peak_size, autocvar_hud_progressbar_speed_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4421 tmp_offset.y = panel_size.y * 0.4;
4422 tmp_size.x = panel_size.x * (1 - 0.75);
4423 tmp_size.y = (panel_size.y - tmp_offset.y) * text_scale;
4424 tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2;
4425 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
4433 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
4435 vector progressbar_color;
4436 if(acceleration < 0)
4437 progressbar_color = autocvar_hud_progressbar_acceleration_neg_color;
4439 progressbar_color = autocvar_hud_progressbar_acceleration_color;
4441 f = acceleration/autocvar_hud_panel_physics_acceleration_max;
4442 if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear)
4443 f = (f >= 0 ? sqrt(f) : -sqrt(-f));
4445 if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds
4447 tmp_size = acceleration_progressbar_scale * panel_size.x * eX + panel_size.y * eY;
4449 if (acceleration_baralign == 1)
4450 tmp_offset.x = panel_size.x - tmp_size.x;
4451 else if (acceleration_baralign == 2 || acceleration_baralign == 3)
4452 tmp_offset.x = (panel_size.x - tmp_size.x) / 2;
4459 tmp_size = panel_size;
4460 tmp_offset = '0 0 0';
4463 HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset + tmp_offset, tmp_size, "accelbar", f, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4466 if(autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
4468 tmp_size.x = panel_size.x;
4469 tmp_size.y = panel_size.y * text_scale;
4471 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
4473 drawstring_aspect(panel_pos + acceleration_offset + tmp_offset, strcat(ftos_decimals(discrete_acceleration, acc_decimals), "g"), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4479 // CenterPrint (#16)
4481 const int CENTERPRINT_MAX_MSGS = 10;
4482 const int CENTERPRINT_MAX_ENTRIES = 50;
4483 const float CENTERPRINT_SPACING = 0.7;
4485 string centerprint_messages[CENTERPRINT_MAX_MSGS];
4486 int centerprint_msgID[CENTERPRINT_MAX_MSGS];
4487 float centerprint_time[CENTERPRINT_MAX_MSGS];
4488 float centerprint_expire_time[CENTERPRINT_MAX_MSGS];
4489 int centerprint_countdown_num[CENTERPRINT_MAX_MSGS];
4490 bool centerprint_showing;
4492 void centerprint_generic(int new_id, string strMessage, float duration, int countdown_num)
4494 //printf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num);
4497 if(strMessage == "" && new_id == 0)
4500 // strip trailing newlines
4501 j = strlen(strMessage) - 1;
4502 while(substring(strMessage, j, 1) == "\n" && j >= 0)
4504 if (j < strlen(strMessage) - 1)
4505 strMessage = substring(strMessage, 0, j + 1);
4507 if(strMessage == "" && new_id == 0)
4510 // strip leading newlines
4512 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
4515 strMessage = substring(strMessage, j, strlen(strMessage) - j);
4517 if(strMessage == "" && new_id == 0)
4520 if (!centerprint_showing)
4521 centerprint_showing = true;
4523 for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4525 if (j == CENTERPRINT_MAX_MSGS)
4527 if (new_id && new_id == centerprint_msgID[j])
4529 if (strMessage == "" && centerprint_messages[j] != "" && centerprint_countdown_num[j] == 0)
4531 // fade out the current msg (duration and countdown_num are ignored)
4532 centerprint_time[j] = min(5, autocvar_hud_panel_centerprint_fade_out);
4533 if (centerprint_expire_time[j] > time + min(5, autocvar_hud_panel_centerprint_fade_out) || centerprint_expire_time[j] < time)
4534 centerprint_expire_time[j] = time + min(5, autocvar_hud_panel_centerprint_fade_out);
4537 break; // found a msg with the same id, at position j
4541 if (i == CENTERPRINT_MAX_MSGS)
4543 // a msg with the same id was not found, add the msg at the next position
4545 if (cpm_index == -1)
4546 cpm_index = CENTERPRINT_MAX_MSGS - 1;
4549 if(centerprint_messages[j])
4550 strunzone(centerprint_messages[j]);
4551 centerprint_messages[j] = strzone(strMessage);
4552 centerprint_msgID[j] = new_id;
4555 centerprint_time[j] = -1;
4556 centerprint_expire_time[j] = time;
4561 duration = max(1, autocvar_hud_panel_centerprint_time);
4562 centerprint_time[j] = duration;
4563 centerprint_expire_time[j] = time + duration;
4565 centerprint_countdown_num[j] = countdown_num;
4568 void centerprint_hud(string strMessage)
4570 centerprint_generic(0, strMessage, autocvar_hud_panel_centerprint_time, 0);
4573 void reset_centerprint_messages(void)
4576 for (i=0; i<CENTERPRINT_MAX_MSGS; ++i)
4578 centerprint_expire_time[i] = 0;
4579 centerprint_time[i] = 1;
4580 centerprint_msgID[i] = 0;
4581 if(centerprint_messages[i])
4582 strunzone(centerprint_messages[i]);
4583 centerprint_messages[i] = string_null;
4586 float hud_configure_cp_generation_time;
4587 void HUD_CenterPrint (void)
4589 if(intermission == 2) return;
4590 if(!autocvar__hud_configure)
4592 if(!autocvar_hud_panel_centerprint) return;
4594 if(hud_configure_prev)
4595 reset_centerprint_messages();
4599 if(!hud_configure_prev)
4600 reset_centerprint_messages();
4601 if (time > hud_configure_cp_generation_time)
4603 if(HUD_PANEL(CENTERPRINT) == highlightedPanel)
4608 centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: ^COUNT"), 1, 10);
4610 centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0);
4612 centerprint_hud(sprintf("Message at time %s", seconds_tostring(time)));
4613 hud_configure_cp_generation_time = time + 1 + random()*4;
4617 centerprint_generic(0, sprintf("Centerprint message", seconds_tostring(time)), 10, 0);
4618 hud_configure_cp_generation_time = time + 10 - random()*3;
4623 // this panel fades only when the menu does
4624 float hud_fade_alpha_save = 0;
4625 if(scoreboard_fade_alpha)
4627 hud_fade_alpha_save = hud_fade_alpha;
4628 hud_fade_alpha = 1 - autocvar__menu_alpha;
4630 HUD_Panel_UpdateCvars();
4632 if ( HUD_Radar_Clickable() )
4634 if (hud_panel_radar_bottom >= 0.96 * vid_conheight)
4637 panel_pos = eY * hud_panel_radar_bottom + eX * 0.5 * (vid_conwidth - panel_size_x);
4638 panel_size_y = min(panel_size_y, vid_conheight - hud_panel_radar_bottom);
4640 else if(scoreboard_fade_alpha)
4642 hud_fade_alpha = hud_fade_alpha_save;
4644 // move the panel below the scoreboard
4645 if (scoreboard_bottom >= 0.96 * vid_conheight)
4649 target_pos = eY * scoreboard_bottom + eX * 0.5 * (vid_conwidth - panel_size.x);
4651 if(target_pos.y > panel_pos.y)
4653 panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha);
4654 panel_size.y = min(panel_size.y, vid_conheight - scoreboard_bottom);
4658 HUD_Panel_DrawBg(1);
4660 if (!centerprint_showing)
4663 if(panel_bg_padding)
4665 panel_pos += '1 1 0' * panel_bg_padding;
4666 panel_size -= '2 2 0' * panel_bg_padding;
4672 // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
4673 // height = panel_size_y/entries;
4674 // fontsize = '1 1 0' * height;
4675 height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
4676 fontsize = '1 1 0' * height;
4677 entries = bound(1, floor(panel_size.y/height), CENTERPRINT_MAX_ENTRIES);
4680 float a, sz, align, current_msg_posY = 0, msg_size;
4683 bool all_messages_expired = true;
4686 if (autocvar_hud_panel_centerprint_flip)
4687 pos.y += panel_size.y;
4688 align = bound(0, autocvar_hud_panel_centerprint_align, 1);
4689 for (g=0, i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4691 if (j == CENTERPRINT_MAX_MSGS)
4693 if (centerprint_expire_time[j] <= time)
4695 if (centerprint_countdown_num[j] && centerprint_time[j] > 0)
4697 centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1;
4698 if (centerprint_countdown_num[j] == 0)
4700 centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
4702 else if(centerprint_time[j] != -1)
4706 all_messages_expired = false;
4708 // fade the centerprint_hud in/out
4709 if(centerprint_time[j] < 0) // Expired but forced. Expire time is the fade-in time.
4710 a = (time - centerprint_expire_time[j]) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4711 else if(centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time) // Regularily printed. Not fading out yet.
4712 a = (time - (centerprint_expire_time[j] - centerprint_time[j])) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4713 else // Expiring soon, so fade it out.
4714 a = (centerprint_expire_time[j] - time) / max(0.0001, autocvar_hud_panel_centerprint_fade_out);
4716 // while counting down show it anyway in order to hold the current message position
4717 if (a <= 0.5/255.0 && centerprint_countdown_num[j] == 0) // Guaranteed invisible - don't show.
4722 // set the size from fading in/out before subsequent fading
4723 sz = autocvar_hud_panel_centerprint_fade_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_minfontsize);
4725 // also fade it based on positioning
4726 if(autocvar_hud_panel_centerprint_fade_subsequent)
4728 a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passone_minalpha, (1 - (g / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passone))), 1); // pass one: all messages after the first have half theAlpha
4729 a = a * bound(autocvar_hud_panel_centerprint_fade_subsequent_passtwo_minalpha, (1 - (g / max(1, autocvar_hud_panel_centerprint_fade_subsequent_passtwo))), 1); // pass two: after that, gradually lower theAlpha even more for each message
4731 a *= panel_fg_alpha;
4733 // finally set the size based on the new theAlpha from subsequent fading
4734 sz = sz * (autocvar_hud_panel_centerprint_fade_subsequent_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_subsequent_minfontsize));
4735 drawfontscale = sz * '1 1 0';
4737 if (centerprint_countdown_num[j])
4738 n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_messages[j]), "\n");
4740 n = tokenizebyseparator(centerprint_messages[j], "\n");
4742 if (autocvar_hud_panel_centerprint_flip)
4744 // check if the message can be entirely shown
4745 for(k = 0; k < n; ++k)
4747 getWrappedLine_remaining = argv(k);
4748 while(getWrappedLine_remaining)
4750 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4752 pos.y -= fontsize.y;
4754 pos.y -= fontsize.y * CENTERPRINT_SPACING/2;
4757 current_msg_posY = pos.y; // save starting pos (first line) of the current message
4761 for(k = 0; k < n; ++k)
4763 getWrappedLine_remaining = argv(k);
4764 while(getWrappedLine_remaining)
4766 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4770 pos.x = panel_pos.x + (panel_size.x - stringwidth(ts, true, fontsize)) * align;
4771 if (a > 0.5/255.0) // Otherwise guaranteed invisible - don't show. This is checked a second time after some multiplications with other factors were done so temporary changes of these cannot cause flicker.
4772 drawcolorcodedstring(pos + eY * 0.5 * (1 - sz) * fontsize.y, ts, fontsize, a, DRAWFLAG_NORMAL);
4773 pos.y += fontsize.y;
4776 pos.y += fontsize.y * CENTERPRINT_SPACING/2;
4780 ++g; // move next position number up
4782 msg_size = pos.y - msg_size;
4783 if (autocvar_hud_panel_centerprint_flip)
4785 pos.y = current_msg_posY - CENTERPRINT_SPACING * fontsize.y;
4786 if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages
4787 pos.y += (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4789 if (pos.y < panel_pos.y) // check if the next message can be shown
4791 drawfontscale = '1 1 0';
4797 pos.y += CENTERPRINT_SPACING * fontsize.y;
4798 if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages
4799 pos.y -= (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4801 if(pos.y > panel_pos.y + panel_size.y - fontsize.y) // check if the next message can be shown
4803 drawfontscale = '1 1 0';
4808 drawfontscale = '1 1 0';
4809 if (all_messages_expired)
4811 centerprint_showing = false;
4812 reset_centerprint_messages();
4819 #include "../common/minigames/cl_minigames_hud.qc"
4824 #include "quickmenu.qc"
4833 bool HUD_Panel_CheckFlags(int showflags)
4835 if ( HUD_Minigame_Showpanels() )
4836 return showflags & PANEL_SHOW_MINIGAME;
4837 return showflags & PANEL_SHOW_MAINGAME;
4840 void HUD_Panel_Draw(entity panent)
4843 if ( HUD_Panel_CheckFlags(panel.panel_showflags) )
4847 void HUD_Reset (void)
4849 // reset gametype specific icons
4850 if(gametype == MAPINFO_TYPE_CTF)
4851 HUD_Mod_CTF_Reset();
4854 void HUD_Main (void)
4857 // global hud theAlpha fade
4858 if(menu_enabled == 1)
4861 hud_fade_alpha = (1 - autocvar__menu_alpha);
4863 if(scoreboard_fade_alpha)
4864 hud_fade_alpha = (1 - scoreboard_fade_alpha);
4866 HUD_Configure_Frame();
4868 // panels that we want to be active together with the scoreboard
4869 // they must fade only when the menu does
4870 if(scoreboard_fade_alpha == 1)
4872 HUD_Panel_Draw(HUD_PANEL(CENTERPRINT));
4876 if(!autocvar__hud_configure && !hud_fade_alpha)
4879 HUD_Panel_Draw(HUD_PANEL(VOTE));
4885 if (hud_skin_prev != autocvar_hud_skin)
4888 strunzone(hud_skin_path);
4889 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
4891 strunzone(hud_skin_prev);
4892 hud_skin_prev = strzone(autocvar_hud_skin);
4896 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
4900 float hud_dock_color_team = autocvar_hud_dock_color_team;
4901 if((teamplay) && hud_dock_color_team) {
4902 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
4903 color = '1 0 0' * hud_dock_color_team;
4905 color = myteamcolors * hud_dock_color_team;
4907 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
4908 color = '1 0 0' * hud_dock_color_team;
4912 string hud_dock_color = autocvar_hud_dock_color;
4913 if(hud_dock_color == "shirt") {
4914 f = stof(getplayerkeyvalue(current_player, "colors"));
4915 color = colormapPaletteColor(floor(f / 16), 0);
4917 else if(hud_dock_color == "pants") {
4918 f = stof(getplayerkeyvalue(current_player, "colors"));
4919 color = colormapPaletteColor(f % 16, 1);
4922 color = stov(hud_dock_color);
4926 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
4927 if(precache_pic(pic) == "") {
4928 pic = strcat(hud_skin_path, "/dock_medium");
4929 if(precache_pic(pic) == "") {
4930 pic = "gfx/hud/default/dock_medium";
4933 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...
4936 // cache the panel order into the panel_order array
4937 if(autocvar__hud_panelorder != hud_panelorder_prev) {
4938 for(i = 0; i < HUD_PANEL_NUM; ++i)
4939 panel_order[i] = -1;
4942 bool warning = false;
4943 int argc = tokenize_console(autocvar__hud_panelorder);
4944 if (argc > HUD_PANEL_NUM)
4946 //first detect wrong/missing panel numbers
4947 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4948 p_num = stoi(argv(i));
4949 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
4950 if (panel_order[p_num] == -1) //found for the first time?
4951 s = strcat(s, ftos(p_num), " ");
4952 panel_order[p_num] = 1; //mark as found
4957 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4958 if (panel_order[i] == -1) {
4960 s = strcat(s, ftos(i), " "); //add missing panel number
4964 dprint("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
4966 cvar_set("_hud_panelorder", s);
4967 if(hud_panelorder_prev)
4968 strunzone(hud_panelorder_prev);
4969 hud_panelorder_prev = strzone(s);
4971 //now properly set panel_order
4972 tokenize_console(s);
4973 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4974 panel_order[i] = stof(argv(i));
4978 hud_draw_maximized = 0;
4979 // draw panels in the order specified by panel_order array
4980 for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
4981 HUD_Panel_Draw(hud_panel[panel_order[i]]);
4983 hud_draw_maximized = 1; // panels that may be maximized must check this var
4984 // draw maximized panels on top
4985 if(hud_panel_radar_maximized)
4986 HUD_Panel_Draw(HUD_PANEL(RADAR));
4987 if(autocvar__con_chat_maximized)
4988 HUD_Panel_Draw(HUD_PANEL(CHAT));
4989 if(hud_panel_quickmenu)
4990 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
4992 HUD_Configure_PostDraw();
4994 hud_configure_prev = autocvar__hud_configure;