1 #include "scoreboard.qh"
2 #include "teamradar.qh"
3 #include "../common/buffs.qh"
4 #include "../common/counting.qh"
5 #include "../common/mapinfo.qh"
6 #include "../common/nades.qh"
7 #include "../server/t_items.qh"
15 // a border picture is a texture containing nine parts:
16 // 1/4 width: left part
17 // 1/2 width: middle part (stretched)
18 // 1/4 width: right part
20 // 1/4 height: top part
21 // 1/2 height: middle part (stretched)
22 // 1/4 height: bottom part
23 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
25 if (theBorderSize.x < 0 && theBorderSize.y < 0) // draw whole image as it is
27 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
30 if (theBorderSize.x == 0 && theBorderSize.y == 0) // no border
32 // draw only the central part
33 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
40 //pic = draw_UseSkinFor(pic);
41 width = eX * theSize.x;
42 height = eY * theSize.y;
43 if(theSize.x <= theBorderSize.x * 2)
45 // not wide enough... draw just left and right then
46 bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2));
47 if(theSize.y <= theBorderSize.y * 2)
49 // not high enough... draw just corners
50 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
51 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
52 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
53 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
54 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
58 dY = theBorderSize.x * eY;
59 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
60 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
61 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
62 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);
63 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
64 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);
69 if(theSize.y <= theBorderSize.y * 2)
71 // not high enough... draw just top and bottom then
72 bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2));
73 dX = theBorderSize.x * eX;
74 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
75 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
76 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
77 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
78 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);
79 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);
83 dX = theBorderSize.x * eX;
84 dY = theBorderSize.x * eY;
85 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
86 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
87 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
88 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
89 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
90 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
91 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
92 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
93 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
98 vector HUD_Get_Num_Color (float x, float maxvalue)
103 color.x = sin(2*M_PI*time);
105 color.z = sin(2*M_PI*time);
107 else if(x > maxvalue * 0.75) {
108 color.x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
109 color.y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
112 else if(x > maxvalue * 0.5) {
113 color.x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
114 color.y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
115 color.z = 1 - (x-100)*0.02; // blue value between 1 -> 0
117 else if(x > maxvalue * 0.25) {
120 color.z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
122 else if(x > maxvalue * 0.1) {
124 color.y = (x-20)*90/27/100; // green value between 0 -> 1
125 color.z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
133 blinkingamt = (1 - x/maxvalue/0.25);
136 color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time);
137 color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time);
138 color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time);
143 float stringwidth_colors(string s, vector theSize)
145 return stringwidth(s, true, theSize);
148 float stringwidth_nocolors(string s, vector theSize)
150 return stringwidth(s, false, theSize);
153 void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag)
155 position.x -= 2 / 3 * strlen(text) * theScale.x;
156 drawstring(position, text, theScale, rgb, theAlpha, flag);
159 void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag)
161 position.x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale.x);
162 drawstring(position, text, theScale, rgb, theAlpha, flag);
165 // return the string of the onscreen race timer
166 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
174 if(histime == 0) // goal hit
178 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
188 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
194 lapstr = sprintf(_(" (-%dL)"), lapdelta);
197 else if(lapdelta < 0)
199 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
203 else if(histime > 0) // anticipation
205 if(mytime >= histime)
206 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
208 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
218 cpname = _("Start line");
220 cpname = _("Finish line");
222 cpname = sprintf(_("Intermediate %d"), cp);
224 cpname = _("Finish line");
227 return strcat(col, cpname);
228 else if(hisname == "")
229 return strcat(col, sprintf("%s (%s)", cpname, timestr));
231 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(hisname, col, lapstr)));
234 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
235 float race_CheckName(string net_name) {
237 for (i=RANKINGS_CNT-1;i>=0;--i)
238 if(grecordholder[i] == net_name)
243 float GetPlayerColorForce(int i)
248 return stof(getplayerkeyvalue(i, "colors")) & 15;
251 float GetPlayerColor(int i)
253 if(!playerslots[i].gotscores) // unconnected
254 return NUM_SPECTATOR;
255 else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR)
256 return NUM_SPECTATOR;
258 return GetPlayerColorForce(i);
261 string GetPlayerName(int i)
263 return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
273 // draw the background/borders
274 #define HUD_Panel_DrawBg(theAlpha) do { \
275 if(panel.current_panel_bg != "0" && panel.current_panel_bg != "") \
276 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));\
279 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
280 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, float vertical, float baralign, vector theColor, float theAlpha, float drawflag)
282 if(!length_ratio || !theAlpha)
288 if(length_ratio < -1)
291 else if(length_ratio < 0)
295 vector width, height;
297 pic = strcat(hud_skin_path, "/", pic, "_vertical");
298 if(precache_pic(pic) == "") {
299 pic = "gfx/hud/default/progressbar_vertical";
302 if (baralign == 1) // bottom align
303 theOrigin.y += (1 - length_ratio) * theSize.y;
304 else if (baralign == 2) // center align
305 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
306 else if (baralign == 3) // center align, positive values down, negative up
309 if (length_ratio > 0)
310 theOrigin.y += theSize.y;
313 theOrigin.y += (1 + length_ratio) * theSize.y;
314 length_ratio = -length_ratio;
317 theSize.y *= length_ratio;
320 width = eX * theSize.x;
321 height = eY * theSize.y;
322 if(theSize.y <= theSize.x * 2)
324 // button not high enough
325 // draw just upper and lower part then
326 square = eY * theSize.y * 0.5;
327 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
328 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
329 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
333 square = eY * theSize.x;
334 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
335 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
336 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
339 pic = strcat(hud_skin_path, "/", pic);
340 if(precache_pic(pic) == "") {
341 pic = "gfx/hud/default/progressbar";
344 if (baralign == 1) // right align
345 theOrigin.x += (1 - length_ratio) * theSize.x;
346 else if (baralign == 2) // center align
347 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
348 else if (baralign == 3) // center align, positive values on the right, negative on the left
351 if (length_ratio > 0)
352 theOrigin.x += theSize.x;
355 theOrigin.x += (1 + length_ratio) * theSize.x;
356 length_ratio = -length_ratio;
359 theSize.x *= length_ratio;
362 width = eX * theSize.x;
363 height = eY * theSize.y;
364 if(theSize.x <= theSize.y * 2)
366 // button not wide enough
367 // draw just left and right part then
368 square = eX * theSize.x * 0.5;
369 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
370 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
371 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
375 square = eX * theSize.y;
376 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
377 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
378 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
383 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, float drawflag)
389 pic = strcat(hud_skin_path, "/num_leading");
390 if(precache_pic(pic) == "") {
391 pic = "gfx/hud/default/num_leading";
394 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
395 if(mySize.x/mySize.y > 2)
396 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);
397 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);
402 entity weaponorder[WEP_MAXCOUNT];
403 void weaponorder_swap(int i, int j, entity pass)
405 entity h = weaponorder[i];
406 weaponorder[i] = weaponorder[j];
410 string weaponorder_cmp_str;
411 float weaponorder_cmp(float i, float j, entity pass)
414 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
415 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
416 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)
419 void HUD_Weapons(void)
422 WepSet weapons_stat = WepSet_GetFromStat();
425 vector center = '0 0 0';
426 float weapon_count, weapon_id;
427 float row, column, rows = 0, columns = 0;
428 float aspect = autocvar_hud_panel_weapons_aspect;
430 float panel_weapon_accuracy;
432 float timeout = autocvar_hud_panel_weapons_timeout;
433 float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
434 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
437 vector barsize = '0 0 0', baroffset = '0 0 0';
438 vector ammo_color = '1 0 1';
439 float ammo_alpha = 1;
441 float when = max(1, autocvar_hud_panel_weapons_complainbubble_time);
442 float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime);
444 vector weapon_pos, weapon_size = '0 0 0';
447 // check to see if we want to continue
448 if(hud != HUD_NORMAL) { return; }
450 if(!autocvar__hud_configure)
452 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
454 if(timeout && time >= weapontime + timeout + timeout_effect_length)
455 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)))
457 weaponprevtime = time;
462 // update generic hud functions
463 HUD_Panel_UpdateCvars();
465 draw_beginBoldFont();
467 // figure out weapon order (how the weapons are sorted) // TODO make this configurable
468 if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
471 if(weaponorder_bypriority)
472 strunzone(weaponorder_bypriority);
473 if(weaponorder_byimpulse)
474 strunzone(weaponorder_byimpulse);
476 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
477 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
478 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
481 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
483 self = get_weaponinfo(i);
484 if(self.impulse >= 0)
486 weaponorder[weapon_cnt] = self;
490 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
491 weaponorder[i] = world;
492 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
494 weaponorder_cmp_str = string_null;
497 if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime)
500 // determine which weapons are going to be shown
501 if (autocvar_hud_panel_weapons_onlyowned)
503 if(autocvar__hud_configure)
506 for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5))
507 weapons_stat |= WepSet_FromWeapon(i);
509 if(menu_enabled != 2)
510 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
513 // do we own this weapon?
515 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
516 if(weapons_stat & WepSet_FromWeapon(weaponorder[i].weapon))
519 // add it anyway if weaponcomplain is shown
523 // might as well commit suicide now, no reason to live ;)
524 if (weapon_count == 0)
530 vector max_panel_size = panel_size - '2 2 0' * panel_bg_padding;
532 // calculate distribution and size of table cells
533 if(max_panel_size.x > max_panel_size.y)
535 while(weapon_count > columns * rows)
538 columns = ceil(max_panel_size.x / (max_panel_size.y / rows * aspect));
541 weapon_size.x = max_panel_size.x / columns;
542 weapon_size.y = max_panel_size.y / rows;
543 columns = ceil(weapon_count / rows);
547 while(weapon_count > columns * rows)
550 rows = ceil(max_panel_size.y / (max_panel_size.x / columns / aspect));
553 weapon_size.x = max_panel_size.x / columns;
554 weapon_size.y = max_panel_size.y / rows;
555 rows = ceil(weapon_count / columns);
558 // reduce size of the panel
559 panel_size.x = columns * weapon_size.x;
560 panel_size.y = rows * weapon_size.y;
561 panel_pos.x += (max_panel_size.x - panel_size.x) / 2;
562 panel_pos.y += (max_panel_size.y - panel_size.y) / 2;
564 panel_size += '2 2 0' * panel_bg_padding;
567 weapon_count = WEP_COUNT;
569 // animation for fading in/out the panel respectively when not in use
570 if(!autocvar__hud_configure)
572 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
574 f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
576 // fade the panel alpha
577 if(autocvar_hud_panel_weapons_timeout_effect == 1)
579 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
580 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
582 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
584 panel_bg_alpha *= (1 - f);
585 panel_fg_alpha *= (1 - f);
588 // move the panel off the screen
589 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
591 f *= f; // for a cooler movement
592 center.x = panel_pos.x + panel_size.x/2;
593 center.y = panel_pos.y + panel_size.y/2;
594 screen_ar = vid_conwidth/vid_conheight;
595 if (center.x/center.y < screen_ar) //bottom left
597 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
598 panel_pos.y += f * (vid_conheight - panel_pos.y);
600 panel_pos.x -= f * (panel_pos.x + panel_size.x);
604 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
605 panel_pos.x += f * (vid_conwidth - panel_pos.x);
607 panel_pos.y -= f * (panel_pos.y + panel_size.y);
610 center.x = -1; // mark the panel as off screen
612 weaponprevtime = time - (1 - f) * timein_effect_length;
614 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
616 f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
618 // fade the panel alpha
619 if(autocvar_hud_panel_weapons_timeout_effect == 1)
621 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
622 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
624 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
626 panel_bg_alpha *= (f);
627 panel_fg_alpha *= (f);
630 // move the panel back on screen
631 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
633 f *= f; // for a cooler movement
635 center.x = panel_pos.x + panel_size.x/2;
636 center.y = panel_pos.y + panel_size.y/2;
637 screen_ar = vid_conwidth/vid_conheight;
638 if (center.x/center.y < screen_ar) //bottom left
640 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
641 panel_pos.y += f * (vid_conheight - panel_pos.y);
643 panel_pos.x -= f * (panel_pos.x + panel_size.x);
647 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
648 panel_pos.x += f * (vid_conwidth - panel_pos.x);
650 panel_pos.y -= f * (panel_pos.y + panel_size.y);
656 // draw the background, then change the virtual size of it to better fit other items inside
667 panel_pos += '1 1 0' * panel_bg_padding;
668 panel_size -= '2 2 0' * panel_bg_padding;
671 // after the sizing and animations are done, update the other values
673 if(!rows) // if rows is > 0 onlyowned code has already updated these vars
675 rows = panel_size.y/panel_size.x;
676 rows = bound(1, floor((sqrt(4 * aspect * rows * weapon_count + rows * rows) + rows + 0.5) / 2), weapon_count);
677 columns = ceil(weapon_count/rows);
678 weapon_size = eX * panel_size.x*(1/columns) + eY * panel_size.y*(1/rows);
681 // calculate position/size for visual bar displaying ammount of ammo status
682 if (autocvar_hud_panel_weapons_ammo)
684 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
685 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
687 if(weapon_size.x/weapon_size.y > aspect)
689 barsize.x = aspect * weapon_size.y;
690 barsize.y = weapon_size.y;
691 baroffset.x = (weapon_size.x - barsize.x) / 2;
695 barsize.y = 1/aspect * weapon_size.x;
696 barsize.x = weapon_size.x;
697 baroffset.y = (weapon_size.y - barsize.y) / 2;
700 if(autocvar_hud_panel_weapons_accuracy)
701 Accuracy_LoadColors();
705 vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
706 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
708 // retrieve information about the current weapon to be drawn
709 self = weaponorder[i];
710 weapon_id = self.impulse;
712 // skip if this weapon doesn't exist
713 if(!self || weapon_id < 0) { continue; }
715 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
716 if(autocvar_hud_panel_weapons_onlyowned)
717 if (!((weapons_stat & WepSet_FromWeapon(self.weapon)) || (self.weapon == complain_weapon)))
720 // figure out the drawing position of weapon
721 weapon_pos = (panel_pos
722 + eX * column * weapon_size.x
723 + eY * row * weapon_size.y);
725 // draw background behind currently selected weapon
726 if(self.weapon == switchweapon)
727 drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
729 // draw the weapon accuracy
730 if(autocvar_hud_panel_weapons_accuracy)
732 panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
733 if(panel_weapon_accuracy >= 0)
735 color = Accuracy_GetColor(panel_weapon_accuracy);
736 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
740 // drawing all the weapon items
741 if(weapons_stat & WepSet_FromWeapon(self.weapon))
743 // draw the weapon image
744 drawpic_aspect_skin(weapon_pos, self.model2, weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
746 // draw weapon label string
747 switch(autocvar_hud_panel_weapons_label)
749 case 1: // weapon number
750 drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
754 drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
757 case 3: // weapon name
758 drawstring(weapon_pos, strtolower(self.message), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
765 // draw ammo status bar
766 if(autocvar_hud_panel_weapons_ammo && (self.ammo_field != ammo_none))
768 a = getstati(GetAmmoStat(self.ammo_field)); // how much ammo do we have?
772 switch(self.ammo_field)
774 case ammo_shells: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
775 case ammo_nails: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
776 case ammo_rockets: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
777 case ammo_cells: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
778 case ammo_plasma: ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma; break;
779 case ammo_fuel: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
780 default: ammo_full = 60;
784 weapon_pos.x + baroffset.x,
785 weapon_pos.y + baroffset.y,
786 barsize.x * bound(0, a/ammo_full, 1),
803 else // draw a "ghost weapon icon" if you don't have the weapon
805 drawpic_aspect_skin(weapon_pos, self.model2, weapon_size, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
808 // draw the complain message
809 if(self.weapon == complain_weapon)
812 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
814 a = ((complain_weapon_time + when > time) ? 1 : 0);
817 if(complain_weapon_type == 0) {
818 s = _("Out of ammo");
819 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
821 else if(complain_weapon_type == 1) {
823 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
826 s = _("Unavailable");
827 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
829 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
830 drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
831 drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
834 // continue with new position for the next weapon
847 void DrawNadeScoreBar(vector myPos, vector mySize, vector color)
850 HUD_Panel_DrawProgressBar(
851 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
852 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
853 autocvar_hud_panel_ammo_progressbar_name,
854 getstatf(STAT_NADE_BONUS_SCORE), 0, 0, color,
855 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
859 void DrawAmmoNades(vector myPos, vector mySize, float draw_expanding, float expand_time)
861 float theAlpha = 1, a, b;
862 vector nade_color, picpos, numpos;
864 nade_color = Nade_Color(getstati(STAT_NADE_BONUS_TYPE));
866 a = getstatf(STAT_NADE_BONUS);
867 b = getstatf(STAT_NADE_BONUS_SCORE);
869 if(autocvar_hud_panel_ammo_iconalign)
872 picpos = myPos + eX * 2 * mySize.y;
876 numpos = myPos + eX * mySize.y;
880 DrawNadeScoreBar(myPos, mySize, nade_color);
884 if(autocvar_hud_panel_ammo_text)
885 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
888 drawpic_aspect_skin_expanding(picpos, "nade_nbg", '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, expand_time);
890 drawpic_aspect_skin(picpos, "nade_bg" , '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
891 drawpic_aspect_skin(picpos, "nade_nbg" , '1 1 0' * mySize.y, nade_color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
895 void DrawAmmoItem(vector myPos, vector mySize, .float ammoType, float isCurrent, float isInfinite)
897 if(ammoType == ammo_none)
900 // Initialize variables
903 if(autocvar__hud_configure)
905 isCurrent = (ammoType == ammo_rockets); // Rockets always current
909 ammo = getstati(GetAmmoStat(ammoType));
913 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
914 myPos = myPos + (mySize - mySize * scale) * 0.5;
915 mySize = mySize * scale;
918 vector iconPos, textPos;
919 if(autocvar_hud_panel_ammo_iconalign)
921 iconPos = myPos + eX * 2 * mySize.y;
927 textPos = myPos + eX * mySize.y;
930 float isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
932 vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
935 textColor = '0.2 0.95 0';
939 textColor = '0.8 0.04 0';
945 alpha = panel_fg_alpha;
947 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
949 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
951 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
956 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
958 if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
959 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);
961 if(autocvar_hud_panel_ammo_text)
962 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
964 drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
967 float nade_prevstatus;
968 float nade_prevframe;
969 float nade_statuschange_time;
972 if(hud != HUD_NORMAL) return;
973 if(!autocvar__hud_configure)
975 if(!autocvar_hud_panel_ammo) return;
976 if(spectatee_status == -1) return;
979 HUD_Panel_UpdateCvars();
981 draw_beginBoldFont();
990 pos += '1 1 0' * panel_bg_padding;
991 mySize -= '2 2 0' * panel_bg_padding;
994 float rows = 0, columns, row, column;
995 float nade_cnt = getstatf(STAT_NADE_BONUS), nade_score = getstatf(STAT_NADE_BONUS_SCORE);
996 float draw_nades = (nade_cnt > 0 || nade_score > 0), nade_statuschange_elapsedtime;
997 float total_ammo_count;
1000 if (autocvar_hud_panel_ammo_onlycurrent)
1001 total_ammo_count = 1;
1003 total_ammo_count = AMMO_COUNT;
1008 if (nade_cnt != nade_prevframe)
1010 nade_statuschange_time = time;
1011 nade_prevstatus = nade_prevframe;
1012 nade_prevframe = nade_cnt;
1016 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
1018 rows = mySize.y/mySize.x;
1019 rows = bound(1, floor((sqrt(4 * (3/1) * rows * (total_ammo_count) + rows * rows) + rows + 0.5) / 2), (total_ammo_count));
1020 // ^^^ ammo item aspect goes here
1022 columns = ceil((total_ammo_count)/rows);
1024 ammo_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
1027 vector offset = '0 0 0'; // fteqcc sucks
1029 if(ammo_size.x/ammo_size.y > 3)
1031 newSize = 3 * ammo_size.y;
1032 offset.x = ammo_size.x - newSize;
1033 pos.x += offset.x/2;
1034 ammo_size.x = newSize;
1038 newSize = 1/3 * ammo_size.x;
1039 offset.y = ammo_size.y - newSize;
1040 pos.y += offset.y/2;
1041 ammo_size.y = newSize;
1045 float infinite_ammo = (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_WEAPON_AMMO);
1047 if(autocvar_hud_panel_ammo_onlycurrent)
1049 if(autocvar__hud_configure)
1051 DrawAmmoItem(pos, ammo_size, ammo_rockets, true, false);
1058 (get_weaponinfo(switchweapon)).ammo_field,
1068 column = column + 1;
1075 for(i = 0; i < AMMO_COUNT; ++i)
1077 ammotype = GetAmmoFieldFromNum(i);
1079 pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y),
1082 ((get_weaponinfo(switchweapon)).ammo_field == ammotype),
1090 column = column + 1;
1097 nade_statuschange_elapsedtime = time - nade_statuschange_time;
1099 float f = bound(0, nade_statuschange_elapsedtime*2, 1);
1101 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);
1107 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha, float fadelerp)
1109 vector newPos = '0 0 0', newSize = '0 0 0';
1110 vector picpos, numpos;
1114 if(mySize.y/mySize.x > 2)
1116 newSize.y = 2 * mySize.x;
1117 newSize.x = mySize.x;
1119 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
1124 newSize.x = 1/2 * mySize.y;
1125 newSize.y = mySize.y;
1127 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
1131 if(icon_right_align)
1134 picpos = newPos + eY * newSize.x;
1139 numpos = newPos + eY * newSize.x;
1143 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1144 // make number smaller than icon, it looks better
1145 // reduce only y to draw numbers with different number of digits with the same y size
1146 numpos.y += newSize.y * ((1 - 0.7) / 2);
1148 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
1152 if(mySize.x/mySize.y > 3)
1154 newSize.x = 3 * mySize.y;
1155 newSize.y = mySize.y;
1157 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
1162 newSize.y = 1/3 * mySize.x;
1163 newSize.x = mySize.x;
1165 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
1169 if(icon_right_align) // right align
1172 picpos = newPos + eX * 2 * newSize.y;
1176 numpos = newPos + eX * newSize.y;
1180 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
1181 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
1182 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1183 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
1186 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float theAlpha)
1188 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
1193 void HUD_Powerups(void)
1195 float strength_time, shield_time, superweapons_time;
1196 if(!autocvar__hud_configure)
1198 if(!autocvar_hud_panel_powerups) return;
1199 if(spectatee_status == -1) return;
1200 if(!(getstati(STAT_ITEMS, 0, 24) & (IT_STRENGTH | IT_INVINCIBLE | IT_SUPERWEAPON))) return;
1201 if (getstati(STAT_HEALTH) <= 0) return;
1203 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1204 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1205 superweapons_time = bound(0, getstatf(STAT_SUPERWEAPONS_FINISHED) - time, 99);
1207 if (getstati(STAT_ITEMS, 0, 24) & IT_UNLIMITED_SUPERWEAPONS)
1208 superweapons_time = 99; // force max
1210 // prevent stuff to show up on mismatch that will be fixed next frame
1211 if (!(getstati(STAT_ITEMS, 0, 24) & IT_SUPERWEAPON))
1212 superweapons_time = 0;
1218 superweapons_time = 13;
1221 HUD_Panel_UpdateCvars();
1223 draw_beginBoldFont();
1227 mySize = panel_size;
1229 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time, superweapons_time), 1));
1230 if(panel_bg_padding)
1232 pos += '1 1 0' * panel_bg_padding;
1233 mySize -= '2 2 0' * panel_bg_padding;
1236 float panel_ar = mySize.x/mySize.y;
1237 float is_vertical = (panel_ar < 1);
1238 vector shield_offset = '0 0 0', strength_offset = '0 0 0', superweapons_offset = '0 0 0';
1240 float superweapons_is = -1;
1242 if(superweapons_time)
1247 superweapons_is = 0;
1249 superweapons_is = 2;
1254 superweapons_is = 1;
1256 superweapons_is = 2;
1260 // FIXME handle superweapons here
1261 if(superweapons_is == 0)
1263 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1265 mySize.x *= (1.0 / 3.0);
1266 superweapons_offset.x = mySize.x;
1267 if (autocvar_hud_panel_powerups_flip)
1268 shield_offset.x = 2*mySize.x;
1270 strength_offset.x = 2*mySize.x;
1274 mySize.y *= (1.0 / 3.0);
1275 superweapons_offset.y = mySize.y;
1276 if (autocvar_hud_panel_powerups_flip)
1277 shield_offset.y = 2*mySize.y;
1279 strength_offset.y = 2*mySize.y;
1284 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1287 if (autocvar_hud_panel_powerups_flip)
1288 shield_offset.x = mySize.x;
1290 strength_offset.x = mySize.x;
1295 if (autocvar_hud_panel_powerups_flip)
1296 shield_offset.y = mySize.y;
1298 strength_offset.y = mySize.y;
1302 float shield_baralign, strength_baralign, superweapons_baralign;
1303 float shield_iconalign, strength_iconalign, superweapons_iconalign;
1305 if (autocvar_hud_panel_powerups_flip)
1307 strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1308 shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1309 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1310 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1314 shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1315 strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1316 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1317 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1320 if(superweapons_is == 0)
1322 superweapons_iconalign = strength_iconalign;
1323 superweapons_baralign = 2;
1325 else if(superweapons_is == 1)
1327 superweapons_offset = strength_offset;
1328 superweapons_iconalign = strength_iconalign;
1329 superweapons_baralign = strength_baralign;
1331 else // if(superweapons_is == 2)
1333 superweapons_offset = shield_offset;
1334 superweapons_iconalign = shield_iconalign;
1335 superweapons_baralign = shield_baralign;
1340 const float maxshield = 30;
1341 float shield = ceil(shield_time);
1342 if(autocvar_hud_panel_powerups_progressbar)
1343 HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, autocvar_hud_progressbar_shield_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1344 if(autocvar_hud_panel_powerups_text)
1347 DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
1349 DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1, bound(0, (shield - shield_time) / 0.5, 1));
1355 const float maxstrength = 30;
1356 float strength = ceil(strength_time);
1357 if(autocvar_hud_panel_powerups_progressbar)
1358 HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, autocvar_hud_progressbar_strength_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1359 if(autocvar_hud_panel_powerups_text)
1362 DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
1364 DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1, bound(0, (strength - strength_time) / 0.5, 1));
1368 if(superweapons_time)
1370 const float maxsuperweapons = 30;
1371 float superweapons = ceil(superweapons_time);
1372 if(autocvar_hud_panel_powerups_progressbar)
1373 HUD_Panel_DrawProgressBar(pos + superweapons_offset, mySize, autocvar_hud_panel_powerups_progressbar_superweapons, superweapons/maxsuperweapons, is_vertical, superweapons_baralign, autocvar_hud_progressbar_superweapons_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1374 if(autocvar_hud_panel_powerups_text)
1376 if(superweapons > 1)
1377 DrawNumIcon(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1);
1378 if(superweapons <= 5)
1379 DrawNumIcon_expanding(pos + superweapons_offset, mySize, superweapons, "superweapons", is_vertical, superweapons_iconalign, '1 1 1', 1, bound(0, (superweapons - superweapons_time) / 0.5, 1));
1386 // Health/armor (#3)
1389 // prev_* vars contain the health/armor at the previous FRAME
1390 // set to -1 when player is dead or was not playing
1391 float prev_health, prev_armor;
1392 float health_damagetime, armor_damagetime;
1393 float health_beforedamage, armor_beforedamage;
1394 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
1395 float old_p_health, old_p_armor;
1396 float old_p_healthtime, old_p_armortime;
1397 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
1398 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
1399 float prev_p_health, prev_p_armor;
1401 void HUD_HealthArmor(void)
1403 float armor, health, fuel;
1404 if(!autocvar__hud_configure)
1406 if(!autocvar_hud_panel_healtharmor) return;
1407 if(hud != HUD_NORMAL) return;
1408 if(spectatee_status == -1) return;
1410 health = getstati(STAT_HEALTH);
1416 armor = getstati(STAT_ARMOR);
1418 // code to check for spectatee_status changes is in Ent_ClientData()
1419 // prev_p_health and prev_health can be set to -1 there
1421 if (prev_p_health == -1)
1424 health_beforedamage = 0;
1425 armor_beforedamage = 0;
1426 health_damagetime = 0;
1427 armor_damagetime = 0;
1428 prev_health = health;
1430 old_p_health = health;
1431 old_p_armor = armor;
1432 prev_p_health = health;
1433 prev_p_armor = armor;
1435 else if (prev_health == -1)
1437 //start the load effect
1438 health_damagetime = 0;
1439 armor_damagetime = 0;
1443 fuel = getstati(STAT_FUEL);
1452 HUD_Panel_UpdateCvars();
1455 mySize = panel_size;
1457 HUD_Panel_DrawBg(1);
1458 if(panel_bg_padding)
1460 pos += '1 1 0' * panel_bg_padding;
1461 mySize -= '2 2 0' * panel_bg_padding;
1464 float baralign = autocvar_hud_panel_healtharmor_baralign;
1465 float iconalign = autocvar_hud_panel_healtharmor_iconalign;
1467 float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1468 float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1469 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1472 v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON);
1477 float maxtotal = maxhealth + maxarmor;
1479 if(v.z) // NOT fully armored
1481 biggercount = "health";
1482 if(autocvar_hud_panel_healtharmor_progressbar)
1483 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);
1485 if(autocvar_hud_panel_healtharmor_text)
1486 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);
1490 biggercount = "armor";
1491 if(autocvar_hud_panel_healtharmor_progressbar)
1492 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);
1494 if(autocvar_hud_panel_healtharmor_text)
1495 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);
1497 if(autocvar_hud_panel_healtharmor_text)
1498 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1501 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);
1505 float panel_ar = mySize.x/mySize.y;
1506 float is_vertical = (panel_ar < 1);
1507 vector health_offset = '0 0 0', armor_offset = '0 0 0';
1508 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1511 if (autocvar_hud_panel_healtharmor_flip)
1512 health_offset.x = mySize.x;
1514 armor_offset.x = mySize.x;
1519 if (autocvar_hud_panel_healtharmor_flip)
1520 health_offset.y = mySize.y;
1522 armor_offset.y = mySize.y;
1525 float health_baralign, armor_baralign, fuel_baralign;
1526 float health_iconalign, armor_iconalign;
1527 if (autocvar_hud_panel_healtharmor_flip)
1529 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1530 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1531 fuel_baralign = health_baralign;
1532 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1533 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1537 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1538 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1539 fuel_baralign = armor_baralign;
1540 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1541 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1546 if(autocvar_hud_panel_healtharmor_progressbar)
1548 float p_health, pain_health_alpha;
1550 pain_health_alpha = 1;
1551 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1553 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1555 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1557 if (time - old_p_healthtime < 1)
1558 old_p_health = prev_p_health;
1560 old_p_health = prev_health;
1561 old_p_healthtime = time;
1563 if (time - old_p_healthtime < 1)
1565 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1566 prev_p_health = p_health;
1569 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1571 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1573 if (time - health_damagetime >= 1)
1574 health_beforedamage = prev_health;
1575 health_damagetime = time;
1577 if (time - health_damagetime < 1)
1579 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1580 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);
1583 prev_health = health;
1585 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1587 float BLINK_FACTOR = 0.15;
1588 float BLINK_BASE = 0.85;
1589 float BLINK_FREQ = 9;
1590 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1593 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);
1595 if(autocvar_hud_panel_healtharmor_text)
1596 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1601 if(autocvar_hud_panel_healtharmor_progressbar)
1605 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1607 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1609 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1611 if (time - old_p_armortime < 1)
1612 old_p_armor = prev_p_armor;
1614 old_p_armor = prev_armor;
1615 old_p_armortime = time;
1617 if (time - old_p_armortime < 1)
1619 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1620 prev_p_armor = p_armor;
1623 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1625 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1627 if (time - armor_damagetime >= 1)
1628 armor_beforedamage = prev_armor;
1629 armor_damagetime = time;
1631 if (time - armor_damagetime < 1)
1633 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1634 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);
1639 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);
1641 if(autocvar_hud_panel_healtharmor_text)
1642 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1648 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1652 mySize.x *= 2; //restore full panel size
1653 else if (panel_ar < 1/4)
1654 mySize.y *= 2; //restore full panel size
1655 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1660 // Notification area (#4)
1663 void HUD_Notify_Push(string icon, string attacker, string victim)
1671 if (notify_index == -1)
1672 notify_index = NOTIFY_MAX_ENTRIES-1;
1675 if (notify_attackers[notify_index])
1676 strunzone(notify_attackers[notify_index]);
1678 if (notify_victims[notify_index])
1679 strunzone(notify_victims[notify_index]);
1681 if (notify_icons[notify_index])
1682 strunzone(notify_icons[notify_index]);
1684 // Allocate new strings
1687 notify_attackers[notify_index] = strzone(attacker);
1688 notify_victims[notify_index] = strzone(victim);
1692 // In case of a notification without a victim, the attacker
1693 // is displayed on the victim's side. Instead of special
1694 // treatment later on, we can simply switch them here.
1695 notify_attackers[notify_index] = string_null;
1696 notify_victims[notify_index] = strzone(attacker);
1699 notify_icons[notify_index] = strzone(icon);
1700 notify_times[notify_index] = time;
1703 void HUD_Notify(void)
1705 if (!autocvar__hud_configure)
1706 if (!autocvar_hud_panel_notify)
1709 HUD_Panel_UpdateCvars();
1710 HUD_Panel_DrawBg(1);
1712 if (!autocvar__hud_configure)
1713 if (notify_count == 0)
1720 if (panel_bg_padding)
1722 pos += '1 1 0' * panel_bg_padding;
1723 size -= '2 2 0' * panel_bg_padding;
1726 float fade_start = max(0, autocvar_hud_panel_notify_time);
1727 float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
1728 float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
1730 float entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size.y / size.x), NOTIFY_MAX_ENTRIES);
1731 float entry_height = size.y / entry_count;
1733 float panel_width_half = size.x * 0.5;
1734 float icon_width_half = entry_height * icon_aspect / 2;
1735 float name_maxwidth = panel_width_half - icon_width_half - size.x * NOTIFY_ICON_MARGIN;
1737 vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
1738 vector icon_size = (eX * icon_aspect + eY) * entry_height;
1739 vector icon_left = eX * (panel_width_half - icon_width_half);
1740 vector attacker_right = eX * name_maxwidth;
1741 vector victim_left = eX * (size.x - name_maxwidth);
1743 vector attacker_pos, victim_pos, icon_pos;
1744 string attacker, victim, icon;
1745 float i, j, count, step, limit, alpha;
1747 if (autocvar_hud_panel_notify_flip)
1749 // Order items from the top down
1752 limit = entry_count;
1756 // Order items from the bottom up
1757 i = entry_count - 1;
1762 for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
1764 if(autocvar__hud_configure)
1766 attacker = sprintf(_("Player %d"), count + 1);
1767 victim = sprintf(_("Player %d"), count + 2);
1768 icon = get_weaponinfo(min(WEP_FIRST + count * 2, WEP_LAST)).model2;
1769 alpha = bound(0, 1.2 - count / entry_count, 1);
1773 if (j == NOTIFY_MAX_ENTRIES)
1776 if (notify_times[j] + fade_start > time)
1778 else if (fade_time != 0)
1780 alpha = bound(0, (notify_times[j] + fade_start + fade_time - time) / fade_time, 1);
1787 attacker = notify_attackers[j];
1788 victim = notify_victims[j];
1789 icon = notify_icons[j];
1792 if (icon != "" && victim != "")
1794 vector name_top = eY * (i * entry_height + 0.5 * (entry_height - font_size.y));
1796 icon_pos = pos + icon_left + eY * i * entry_height;
1797 drawpic_aspect_skin(icon_pos, icon, icon_size, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1799 victim = textShortenToWidth(victim, name_maxwidth, font_size, stringwidth_colors);
1800 victim_pos = pos + victim_left + name_top;
1801 drawcolorcodedstring(victim_pos, victim, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1805 attacker = textShortenToWidth(attacker, name_maxwidth, font_size, stringwidth_colors);
1806 attacker_pos = pos + attacker_right - eX * stringwidth(attacker, true, font_size) + name_top;
1807 drawcolorcodedstring(attacker_pos, attacker, font_size, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1812 notify_count = count;
1818 string seconds_tostring(float sec)
1821 minutes = floor(sec / 60);
1823 sec -= minutes * 60;
1824 return sprintf("%d:%02d", minutes, sec);
1827 void HUD_Timer(void)
1829 if(!autocvar__hud_configure)
1831 if(!autocvar_hud_panel_timer) return;
1834 HUD_Panel_UpdateCvars();
1836 draw_beginBoldFont();
1840 mySize = panel_size;
1842 HUD_Panel_DrawBg(1);
1843 if(panel_bg_padding)
1845 pos += '1 1 0' * panel_bg_padding;
1846 mySize -= '2 2 0' * panel_bg_padding;
1850 float timelimit, elapsedTime, timeleft, minutesLeft;
1852 timelimit = getstatf(STAT_TIMELIMIT);
1854 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1855 timeleft = ceil(timeleft);
1857 minutesLeft = floor(timeleft / 60);
1860 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
1861 timer_color = '1 1 1'; //white
1862 else if(minutesLeft >= 1)
1863 timer_color = '1 1 0'; //yellow
1865 timer_color = '1 0 0'; //red
1867 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
1868 if (time < getstatf(STAT_GAMESTARTTIME)) {
1869 //while restart is still active, show 00:00
1870 timer = seconds_tostring(0);
1872 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
1873 timer = seconds_tostring(elapsedTime);
1876 timer = seconds_tostring(timeleft);
1879 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
1886 void HUD_Radar(void)
1888 if (!autocvar__hud_configure)
1890 if (hud_panel_radar_maximized)
1892 if (!hud_draw_maximized) return;
1896 if (autocvar_hud_panel_radar == 0) return;
1897 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
1898 if(radar_panel_modified)
1900 panel.update_time = time; // forces reload of panel attributes
1901 radar_panel_modified = false;
1906 HUD_Panel_UpdateCvars();
1910 if (hud_panel_radar_maximized && !autocvar__hud_configure)
1912 panel_size = autocvar_hud_panel_radar_maximized_size;
1913 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
1914 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
1915 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
1916 panel_pos.y = (vid_conheight - panel_size.y) / 2;
1919 panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
1920 if(precache_pic(panel_bg) == "")
1921 panel_bg = "gfx/hud/default/border_default"; // fallback
1922 if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
1923 radar_panel_modified = true;
1924 if(panel.current_panel_bg)
1925 strunzone(panel.current_panel_bg);
1926 panel.current_panel_bg = strzone(panel_bg);
1928 switch(hud_panel_radar_maximized_zoommode)
1932 f = current_zoomfraction;
1935 f = 1 - current_zoomfraction;
1945 switch(hud_panel_radar_maximized_rotation)
1948 teamradar_angle = view_angles.y - 90;
1951 teamradar_angle = 90 * hud_panel_radar_maximized_rotation;
1955 if (!hud_panel_radar_maximized && !autocvar__hud_configure)
1957 switch(hud_panel_radar_zoommode)
1961 f = current_zoomfraction;
1964 f = 1 - current_zoomfraction;
1974 switch(hud_panel_radar_rotation)
1977 teamradar_angle = view_angles.y - 90;
1980 teamradar_angle = 90 * hud_panel_radar_rotation;
1987 mySize = panel_size;
1989 HUD_Panel_DrawBg(1);
1990 if(panel_bg_padding)
1992 pos += '1 1 0' * panel_bg_padding;
1993 mySize -= '2 2 0' * panel_bg_padding;
1998 float scale2d, normalsize, bigsize;
2000 teamradar_origin2d = pos + 0.5 * mySize;
2001 teamradar_size2d = mySize;
2003 if(minimapname == "")
2006 teamradar_loadcvars();
2008 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2009 teamradar_size2d = mySize;
2011 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2013 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2014 if((hud_panel_radar_rotation == 0 && !hud_panel_radar_maximized) || (hud_panel_radar_maximized_rotation == 0 && hud_panel_radar_maximized))
2016 // max-min distance must fit the radar in any rotation
2017 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2021 vector c0, c1, c2, c3, span;
2022 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2023 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2024 c2 = rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
2025 c3 = rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
2027 span.x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
2028 span.y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
2030 // max-min distance must fit the radar in x=x, y=y
2032 teamradar_size2d.x * scale2d / (1.05 * span.x),
2033 teamradar_size2d.y * scale2d / (1.05 * span.y)
2037 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2038 if(bigsize > normalsize)
2039 normalsize = bigsize;
2043 + (1 - f) * normalsize;
2044 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2046 + (1 - f) * view_origin);
2055 draw_teamradar_background(hud_panel_radar_foreground_alpha);
2057 for(tm = world; (tm = find(tm, classname, "radarlink")); )
2058 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2059 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2060 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2061 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2063 color2 = GetPlayerColor(tm.sv_entnum);
2064 //if(color == NUM_SPECTATOR || color == color2)
2065 draw_teamradar_player(tm.origin, tm.angles, Team_ColorRGB(color2));
2067 draw_teamradar_player(view_origin, view_angles, '1 1 1');
2069 drawresetcliparea();
2074 void HUD_UpdatePlayerTeams();
2075 void HUD_Score_Rankings(vector pos, vector mySize, entity me)
2078 entity tm = world, pl;
2079 float SCOREPANEL_MAX_ENTRIES = 6;
2080 float SCOREPANEL_ASPECTRATIO = 2;
2081 float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize.y/mySize.x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2082 vector fontsize = '1 1 0' * (mySize.y/entries);
2084 vector rgb, score_color;
2086 score_color = '1 1 1';
2088 float name_size = mySize.x*0.75;
2089 float spacing_size = mySize.x*0.04;
2090 const float highlight_alpha = 0.2;
2091 float i = 0, me_printed = 0, first_pl = 0;
2093 if (autocvar__hud_configure)
2095 float players_per_team = 0;
2098 // show team scores in the first line
2099 float score_size = mySize.x / team_count;
2100 players_per_team = max(2, ceil((entries - 1) / team_count));
2101 for(i=0; i<team_count; ++i) {
2102 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2103 HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2104 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);
2107 pos.y += fontsize.y;
2109 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2110 for (i=first_pl; i<entries; ++i)
2112 //simulate my score is lower than all displayed players,
2113 //so that I don't appear at all showing pure rankings.
2114 //This is to better show the difference between the 2 ranking views
2115 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2118 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2119 s = GetPlayerName(player_localnum);
2124 s = sprintf(_("Player %d"), i + 1 - first_pl);
2129 score_color = Team_ColorRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2130 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2131 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2132 drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2133 pos.y += fontsize.y;
2138 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2139 HUD_UpdatePlayerTeams();
2142 // show team scores in the first line
2143 float score_size = mySize.x / team_count;
2144 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2145 if(tm.team == NUM_SPECTATOR)
2147 if (tm.team == myteam)
2148 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2149 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);
2153 pos.y += fontsize.y;
2154 tm = teams.sort_next;
2159 for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2161 if ((team_count && pl.team != tm.team) || pl.team == NUM_SPECTATOR)
2164 if (i == entries-1 && !me_printed && pl != me)
2165 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2167 for (pl = me.sort_next; pl; pl = pl.sort_next)
2168 if (pl.team != NUM_SPECTATOR)
2172 rgb = '1 1 0'; //not last but not among the leading players: yellow
2174 rgb = '1 0 0'; //last: red
2181 rgb = '0 1 0'; //first: green
2183 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2186 score_color = Team_ColorRGB(pl.team) * 0.8;
2187 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2188 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2189 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2190 pos.y += fontsize.y;
2193 while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != NUM_SPECTATOR || (tm = tm.sort_next)));
2196 void HUD_Score(void)
2198 if(!autocvar__hud_configure)
2200 if(!autocvar_hud_panel_score) return;
2201 if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2204 HUD_Panel_UpdateCvars();
2207 mySize = panel_size;
2209 HUD_Panel_DrawBg(1);
2210 if(panel_bg_padding)
2212 pos += '1 1 0' * panel_bg_padding;
2213 mySize -= '2 2 0' * panel_bg_padding;
2216 float score, distribution = 0;
2218 vector distribution_color;
2221 me = playerslots[player_localentnum - 1];
2223 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2224 string timer, distrtimer;
2226 pl = players.sort_next;
2229 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2230 if(pl.scores[ps_primary] == 0)
2233 score = me.(scores[ps_primary]);
2234 timer = TIME_ENCODED_TOSTRING(score);
2236 draw_beginBoldFont();
2237 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2238 // distribution display
2239 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2241 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2243 if (distribution <= 0) {
2244 distribution_color = '0 1 0';
2248 distribution_color = '1 0 0';
2251 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);
2253 // race record display
2254 if (distribution <= 0)
2255 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2256 drawstring_aspect(pos, timer, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2258 } else if (!teamplay) { // non-teamgames
2259 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2261 HUD_Score_Rankings(pos, mySize, me);
2264 // me vector := [team/connected frags id]
2265 pl = players.sort_next;
2269 if(autocvar__hud_configure)
2272 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2276 score = me.(scores[ps_primary]);
2277 if(autocvar__hud_configure)
2280 if(distribution >= 5)
2281 distribution_color = eY;
2282 else if(distribution >= 0)
2283 distribution_color = '1 1 1';
2284 else if(distribution >= -5)
2285 distribution_color = '1 1 0';
2287 distribution_color = eX;
2289 string distribution_str;
2290 distribution_str = ftos(distribution);
2291 draw_beginBoldFont();
2292 if (distribution >= 0)
2294 if (distribution > 0)
2295 distribution_str = strcat("+", distribution_str);
2296 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2298 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2299 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);
2301 } else { // teamgames
2302 float row, column, rows = 0, columns = 0;
2303 vector offset = '0 0 0';
2304 vector score_pos, score_size; //for scores other than myteam
2305 if(autocvar_hud_panel_score_rankings)
2307 HUD_Score_Rankings(pos, mySize, me);
2310 if(spectatee_status == -1)
2312 rows = mySize.y/mySize.x;
2313 rows = bound(1, floor((sqrt(4 * (3/1) * rows * team_count + rows * rows) + rows + 0.5) / 2), team_count);
2314 // ^^^ ammo item aspect goes here
2316 columns = ceil(team_count/rows);
2318 score_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
2321 if(score_size.x/score_size.y > 3)
2323 newSize = 3 * score_size.y;
2324 offset.x = score_size.x - newSize;
2325 pos.x += offset.x/2;
2326 score_size.x = newSize;
2330 newSize = 1/3 * score_size.x;
2331 offset.y = score_size.y - newSize;
2332 pos.y += offset.y/2;
2333 score_size.y = newSize;
2337 score_size = eX * mySize.x*(1/4) + eY * mySize.y*(1/3);
2339 float max_fragcount;
2340 max_fragcount = -99;
2341 draw_beginBoldFont();
2343 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2344 if(tm.team == NUM_SPECTATOR)
2346 score = tm.(teamscores[ts_primary]);
2347 if(autocvar__hud_configure)
2350 if (score > max_fragcount)
2351 max_fragcount = score;
2353 if (spectatee_status == -1)
2355 score_pos = pos + eX * column * (score_size.x + offset.x) + eY * row * (score_size.y + offset.y);
2356 if (max_fragcount == score)
2357 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2358 drawstring_aspect(score_pos, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2366 else if(tm.team == myteam) {
2367 if (max_fragcount == score)
2368 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2369 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2371 if (max_fragcount == score)
2372 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);
2373 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);
2383 void HUD_RaceTimer (void)
2385 if(!autocvar__hud_configure)
2387 if(!autocvar_hud_panel_racetimer) return;
2388 if(!(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
2389 if(spectatee_status == -1) return;
2392 HUD_Panel_UpdateCvars();
2394 draw_beginBoldFont();
2398 mySize = panel_size;
2400 HUD_Panel_DrawBg(1);
2401 if(panel_bg_padding)
2403 pos += '1 1 0' * panel_bg_padding;
2404 mySize -= '2 2 0' * panel_bg_padding;
2407 // always force 4:1 aspect
2408 vector newSize = '0 0 0';
2409 if(mySize.x/mySize.y > 4)
2411 newSize.x = 4 * mySize.y;
2412 newSize.y = mySize.y;
2414 pos.x = pos.x + (mySize.x - newSize.x) / 2;
2418 newSize.y = 1/4 * mySize.x;
2419 newSize.x = mySize.x;
2421 pos.y = pos.y + (mySize.y - newSize.y) / 2;
2426 string s, forcetime;
2428 if(autocvar__hud_configure)
2431 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);
2432 s = _("^1Intermediate 1 (+15.42)");
2433 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);
2434 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
2435 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);
2437 else if(race_checkpointtime)
2439 a = bound(0, 2 - (time - race_checkpointtime), 1);
2442 if(a > 0) // just hit a checkpoint?
2444 if(race_checkpoint != 254)
2446 if(race_time && race_previousbesttime)
2447 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2449 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2451 forcetime = TIME_ENCODED_TOSTRING(race_time);
2456 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2458 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2459 if(a > 0) // next one?
2461 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2466 if(s != "" && a > 0)
2468 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);
2471 if(race_penaltytime)
2473 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2476 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
2477 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);
2483 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2484 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);
2489 if(race_laptime && race_checkpoint != 255)
2491 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2492 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);
2497 if(race_mycheckpointtime)
2499 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2500 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -(race_mycheckpointenemy == ""), race_mycheckpointlapsdelta, race_mycheckpointenemy);
2501 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);
2503 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2505 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2506 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -(race_othercheckpointenemy == ""), race_othercheckpointlapsdelta, race_othercheckpointenemy);
2507 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);
2510 if(race_penaltytime && !race_penaltyaccumulator)
2512 t = race_penaltytime * 0.1 + race_penaltyeventtime;
2513 a = bound(0, (1 + t - time), 1);
2517 s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
2519 s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
2520 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);
2530 float vote_yescount;
2533 float vote_highlighted; // currently selected vote
2535 float vote_active; // is there an active vote?
2536 float vote_prev; // previous state of vote_active to check for a change
2538 float vote_change; // "time" when vote_active changed
2542 if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS)))
2545 if (autocvar__hud_configure)
2549 print(_("^1You must answer before entering hud configure mode\n"));
2550 cvar_set("_hud_configure", "0");
2552 if(vote_called_vote)
2553 strunzone(vote_called_vote);
2554 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
2555 uid2name_dialog = 1;
2558 if(!autocvar__hud_configure)
2560 if(!autocvar_hud_panel_vote) return;
2562 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
2563 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
2565 if(panel_bg_alpha_str == "") {
2566 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
2568 panel_bg_alpha = stof(panel_bg_alpha_str);
2579 if(vote_active != vote_prev) {
2581 vote_prev = vote_active;
2584 if(vote_active || autocvar__hud_configure)
2585 vote_alpha = bound(0, (time - vote_change) * 2, 1);
2587 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
2592 HUD_Panel_UpdateCvars();
2596 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
2597 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
2600 // these must be below above block
2603 mySize = panel_size;
2605 a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
2606 HUD_Panel_DrawBg(a);
2607 a = panel_fg_alpha * a;
2609 if(panel_bg_padding)
2611 pos += '1 1 0' * panel_bg_padding;
2612 mySize -= '2 2 0' * panel_bg_padding;
2615 // always force 3:1 aspect
2616 vector newSize = '0 0 0';
2617 if(mySize.x/mySize.y > 3)
2619 newSize.x = 3 * mySize.y;
2620 newSize.y = mySize.y;
2622 pos.x = pos.x + (mySize.x - newSize.x) / 2;
2626 newSize.y = 1/3 * mySize.x;
2627 newSize.x = mySize.x;
2629 pos.y = pos.y + (mySize.y - newSize.y) / 2;
2633 s = _("A vote has been called for:");
2635 s = _("Allow servers to store and display your name?");
2636 drawstring_aspect(pos, s, eX * mySize.x + eY * (2/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2637 s = textShortenToWidth(vote_called_vote, mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
2638 if(autocvar__hud_configure)
2639 s = _("^1Configure the HUD");
2640 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, eX * mySize.x + eY * (1.75/8) * mySize.y, a, DRAWFLAG_NORMAL);
2642 // print the yes/no counts
2643 s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
2644 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);
2645 s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
2646 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);
2648 // draw the progress bar backgrounds
2649 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_back", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2651 // draw the highlights
2652 if(vote_highlighted == 1) {
2653 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
2654 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2656 else if(vote_highlighted == -1) {
2657 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
2658 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2661 // draw the progress bars
2662 if(vote_yescount && vote_needed)
2664 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
2665 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2668 if(vote_nocount && vote_needed)
2670 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
2671 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
2674 drawresetcliparea();
2677 // Mod icons panel (#10)
2680 float mod_active; // is there any active mod icon?
2682 void DrawCAItem(vector myPos, vector mySize, float aspect_ratio, int layout, float i)
2686 vector color = '0 0 0';
2690 stat = getstati(STAT_REDALIVE);
2691 pic = "player_red.tga";
2695 stat = getstati(STAT_BLUEALIVE);
2696 pic = "player_blue.tga";
2700 stat = getstati(STAT_YELLOWALIVE);
2701 pic = "player_yellow.tga";
2706 stat = getstati(STAT_PINKALIVE);
2707 pic = "player_pink.tga";
2712 if(mySize.x/mySize.y > aspect_ratio)
2714 i = aspect_ratio * mySize.y;
2715 myPos.x = myPos.x + (mySize.x - i) / 2;
2720 i = 1/aspect_ratio * mySize.x;
2721 myPos.y = myPos.y + (mySize.y - i) / 2;
2727 drawpic_aspect_skin(myPos, pic, eX * 0.7 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2728 drawstring_aspect(myPos + eX * 0.7 * mySize.x, ftos(stat), eX * 0.3 * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
2731 drawstring_aspect(myPos, ftos(stat), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
2734 // Clan Arena and Freeze Tag HUD modicons
2735 void HUD_Mod_CA(vector myPos, vector mySize)
2737 mod_active = 1; // required in each mod function that always shows something
2740 if(gametype == MAPINFO_TYPE_CA)
2741 layout = autocvar_hud_panel_modicons_ca_layout;
2742 else //if(gametype == MAPINFO_TYPE_FREEZETAG)
2743 layout = autocvar_hud_panel_modicons_freezetag_layout;
2744 float rows, columns, aspect_ratio;
2745 rows = mySize.y/mySize.x;
2746 aspect_ratio = (layout) ? 2 : 1;
2747 rows = bound(1, floor((sqrt((4 * aspect_ratio * team_count + rows) * rows) + rows + 0.5) / 2), team_count);
2748 columns = ceil(team_count/rows);
2751 float row = 0, column = 0;
2752 vector pos, itemSize;
2753 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
2754 for(i=0; i<team_count; ++i)
2756 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
2758 DrawCAItem(pos, itemSize, aspect_ratio, layout, i);
2769 // CTF HUD modicon section
2770 float redflag_prevframe, blueflag_prevframe; // status during previous frame
2771 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
2772 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
2774 void HUD_Mod_CTF_Reset(void)
2776 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
2779 void HUD_Mod_CTF(vector pos, vector mySize)
2781 vector redflag_pos, blueflag_pos;
2783 float f; // every function should have that
2785 float redflag, blueflag; // current status
2786 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
2789 stat_items = getstati(STAT_ITEMS, 0, 24);
2790 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2791 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2793 if(redflag || blueflag)
2798 if(autocvar__hud_configure)
2804 // when status CHANGES, set old status into prevstatus and current status into status
2805 if (redflag != redflag_prevframe)
2807 redflag_statuschange_time = time;
2808 redflag_prevstatus = redflag_prevframe;
2809 redflag_prevframe = redflag;
2812 if (blueflag != blueflag_prevframe)
2814 blueflag_statuschange_time = time;
2815 blueflag_prevstatus = blueflag_prevframe;
2816 blueflag_prevframe = blueflag;
2819 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
2820 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
2822 float BLINK_FACTOR = 0.15;
2823 float BLINK_BASE = 0.85;
2825 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
2827 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
2829 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
2831 string red_icon, red_icon_prevstatus;
2832 float red_alpha, red_alpha_prevstatus;
2833 red_alpha = red_alpha_prevstatus = 1;
2835 case 1: red_icon = "flag_red_taken"; break;
2836 case 2: red_icon = "flag_red_lost"; break;
2837 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2839 if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_2))
2840 red_icon = "flag_red_shielded";
2842 red_icon = string_null;
2845 switch(redflag_prevstatus) {
2846 case 1: red_icon_prevstatus = "flag_red_taken"; break;
2847 case 2: red_icon_prevstatus = "flag_red_lost"; break;
2848 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2851 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
2852 else if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_2))
2853 red_icon_prevstatus = "flag_red_shielded";
2855 red_icon_prevstatus = string_null;
2859 string blue_icon, blue_icon_prevstatus;
2860 float blue_alpha, blue_alpha_prevstatus;
2861 blue_alpha = blue_alpha_prevstatus = 1;
2863 case 1: blue_icon = "flag_blue_taken"; break;
2864 case 2: blue_icon = "flag_blue_lost"; break;
2865 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2867 if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_1))
2868 blue_icon = "flag_blue_shielded";
2870 blue_icon = string_null;
2873 switch(blueflag_prevstatus) {
2874 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
2875 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
2876 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
2879 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
2880 else if((stat_items & IT_CTF_SHIELDED) && (myteam == NUM_TEAM_1))
2881 blue_icon_prevstatus = "flag_blue_shielded";
2883 blue_icon_prevstatus = string_null;
2887 if(mySize.x > mySize.y) {
2888 if (myteam == NUM_TEAM_1) { // always draw own flag on left
2890 blueflag_pos = pos + eX * 0.5 * mySize.x;
2893 redflag_pos = pos + eX * 0.5 * mySize.x;
2895 flag_size = eX * 0.5 * mySize.x + eY * mySize.y;
2897 if (myteam == NUM_TEAM_1) { // always draw own flag on left
2899 blueflag_pos = pos + eY * 0.5 * mySize.y;
2902 redflag_pos = pos + eY * 0.5 * mySize.y;
2904 flag_size = eY * 0.5 * mySize.y + eX * mySize.x;
2907 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
2908 if(red_icon_prevstatus && f < 1)
2909 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2911 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
2913 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
2914 if(blue_icon_prevstatus && f < 1)
2915 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
2917 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
2920 // Keyhunt HUD modicon section
2923 void HUD_Mod_KH(vector pos, vector mySize)
2925 mod_active = 1; // keyhunt should never hide the mod icons panel
2927 // Read current state
2929 float state = getstati(STAT_KH_KEYS);
2931 float all_keys, team1_keys, team2_keys, team3_keys, team4_keys, dropped_keys, carrying_keys;
2932 all_keys = team1_keys = team2_keys = team3_keys = team4_keys = dropped_keys = carrying_keys = 0;
2934 for(i = 0; i < 4; ++i)
2936 key_state = (bitshift(state, i * -5) & 31) - 1;
2949 case NUM_TEAM_1: ++team1_keys; break;
2950 case NUM_TEAM_2: ++team2_keys; break;
2951 case NUM_TEAM_3: ++team3_keys; break;
2952 case NUM_TEAM_4: ++team4_keys; break;
2953 case 29: ++dropped_keys; break;
2959 // Calculate slot measurements
2963 if(all_keys == 4 && mySize.x * 0.5 < mySize.y && mySize.y * 0.5 < mySize.x)
2965 // Quadratic arrangement
2966 slot_size = eX * mySize.x * 0.5 + eY * mySize.y * 0.5;
2968 KH_SLOTS[1] = pos + eX * slot_size.x;
2969 KH_SLOTS[2] = pos + eY * slot_size.y;
2970 KH_SLOTS[3] = pos + eX * slot_size.x + eY * slot_size.y;
2974 if(mySize.x > mySize.y)
2976 // Horizontal arrangement
2977 slot_size = eX * mySize.x / all_keys + eY * mySize.y;
2978 for(i = 0; i < all_keys; ++i)
2979 KH_SLOTS[i] = pos + eX * slot_size.x * i;
2983 // Vertical arrangement
2984 slot_size = eX * mySize.x + eY * mySize.y / all_keys;
2985 for(i = 0; i < all_keys; ++i)
2986 KH_SLOTS[i] = pos + eY * slot_size.y * i;
2990 // Make icons blink in case of RUN HERE
2992 float blink = 0.6 + sin(2*M_PI*time) / 2.5; // Oscillate between 0.2 and 1
2999 case NUM_TEAM_1: if(team1_keys == all_keys) alpha = blink; break;
3000 case NUM_TEAM_2: if(team2_keys == all_keys) alpha = blink; break;
3001 case NUM_TEAM_3: if(team3_keys == all_keys) alpha = blink; break;
3002 case NUM_TEAM_4: if(team4_keys == all_keys) alpha = blink; break;
3010 if(myteam == NUM_TEAM_1 && carrying_keys)
3012 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3016 drawpic_aspect_skin(KH_SLOTS[i++], "kh_red_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3019 if(myteam == NUM_TEAM_2 && carrying_keys)
3021 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3025 drawpic_aspect_skin(KH_SLOTS[i++], "kh_blue_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3028 if(myteam == NUM_TEAM_3 && carrying_keys)
3030 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3034 drawpic_aspect_skin(KH_SLOTS[i++], "kh_yellow_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3037 if(myteam == NUM_TEAM_4 && carrying_keys)
3039 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_carrying", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3043 drawpic_aspect_skin(KH_SLOTS[i++], "kh_pink_taken", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3045 while(dropped_keys--)
3046 drawpic_aspect_skin(KH_SLOTS[i++], "kh_dropped", slot_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
3049 // Keepaway HUD mod icon
3050 float kaball_prevstatus; // last remembered status
3051 float kaball_statuschange_time; // time when the status changed
3053 // we don't need to reset for keepaway since it immediately
3054 // autocorrects prevstatus as to if the player has the ball or not
3056 void HUD_Mod_Keepaway(vector pos, vector mySize)
3058 mod_active = 1; // keepaway should always show the mod HUD
3060 float BLINK_FACTOR = 0.15;
3061 float BLINK_BASE = 0.85;
3062 float BLINK_FREQ = 5;
3063 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
3065 float stat_items = getstati(STAT_ITEMS, 0, 24);
3066 float kaball = (stat_items/IT_KEY1) & 1;
3068 if(kaball != kaball_prevstatus)
3070 kaball_statuschange_time = time;
3071 kaball_prevstatus = kaball;
3074 vector kaball_pos, kaball_size;
3076 if(mySize.x > mySize.y) {
3077 kaball_pos = pos + eX * 0.25 * mySize.x;
3078 kaball_size = eX * 0.5 * mySize.x + eY * mySize.y;
3080 kaball_pos = pos + eY * 0.25 * mySize.y;
3081 kaball_size = eY * 0.5 * mySize.y + eX * mySize.x;
3084 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
3085 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
3087 if(kaball_prevstatus && f < 1)
3088 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
3091 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
3095 // Nexball HUD mod icon
3096 void HUD_Mod_NexBall(vector pos, vector mySize)
3098 float stat_items, nb_pb_starttime, dt, p;
3100 stat_items = getstati(STAT_ITEMS, 0, 24);
3101 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3103 if (stat_items & IT_KEY1)
3108 //Manage the progress bar if any
3109 if (nb_pb_starttime > 0)
3111 dt = (time - nb_pb_starttime) % nb_pb_period;
3112 // one period of positive triangle
3113 p = 2 * dt / nb_pb_period;
3117 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);
3120 if (stat_items & IT_KEY1)
3121 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3124 // Race/CTS HUD mod icons
3125 float crecordtime_prev; // last remembered crecordtime
3126 float crecordtime_change_time; // time when crecordtime last changed
3127 float srecordtime_prev; // last remembered srecordtime
3128 float srecordtime_change_time; // time when srecordtime last changed
3130 float race_status_time;
3131 float race_status_prev;
3132 string race_status_name_prev;
3133 void HUD_Mod_Race(vector pos, vector mySize)
3135 mod_active = 1; // race should never hide the mod icons panel
3137 me = playerslots[player_localnum];
3139 float f; // yet another function has this
3140 score = me.(scores[ps_primary]);
3142 if(!(scores_flags[ps_primary] & SFL_TIME) || teamplay) // race/cts record display on HUD
3143 return; // no records in the actual race
3145 // clientside personal record
3147 if(gametype == MAPINFO_TYPE_CTS)
3151 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3153 if(score && (score < t || !t)) {
3154 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3155 if(autocvar_cl_autodemo_delete_keeprecords)
3157 f = autocvar_cl_autodemo_delete;
3159 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3163 if(t != crecordtime_prev) {
3164 crecordtime_prev = t;
3165 crecordtime_change_time = time;
3168 vector textPos, medalPos;
3170 if(mySize.x > mySize.y) {
3171 // text on left side
3172 squareSize = min(mySize.y, mySize.x/2);
3173 textPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eY * 0.5 * (mySize.y - squareSize);
3174 medalPos = pos + eX * 0.5 * max(0, mySize.x/2 - squareSize) + eX * 0.5 * mySize.x + eY * 0.5 * (mySize.y - squareSize);
3177 squareSize = min(mySize.x, mySize.y/2);
3178 textPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eX * 0.5 * (mySize.x - squareSize);
3179 medalPos = pos + eY * 0.5 * max(0, mySize.y/2 - squareSize) + eY * 0.5 * mySize.y + eX * 0.5 * (mySize.x - squareSize);
3182 f = time - crecordtime_change_time;
3185 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3186 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);
3188 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3189 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);
3190 drawstring_aspect_expanding(pos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3191 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);
3195 t = race_server_record;
3196 if(t != srecordtime_prev) {
3197 srecordtime_prev = t;
3198 srecordtime_change_time = time;
3200 f = time - srecordtime_change_time;
3203 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3204 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);
3206 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3207 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);
3208 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);
3209 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);
3212 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3213 race_status_time = time + 5;
3214 race_status_prev = race_status;
3215 if (race_status_name_prev)
3216 strunzone(race_status_name_prev);
3217 race_status_name_prev = strzone(race_status_name);
3222 a = bound(0, race_status_time - time, 1);
3225 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
3229 rank = race_CheckName(race_status_name);
3233 rankname = count_ordinal(rank);
3236 namepos = medalPos + '0 0.8 0' * squareSize;
3238 rankpos = medalPos + '0 0.15 0' * squareSize;
3240 if(race_status == 0)
3241 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3242 else if(race_status == 1) {
3243 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);
3244 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3245 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3246 } else if(race_status == 2) {
3247 if(race_status_name == GetPlayerName(player_localnum) || !race_myrank || race_myrank < rank)
3248 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);
3250 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);
3251 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3252 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3253 } else if(race_status == 3) {
3254 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);
3255 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3256 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3259 if (race_status_time - time <= 0) {
3260 race_status_prev = -1;
3262 if(race_status_name)
3263 strunzone(race_status_name);
3264 race_status_name = string_null;
3265 if(race_status_name_prev)
3266 strunzone(race_status_name_prev);
3267 race_status_name_prev = string_null;
3271 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, float i)
3275 vector color = '0 0 0';
3279 stat = getstatf(STAT_DOM_PPS_RED);
3280 pic = "dom_icon_red";
3284 stat = getstatf(STAT_DOM_PPS_BLUE);
3285 pic = "dom_icon_blue";
3289 stat = getstatf(STAT_DOM_PPS_YELLOW);
3290 pic = "dom_icon_yellow";
3295 stat = getstatf(STAT_DOM_PPS_PINK);
3296 pic = "dom_icon_pink";
3300 float pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
3302 if(mySize.x/mySize.y > aspect_ratio)
3304 i = aspect_ratio * mySize.y;
3305 myPos.x = myPos.x + (mySize.x - i) / 2;
3310 i = 1/aspect_ratio * mySize.x;
3311 myPos.y = myPos.y + (mySize.y - i) / 2;
3315 if (layout) // show text too
3318 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
3319 if (layout == 2) // average pps
3320 drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), eX * (2/3) * mySize.x + eY * mySize.y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3321 else // percentage of average pps
3322 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);
3326 drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3329 drawsetcliparea(myPos.x, myPos.y + mySize.y * (1 - pps_ratio), mySize.y, mySize.y * pps_ratio);
3330 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3331 drawresetcliparea();
3335 void HUD_Mod_Dom(vector myPos, vector mySize)
3337 mod_active = 1; // required in each mod function that always shows something
3339 int layout = autocvar_hud_panel_modicons_dom_layout;
3340 float rows, columns, aspect_ratio;
3341 rows = mySize.y/mySize.x;
3342 aspect_ratio = (layout) ? 3 : 1;
3343 rows = bound(1, floor((sqrt((4 * aspect_ratio * team_count + rows) * rows) + rows + 0.5) / 2), team_count);
3344 columns = ceil(team_count/rows);
3347 float row = 0, column = 0;
3348 vector pos, itemSize;
3349 itemSize = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
3350 for(i=0; i<team_count; ++i)
3352 pos = myPos + eX * column * itemSize.x + eY * row * itemSize.y;
3354 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
3365 void HUD_ModIcons_SetFunc()
3369 case MAPINFO_TYPE_KEYHUNT: HUD_ModIcons_GameType = HUD_Mod_KH; break;
3370 case MAPINFO_TYPE_CTF: HUD_ModIcons_GameType = HUD_Mod_CTF; break;
3371 case MAPINFO_TYPE_NEXBALL: HUD_ModIcons_GameType = HUD_Mod_NexBall; break;
3372 case MAPINFO_TYPE_CTS:
3373 case MAPINFO_TYPE_RACE: HUD_ModIcons_GameType = HUD_Mod_Race; break;
3374 case MAPINFO_TYPE_CA:
3375 case MAPINFO_TYPE_FREEZETAG: HUD_ModIcons_GameType = HUD_Mod_CA; break;
3376 case MAPINFO_TYPE_DOMINATION: HUD_ModIcons_GameType = HUD_Mod_Dom; break;
3377 case MAPINFO_TYPE_KEEPAWAY: HUD_ModIcons_GameType = HUD_Mod_Keepaway; break;
3381 float mod_prev; // previous state of mod_active to check for a change
3383 float mod_change; // "time" when mod_active changed
3385 void HUD_ModIcons(void)
3387 if(!autocvar__hud_configure)
3389 if(!autocvar_hud_panel_modicons) return;
3390 if(!HUD_ModIcons_GameType) return;
3393 HUD_Panel_UpdateCvars();
3395 draw_beginBoldFont();
3397 if(mod_active != mod_prev) {
3399 mod_prev = mod_active;
3402 if(mod_active || autocvar__hud_configure)
3403 mod_alpha = bound(0, (time - mod_change) * 2, 1);
3405 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
3408 HUD_Panel_DrawBg(mod_alpha);
3410 if(panel_bg_padding)
3412 panel_pos += '1 1 0' * panel_bg_padding;
3413 panel_size -= '2 2 0' * panel_bg_padding;
3416 if(autocvar__hud_configure)
3417 HUD_Mod_CTF(panel_pos, panel_size);
3419 HUD_ModIcons_GameType(panel_pos, panel_size);
3424 // Draw pressed keys (#11)
3426 void HUD_PressedKeys(void)
3428 if(!autocvar__hud_configure)
3430 if(!autocvar_hud_panel_pressedkeys) return;
3431 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
3434 HUD_Panel_UpdateCvars();
3437 mySize = panel_size;
3439 HUD_Panel_DrawBg(1);
3440 if(panel_bg_padding)
3442 pos += '1 1 0' * panel_bg_padding;
3443 mySize -= '2 2 0' * panel_bg_padding;
3446 // force custom aspect
3447 float aspect = autocvar_hud_panel_pressedkeys_aspect;
3450 vector newSize = '0 0 0';
3451 if(mySize.x/mySize.y > aspect)
3453 newSize.x = aspect * mySize.y;
3454 newSize.y = mySize.y;
3456 pos.x = pos.x + (mySize.x - newSize.x) / 2;
3460 newSize.y = 1/aspect * mySize.x;
3461 newSize.x = mySize.x;
3463 pos.y = pos.y + (mySize.y - newSize.y) / 2;
3469 keysize = eX * mySize.x * (1/3.0) + eY * mySize.y * (1/(3.0 - !autocvar_hud_panel_pressedkeys_attack));
3471 pressedkeys = getstatf(STAT_PRESSED_KEYS);
3473 if(autocvar_hud_panel_pressedkeys_attack)
3475 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);
3476 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);
3480 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3481 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);
3482 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);
3484 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3485 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);
3486 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);
3489 // Handle chat as a panel (#12)
3493 if(!autocvar__hud_configure)
3495 if (!autocvar_hud_panel_chat)
3497 if (!autocvar_con_chatrect)
3498 cvar_set("con_chatrect", "0");
3501 if(autocvar__con_chat_maximized)
3503 if(!hud_draw_maximized) return;
3505 else if(chat_panel_modified)
3507 panel.update_time = time; // forces reload of panel attributes
3508 chat_panel_modified = false;
3512 HUD_Panel_UpdateCvars();
3514 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
3516 panel_pos.y = panel_bg_border;
3517 panel_size.y = vid_conheight - panel_bg_border * 2;
3518 if(panel.current_panel_bg == "0") // force a border when maximized
3521 panel_bg = strcat(hud_skin_path, "/border_default");
3522 if(precache_pic(panel_bg) == "")
3523 panel_bg = "gfx/hud/default/border_default";
3524 if(panel.current_panel_bg)
3525 strunzone(panel.current_panel_bg);
3526 panel.current_panel_bg = strzone(panel_bg);
3527 chat_panel_modified = true;
3529 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an theAlpha of at least 0.75
3534 mySize = panel_size;
3536 HUD_Panel_DrawBg(1);
3538 if(panel_bg_padding)
3540 pos += '1 1 0' * panel_bg_padding;
3541 mySize -= '2 2 0' * panel_bg_padding;
3544 if (!autocvar_con_chatrect)
3545 cvar_set("con_chatrect", "1");
3547 cvar_set("con_chatrect_x", ftos(pos.x/vid_conwidth));
3548 cvar_set("con_chatrect_y", ftos(pos.y/vid_conheight));
3550 cvar_set("con_chatwidth", ftos(mySize.x/vid_conwidth));
3551 cvar_set("con_chat", ftos(floor(mySize.y/autocvar_con_chatsize - 0.5)));
3553 if(autocvar__hud_configure)
3556 chatsize = '1 1 0' * autocvar_con_chatsize;
3557 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over theAlpha and such
3559 for(i = 0; i < autocvar_con_chat; ++i)
3561 if(i == autocvar_con_chat - 1)
3564 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
3565 drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize.x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
3566 pos.y += chatsize.y;
3571 // Engine info panel (#13)
3578 float frametimeavg1; // 1 frame ago
3579 float frametimeavg2; // 2 frames ago
3580 void HUD_EngineInfo(void)
3582 if(!autocvar__hud_configure)
3584 if(!autocvar_hud_panel_engineinfo) return;
3587 HUD_Panel_UpdateCvars();
3590 mySize = panel_size;
3592 HUD_Panel_DrawBg(1);
3593 if(panel_bg_padding)
3595 pos += '1 1 0' * panel_bg_padding;
3596 mySize -= '2 2 0' * panel_bg_padding;
3599 float currentTime = gettime(GETTIME_REALTIME);
3600 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
3602 float currentframetime = currentTime - prevfps_time;
3603 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
3604 frametimeavg2 = frametimeavg1;
3605 frametimeavg1 = frametimeavg;
3608 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
3609 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.
3611 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
3612 prevfps = (1/currentframetime);
3613 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"
3615 prevfps_time = currentTime;
3620 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
3622 prevfps = framecounter/(currentTime - prevfps_time);
3624 prevfps_time = currentTime;
3629 color = HUD_Get_Num_Color (prevfps, 100);
3630 drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3633 // Info messages panel (#14)
3635 #define drawInfoMessage(s) do { \
3636 if(autocvar_hud_panel_infomessages_flip) \
3637 o.x = pos.x + mySize.x - stringwidth(s, true, fontsize); \
3638 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL); \
3639 o.y += fontsize.y; \
3641 void HUD_InfoMessages(void)
3643 if(!autocvar__hud_configure)
3645 if(!autocvar_hud_panel_infomessages) return;
3648 HUD_Panel_UpdateCvars();
3651 mySize = panel_size;
3653 HUD_Panel_DrawBg(1);
3654 if(panel_bg_padding)
3656 pos += '1 1 0' * panel_bg_padding;
3657 mySize -= '2 2 0' * panel_bg_padding;
3660 // always force 5:1 aspect
3661 vector newSize = '0 0 0';
3662 if(mySize.x/mySize.y > 5)
3664 newSize.x = 5 * mySize.y;
3665 newSize.y = mySize.y;
3667 pos.x = pos.x + (mySize.x - newSize.x) / 2;
3671 newSize.y = 1/5 * mySize.x;
3672 newSize.x = mySize.x;
3674 pos.y = pos.y + (mySize.y - newSize.y) / 2;
3683 fontsize = '0.20 0.20 0' * mySize.y;
3689 if(!autocvar__hud_configure)
3691 if(spectatee_status && !intermission)
3694 if(spectatee_status == -1)
3695 s = _("^1Observing");
3697 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(player_localentnum - 1));
3700 if(spectatee_status == -1)
3701 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
3703 s = sprintf(_("^1Press ^3%s^1 or ^3%s^1 for next or previous player"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
3706 if(spectatee_status == -1)
3707 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
3709 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
3712 s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
3715 if(gametype == MAPINFO_TYPE_LMS)
3718 sk = playerslots[player_localnum];
3719 if(sk.(scores[ps_primary]) >= 666)
3720 s = _("^1Match has already begun");
3721 else if(sk.(scores[ps_primary]) > 0)
3722 s = _("^1You have no more lives left");
3724 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
3727 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
3730 //show restart countdown:
3731 if (time < getstatf(STAT_GAMESTARTTIME)) {
3733 //we need to ceil, otherwise the countdown would be off by .5 when using round()
3734 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
3735 s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
3736 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
3740 if(warmup_stage && !intermission)
3742 s = _("^2Currently in ^1warmup^2 stage!");
3752 if(ready_waiting && !intermission && !spectatee_status)
3754 if(ready_waiting_for_me)
3757 s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
3759 s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
3764 s = _("^2Waiting for others to ready up to end warmup...");
3766 s = _("^2Waiting for others to ready up...");
3770 else if(warmup_stage && !intermission && !spectatee_status)
3772 s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
3776 if(teamplay && !intermission && !spectatee_status && gametype != MAPINFO_TYPE_CA && teamnagger)
3778 float ts_min = 0, ts_max = 0;
3779 tm = teams.sort_next;
3782 for (; tm.sort_next; tm = tm.sort_next)
3784 if(!tm.team_size || tm.team == NUM_SPECTATOR)
3786 if(!ts_min) ts_min = tm.team_size;
3787 else ts_min = min(ts_min, tm.team_size);
3788 if(!ts_max) ts_max = tm.team_size;
3789 else ts_max = max(ts_max, tm.team_size);
3791 if ((ts_max - ts_min) > 1)
3793 s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
3794 tm = GetTeam(myteam, false);
3796 if (tm.team != NUM_SPECTATOR)
3797 if (tm.team_size == ts_max)
3798 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
3806 s = _("^7Press ^3ESC ^7to show HUD options.");
3808 s = _("^3Doubleclick ^7a panel for panel-specific options.");
3810 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
3812 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
3817 // Physics panel (#15)
3819 vector acc_prevspeed;
3820 float acc_prevtime, acc_avg, top_speed, top_speed_time;
3821 void HUD_Physics(void)
3823 if(!autocvar__hud_configure)
3825 if(!autocvar_hud_panel_physics) return;
3826 if(spectatee_status == -1 && (autocvar_hud_panel_physics == 1 || autocvar_hud_panel_physics == 3)) return;
3827 if(autocvar_hud_panel_physics == 3 && !(gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
3830 HUD_Panel_UpdateCvars();
3832 draw_beginBoldFont();
3834 HUD_Panel_DrawBg(1);
3835 if(panel_bg_padding)
3837 panel_pos += '1 1 0' * panel_bg_padding;
3838 panel_size -= '2 2 0' * panel_bg_padding;
3841 float acceleration_progressbar_scale = 0;
3842 if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1)
3843 acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
3846 if (autocvar_hud_panel_physics_text_scale <= 0)
3849 text_scale = min(autocvar_hud_panel_physics_text_scale, 1);
3852 float speed, conversion_factor;
3855 switch(autocvar_hud_panel_physics_speed_unit)
3860 conversion_factor = 1.0;
3864 conversion_factor = 0.0254;
3868 conversion_factor = 0.0254 * 3.6;
3872 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
3876 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
3880 vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel);
3882 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
3883 if (autocvar__hud_configure)
3884 speed = floor( max_speed * 0.65 + 0.5 );
3885 else if(autocvar_hud_panel_physics_speed_vertical)
3886 speed = floor( vlen(vel) * conversion_factor + 0.5 );
3888 speed = floor( vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5 );
3890 //compute acceleration
3891 float acceleration, f;
3892 if (autocvar__hud_configure)
3893 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
3896 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
3897 f = time - acc_prevtime;
3898 if(autocvar_hud_panel_physics_acceleration_vertical)
3899 acceleration = (vlen(vel) - vlen(acc_prevspeed));
3901 acceleration = (vlen(vel - '0 0 1' * vel.z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed.z));
3903 acceleration = acceleration * (1 / max(0.0001, f)) * (0.0254 / 9.80665);
3905 acc_prevspeed = vel;
3906 acc_prevtime = time;
3908 f = bound(0, f * 10, 1);
3909 acc_avg = acc_avg * (1 - f) + acceleration * f;
3913 float panel_ar = panel_size.x/panel_size.y;
3914 vector speed_offset = '0 0 0', acceleration_offset = '0 0 0';
3915 if (panel_ar >= 5 && !acceleration_progressbar_scale)
3917 panel_size.x *= 0.5;
3918 if (autocvar_hud_panel_physics_flip)
3919 speed_offset.x = panel_size.x;
3921 acceleration_offset.x = panel_size.x;
3925 panel_size.y *= 0.5;
3926 if (autocvar_hud_panel_physics_flip)
3927 speed_offset.y = panel_size.y;
3929 acceleration_offset.y = panel_size.y;
3931 float speed_baralign, acceleration_baralign;
3932 if (autocvar_hud_panel_physics_baralign == 1)
3933 acceleration_baralign = speed_baralign = 1;
3934 else if(autocvar_hud_panel_physics_baralign == 4)
3935 acceleration_baralign = speed_baralign = 2;
3936 else if (autocvar_hud_panel_physics_flip)
3938 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
3939 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
3943 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
3944 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
3946 if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
3947 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
3951 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
3952 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);
3953 vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
3954 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
3956 tmp_size.x = panel_size.x * 0.75;
3957 tmp_size.y = panel_size.y * text_scale;
3959 tmp_offset.x = panel_size.x - tmp_size.x;
3962 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
3963 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3969 tmp_offset.x = tmp_size.x;
3970 if (autocvar_hud_panel_physics_speed_unit_show)
3973 tmp_size.x = panel_size.x * (1 - 0.75);
3974 tmp_size.y = panel_size.y * 0.4 * text_scale;
3975 tmp_offset.y = (panel_size.y * 0.4 - tmp_size.y) / 2;
3976 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3980 //compute and draw top speed
3981 if (autocvar_hud_panel_physics_topspeed)
3982 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
3984 if (autocvar__hud_configure)
3986 top_speed = floor( max_speed * 0.75 + 0.5 );
3991 if (speed >= top_speed)
3994 top_speed_time = time;
3998 f = max(1, autocvar_hud_panel_physics_topspeed_time);
3999 // divide by f to make it start from 1
4000 f = cos( ((time - top_speed_time) / f) * PI/2 );
4002 else //hide top speed 0, it would be stupid
4007 //top speed progressbar peak
4008 if(speed < top_speed)
4009 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4012 vector peak_size = '0 0 0';
4013 if (speed_baralign == 0)
4014 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x;
4015 else if (speed_baralign == 1)
4016 peak_offsetX = (1 - min(top_speed, max_speed)/max_speed) * panel_size.x;
4017 else // if (speed_baralign == 2)
4018 peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x * 0.5;
4019 peak_size.x = floor(panel_size.x * 0.01 + 1.5);
4020 peak_size.y = panel_size.y;
4021 if (speed_baralign == 2) // draw two peaks, on both sides
4023 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);
4024 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);
4027 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);
4031 tmp_offset.y = panel_size.y * 0.4;
4032 tmp_size.x = panel_size.x * (1 - 0.75);
4033 tmp_size.y = (panel_size.y - tmp_offset.y) * text_scale;
4034 tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2;
4035 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
4043 if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
4045 vector progressbar_color;
4046 if(acceleration < 0)
4047 progressbar_color = autocvar_hud_progressbar_acceleration_neg_color;
4049 progressbar_color = autocvar_hud_progressbar_acceleration_color;
4051 f = acceleration/autocvar_hud_panel_physics_acceleration_max;
4052 if (autocvar_hud_panel_physics_acceleration_progressbar_nonlinear)
4055 if (acceleration_progressbar_scale) // allow progressbar to go out of panel bounds
4057 tmp_size = acceleration_progressbar_scale * panel_size.x * eX + panel_size.y * eY;
4059 if (acceleration_baralign == 1)
4060 tmp_offset.x = panel_size.x - tmp_size.x;
4061 else if (acceleration_baralign == 2 || acceleration_baralign == 3)
4062 tmp_offset.x = (panel_size.x - tmp_size.x) / 2;
4069 tmp_size = panel_size;
4070 tmp_offset = '0 0 0';
4073 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);
4075 tmp_size.x = panel_size.x;
4076 tmp_size.y = panel_size.y * text_scale;
4078 tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
4079 if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
4080 drawstring_aspect(panel_pos + acceleration_offset + tmp_offset, strcat(ftos_decimals(acceleration, 2), "g"), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4085 // CenterPrint (#16)
4087 const float CENTERPRINT_MAX_MSGS = 10;
4088 const float CENTERPRINT_MAX_ENTRIES = 50;
4089 const float CENTERPRINT_SPACING = 0.7;
4091 string centerprint_messages[CENTERPRINT_MAX_MSGS];
4092 float centerprint_msgID[CENTERPRINT_MAX_MSGS];
4093 float centerprint_time[CENTERPRINT_MAX_MSGS];
4094 float centerprint_expire_time[CENTERPRINT_MAX_MSGS];
4095 float centerprint_countdown_num[CENTERPRINT_MAX_MSGS];
4096 float centerprint_showing;
4098 void centerprint_generic(float new_id, string strMessage, float duration, float countdown_num)
4100 //printf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num);
4103 if(strMessage == "" && new_id == 0)
4106 // strip trailing newlines
4107 j = strlen(strMessage) - 1;
4108 while(substring(strMessage, j, 1) == "\n" && j >= 0)
4110 if (j < strlen(strMessage) - 1)
4111 strMessage = substring(strMessage, 0, j + 1);
4113 if(strMessage == "" && new_id == 0)
4116 // strip leading newlines
4118 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
4121 strMessage = substring(strMessage, j, strlen(strMessage) - j);
4123 if(strMessage == "" && new_id == 0)
4126 if (!centerprint_showing)
4127 centerprint_showing = true;
4129 for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4131 if (j == CENTERPRINT_MAX_MSGS)
4133 if (new_id && new_id == centerprint_msgID[j])
4135 if (strMessage == "" && centerprint_messages[j] != "" && centerprint_countdown_num[j] == 0)
4137 // fade out the current msg (duration and countdown_num are ignored)
4138 centerprint_time[j] = min(5, autocvar_hud_panel_centerprint_fade_out);
4139 if (centerprint_expire_time[j] > time + min(5, autocvar_hud_panel_centerprint_fade_out) || centerprint_expire_time[j] < time)
4140 centerprint_expire_time[j] = time + min(5, autocvar_hud_panel_centerprint_fade_out);
4143 break; // found a msg with the same id, at position j
4147 if (i == CENTERPRINT_MAX_MSGS)
4149 // a msg with the same id was not found, add the msg at the next position
4151 if (cpm_index == -1)
4152 cpm_index = CENTERPRINT_MAX_MSGS - 1;
4155 if(centerprint_messages[j])
4156 strunzone(centerprint_messages[j]);
4157 centerprint_messages[j] = strzone(strMessage);
4158 centerprint_msgID[j] = new_id;
4161 centerprint_time[j] = -1;
4162 centerprint_expire_time[j] = time;
4167 duration = max(1, autocvar_hud_panel_centerprint_time);
4168 centerprint_time[j] = duration;
4169 centerprint_expire_time[j] = time + duration;
4171 centerprint_countdown_num[j] = countdown_num;
4174 void centerprint_hud(string strMessage)
4176 centerprint_generic(0, strMessage, autocvar_hud_panel_centerprint_time, 0);
4179 void reset_centerprint_messages(void)
4182 for (i=0; i<CENTERPRINT_MAX_MSGS; ++i)
4184 centerprint_expire_time[i] = 0;
4185 centerprint_time[i] = 1;
4186 centerprint_msgID[i] = 0;
4187 if(centerprint_messages[i])
4188 strunzone(centerprint_messages[i]);
4189 centerprint_messages[i] = string_null;
4192 float hud_configure_cp_generation_time;
4193 void HUD_CenterPrint (void)
4195 if(!autocvar__hud_configure)
4197 if(!autocvar_hud_panel_centerprint) return;
4199 if (hud_configure_prev && hud_configure_prev != -1)
4200 reset_centerprint_messages();
4204 if (!hud_configure_prev)
4205 reset_centerprint_messages();
4206 if (time > hud_configure_cp_generation_time)
4211 centerprint_generic(floor(r*1000), strcat(sprintf("^3Countdown message at time %s", seconds_tostring(time)), ", seconds left: ^COUNT"), 1, 10);
4213 centerprint_generic(0, sprintf("^1Multiline message at time %s that\n^1lasts longer than normal", seconds_tostring(time)), 20, 0);
4215 centerprint_hud(sprintf("Message at time %s", seconds_tostring(time)));
4216 hud_configure_cp_generation_time = time + 1 + random()*4;
4220 // this panel fades only when the menu does
4221 float hud_fade_alpha_save = 0;
4222 if(scoreboard_fade_alpha)
4224 hud_fade_alpha_save = hud_fade_alpha;
4225 hud_fade_alpha = 1 - autocvar__menu_alpha;
4227 HUD_Panel_UpdateCvars();
4229 if(scoreboard_fade_alpha)
4231 hud_fade_alpha = hud_fade_alpha_save;
4233 // move the panel below the scoreboard
4234 if (scoreboard_bottom >= 0.96 * vid_conheight)
4238 target_pos = eY * scoreboard_bottom + eX * 0.5 * (vid_conwidth - panel_size.x);
4240 if(target_pos.y > panel_pos.y)
4242 panel_pos = panel_pos + (target_pos - panel_pos) * sqrt(scoreboard_fade_alpha);
4243 panel_size.y = min(panel_size.y, vid_conheight - scoreboard_bottom);
4247 HUD_Panel_DrawBg(1);
4249 if (!centerprint_showing)
4252 if(panel_bg_padding)
4254 panel_pos += '1 1 0' * panel_bg_padding;
4255 panel_size -= '2 2 0' * panel_bg_padding;
4258 float entries, height;
4260 // entries = bound(1, floor(CENTERPRINT_MAX_ENTRIES * 4 * panel_size_y/panel_size_x), CENTERPRINT_MAX_ENTRIES);
4261 // height = panel_size_y/entries;
4262 // fontsize = '1 1 0' * height;
4263 height = vid_conheight/50 * autocvar_hud_panel_centerprint_fontscale;
4264 fontsize = '1 1 0' * height;
4265 entries = bound(1, floor(panel_size.y/height), CENTERPRINT_MAX_ENTRIES);
4267 float i, j, k, n, g;
4268 float a, sz, align, current_msg_posY = 0, msg_size;
4271 float all_messages_expired = true;
4274 if (autocvar_hud_panel_centerprint_flip)
4275 pos.y += panel_size.y;
4276 align = bound(0, autocvar_hud_panel_centerprint_align, 1);
4277 for (g=0, i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
4279 if (j == CENTERPRINT_MAX_MSGS)
4281 if (centerprint_expire_time[j] <= time)
4283 if (centerprint_countdown_num[j] && centerprint_time[j] > 0)
4285 centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1;
4286 if (centerprint_countdown_num[j] == 0)
4288 centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
4290 else if(centerprint_time[j] != -1)
4294 all_messages_expired = false;
4296 // fade the centerprint_hud in/out
4297 if(centerprint_time[j] < 0) // Expired but forced. Expire time is the fade-in time.
4298 a = (time - centerprint_expire_time[j]) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4299 else if(centerprint_expire_time[j] - autocvar_hud_panel_centerprint_fade_out > time) // Regularily printed. Not fading out yet.
4300 a = (time - (centerprint_expire_time[j] - centerprint_time[j])) / max(0.0001, autocvar_hud_panel_centerprint_fade_in);
4301 else // Expiring soon, so fade it out.
4302 a = (centerprint_expire_time[j] - time) / max(0.0001, autocvar_hud_panel_centerprint_fade_out);
4304 // while counting down show it anyway in order to hold the current message position
4305 if (a <= 0.5/255.0 && centerprint_countdown_num[j] == 0) // Guaranteed invisible - don't show.
4310 // set the size from fading in/out before subsequent fading
4311 sz = autocvar_hud_panel_centerprint_fade_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_minfontsize);
4313 // also fade it based on positioning
4314 if(autocvar_hud_panel_centerprint_fade_subsequent)
4316 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
4317 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
4319 a *= panel_fg_alpha;
4321 // finally set the size based on the new theAlpha from subsequent fading
4322 sz = sz * (autocvar_hud_panel_centerprint_fade_subsequent_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_subsequent_minfontsize));
4323 drawfontscale = sz * '1 1 0';
4325 if (centerprint_countdown_num[j])
4326 n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_messages[j]), "\n");
4328 n = tokenizebyseparator(centerprint_messages[j], "\n");
4330 if (autocvar_hud_panel_centerprint_flip)
4332 // check if the message can be entirely shown
4333 for(k = 0; k < n; ++k)
4335 getWrappedLine_remaining = argv(k);
4336 while(getWrappedLine_remaining)
4338 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4340 pos.y -= fontsize.y;
4342 pos.y -= fontsize.y * CENTERPRINT_SPACING/2;
4345 current_msg_posY = pos.y; // save starting pos (first line) of the current message
4349 for(k = 0; k < n; ++k)
4351 getWrappedLine_remaining = argv(k);
4352 while(getWrappedLine_remaining)
4354 ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
4358 pos.x = panel_pos.x + (panel_size.x - stringwidth(ts, true, fontsize)) * align;
4359 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.
4360 drawcolorcodedstring(pos + eY * 0.5 * (1 - sz) * fontsize.y, ts, fontsize, a, DRAWFLAG_NORMAL);
4361 pos.y += fontsize.y;
4364 pos.y += fontsize.y * CENTERPRINT_SPACING/2;
4368 ++g; // move next position number up
4370 msg_size = pos.y - msg_size;
4371 if (autocvar_hud_panel_centerprint_flip)
4373 pos.y = current_msg_posY - CENTERPRINT_SPACING * fontsize.y;
4374 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
4375 pos.y += (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4377 if (pos.y < panel_pos.y) // check if the next message can be shown
4379 drawfontscale = '1 1 0';
4385 pos.y += CENTERPRINT_SPACING * fontsize.y;
4386 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
4387 pos.y -= (msg_size + CENTERPRINT_SPACING * fontsize.y) * (1 - sqrt(sz));
4389 if(pos.y > panel_pos.y + panel_size.y - fontsize.y) // check if the next message can be shown
4391 drawfontscale = '1 1 0';
4396 drawfontscale = '1 1 0';
4397 if (all_messages_expired)
4399 centerprint_showing = false;
4400 reset_centerprint_messages();
4406 void HUD_Buffs(void)
4408 float buffs = getstati(STAT_BUFFS, 0, 24);
4409 if(!autocvar__hud_configure)
4411 if(!autocvar_hud_panel_buffs) return;
4412 if(spectatee_status == -1) return;
4413 if(getstati(STAT_HEALTH) <= 0) return;
4418 buffs = Buff_Type_first.items; // force first buff
4421 float b = 0; // counter to tell other functions that we have buffs
4424 for(e = Buff_Type_first; e; e = e.enemy) if(buffs & e.items)
4427 string o = strcat(rgb_to_hexcolor(Buff_Color(e.items)), Buff_PrettyName(e.items));
4431 s = strcat(s, " ", o);
4434 HUD_Panel_UpdateCvars();
4436 draw_beginBoldFont();
4440 mySize = panel_size;
4442 HUD_Panel_DrawBg(bound(0, b, 1));
4443 if(panel_bg_padding)
4445 pos += '1 1 0' * panel_bg_padding;
4446 mySize -= '2 2 0' * panel_bg_padding;
4449 //float panel_ar = mySize_x/mySize_y;
4450 //float is_vertical = (panel_ar < 1);
4451 //float buff_iconalign = autocvar_hud_panel_buffs_iconalign;
4452 vector buff_offset = '0 0 0';
4454 for(e = Buff_Type_first; e; e = e.enemy) if(buffs & e.items)
4456 //DrawNumIcon(pos + buff_offset, mySize, shield, "shield", is_vertical, buff_iconalign, '1 1 1', 1);
4457 drawcolorcodedstring_aspect(pos + buff_offset, s, mySize, panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
4465 // QUICKMENU_MAXLINES must be <= 10
4466 #define QUICKMENU_MAXLINES 10
4467 #define QUICKMENU_MAXENTRIES 256
4468 string QuickMenu_Command[QUICKMENU_MAXLINES];
4469 string QuickMenu_Description[QUICKMENU_MAXLINES];
4470 float QuickMenu_CurrentPage;
4471 float QuickMenu_IsLastPage;
4472 // each quickmenu entry (submenu or command) is composed of 2 entries in the buffer
4473 #define QUICKMENU_BUFFER_MAXENTRIES 2*QUICKMENU_MAXENTRIES
4474 var float QuickMenu_Buffer = -1;
4475 float QuickMenu_Buffer_Size;
4476 float QuickMenu_Buffer_Index;
4477 string QuickMenu_CurrentSubMenu;
4478 float QuickMenu_CurrentPage_FirstEntry;
4479 var float QuickMenu_Entries;
4480 float QuickMenu_TimeOut;
4481 // if s1 is not empty s will be displayed as command otherwise as submenu
4482 void HUD_QuickMenu_load_entry(float i, string s, string s1)
4484 //printf("^xc80 entry %d: %s, %s\n", i, s, s1);
4485 if (QuickMenu_Description[i])
4486 strunzone(QuickMenu_Description[i]);
4487 QuickMenu_Description[i] = strzone(s);
4488 if (QuickMenu_Command[i])
4489 strunzone(QuickMenu_Command[i]);
4490 QuickMenu_Command[i] = strzone(s1);
4492 void HUD_QuickMenu_clear_entry(float i)
4494 if (QuickMenu_Description[i])
4495 strunzone(QuickMenu_Description[i]);
4496 QuickMenu_Description[i] = string_null;
4497 if (QuickMenu_Command[i])
4498 strunzone(QuickMenu_Command[i]);
4499 QuickMenu_Command[i] = string_null;
4502 float HUD_QuickMenu_Page(string target_submenu, float new_page);
4503 void HUD_QuickMenu_Default(string submenu);
4504 float HUD_QuickMenu_Open(string mode, string submenu)
4511 if(autocvar_hud_panel_quickmenu_file == "" || autocvar_hud_panel_quickmenu_file == "0")
4517 if(mode == "default")
4519 QuickMenu_Buffer = buf_create();
4520 if(QuickMenu_Buffer < 0)
4523 HUD_QuickMenu_Default(submenu);
4525 else if(mode == "file")
4527 if(autocvar_hud_panel_quickmenu_file != "")
4528 if(autocvar_hud_panel_quickmenu_file != "0")
4529 fh = fopen(autocvar_hud_panel_quickmenu_file, FILE_READ);
4532 printf("Couldn't open file \"%s\"\n", autocvar_hud_panel_quickmenu_file);
4536 QuickMenu_Buffer = buf_create();
4537 if(QuickMenu_Buffer < 0)
4543 QuickMenu_Buffer_Size = 0;
4544 while((s = fgets(fh)) && QuickMenu_Buffer_Size < QUICKMENU_BUFFER_MAXENTRIES)
4546 // first skip invalid entries, so we don't check them anymore
4548 argc = tokenize_console(s);
4549 if(argc == 0 || argv(0) == "" || substring(argv(0), 0, 2) == "////")
4552 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("S", argv(0))); // Submenu
4557 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("T", argv(0))); // command Title
4558 ++QuickMenu_Buffer_Size;
4559 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("C", argv(1))); // command
4563 // check for special keywords
4564 float teamplayers = 0, without_me = 0;
4567 case "ALLPLAYERS_BUT_ME": without_me = 1;
4568 case "ALLPLAYERS": teamplayers = 0; break;
4569 case "OWNTEAMPLAYERS_BUT_ME": without_me = 1;
4570 case "OWNTEAMPLAYERS": teamplayers = 1; break;
4571 case "ENEMYTEAMPLAYERS": teamplayers = 2; break;
4575 if(QuickMenu_Buffer_Size + 3 < QUICKMENU_BUFFER_MAXENTRIES)
4577 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("S", argv(0))); // Submenu
4578 ++QuickMenu_Buffer_Size;
4579 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("T", ftos(teamplayers), ftos(without_me))); // command arguments
4580 ++QuickMenu_Buffer_Size;
4581 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("P", argv(1))); // command for each player
4582 ++QuickMenu_Buffer_Size;
4583 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("S", argv(0))); // Submenu
4586 ++QuickMenu_Buffer_Size;
4592 printf("Unrecognized mode %s\n", mode);
4596 if (QuickMenu_Buffer_Size <= 0)
4598 buf_del(QuickMenu_Buffer);
4599 QuickMenu_Buffer = -1;
4604 HUD_QuickMenu_Page(submenu, 0);
4606 HUD_QuickMenu_Page("", 0);
4608 hud_panel_quickmenu = 1;
4609 if(autocvar_hud_cursormode)
4613 QuickMenu_TimeOut = time + autocvar_hud_panel_quickmenu_time;
4617 void HUD_QuickMenu_Buffer_Close()
4619 if (QuickMenu_Buffer >= 0)
4621 buf_del(QuickMenu_Buffer);
4622 QuickMenu_Buffer = -1;
4623 QuickMenu_Buffer_Size = 0;
4627 void HUD_QuickMenu_Close()
4629 if (QuickMenu_CurrentSubMenu)
4630 strunzone(QuickMenu_CurrentSubMenu);
4631 QuickMenu_CurrentSubMenu = string_null;
4633 for (i = 0; i < QUICKMENU_MAXLINES; ++i)
4634 HUD_QuickMenu_clear_entry(i);
4635 QuickMenu_Entries = 0;
4636 hud_panel_quickmenu = 0;
4638 prevMouseClicked = 0;
4639 HUD_QuickMenu_Buffer_Close();
4641 if(autocvar_hud_cursormode)
4646 // It assumes submenu open tag is already detected
4647 void HUD_QuickMenu_skip_submenu(string submenu)
4649 string s, z_submenu;
4650 z_submenu = strzone(submenu);
4651 for(++QuickMenu_Buffer_Index ; QuickMenu_Buffer_Index < QuickMenu_Buffer_Size; ++QuickMenu_Buffer_Index)
4653 s = bufstr_get(QuickMenu_Buffer, QuickMenu_Buffer_Index);
4654 if(substring(s, 0, 1) != "S")
4656 if(substring(s, 1, -1) == z_submenu) // submenu end
4658 HUD_QuickMenu_skip_submenu(substring(s, 1, -1));
4660 strunzone(z_submenu);
4663 float HUD_QuickMenu_IsOpened()
4665 return (QuickMenu_Entries > 0);
4668 void HUD_Quickmenu_PlayerListEntries(string cmd, float teamplayers, float without_me);
4669 float HUD_Quickmenu_PlayerListEntries_Create(string cmd, float teamplayers, float without_me)
4672 for(i = 0; i < QUICKMENU_MAXLINES; ++i)
4673 HUD_QuickMenu_clear_entry(i);
4674 HUD_QuickMenu_Buffer_Close();
4676 QuickMenu_Buffer = buf_create();
4677 if(QuickMenu_Buffer < 0)
4680 HUD_Quickmenu_PlayerListEntries(cmd, teamplayers, without_me);
4682 if(QuickMenu_Buffer_Size <= 0)
4684 buf_del(QuickMenu_Buffer);
4685 QuickMenu_Buffer = -1;
4691 // new_page 0 means page 0, new_page != 0 means next page
4692 float QuickMenu_Buffer_Index_Prev;
4693 float HUD_QuickMenu_Page(string target_submenu, float new_page)
4695 string s = string_null, cmd = string_null, z_submenu;
4698 QuickMenu_CurrentPage = 0;
4700 ++QuickMenu_CurrentPage;
4701 QuickMenu_CurrentPage_FirstEntry = QuickMenu_CurrentPage * (QUICKMENU_MAXLINES - 2);
4703 z_submenu = strzone(target_submenu);
4704 if (QuickMenu_CurrentSubMenu)
4705 strunzone(QuickMenu_CurrentSubMenu);
4706 QuickMenu_CurrentSubMenu = strzone(z_submenu);
4708 QuickMenu_IsLastPage = TRUE;
4709 QuickMenu_Entries = 0;
4711 QuickMenu_Buffer_Index = 0;
4712 if (z_submenu != "")
4714 // skip everything until the submenu open tag is found
4715 for( ; QuickMenu_Buffer_Index < QuickMenu_Buffer_Size; ++QuickMenu_Buffer_Index)
4717 s = bufstr_get(QuickMenu_Buffer, QuickMenu_Buffer_Index);
4718 if(substring(s, 0, 1) == "S" && substring(s, 1, -1) == z_submenu)
4720 // printf("^3 beginning of %s\n", z_submenu);
4721 ++QuickMenu_Buffer_Index;
4724 // printf("^1 skipping %s\n", s);
4726 if(QuickMenu_Buffer_Index == QuickMenu_Buffer_Size)
4727 printf("Couldn't find submenu \"%s\"\n", z_submenu);
4729 float entry_num = 0;
4730 for( ; QuickMenu_Buffer_Index < QuickMenu_Buffer_Size; ++QuickMenu_Buffer_Index)
4732 s = bufstr_get(QuickMenu_Buffer, QuickMenu_Buffer_Index);
4734 if(z_submenu != "" && substring(s, 1, -1) == z_submenu)
4736 // printf("^3 end of %s\n", z_submenu);
4740 if(entry_num >= QuickMenu_CurrentPage_FirstEntry)
4742 ++QuickMenu_Entries;
4743 if(QuickMenu_Entries == QUICKMENU_MAXLINES - 2)
4744 QuickMenu_Buffer_Index_Prev = QuickMenu_Buffer_Index;
4745 else if(QuickMenu_Entries == QUICKMENU_MAXLINES)
4747 HUD_QuickMenu_clear_entry(QUICKMENU_MAXLINES - 1);
4748 QuickMenu_Buffer_Index = QuickMenu_Buffer_Index_Prev;
4749 QuickMenu_IsLastPage = FALSE;
4754 // NOTE: entries are loaded starting from 1, not from 0
4755 if(substring(s, 0, 1) == "S") // submenu
4757 if(entry_num >= QuickMenu_CurrentPage_FirstEntry)
4758 HUD_QuickMenu_load_entry(QuickMenu_Entries, substring(s, 1, -1), "");
4759 HUD_QuickMenu_skip_submenu(substring(s, 1, -1));
4761 else if(entry_num >= QuickMenu_CurrentPage_FirstEntry && substring(s, 0, 1) == "T")
4763 ++QuickMenu_Buffer_Index;
4764 cmd = bufstr_get(QuickMenu_Buffer, QuickMenu_Buffer_Index);
4765 string command_code = substring(cmd, 0, 1);
4766 if(command_code == "C")
4767 cmd = substring(cmd, 1, -1);
4768 else if(command_code == "P")
4770 cmd = substring(cmd, 1, -1);
4771 strunzone(z_submenu);
4772 if(HUD_Quickmenu_PlayerListEntries_Create(cmd, stof(substring(s, 1, 1)), stof(substring(s, 2, 1))))
4773 return HUD_QuickMenu_Page("", 0);
4774 HUD_QuickMenu_Close();
4777 HUD_QuickMenu_load_entry(QuickMenu_Entries, substring(s, 1, -1), cmd);
4782 strunzone(z_submenu);
4783 if (QuickMenu_Entries == 0)
4785 HUD_QuickMenu_Close();
4788 QuickMenu_TimeOut = time + autocvar_hud_panel_quickmenu_time;
4792 float HUD_QuickMenu_ActionForNumber(float num)
4794 if (!QuickMenu_IsLastPage)
4796 if (num < 0 || num >= QUICKMENU_MAXLINES)
4798 if (num == QUICKMENU_MAXLINES - 1)
4802 HUD_QuickMenu_Page(QuickMenu_CurrentSubMenu, +1);
4805 } else if (num <= 0 || num > QuickMenu_Entries)
4808 if (QuickMenu_Command[num] != "")
4810 localcmd(strcat("\n", QuickMenu_Command[num], "\n"));
4813 if (QuickMenu_Description[num] != "")
4814 HUD_QuickMenu_Page(QuickMenu_Description[num], 0);
4818 float HUD_QuickMenu_InputEvent(float bInputType, float nPrimary, float nSecondary)
4820 // we only care for keyboard events
4824 if(!HUD_QuickMenu_IsOpened() || autocvar__hud_configure || mv_active)
4829 mousepos_x = nPrimary;
4830 mousepos_y = nSecondary;
4834 // allow console bind to work
4837 con_keys = findkeysforcommand("toggleconsole", 0);
4838 keys = tokenize(con_keys); // findkeysforcommand returns data for this
4840 float hit_con_bind = 0, i;
4841 for (i = 0; i < keys; ++i)
4843 if(nPrimary == stof(argv(i)))
4847 if(bInputType == 0) {
4848 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
4849 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
4850 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
4852 else if(bInputType == 1) {
4853 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
4854 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
4855 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
4858 if(nPrimary == K_ESCAPE)
4860 if (bInputType == 1)
4862 HUD_QuickMenu_Close();
4864 else if(nPrimary >= '0' && nPrimary <= '9')
4866 if (bInputType == 1)
4868 HUD_QuickMenu_ActionForNumber(stof(chr2str(nPrimary)));
4870 if(nPrimary == K_MOUSE1)
4872 if(bInputType == 0) // key pressed
4873 mouseClicked |= S_MOUSE1;
4874 else if(bInputType == 1) // key released
4875 mouseClicked -= (mouseClicked & S_MOUSE1);
4877 else if(nPrimary == K_MOUSE2)
4879 if(bInputType == 0) // key pressed
4880 mouseClicked |= S_MOUSE2;
4881 else if(bInputType == 1) // key released
4882 mouseClicked -= (mouseClicked & S_MOUSE2);
4884 else if(hit_con_bind)
4889 void HUD_QuickMenu_Mouse()
4891 if(mv_active) return;
4894 if(prevMouseClicked & S_MOUSE2)
4896 HUD_QuickMenu_Close();
4900 if(!autocvar_hud_cursormode)
4902 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
4904 mousepos_x = bound(0, mousepos_x, vid_conwidth);
4905 mousepos_y = bound(0, mousepos_y, vid_conheight);
4908 HUD_Panel_UpdateCvars()
4910 if(panel_bg_padding)
4912 panel_pos += '1 1 0' * panel_bg_padding;
4913 panel_size -= '2 2 0' * panel_bg_padding;
4916 float first_entry_pos, entries_height;
4918 fontsize = '1 1 0' * (panel_size_y / QUICKMENU_MAXLINES);
4919 first_entry_pos = panel_pos_y + ((QUICKMENU_MAXLINES - QuickMenu_Entries) * fontsize_y) / 2;
4920 entries_height = panel_size_y - ((QUICKMENU_MAXLINES - QuickMenu_Entries) * fontsize_y);
4922 if (mousepos_x >= panel_pos_x && mousepos_y >= first_entry_pos && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= first_entry_pos + entries_height)
4925 entry_num = floor((mousepos_y - first_entry_pos) / fontsize_y);
4926 if (QuickMenu_IsLastPage || entry_num != QUICKMENU_MAXLINES - 2)
4928 panel_pos_y = first_entry_pos + entry_num * fontsize_y;
4930 if(mouseClicked & S_MOUSE1)
4931 color = '0.5 1 0.5';
4932 else if(hudShiftState & S_CTRL)
4936 drawfill(panel_pos, eX * panel_size_x + eY * fontsize_y, color, .2, DRAWFLAG_NORMAL);
4938 if(!mouseClicked && (prevMouseClicked & S_MOUSE1))
4941 if (entry_num < QUICKMENU_MAXLINES - 1)
4942 f = HUD_QuickMenu_ActionForNumber(entry_num + 1);
4944 f = HUD_QuickMenu_ActionForNumber(0);
4945 if(f && !(hudShiftState & S_CTRL))
4946 HUD_QuickMenu_Close();
4951 const vector cursorsize = '32 32 0';
4952 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', 0.8, DRAWFLAG_NORMAL);
4954 prevMouseClicked = mouseClicked;
4956 void HUD_QuickMenu_DrawEntry(vector pos, string s, vector fontsize)
4960 entry = textShortenToWidth(s, panel_size_x, fontsize, stringwidth_colors);
4961 if (autocvar_hud_panel_quickmenu_align > 0)
4963 offset = (panel_size_x - stringwidth_colors(entry, fontsize)) * min(autocvar_hud_panel_quickmenu_align, 1);
4964 drawcolorcodedstring(pos + eX * offset, entry, fontsize, panel_fg_alpha, DRAWFLAG_ADDITIVE);
4967 drawcolorcodedstring(pos, entry, fontsize, panel_fg_alpha, DRAWFLAG_ADDITIVE);
4969 void HUD_QuickMenu(void)
4971 if(!autocvar__hud_configure)
4973 if (hud_configure_prev && hud_configure_prev != -1)
4974 HUD_QuickMenu_Close();
4976 if(!hud_draw_maximized) return;
4977 if(mv_active) return;
4978 //if(!autocvar_hud_panel_quickmenu) return;
4979 if(!hud_panel_quickmenu) return;
4981 if(time > QuickMenu_TimeOut)
4983 HUD_QuickMenu_Close();
4989 if(!HUD_QuickMenu_IsOpened())
4991 QuickMenu_Entries = 1;
4992 HUD_QuickMenu_load_entry(QuickMenu_Entries, sprintf(_("Submenu%d"), QuickMenu_Entries), "");
4993 ++QuickMenu_Entries;
4994 HUD_QuickMenu_load_entry(QuickMenu_Entries, sprintf(_("Submenu%d"), QuickMenu_Entries), "");
4995 ++QuickMenu_Entries;
4996 // although real command doesn't matter here, it must not be empty
4997 // otherwise the entry is displayed like a submenu
4998 for (; QuickMenu_Entries < QUICKMENU_MAXLINES - 1; ++QuickMenu_Entries)
4999 HUD_QuickMenu_load_entry(QuickMenu_Entries, sprintf(_("Command%d"), QuickMenu_Entries), "-");
5000 ++QuickMenu_Entries;
5001 HUD_QuickMenu_clear_entry(QuickMenu_Entries);
5002 QuickMenu_IsLastPage = FALSE;
5006 HUD_Panel_UpdateCvars();
5008 HUD_Panel_DrawBg(1);
5010 if(panel_bg_padding)
5012 panel_pos += '1 1 0' * panel_bg_padding;
5013 panel_size -= '2 2 0' * panel_bg_padding;
5019 fontsize = '1 1 0' * (panel_size_y / QUICKMENU_MAXLINES);
5021 if (!QuickMenu_IsLastPage)
5024 HUD_QuickMenu_DrawEntry(panel_pos + eY * (panel_size_y - fontsize_y), sprintf("%d: %s%s", 0, color, _("Continue...")), fontsize);
5027 panel_pos_y += ((QUICKMENU_MAXLINES - QuickMenu_Entries) * fontsize_y) / 2;
5029 for (i = 1; i <= QuickMenu_Entries; ++i) {
5030 if (QuickMenu_Description[i] == "")
5032 if (QuickMenu_Command[i] == "")
5036 HUD_QuickMenu_DrawEntry(panel_pos, sprintf("%d: %s%s", i, color, QuickMenu_Description[i]), fontsize);
5037 panel_pos_y += fontsize_y;
5042 #define QUICKMENU_SMENU(submenu,eng_submenu) { \
5043 if(target_submenu == eng_submenu && target_submenu_found) \
5044 return; /* target_submenu entries are now loaded, exit */ \
5045 if(QuickMenu_Buffer_Size < QUICKMENU_BUFFER_MAXENTRIES) \
5046 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("S", submenu)); \
5047 ++QuickMenu_Buffer_Size; \
5048 if(target_submenu == eng_submenu && !target_submenu_found) { \
5049 QuickMenu_Buffer_Size = 0; /* enable load of next entries */ \
5050 target_submenu_found = TRUE; \
5054 #define QUICKMENU_ENTRY(title,command) { \
5055 if(QuickMenu_Buffer_Size + 1 < QUICKMENU_BUFFER_MAXENTRIES) \
5057 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("T", title)); \
5058 ++QuickMenu_Buffer_Size; \
5059 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("C", command)); \
5061 ++QuickMenu_Buffer_Size; \
5064 #define QUICKMENU_SMENU_PL(submenu,eng_submenu,command,teamplayers,without_me) { \
5065 if(QuickMenu_Buffer_Size + 3 < QUICKMENU_BUFFER_MAXENTRIES) {\
5066 QUICKMENU_SMENU(submenu,eng_submenu) \
5067 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("T", ftos(teamplayers), ftos(without_me))); \
5068 ++QuickMenu_Buffer_Size; \
5069 bufstr_set(QuickMenu_Buffer, QuickMenu_Buffer_Size, strcat("P", command)); \
5070 ++QuickMenu_Buffer_Size; \
5071 QUICKMENU_SMENU(submenu,eng_submenu) \
5077 // useful to Translate a string inside the Command
5078 #define QUICKMENU_ENTRY_TC(title,command,text,translated_text) {\
5079 if(prvm_language == "en") \
5080 QUICKMENU_ENTRY(title, sprintf(command, text)) \
5081 else if(!autocvar_hud_panel_quickmenu_translatecommands || translated_text == text) \
5082 QUICKMENU_ENTRY(strcat("(en)", title), sprintf(command, text)) \
5084 QUICKMENU_ENTRY(strcat("(", prvm_language, ")", title), sprintf(command, translated_text)) \
5087 void HUD_Quickmenu_PlayerListEntries(string cmd, float teamplayers, float without_me)
5090 if(teamplayers && !team_count)
5093 for(pl = players.sort_next; pl; pl = pl.sort_next)
5095 if(teamplayers == 1 && (pl.team != myteam || pl.team == NUM_SPECTATOR)) // only own team players
5097 if(teamplayers == 2 && (pl.team == myteam || pl.team == NUM_SPECTATOR)) // only enemy team players
5099 if(without_me && pl.sv_entnum == player_localnum)
5101 QUICKMENU_ENTRY(GetPlayerName(pl.sv_entnum), sprintf(cmd, GetPlayerName(pl.sv_entnum)))
5108 // Specifying target_submenu, this function only loads entries inside target_submenu
5109 // NOTE: alternatively we could have loaded the whole default quickmenu and
5110 // then called HUD_QuickMenu_Page(target_submenu, 0);
5111 // but this sytem is more reliable since we can always refer to target_submenu
5112 // with the English title even if a translation is active
5113 void HUD_QuickMenu_Default(string target_submenu)
5115 float target_submenu_found = FALSE;
5116 if(target_submenu != "")
5117 QuickMenu_Buffer_Size = QUICKMENU_BUFFER_MAXENTRIES; // forbids load of next entries until target_submenu
5119 QUICKMENU_SMENU(CTX(_("QMCMD^Chat")), "Chat")
5120 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^nice one")), "say %s", ":-) / nice one", CTX(_("QMCMD^:-) / nice one")))
5121 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^good game")), "say %s", "good game", CTX(_("QMCMD^good game")))
5122 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^hi / good luck")), "say %s", "hi / good luck and have fun", CTX(_("QMCMD^hi / good luck and have fun")))
5123 QUICKMENU_SMENU(CTX(_("QMCMD^Chat")), "Chat")
5127 QUICKMENU_SMENU(CTX(_("QMCMD^Team chat")), "Team chat")
5128 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^quad soon")), "say_team %s", "quad soon", CTX(_("QMCMD^quad soon")))
5129 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^free item, icon")), "say_team %s; g_waypointsprite_team_here_p", "free item %x^7 (l:%y^7)", CTX(_("QMCMD^free item %x^7 (l:%y^7)")))
5130 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^took item, icon")), "say_team %s; g_waypointsprite_team_here", "took item (l:%l^7)", CTX(_("QMCMD^took item (l:%l^7)")))
5131 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^negative")), "say_team %s", "negative", CTX(_("QMCMD^negative")))
5132 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^positive")), "say_team %s", "positive", CTX(_("QMCMD^positive")))
5133 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^need help, icon")), "say_team %s; g_waypointsprite_team_helpme; cmd voice needhelp", "need help (l:%l^7) (h:%h^7 a:%a^7 w:%w^7)", CTX(_("QMCMD^need help (l:%l^7) (h:%h^7 a:%a^7 w:%w^7)")))
5134 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^enemy seen, icon")), "say_team %s; g_waypointsprite_team_danger_p; cmd voice incoming", "enemy seen (l:%y^7)", CTX(_("QMCMD^enemy seen (l:%y^7)")))
5135 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^flag seen, icon")), "say_team %s; g_waypointsprite_team_here_p; cmd voice seenflag", "flag seen (l:%y^7)", CTX(_("QMCMD^flag seen (l:%y^7)")))
5136 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^defending, icon")), "say_team %s; g_waypointsprite_team_here", "defending (l:%l^7) (h:%h^7 a:%a^7 w:%w^7)", CTX(_("QMCMD^defending (l:%l^7) (h:%h^7 a:%a^7 w:%w^7)")))
5137 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^roaming, icon")), "say_team %s; g_waypointsprite_team_here", "roaming (l:%l^7) (h:%h^7 a:%a^7 w:%w^7)", CTX(_("QMCMD^roaming (l:%l^7) (h:%h^7 a:%a^7 w:%w^7)")))
5138 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^attacking, icon")), "say_team %s; g_waypointsprite_team_here", "attacking (l:%l^7) (h:%h^7 a:%a^7 w:%w^7)", CTX(_("QMCMD^attacking (l:%l^7) (h:%h^7 a:%a^7 w:%w^7)")))
5139 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^killed flag, icon")), "say_team %s; g_waypointsprite_team_here_p", "killed flagcarrier (l:%y^7)", CTX(_("QMCMD^killed flagcarrier (l:%y^7)")))
5140 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^dropped flag, icon")), "say_team %s; g_waypointsprite_team_here_d", "dropped flag (l:%d^7)", CTX(_("QMCMD^dropped flag (l:%d^7)")))
5141 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^drop gun, icon")), "say_team %s; g_waypointsprite_team_here; wait; dropweapon", "dropped gun %w^7 (l:%l^7)", CTX(_("QMCMD^dropped gun %w^7 (l:%l^7)")))
5142 QUICKMENU_ENTRY_TC(CTX(_("QMCMD^drop flag/key, icon")), "say_team %s; g_waypointsprite_team_here; wait; +use", "dropped flag/key %w^7 (l:%l^7)", CTX(_("QMCMD^dropped flag/key %w^7 (l:%l^7)")))
5143 QUICKMENU_SMENU(CTX(_("QMCMD^Team chat")), "Team chat")
5146 QUICKMENU_SMENU_PL(CTX(_("QMCMD^Send private message to")), "Send private message to", "commandmode tell \"%s\" ^7", 0, 1)
5148 QUICKMENU_SMENU(CTX(_("QMCMD^Settings")), "Settings")
5149 QUICKMENU_SMENU(CTX(_("QMCMD^View/HUD settings")), "View/HUD settings")
5150 QUICKMENU_ENTRY(CTX(_("QMCMD^1st/3rd person view")), "toggle chase_active")
5151 QUICKMENU_ENTRY(CTX(_("QMCMD^Player models like mine on/off")), "toggle cl_forceplayermodels")
5152 QUICKMENU_ENTRY(CTX(_("QMCMD^Names above players on/off")), "toggle hud_shownames")
5153 QUICKMENU_ENTRY(CTX(_("QMCMD^Crosshair per weapon on/off")), "toggle crosshair_per_weapon")
5154 QUICKMENU_ENTRY(CTX(_("QMCMD^FPS on/off")), "toggle hud_panel_engineinfo")
5155 QUICKMENU_ENTRY(CTX(_("QMCMD^Net graph on/off")), "toggle shownetgraph")
5156 QUICKMENU_SMENU(CTX(_("QMCMD^View/HUD settings")), "View/HUD settings")
5158 QUICKMENU_SMENU(CTX(_("QMCMD^Sound settings")), "Sound settings")
5159 QUICKMENU_ENTRY(CTX(_("QMCMD^Hit sound on/off")), "toggle cl_hitsound")
5160 QUICKMENU_ENTRY(CTX(_("QMCMD^Chat sound on/off")), "toggle cl_chatsound")
5161 QUICKMENU_SMENU(CTX(_("QMCMD^Sound settings")), "Sound settings")
5163 if(spectatee_status > 0)
5165 QUICKMENU_SMENU(CTX(_("QMCMD^Spectator camera")), "Spectator camera")
5166 QUICKMENU_ENTRY(CTX(_("QMCMD^1st person")), "chase_active 0; -use")
5167 QUICKMENU_ENTRY(CTX(_("QMCMD^3rd person around player")), "chase_active 1; +use")
5168 QUICKMENU_ENTRY(CTX(_("QMCMD^3rd person behind")), "chase_active 1; -use")
5169 QUICKMENU_SMENU(CTX(_("QMCMD^Spectator camera")), "Spectator camera")
5172 if(spectatee_status == -1)
5174 QUICKMENU_SMENU(CTX(_("QMCMD^Observer camera")), "Observer camera")
5175 QUICKMENU_ENTRY(CTX(_("QMCMD^Increase speed")), "weapnext")
5176 QUICKMENU_ENTRY(CTX(_("QMCMD^Decrease speed")), "weapprev")
5177 QUICKMENU_ENTRY(CTX(_("QMCMD^Wall collision off")), "+use")
5178 QUICKMENU_ENTRY(CTX(_("QMCMD^Wall collision on")), "-use")
5179 QUICKMENU_SMENU(CTX(_("QMCMD^Observer camera")), "Observer camera")
5182 QUICKMENU_ENTRY(CTX(_("QMCMD^toggle fullscreen")), "toggle vid_fullscreen; vid_restart")
5183 if(prvm_language != "en")
5184 QUICKMENU_ENTRY(CTX(_("QMCMD^Translate chat messages on/off")), "toggle hud_panel_quickmenu_translatecommands")
5185 QUICKMENU_SMENU(CTX(_("QMCMD^Settings")), "Settings")
5187 QUICKMENU_SMENU(CTX(_("QMCMD^Call a vote")), "Call a vote")
5188 QUICKMENU_ENTRY(CTX(_("QMCMD^Restart the map")), "vcall restart")
5189 QUICKMENU_ENTRY(CTX(_("QMCMD^End match")), "vcall endmatch")
5190 if(getstatf(STAT_TIMELIMIT) > 0)
5192 QUICKMENU_ENTRY(CTX(_("QMCMD^Reduce match time")), "vcall reducematchtime")
5193 QUICKMENU_ENTRY(CTX(_("QMCMD^Extend match time")), "vcall extendmatchtime")
5196 QUICKMENU_ENTRY(CTX(_("QMCMD^Shuffle teams")), "vcall shuffleteams")
5197 QUICKMENU_SMENU(CTX(_("QMCMD^Call a vote")), "Call a vote")
5199 if(target_submenu != "" && !target_submenu_found)
5201 printf("Couldn't find submenu \"%s\"\n", target_submenu);
5202 if(prvm_language != "en")
5203 printf("^3Warning: submenu must be in English\n", target_submenu);
5204 QuickMenu_Buffer_Size = 0;
5207 #undef QUICKMENU_SMENU
5208 #undef QUICKMENU_ENTRY
5209 #undef QUICKMENU_ENTRY_TC
5219 void HUD_Reset (void)
5221 // reset gametype specific icons
5222 if(gametype == MAPINFO_TYPE_CTF)
5223 HUD_Mod_CTF_Reset();
5226 void HUD_Main (void)
5229 // global hud theAlpha fade
5230 if(menu_enabled == 1)
5233 hud_fade_alpha = (1 - autocvar__menu_alpha);
5235 if(scoreboard_fade_alpha)
5236 hud_fade_alpha = (1 - scoreboard_fade_alpha);
5238 HUD_Configure_Frame();
5240 if(intermission == 2) // no hud during mapvote
5243 // panels that we want to be active together with the scoreboard
5244 // they must fade only when the menu does
5245 if(scoreboard_fade_alpha == 1)
5247 (panel = HUD_PANEL(CENTERPRINT)).panel_draw();
5251 if(!autocvar__hud_configure && !hud_fade_alpha)
5255 if (hud_skin_prev != autocvar_hud_skin)
5258 strunzone(hud_skin_path);
5259 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
5261 strunzone(hud_skin_prev);
5262 hud_skin_prev = strzone(autocvar_hud_skin);
5265 current_player = player_localentnum;
5268 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
5272 float hud_dock_color_team = autocvar_hud_dock_color_team;
5273 if((teamplay) && hud_dock_color_team) {
5274 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
5275 color = '1 0 0' * hud_dock_color_team;
5277 color = myteamcolors * hud_dock_color_team;
5279 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
5280 color = '1 0 0' * hud_dock_color_team;
5284 string hud_dock_color = autocvar_hud_dock_color;
5285 if(hud_dock_color == "shirt") {
5286 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
5287 color = colormapPaletteColor(floor(f / 16), 0);
5289 else if(hud_dock_color == "pants") {
5290 f = stof(getplayerkeyvalue(current_player - 1, "colors"));
5291 color = colormapPaletteColor(f % 16, 1);
5294 color = stov(hud_dock_color);
5298 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
5299 if(precache_pic(pic) == "") {
5300 pic = strcat(hud_skin_path, "/dock_medium");
5301 if(precache_pic(pic) == "") {
5302 pic = "gfx/hud/default/dock_medium";
5305 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...
5308 // cache the panel order into the panel_order array
5309 if(autocvar__hud_panelorder != hud_panelorder_prev) {
5310 for(i = 0; i < HUD_PANEL_NUM; ++i)
5311 panel_order[i] = -1;
5313 float p_num, warning = false;
5314 float argc = tokenize_console(autocvar__hud_panelorder);
5315 if (argc > HUD_PANEL_NUM)
5317 //first detect wrong/missing panel numbers
5318 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5319 p_num = stof(argv(i));
5320 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
5321 if (panel_order[p_num] == -1) //found for the first time?
5322 s = strcat(s, ftos(p_num), " ");
5323 panel_order[p_num] = 1; //mark as found
5328 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5329 if (panel_order[i] == -1) {
5331 s = strcat(s, ftos(i), " "); //add missing panel number
5335 dprint("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
5337 cvar_set("_hud_panelorder", s);
5338 if(hud_panelorder_prev)
5339 strunzone(hud_panelorder_prev);
5340 hud_panelorder_prev = strzone(s);
5342 //now properly set panel_order
5343 tokenize_console(s);
5344 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5345 panel_order[i] = stof(argv(i));
5349 hud_draw_maximized = 0;
5350 // draw panels in order specified by panel_order array
5351 for(i = HUD_PANEL_NUM - 1; i >= 0; --i)
5352 (panel = hud_panel[panel_order[i]]).panel_draw();
5354 hud_draw_maximized = 1; // panels that may be maximized must check this var
5355 // draw maximized panels on top
5356 if(hud_panel_radar_maximized)
5357 (panel = HUD_PANEL(RADAR)).panel_draw();
5358 if(autocvar__con_chat_maximized)
5359 (panel = HUD_PANEL(CHAT)).panel_draw();
5360 if(hud_panel_quickmenu)
5361 (panel = HUD_PANEL(QUICKMENU)).panel_draw();
5363 HUD_Configure_PostDraw();
5365 hud_configure_prev = autocvar__hud_configure;