7 // a border picture is a texture containing nine parts:
8 // 1/4 width: left part
9 // 1/2 width: middle part (stretched)
10 // 1/4 width: right part
12 // 1/4 height: top part
13 // 1/2 height: middle part (stretched)
14 // 1/4 height: bottom part
15 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
17 if (theBorderSize_x <= 0 && theBorderSize_y <= 0) // no border
19 // draw only the central part
20 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
27 //pic = draw_UseSkinFor(pic);
28 width = eX * theSize_x;
29 height = eY * theSize_y;
30 if(theSize_x <= theBorderSize_x * 2)
32 // not wide enough... draw just left and right then
33 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
34 if(theSize_y <= theBorderSize_y * 2)
36 // not high enough... draw just corners
37 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
38 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
39 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
40 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
41 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
45 dY = theBorderSize_x * eY;
46 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
47 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
48 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
49 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);
50 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
51 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);
56 if(theSize_y <= theBorderSize_y * 2)
58 // not high enough... draw just top and bottom then
59 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
60 dX = theBorderSize_x * eX;
61 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
62 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
63 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
64 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
65 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);
66 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);
70 dX = theBorderSize_x * eX;
71 dY = theBorderSize_x * eY;
72 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
73 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
74 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
75 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
76 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
77 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
78 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
79 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
80 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
85 vector HUD_Get_Num_Color (float x, float maxvalue)
93 else if(x > maxvalue * 0.75) {
94 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
95 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
98 else if(x > maxvalue * 0.5) {
99 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
100 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
101 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
103 else if(x > maxvalue * 0.25) {
106 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
108 else if(x > maxvalue * 0.1) {
110 color_y = (x-20)*90/27/100; // green value between 0 -> 1
111 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
121 float stringwidth_colors(string s, vector theSize)
123 return stringwidth(s, TRUE, theSize);
126 float stringwidth_nocolors(string s, vector theSize)
128 return stringwidth(s, FALSE, theSize);
131 #define CENTERPRINT_MAX_LINES 30
132 string centerprint_messages[CENTERPRINT_MAX_LINES];
133 float centerprint_width[CENTERPRINT_MAX_LINES];
134 float centerprint_time;
135 float centerprint_expire;
136 float centerprint_num;
137 float centerprint_offset_hint;
138 vector centerprint_fontsize;
140 void centerprint(string strMessage)
142 float i, j, n, hcount;
145 centerprint_fontsize = HUD_GetFontsize("scr_centersize");
147 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
149 if(cvar("scr_centertime") <= 0)
155 // strip trailing newlines
156 j = strlen(strMessage) - 1;
157 while(substring(strMessage, j, 1) == "\n" && j >= 0)
159 strMessage = substring(strMessage, 0, j + 1);
164 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
166 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
168 strMessage = substring(strMessage, j, strlen(strMessage) - j);
169 centerprint_offset_hint = j;
174 // if we get here, we have a message. Initialize its height.
177 n = tokenizebyseparator(strMessage, "\n");
179 for(j = 0; j < n; ++j)
181 getWrappedLine_remaining = argv(j);
182 while(getWrappedLine_remaining)
184 s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
185 if(centerprint_messages[i] != s) // don't fade the same message in, looks stupid
186 centerprint_time = time;
187 if(centerprint_messages[i])
188 strunzone(centerprint_messages[i]);
189 centerprint_messages[i] = strzone(s);
190 centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
193 // half height for empty lines looks better
199 if(i >= CENTERPRINT_MAX_LINES)
205 h = centerprint_fontsize_y*hcount;
207 havail = vid_conheight;
208 if(cvar("con_chatpos") < 0)
209 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
210 if(havail > vid_conheight - 70)
211 havail = vid_conheight - 70; // avoid overlapping HUD
214 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
216 // here, the centerprint would cover the crosshair. REALLY BAD.
217 forbiddenmin = vid_conheight * 0.5 - h - 16;
218 forbiddenmax = vid_conheight * 0.5 + 16;
220 allowedmin = scoreboard_bottom;
221 allowedmax = havail - h;
222 preferred = (havail - h)/2;
225 // possible orderings (total: 4! / 4 = 6)
226 // allowedmin allowedmax forbiddenmin forbiddenmax
227 // forbiddenmin forbiddenmax allowedmin allowedmax
228 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
230 // forbidden doesn't matter in this case
231 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
233 // allowedmin forbiddenmin allowedmax forbiddenmax
234 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
236 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
238 // allowedmin forbiddenmin forbiddenmax allowedmax
239 else if(allowedmin < forbiddenmin)
241 // make sure the forbidden zone is not covered
242 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
243 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
245 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
247 // forbiddenmin allowedmin allowedmax forbiddenmax
248 else if(allowedmax < forbiddenmax)
250 // it's better to leave the allowed zone (overlap with scoreboard) than
251 // to cover the forbidden zone (crosshair)
252 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
253 centerprint_start_y = forbiddenmax;
255 centerprint_start_y = forbiddenmin;
257 // forbiddenmin allowedmin forbiddenmax allowedmax
260 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
267 centerprint_expire = time + cvar("scr_centertime");
270 void HUD_DrawCenterPrint (void)
277 if(time - centerprint_time < 0.25)
278 a = (time - centerprint_time) / 0.25;
280 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
287 if(centerprint_num * cvar("scr_centersize") > 24 && scoreboard_active) // 24 = height of Scoreboard text
288 centerprint_start_y = scoreboard_bottom + centerprint_fontsize_y;
290 pos = centerprint_start;
291 for (i=0; i<centerprint_num; i = i + 1)
293 ts = centerprint_messages[i];
294 drawfontscale = sz * '1 1 0';
295 drawfont = hud_bigfont;
296 pos_x = (vid_conwidth - stringwidth(ts, TRUE, centerprint_fontsize)) * 0.5;
299 drawcolorcodedstring(pos + '0 1 0' * (1 - sz) * 0.5 *centerprint_fontsize_y, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
300 pos_y = pos_y + centerprint_fontsize_y;
303 // half height for empty lines looks better
304 pos_y = pos_y + sz * centerprint_fontsize_y * 0.5;
305 drawfontscale = '1 1 0';
310 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
312 position_x -= 2 / 3 * strlen(text) * scale_x;
313 drawstring(position, text, scale, rgb, alpha, flag);
316 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
318 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
319 drawstring(position, text, scale, rgb, alpha, flag);
322 // return the string of the given race place
323 string race_PlaceName(float pos) {
331 return strcat(ftos(pos), "th");
334 // return the string of the onscreen race timer
335 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
343 if(histime == 0) // goal hit
347 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
357 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
363 lapstr = strcat(" (-", ftos(lapdelta), "L)");
366 else if(lapdelta < 0)
368 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
372 else if(histime > 0) // anticipation
374 if(mytime >= histime)
375 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
377 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
384 cpname = "Start line";
386 cpname = "Finish line";
388 cpname = strcat("Intermediate ", ftos(cp));
390 cpname = "Finish line";
393 return strcat(col, cpname);
394 else if(hisname == "")
395 return strcat(col, cpname, " (", timestr, ")");
397 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
400 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
401 float race_CheckName(string net_name) {
403 for (i=RANKINGS_CNT-1;i>=0;--i)
404 if(grecordholder[i] == net_name)
415 #define HUD_Write(s) fputs(fh, s)
416 // q: quoted, n: not quoted
417 #define HUD_Write_Cvar_n(cvar) HUD_Write(strcat("seta ", cvar, " ", cvar_string(cvar), "\n"))
418 #define HUD_Write_Cvar_q(cvar) HUD_Write(strcat("seta ", cvar, " \"", cvar_string(cvar), "\"\n"))
419 #define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel_name, cvar_suf))
420 #define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel_name, cvar_suf))
422 void HUD_Panel_ExportCfg(string cfgname)
425 string filename = strcat("hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg");
426 fh = fopen(filename, FILE_WRITE);
429 HUD_Write_Cvar_q("hud_skin");
430 HUD_Write_Cvar_q("hud_panel_bg");
431 HUD_Write_Cvar_q("hud_panel_bg_color");
432 HUD_Write_Cvar_q("hud_panel_bg_color_team");
433 HUD_Write_Cvar_q("hud_panel_bg_alpha");
434 HUD_Write_Cvar_q("hud_panel_bg_border");
435 HUD_Write_Cvar_q("hud_panel_bg_padding");
436 HUD_Write_Cvar_q("hud_panel_fg_alpha");
439 HUD_Write_Cvar_q("hud_dock");
440 HUD_Write_Cvar_q("hud_dock_color");
441 HUD_Write_Cvar_q("hud_dock_color_team");
442 HUD_Write_Cvar_q("hud_dock_alpha");
445 HUD_Write_Cvar_q("hud_progressbar_alpha");
446 HUD_Write_Cvar_q("hud_progressbar_strength_color");
447 HUD_Write_Cvar_q("hud_progressbar_shield_color");
448 HUD_Write_Cvar_q("hud_progressbar_health_color");
449 HUD_Write_Cvar_q("hud_progressbar_armor_color");
450 HUD_Write_Cvar_q("hud_progressbar_fuel_color");
451 HUD_Write_Cvar_q("hud_progressbar_nexball_color");
454 HUD_Write_Cvar_q("_hud_panelorder");
457 HUD_Write_Cvar_q("hud_configure_grid");
458 HUD_Write_Cvar_q("hud_configure_grid_xsize");
459 HUD_Write_Cvar_q("hud_configure_grid_ysize");
462 HUD_Write_Cvar_q("scr_centerpos");
465 // common cvars for all panels
467 for (i = 0; i < HUD_PANEL_NUM; ++i)
469 HUD_Panel_GetName(i);
471 HUD_Write_PanelCvar_n("");
472 HUD_Write_PanelCvar_q("_pos");
473 HUD_Write_PanelCvar_q("_size");
474 HUD_Write_PanelCvar_q("_bg");
475 HUD_Write_PanelCvar_q("_bg_color");
476 HUD_Write_PanelCvar_q("_bg_color_team");
477 HUD_Write_PanelCvar_q("_bg_alpha");
478 HUD_Write_PanelCvar_q("_bg_border");
479 HUD_Write_PanelCvar_q("_bg_padding");
481 case HUD_PANEL_WEAPONS:
482 HUD_Write_PanelCvar_q("_complainbubble");
483 HUD_Write_PanelCvar_q("_complainbubble_padding");
484 HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
485 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
486 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
487 HUD_Write_PanelCvar_q("_ammo_color");
488 HUD_Write_PanelCvar_q("_ammo_alpha");
489 HUD_Write_PanelCvar_q("_aspect");
492 HUD_Write_PanelCvar_q("_onlycurrent");
493 HUD_Write_PanelCvar_q("_iconalign");
495 case HUD_PANEL_POWERUPS:
496 HUD_Write_PanelCvar_q("_flip");
497 HUD_Write_PanelCvar_q("_iconalign");
498 HUD_Write_PanelCvar_q("_baralign");
499 HUD_Write_PanelCvar_q("_progressbar");
501 case HUD_PANEL_HEALTHARMOR:
502 HUD_Write_PanelCvar_q("_flip");
503 HUD_Write_PanelCvar_q("_iconalign");
504 HUD_Write_PanelCvar_q("_baralign");
505 HUD_Write_PanelCvar_q("_progressbar");
507 case HUD_PANEL_NOTIFY:
508 HUD_Write_PanelCvar_q("_flip");
509 HUD_Write_PanelCvar_q("_print");
511 case HUD_PANEL_RADAR:
512 HUD_Write_PanelCvar_q("_foreground_alpha");
515 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
517 case HUD_PANEL_PRESSEDKEYS:
518 HUD_Write_PanelCvar_q("_aspect");
520 case HUD_PANEL_INFOMESSAGES:
521 HUD_Write_PanelCvar_q("_flip");
523 case HUD_PANEL_PHYSICS:
524 HUD_Write_PanelCvar_q("_flip");
525 HUD_Write_PanelCvar_q("_baralign");
526 HUD_Write_PanelCvar_q("_progressbar");
531 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
533 print("^2Successfully exported to ", filename, "! (Note: It's saved in data/data/)\n");
537 print("^1Couldn't write to ", filename, "\n");
540 const float hlBorderSize = 4;
541 const string hlBorder = "gfx/hud/default/border_highlighted";
542 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
543 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
545 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
546 drawpic_tiled(panel_pos - '1 1 0' * myBorder, hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
547 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * (panel_size_y + 2 * myBorder - hlBorderSize), hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
548 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize, hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
549 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize + eX * (panel_size_x + 2 * myBorder - hlBorderSize), hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
552 // draw the background/borders
553 #define HUD_Panel_DrawBg(alpha)\
555 draw_BorderPicture(panel_pos - '1 1 0' * panel_bg_border, panel_bg, panel_size + '1 1 0' * 2 * panel_bg_border, panel_bg_color, panel_bg_alpha * alpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER));\
556 if(highlightedPanel_prev == active_panel && autocvar__hud_configure)\
558 HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha) * alpha);\
559 } ENDS_WITH_CURLY_BRACE
561 void HUD_Panel_DrawProgressBar(vector pos, vector mySize, float lenght_ratio, float vertical, float right_align, vector color, float alpha, float drawflag)
563 if(lenght_ratio <= 0 || !alpha)
570 pic = strcat(hud_skin_path, "/statusbar_vertical");
571 if(precache_pic(pic) == "") {
572 pic = "gfx/hud/default/statusbar_vertical";
576 pos_y += (1 - lenght_ratio) * mySize_y;
577 mySize_y *= lenght_ratio;
579 drawsubpic(pos, eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, pic, '0 0 0', '1 0.25 0', color, alpha, drawflag);
580 if(mySize_y/mySize_x > 2)
581 drawsubpic(pos + eY * mySize_x, eY * (mySize_y - 2 * mySize_x) + eX * mySize_x, pic, '0 0.25 0', '1 0.5 0', color, alpha, drawflag);
582 drawsubpic(pos + eY * mySize_y - eY * min(mySize_y * 0.5, mySize_x), eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, pic, '0 0.75 0', '1 0.25 0', color, alpha, drawflag);
584 pic = strcat(hud_skin_path, "/statusbar");
585 if(precache_pic(pic) == "") {
586 pic = "gfx/hud/default/statusbar";
590 pos_x += (1 - lenght_ratio) * mySize_x;
591 mySize_x *= lenght_ratio;
593 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
594 if(mySize_x/mySize_y > 2)
595 drawsubpic(pos + eX * mySize_y, eX * (mySize_x - 2 * mySize_y) + eY * mySize_y, pic, '0.25 0 0', '0.5 1 0', color, alpha, drawflag);
596 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, alpha, drawflag);
600 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
606 pic = strcat(hud_skin_path, "/num_leading");
607 if(precache_pic(pic) == "") {
608 pic = "gfx/hud/default/num_leading";
611 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
612 if(mySize_x/mySize_y > 2)
613 drawsubpic(pos + eX * mySize_y, eX * (mySize_x - 2 * mySize_y) + eY * mySize_y, pic, '0.25 0 0', '0.5 1 0', color, alpha, drawflag);
614 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, alpha, drawflag);
617 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
618 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
627 myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
628 targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
630 for (i = 0; i < HUD_PANEL_NUM; ++i) {
631 if(i == highlightedPanel || !panel_enabled)
634 HUD_Panel_UpdatePosSizeForId(i);
636 panel_pos -= '1 1 0' * panel_bg_border;
637 panel_size += '2 2 0' * panel_bg_border;
639 if(myPos_y + mySize_y < panel_pos_y)
641 if(myPos_y > panel_pos_y + panel_size_y)
644 if(myPos_x + mySize_x < panel_pos_x)
646 if(myPos_x > panel_pos_x + panel_size_x)
649 // OK, there IS a collision.
651 myCenter_x = myPos_x + 0.5 * mySize_x;
652 myCenter_y = myPos_y + 0.5 * mySize_y;
654 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
655 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
657 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
659 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
660 myTarget_x = panel_pos_x - mySize_x;
661 else // push it upwards
662 myTarget_y = panel_pos_y - mySize_y;
664 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
666 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
667 myTarget_x = panel_pos_x + panel_size_x;
668 else // push it upwards
669 myTarget_y = panel_pos_y - mySize_y;
671 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
673 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
674 myTarget_x = panel_pos_x - mySize_x;
675 else // push it downwards
676 myTarget_y = panel_pos_y + panel_size_y;
678 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
680 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
681 myTarget_x = panel_pos_x + panel_size_x;
682 else // push it downwards
683 myTarget_y = panel_pos_y + panel_size_y;
685 //if(cvar("hud_configure_checkcollisions_debug"))
686 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
692 void HUD_Panel_SetPos(vector pos)
694 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
698 //if(cvar("hud_configure_checkcollisions_debug"))
699 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
701 if(cvar("hud_configure_grid"))
703 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
704 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
707 if(hud_configure_checkcollisions)
708 pos = HUD_Panel_CheckMove(pos, mySize);
710 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
711 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
714 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
716 HUD_Panel_GetName(highlightedPanel);
717 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
720 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
721 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
726 float dist_x, dist_y;
728 ratio = mySize_x/mySize_y;
730 for (i = 0; i < HUD_PANEL_NUM; ++i) {
731 if(i == highlightedPanel || !panel_enabled)
734 HUD_Panel_UpdatePosSizeForId(i);
736 panel_pos -= '1 1 0' * panel_bg_border;
737 panel_size += '2 2 0' * panel_bg_border;
739 targEndPos = panel_pos + panel_size;
741 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
742 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
745 if (resizeCorner == 1)
747 // check if this panel is on our way
748 if (resizeorigin_x <= panel_pos_x)
750 if (resizeorigin_y <= panel_pos_y)
752 if (targEndPos_x <= resizeorigin_x - mySize_x)
754 if (targEndPos_y <= resizeorigin_y - mySize_y)
757 // there is a collision:
758 // detect which side of the panel we are facing is actually limiting the resizing
759 // (which side the resize direction finds for first) and reduce the size up to there
761 // dist is the distance between resizeorigin and the "analogous" point of the panel
762 // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
763 dist_x = resizeorigin_x - targEndPos_x;
764 dist_y = resizeorigin_y - targEndPos_y;
765 if (dist_y <= 0 || dist_x / dist_y > ratio)
766 mySize_x = min(mySize_x, dist_x);
768 mySize_y = min(mySize_y, dist_y);
770 else if (resizeCorner == 2)
772 if (resizeorigin_x >= targEndPos_x)
774 if (resizeorigin_y <= panel_pos_y)
776 if (panel_pos_x >= resizeorigin_x + mySize_x)
778 if (targEndPos_y <= resizeorigin_y - mySize_y)
781 dist_x = panel_pos_x - resizeorigin_x;
782 dist_y = resizeorigin_y - targEndPos_y;
783 if (dist_y <= 0 || dist_x / dist_y > ratio)
784 mySize_x = min(mySize_x, dist_x);
786 mySize_y = min(mySize_y, dist_y);
788 else if (resizeCorner == 3)
790 if (resizeorigin_x <= panel_pos_x)
792 if (resizeorigin_y >= targEndPos_y)
794 if (targEndPos_x <= resizeorigin_x - mySize_x)
796 if (panel_pos_y >= resizeorigin_y + mySize_y)
799 dist_x = resizeorigin_x - targEndPos_x;
800 dist_y = panel_pos_y - resizeorigin_y;
801 if (dist_y <= 0 || dist_x / dist_y > ratio)
802 mySize_x = min(mySize_x, dist_x);
804 mySize_y = min(mySize_y, dist_y);
806 else if (resizeCorner == 4)
808 if (resizeorigin_x >= targEndPos_x)
810 if (resizeorigin_y >= targEndPos_y)
812 if (panel_pos_x >= resizeorigin_x + mySize_x)
814 if (panel_pos_y >= resizeorigin_y + mySize_y)
817 dist_x = panel_pos_x - resizeorigin_x;
818 dist_y = panel_pos_y - resizeorigin_y;
819 if (dist_y <= 0 || dist_x / dist_y > ratio)
820 mySize_x = min(mySize_x, dist_x);
822 mySize_y = min(mySize_y, dist_y);
824 //if(cvar("hud_configure_checkcollisions_debug"))
825 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
831 void HUD_Panel_SetPosSize(vector mySize)
833 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
835 resizeorigin = panel_click_resizeorigin;
838 // minimum panel size cap
839 mySize_x = max(0.025 * vid_conwidth, mySize_x);
840 mySize_y = max(0.025 * vid_conheight, mySize_y);
842 if(highlightedPanel == HUD_PANEL_CHAT) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small.
844 mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
845 mySize_y = max(2 * cvar("con_chatsize") + 2 * panel_bg_padding, mySize_y);
848 // collision testing|
849 // -----------------+
851 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
852 if(resizeCorner == 1) {
853 myPos_x = resizeorigin_x - mySize_x;
854 myPos_y = resizeorigin_y - mySize_y;
855 } else if(resizeCorner == 2) {
856 myPos_x = resizeorigin_x;
857 myPos_y = resizeorigin_y - mySize_y;
858 } else if(resizeCorner == 3) {
859 myPos_x = resizeorigin_x - mySize_x;
860 myPos_y = resizeorigin_y;
861 } else { // resizeCorner == 4
862 myPos_x = resizeorigin_x;
863 myPos_y = resizeorigin_y;
866 // left/top screen edges
868 mySize_x = mySize_x + myPos_x;
870 mySize_y = mySize_y + myPos_y;
872 // bottom/right screen edges
873 if(myPos_x + mySize_x > vid_conwidth)
874 mySize_x = vid_conwidth - myPos_x;
875 if(myPos_y + mySize_y > vid_conheight)
876 mySize_y = vid_conheight - myPos_y;
878 //if(cvar("hud_configure_checkcollisions_debug"))
879 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
881 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
882 if(cvar("hud_configure_grid"))
884 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
885 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
888 if(hud_configure_checkcollisions)
889 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
891 // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then)
892 mySize_x = max(0.025 * vid_conwidth, mySize_x);
893 mySize_y = max(0.025 * vid_conheight, mySize_y);
895 // do another pos check, as size might have changed by now
896 if(resizeCorner == 1) {
897 myPos_x = resizeorigin_x - mySize_x;
898 myPos_y = resizeorigin_y - mySize_y;
899 } else if(resizeCorner == 2) {
900 myPos_x = resizeorigin_x;
901 myPos_y = resizeorigin_y - mySize_y;
902 } else if(resizeCorner == 3) {
903 myPos_x = resizeorigin_x - mySize_x;
904 myPos_y = resizeorigin_y;
905 } else { // resizeCorner == 4
906 myPos_x = resizeorigin_x;
907 myPos_y = resizeorigin_y;
910 //if(cvar("hud_configure_checkcollisions_debug"))
911 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
913 HUD_Panel_GetName(highlightedPanel);
915 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
916 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
918 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
919 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
923 float prevMouseClicked; // previous state
924 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
925 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
927 float pressed_key_time;
928 void HUD_Panel_Arrow_Action(float nPrimary)
930 if (highlightedPanel_prev == -1 || mouseClicked)
933 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
936 if(cvar("hud_configure_grid"))
938 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
940 if (hudShiftState & S_SHIFT)
941 step = hud_configure_realGridSize_y;
943 step = 2 * hud_configure_realGridSize_y;
947 if (hudShiftState & S_SHIFT)
948 step = hud_configure_realGridSize_x;
950 step = 2 * hud_configure_realGridSize_x;
955 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
956 step = vid_conheight;
959 if (hudShiftState & S_SHIFT)
960 step = (step / 256); // more precision
962 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
965 highlightedPanel = highlightedPanel_prev;
967 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
969 vector prev_pos, prev_size;
970 prev_pos = panel_pos;
971 prev_size = panel_size;
973 if (hudShiftState & S_ALT) // resize
975 highlightedAction = 1;
976 if(nPrimary == K_UPARROW)
978 else if(nPrimary == K_RIGHTARROW)
980 else if(nPrimary == K_LEFTARROW)
982 else // if(nPrimary == K_DOWNARROW)
985 // ctrl+arrow reduces the size, instead of increasing it
986 // Note that ctrl disables collisions check too, but it's fine
987 // since we don't collide with anything reducing the size
988 if (hudShiftState & S_CTRL) {
990 resizeCorner = 5 - resizeCorner;
995 panel_click_resizeorigin = panel_pos;
996 if(resizeCorner == 1) {
997 panel_click_resizeorigin += mySize;
999 } else if(resizeCorner == 2) {
1000 panel_click_resizeorigin_y += mySize_y;
1002 } else if(resizeCorner == 3) {
1003 panel_click_resizeorigin_x += mySize_x;
1005 } else { // resizeCorner == 4
1008 HUD_Panel_SetPosSize(mySize);
1012 highlightedAction = 2;
1015 if(nPrimary == K_UPARROW)
1017 else if(nPrimary == K_DOWNARROW)
1019 else if(nPrimary == K_LEFTARROW)
1021 else // if(nPrimary == K_RIGHTARROW)
1024 HUD_Panel_SetPos(pos);
1027 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1029 if (prev_pos != panel_pos || prev_size != panel_size)
1032 panel_pos_backup = prev_pos;
1033 panel_size_backup = prev_size;
1034 highlightedPanel_backup = highlightedPanel;
1038 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1042 if(!autocvar__hud_configure)
1045 // allow console bind to work
1048 con_keys = findkeysforcommand("toggleconsole");
1049 keys = tokenize(con_keys);
1051 float hit_con_bind, i;
1052 for (i = 0; i < keys; ++i)
1054 if(nPrimary == stof(argv(i)))
1058 if(bInputType == 0) {
1059 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
1060 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
1061 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
1063 else if(bInputType == 1) {
1064 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
1065 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
1066 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
1069 if(nPrimary == K_MOUSE1)
1071 if(bInputType == 0) { // key pressed
1075 else if(bInputType == 1) {// key released
1080 else if(nPrimary == K_ESCAPE)
1082 if (bInputType == 1)
1085 menu_enabled_time = time;
1086 localcmd("menu_showhudexit\n");
1088 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
1090 if (bInputType == 1 || mouseClicked)
1093 if (highlightedPanel_prev != -1)
1094 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
1096 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
1098 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
1100 if (bInputType == 1 || mouseClicked)
1103 if (highlightedPanel_prev != -1)
1105 panel_size_copied = panel_size;
1106 highlightedPanel_copied = highlightedPanel_prev;
1109 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
1111 if (bInputType == 1 || mouseClicked)
1114 if (highlightedPanel_copied == -1 || highlightedPanel_prev == -1)
1117 HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev);
1119 // reduce size if it'd go beyond screen boundaries
1120 vector tmp_size = panel_size_copied;
1121 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
1122 tmp_size_x = vid_conwidth - panel_pos_x;
1123 if (panel_pos_y + panel_size_copied_y > vid_conheight)
1124 tmp_size_y = vid_conheight - panel_pos_y;
1126 if (panel_size == tmp_size)
1130 panel_pos_backup = panel_pos;
1131 panel_size_backup = panel_size;
1132 highlightedPanel_backup = highlightedPanel_prev;
1134 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
1135 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1137 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
1139 if (bInputType == 1 || mouseClicked)
1141 //restore previous values
1142 if (highlightedPanel_backup != -1)
1144 HUD_Panel_GetName(highlightedPanel_backup);
1145 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
1146 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
1147 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
1148 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1149 highlightedPanel_backup = -1;
1152 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
1154 if (bInputType == 1)
1156 pressed_key_time = 0;
1159 else if (pressed_key_time == 0)
1160 pressed_key_time = time;
1162 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
1164 else if(hit_con_bind)
1167 return true; // Suppress ALL other input
1170 float HUD_Panel_HighlightCheck()
1174 while(j < HUD_PANEL_NUM)
1179 HUD_Panel_UpdatePosSizeForId(i);
1181 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1184 if(mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
1188 // resize from topleft border
1189 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
1193 // resize from topright border
1194 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
1198 // resize from bottomleft border
1199 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
1203 // resize from bottomright border
1204 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
1212 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
1213 void HUD_Panel_FirstInDrawQ(float id)
1216 var float place = -1;
1217 // find out where in the array our current id is, save into place
1218 for(i = 0; i < HUD_PANEL_NUM; ++i)
1220 if(panel_order[i] == id)
1226 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
1228 place = HUD_PANEL_NUM - 1;
1230 // move all ids up by one step in the array until "place"
1231 for(i = place; i > 0; --i)
1233 panel_order[i] = panel_order[i-1];
1235 // now save the new top id
1236 panel_order[0] = id;
1238 // let's save them into the cvar by some strcat trickery
1240 for(i = 0; i < HUD_PANEL_NUM; ++i)
1242 s = strcat(s, ftos(panel_order[i]), " ");
1244 cvar_set("_hud_panelorder", s);
1245 if(hud_panelorder_prev)
1246 strunzone(hud_panelorder_prev);
1247 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
1250 void HUD_Panel_Highlight()
1254 while(j < HUD_PANEL_NUM)
1259 HUD_Panel_UpdatePosSizeForId(i);
1261 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1264 if(mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
1266 highlightedPanel = i;
1267 HUD_Panel_FirstInDrawQ(i);
1268 highlightedAction = 1;
1269 panel_click_distance = mousepos - panel_pos;
1272 // resize from topleft border
1273 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
1275 highlightedPanel = i;
1276 HUD_Panel_FirstInDrawQ(i);
1277 highlightedAction = 2;
1279 panel_click_distance = mousepos - panel_pos;
1280 panel_click_resizeorigin = panel_pos + panel_size;
1283 // resize from topright border
1284 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
1286 highlightedPanel = i;
1287 HUD_Panel_FirstInDrawQ(i);
1288 highlightedAction = 2;
1290 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
1291 panel_click_distance_y = mousepos_y - panel_pos_y;
1292 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
1295 // resize from bottomleft border
1296 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
1298 highlightedPanel = i;
1299 HUD_Panel_FirstInDrawQ(i);
1300 highlightedAction = 2;
1302 panel_click_distance_x = mousepos_x - panel_pos_x;
1303 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
1304 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
1307 // resize from bottomright border
1308 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
1310 highlightedPanel = i;
1311 HUD_Panel_FirstInDrawQ(i);
1312 highlightedAction = 2;
1314 panel_click_distance = panel_size - mousepos + panel_pos;
1315 panel_click_resizeorigin = panel_pos;
1320 highlightedPanel_prev = -1;
1325 float highlightcheck;
1326 vector prev_pos, prev_size;
1327 void HUD_Panel_Mouse()
1329 // TODO: needs better check... is there any float that contains the current state of the menu? _menu_alpha isn't apparently updated the frame the menu gets enabled
1330 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1334 print("menu_enabled: ", ftos(menu_enabled), "\n");
1335 print("Highlighted: ", ftos(highlightedPanel), "\n");
1336 print("Menu alpha: ", cvar_string("_menu_alpha"), "\n");
1339 // instantly hide the editor cursor if we open the HUDExit dialog
1340 // as hud_fade_alpha doesn't decrease to 0 in this case
1341 // TODO: find a way to fade the cursor out even in this case
1342 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1345 if(mouseClicked == 0 && menu_enabled != 2 && highlightedPanel >= 0) { // don't reset these variables in menu_enabled mode 2!
1346 highlightedPanel = -1;
1347 highlightedAction = 0;
1349 if(highlightedPanel != -1)
1350 highlightedPanel_prev = highlightedPanel;
1352 mousepos = mousepos + getmousepos() * cvar("menu_mouse_speed");
1354 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1355 mousepos_y = bound(0, mousepos_y, vid_conheight);
1359 if(prevMouseClicked == 0)
1361 HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1362 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1363 prev_pos = panel_pos;
1364 prev_size = panel_size;
1367 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1369 if (prev_pos != panel_pos || prev_size != panel_size)
1371 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
1373 panel_pos_backup = prev_pos;
1374 panel_size_backup = prev_size;
1375 highlightedPanel_backup = highlightedPanel;
1378 // in case the clicked panel is inside another panel and we aren't
1379 // moving it, avoid the immediate "fix" of its position/size
1380 // (often unwanted and hateful) by disabling collisions check
1381 hud_configure_checkcollisions = false;
1383 if(highlightedAction == 1)
1384 HUD_Panel_SetPos(mousepos - panel_click_distance);
1385 else if(highlightedAction == 2)
1388 if(resizeCorner == 1) {
1389 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1390 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1391 } else if(resizeCorner == 2) {
1392 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1393 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1394 } else if(resizeCorner == 3) {
1395 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1396 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1397 } else { // resizeCorner == 4
1398 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1399 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1401 HUD_Panel_SetPosSize(mySize);
1404 // doubleclick check
1405 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1407 mouseClicked = 0; // to prevent spam, I guess.
1409 menu_enabled_time = time;
1410 HUD_Panel_GetName(highlightedPanel);
1411 localcmd("menu_showhudoptions ", panel_name, "\n");
1414 if(prevMouseClicked == 0)
1416 prevMouseClickedTime = time;
1417 prevMouseClickedPos = mousepos;
1422 highlightcheck = HUD_Panel_HighlightCheck();
1424 // draw cursor after performing move/resize to have the panel pos/size updated before highlightcheck
1426 cursorsize = '32 32 0';
1428 if(highlightcheck == 0)
1429 drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1430 else if(highlightcheck == 1)
1431 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1432 else if(highlightcheck == 2)
1433 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1435 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1437 prevMouseClicked = mouseClicked;
1440 // Weapon icons (#0)
1442 float weaponspace[10];
1443 #define HUD_Weapons_Clear()\
1445 for(idx = 0; idx < 10; ++idx)\
1446 weaponspace[idx] = 0
1448 entity weaponorder[WEP_MAXCOUNT];
1449 void weaponorder_swap(float i, float j, entity pass)
1453 weaponorder[i] = weaponorder[j];
1457 string weaponorder_cmp_str;
1458 float weaponorder_cmp(float i, float j, entity pass)
1461 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1462 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1463 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)
1466 float GetAmmoStat(float i)
1470 case 0: return STAT_SHELLS;
1471 case 1: return STAT_NAILS;
1472 case 2: return STAT_ROCKETS;
1473 case 3: return STAT_CELLS;
1474 case 4: return STAT_FUEL;
1479 float GetAmmoTypeForWep(float i)
1483 case WEP_SHOTGUN: return 0;
1484 case WEP_UZI: return 1;
1485 case WEP_GRENADE_LAUNCHER: return 2;
1486 case WEP_MINE_LAYER: return 2;
1487 case WEP_ELECTRO: return 3;
1488 case WEP_CRYLINK: return 3;
1489 case WEP_HLAC: return 3;
1490 case WEP_MINSTANEX: return 3;
1491 case WEP_NEX: return 3;
1492 case WEP_CAMPINGRIFLE: return 1;
1493 case WEP_HAGAR: return 2;
1494 case WEP_ROCKET_LAUNCHER: return 2;
1495 case WEP_SEEKER: return 2;
1496 case WEP_FIREBALL: return 4;
1497 case WEP_HOOK: return 3;
1502 void HUD_Weapons(void)
1505 float center_x, center_y;
1507 if(!autocvar__hud_configure)
1509 if(!autocvar_hud_panel_weapons) return;
1510 if(spectatee_status == -1) return;
1513 float timeout = cvar("hud_panel_weapons_timeout");
1514 float timeout_effect_length, timein_effect_length;
1515 if (cvar("hud_panel_weapons_timeout_effect") == 0)
1517 timeout_effect_length = 0;
1518 timein_effect_length = 0;
1522 timeout_effect_length = 0.75;
1523 timein_effect_length = 0.375;
1526 if (timeout && time >= weapontime + timeout + timeout_effect_length && !autocvar__hud_configure)
1528 weaponprevtime = time;
1532 active_panel = HUD_PANEL_WEAPONS;
1533 HUD_Panel_UpdateCvars(weapons);
1535 if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
1537 f = (time - (weapontime + timeout)) / timeout_effect_length;
1538 if (cvar("hud_panel_weapons_timeout_effect"))
1540 panel_bg_alpha *= (1 - f);
1541 panel_fg_alpha *= (1 - f);
1543 if (cvar("hud_panel_weapons_timeout_effect") == 1)
1545 f *= f; // for a cooler movement
1546 center_x = panel_pos_x + panel_size_x/2;
1547 center_y = panel_pos_y + panel_size_y/2;
1548 screen_ar = vid_conwidth/vid_conheight;
1549 if (center_x/center_y < screen_ar) //bottom left
1551 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1552 panel_pos_y += f * (vid_conheight - panel_pos_y);
1554 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1558 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1559 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1561 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1564 weaponprevtime = time - (1 - f) * timein_effect_length;
1566 else if (timeout && time < weaponprevtime + timein_effect_length && !autocvar__hud_configure)
1568 f = (time - weaponprevtime) / timein_effect_length;
1569 if (cvar("hud_panel_weapons_timeout_effect"))
1571 panel_bg_alpha *= (f);
1572 panel_fg_alpha *= (f);
1574 if (cvar("hud_panel_weapons_timeout_effect") == 1)
1576 f *= f; // for a cooler movement
1578 center_x = panel_pos_x + panel_size_x/2;
1579 center_y = panel_pos_y + panel_size_y/2;
1580 screen_ar = vid_conwidth/vid_conheight;
1581 if (center_x/center_y < screen_ar) //bottom left
1583 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1584 panel_pos_y += f * (vid_conheight - panel_pos_y);
1586 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1590 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1591 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1593 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1598 float i, weapid, wpnalpha, weapon_cnt;
1600 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1602 self = get_weaponinfo(i);
1603 if(self.impulse >= 0)
1607 // TODO make this configurable
1608 if(weaponorder_bypriority != cvar_string("cl_weaponpriority"))
1610 if(weaponorder_bypriority)
1611 strunzone(weaponorder_bypriority);
1612 if(weaponorder_byimpulse)
1613 strunzone(weaponorder_byimpulse);
1615 weaponorder_bypriority = strzone(cvar_string("cl_weaponpriority"));
1616 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
1617 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1620 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1622 self = get_weaponinfo(i);
1623 if(self.impulse >= 0)
1625 weaponorder[weapon_cnt] = self;
1629 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1631 weaponorder_cmp_str = string_null;
1634 HUD_Panel_DrawBg(1);
1635 if(panel_bg_padding)
1637 panel_pos += '1 1 0' * panel_bg_padding;
1638 panel_size -= '2 2 0' * panel_bg_padding;
1641 if(cvar_or("hud_panel_weapons_fade", 1))
1643 wpnalpha = 3.2 - 2 * (time - weapontime);
1644 wpnalpha = bound(0.7, wpnalpha, 1) * panel_fg_alpha;
1647 wpnalpha = panel_fg_alpha;
1649 HUD_Weapons_Clear();
1651 float rows, columns;
1652 float aspect = cvar("hud_panel_weapons_aspect");
1653 rows = panel_size_y/panel_size_x;
1654 rows = bound(1, floor((sqrt(4 * aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1656 columns = ceil(WEP_COUNT/rows);
1659 float a, type, fullammo;
1661 when = cvar("hud_panel_weapons_complainbubble_time");
1663 fadetime = cvar("hud_panel_weapons_complainbubble_fadetime");
1669 float fullammo_shells, fullammo_nails, fullammo_rockets, fullammo_cells, fullammo_fuel;
1672 wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
1673 float barsize_x, barsize_y, baroffset_x, baroffset_y;
1674 float show_ammo = cvar("hud_panel_weapons_ammo");
1677 fullammo_shells = cvar("hud_panel_weapons_ammo_full_shells");
1678 fullammo_nails = cvar("hud_panel_weapons_ammo_full_nails");
1679 fullammo_rockets = cvar("hud_panel_weapons_ammo_full_rockets");
1680 fullammo_cells = cvar("hud_panel_weapons_ammo_full_cells");
1681 fullammo_fuel = cvar("hud_panel_weapons_ammo_full_fuel");
1682 ammo_color = stov(cvar_string("hud_panel_weapons_ammo_color"));
1683 ammo_alpha = panel_fg_alpha * cvar("hud_panel_weapons_ammo_alpha");
1686 if(wpnsize_x/wpnsize_y > aspect)
1688 barsize_x = aspect * wpnsize_y;
1689 barsize_y = wpnsize_y;
1690 baroffset_x = (wpnsize_x - barsize_x) / 2;
1694 barsize_y = 1/aspect * wpnsize_x;
1695 barsize_x = wpnsize_x;
1696 baroffset_y = (wpnsize_y - barsize_y) / 2;
1700 float show_accuracy;
1702 if(cvar("hud_panel_weapons_accuracy") && acc_levels)
1704 show_accuracy = true;
1705 if (acc_col_x[0] == -1)
1706 for (i = 0; i < acc_levels; ++i)
1707 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
1710 float weapons_st = getstati(STAT_WEAPONS);
1711 float label = cvar("hud_panel_weapons_label");
1713 for(i = 0; i < weapon_cnt; ++i)
1715 wpnpos = panel_pos + eX * column * wpnsize_x + eY * row * wpnsize_y;
1717 self = weaponorder[i];
1718 weapid = self.impulse;
1720 // draw background behind currently selected weapon
1721 if(self.weapon == activeweapon)
1722 drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1724 // draw the weapon accuracy
1727 weapon_stats = weapon_accuracy[self.weapon-WEP_FIRST];
1728 if(weapon_stats >= 0)
1730 // find the max level lower than weapon_stats
1733 while ( j && weapon_stats < acc_lev[j] )
1736 // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
1738 factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
1740 color = color + factor * (acc_col[j+1] - color);
1742 drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
1746 // draw the weapon icon
1747 if((weapid >= 0) && (weapons_st & self.weapons))
1749 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1751 if(label == 1) // weapon number
1752 drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1753 else if(label == 2) // bind
1754 drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1756 // draw ammo status bar
1757 if(show_ammo && weapid != WEP_TUBA && weapid != WEP_LASER && weapid != WEP_PORTO)
1760 type = GetAmmoTypeForWep(weapid);
1762 a = getstati(GetAmmoStat(type)); // how much ammo do we have?
1767 case 0: fullammo = fullammo_shells; break;
1768 case 1: fullammo = fullammo_nails; break;
1769 case 2: fullammo = fullammo_rockets; break;
1770 case 3: fullammo = fullammo_cells; break;
1771 case 4: fullammo = fullammo_fuel; break;
1772 default: fullammo = 60;
1776 wpnpos_x + baroffset_x,
1777 wpnpos_y + baroffset_y,
1778 barsize_x * bound(0, a/fullammo, 1),
1780 drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
1781 drawresetcliparea();
1786 // draw a "ghost weapon icon" if you don't have the weapon
1789 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
1792 // draw the complain message
1793 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && cvar("hud_panel_weapons_complainbubble"))
1797 if(complain_weapon_time + when > time)
1800 a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
1804 if(complain_weapon_time + when > time)
1811 if(complain_weapon_type == 0) {
1813 color = stov(cvar_string("hud_panel_weapons_complainbubble_color_outofammo"));
1815 else if(complain_weapon_type == 1) {
1817 color = stov(cvar_string("hud_panel_weapons_complainbubble_color_donthave"));
1821 color = stov(cvar_string("hud_panel_weapons_complainbubble_color_unavailable"));
1823 float padding = cvar("hud_panel_weapons_complainbubble_padding");
1824 drawpic_aspect_skin(wpnpos + '1 1 0' * padding, "weapon_complainbubble", wpnsize - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
1825 drawstring_aspect(wpnpos + '1 1 0' * padding, s, wpnsize - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
1841 float GetAmmoItemCode(float i)
1845 case 0: return IT_SHELLS;
1846 case 1: return IT_NAILS;
1847 case 2: return IT_ROCKETS;
1848 case 3: return IT_CELLS;
1849 case 4: return IT_FUEL;
1854 string GetAmmoPicture(float i)
1858 case 0: return "ammo_shells";
1859 case 1: return "ammo_bullets";
1860 case 2: return "ammo_rockets";
1861 case 3: return "ammo_cells";
1862 case 4: return "ammo_fuel";
1867 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
1870 if(autocvar__hud_configure)
1872 currently_selected = (itemcode == 2); //rockets always selected
1873 a = 31 + mod(itemcode*93, 128);
1876 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
1885 if(currently_selected)
1890 vector picpos, numpos;
1891 if(autocvar_hud_panel_ammo_iconalign)
1894 picpos = myPos + eX * 2 * mySize_y;
1898 numpos = myPos + eX * mySize_y;
1902 if (currently_selected)
1903 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1906 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1907 else // "ghost" ammo count
1908 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
1910 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1911 else // "ghost" ammo icon
1912 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
1917 if(!autocvar__hud_configure)
1919 if(!autocvar_hud_panel_ammo) return;
1920 if(spectatee_status == -1) return;
1923 active_panel = HUD_PANEL_AMMO;
1924 HUD_Panel_UpdateCvars(ammo);
1927 mySize = panel_size;
1929 HUD_Panel_DrawBg(1);
1930 if(panel_bg_padding)
1932 pos += '1 1 0' * panel_bg_padding;
1933 mySize -= '2 2 0' * panel_bg_padding;
1936 float rows, columns, row, column;
1938 if (autocvar_hud_panel_ammo_onlycurrent)
1942 rows = mySize_y/mySize_x;
1943 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
1944 // ^^^ ammo item aspect goes here
1946 columns = ceil(AMMO_COUNT/rows);
1948 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
1953 if(ammo_size_x/ammo_size_y > 3)
1955 newSize = 3 * ammo_size_y;
1956 offset_x = ammo_size_x - newSize;
1957 pos_x += offset_x/2;
1958 ammo_size_x = newSize;
1962 newSize = 1/3 * ammo_size_x;
1963 offset_y = ammo_size_y - newSize;
1964 pos_y += offset_y/2;
1965 ammo_size_y = newSize;
1968 drawfont = hud_bigfont;
1969 float i, stat_items, currently_selected;
1970 if (autocvar_hud_panel_ammo_onlycurrent)
1972 if(autocvar__hud_configure)
1974 DrawAmmoItem(pos, ammo_size, 2, true); //show rockets
1977 stat_items = getstati(STAT_ITEMS);
1978 for (i = 0; i < AMMO_COUNT; ++i) {
1979 currently_selected = stat_items & GetAmmoItemCode(i);
1980 if (currently_selected)
1982 DrawAmmoItem(pos, ammo_size, i, true);
1986 return; // nothing to display
1989 stat_items = getstati(STAT_ITEMS);
1990 for (i = 0; i < AMMO_COUNT; ++i) {
1991 currently_selected = stat_items & GetAmmoItemCode(i);
1992 DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected);
1997 column = column + 1;
2000 drawfont = hud_font;
2003 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float alpha)
2005 vector newPos, newSize;
2006 vector picpos, numpos;
2010 if(mySize_y/mySize_x > 2)
2012 newSize_y = 2 * mySize_x;
2013 newSize_x = mySize_x;
2015 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
2020 newSize_x = 1/2 * mySize_y;
2021 newSize_y = mySize_y;
2023 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
2027 if(icon_right_align)
2030 picpos = newPos + eY * newSize_x;
2035 numpos = newPos + eY * newSize_x;
2039 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2040 // make number smaller than icon, it looks better
2041 // reduce only y to draw numbers with different number of digits with the same y size
2042 numpos_y += newSize_y * ((1 - 0.7) / 2);
2044 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2048 if(mySize_x/mySize_y > 3)
2050 newSize_x = 3 * mySize_y;
2051 newSize_y = mySize_y;
2053 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
2058 newSize_y = 1/3 * mySize_x;
2059 newSize_x = mySize_x;
2061 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
2065 if(icon_right_align) // right align
2068 picpos = newPos + eX * 2 * newSize_y;
2072 numpos = newPos + eX * newSize_y;
2076 drawstring_aspect(numpos, ftos(x), '2 1 0' * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2077 drawpic_aspect_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2080 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float fadelerp)
2083 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
2085 DrawNumIcon(myPos + expandingbox_resize_centered_box_offset(sz, mySize, 1), mySize * sz, x, icon, vertical, icon_right_align, color, (1 - fadelerp));
2090 void HUD_Powerups(void) {
2091 if(!autocvar__hud_configure)
2093 if(!autocvar_hud_panel_powerups) return;
2094 if(spectatee_status == -1) return;
2095 if not(getstati(STAT_ITEMS) & (IT_STRENGTH | IT_INVINCIBLE)) return;
2096 if (getstati(STAT_HEALTH) <= 0) return;
2099 active_panel = HUD_PANEL_POWERUPS;
2100 HUD_Panel_UpdateCvars(powerups);
2103 mySize = panel_size;
2105 float strength_time, shield_time;
2106 if(autocvar__hud_configure)
2113 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
2114 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
2117 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
2118 if(panel_bg_padding)
2120 pos += '1 1 0' * panel_bg_padding;
2121 mySize -= '2 2 0' * panel_bg_padding;
2124 vector barpos, barsize;
2128 string leftname, rightname;
2129 float leftcnt, rightcnt;
2130 float leftexact, rightexact;
2131 if (cvar("hud_panel_powerups_flip")) {
2132 leftname = "strength";
2133 leftcnt = ceil(strength_time);
2134 leftexact = strength_time;
2136 rightname = "shield";
2137 rightcnt = ceil(shield_time);
2138 rightexact = shield_time;
2140 leftname = "shield";
2141 leftcnt = ceil(shield_time);
2142 leftexact = shield_time;
2144 rightname = "strength";
2145 rightcnt = ceil(strength_time);
2146 rightexact = strength_time;
2149 drawfont = hud_bigfont;
2150 float baralign = cvar("hud_panel_powerups_baralign");
2151 float iconalign = cvar("hud_panel_powerups_iconalign");
2152 float progressbar = cvar("hud_panel_powerups_progressbar");
2153 float panel_ar = mySize_x/mySize_y;
2154 float is_vertical = (panel_ar < 1);
2155 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
2161 HUD_Panel_GetProgressBarColorForString(leftname);
2162 HUD_Panel_DrawProgressBar(pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt/30, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2165 DrawNumIcon(pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
2167 DrawNumIcon_expanding(pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2174 HUD_Panel_GetProgressBarColorForString(rightname);
2175 HUD_Panel_DrawProgressBar(pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt/30, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2178 DrawNumIcon(pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
2180 DrawNumIcon_expanding(pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
2189 HUD_Panel_GetProgressBarColorForString(leftname);
2190 HUD_Panel_DrawProgressBar(pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt/30, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2193 DrawNumIcon(pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
2195 DrawNumIcon_expanding(pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2202 HUD_Panel_GetProgressBarColorForString(rightname);
2203 HUD_Panel_DrawProgressBar(pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt/30, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2206 DrawNumIcon(pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
2208 DrawNumIcon_expanding(pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
2211 drawfont = hud_font;
2214 // Health/armor (#3)
2216 void HUD_HealthArmor(void)
2218 if(!autocvar__hud_configure)
2220 if(!autocvar_hud_panel_healtharmor) return;
2221 if(spectatee_status == -1) return;
2224 active_panel = HUD_PANEL_HEALTHARMOR;
2225 HUD_Panel_UpdateCvars(healtharmor);
2228 mySize = panel_size;
2230 HUD_Panel_DrawBg(1);
2231 if(panel_bg_padding)
2233 pos += '1 1 0' * panel_bg_padding;
2234 mySize -= '2 2 0' * panel_bg_padding;
2237 float armor, health, fuel;
2238 armor = getstati(STAT_ARMOR);
2239 health = getstati(STAT_HEALTH);
2240 fuel = getstati(STAT_FUEL);
2242 if(autocvar__hud_configure)
2252 vector barpos, barsize;
2253 vector picpos, numpos;
2255 drawfont = hud_bigfont;
2256 float baralign = cvar("hud_panel_healtharmor_baralign");
2257 float iconalign = cvar("hud_panel_healtharmor_iconalign");
2258 float progressbar = cvar("hud_panel_healtharmor_progressbar");
2259 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
2262 v = healtharmor_maxdamage(health, armor, armorblockpercent);
2268 if(v_z) // NOT fully armored
2270 biggercount = "health";
2273 HUD_Panel_GetProgressBarColor(health);
2274 HUD_Panel_DrawProgressBar(pos, mySize, x/400, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2277 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);
2281 biggercount = "armor";
2284 HUD_Panel_GetProgressBarColor(armor);
2285 HUD_Panel_DrawProgressBar(pos, mySize, x/400, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2288 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);
2290 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, 2 * 200), 1);
2294 HUD_Panel_GetProgressBarColor(fuel);
2295 HUD_Panel_DrawProgressBar(pos, eX * mySize_x + eY * 0.2 * mySize_y, fuel/100, 0, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2300 string leftname, rightname;
2301 float leftcnt, rightcnt;
2302 float leftactive, rightactive;
2303 float leftalpha, rightalpha;
2304 if (cvar("hud_panel_healtharmor_flip")) { // layout with armor left/top of health
2309 leftalpha = min((armor+10)/55, 1);
2311 rightname = "health";
2316 leftname = "health";
2321 rightname = "armor";
2325 rightalpha = min((armor+10)/55, 1);
2328 float panel_ar = mySize_x/mySize_y;
2329 float is_vertical = (panel_ar < 1);
2330 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
2336 HUD_Panel_GetProgressBarColorForString(leftname);
2337 HUD_Panel_DrawProgressBar(pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt/200, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2339 DrawNumIcon(pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, 200), 1);
2346 HUD_Panel_GetProgressBarColorForString(rightname);
2347 HUD_Panel_DrawProgressBar(pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt/200, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2349 DrawNumIcon(pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, 200), 1);
2354 HUD_Panel_GetProgressBarColor(fuel);
2355 if (is_vertical) //if vertical always halve x to not cover too much numbers with 3 digits
2356 mySize_x *= 0.2 * 0.5 / 2;
2359 HUD_Panel_DrawProgressBar(pos, mySize, fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2368 HUD_Panel_GetProgressBarColorForString(leftname);
2369 HUD_Panel_DrawProgressBar(pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt/200, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2371 DrawNumIcon(pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, 200), 1);
2378 HUD_Panel_GetProgressBarColorForString(rightname);
2379 HUD_Panel_DrawProgressBar(pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt/200, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2381 DrawNumIcon(pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, 200), 1);
2386 HUD_Panel_GetProgressBarColor(fuel);
2387 if (is_vertical) //if vertical always halve x to not cover numbers with 3 digits
2388 mySize_x *= 0.2 / 2;
2390 mySize_y *= 0.2 * 0.5;
2391 HUD_Panel_DrawProgressBar(pos, mySize, fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2395 drawfont = hud_font;
2398 // Notification area (#4)
2401 string Weapon_SuicideMessage(float deathtype)
2403 w_deathtype = deathtype;
2404 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2405 return w_deathtypestring;
2408 string Weapon_KillMessage(float deathtype)
2410 w_deathtype = deathtype;
2411 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2412 return w_deathtypestring;
2415 #define KN_MAX_ENTRIES 10
2417 float killnotify_times[KN_MAX_ENTRIES];
2418 float killnotify_deathtype[KN_MAX_ENTRIES];
2419 float killnotify_actiontype[KN_MAX_ENTRIES]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2420 string killnotify_attackers[KN_MAX_ENTRIES];
2421 string killnotify_victims[KN_MAX_ENTRIES];
2422 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2426 kn_index = KN_MAX_ENTRIES-1;
2427 killnotify_times[kn_index] = time;
2428 killnotify_deathtype[kn_index] = wpn;
2429 killnotify_actiontype[kn_index] = actiontype;
2430 if(killnotify_attackers[kn_index])
2431 strunzone(killnotify_attackers[kn_index]);
2432 killnotify_attackers[kn_index] = strzone(attacker);
2433 if(killnotify_victims[kn_index])
2434 strunzone(killnotify_victims[kn_index]);
2435 killnotify_victims[kn_index] = strzone(victim);
2438 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
2441 float alsoprint, gentle;
2442 alsoprint = (cvar("hud_panel_notify_print") || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
2443 gentle = (cvar("cl_gentle") || cvar("cl_gentle_messages"));
2445 if ((msg == MSG_SUICIDE || msg == MSG_KILL || msg == MSG_KILL_ACTION) && gametype == GAME_CTS) // selfkill isn't interesting in CTS and only spams up the notify panel
2448 if(msg == MSG_SUICIDE) {
2449 w = DEATH_WEAPONOF(type);
2451 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2453 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
2454 } else if (type == DEATH_KILL) {
2455 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2457 print ("^1",s1, "^1 couldn't take it anymore\n");
2458 } else if (type == DEATH_ROT) {
2459 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2461 print ("^1",s1, "^1 died\n");
2462 } else if (type == DEATH_NOAMMO) {
2463 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2465 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2466 } else if (type == DEATH_CAMP) {
2467 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2469 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2470 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2471 HUD_KillNotify_Push(s1, "", 0, type);
2473 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2474 } else if (type == DEATH_CHEAT) {
2475 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2477 print ("^1",s1, "^1 unfairly eliminated themself\n");
2478 } else if (type == DEATH_FIRE) {
2479 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2481 print ("^1",s1, "^1 burned to death\n");
2482 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2483 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2485 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2488 if (stof(s2) > 2) // killcount > 2
2489 print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2490 } else if(msg == MSG_KILL) {
2491 w = DEATH_WEAPONOF(type);
2493 if((w == WEP_CAMPINGRIFLE || w == WEP_MINSTANEX) && type & HITTYPE_HEADSHOT) // all headshot weapons go here
2494 HUD_KillNotify_Push(s1, s2, 1, DEATH_HEADSHOT);
2496 HUD_KillNotify_Push(s1, s2, 1, type);
2499 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
2501 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2502 HUD_KillNotify_Push(s1, s2, 1, type);
2506 print ("^1", s1, "^1 took action against a team mate\n");
2508 print ("^1", s1, "^1 mows down a team mate\n");
2511 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2513 print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2515 print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2517 else if (stof(s2) > 2) {
2519 print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2521 print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2524 else if(type == KILL_FIRST_BLOOD)
2525 print("^1",s1, "^1 drew first blood", "\n");
2526 else if (type == DEATH_TELEFRAG) {
2527 HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
2529 print ("^1",s2, "^1 tried to occupy ", s1, "^1's teleport destination space\n");
2531 print ("^1",s2, "^1 was telefragged by ", s1, "\n");
2533 else if (type == DEATH_DROWN) {
2534 HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
2536 print ("^1",s2, "^1 was drowned by ", s1, "\n");
2538 else if (type == DEATH_SLIME) {
2539 HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
2541 print ("^1",s2, "^1 was slimed by ", s1, "\n");
2543 else if (type == DEATH_LAVA) {
2544 HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
2546 print ("^1",s2, "^1 was cooked by ", s1, "\n");
2548 else if (type == DEATH_FALL) {
2549 HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
2551 print ("^1",s2, "^1 was grounded by ", s1, "\n");
2553 else if (type == DEATH_SHOOTING_STAR) {
2554 HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
2556 print ("^1",s2, "^1 was shot into space by ", s1, "\n");
2558 else if (type == DEATH_SWAMP) {
2559 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2561 print ("^1",s2, "^1 was conserved by ", s1, "\n");
2563 else if (type == DEATH_HURTTRIGGER)
2565 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2567 print("^1",s2, "^1 was thrown into a world of hurt by ", s1, "\n");
2568 } else if(type == DEATH_SBCRUSH) {
2569 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2571 print ("^1",s2, "^1 was crushed by ^1", s1, "\n");
2572 } else if(type == DEATH_SBMINIGUN) {
2573 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2575 print ("^1",s2, "^1 got shredded by ^1", s1, "\n");
2576 } else if(type == DEATH_SBROCKET) {
2577 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2579 print ("^1",s2, "^1 was blased to bits by ^1", s1, "\n");
2580 } else if(type == DEATH_SBBLOWUP) {
2581 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2583 print ("^1",s2, "^1 got caught in the destruction of ^1", s1, "'s vehicle\n");
2584 } else if(type == DEATH_WAKIGUN) {
2585 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2587 print ("^1",s2, "^1 was bolted down by ^1", s1, "\n");
2588 } else if(type == DEATH_WAKIROCKET) {
2589 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2591 print ("^1",s2, "^1 could find no shelter from ^1", s1, "'s rockets\n");
2592 } else if(type == DEATH_WAKIBLOWUP) {
2593 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2595 print ("^1",s2, "^1 dies when ^1", s1, "'s wakizashi dies.\n");
2596 } else if(type == DEATH_TURRET) {
2597 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2599 print ("^1",s2, "^1 was pushed into the line of fire by ^1", s1, "\n");
2600 } else if(type == DEATH_TOUCHEXPLODE) {
2601 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2603 print ("^1",s2, "^1 was pushed into an accident by ^1", s1, "\n");
2604 } else if(type == DEATH_CHEAT) {
2605 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2607 print ("^1",s2, "^1 was unfairly eliminated by ^1", s1, "\n");
2608 } else if (type == DEATH_FIRE) {
2609 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2611 print ("^1",s2, "^1 was burnt to death by ^1", s1, "\n");
2612 } else if (type == DEATH_CUSTOM) {
2613 HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
2615 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2616 } else if (type == DEATH_HURTTRIGGER) {
2617 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2619 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2621 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2623 print ("^1",s2, "^1 was fragged by ", s1, "\n");
2625 } else if(msg == MSG_SPREE) {
2626 if(type == KILL_END_SPREE) {
2628 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2630 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2631 } else if(type == KILL_SPREE) {
2633 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2635 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2636 } else if(type == KILL_SPREE_3) {
2638 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2640 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2641 } else if(type == KILL_SPREE_5) {
2643 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2645 print (s1,"^7 unleashes ^1RAGE\n");
2646 } else if(type == KILL_SPREE_10) {
2648 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2650 print (s1,"^7 starts the ^1MASSACRE!\n");
2651 } else if(type == KILL_SPREE_15) {
2653 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2655 print (s1,"^7 executes ^1MAYHEM!\n");
2656 } else if(type == KILL_SPREE_20) {
2658 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2660 print (s1,"^7 is a ^1BERSERKER!\n");
2661 } else if(type == KILL_SPREE_25) {
2663 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2665 print (s1,"^7 inflicts ^1CARNAGE!\n");
2666 } else if(type == KILL_SPREE_30) {
2668 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2670 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2672 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2673 if (type == DEATH_DROWN) {
2674 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2678 print ("^1",s1, "^1 was in the water for too long\n");
2680 print ("^1",s1, "^1 drowned\n");
2682 } else if (type == DEATH_SLIME) {
2683 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2685 print ("^1",s1, "^1 was slimed\n");
2686 } else if (type == DEATH_LAVA) {
2687 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2691 print ("^1",s1, "^1 found a hot place\n");
2693 print ("^1",s1, "^1 turned into hot slag\n");
2695 } else if (type == DEATH_FALL) {
2696 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2700 print ("^1",s1, "^1 tested gravity (and it worked)\n");
2702 print ("^1",s1, "^1 hit the ground with a crunch\n");
2704 } else if (type == DEATH_SHOOTING_STAR) {
2705 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2707 print ("^1",s1, "^1 became a shooting star\n");
2708 } else if (type == DEATH_SWAMP) {
2709 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2713 print ("^1",s1, "^1 discovered a swamp\n");
2715 print ("^1",s1, "^1 is now conserved for centuries to come\n");
2717 } else if(type == DEATH_TURRET) {
2718 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2720 print ("^1",s1, "^1 was mowed down by a turret \n");
2721 } else if (type == DEATH_CUSTOM) {
2722 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2724 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2725 } else if (type == DEATH_HURTTRIGGER) {
2726 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2728 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2729 } else if(type == DEATH_TOUCHEXPLODE) {
2730 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2732 print ("^1",s1, "^1 died in an accident\n");
2733 } else if(type == DEATH_CHEAT) {
2734 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2736 print ("^1",s1, "^1 was unfairly eliminated\n");
2737 } else if(type == DEATH_FIRE) {
2738 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2742 print ("^1",s1, "^1 felt a little hot\n");
2744 print ("^1",s1, "^1 burnt to death\n");
2747 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2751 print ("^1",s1, "^1 needs a restart\n");
2753 print ("^1",s1, "^1 died\n");
2756 } else if(msg == MSG_KILL_ACTION_SPREE) {
2758 print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2760 print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2761 } else if(msg == MSG_INFO) {
2762 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2763 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2764 print(s1, "^7 got the ", s2, "\n");
2765 } else if(type == INFO_LOSTFLAG) {
2766 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2767 print(s1, "^7 lost the ", s2, "\n");
2768 } else if(type == INFO_PICKUPFLAG) {
2769 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2770 print(s1, "^7 picked up the ", s2, "\n");
2771 } else if(type == INFO_RETURNFLAG) {
2772 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2773 print(s1, "^7 returned the ", s2, "\n");
2774 } else if(type == INFO_CAPTUREFLAG) {
2775 HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
2776 print(s1, "^7 captured the ", s2, s3, "\n");
2778 } else if(msg == MSG_RACE) {
2779 if(type == RACE_SERVER_RECORD) {
2780 HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
2782 else if(type == RACE_NEW_RANK) {
2783 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
2785 else if(type == RACE_NEW_TIME) {
2786 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
2788 else if(type == RACE_FAIL) {
2789 HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
2794 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
2796 void HUD_Centerprint(string s1, string s2, float type, float msg)
2799 gentle = (cvar("cl_gentle") || cvar("cl_gentle_messages"));
2800 if(msg == MSG_SUICIDE) {
2801 if (type == DEATH_TEAMCHANGE) {
2802 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
2803 } else if (type == DEATH_AUTOTEAMCHANGE) {
2804 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
2805 } else if (type == DEATH_CAMP) {
2807 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
2809 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
2810 } else if (type == DEATH_NOAMMO) {
2812 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
2814 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
2815 } else if (type == DEATH_ROT) {
2817 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
2819 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
2820 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2822 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
2824 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
2825 } else if (type == DEATH_QUIET) {
2827 } else { // generic message
2829 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
2831 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
2833 } else if(msg == MSG_KILL) {
2834 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2836 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
2838 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
2840 } else if (type == KILL_FIRST_BLOOD) {
2842 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
2844 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
2846 } else if (type == KILL_FIRST_VICTIM) {
2848 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
2850 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
2852 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
2854 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
2856 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
2858 } else if (type == KILL_TYPEFRAGGED) {
2860 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
2862 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
2864 } else if (type == KILL_FRAG) {
2866 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
2868 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
2870 } else { // generic message
2872 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
2874 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
2877 } else if(msg == MSG_KILL_ACTION) {
2878 // TODO: invent more centerprints here?
2879 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
2883 void HUD_Notify (void)
2885 if(!autocvar_hud_panel_notify && !autocvar__hud_configure)
2888 active_panel = HUD_PANEL_NOTIFY;
2889 HUD_Panel_UpdateCvars(notify);
2892 mySize = panel_size;
2894 HUD_Panel_DrawBg(1);
2895 if(panel_bg_padding)
2897 pos += '1 1 0' * panel_bg_padding;
2898 mySize -= '2 2 0' * panel_bg_padding;
2901 float entries, height;
2902 entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
2903 height = mySize_y/entries;
2906 fontsize = '0.5 0.5 0' * height;
2910 when = cvar("hud_panel_notify_time");
2912 fadetime = cvar("hud_panel_notify_fadetime");
2916 vector pos_attacker, pos_victim;
2918 float width_attacker;
2919 string attacker, victim;
2921 float i, j, w, step, limit;
2922 if(cvar("hud_panel_notify_flip")) //order items from the top down
2928 else //order items from the bottom up
2935 for(j = kn_index; i != limit; i += step, ++j)
2937 if(autocvar__hud_configure)
2941 else // inverse order
2942 a = entries - 1 - i;
2943 attacker = textShortenToWidth(strcat("Player", ftos(a+1)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2944 victim = textShortenToWidth(strcat("Player", ftos(a+2)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2945 s = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
2946 a = bound(0, (when - a) / 4, 1);
2947 goto hud_config_notifyprint;
2950 if (j == KN_MAX_ENTRIES)
2953 if(killnotify_times[j] + when > time)
2957 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2971 w = DEATH_WEAPONOF(killnotify_deathtype[j]);
2973 // TODO: maybe print in team colors?
2976 if(killnotify_actiontype[j] == 0)
2978 if(killnotify_deathtype[j] == DEATH_GENERIC)
2982 else if(killnotify_deathtype[j] == DEATH_NOAMMO)
2984 s = "notify_outofammo";
2986 else if(killnotify_deathtype[j] == DEATH_KILL)
2988 s = "notify_selfkill";
2990 else if(killnotify_deathtype[j] == DEATH_CAMP)
2992 s = "notify_camping";
2994 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2996 s = "notify_teamkill_red";
2998 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
3000 s = "notify_teamkill_blue";
3002 else if(killnotify_deathtype[j] == DEATH_DROWN)
3006 else if(killnotify_deathtype[j] == DEATH_SLIME)
3010 else if(killnotify_deathtype[j] == DEATH_LAVA)
3014 else if(killnotify_deathtype[j] == DEATH_FALL)
3018 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
3020 s = "notify_shootingstar";
3022 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
3026 else if(killnotify_deathtype[j] == INFO_GOTFLAG)
3028 if(killnotify_victims[j] == "^1RED^7 flag")
3030 s = "notify_red_taken";
3034 s = "notify_blue_taken";
3037 else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
3039 if(killnotify_victims[j] == "^1RED^7 flag")
3041 s = "notify_red_returned";
3045 s = "notify_blue_returned";
3048 else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
3050 if(killnotify_victims[j] == "^1RED^7 flag")
3052 s = "notify_red_lost";
3056 s = "notify_blue_lost";
3059 else if(killnotify_deathtype[j] == INFO_CAPTUREFLAG)
3061 if(killnotify_victims[j] == "^1RED^7 flag")
3063 s = "notify_red_captured";
3067 s = "notify_blue_captured";
3070 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3071 pos_attacker = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
3072 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
3076 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3077 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3080 // X [did action to] Y
3083 if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_LASER)
3085 s = "notify_melee_laser";
3087 else if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_SHOTGUN)
3089 s = "notify_melee_shotgun";
3091 else if(WEP_VALID(w))
3093 self = get_weaponinfo(w);
3094 s = strcat("weapon", self.netname);
3096 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
3098 s = "notify_teamkill_red";
3100 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
3102 s = "notify_teamkill_red";
3104 else if(killnotify_deathtype[j] == DEATH_TELEFRAG)
3106 s = "notify_telefrag";
3108 else if(killnotify_deathtype[j] == DEATH_DROWN)
3112 else if(killnotify_deathtype[j] == DEATH_SLIME)
3116 else if(killnotify_deathtype[j] == DEATH_LAVA)
3120 else if(killnotify_deathtype[j] == DEATH_FALL)
3124 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
3126 s = "notify_shootingstar";
3128 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
3132 else if(killnotify_deathtype[j] == DEATH_HEADSHOT)
3134 s = "notify_headshot";
3136 else if(killnotify_deathtype[j] == RACE_SERVER_RECORD)
3138 s = "race_newrecordserver";
3140 else if(killnotify_deathtype[j] == RACE_NEW_RANK)
3142 s = "race_newrankyellow";
3144 else if(killnotify_deathtype[j] == RACE_NEW_TIME)
3148 else if(killnotify_deathtype[j] == RACE_FAIL)
3153 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3154 victim = textShortenToWidth(killnotify_victims[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3155 :hud_config_notifyprint
3156 width_attacker = stringwidth(attacker, TRUE, fontsize);
3157 pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * (0.5 * fontsize_y + i * height);
3158 pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
3159 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
3163 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3164 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3165 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3174 string seconds_tostring(float sec)
3177 minutes = floor(sec / 60);
3179 sec -= minutes * 60;
3182 s = ftos(100 + sec);
3184 return strcat(ftos(minutes), ":", substring(s, 1, 3));
3187 void HUD_Timer(void)
3189 if(!autocvar_hud_panel_timer && !autocvar__hud_configure)
3192 active_panel = HUD_PANEL_TIMER;
3193 HUD_Panel_UpdateCvars(timer);
3196 mySize = panel_size;
3198 HUD_Panel_DrawBg(1);
3199 if(panel_bg_padding)
3201 pos += '1 1 0' * panel_bg_padding;
3202 mySize -= '2 2 0' * panel_bg_padding;
3206 float timelimit, elapsedTime, timeleft, minutesLeft;
3208 timelimit = getstatf(STAT_TIMELIMIT);
3210 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
3211 timeleft = ceil(timeleft);
3213 minutesLeft = floor(timeleft / 60);
3216 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
3217 timer_color = '1 1 1'; //white
3218 else if(minutesLeft >= 1)
3219 timer_color = '1 1 0'; //yellow
3221 timer_color = '1 0 0'; //red
3223 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
3224 if (time < getstatf(STAT_GAMESTARTTIME)) {
3225 //while restart is still active, show 00:00
3226 timer = seconds_tostring(0);
3228 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
3229 timer = seconds_tostring(elapsedTime);
3232 timer = seconds_tostring(timeleft);
3235 drawfont = hud_bigfont;
3236 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3237 drawfont = hud_font;
3242 void HUD_Radar(void)
3244 if ((autocvar_hud_panel_radar == 0 || (autocvar_hud_panel_radar != 2 && !teamplay)) && !autocvar__hud_configure)
3247 active_panel = HUD_PANEL_RADAR;
3248 HUD_Panel_UpdateCvars(radar);
3251 mySize = panel_size;
3253 HUD_Panel_DrawBg(1);
3254 if(panel_bg_padding)
3256 pos += '1 1 0' * panel_bg_padding;
3257 mySize -= '2 2 0' * panel_bg_padding;
3262 float scale2d, normalsize, bigsize;
3265 teamradar_origin2d = pos + 0.5 * mySize;
3266 teamradar_size2d = mySize;
3268 if(minimapname == "")
3271 teamradar_loadcvars();
3273 switch(hud_panel_radar_zoommode)
3277 f = current_zoomfraction;
3280 f = 1 - current_zoomfraction;
3290 switch(hud_panel_radar_rotation)
3293 teamradar_angle = view_angles_y - 90;
3296 teamradar_angle = 90 * hud_panel_radar_rotation;
3300 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
3301 teamradar_size2d = mySize;
3303 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
3305 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
3306 if(hud_panel_radar_rotation == 0)
3308 // max-min distance must fit the radar in any rotation
3309 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
3313 vector c0, c1, c2, c3, span;
3314 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
3315 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
3316 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
3317 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
3319 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
3320 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
3322 // max-min distance must fit the radar in x=x, y=y
3324 teamradar_size2d_x * scale2d / (1.05 * span_x),
3325 teamradar_size2d_y * scale2d / (1.05 * span_y)
3329 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
3330 if(bigsize > normalsize)
3331 normalsize = bigsize;
3335 + (1 - f) * normalsize;
3336 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
3337 f * (mi_min + mi_max) * 0.5
3338 + (1 - f) * view_origin);
3347 draw_teamradar_background(hud_panel_radar_foreground_alpha);
3349 for(tm = world; (tm = find(tm, classname, "radarlink")); )
3350 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
3351 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
3352 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
3353 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
3355 color2 = GetPlayerColor(tm.sv_entnum);
3356 //if(color == COLOR_SPECTATOR || color == color2)
3357 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
3359 draw_teamradar_player(view_origin, view_angles, '1 1 1');
3361 drawresetcliparea();
3366 void HUD_UpdatePlayerTeams();
3367 void HUD_Score(void)
3369 if(!autocvar__hud_configure && !autocvar_hud_panel_score)
3372 active_panel = HUD_PANEL_SCORE;
3373 HUD_Panel_UpdateCvars(score);
3376 mySize = panel_size;
3378 HUD_Panel_DrawBg(1);
3379 if(panel_bg_padding)
3381 pos += '1 1 0' * panel_bg_padding;
3382 mySize -= '2 2 0' * panel_bg_padding;
3385 float score, distribution;
3387 vector distribution_color;
3389 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
3391 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
3392 string timer, distrtimer;
3394 pl = players.sort_next;
3397 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
3398 if(pl.scores[ps_primary] == 0)
3401 score = me.(scores[ps_primary]);
3402 timer = TIME_ENCODED_TOSTRING(score);
3404 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
3405 // distribution display
3406 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3408 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
3410 if (distribution <= 0) {
3411 distribution_color = '0 1 0';
3415 distribution_color = '1 0 0';
3418 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);
3420 // race record display
3421 if (distribution <= 0)
3422 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3423 drawfont = hud_bigfont;
3424 drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3425 drawfont = hud_font;
3426 } else if (!teamplay) { // non-teamgames
3427 if ((spectatee_status == -1 && !autocvar__hud_configure) || cvar("hud_panel_score_rankings"))
3429 #define SCOREPANEL_MAX_ENTRIES 6
3430 #define SCOREPANEL_ASPECTRATIO 2
3431 float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
3432 float height = mySize_y/entries;
3433 vector fontsize = '0.9 0.9 0' * height;
3434 pos_y += height * (1 - 0.9) / 2;
3439 float name_size = mySize_x*0.75;
3440 float i, me_printed;
3442 if (autocvar__hud_configure)
3444 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
3445 for (i=0; i<entries; ++i)
3447 //simulate my score is lower than all displayed players,
3448 //so that I don't appear at all showing pure rankings.
3449 //This is to better show the difference between the 2 ranking views
3450 if (i == entries-1 && cvar("hud_panel_score_rankings") == 1)
3453 drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, 0.3 * panel_fg_alpha, DRAWFLAG_NORMAL);
3454 s = GetPlayerName(pl.sv_entnum);
3459 s = strcat("Player", ftos(i+1));
3463 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
3464 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
3465 drawstring(pos + eX * mySize_x*0.79, ftos(score), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3471 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
3472 HUD_UpdatePlayerTeams();
3474 for (pl = players.sort_next, i=0; pl && i<entries; pl = pl.sort_next, ++i)
3476 if (pl.team == COLOR_SPECTATOR)
3479 if (i == entries-1 && !me_printed && pl != me)
3480 if (cvar("hud_panel_score_rankings") == 1 && spectatee_status != -1)
3482 for (pl = me.sort_next; pl; pl = pl.sort_next)
3483 if (pl.team != COLOR_SPECTATOR)
3487 rgb = '1 1 0'; //not last but not among the leading players: yellow
3489 rgb = '1 0 0'; //last: red
3496 rgb = '0 1 0'; //first: green
3498 drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, 0.3 * panel_fg_alpha, DRAWFLAG_NORMAL);
3500 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
3501 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
3502 drawstring(pos + eX * mySize_x*0.79, ftos(pl.(scores[ps_primary])), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3507 // me vector := [team/connected frags id]
3508 pl = players.sort_next;
3512 if(autocvar__hud_configure)
3515 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3519 score = me.(scores[ps_primary]);
3520 if(autocvar__hud_configure)
3523 if(distribution >= 5)
3524 distribution_color = eY;
3525 else if(distribution >= 0)
3526 distribution_color = '1 1 1';
3527 else if(distribution >= -5)
3528 distribution_color = '1 1 0';
3530 distribution_color = eX;
3532 string distribution_str;
3533 distribution_str = ftos(distribution);
3534 if (distribution >= 0)
3536 if (distribution > 0)
3537 distribution_str = strcat("+", distribution_str);
3538 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3540 drawfont = hud_bigfont;
3541 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3542 drawfont = hud_font;
3543 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);
3544 } else { // teamgames
3545 float max_fragcount;
3546 max_fragcount = -99;
3548 float scores_count, row, column, rows, columns;
3550 vector score_pos, score_size; //for scores other than myteam
3551 if (spectatee_status == -1)
3553 if (autocvar__hud_configure)
3555 else for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3556 if(tm.team == COLOR_SPECTATOR)
3560 rows = mySize_y/mySize_x;
3561 rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
3562 // ^^^ ammo item aspect goes here
3564 columns = ceil(scores_count/rows);
3566 score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
3569 if(score_size_x/score_size_y > 3)
3571 newSize = 3 * score_size_y;
3572 offset_x = score_size_x - newSize;
3573 pos_x += offset_x/2;
3574 score_size_x = newSize;
3578 newSize = 1/3 * score_size_x;
3579 offset_y = score_size_y - newSize;
3580 pos_y += offset_y/2;
3581 score_size_y = newSize;
3585 score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
3586 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3587 if(tm.team == COLOR_SPECTATOR)
3589 score = tm.(teamscores[ts_primary]);
3590 if(autocvar__hud_configure)
3593 if (score > max_fragcount)
3594 max_fragcount = score;
3596 if (spectatee_status == -1)
3598 score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
3599 if (max_fragcount == score)
3600 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3601 drawfont = hud_bigfont;
3602 drawstring_aspect(score_pos, ftos(score), score_size, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3603 drawfont = hud_font;
3611 else if(tm.team == myteam) {
3612 if (max_fragcount == score)
3613 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3614 drawfont = hud_bigfont;
3615 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3616 drawfont = hud_font;
3618 if (max_fragcount == score)
3619 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);
3620 drawstring_aspect(pos + eX * 0.75 * mySize_x + eY * (1/3) * rows * mySize_y, ftos(score), score_size, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3629 void HUD_RaceTimer (void) {
3630 if(!autocvar__hud_configure)
3632 if(!autocvar_hud_panel_racetimer) return;
3633 if(!(gametype == GAME_RACE || gametype == GAME_CTS)) return;
3634 if(spectatee_status == -1) return;
3637 active_panel = HUD_PANEL_RACETIMER;
3638 HUD_Panel_UpdateCvars(racetimer);
3641 mySize = panel_size;
3643 HUD_Panel_DrawBg(1);
3644 if(panel_bg_padding)
3646 pos += '1 1 0' * panel_bg_padding;
3647 mySize -= '2 2 0' * panel_bg_padding;
3650 // always force 4:1 aspect
3652 if(mySize_x/mySize_y > 4)
3654 newSize_x = 4 * mySize_y;
3655 newSize_y = mySize_y;
3657 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3661 newSize_y = 1/4 * mySize_x;
3662 newSize_x = mySize_x;
3664 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3668 drawfont = hud_bigfont;
3670 string s, forcetime;
3672 if(autocvar__hud_configure)
3675 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);
3676 s = "^1Intermediate 1 (+15.42)";
3677 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);
3678 s = strcat("^1PENALTY: ", ftos_decimals(20 * 0.1, 1), " (missing a checkpoint)");
3679 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);
3681 else if(race_checkpointtime)
3683 a = bound(0, 2 - (time - race_checkpointtime), 1);
3686 if(a > 0) // just hit a checkpoint?
3688 if(race_checkpoint != 254)
3690 if(race_time && race_previousbesttime)
3691 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
3693 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
3695 forcetime = TIME_ENCODED_TOSTRING(race_time);
3700 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
3702 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
3703 if(a > 0) // next one?
3705 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
3710 if(s != "" && a > 0)
3712 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);
3715 if(race_penaltytime)
3717 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
3720 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
3721 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);
3727 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
3728 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);
3733 if(race_laptime && race_checkpoint != 255)
3735 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
3736 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);
3741 if(race_mycheckpointtime)
3743 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
3744 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
3745 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);
3747 if(race_othercheckpointtime && race_othercheckpointenemy != "")
3749 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
3750 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
3751 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);
3754 if(race_penaltytime && !race_penaltyaccumulator)
3756 t = race_penaltytime * 0.1 + race_penaltyeventtime;
3757 a = bound(0, (1 + t - time), 1);
3761 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
3763 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
3764 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);
3769 drawfont = hud_font;
3774 float vote_yescount;
3777 float vote_highlighted; // currently selected vote
3779 float vote_active; // is there an active vote?
3780 float vote_prev; // previous state of vote_active to check for a change
3782 float vote_change; // "time" when vote_active changed
3784 void HUD_VoteWindow(void)
3786 if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
3789 vote_called_vote = strzone(strcat("^2Name ^7instead of \"^1Unregistered player\"", " ^7in stats"));
3792 if(!autocvar_hud_panel_vote && !autocvar__hud_configure)
3795 if(!autocvar__hud_configure)
3797 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
3798 panel_bg_alpha_str = cvar_string("hud_panel_vote_bg_alpha");
3800 if(panel_bg_alpha_str == "") {
3801 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
3803 panel_bg_alpha = stof(panel_bg_alpha_str);
3808 if(vote_active != vote_prev) {
3810 vote_prev = vote_active;
3813 if(vote_active || autocvar__hud_configure)
3814 vote_alpha = bound(0, (time - vote_change) * 2, 1);
3816 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
3818 if(autocvar__hud_configure)
3828 active_panel = HUD_PANEL_VOTE;
3829 HUD_Panel_UpdateCvars(vote);
3832 mySize = panel_size;
3834 if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
3836 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
3837 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
3840 a = vote_alpha * bound(cvar("hud_panel_vote_alreadyvoted_alpha"), 1 - vote_highlighted, 1);
3841 HUD_Panel_DrawBg(a);
3842 a = panel_fg_alpha * a;
3844 if(panel_bg_padding)
3846 pos += '1 1 0' * panel_bg_padding;
3847 mySize -= '2 2 0' * panel_bg_padding;
3850 // always force 3:1 aspect
3852 if(mySize_x/mySize_y > 3)
3854 newSize_x = 3 * mySize_y;
3855 newSize_y = mySize_y;
3857 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3861 newSize_y = 1/3 * mySize_x;
3862 newSize_x = mySize_x;
3864 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3868 s = "A vote has been called for:";
3869 if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
3870 s = "Allow servers to store and display your name?";
3871 drawstring_aspect(pos, s, eX * mySize_x + eY * (2/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3872 s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (1/8), stringwidth_colors);
3873 if(autocvar__hud_configure)
3874 s = "^1Configure the HUD";
3875 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a, DRAWFLAG_NORMAL);
3877 // print the yes/no counts
3878 s = strcat("Yes (", getcommandkey("vyes", "vyes"), "): ", ftos(vote_yescount));
3879 if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
3880 s = strcat("Yes: (press y)");
3881 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);
3882 s = strcat("No (", getcommandkey("vno", "vno"), "): ", ftos(vote_nocount));
3883 if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
3884 s = strcat("No: (press n)");
3885 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);
3887 // draw the progress bar backgrounds
3888 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_back", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3890 // draw the highlights
3891 if(vote_highlighted == 1) {
3892 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3893 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3895 else if(vote_highlighted == 2) {
3896 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3897 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3900 // draw the progress bars
3901 if(vote_yescount && vote_needed)
3903 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3904 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3907 if(vote_nocount && vote_needed)
3909 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3910 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3913 drawresetcliparea();
3916 vote_highlighted = 0;
3920 // Mod icons panel (#10)
3923 float mod_active; // is there any active mod icon?
3925 // Clan Arena HUD modicons
3926 void HUD_Mod_CA(vector pos, vector mySize)
3928 mod_active = 1; // CA should never hide the mod icons panel
3929 float redalive, bluealive;
3930 redalive = getstati(STAT_REDALIVE);
3931 bluealive = getstati(STAT_BLUEALIVE);
3933 drawfont = hud_bigfont;
3934 vector redpos, bluepos;
3935 if(mySize_x > mySize_y)
3938 bluepos = pos + eY * 0.5 * mySize_y;
3939 drawpic_aspect_skin(redpos, "player_red.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3940 drawstring_aspect(redpos + eX * 0.5 * mySize_x, ftos(redalive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3941 drawpic_aspect_skin(bluepos, "player_blue.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3942 drawstring_aspect(bluepos + eX * 0.5 * mySize_x, ftos(bluealive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3947 bluepos = pos + eY * 0.5 * mySize_y;
3948 drawpic_aspect_skin(redpos, "player_red.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3949 drawstring_aspect(redpos + eY * 0.3 * mySize_y, ftos(redalive), eX * mySize_x + eY * 0.2 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3950 drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3951 drawstring_aspect(bluepos + eY * 0.3 * mySize_y, ftos(bluealive), eX * mySize_x + eY * 0.2 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3953 drawfont = hud_font;
3956 // CTF HUD modicon section
3957 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3958 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3959 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3961 void HUD_Mod_CTF_Reset(void)
3963 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3966 void HUD_Mod_CTF(vector pos, vector mySize)
3968 vector redflag_pos, blueflag_pos;
3970 float f; // every function should have that
3972 float redflag, blueflag; // current status
3973 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3976 stat_items = getstati(STAT_ITEMS);
3977 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3978 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3980 if(redflag || blueflag)
3985 if(autocvar__hud_configure)
3991 // when status CHANGES, set old status into prevstatus and current status into status
3992 if (redflag != redflag_prevframe)
3994 redflag_statuschange_time = time;
3995 redflag_prevstatus = redflag_prevframe;
3996 redflag_prevframe = redflag;
3999 if (blueflag != blueflag_prevframe)
4001 blueflag_statuschange_time = time;
4002 blueflag_prevstatus = blueflag_prevframe;
4003 blueflag_prevframe = blueflag;
4006 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
4007 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
4009 float BLINK_FACTOR = 0.15;
4010 float BLINK_BASE = 0.85;
4012 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
4014 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
4016 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
4018 string red_icon, red_icon_prevstatus;
4019 float red_alpha, red_alpha_prevstatus;
4020 red_alpha = red_alpha_prevstatus = 1;
4022 case 1: red_icon = "flag_red_taken"; break;
4023 case 2: red_icon = "flag_red_lost"; break;
4024 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4026 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
4027 red_icon = "flag_red_shielded";
4029 red_icon = string_null;
4032 switch(redflag_prevstatus) {
4033 case 1: red_icon_prevstatus = "flag_red_taken"; break;
4034 case 2: red_icon_prevstatus = "flag_red_lost"; break;
4035 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4038 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
4039 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
4040 red_icon_prevstatus = "flag_red_shielded";
4042 red_icon_prevstatus = string_null;
4046 string blue_icon, blue_icon_prevstatus;
4047 float blue_alpha, blue_alpha_prevstatus;
4048 blue_alpha = blue_alpha_prevstatus = 1;
4050 case 1: blue_icon = "flag_blue_taken"; break;
4051 case 2: blue_icon = "flag_blue_lost"; break;
4052 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4054 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
4055 blue_icon = "flag_blue_shielded";
4057 blue_icon = string_null;
4060 switch(blueflag_prevstatus) {
4061 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
4062 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
4063 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4066 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
4067 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
4068 blue_icon_prevstatus = "flag_blue_shielded";
4070 blue_icon_prevstatus = string_null;
4074 if(mySize_x > mySize_y) {
4075 if (myteam == COLOR_TEAM1) { // always draw own flag on left
4077 blueflag_pos = pos + eX * 0.5 * mySize_x;
4080 redflag_pos = pos + eX * 0.5 * mySize_x;
4082 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
4084 if (myteam == COLOR_TEAM1) { // always draw own flag on left
4086 blueflag_pos = pos + eY * 0.5 * mySize_y;
4089 redflag_pos = pos + eY * 0.5 * mySize_y;
4091 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
4094 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
4095 if(red_icon_prevstatus && f < 1)
4096 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
4098 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
4100 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
4101 if(blue_icon_prevstatus && f < 1)
4102 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
4104 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
4107 // Keyhunt HUD modicon section
4108 float kh_runheretime;
4110 void HUD_Mod_KH_Reset(void)
4115 void HUD_Mod_KH(vector pos, vector mySize)
4117 mod_active = 1; // keyhunt should never hide the mod icons panel
4121 vector p, pa, kh_size, kh_asize;
4123 kh_keys = getstati(STAT_KH_KEYS);
4126 if(mySize_x > mySize_y)
4128 p_y = pos_y + 0.25 * mySize_y;
4129 pa = p - eY * 0.25 * mySize_y;
4131 kh_size_x = mySize_x * 0.25;
4132 kh_size_y = 0.75 * mySize_y;
4133 kh_asize_x = mySize_x * 0.25;
4134 kh_asize_y = mySize_y * 0.25;
4138 p_y = pos_y + 0.125 * mySize_y;
4139 pa = p - eY * 0.125 * mySize_y;
4141 kh_size_x = mySize_x * 0.5;
4142 kh_size_y = 0.375 * mySize_y;
4143 kh_asize_x = mySize_x * 0.5;
4144 kh_asize_y = mySize_y * 0.125;
4151 for(i = 0; i < 4; ++i)
4153 key = floor(kh_keys / pow(32, i)) & 31;
4155 if(keyteam == 30 && keycount <= 4)
4157 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
4161 // this yields 8 exactly if "RUN HERE" shows
4166 kh_runheretime = time;
4167 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
4172 for(i = 0; i < 4; ++i)
4174 key = floor(kh_keys / pow(32, i)) & 31;
4187 default: // owned or dropped
4192 a = a * panel_fg_alpha;
4193 aa = aa * panel_fg_alpha;
4199 drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4202 drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4205 drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4208 drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4213 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
4216 drawpic_aspect_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4219 drawpic_aspect_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4222 drawpic_aspect_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4225 drawpic_aspect_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4229 if(mySize_x > mySize_y)
4231 p_x += 0.25 * mySize_x;
4232 pa_x += 0.25 * mySize_x;
4238 p_y = pos_y + 0.625 * mySize_y;
4239 pa_y = pos_y + 0.5 * mySize_y;
4245 p_x += 0.5 * mySize_x;
4246 pa_x += 0.5 * mySize_x;
4252 // Nexball HUD mod icon
4253 void HUD_Mod_NexBall(vector pos, vector mySize)
4255 float stat_items, nb_pb_starttime, dt, p;
4257 stat_items = getstati(STAT_ITEMS);
4258 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
4260 if (stat_items & IT_KEY1)
4265 //Manage the progress bar if any
4266 if (nb_pb_starttime > 0)
4268 dt = mod(time - nb_pb_starttime, nb_pb_period);
4269 // one period of positive triangle
4270 p = 2 * dt / nb_pb_period;
4277 HUD_Panel_GetProgressBarColor(nexball);
4278 if(mySize_x > mySize_y)
4279 HUD_Panel_DrawProgressBar(pos, mySize, p, 0, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4281 HUD_Panel_DrawProgressBar(pos, mySize, p, 1, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4284 if (stat_items & IT_KEY1)
4285 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4288 // Race/CTS HUD mod icons
4289 float crecordtime_prev; // last remembered crecordtime
4290 float crecordtime_change_time; // time when crecordtime last changed
4291 float srecordtime_prev; // last remembered srecordtime
4292 float srecordtime_change_time; // time when srecordtime last changed
4294 float race_status_time;
4295 float race_status_prev;
4296 string race_status_name_prev;
4297 void HUD_Mod_Race(vector pos, vector mySize)
4299 mod_active = 1; // race should never hide the mod icons panel
4301 me = playerslots[player_localentnum - 1];
4303 float f; // yet another function has this
4304 score = me.(scores[ps_primary]);
4306 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
4307 return; // no records in the actual race
4309 drawfont = hud_bigfont;
4311 // clientside personal record
4313 if(gametype == GAME_CTS)
4317 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
4319 if(score && (score < t || !t)) {
4320 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
4321 if(cvar("cl_autodemo_delete_keeprecords"))
4323 f = cvar("cl_autodemo_delete");
4325 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
4329 if(t != crecordtime_prev) {
4330 crecordtime_prev = t;
4331 crecordtime_change_time = time;
4334 vector textPos, medalPos;
4336 if(mySize_x > mySize_y) {
4337 // text on left side
4338 squareSize = min(mySize_y, mySize_x/2);
4339 textPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eY * 0.5 * (mySize_y - squareSize);
4340 medalPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eX * 0.5 * mySize_x + eY * 0.5 * (mySize_y - squareSize);
4343 squareSize = min(mySize_x, mySize_y/2);
4344 textPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eX * 0.5 * (mySize_x - squareSize);
4345 medalPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eY * 0.5 * mySize_y + eX * 0.5 * (mySize_x - squareSize);
4348 f = time - crecordtime_change_time;
4351 drawstring_aspect(textPos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4352 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);
4354 drawstring_aspect(textPos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4355 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);
4356 drawstring_aspect_expanding(pos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
4357 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);
4361 t = race_server_record;
4362 if(t != srecordtime_prev) {
4363 srecordtime_prev = t;
4364 srecordtime_change_time = time;
4366 f = time - srecordtime_change_time;
4369 drawstring_aspect(textPos + eY * 0.5 * squareSize, "Server best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4370 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);
4372 drawstring_aspect(textPos + eY * 0.5 * squareSize, "Server best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4373 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);
4374 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);
4375 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);
4378 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
4379 race_status_time = time + 5;
4380 race_status_prev = race_status;
4381 if (race_status_name_prev)
4382 strunzone(race_status_name_prev);
4383 race_status_name_prev = strzone(race_status_name);
4388 a = bound(0, race_status_time - time, 1);
4391 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
4395 rank = race_CheckName(race_status_name);
4397 rankname = race_PlaceName(rank);
4400 namepos = medalPos + '0 0.8 0' * squareSize;
4402 rankpos = medalPos + '0 0.15 0' * squareSize;
4404 if(race_status == 0)
4405 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4406 else if(race_status == 1) {
4407 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);
4408 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4409 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4410 } else if(race_status == 2) {
4411 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
4412 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);
4414 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);
4415 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4416 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4417 } else if(race_status == 3) {
4418 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);
4419 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4420 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4423 if (race_status_time - time <= 0) {
4424 race_status_prev = -1;
4426 if(race_status_name)
4427 strunzone(race_status_name);
4428 race_status_name = string_null;
4429 if(race_status_name_prev)
4430 strunzone(race_status_name_prev);
4431 race_status_name_prev = string_null;
4433 drawfont = hud_font;
4436 float mod_prev; // previous state of mod_active to check for a change
4438 float mod_change; // "time" when mod_active changed
4440 void HUD_ModIcons(void)
4442 if(!autocvar_hud_panel_modicons && !autocvar__hud_configure)
4445 if (gametype != GAME_KEYHUNT && gametype != GAME_CTF && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && gametype != GAME_CA && !autocvar__hud_configure)
4448 active_panel = HUD_PANEL_MODICONS;
4449 HUD_Panel_UpdateCvars(modicons);
4452 mySize = panel_size;
4454 if(mod_active != mod_prev) {
4456 mod_prev = mod_active;
4459 if(mod_active || autocvar__hud_configure)
4460 mod_alpha = bound(0, (time - mod_change) * 2, 1);
4462 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
4465 HUD_Panel_DrawBg(mod_alpha);
4467 if(panel_bg_padding)
4469 pos += '1 1 0' * panel_bg_padding;
4470 mySize -= '2 2 0' * panel_bg_padding;
4473 // these MUST be ran in order to update mod_active
4474 if(gametype == GAME_KEYHUNT)
4475 HUD_Mod_KH(pos, mySize);
4476 else if(gametype == GAME_CTF || autocvar__hud_configure)
4477 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
4478 else if(gametype == GAME_NEXBALL)
4479 HUD_Mod_NexBall(pos, mySize);
4480 else if(gametype == GAME_CTS || gametype == GAME_RACE)
4481 HUD_Mod_Race(pos, mySize);
4482 else if(gametype == GAME_CA)
4483 HUD_Mod_CA(pos, mySize);
4486 // Draw pressed keys (#11)
4488 void HUD_DrawPressedKeys(void)
4490 if(!autocvar_hud_panel_pressedkeys && !autocvar__hud_configure)
4493 if(!(spectatee_status > 0 || autocvar_hud_panel_pressedkeys >= 2 || autocvar__hud_configure))
4496 active_panel = HUD_PANEL_PRESSEDKEYS;
4497 HUD_Panel_UpdateCvars(pressedkeys);
4500 mySize = panel_size;
4502 HUD_Panel_DrawBg(1);
4503 if(panel_bg_padding)
4505 pos += '1 1 0' * panel_bg_padding;
4506 mySize -= '2 2 0' * panel_bg_padding;
4509 // force custom aspect
4510 float aspect = cvar("hud_panel_pressedkeys_aspect");
4514 if(mySize_x/mySize_y > aspect)
4516 newSize_x = aspect * mySize_y;
4517 newSize_y = mySize_y;
4519 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4523 newSize_y = 1/aspect * mySize_x;
4524 newSize_x = mySize_x;
4526 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4532 keysize = eX * mySize_x * (1/3) + eY * mySize_y * 0.5;
4534 pressedkeys = getstatf(STAT_PRESSED_KEYS);
4536 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4537 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);
4538 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);
4540 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4541 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);
4542 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);
4545 // Handle chat as a panel (#12)
4549 if(!autocvar_hud_panel_chat && !autocvar__hud_configure)
4551 cvar_set("con_chatrect", "0");
4555 active_panel = HUD_PANEL_CHAT;
4556 HUD_Panel_UpdateCvars(chat);
4558 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
4560 panel_pos_y = panel_bg_border;
4561 panel_size_y = vid_conheight - panel_bg_border * 2;
4562 if(panel_bg == "0") // force a border when maximized
4564 if(precache_pic(panel_bg) == "") {
4565 panel_bg = strcat(hud_skin_path, "/border_default");
4566 if(precache_pic(panel_bg) == "") {
4567 panel_bg = "gfx/hud/default/border_default";
4571 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an alpha of at least 0.75
4576 mySize = panel_size;
4578 HUD_Panel_DrawBg(1);
4580 if(panel_bg_padding)
4582 pos += '1 1 0' * panel_bg_padding;
4583 mySize -= '2 2 0' * panel_bg_padding;
4586 cvar_set("con_chatrect", "1");
4588 cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
4589 cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
4591 cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
4592 cvar_set("con_chat", ftos(floor(mySize_y/cvar("con_chatsize") - 0.5)));
4594 if(autocvar__hud_configure)
4597 chatsize = cvar("con_chatsize");
4598 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
4600 for(i = 0; i < cvar("con_chat"); ++i)
4602 if(i == cvar("con_chat") - 1)
4605 a = panel_fg_alpha * floor(((i + 1) * 7 + cvar("con_chattime"))/45);
4606 drawcolorcodedstring(pos + eY * i * chatsize, textShortenToWidth("^3Player^7: This is the chat area.", mySize_x, '1 1 0' * chatsize, stringwidth_colors), '1 1 0' * chatsize, a, DRAWFLAG_NORMAL);
4611 // Engine info panel (#13)
4618 float frametimeavg1; // 1 frame ago
4619 float frametimeavg2; // 2 frames ago
4620 void HUD_EngineInfo(void)
4622 if(!autocvar_hud_panel_engineinfo && !autocvar__hud_configure)
4625 active_panel = HUD_PANEL_ENGINEINFO;
4626 HUD_Panel_UpdateCvars(engineinfo);
4629 mySize = panel_size;
4631 HUD_Panel_DrawBg(1);
4632 if(panel_bg_padding)
4634 pos += '1 1 0' * panel_bg_padding;
4635 mySize -= '2 2 0' * panel_bg_padding;
4638 float currentTime = gettime(GETTIME_REALTIME);
4639 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
4641 float currentframetime = currentTime - prevfps_time;
4642 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
4643 frametimeavg2 = frametimeavg1;
4644 frametimeavg1 = frametimeavg;
4647 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
4648 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.
4650 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
4651 prevfps = (1/currentframetime);
4652 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"
4654 prevfps_time = currentTime;
4659 if(currentTime - prevfps_time > cvar("hud_panel_engineinfo_framecounter_time"))
4661 prevfps = framecounter/(currentTime - prevfps_time);
4663 prevfps_time = currentTime;
4668 color = HUD_Get_Num_Color (prevfps, 100);
4669 drawfont = hud_bigfont;
4670 drawstring_aspect(pos, strcat("FPS: ", ftos_decimals(prevfps, cvar("hud_panel_engineinfo_framecounter_decimals"))), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
4671 drawfont = hud_font;
4674 // Info messages panel (#14)
4676 #define drawInfoMessage(s)\
4677 if(autocvar_hud_panel_infomessages_flip)\
4678 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);\
4679 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);\
4681 void HUD_InfoMessages(void)
4683 if(!autocvar_hud_panel_infomessages && !autocvar__hud_configure)
4686 active_panel = HUD_PANEL_INFOMESSAGES;
4687 HUD_Panel_UpdateCvars(infomessages);
4690 mySize = panel_size;
4692 HUD_Panel_DrawBg(1);
4693 if(panel_bg_padding)
4695 pos += '1 1 0' * panel_bg_padding;
4696 mySize -= '2 2 0' * panel_bg_padding;
4699 // always force 5:1 aspect
4701 if(mySize_x/mySize_y > 5)
4703 newSize_x = 5 * mySize_y;
4704 newSize_y = mySize_y;
4706 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4710 newSize_y = 1/5 * mySize_x;
4711 newSize_x = mySize_x;
4713 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4722 fontsize = '0.20 0.20 0' * mySize_y;
4725 if(spectatee_status != 0)
4731 if(!autocvar__hud_configure)
4733 if(spectatee_status && !intermission)
4735 if(spectatee_status == -1)
4738 s = strcat("^1Spectating: ^7", GetPlayerName(spectatee_status - 1));
4741 if(spectatee_status == -1)
4742 s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 to spectate");
4744 s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 for another player");
4747 if(spectatee_status == -1)
4748 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
4750 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+fire2"), "^1 to observe");
4753 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
4756 if(gametype == GAME_ARENA)
4757 s = "^1Wait for your turn to join";
4758 else if(gametype == GAME_LMS)
4761 sk = playerslots[player_localentnum - 1];
4762 if(sk.(scores[ps_primary]) >= 666)
4763 s = "^1Match has already begun";
4764 else if(sk.(scores[ps_primary]) > 0)
4765 s = "^1You have no more lives left";
4767 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
4770 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
4773 //show restart countdown:
4774 if (time < getstatf(STAT_GAMESTARTTIME)) {
4776 //we need to ceil, otherwise the countdown would be off by .5 when using round()
4777 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
4778 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
4779 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
4783 if(warmup_stage && !intermission)
4785 s = "^2Currently in ^1warmup^2 stage!";
4790 if(mod(time, 1) >= 0.5)
4795 if(ready_waiting && !intermission && !spectatee_status)
4797 if(ready_waiting_for_me)
4800 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
4802 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
4807 s = strcat("^2Waiting for others to ready up to end warmup...");
4809 s = strcat("^2Waiting for others to ready up...");
4813 else if(warmup_stage && !intermission && !spectatee_status)
4815 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
4819 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
4821 float ts_min, ts_max;
4822 tm = teams.sort_next;
4825 for(; tm.sort_next; tm = tm.sort_next)
4827 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
4829 if(!ts_min) ts_min = tm.team_size;
4830 else ts_min = min(ts_min, tm.team_size);
4831 if(!ts_max) ts_max = tm.team_size;
4832 else ts_max = max(ts_max, tm.team_size);
4834 if ((ts_max - ts_min) > 1)
4836 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
4837 tm = GetTeam(myteam, false);
4839 if (tm.team != COLOR_SPECTATOR)
4840 if (tm.team_size == ts_max)
4841 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
4849 s = "^7Press ^3ESC ^7to show HUD options.";
4851 s = "^3Doubleclick ^7a panel for panel-specific options.";
4853 s = "^3CTRL ^7to disable collision testing, ^3SHIFT ^7and";
4855 s = "^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.";
4860 // Physics panel (#15)
4862 vector acc_prevspeed;
4863 float acc_prevtime, acc_avg, top_speed, top_speed_time;
4865 void HUD_Physics(void)
4867 if(!autocvar_hud_panel_physics && !autocvar__hud_configure)
4870 active_panel = HUD_PANEL_PHYSICS;
4871 HUD_Panel_UpdateCvars(physics);
4874 mySize = panel_size;
4876 HUD_Panel_DrawBg(1);
4877 if(panel_bg_padding)
4879 pos += '1 1 0' * panel_bg_padding;
4880 mySize -= '2 2 0' * panel_bg_padding;
4884 float speed, conversion_factor;
4885 string zspeed, unit;
4887 switch(cvar("hud_panel_physics_speed_unit"))
4892 conversion_factor = 1.0;
4896 conversion_factor = 0.0254;
4900 conversion_factor = 0.0254 * 3.6;
4904 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4908 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4912 float max_speed = floor( cvar("hud_panel_physics_speed_max") * conversion_factor + 0.5 );
4913 if (autocvar__hud_configure)
4914 speed = floor( max_speed * 0.65 + 0.5 );
4915 else if(cvar("hud_panel_physics_speed_z"))
4916 speed = floor( vlen(pmove_vel) * conversion_factor + 0.5 );
4918 speed = floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 );
4920 //compute acceleration
4921 float acceleration, f;
4922 float max_acceleration = cvar("hud_panel_physics_acceleration_max");
4923 if (autocvar__hud_configure)
4924 acceleration = max_acceleration * 0.3;
4927 f = time - acc_prevtime;
4928 if(cvar("hud_panel_physics_acceleration_z"))
4929 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
4931 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
4932 acc_prevspeed = pmove_vel;
4933 acc_prevtime = time;
4935 f = bound(0, f * 10, 1);
4936 acc_avg = acc_avg * (1 - f) + acceleration * f;
4937 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
4941 drawfont = hud_bigfont;
4942 float baralign = cvar("hud_panel_physics_baralign");
4943 float progressbar = cvar("hud_panel_physics_progressbar");
4944 float panel_ar = mySize_x/mySize_y;
4945 vector speed_offset, acceleration_offset;
4949 if (cvar("hud_panel_physics_flip"))
4950 speed_offset_x = mySize_x;
4952 acceleration_offset_x = mySize_x;
4957 if (cvar("hud_panel_physics_flip"))
4958 speed_offset_y = mySize_y;
4960 acceleration_offset_y = mySize_y;
4962 float speed_baralign, acceleration_baralign;
4963 if (cvar("hud_panel_physics_flip"))
4965 acceleration_baralign = (baralign == 1 || baralign == 2);
4966 speed_baralign = (baralign == 1 || baralign == 3);
4970 speed_baralign = (baralign == 1 || baralign == 2);
4971 acceleration_baralign = (baralign == 1 || baralign == 3);
4975 if(speed && progressbar)
4977 HUD_Panel_GetProgressBarColor(speed);
4978 HUD_Panel_DrawProgressBar(pos + speed_offset, mySize, speed/max_speed, 0, speed_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4981 vector tmp_offset, tmp_size;
4982 tmp_size_x = mySize_x * 0.75;
4983 tmp_size_y = mySize_y;
4985 tmp_offset_x = mySize_x - tmp_size_x;
4988 drawstring_aspect(pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4994 tmp_offset_x = tmp_size_x;
4995 if (cvar("hud_panel_physics_speed_unit_show"))
4998 tmp_size_x = mySize_x * (1 - 0.75);
4999 tmp_size_y = mySize_y * 0.4;
5000 drawstring_aspect(pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
5003 //compute and draw top speed
5004 if (cvar("hud_panel_physics_topspeed"))
5006 if (autocvar__hud_configure)
5008 top_speed = floor( max_speed * 0.75 + 0.5 );
5013 if (speed >= top_speed)
5016 top_speed_time = time;
5018 if (top_speed == 0) //hide top speed 0, it would be stupid
5022 f = max(1, cvar("hud_panel_physics_topspeed_time"));
5023 // divide by f to make it start from 1
5024 f = cos( ((time - top_speed_time) / f) * PI/2 );
5029 //top speed progressbar peek
5030 if(progressbar && speed < top_speed)
5032 float peek_offset_x, peek_size_x;
5034 peek_offset_x = (1 - min(top_speed, max_speed)/max_speed) * mySize_x;
5036 peek_offset_x = min(top_speed, max_speed)/max_speed * mySize_x;
5037 //if speed is not 0 the speed progressbar already fetched the color
5039 HUD_Panel_GetProgressBarColor(speed);
5040 peek_size_x = mySize_x * 0.01;
5041 drawfill(pos + speed_offset + eX * (peek_offset_x - peek_size_x), eX * peek_size_x + eY * mySize_y, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
5045 tmp_offset_y = mySize_y * 0.4;
5046 tmp_size_x = mySize_x * (1 - 0.75);
5047 tmp_size_y = mySize_y - tmp_offset_y;
5048 drawstring_aspect(pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
5055 if(acceleration && progressbar)
5057 if (acceleration < 0)
5058 HUD_Panel_GetProgressBarColor(acceleration_neg);
5060 HUD_Panel_GetProgressBarColor(acceleration);
5061 HUD_Panel_DrawProgressBar(pos + acceleration_offset, mySize, fabs(acceleration)/max_acceleration, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
5063 drawstring_aspect(pos + acceleration_offset, ftos_decimals(acceleration, 3), mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
5064 drawfont = hud_font;
5073 void HUD_ShowSpeed(void)
5076 float pos, conversion_factor;
5077 string speed, zspeed, unit;
5079 switch(cvar("cl_showspeed_unit"))
5084 conversion_factor = 1.0;
5088 conversion_factor = 1.0;
5092 conversion_factor = 0.0254;
5096 conversion_factor = 0.0254 * 3.6;
5100 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
5104 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
5108 speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
5110 numsize_x = numsize_y = cvar("cl_showspeed_size");
5111 pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
5113 drawfont = hud_bigfont;
5114 drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
5116 if (cvar("cl_showspeed_z") == 1) {
5117 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
5118 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
5121 drawfont = hud_font;
5124 void HUD_ShowAcceleration(void)
5126 float acceleration, sz, scale, alpha, f;
5127 vector pos, mySize, rgb;
5129 f = time - acc_prevtime;
5130 if(cvar("cl_showacceleration_z"))
5131 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
5133 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
5134 acc_prevspeed = pmove_vel;
5135 acc_prevtime = time;
5137 f = bound(0, f * 10, 1);
5138 acc_avg = acc_avg * (1 - f) + acceleration * f;
5139 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
5140 if (acceleration == 0)
5143 sz = cvar("cl_showacceleration_size");
5144 scale = cvar("cl_showacceleration_scale");
5145 alpha = cvar("cl_showacceleration_alpha");
5146 if (cvar("cl_showacceleration_color_custom"))
5147 rgb = stov(cvar_string("cl_showacceleration_color"));
5149 if (acceleration < 0)
5150 rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
5152 rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
5155 mySize_x = vid_conwidth/2;
5157 pos_y = cvar("cl_showacceleration_position") * vid_conheight - sz/2;
5158 if (acceleration > 0)
5161 HUD_Panel_DrawProgressBar(pos, mySize, acceleration * scale, 0, 0, rgb, alpha * autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
5166 HUD_Panel_DrawProgressBar(pos, mySize, -acceleration * scale, 0, 1, rgb, alpha * autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
5170 void HUD_Reset (void)
5172 // reset gametype specific icons
5173 if(gametype == GAME_KEYHUNT)
5175 else if(gametype == GAME_CTF)
5176 HUD_Mod_CTF_Reset();
5179 #define HUD_DrawPanel(id)\
5181 case (HUD_PANEL_RADAR):\
5182 HUD_Radar(); break;\
5183 case (HUD_PANEL_WEAPONS):\
5184 HUD_Weapons(); break;\
5185 case (HUD_PANEL_AMMO):\
5187 case (HUD_PANEL_POWERUPS):\
5188 HUD_Powerups(); break;\
5189 case (HUD_PANEL_HEALTHARMOR):\
5190 HUD_HealthArmor(); break;\
5191 case (HUD_PANEL_NOTIFY):\
5192 HUD_Notify(); break;\
5193 case (HUD_PANEL_TIMER):\
5194 HUD_Timer(); break;\
5195 case (HUD_PANEL_SCORE):\
5196 HUD_Score(); break;\
5197 case (HUD_PANEL_RACETIMER):\
5198 HUD_RaceTimer(); break;\
5199 case (HUD_PANEL_VOTE):\
5200 HUD_VoteWindow(); break;\
5201 case (HUD_PANEL_MODICONS):\
5202 HUD_ModIcons(); break;\
5203 case (HUD_PANEL_PRESSEDKEYS):\
5204 HUD_DrawPressedKeys(); break;\
5205 case (HUD_PANEL_CHAT):\
5207 case (HUD_PANEL_ENGINEINFO):\
5208 HUD_EngineInfo(); break;\
5209 case (HUD_PANEL_INFOMESSAGES):\
5210 HUD_InfoMessages(); break;\
5211 case (HUD_PANEL_PHYSICS):\
5212 HUD_Physics(); break;\
5213 } ENDS_WITH_CURLY_BRACE
5215 void HUD_Main (void)
5218 // global hud alpha fade
5219 if(menu_enabled == 1)
5222 hud_fade_alpha = (1 - autocvar__menu_alpha);
5224 if(scoreboard_fade_alpha)
5225 hud_fade_alpha = (1 - scoreboard_fade_alpha);
5227 if(intermission == 2) // no hud during mapvote
5229 else if(autocvar__menu_alpha == 0 && scoreboard_fade_alpha == 0)
5232 if(!autocvar__hud_configure && !hud_fade_alpha)
5236 if (hud_skin_path != cvar_string("hud_skin"))
5239 strunzone(hud_skin_path);
5240 hud_skin_path = strzone(strcat("gfx/hud/", cvar_string("hud_skin")));
5243 // HUD configure visible grid
5244 float hud_configure_grid_alpha;
5245 if(autocvar__hud_configure && cvar("hud_configure_grid") && (hud_configure_grid_alpha = cvar("hud_configure_grid_alpha")))
5247 hud_configure_gridSize_x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
5248 hud_configure_gridSize_y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
5249 hud_configure_realGridSize_x = hud_configure_gridSize_x * vid_conwidth;
5250 hud_configure_realGridSize_y = hud_configure_gridSize_y * vid_conheight;
5252 for(i = 0; i < 1/hud_configure_gridSize_x; ++i)
5253 drawfill(eX * i * hud_configure_realGridSize_x, eX + eY * vid_conheight, '0.5 0.5 0.5', hud_configure_grid_alpha, DRAWFLAG_NORMAL);
5255 for(i = 0; i < 1/hud_configure_gridSize_y; ++i)
5256 drawfill(eY * i * hud_configure_realGridSize_y, eY + eX * vid_conwidth, '0.5 0.5 0.5', hud_configure_grid_alpha, DRAWFLAG_NORMAL);
5260 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
5264 float hud_dock_color_team = cvar("hud_dock_color_team");
5265 if((teamplay) && hud_dock_color_team) {
5266 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5267 color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
5269 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
5270 color = '1 0 0' * hud_dock_color_team;
5274 string hud_dock_color = cvar_string("hud_dock_color");
5275 if(hud_dock_color == "shirt") {
5276 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5277 color = colormapPaletteColor(floor(f / 16), 0);
5279 else if(hud_dock_color == "pants") {
5280 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5281 color = colormapPaletteColor(mod(f, 16), 1);
5284 color = stov(hud_dock_color);
5288 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
5289 if(precache_pic(pic) == "") {
5290 pic = strcat(hud_skin_path, "/dock_medium");
5291 if(precache_pic(pic) == "") {
5292 pic = "gfx/hud/default/dock_medium";
5295 drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, cvar("hud_dock_alpha") * hud_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
5298 // cache the panel order into the panel_order array
5299 if(autocvar__hud_panelorder != hud_panelorder_prev) {
5300 if(hud_panelorder_prev)
5301 strunzone(hud_panelorder_prev);
5302 hud_panelorder_prev = strzone(autocvar__hud_panelorder);
5303 tokenize_console(autocvar__hud_panelorder);
5304 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5305 panel_order[i] = stof(argv(i));
5308 // draw panels in order specified by panel_order array
5309 for(i = HUD_PANEL_NUM - 1; i >= 0; --i) {
5310 if(i != HUD_PANEL_CHAT || !autocvar__con_chat_maximized) // don't draw maximized chat panel twice!
5311 HUD_DrawPanel(panel_order[i]);
5314 // draw chat panel on top if it is maximized
5315 if(autocvar__con_chat_maximized)
5316 HUD_Chat(); // HUD_DrawPanel(HUD_PANEL_CHAT);
5318 // TODO hud_'ify these
5319 if (cvar("cl_showspeed"))
5321 if (cvar("cl_showacceleration"))
5322 HUD_ShowAcceleration();
5324 if (autocvar__hud_configure && spectatee_status && hud_configure_prev == -1) // try to join if we are in hud_configure mode, but still spectating, and in the first frame (in order to get rid of motd when launching a server via the menu "HUD Setup" button)
5325 localcmd("cmd selectteam auto; cmd join\n");
5327 hud_configure_prev = autocvar__hud_configure;
5329 if (!autocvar__hud_configure) // hud config mode disabled, enable normal alpha stuff again