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) // draw whole image as it is
19 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
22 if (theBorderSize_x == 0 && theBorderSize_y == 0) // no border
24 // draw only the central part
25 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
32 //pic = draw_UseSkinFor(pic);
33 width = eX * theSize_x;
34 height = eY * theSize_y;
35 if(theSize_x <= theBorderSize_x * 2)
37 // not wide enough... draw just left and right then
38 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
39 if(theSize_y <= theBorderSize_y * 2)
41 // not high enough... draw just corners
42 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
43 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
44 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
45 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
46 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
50 dY = theBorderSize_x * eY;
51 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
52 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
53 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
54 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);
55 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
56 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);
61 if(theSize_y <= theBorderSize_y * 2)
63 // not high enough... draw just top and bottom then
64 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
65 dX = theBorderSize_x * eX;
66 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
67 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
68 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
69 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
70 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);
71 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);
75 dX = theBorderSize_x * eX;
76 dY = theBorderSize_x * eY;
77 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
78 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
79 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
80 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
81 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
82 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
83 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
84 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
85 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
90 vector HUD_Get_Num_Color (float x, float maxvalue)
98 else if(x > maxvalue * 0.75) {
99 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
100 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
103 else if(x > maxvalue * 0.5) {
104 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
105 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
106 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
108 else if(x > maxvalue * 0.25) {
111 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
113 else if(x > maxvalue * 0.1) {
115 color_y = (x-20)*90/27/100; // green value between 0 -> 1
116 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
126 float stringwidth_colors(string s, vector theSize)
128 return stringwidth(s, TRUE, theSize);
131 float stringwidth_nocolors(string s, vector theSize)
133 return stringwidth(s, FALSE, theSize);
136 #define CENTERPRINT_MAX_LINES 30
137 string centerprint_messages[CENTERPRINT_MAX_LINES];
138 float centerprint_width[CENTERPRINT_MAX_LINES];
139 float centerprint_time;
140 float centerprint_expire;
141 float centerprint_num;
142 float centerprint_offset_hint;
143 vector centerprint_fontsize;
145 void centerprint(string strMessage)
147 float i, j, n, hcount;
150 centerprint_fontsize = HUD_GetFontsize("scr_centersize");
152 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
154 if(autocvar_scr_centertime <= 0)
160 // strip trailing newlines
161 j = strlen(strMessage) - 1;
162 while(substring(strMessage, j, 1) == "\n" && j >= 0)
164 strMessage = substring(strMessage, 0, j + 1);
169 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
171 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
173 strMessage = substring(strMessage, j, strlen(strMessage) - j);
174 centerprint_offset_hint = j;
179 // if we get here, we have a message. Initialize its height.
182 n = tokenizebyseparator(strMessage, "\n");
184 for(j = 0; j < n; ++j)
186 getWrappedLine_remaining = argv(j);
187 while(getWrappedLine_remaining)
189 s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
190 if(centerprint_messages[i] != s) // don't fade the same message in, looks stupid
191 centerprint_time = time;
192 if(centerprint_messages[i])
193 strunzone(centerprint_messages[i]);
194 centerprint_messages[i] = strzone(s);
195 centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
198 // half height for empty lines looks better
204 if(i >= CENTERPRINT_MAX_LINES)
210 h = centerprint_fontsize_y*hcount;
212 havail = vid_conheight;
213 if(autocvar_con_chatpos < 0)
214 havail -= (-autocvar_con_chatpos + autocvar_con_chat) * autocvar_con_chatsize; // avoid overlapping chat
215 if(havail > vid_conheight - 70)
216 havail = vid_conheight - 70; // avoid overlapping HUD
219 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
221 // here, the centerprint would cover the crosshair. REALLY BAD.
222 forbiddenmin = vid_conheight * 0.5 - h - 16;
223 forbiddenmax = vid_conheight * 0.5 + 16;
225 allowedmin = scoreboard_bottom;
226 allowedmax = havail - h;
227 preferred = (havail - h)/2;
230 // possible orderings (total: 4! / 4 = 6)
231 // allowedmin allowedmax forbiddenmin forbiddenmax
232 // forbiddenmin forbiddenmax allowedmin allowedmax
233 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
235 // forbidden doesn't matter in this case
236 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
238 // allowedmin forbiddenmin allowedmax forbiddenmax
239 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
241 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
243 // allowedmin forbiddenmin forbiddenmax allowedmax
244 else if(allowedmin < forbiddenmin)
246 // make sure the forbidden zone is not covered
247 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
248 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
250 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
252 // forbiddenmin allowedmin allowedmax forbiddenmax
253 else if(allowedmax < forbiddenmax)
255 // it's better to leave the allowed zone (overlap with scoreboard) than
256 // to cover the forbidden zone (crosshair)
257 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
258 centerprint_start_y = forbiddenmax;
260 centerprint_start_y = forbiddenmin;
262 // forbiddenmin allowedmin forbiddenmax allowedmax
265 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
272 centerprint_expire = time + autocvar_scr_centertime;
275 void HUD_DrawCenterPrint (void)
282 if(time - centerprint_time < 0.25)
283 a = (time - centerprint_time) / 0.25;
285 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
292 if(centerprint_num * autocvar_scr_centersize > 24 && scoreboard_active) // 24 = height of Scoreboard text
293 centerprint_start_y = scoreboard_bottom + centerprint_fontsize_y;
295 pos = centerprint_start;
296 for (i=0; i<centerprint_num; i = i + 1)
298 ts = centerprint_messages[i];
299 drawfontscale = sz * '1 1 0';
300 drawfont = hud_bigfont;
301 pos_x = (vid_conwidth - stringwidth(ts, TRUE, centerprint_fontsize)) * 0.5;
304 drawcolorcodedstring(pos + '0 1 0' * (1 - sz) * 0.5 *centerprint_fontsize_y, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
305 pos_y = pos_y + centerprint_fontsize_y;
308 // half height for empty lines looks better
309 pos_y = pos_y + sz * centerprint_fontsize_y * 0.5;
310 drawfontscale = '1 1 0';
315 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
317 position_x -= 2 / 3 * strlen(text) * scale_x;
318 drawstring(position, text, scale, rgb, alpha, flag);
321 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
323 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
324 drawstring(position, text, scale, rgb, alpha, flag);
327 // return the string of the given race place
328 string race_PlaceName(float pos) {
336 return strcat(ftos(pos), "th");
339 // return the string of the onscreen race timer
340 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
348 if(histime == 0) // goal hit
352 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
362 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
368 lapstr = strcat(" (-", ftos(lapdelta), "L)");
371 else if(lapdelta < 0)
373 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
377 else if(histime > 0) // anticipation
379 if(mytime >= histime)
380 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
382 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
389 cpname = "Start line";
391 cpname = "Finish line";
393 cpname = strcat("Intermediate ", ftos(cp));
395 cpname = "Finish line";
398 return strcat(col, cpname);
399 else if(hisname == "")
400 return strcat(col, cpname, " (", timestr, ")");
402 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
405 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
406 float race_CheckName(string net_name) {
408 for (i=RANKINGS_CNT-1;i>=0;--i)
409 if(grecordholder[i] == net_name)
420 #define HUD_Write(s) fputs(fh, s)
421 // q: quoted, n: not quoted
422 #define HUD_Write_Cvar_n(cvar) HUD_Write(strcat("seta ", cvar, " ", cvar_string(cvar), "\n"))
423 #define HUD_Write_Cvar_q(cvar) HUD_Write(strcat("seta ", cvar, " \"", cvar_string(cvar), "\"\n"))
424 #define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel_name, cvar_suf))
425 #define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel_name, cvar_suf))
427 void HUD_Panel_ExportCfg(string cfgname)
430 string filename = strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg");
431 fh = fopen(filename, FILE_WRITE);
434 HUD_Write_Cvar_q("hud_skin");
435 HUD_Write_Cvar_q("hud_panel_bg");
436 HUD_Write_Cvar_q("hud_panel_bg_color");
437 HUD_Write_Cvar_q("hud_panel_bg_color_team");
438 HUD_Write_Cvar_q("hud_panel_bg_alpha");
439 HUD_Write_Cvar_q("hud_panel_bg_border");
440 HUD_Write_Cvar_q("hud_panel_bg_padding");
441 HUD_Write_Cvar_q("hud_panel_fg_alpha");
444 HUD_Write_Cvar_q("hud_dock");
445 HUD_Write_Cvar_q("hud_dock_color");
446 HUD_Write_Cvar_q("hud_dock_color_team");
447 HUD_Write_Cvar_q("hud_dock_alpha");
450 HUD_Write_Cvar_q("hud_progressbar_alpha");
451 HUD_Write_Cvar_q("hud_progressbar_strength_color");
452 HUD_Write_Cvar_q("hud_progressbar_shield_color");
453 HUD_Write_Cvar_q("hud_progressbar_health_color");
454 HUD_Write_Cvar_q("hud_progressbar_armor_color");
455 HUD_Write_Cvar_q("hud_progressbar_fuel_color");
456 HUD_Write_Cvar_q("hud_progressbar_nexball_color");
459 HUD_Write_Cvar_q("_hud_panelorder");
462 HUD_Write_Cvar_q("hud_configure_grid");
463 HUD_Write_Cvar_q("hud_configure_grid_xsize");
464 HUD_Write_Cvar_q("hud_configure_grid_ysize");
467 HUD_Write_Cvar_q("scr_centerpos");
470 // common cvars for all panels
472 for (i = 0; i < HUD_PANEL_NUM; ++i)
474 HUD_Panel_GetName(i);
476 HUD_Write_PanelCvar_n("");
477 HUD_Write_PanelCvar_q("_pos");
478 HUD_Write_PanelCvar_q("_size");
479 HUD_Write_PanelCvar_q("_bg");
480 HUD_Write_PanelCvar_q("_bg_color");
481 HUD_Write_PanelCvar_q("_bg_color_team");
482 HUD_Write_PanelCvar_q("_bg_alpha");
483 HUD_Write_PanelCvar_q("_bg_border");
484 HUD_Write_PanelCvar_q("_bg_padding");
486 case HUD_PANEL_WEAPONS:
487 HUD_Write_PanelCvar_q("_complainbubble");
488 HUD_Write_PanelCvar_q("_complainbubble_padding");
489 HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
490 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
491 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
492 HUD_Write_PanelCvar_q("_ammo_color");
493 HUD_Write_PanelCvar_q("_ammo_alpha");
494 HUD_Write_PanelCvar_q("_aspect");
497 HUD_Write_PanelCvar_q("_onlycurrent");
498 HUD_Write_PanelCvar_q("_iconalign");
499 HUD_Write_PanelCvar_q("_progressbar");
500 HUD_Write_PanelCvar_q("_progressbar_name");
501 HUD_Write_PanelCvar_q("_text");
503 case HUD_PANEL_POWERUPS:
504 HUD_Write_PanelCvar_q("_flip");
505 HUD_Write_PanelCvar_q("_iconalign");
506 HUD_Write_PanelCvar_q("_baralign");
507 HUD_Write_PanelCvar_q("_progressbar");
508 HUD_Write_PanelCvar_q("_progressbar_strength");
509 HUD_Write_PanelCvar_q("_progressbar_shield");
511 case HUD_PANEL_HEALTHARMOR:
512 HUD_Write_PanelCvar_q("_flip");
513 HUD_Write_PanelCvar_q("_iconalign");
514 HUD_Write_PanelCvar_q("_baralign");
515 HUD_Write_PanelCvar_q("_progressbar");
516 HUD_Write_PanelCvar_q("_progressbar_health");
517 HUD_Write_PanelCvar_q("_progressbar_armor");
518 HUD_Write_PanelCvar_q("_text");
520 case HUD_PANEL_NOTIFY:
521 HUD_Write_PanelCvar_q("_flip");
522 HUD_Write_PanelCvar_q("_print");
524 case HUD_PANEL_RADAR:
525 HUD_Write_PanelCvar_q("_foreground_alpha");
528 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
530 case HUD_PANEL_PRESSEDKEYS:
531 HUD_Write_PanelCvar_q("_aspect");
533 case HUD_PANEL_INFOMESSAGES:
534 HUD_Write_PanelCvar_q("_flip");
539 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
541 print("^2Successfully exported to ", filename, "! (Note: It's saved in data/data/)\n");
545 print("^1Couldn't write to ", filename, "\n");
548 const float hlBorderSize = 4;
549 const string hlBorder = "gfx/hud/default/border_highlighted";
550 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
551 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
553 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
554 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);
555 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);
556 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);
557 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);
560 // draw the background/borders
561 #define HUD_Panel_DrawBg(alpha)\
563 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));\
564 if(highlightedPanel_prev == active_panel && autocvar__hud_configure)\
566 HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha) * alpha);\
567 } ENDS_WITH_CURLY_BRACE
569 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
570 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float lenght_ratio, float vertical, float right_align, vector theColor, float theAlpha, float drawflag)
572 if(lenght_ratio <= 0 || !theAlpha)
578 vector width, height;
580 pic = strcat(hud_skin_path, "/", pic, "_vertical");
581 if(precache_pic(pic) == "") {
582 pic = "gfx/hud/default/statusbar_vertical";
586 theOrigin_y += (1 - lenght_ratio) * theSize_y;
587 theSize_y *= lenght_ratio;
590 width = eX * theSize_x;
591 height = eY * theSize_y;
592 if(theSize_y <= theSize_x * 2)
594 // button not high enough
595 // draw just upper and lower part then
596 square = eY * theSize_y * 0.5;
597 bH = eY * (0.25 * theSize_y / (theSize_x * 2));
598 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
599 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
603 square = eY * theSize_x;
604 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
605 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
606 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
609 pic = strcat(hud_skin_path, "/", pic);
610 if(precache_pic(pic) == "") {
611 pic = "gfx/hud/default/statusbar";
615 theOrigin_x += (1 - lenght_ratio) * theSize_x;
616 theSize_x *= lenght_ratio;
619 width = eX * theSize_x;
620 height = eY * theSize_y;
621 if(theSize_x <= theSize_y * 2)
623 // button not wide enough
624 // draw just left and right part then
625 square = eX * theSize_x * 0.5;
626 bW = eX * (0.25 * theSize_x / (theSize_y * 2));
627 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
628 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
632 square = eX * theSize_y;
633 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
634 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
635 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
640 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
646 pic = strcat(hud_skin_path, "/num_leading");
647 if(precache_pic(pic) == "") {
648 pic = "gfx/hud/default/num_leading";
651 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
652 if(mySize_x/mySize_y > 2)
653 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);
654 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);
657 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
658 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
667 myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
668 targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
670 for (i = 0; i < HUD_PANEL_NUM; ++i) {
671 if(i == highlightedPanel || !panel_enabled)
674 HUD_Panel_UpdatePosSizeForId(i);
676 panel_pos -= '1 1 0' * panel_bg_border;
677 panel_size += '2 2 0' * panel_bg_border;
679 if(myPos_y + mySize_y < panel_pos_y)
681 if(myPos_y > panel_pos_y + panel_size_y)
684 if(myPos_x + mySize_x < panel_pos_x)
686 if(myPos_x > panel_pos_x + panel_size_x)
689 // OK, there IS a collision.
691 myCenter_x = myPos_x + 0.5 * mySize_x;
692 myCenter_y = myPos_y + 0.5 * mySize_y;
694 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
695 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
697 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
699 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
700 myTarget_x = panel_pos_x - mySize_x;
701 else // push it upwards
702 myTarget_y = panel_pos_y - mySize_y;
704 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
706 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
707 myTarget_x = panel_pos_x + panel_size_x;
708 else // push it upwards
709 myTarget_y = panel_pos_y - mySize_y;
711 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
713 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
714 myTarget_x = panel_pos_x - mySize_x;
715 else // push it downwards
716 myTarget_y = panel_pos_y + panel_size_y;
718 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
720 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
721 myTarget_x = panel_pos_x + panel_size_x;
722 else // push it downwards
723 myTarget_y = panel_pos_y + panel_size_y;
725 //if(cvar("hud_configure_checkcollisions_debug"))
726 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
732 void HUD_Panel_SetPos(vector pos)
734 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
738 //if(cvar("hud_configure_checkcollisions_debug"))
739 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
741 if(cvar("hud_configure_grid"))
743 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
744 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
747 if(hud_configure_checkcollisions)
748 pos = HUD_Panel_CheckMove(pos, mySize);
750 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
751 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
754 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
756 HUD_Panel_GetName(highlightedPanel);
757 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
760 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
761 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
766 float dist_x, dist_y;
768 ratio = mySize_x/mySize_y;
770 for (i = 0; i < HUD_PANEL_NUM; ++i) {
771 if(i == highlightedPanel || !panel_enabled)
774 HUD_Panel_UpdatePosSizeForId(i);
776 panel_pos -= '1 1 0' * panel_bg_border;
777 panel_size += '2 2 0' * panel_bg_border;
779 targEndPos = panel_pos + panel_size;
781 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
782 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
785 if (resizeCorner == 1)
787 // check if this panel is on our way
788 if (resizeorigin_x <= panel_pos_x)
790 if (resizeorigin_y <= panel_pos_y)
792 if (targEndPos_x <= resizeorigin_x - mySize_x)
794 if (targEndPos_y <= resizeorigin_y - mySize_y)
797 // there is a collision:
798 // detect which side of the panel we are facing is actually limiting the resizing
799 // (which side the resize direction finds for first) and reduce the size up to there
801 // dist is the distance between resizeorigin and the "analogous" point of the panel
802 // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
803 dist_x = resizeorigin_x - targEndPos_x;
804 dist_y = resizeorigin_y - targEndPos_y;
805 if (dist_y <= 0 || dist_x / dist_y > ratio)
806 mySize_x = min(mySize_x, dist_x);
808 mySize_y = min(mySize_y, dist_y);
810 else if (resizeCorner == 2)
812 if (resizeorigin_x >= targEndPos_x)
814 if (resizeorigin_y <= panel_pos_y)
816 if (panel_pos_x >= resizeorigin_x + mySize_x)
818 if (targEndPos_y <= resizeorigin_y - mySize_y)
821 dist_x = panel_pos_x - resizeorigin_x;
822 dist_y = resizeorigin_y - targEndPos_y;
823 if (dist_y <= 0 || dist_x / dist_y > ratio)
824 mySize_x = min(mySize_x, dist_x);
826 mySize_y = min(mySize_y, dist_y);
828 else if (resizeCorner == 3)
830 if (resizeorigin_x <= panel_pos_x)
832 if (resizeorigin_y >= targEndPos_y)
834 if (targEndPos_x <= resizeorigin_x - mySize_x)
836 if (panel_pos_y >= resizeorigin_y + mySize_y)
839 dist_x = resizeorigin_x - targEndPos_x;
840 dist_y = panel_pos_y - resizeorigin_y;
841 if (dist_y <= 0 || dist_x / dist_y > ratio)
842 mySize_x = min(mySize_x, dist_x);
844 mySize_y = min(mySize_y, dist_y);
846 else if (resizeCorner == 4)
848 if (resizeorigin_x >= targEndPos_x)
850 if (resizeorigin_y >= targEndPos_y)
852 if (panel_pos_x >= resizeorigin_x + mySize_x)
854 if (panel_pos_y >= resizeorigin_y + mySize_y)
857 dist_x = panel_pos_x - resizeorigin_x;
858 dist_y = panel_pos_y - resizeorigin_y;
859 if (dist_y <= 0 || dist_x / dist_y > ratio)
860 mySize_x = min(mySize_x, dist_x);
862 mySize_y = min(mySize_y, dist_y);
864 //if(cvar("hud_configure_checkcollisions_debug"))
865 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
871 void HUD_Panel_SetPosSize(vector mySize)
873 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
875 resizeorigin = panel_click_resizeorigin;
878 // minimum panel size cap
879 mySize_x = max(0.025 * vid_conwidth, mySize_x);
880 mySize_y = max(0.025 * vid_conheight, mySize_y);
882 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.
884 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
885 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
888 // collision testing|
889 // -----------------+
891 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
892 if(resizeCorner == 1) {
893 myPos_x = resizeorigin_x - mySize_x;
894 myPos_y = resizeorigin_y - mySize_y;
895 } else if(resizeCorner == 2) {
896 myPos_x = resizeorigin_x;
897 myPos_y = resizeorigin_y - mySize_y;
898 } else if(resizeCorner == 3) {
899 myPos_x = resizeorigin_x - mySize_x;
900 myPos_y = resizeorigin_y;
901 } else { // resizeCorner == 4
902 myPos_x = resizeorigin_x;
903 myPos_y = resizeorigin_y;
906 // left/top screen edges
908 mySize_x = mySize_x + myPos_x;
910 mySize_y = mySize_y + myPos_y;
912 // bottom/right screen edges
913 if(myPos_x + mySize_x > vid_conwidth)
914 mySize_x = vid_conwidth - myPos_x;
915 if(myPos_y + mySize_y > vid_conheight)
916 mySize_y = vid_conheight - myPos_y;
918 //if(cvar("hud_configure_checkcollisions_debug"))
919 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
921 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
922 if(cvar("hud_configure_grid"))
924 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
925 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
928 if(hud_configure_checkcollisions)
929 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
931 // 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)
932 mySize_x = max(0.025 * vid_conwidth, mySize_x);
933 mySize_y = max(0.025 * vid_conheight, mySize_y);
935 // do another pos check, as size might have changed by now
936 if(resizeCorner == 1) {
937 myPos_x = resizeorigin_x - mySize_x;
938 myPos_y = resizeorigin_y - mySize_y;
939 } else if(resizeCorner == 2) {
940 myPos_x = resizeorigin_x;
941 myPos_y = resizeorigin_y - mySize_y;
942 } else if(resizeCorner == 3) {
943 myPos_x = resizeorigin_x - mySize_x;
944 myPos_y = resizeorigin_y;
945 } else { // resizeCorner == 4
946 myPos_x = resizeorigin_x;
947 myPos_y = resizeorigin_y;
950 //if(cvar("hud_configure_checkcollisions_debug"))
951 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
953 HUD_Panel_GetName(highlightedPanel);
955 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
956 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
958 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
959 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
963 float prevMouseClicked; // previous state
964 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
965 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
967 float pressed_key_time;
968 void HUD_Panel_Arrow_Action(float nPrimary)
970 if (highlightedPanel_prev == -1 || mouseClicked)
973 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
976 if(cvar("hud_configure_grid"))
978 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
980 if (hudShiftState & S_SHIFT)
981 step = hud_configure_realGridSize_y;
983 step = 2 * hud_configure_realGridSize_y;
987 if (hudShiftState & S_SHIFT)
988 step = hud_configure_realGridSize_x;
990 step = 2 * hud_configure_realGridSize_x;
995 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
996 step = vid_conheight;
999 if (hudShiftState & S_SHIFT)
1000 step = (step / 256); // more precision
1002 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
1005 highlightedPanel = highlightedPanel_prev;
1007 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1009 vector prev_pos, prev_size;
1010 prev_pos = panel_pos;
1011 prev_size = panel_size;
1013 if (hudShiftState & S_ALT) // resize
1015 highlightedAction = 1;
1016 if(nPrimary == K_UPARROW)
1018 else if(nPrimary == K_RIGHTARROW)
1020 else if(nPrimary == K_LEFTARROW)
1022 else // if(nPrimary == K_DOWNARROW)
1025 // ctrl+arrow reduces the size, instead of increasing it
1026 // Note that ctrl disables collisions check too, but it's fine
1027 // since we don't collide with anything reducing the size
1028 if (hudShiftState & S_CTRL) {
1030 resizeCorner = 5 - resizeCorner;
1034 mySize = panel_size;
1035 panel_click_resizeorigin = panel_pos;
1036 if(resizeCorner == 1) {
1037 panel_click_resizeorigin += mySize;
1039 } else if(resizeCorner == 2) {
1040 panel_click_resizeorigin_y += mySize_y;
1042 } else if(resizeCorner == 3) {
1043 panel_click_resizeorigin_x += mySize_x;
1045 } else { // resizeCorner == 4
1048 HUD_Panel_SetPosSize(mySize);
1052 highlightedAction = 2;
1055 if(nPrimary == K_UPARROW)
1057 else if(nPrimary == K_DOWNARROW)
1059 else if(nPrimary == K_LEFTARROW)
1061 else // if(nPrimary == K_RIGHTARROW)
1064 HUD_Panel_SetPos(pos);
1067 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1069 if (prev_pos != panel_pos || prev_size != panel_size)
1072 panel_pos_backup = prev_pos;
1073 panel_size_backup = prev_size;
1074 highlightedPanel_backup = highlightedPanel;
1078 void HUD_Panel_EnableMenu();
1079 float tab_panels[HUD_PANEL_NUM];
1080 float tab_panel, tab_backward;
1081 vector tab_panel_pos;
1082 void HUD_Panel_FirstInDrawQ(float id);
1083 void reset_tab_panels()
1086 for(i = 0; i < HUD_PANEL_NUM; ++i)
1089 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1093 if(!autocvar__hud_configure)
1096 // allow console bind to work
1099 con_keys = findkeysforcommand("toggleconsole");
1100 keys = tokenize(con_keys);
1102 float hit_con_bind, i;
1103 for (i = 0; i < keys; ++i)
1105 if(nPrimary == stof(argv(i)))
1109 if(bInputType == 0) {
1110 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
1111 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
1112 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
1114 else if(bInputType == 1) {
1115 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
1116 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
1117 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
1120 if(nPrimary == K_CTRL)
1122 if (bInputType == 1) //ctrl has been released
1124 if (tab_panel != -1)
1126 //switch to selected panel
1127 highlightedPanel = tab_panel;
1128 highlightedPanel_prev = tab_panel;
1129 HUD_Panel_FirstInDrawQ(highlightedPanel_prev);
1136 if(nPrimary == K_MOUSE1)
1138 if(bInputType == 0) { // key pressed
1142 else if(bInputType == 1) {// key released
1147 else if(nPrimary == K_ESCAPE)
1149 if (bInputType == 1)
1152 menu_enabled_time = time;
1153 localcmd("menu_showhudexit\n");
1155 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
1157 if (bInputType == 1 || mouseClicked)
1160 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
1161 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
1162 //(it should only after every other panel of the hud)
1163 //It's a minor bug anyway, we can live with it
1165 float starting_panel;
1166 float old_tab_panel = tab_panel;
1167 if (tab_panel == -1) //first press of TAB
1169 if (highlightedPanel_prev != -1)
1170 HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev)
1172 panel_pos = '0 0 0';
1173 starting_panel = highlightedPanel_prev; //can be -1, it means no starting panel
1174 tab_panel_pos = panel_pos; //to compute level
1178 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
1180 starting_panel = tab_panel;
1182 tab_backward = (hudShiftState & S_SHIFT);
1184 float k, level, start_pos_x;
1185 vector candidate_pos;
1186 const float LEVELS_NUM = 4;
1187 const float level_height = vid_conheight / LEVELS_NUM;
1189 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
1190 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
1191 start_pos_x = tab_panel_pos_x;
1196 for(i = 0; i < HUD_PANEL_NUM; ++i)
1198 if (i == tab_panels[i] || i == starting_panel)
1200 HUD_Panel_UpdatePosSizeForId(i)
1201 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
1202 if ( ( !tab_backward && panel_pos_x >= start_pos_x && (panel_pos_x < candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y <= candidate_pos_y)) )
1203 || ( tab_backward && panel_pos_x <= start_pos_x && (panel_pos_x > candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y >= candidate_pos_y)) ) )
1206 tab_panel_pos = candidate_pos = panel_pos;
1209 if (tab_panel != -1)
1211 if (k == LEVELS_NUM) //tab_panel not found
1214 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
1219 starting_panel = old_tab_panel;
1221 goto find_tab_panel; //u must find tab_panel!
1225 level = mod(level + level_height, vid_conheight);
1227 candidate_pos_x = vid_conwidth;
1231 level = mod(level - level_height, vid_conheight);
1232 start_pos_x = vid_conwidth;
1233 candidate_pos_x = 0;
1237 tab_panels[tab_panel] = tab_panel;
1239 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
1241 if (bInputType == 1 || mouseClicked)
1244 if (highlightedPanel_prev != -1)
1246 HUD_Panel_GetName(highlightedPanel_prev);
1247 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
1250 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
1252 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
1254 if (bInputType == 1 || mouseClicked)
1257 if (highlightedPanel_prev != -1)
1259 HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev);
1260 panel_size_copied = panel_size;
1261 highlightedPanel_copied = highlightedPanel_prev;
1264 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
1266 if (bInputType == 1 || mouseClicked)
1269 if (highlightedPanel_copied == -1 || highlightedPanel_prev == -1)
1272 HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev);
1274 // reduce size if it'd go beyond screen boundaries
1275 vector tmp_size = panel_size_copied;
1276 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
1277 tmp_size_x = vid_conwidth - panel_pos_x;
1278 if (panel_pos_y + panel_size_copied_y > vid_conheight)
1279 tmp_size_y = vid_conheight - panel_pos_y;
1281 if (panel_size == tmp_size)
1285 panel_pos_backup = panel_pos;
1286 panel_size_backup = panel_size;
1287 highlightedPanel_backup = highlightedPanel_prev;
1289 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
1290 HUD_Panel_GetName(highlightedPanel_prev);
1291 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1293 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
1295 if (bInputType == 1 || mouseClicked)
1297 //restore previous values
1298 if (highlightedPanel_backup != -1)
1300 HUD_Panel_GetName(highlightedPanel_backup);
1301 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
1302 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
1303 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
1304 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1305 highlightedPanel_backup = -1;
1308 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
1310 if (bInputType == 1)
1312 pressed_key_time = 0;
1315 else if (pressed_key_time == 0)
1316 pressed_key_time = time;
1318 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
1320 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
1322 if (bInputType == 1)
1324 if (highlightedPanel_prev != -1)
1326 highlightedPanel = highlightedPanel_prev;
1327 HUD_Panel_EnableMenu();
1330 else if(hit_con_bind)
1336 float HUD_Panel_HighlightCheck()
1340 while(j < HUD_PANEL_NUM)
1345 HUD_Panel_UpdatePosSizeForId(i);
1347 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1350 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)
1354 // resize from topleft border
1355 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)
1359 // resize from topright border
1360 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)
1364 // resize from bottomleft border
1365 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)
1369 // resize from bottomright border
1370 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)
1378 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
1379 void HUD_Panel_FirstInDrawQ(float id)
1382 var float place = -1;
1383 // find out where in the array our current id is, save into place
1384 for(i = 0; i < HUD_PANEL_NUM; ++i)
1386 if(panel_order[i] == id)
1392 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
1394 place = HUD_PANEL_NUM - 1;
1396 // move all ids up by one step in the array until "place"
1397 for(i = place; i > 0; --i)
1399 panel_order[i] = panel_order[i-1];
1401 // now save the new top id
1402 panel_order[0] = id;
1404 // let's save them into the cvar by some strcat trickery
1406 for(i = 0; i < HUD_PANEL_NUM; ++i)
1408 s = strcat(s, ftos(panel_order[i]), " ");
1410 cvar_set("_hud_panelorder", s);
1411 if(hud_panelorder_prev)
1412 strunzone(hud_panelorder_prev);
1413 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
1416 void HUD_Panel_Highlight()
1420 while(j < HUD_PANEL_NUM)
1425 HUD_Panel_UpdatePosSizeForId(i);
1427 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1430 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)
1432 highlightedPanel = i;
1433 HUD_Panel_FirstInDrawQ(i);
1434 highlightedAction = 1;
1435 panel_click_distance = mousepos - panel_pos;
1438 // resize from topleft border
1439 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)
1441 highlightedPanel = i;
1442 HUD_Panel_FirstInDrawQ(i);
1443 highlightedAction = 2;
1445 panel_click_distance = mousepos - panel_pos;
1446 panel_click_resizeorigin = panel_pos + panel_size;
1449 // resize from topright border
1450 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)
1452 highlightedPanel = i;
1453 HUD_Panel_FirstInDrawQ(i);
1454 highlightedAction = 2;
1456 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
1457 panel_click_distance_y = mousepos_y - panel_pos_y;
1458 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
1461 // resize from bottomleft border
1462 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)
1464 highlightedPanel = i;
1465 HUD_Panel_FirstInDrawQ(i);
1466 highlightedAction = 2;
1468 panel_click_distance_x = mousepos_x - panel_pos_x;
1469 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
1470 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
1473 // resize from bottomright border
1474 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)
1476 highlightedPanel = i;
1477 HUD_Panel_FirstInDrawQ(i);
1478 highlightedAction = 2;
1480 panel_click_distance = panel_size - mousepos + panel_pos;
1481 panel_click_resizeorigin = panel_pos;
1486 highlightedPanel_prev = -1;
1491 void HUD_Panel_EnableMenu()
1494 menu_enabled_time = time;
1495 HUD_Panel_GetName(highlightedPanel);
1496 localcmd("menu_showhudoptions ", panel_name, "\n");
1498 float highlightcheck;
1499 vector prev_pos, prev_size;
1500 void HUD_Panel_Mouse()
1502 // 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
1503 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1507 print("menu_enabled: ", ftos(menu_enabled), "\n");
1508 print("Highlighted: ", ftos(highlightedPanel), "\n");
1509 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1512 // instantly hide the editor cursor if we open the HUDExit dialog
1513 // as hud_fade_alpha doesn't decrease to 0 in this case
1514 // TODO: find a way to fade the cursor out even in this case
1515 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1518 if(mouseClicked == 0 && menu_enabled != 2 && highlightedPanel >= 0) { // don't reset these variables in menu_enabled mode 2!
1519 highlightedPanel = -1;
1520 highlightedAction = 0;
1522 if(highlightedPanel != -1)
1523 highlightedPanel_prev = highlightedPanel;
1525 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1527 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1528 mousepos_y = bound(0, mousepos_y, vid_conheight);
1532 if (tab_panel != -1)
1534 //stop ctrl-tab selection
1538 if(prevMouseClicked == 0)
1540 HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1541 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1542 prev_pos = panel_pos;
1543 prev_size = panel_size;
1546 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1548 if (prev_pos != panel_pos || prev_size != panel_size)
1550 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1552 panel_pos_backup = prev_pos;
1553 panel_size_backup = prev_size;
1554 highlightedPanel_backup = highlightedPanel;
1557 // in case the clicked panel is inside another panel and we aren't
1558 // moving it, avoid the immediate "fix" of its position/size
1559 // (often unwanted and hateful) by disabling collisions check
1560 hud_configure_checkcollisions = false;
1562 if(highlightedAction == 1)
1563 HUD_Panel_SetPos(mousepos - panel_click_distance);
1564 else if(highlightedAction == 2)
1567 if(resizeCorner == 1) {
1568 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1569 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1570 } else if(resizeCorner == 2) {
1571 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1572 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1573 } else if(resizeCorner == 3) {
1574 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1575 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1576 } else { // resizeCorner == 4
1577 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1578 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1580 HUD_Panel_SetPosSize(mySize);
1583 // doubleclick check
1584 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1586 mouseClicked = 0; // to prevent spam, I guess.
1587 HUD_Panel_EnableMenu();
1590 if(prevMouseClicked == 0)
1592 prevMouseClickedTime = time;
1593 prevMouseClickedPos = mousepos;
1598 highlightcheck = HUD_Panel_HighlightCheck();
1600 // draw cursor after performing move/resize to have the panel pos/size updated before highlightcheck
1602 cursorsize = '32 32 0';
1604 if(highlightcheck == 0)
1605 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1606 else if(highlightcheck == 1)
1607 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1608 else if(highlightcheck == 2)
1609 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1611 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1613 prevMouseClicked = mouseClicked;
1616 // Weapon icons (#0)
1618 float weaponspace[10];
1619 #define HUD_Weapons_Clear()\
1621 for(idx = 0; idx < 10; ++idx)\
1622 weaponspace[idx] = 0
1624 entity weaponorder[WEP_MAXCOUNT];
1625 void weaponorder_swap(float i, float j, entity pass)
1629 weaponorder[i] = weaponorder[j];
1633 string weaponorder_cmp_str;
1634 float weaponorder_cmp(float i, float j, entity pass)
1637 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1638 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1639 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)
1642 float GetAmmoStat(float i)
1646 case 0: return STAT_SHELLS;
1647 case 1: return STAT_NAILS;
1648 case 2: return STAT_ROCKETS;
1649 case 3: return STAT_CELLS;
1650 case 4: return STAT_FUEL;
1655 float GetAmmoTypeForWep(float i)
1659 case WEP_SHOTGUN: return 0;
1660 case WEP_UZI: return 1;
1661 case WEP_GRENADE_LAUNCHER: return 2;
1662 case WEP_MINE_LAYER: return 2;
1663 case WEP_ELECTRO: return 3;
1664 case WEP_CRYLINK: return 3;
1665 case WEP_HLAC: return 3;
1666 case WEP_MINSTANEX: return 3;
1667 case WEP_NEX: return 3;
1668 case WEP_CAMPINGRIFLE: return 1;
1669 case WEP_HAGAR: return 2;
1670 case WEP_ROCKET_LAUNCHER: return 2;
1671 case WEP_SEEKER: return 2;
1672 case WEP_FIREBALL: return 4;
1673 case WEP_HOOK: return 3;
1678 void HUD_Weapons(void)
1681 float center_x, center_y;
1683 if(!autocvar__hud_configure)
1685 if(!autocvar_hud_panel_weapons) return;
1686 if(spectatee_status == -1) return;
1689 float timeout = autocvar_hud_panel_weapons_timeout;
1690 float timeout_effect_length, timein_effect_length;
1691 if (autocvar_hud_panel_weapons_timeout_effect == 0)
1693 timeout_effect_length = 0;
1694 timein_effect_length = 0;
1698 timeout_effect_length = 0.75;
1699 timein_effect_length = 0.375;
1702 if (timeout && time >= weapontime + timeout + timeout_effect_length && !autocvar__hud_configure)
1704 weaponprevtime = time;
1708 active_panel = HUD_PANEL_WEAPONS;
1709 HUD_Panel_UpdateCvars(weapons);
1711 if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
1713 f = (time - (weapontime + timeout)) / timeout_effect_length;
1714 if (autocvar_hud_panel_weapons_timeout_effect)
1716 panel_bg_alpha *= (1 - f);
1717 panel_fg_alpha *= (1 - f);
1719 if (autocvar_hud_panel_weapons_timeout_effect == 1)
1721 f *= f; // for a cooler movement
1722 center_x = panel_pos_x + panel_size_x/2;
1723 center_y = panel_pos_y + panel_size_y/2;
1724 screen_ar = vid_conwidth/vid_conheight;
1725 if (center_x/center_y < screen_ar) //bottom left
1727 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1728 panel_pos_y += f * (vid_conheight - panel_pos_y);
1730 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1734 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1735 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1737 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1740 weaponprevtime = time - (1 - f) * timein_effect_length;
1742 else if (timeout && time < weaponprevtime + timein_effect_length && !autocvar__hud_configure)
1744 f = (time - weaponprevtime) / timein_effect_length;
1745 if (autocvar_hud_panel_weapons_timeout_effect)
1747 panel_bg_alpha *= (f);
1748 panel_fg_alpha *= (f);
1750 if (autocvar_hud_panel_weapons_timeout_effect == 1)
1752 f *= f; // for a cooler movement
1754 center_x = panel_pos_x + panel_size_x/2;
1755 center_y = panel_pos_y + panel_size_y/2;
1756 screen_ar = vid_conwidth/vid_conheight;
1757 if (center_x/center_y < screen_ar) //bottom left
1759 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1760 panel_pos_y += f * (vid_conheight - panel_pos_y);
1762 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1766 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1767 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1769 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1774 float i, weapid, wpnalpha, weapon_cnt;
1776 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1778 self = get_weaponinfo(i);
1779 if(self.impulse >= 0)
1783 // TODO make this configurable
1784 if(weaponorder_bypriority != autocvar_cl_weaponpriority)
1786 if(weaponorder_bypriority)
1787 strunzone(weaponorder_bypriority);
1788 if(weaponorder_byimpulse)
1789 strunzone(weaponorder_byimpulse);
1791 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
1792 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
1793 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1796 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1798 self = get_weaponinfo(i);
1799 if(self.impulse >= 0)
1801 weaponorder[weapon_cnt] = self;
1805 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1807 weaponorder_cmp_str = string_null;
1810 HUD_Panel_DrawBg(1);
1811 if(panel_bg_padding)
1813 panel_pos += '1 1 0' * panel_bg_padding;
1814 panel_size -= '2 2 0' * panel_bg_padding;
1817 if(autocvar_hud_panel_weapons_fade)
1819 wpnalpha = 3.2 - 2 * (time - weapontime);
1820 wpnalpha = bound(0.7, wpnalpha, 1) * panel_fg_alpha;
1823 wpnalpha = panel_fg_alpha;
1825 HUD_Weapons_Clear();
1827 float rows, columns;
1828 float aspect = autocvar_hud_panel_weapons_aspect;
1829 rows = panel_size_y/panel_size_x;
1830 rows = bound(1, floor((sqrt(4 * aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1832 columns = ceil(WEP_COUNT/rows);
1835 float a, type, fullammo;
1837 when = autocvar_hud_panel_weapons_complainbubble_time;
1839 fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
1847 wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
1848 float barsize_x, barsize_y, baroffset_x, baroffset_y;
1849 if (autocvar_hud_panel_weapons_ammo)
1851 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
1852 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
1855 if(wpnsize_x/wpnsize_y > aspect)
1857 barsize_x = aspect * wpnsize_y;
1858 barsize_y = wpnsize_y;
1859 baroffset_x = (wpnsize_x - barsize_x) / 2;
1863 barsize_y = 1/aspect * wpnsize_x;
1864 barsize_x = wpnsize_x;
1865 baroffset_y = (wpnsize_y - barsize_y) / 2;
1869 float show_accuracy;
1871 if(autocvar_hud_panel_weapons_accuracy && acc_levels)
1873 show_accuracy = true;
1874 if (acc_col_x[0] == -1)
1875 for (i = 0; i < acc_levels; ++i)
1876 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
1879 float weapons_st = getstati(STAT_WEAPONS);
1880 float label = autocvar_hud_panel_weapons_label;
1882 for(i = 0; i < weapon_cnt; ++i)
1884 wpnpos = panel_pos + eX * column * wpnsize_x + eY * row * wpnsize_y;
1886 self = weaponorder[i];
1887 weapid = self.impulse;
1889 // draw background behind currently selected weapon
1890 if(self.weapon == activeweapon)
1891 drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1893 // draw the weapon accuracy
1896 weapon_stats = weapon_accuracy[self.weapon-WEP_FIRST];
1897 if(weapon_stats >= 0)
1899 // find the max level lower than weapon_stats
1902 while ( j && weapon_stats < acc_lev[j] )
1905 // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
1907 factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
1909 color = color + factor * (acc_col[j+1] - color);
1911 drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
1915 // draw the weapon icon
1916 if((weapid >= 0) && (weapons_st & self.weapons))
1918 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1920 if(label == 1) // weapon number
1921 drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1922 else if(label == 2) // bind
1923 drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1925 // draw ammo status bar
1926 if(autocvar_hud_panel_weapons_ammo && weapid != WEP_TUBA && weapid != WEP_LASER && weapid != WEP_PORTO)
1929 type = GetAmmoTypeForWep(weapid);
1931 a = getstati(GetAmmoStat(type)); // how much ammo do we have?
1936 case 0: fullammo = autocvar_hud_panel_weapons_ammo_full_shells; break;
1937 case 1: fullammo = autocvar_hud_panel_weapons_ammo_full_nails; break;
1938 case 2: fullammo = autocvar_hud_panel_weapons_ammo_full_rockets; break;
1939 case 3: fullammo = autocvar_hud_panel_weapons_ammo_full_cells; break;
1940 case 4: fullammo = autocvar_hud_panel_weapons_ammo_full_fuel; break;
1941 default: fullammo = 60;
1945 wpnpos_x + baroffset_x,
1946 wpnpos_y + baroffset_y,
1947 barsize_x * bound(0, a/fullammo, 1),
1949 drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
1950 drawresetcliparea();
1955 // draw a "ghost weapon icon" if you don't have the weapon
1958 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
1961 // draw the complain message
1962 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
1966 if(complain_weapon_time + when > time)
1969 a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
1973 if(complain_weapon_time + when > time)
1980 if(complain_weapon_type == 0) {
1982 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
1984 else if(complain_weapon_type == 1) {
1986 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
1990 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
1992 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
1993 drawpic_aspect_skin(wpnpos + '1 1 0' * padding, "weapon_complainbubble", wpnsize - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
1994 drawstring_aspect(wpnpos + '1 1 0' * padding, s, wpnsize - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2010 float GetAmmoItemCode(float i)
2014 case 0: return IT_SHELLS;
2015 case 1: return IT_NAILS;
2016 case 2: return IT_ROCKETS;
2017 case 3: return IT_CELLS;
2018 case 4: return IT_FUEL;
2023 string GetAmmoPicture(float i)
2027 case 0: return "ammo_shells";
2028 case 1: return "ammo_bullets";
2029 case 2: return "ammo_rockets";
2030 case 3: return "ammo_cells";
2031 case 4: return "ammo_fuel";
2036 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
2039 if(autocvar__hud_configure)
2041 currently_selected = (itemcode == 2); //rockets always selected
2042 a = 31 + mod(itemcode*93, 128);
2045 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
2054 if(currently_selected)
2059 vector picpos, numpos;
2060 if(autocvar_hud_panel_ammo_iconalign)
2063 picpos = myPos + eX * 2 * mySize_y;
2067 numpos = myPos + eX * mySize_y;
2071 if (currently_selected)
2072 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2074 if(a > 0 && autocvar_hud_panel_ammo_progressbar)
2075 HUD_Panel_DrawProgressBar(myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize_x, mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize_x, autocvar_hud_panel_ammo_progressbar_name, 0, 0, a/autocvar_hud_panel_ammo_maxammo, color, autocvar_hud_progressbar_alpha * panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2077 if(autocvar_hud_panel_ammo_text)
2080 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2081 else // "ghost" ammo count
2082 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
2085 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2086 else // "ghost" ammo icon
2087 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
2092 if(!autocvar__hud_configure)
2094 if(!autocvar_hud_panel_ammo) return;
2095 if(spectatee_status == -1) return;
2098 active_panel = HUD_PANEL_AMMO;
2099 HUD_Panel_UpdateCvars(ammo);
2102 mySize = panel_size;
2104 HUD_Panel_DrawBg(1);
2105 if(panel_bg_padding)
2107 pos += '1 1 0' * panel_bg_padding;
2108 mySize -= '2 2 0' * panel_bg_padding;
2111 float rows, columns, row, column;
2113 if (autocvar_hud_panel_ammo_onlycurrent)
2117 rows = mySize_y/mySize_x;
2118 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
2119 // ^^^ ammo item aspect goes here
2121 columns = ceil(AMMO_COUNT/rows);
2123 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
2128 if(ammo_size_x/ammo_size_y > 3)
2130 newSize = 3 * ammo_size_y;
2131 offset_x = ammo_size_x - newSize;
2132 pos_x += offset_x/2;
2133 ammo_size_x = newSize;
2137 newSize = 1/3 * ammo_size_x;
2138 offset_y = ammo_size_y - newSize;
2139 pos_y += offset_y/2;
2140 ammo_size_y = newSize;
2143 drawfont = hud_bigfont;
2144 float i, stat_items, currently_selected;
2145 if (autocvar_hud_panel_ammo_onlycurrent)
2147 if(autocvar__hud_configure)
2149 DrawAmmoItem(pos, ammo_size, 2, true); //show rockets
2152 stat_items = getstati(STAT_ITEMS);
2153 for (i = 0; i < AMMO_COUNT; ++i) {
2154 currently_selected = stat_items & GetAmmoItemCode(i);
2155 if (currently_selected)
2157 DrawAmmoItem(pos, ammo_size, i, true);
2161 return; // nothing to display
2164 stat_items = getstati(STAT_ITEMS);
2165 for (i = 0; i < AMMO_COUNT; ++i) {
2166 currently_selected = stat_items & GetAmmoItemCode(i);
2167 DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected);
2172 column = column + 1;
2175 drawfont = hud_font;
2178 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float alpha)
2180 vector newPos, newSize;
2181 vector picpos, numpos;
2185 if(mySize_y/mySize_x > 2)
2187 newSize_y = 2 * mySize_x;
2188 newSize_x = mySize_x;
2190 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
2195 newSize_x = 1/2 * mySize_y;
2196 newSize_y = mySize_y;
2198 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
2202 if(icon_right_align)
2205 picpos = newPos + eY * newSize_x;
2210 numpos = newPos + eY * newSize_x;
2214 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2215 // make number smaller than icon, it looks better
2216 // reduce only y to draw numbers with different number of digits with the same y size
2217 numpos_y += newSize_y * ((1 - 0.7) / 2);
2219 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2223 if(mySize_x/mySize_y > 3)
2225 newSize_x = 3 * mySize_y;
2226 newSize_y = mySize_y;
2228 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
2233 newSize_y = 1/3 * mySize_x;
2234 newSize_x = mySize_x;
2236 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
2240 if(icon_right_align) // right align
2243 picpos = newPos + eX * 2 * newSize_y;
2247 numpos = newPos + eX * newSize_y;
2251 drawstring_aspect(numpos, ftos(x), '2 1 0' * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2252 drawpic_aspect_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2255 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float fadelerp)
2258 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
2260 DrawNumIcon(myPos + expandingbox_resize_centered_box_offset(sz, mySize, 1), mySize * sz, x, icon, vertical, icon_right_align, color, (1 - fadelerp));
2265 void HUD_Powerups(void) {
2266 if(!autocvar__hud_configure)
2268 if(!autocvar_hud_panel_powerups) return;
2269 if(spectatee_status == -1) return;
2270 if not(getstati(STAT_ITEMS) & (IT_STRENGTH | IT_INVINCIBLE)) return;
2271 if (getstati(STAT_HEALTH) <= 0) return;
2274 active_panel = HUD_PANEL_POWERUPS;
2275 HUD_Panel_UpdateCvars(powerups);
2278 mySize = panel_size;
2280 float strength_time, shield_time;
2281 if(autocvar__hud_configure)
2288 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
2289 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
2292 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
2293 if(panel_bg_padding)
2295 pos += '1 1 0' * panel_bg_padding;
2296 mySize -= '2 2 0' * panel_bg_padding;
2303 string leftname, rightname;
2304 string leftprogressname, rightprogressname;
2305 float leftcnt, rightcnt;
2306 float leftexact, rightexact;
2307 if (autocvar_hud_panel_powerups_flip) {
2308 leftname = "strength";
2309 leftprogressname = autocvar_hud_panel_powerups_progressbar_strength;
2310 leftcnt = ceil(strength_time);
2311 leftexact = strength_time;
2313 rightname = "shield";
2314 rightprogressname = autocvar_hud_panel_powerups_progressbar_shield;
2315 rightcnt = ceil(shield_time);
2316 rightexact = shield_time;
2318 leftname = "shield";
2319 leftprogressname = autocvar_hud_panel_powerups_progressbar_shield;
2320 leftcnt = ceil(shield_time);
2321 leftexact = shield_time;
2323 rightname = "strength";
2324 rightprogressname = autocvar_hud_panel_powerups_progressbar_strength;
2325 rightcnt = ceil(strength_time);
2326 rightexact = strength_time;
2329 drawfont = hud_bigfont;
2330 float baralign = autocvar_hud_panel_powerups_baralign;
2331 float iconalign = autocvar_hud_panel_powerups_iconalign;
2333 float panel_ar = mySize_x/mySize_y;
2334 float is_vertical = (panel_ar < 1);
2335 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
2337 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2340 if(autocvar_hud_panel_powerups_progressbar)
2342 HUD_Panel_GetProgressBarColorForString(leftname);
2343 HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, 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);
2345 if(autocvar_hud_panel_powerups_text)
2348 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
2350 DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2357 if(autocvar_hud_panel_powerups_progressbar)
2359 HUD_Panel_GetProgressBarColorForString(rightname);
2360 HUD_Panel_DrawProgressBar(pos, barsize, rightprogressname, 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);
2362 if(autocvar_hud_panel_powerups_text)
2365 DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
2367 DrawNumIcon_expanding(pos, 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));
2373 barsize = eX * mySize_x + eY * 0.5 * mySize_y;
2376 if(autocvar_hud_panel_powerups_progressbar)
2378 HUD_Panel_GetProgressBarColorForString(leftname);
2379 HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, 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);
2381 if(autocvar_hud_panel_powerups_text)
2384 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
2386 DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2393 if(autocvar_hud_panel_powerups_progressbar)
2395 HUD_Panel_GetProgressBarColorForString(rightname);
2396 HUD_Panel_DrawProgressBar(pos, barsize, rightprogressname, 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);
2398 if(autocvar_hud_panel_powerups_text)
2401 DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
2403 DrawNumIcon_expanding(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
2407 drawfont = hud_font;
2410 // Health/armor (#3)
2412 void HUD_HealthArmor(void)
2414 if(!autocvar__hud_configure)
2416 if(!autocvar_hud_panel_healtharmor) return;
2417 if(spectatee_status == -1) return;
2420 active_panel = HUD_PANEL_HEALTHARMOR;
2421 HUD_Panel_UpdateCvars(healtharmor);
2424 mySize = panel_size;
2426 HUD_Panel_DrawBg(1);
2427 if(panel_bg_padding)
2429 pos += '1 1 0' * panel_bg_padding;
2430 mySize -= '2 2 0' * panel_bg_padding;
2433 float armor, health, fuel;
2434 armor = getstati(STAT_ARMOR);
2435 health = getstati(STAT_HEALTH);
2436 fuel = getstati(STAT_FUEL);
2438 if(autocvar__hud_configure)
2449 vector picpos, numpos;
2451 drawfont = hud_bigfont;
2452 float baralign = autocvar_hud_panel_healtharmor_baralign;
2453 float iconalign = autocvar_hud_panel_healtharmor_iconalign;
2455 float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
2456 float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
2457 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
2460 v = healtharmor_maxdamage(health, armor, armorblockpercent);
2465 float maxtotal = maxhealth + maxarmor;
2467 if(v_z) // NOT fully armored
2469 biggercount = "health";
2470 if(autocvar_hud_panel_healtharmor_progressbar)
2472 HUD_Panel_GetProgressBarColor(health);
2473 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2476 if(autocvar_hud_panel_healtharmor_text)
2477 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);
2481 biggercount = "armor";
2482 if(autocvar_hud_panel_healtharmor_progressbar)
2484 HUD_Panel_GetProgressBarColor(armor);
2485 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2488 if(autocvar_hud_panel_healtharmor_text)
2489 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);
2491 if(autocvar_hud_panel_healtharmor_text)
2492 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
2496 HUD_Panel_GetProgressBarColor(fuel);
2497 HUD_Panel_DrawProgressBar(pos, eX * mySize_x + eY * 0.2 * mySize_y, "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2502 string leftname, rightname;
2503 string leftprogressname, rightprogressname;
2504 float leftcnt, rightcnt;
2505 float leftmax, rightmax;
2506 float leftactive, rightactive;
2507 float leftalpha, rightalpha;
2508 if (autocvar_hud_panel_healtharmor_flip) { // old style layout with armor left/top of health
2510 leftprogressname = autocvar_hud_panel_healtharmor_progressbar_armor;
2514 leftalpha = min((armor+10)/55, 1);
2517 rightname = "health";
2518 rightprogressname = autocvar_hud_panel_healtharmor_progressbar_health;
2522 rightmax = maxhealth;
2524 leftname = "health";
2525 leftprogressname = autocvar_hud_panel_healtharmor_progressbar_health;
2529 leftmax = maxhealth;
2531 rightname = "armor";
2532 rightprogressname = autocvar_hud_panel_healtharmor_progressbar_armor;
2536 rightalpha = min((armor+10)/55, 1);
2537 rightmax = maxarmor;
2540 float panel_ar = mySize_x/mySize_y;
2541 float is_vertical = (panel_ar < 1);
2542 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
2544 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2547 if(autocvar_hud_panel_healtharmor_progressbar)
2549 HUD_Panel_GetProgressBarColorForString(leftname);
2550 HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, leftcnt/leftmax, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2552 if(autocvar_hud_panel_healtharmor_text)
2553 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, leftmax), 1);
2558 if(autocvar_hud_panel_healtharmor_progressbar)
2560 HUD_Panel_GetProgressBarColorForString(rightname);
2561 HUD_Panel_DrawProgressBar(pos + eX * 0.5 * mySize_x, barsize, rightprogressname, rightcnt/rightmax, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2563 if(autocvar_hud_panel_healtharmor_text)
2564 DrawNumIcon(pos + eX * 0.5 * mySize_x, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, rightmax), 1);
2569 HUD_Panel_GetProgressBarColor(fuel);
2570 if (is_vertical) //if vertical always halve x to not cover too much numbers with 3 digits
2571 mySize_x *= 0.2 * 0.5 / 2;
2574 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2579 barsize = eX * mySize_x + eY * 0.5 * mySize_y;
2582 if(autocvar_hud_panel_healtharmor_progressbar)
2584 HUD_Panel_GetProgressBarColorForString(leftname);
2585 HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, leftcnt/leftmax, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2587 if(autocvar_hud_panel_healtharmor_text)
2588 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, leftmax), 1);
2593 if(autocvar_hud_panel_healtharmor_progressbar)
2595 HUD_Panel_GetProgressBarColorForString(rightname);
2596 HUD_Panel_DrawProgressBar(pos + eY * 0.5 * mySize_y, barsize, rightprogressname, rightcnt/rightmax, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2598 if(autocvar_hud_panel_healtharmor_text)
2599 DrawNumIcon(pos + eY * 0.5 * mySize_y, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, rightmax), 1);
2604 HUD_Panel_GetProgressBarColor(fuel);
2605 if (is_vertical) //if vertical always halve x to not cover numbers with 3 digits
2606 mySize_x *= 0.2 / 2;
2608 mySize_y *= 0.2 * 0.5;
2609 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2613 drawfont = hud_font;
2616 // Notification area (#4)
2619 string Weapon_SuicideMessage(float deathtype)
2621 w_deathtype = deathtype;
2622 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2623 return w_deathtypestring;
2626 string Weapon_KillMessage(float deathtype)
2628 w_deathtype = deathtype;
2629 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2630 return w_deathtypestring;
2633 #define KN_MAX_ENTRIES 10
2635 float killnotify_times[KN_MAX_ENTRIES];
2636 float killnotify_deathtype[KN_MAX_ENTRIES];
2637 float killnotify_actiontype[KN_MAX_ENTRIES]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2638 string killnotify_attackers[KN_MAX_ENTRIES];
2639 string killnotify_victims[KN_MAX_ENTRIES];
2640 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2644 kn_index = KN_MAX_ENTRIES-1;
2645 killnotify_times[kn_index] = time;
2646 killnotify_deathtype[kn_index] = wpn;
2647 killnotify_actiontype[kn_index] = actiontype;
2648 if(killnotify_attackers[kn_index])
2649 strunzone(killnotify_attackers[kn_index]);
2650 killnotify_attackers[kn_index] = strzone(attacker);
2651 if(killnotify_victims[kn_index])
2652 strunzone(killnotify_victims[kn_index]);
2653 killnotify_victims[kn_index] = strzone(victim);
2656 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
2659 float alsoprint, gentle;
2660 alsoprint = (autocvar_hud_panel_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
2661 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
2663 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
2666 if(msg == MSG_SUICIDE) {
2667 w = DEATH_WEAPONOF(type);
2669 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2671 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
2672 } else if (type == DEATH_KILL) {
2673 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2675 print ("^1",s1, "^1 couldn't take it anymore\n");
2676 } else if (type == DEATH_ROT) {
2677 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2679 print ("^1",s1, "^1 died\n");
2680 } else if (type == DEATH_NOAMMO) {
2681 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2683 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2684 } else if (type == DEATH_CAMP) {
2685 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2687 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2688 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2689 HUD_KillNotify_Push(s1, "", 0, type);
2691 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2692 } else if (type == DEATH_CHEAT) {
2693 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2695 print ("^1",s1, "^1 unfairly eliminated themself\n");
2696 } else if (type == DEATH_FIRE) {
2697 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2699 print ("^1",s1, "^1 burned to death\n");
2700 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2701 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2703 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2706 if (stof(s2) > 2) // killcount > 2
2707 print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2708 } else if(msg == MSG_KILL) {
2709 w = DEATH_WEAPONOF(type);
2711 if((w == WEP_CAMPINGRIFLE || w == WEP_MINSTANEX) && type & HITTYPE_HEADSHOT) // all headshot weapons go here
2712 HUD_KillNotify_Push(s1, s2, 1, DEATH_HEADSHOT);
2714 HUD_KillNotify_Push(s1, s2, 1, type);
2717 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
2719 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2720 HUD_KillNotify_Push(s1, s2, 1, type);
2724 print ("^1", s1, "^1 took action against a team mate\n");
2726 print ("^1", s1, "^1 mows down a team mate\n");
2729 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2731 print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2733 print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2735 else if (stof(s2) > 2) {
2737 print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2739 print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2742 else if(type == KILL_FIRST_BLOOD)
2743 print("^1",s1, "^1 drew first blood", "\n");
2744 else if (type == DEATH_TELEFRAG) {
2745 HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
2747 print ("^1",s2, "^1 tried to occupy ", s1, "^1's teleport destination space\n");
2749 print ("^1",s2, "^1 was telefragged by ", s1, "\n");
2751 else if (type == DEATH_DROWN) {
2752 HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
2754 print ("^1",s2, "^1 was drowned by ", s1, "\n");
2756 else if (type == DEATH_SLIME) {
2757 HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
2759 print ("^1",s2, "^1 was slimed by ", s1, "\n");
2761 else if (type == DEATH_LAVA) {
2762 HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
2764 print ("^1",s2, "^1 was cooked by ", s1, "\n");
2766 else if (type == DEATH_FALL) {
2767 HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
2769 print ("^1",s2, "^1 was grounded by ", s1, "\n");
2771 else if (type == DEATH_SHOOTING_STAR) {
2772 HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
2774 print ("^1",s2, "^1 was shot into space by ", s1, "\n");
2776 else if (type == DEATH_SWAMP) {
2777 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2779 print ("^1",s2, "^1 was conserved by ", s1, "\n");
2781 else if (type == DEATH_HURTTRIGGER)
2783 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2785 print("^1",s2, "^1 was thrown into a world of hurt by ", s1, "\n");
2786 } else if(type == DEATH_SBCRUSH) {
2787 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2789 print ("^1",s2, "^1 was crushed by ^1", s1, "\n");
2790 } else if(type == DEATH_SBMINIGUN) {
2791 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2793 print ("^1",s2, "^1 got shredded by ^1", s1, "\n");
2794 } else if(type == DEATH_SBROCKET) {
2795 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2797 print ("^1",s2, "^1 was blased to bits by ^1", s1, "\n");
2798 } else if(type == DEATH_SBBLOWUP) {
2799 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2801 print ("^1",s2, "^1 got caught in the destruction of ^1", s1, "'s vehicle\n");
2802 } else if(type == DEATH_WAKIGUN) {
2803 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2805 print ("^1",s2, "^1 was bolted down by ^1", s1, "\n");
2806 } else if(type == DEATH_WAKIROCKET) {
2807 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2809 print ("^1",s2, "^1 could find no shelter from ^1", s1, "'s rockets\n");
2810 } else if(type == DEATH_WAKIBLOWUP) {
2811 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2813 print ("^1",s2, "^1 dies when ^1", s1, "'s wakizashi dies.\n");
2814 } else if(type == DEATH_TURRET) {
2815 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2817 print ("^1",s2, "^1 was pushed into the line of fire by ^1", s1, "\n");
2818 } else if(type == DEATH_TOUCHEXPLODE) {
2819 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2821 print ("^1",s2, "^1 was pushed into an accident by ^1", s1, "\n");
2822 } else if(type == DEATH_CHEAT) {
2823 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2825 print ("^1",s2, "^1 was unfairly eliminated by ^1", s1, "\n");
2826 } else if (type == DEATH_FIRE) {
2827 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2829 print ("^1",s2, "^1 was burnt to death by ^1", s1, "\n");
2830 } else if (type == DEATH_CUSTOM) {
2831 HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
2833 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2834 } else if (type == DEATH_HURTTRIGGER) {
2835 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2837 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2839 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2841 print ("^1",s2, "^1 was fragged by ", s1, "\n");
2843 } else if(msg == MSG_SPREE) {
2844 if(type == KILL_END_SPREE) {
2846 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2848 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2849 } else if(type == KILL_SPREE) {
2851 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2853 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2854 } else if(type == KILL_SPREE_3) {
2856 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2858 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2859 } else if(type == KILL_SPREE_5) {
2861 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2863 print (s1,"^7 unleashes ^1RAGE\n");
2864 } else if(type == KILL_SPREE_10) {
2866 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2868 print (s1,"^7 starts the ^1MASSACRE!\n");
2869 } else if(type == KILL_SPREE_15) {
2871 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2873 print (s1,"^7 executes ^1MAYHEM!\n");
2874 } else if(type == KILL_SPREE_20) {
2876 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2878 print (s1,"^7 is a ^1BERSERKER!\n");
2879 } else if(type == KILL_SPREE_25) {
2881 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2883 print (s1,"^7 inflicts ^1CARNAGE!\n");
2884 } else if(type == KILL_SPREE_30) {
2886 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2888 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2890 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2891 if (type == DEATH_DROWN) {
2892 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2896 print ("^1",s1, "^1 was in the water for too long\n");
2898 print ("^1",s1, "^1 drowned\n");
2900 } else if (type == DEATH_SLIME) {
2901 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2903 print ("^1",s1, "^1 was slimed\n");
2904 } else if (type == DEATH_LAVA) {
2905 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2909 print ("^1",s1, "^1 found a hot place\n");
2911 print ("^1",s1, "^1 turned into hot slag\n");
2913 } else if (type == DEATH_FALL) {
2914 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2918 print ("^1",s1, "^1 tested gravity (and it worked)\n");
2920 print ("^1",s1, "^1 hit the ground with a crunch\n");
2922 } else if (type == DEATH_SHOOTING_STAR) {
2923 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2925 print ("^1",s1, "^1 became a shooting star\n");
2926 } else if (type == DEATH_SWAMP) {
2927 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2931 print ("^1",s1, "^1 discovered a swamp\n");
2933 print ("^1",s1, "^1 is now conserved for centuries to come\n");
2935 } else if(type == DEATH_TURRET) {
2936 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2938 print ("^1",s1, "^1 was mowed down by a turret \n");
2939 } else if (type == DEATH_CUSTOM) {
2940 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2942 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2943 } else if (type == DEATH_HURTTRIGGER) {
2944 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2946 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2947 } else if(type == DEATH_TOUCHEXPLODE) {
2948 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2950 print ("^1",s1, "^1 died in an accident\n");
2951 } else if(type == DEATH_CHEAT) {
2952 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2954 print ("^1",s1, "^1 was unfairly eliminated\n");
2955 } else if(type == DEATH_FIRE) {
2956 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2960 print ("^1",s1, "^1 felt a little hot\n");
2962 print ("^1",s1, "^1 burnt to death\n");
2965 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2969 print ("^1",s1, "^1 needs a restart\n");
2971 print ("^1",s1, "^1 died\n");
2974 } else if(msg == MSG_KILL_ACTION_SPREE) {
2976 print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2978 print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2979 } else if(msg == MSG_INFO) {
2980 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2981 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2982 print(s1, "^7 got the ", s2, "\n");
2983 } else if(type == INFO_LOSTFLAG) {
2984 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2985 print(s1, "^7 lost the ", s2, "\n");
2986 } else if(type == INFO_PICKUPFLAG) {
2987 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2988 print(s1, "^7 picked up the ", s2, "\n");
2989 } else if(type == INFO_RETURNFLAG) {
2990 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2991 print(s1, "^7 returned the ", s2, "\n");
2992 } else if(type == INFO_CAPTUREFLAG) {
2993 HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
2994 print(s1, "^7 captured the ", s2, s3, "\n");
2996 } else if(msg == MSG_RACE) {
2997 if(type == RACE_SERVER_RECORD) {
2998 HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
3000 else if(type == RACE_NEW_RANK) {
3001 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
3003 else if(type == RACE_NEW_TIME) {
3004 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
3006 else if(type == RACE_FAIL) {
3007 HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
3009 } else if(msg == MSG_KA) {
3010 if(type == KA_PICKUPBALL) {
3011 HUD_KillNotify_Push(s1, s2, 0, KA_PICKUPBALL);
3013 print (s1, "^7 has picked up the ball!\n");
3015 else if(type == KA_DROPBALL) {
3016 HUD_KillNotify_Push(s1, s2, 0, KA_DROPBALL);
3018 print(s1, "^7 has dropped the ball!\n");
3023 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
3025 void HUD_Centerprint(string s1, string s2, float type, float msg)
3028 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
3029 if(msg == MSG_SUICIDE) {
3030 if (type == DEATH_TEAMCHANGE) {
3031 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
3032 } else if (type == DEATH_AUTOTEAMCHANGE) {
3033 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
3034 } else if (type == DEATH_CAMP) {
3036 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
3038 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
3039 } else if (type == DEATH_NOAMMO) {
3041 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
3043 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
3044 } else if (type == DEATH_ROT) {
3046 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
3048 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
3049 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
3051 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
3053 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
3054 } else if (type == DEATH_QUIET) {
3056 } else { // generic message
3058 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
3060 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
3062 } else if(msg == MSG_KILL) {
3063 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
3065 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
3067 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
3069 } else if (type == KILL_FIRST_BLOOD) {
3071 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
3073 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
3075 } else if (type == KILL_FIRST_VICTIM) {
3077 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
3079 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
3081 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
3083 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
3085 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
3087 } else if (type == KILL_TYPEFRAGGED) {
3089 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
3091 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
3093 } else if (type == KILL_FRAG) {
3095 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
3097 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
3099 } else { // generic message
3101 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
3103 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
3106 } else if(msg == MSG_KILL_ACTION) {
3107 // TODO: invent more centerprints here?
3108 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
3112 void HUD_Notify (void)
3114 if(!autocvar_hud_panel_notify && !autocvar__hud_configure)
3117 active_panel = HUD_PANEL_NOTIFY;
3118 HUD_Panel_UpdateCvars(notify);
3121 mySize = panel_size;
3123 HUD_Panel_DrawBg(1);
3124 if(panel_bg_padding)
3126 pos += '1 1 0' * panel_bg_padding;
3127 mySize -= '2 2 0' * panel_bg_padding;
3130 float entries, height;
3131 entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
3132 height = mySize_y/entries;
3135 fontsize = '0.5 0.5 0' * height;
3139 when = autocvar_hud_panel_notify_time;
3141 fadetime = autocvar_hud_panel_notify_fadetime;
3145 vector pos_attacker, pos_victim;
3147 float width_attacker;
3148 string attacker, victim;
3150 float i, j, w, step, limit;
3151 if(autocvar_hud_panel_notify_flip) //order items from the top down
3157 else //order items from the bottom up
3164 for(j = kn_index; i != limit; i += step, ++j)
3166 if(autocvar__hud_configure)
3170 else // inverse order
3171 a = entries - 1 - i;
3172 attacker = textShortenToWidth(strcat("Player", ftos(a+1)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3173 victim = textShortenToWidth(strcat("Player", ftos(a+2)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3174 s = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
3175 a = bound(0, (when - a) / 4, 1);
3176 goto hud_config_notifyprint;
3179 if (j == KN_MAX_ENTRIES)
3182 if(killnotify_times[j] + when > time)
3186 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
3200 w = DEATH_WEAPONOF(killnotify_deathtype[j]);
3202 // TODO: maybe print in team colors?
3205 if(killnotify_actiontype[j] == 0)
3207 if(killnotify_deathtype[j] == DEATH_GENERIC)
3211 else if(killnotify_deathtype[j] == DEATH_NOAMMO)
3213 s = "notify_outofammo";
3215 else if(killnotify_deathtype[j] == DEATH_KILL)
3217 s = "notify_selfkill";
3219 else if(killnotify_deathtype[j] == DEATH_CAMP)
3221 s = "notify_camping";
3223 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
3225 s = "notify_teamkill_red";
3227 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
3229 s = "notify_teamkill_blue";
3231 else if(killnotify_deathtype[j] == DEATH_DROWN)
3235 else if(killnotify_deathtype[j] == DEATH_SLIME)
3239 else if(killnotify_deathtype[j] == DEATH_LAVA)
3243 else if(killnotify_deathtype[j] == DEATH_FALL)
3247 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
3249 s = "notify_shootingstar";
3251 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
3255 else if(killnotify_deathtype[j] == INFO_GOTFLAG)
3257 if(killnotify_victims[j] == "^1RED^7 flag")
3259 s = "notify_red_taken";
3263 s = "notify_blue_taken";
3266 else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
3268 if(killnotify_victims[j] == "^1RED^7 flag")
3270 s = "notify_red_returned";
3274 s = "notify_blue_returned";
3277 else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
3279 if(killnotify_victims[j] == "^1RED^7 flag")
3281 s = "notify_red_lost";
3285 s = "notify_blue_lost";
3288 else if(killnotify_deathtype[j] == INFO_CAPTUREFLAG)
3290 if(killnotify_victims[j] == "^1RED^7 flag")
3292 s = "notify_red_captured";
3296 s = "notify_blue_captured";
3299 else if(killnotify_deathtype[j] == KA_DROPBALL)
3301 s = "notify_balldropped";
3303 else if(killnotify_deathtype[j] == KA_PICKUPBALL)
3305 s = "notify_ballpickedup";
3308 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3309 pos_attacker = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
3310 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
3314 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3315 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3318 // X [did action to] Y
3321 if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_LASER)
3323 s = "notify_melee_laser";
3325 else if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_SHOTGUN)
3327 s = "notify_melee_shotgun";
3329 else if(WEP_VALID(w))
3331 self = get_weaponinfo(w);
3332 s = strcat("weapon", self.netname);
3334 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
3336 s = "notify_teamkill_red";
3338 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
3340 s = "notify_teamkill_red";
3342 else if(killnotify_deathtype[j] == DEATH_TELEFRAG)
3344 s = "notify_telefrag";
3346 else if(killnotify_deathtype[j] == DEATH_DROWN)
3350 else if(killnotify_deathtype[j] == DEATH_SLIME)
3354 else if(killnotify_deathtype[j] == DEATH_LAVA)
3358 else if(killnotify_deathtype[j] == DEATH_FALL)
3362 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
3364 s = "notify_shootingstar";
3366 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
3370 else if(killnotify_deathtype[j] == DEATH_HEADSHOT)
3372 s = "notify_headshot";
3374 else if(killnotify_deathtype[j] == RACE_SERVER_RECORD)
3376 s = "race_newrecordserver";
3378 else if(killnotify_deathtype[j] == RACE_NEW_RANK)
3380 s = "race_newrankyellow";
3382 else if(killnotify_deathtype[j] == RACE_NEW_TIME)
3386 else if(killnotify_deathtype[j] == RACE_FAIL)
3391 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3392 victim = textShortenToWidth(killnotify_victims[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3393 :hud_config_notifyprint
3394 width_attacker = stringwidth(attacker, TRUE, fontsize);
3395 pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * (0.5 * fontsize_y + i * height);
3396 pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
3397 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
3401 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3402 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3403 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3412 string seconds_tostring(float sec)
3415 minutes = floor(sec / 60);
3417 sec -= minutes * 60;
3420 s = ftos(100 + sec);
3422 return strcat(ftos(minutes), ":", substring(s, 1, 3));
3425 void HUD_Timer(void)
3427 if(!autocvar_hud_panel_timer && !autocvar__hud_configure)
3430 active_panel = HUD_PANEL_TIMER;
3431 HUD_Panel_UpdateCvars(timer);
3434 mySize = panel_size;
3436 HUD_Panel_DrawBg(1);
3437 if(panel_bg_padding)
3439 pos += '1 1 0' * panel_bg_padding;
3440 mySize -= '2 2 0' * panel_bg_padding;
3444 float timelimit, elapsedTime, timeleft, minutesLeft;
3446 timelimit = getstatf(STAT_TIMELIMIT);
3448 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
3449 timeleft = ceil(timeleft);
3451 minutesLeft = floor(timeleft / 60);
3454 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
3455 timer_color = '1 1 1'; //white
3456 else if(minutesLeft >= 1)
3457 timer_color = '1 1 0'; //yellow
3459 timer_color = '1 0 0'; //red
3461 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
3462 if (time < getstatf(STAT_GAMESTARTTIME)) {
3463 //while restart is still active, show 00:00
3464 timer = seconds_tostring(0);
3466 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
3467 timer = seconds_tostring(elapsedTime);
3470 timer = seconds_tostring(timeleft);
3473 drawfont = hud_bigfont;
3474 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3475 drawfont = hud_font;
3480 void HUD_Radar(void)
3482 if ((autocvar_hud_panel_radar == 0 || (autocvar_hud_panel_radar != 2 && !teamplay)) && !autocvar__hud_configure)
3485 active_panel = HUD_PANEL_RADAR;
3486 HUD_Panel_UpdateCvars(radar);
3489 mySize = panel_size;
3491 HUD_Panel_DrawBg(1);
3492 if(panel_bg_padding)
3494 pos += '1 1 0' * panel_bg_padding;
3495 mySize -= '2 2 0' * panel_bg_padding;
3500 float scale2d, normalsize, bigsize;
3503 teamradar_origin2d = pos + 0.5 * mySize;
3504 teamradar_size2d = mySize;
3506 if(minimapname == "")
3509 teamradar_loadcvars();
3511 switch(hud_panel_radar_zoommode)
3515 f = current_zoomfraction;
3518 f = 1 - current_zoomfraction;
3528 switch(hud_panel_radar_rotation)
3531 teamradar_angle = view_angles_y - 90;
3534 teamradar_angle = 90 * hud_panel_radar_rotation;
3538 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
3539 teamradar_size2d = mySize;
3541 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
3543 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
3544 if(hud_panel_radar_rotation == 0)
3546 // max-min distance must fit the radar in any rotation
3547 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
3551 vector c0, c1, c2, c3, span;
3552 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
3553 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
3554 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
3555 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
3557 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
3558 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
3560 // max-min distance must fit the radar in x=x, y=y
3562 teamradar_size2d_x * scale2d / (1.05 * span_x),
3563 teamradar_size2d_y * scale2d / (1.05 * span_y)
3567 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
3568 if(bigsize > normalsize)
3569 normalsize = bigsize;
3573 + (1 - f) * normalsize;
3574 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
3575 f * (mi_min + mi_max) * 0.5
3576 + (1 - f) * view_origin);
3585 draw_teamradar_background(hud_panel_radar_foreground_alpha);
3587 for(tm = world; (tm = find(tm, classname, "radarlink")); )
3588 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
3589 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
3590 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
3591 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
3593 color2 = GetPlayerColor(tm.sv_entnum);
3594 //if(color == COLOR_SPECTATOR || color == color2)
3595 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
3597 draw_teamradar_player(view_origin, view_angles, '1 1 1');
3599 drawresetcliparea();
3604 void HUD_UpdatePlayerTeams();
3605 void HUD_Score(void)
3607 if(!autocvar__hud_configure && !autocvar_hud_panel_score)
3610 active_panel = HUD_PANEL_SCORE;
3611 HUD_Panel_UpdateCvars(score);
3614 mySize = panel_size;
3616 HUD_Panel_DrawBg(1);
3617 if(panel_bg_padding)
3619 pos += '1 1 0' * panel_bg_padding;
3620 mySize -= '2 2 0' * panel_bg_padding;
3623 float score, distribution;
3625 vector distribution_color;
3627 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
3629 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
3630 string timer, distrtimer;
3632 pl = players.sort_next;
3635 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
3636 if(pl.scores[ps_primary] == 0)
3639 score = me.(scores[ps_primary]);
3640 timer = TIME_ENCODED_TOSTRING(score);
3642 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
3643 // distribution display
3644 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3646 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
3648 if (distribution <= 0) {
3649 distribution_color = '0 1 0';
3653 distribution_color = '1 0 0';
3656 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);
3658 // race record display
3659 if (distribution <= 0)
3660 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3661 drawfont = hud_bigfont;
3662 drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3663 drawfont = hud_font;
3664 } else if (!teamplay) { // non-teamgames
3665 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
3667 #define SCOREPANEL_MAX_ENTRIES 6
3668 #define SCOREPANEL_ASPECTRATIO 2
3669 float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
3670 float height = mySize_y/entries;
3671 vector fontsize = '0.9 0.9 0' * height;
3672 pos_y += height * (1 - 0.9) / 2;
3677 float name_size = mySize_x*0.75;
3678 float i, me_printed;
3680 if (autocvar__hud_configure)
3682 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
3683 for (i=0; i<entries; ++i)
3685 //simulate my score is lower than all displayed players,
3686 //so that I don't appear at all showing pure rankings.
3687 //This is to better show the difference between the 2 ranking views
3688 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
3691 drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, 0.3 * panel_fg_alpha, DRAWFLAG_NORMAL);
3692 s = GetPlayerName(pl.sv_entnum);
3697 s = strcat("Player", ftos(i+1));
3701 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
3702 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
3703 drawstring(pos + eX * mySize_x*0.79, ftos(score), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3709 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
3710 HUD_UpdatePlayerTeams();
3712 for (pl = players.sort_next, i=0; pl && i<entries; pl = pl.sort_next, ++i)
3714 if (pl.team == COLOR_SPECTATOR)
3717 if (i == entries-1 && !me_printed && pl != me)
3718 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
3720 for (pl = me.sort_next; pl; pl = pl.sort_next)
3721 if (pl.team != COLOR_SPECTATOR)
3725 rgb = '1 1 0'; //not last but not among the leading players: yellow
3727 rgb = '1 0 0'; //last: red
3734 rgb = '0 1 0'; //first: green
3736 drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, 0.3 * panel_fg_alpha, DRAWFLAG_NORMAL);
3738 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
3739 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
3740 drawstring(pos + eX * mySize_x*0.79, ftos(pl.(scores[ps_primary])), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3745 // me vector := [team/connected frags id]
3746 pl = players.sort_next;
3750 if(autocvar__hud_configure)
3753 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3757 score = me.(scores[ps_primary]);
3758 if(autocvar__hud_configure)
3761 if(distribution >= 5)
3762 distribution_color = eY;
3763 else if(distribution >= 0)
3764 distribution_color = '1 1 1';
3765 else if(distribution >= -5)
3766 distribution_color = '1 1 0';
3768 distribution_color = eX;
3770 string distribution_str;
3771 distribution_str = ftos(distribution);
3772 if (distribution >= 0)
3774 if (distribution > 0)
3775 distribution_str = strcat("+", distribution_str);
3776 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3778 drawfont = hud_bigfont;
3779 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3780 drawfont = hud_font;
3781 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);
3782 } else { // teamgames
3783 float max_fragcount;
3784 max_fragcount = -99;
3786 float scores_count, row, column, rows, columns;
3788 vector score_pos, score_size; //for scores other than myteam
3789 if (spectatee_status == -1)
3791 if (autocvar__hud_configure)
3793 else for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3794 if(tm.team == COLOR_SPECTATOR)
3798 rows = mySize_y/mySize_x;
3799 rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
3800 // ^^^ ammo item aspect goes here
3802 columns = ceil(scores_count/rows);
3804 score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
3807 if(score_size_x/score_size_y > 3)
3809 newSize = 3 * score_size_y;
3810 offset_x = score_size_x - newSize;
3811 pos_x += offset_x/2;
3812 score_size_x = newSize;
3816 newSize = 1/3 * score_size_x;
3817 offset_y = score_size_y - newSize;
3818 pos_y += offset_y/2;
3819 score_size_y = newSize;
3823 score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
3824 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3825 if(tm.team == COLOR_SPECTATOR)
3827 score = tm.(teamscores[ts_primary]);
3828 if(autocvar__hud_configure)
3831 if (score > max_fragcount)
3832 max_fragcount = score;
3834 if (spectatee_status == -1)
3836 score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
3837 if (max_fragcount == score)
3838 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3839 drawfont = hud_bigfont;
3840 drawstring_aspect(score_pos, ftos(score), score_size, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3841 drawfont = hud_font;
3849 else if(tm.team == myteam) {
3850 if (max_fragcount == score)
3851 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3852 drawfont = hud_bigfont;
3853 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3854 drawfont = hud_font;
3856 if (max_fragcount == score)
3857 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);
3858 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);
3867 void HUD_RaceTimer (void) {
3868 if(!autocvar__hud_configure)
3870 if(!autocvar_hud_panel_racetimer) return;
3871 if(!(gametype == GAME_RACE || gametype == GAME_CTS)) return;
3872 if(spectatee_status == -1) return;
3875 active_panel = HUD_PANEL_RACETIMER;
3876 HUD_Panel_UpdateCvars(racetimer);
3879 mySize = panel_size;
3881 HUD_Panel_DrawBg(1);
3882 if(panel_bg_padding)
3884 pos += '1 1 0' * panel_bg_padding;
3885 mySize -= '2 2 0' * panel_bg_padding;
3888 // always force 4:1 aspect
3890 if(mySize_x/mySize_y > 4)
3892 newSize_x = 4 * mySize_y;
3893 newSize_y = mySize_y;
3895 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3899 newSize_y = 1/4 * mySize_x;
3900 newSize_x = mySize_x;
3902 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3906 drawfont = hud_bigfont;
3908 string s, forcetime;
3910 if(autocvar__hud_configure)
3913 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);
3914 s = "^1Intermediate 1 (+15.42)";
3915 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);
3916 s = strcat("^1PENALTY: ", ftos_decimals(20 * 0.1, 1), " (missing a checkpoint)");
3917 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);
3919 else if(race_checkpointtime)
3921 a = bound(0, 2 - (time - race_checkpointtime), 1);
3924 if(a > 0) // just hit a checkpoint?
3926 if(race_checkpoint != 254)
3928 if(race_time && race_previousbesttime)
3929 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
3931 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
3933 forcetime = TIME_ENCODED_TOSTRING(race_time);
3938 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
3940 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
3941 if(a > 0) // next one?
3943 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
3948 if(s != "" && a > 0)
3950 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);
3953 if(race_penaltytime)
3955 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
3958 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
3959 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);
3965 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
3966 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);
3971 if(race_laptime && race_checkpoint != 255)
3973 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
3974 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);
3979 if(race_mycheckpointtime)
3981 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
3982 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
3983 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);
3985 if(race_othercheckpointtime && race_othercheckpointenemy != "")
3987 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
3988 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
3989 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);
3992 if(race_penaltytime && !race_penaltyaccumulator)
3994 t = race_penaltytime * 0.1 + race_penaltyeventtime;
3995 a = bound(0, (1 + t - time), 1);
3999 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
4001 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
4002 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);
4007 drawfont = hud_font;
4012 float vote_yescount;
4015 float vote_highlighted; // currently selected vote
4017 float vote_active; // is there an active vote?
4018 float vote_prev; // previous state of vote_active to check for a change
4020 float vote_change; // "time" when vote_active changed
4022 void HUD_VoteWindow(void)
4024 uid2name_dialog = 0;
4025 if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
4028 vote_called_vote = strzone(strcat("^2Name ^7instead of \"^1Unregistered player\"", " ^7in stats"));
4029 uid2name_dialog = 1;
4032 if(!autocvar_hud_panel_vote && !autocvar__hud_configure)
4035 if(!autocvar__hud_configure)
4037 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
4038 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
4040 if(panel_bg_alpha_str == "") {
4041 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
4043 panel_bg_alpha = stof(panel_bg_alpha_str);
4048 if(vote_active != vote_prev) {
4050 vote_prev = vote_active;
4053 if(vote_active || autocvar__hud_configure)
4054 vote_alpha = bound(0, (time - vote_change) * 2, 1);
4056 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
4058 if(autocvar__hud_configure)
4068 active_panel = HUD_PANEL_VOTE;
4069 HUD_Panel_UpdateCvars(vote);
4073 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
4074 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
4077 // these must be below above block
4080 mySize = panel_size;
4082 a = vote_alpha * bound(autocvar_hud_panel_vote_alreadyvoted_alpha, 1 - vote_highlighted, 1);
4083 HUD_Panel_DrawBg(a);
4084 a = panel_fg_alpha * a;
4086 if(panel_bg_padding)
4088 pos += '1 1 0' * panel_bg_padding;
4089 mySize -= '2 2 0' * panel_bg_padding;
4092 // always force 3:1 aspect
4094 if(mySize_x/mySize_y > 3)
4096 newSize_x = 3 * mySize_y;
4097 newSize_y = mySize_y;
4099 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4103 newSize_y = 1/3 * mySize_x;
4104 newSize_x = mySize_x;
4106 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4110 s = "A vote has been called for:";
4112 s = "Allow servers to store and display your name?";
4113 drawstring_aspect(pos, s, eX * mySize_x + eY * (2/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4114 s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (1/8), stringwidth_colors);
4115 if(autocvar__hud_configure)
4116 s = "^1Configure the HUD";
4117 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a, DRAWFLAG_NORMAL);
4119 // print the yes/no counts
4120 s = strcat("Yes (", getcommandkey("vyes", "vyes"), "): ", ftos(vote_yescount));
4121 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);
4122 s = strcat("No (", getcommandkey("vno", "vno"), "): ", ftos(vote_nocount));
4123 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);
4125 // draw the progress bar backgrounds
4126 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_back", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4128 // draw the highlights
4129 if(vote_highlighted == 1) {
4130 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
4131 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4133 else if(vote_highlighted == 2) {
4134 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
4135 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4138 // draw the progress bars
4139 if(vote_yescount && vote_needed)
4141 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
4142 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4145 if(vote_nocount && vote_needed)
4147 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
4148 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4151 drawresetcliparea();
4154 vote_highlighted = 0;
4158 // Mod icons panel (#10)
4161 float mod_active; // is there any active mod icon?
4163 // Clan Arena HUD modicons
4164 void HUD_Mod_CA(vector pos, vector mySize)
4166 mod_active = 1; // CA should never hide the mod icons panel
4167 float redalive, bluealive;
4168 redalive = getstati(STAT_REDALIVE);
4169 bluealive = getstati(STAT_BLUEALIVE);
4171 drawfont = hud_bigfont;
4172 vector redpos, bluepos;
4173 if(mySize_x > mySize_y)
4176 bluepos = pos + eY * 0.5 * mySize_y;
4177 drawpic_aspect_skin(redpos, "player_red.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4178 drawstring_aspect(redpos + eX * 0.5 * mySize_x, ftos(redalive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4179 drawpic_aspect_skin(bluepos, "player_blue.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4180 drawstring_aspect(bluepos + eX * 0.5 * mySize_x, ftos(bluealive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4185 bluepos = pos + eY * 0.5 * mySize_y;
4186 drawpic_aspect_skin(redpos, "player_red.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4187 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);
4188 drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4189 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);
4191 drawfont = hud_font;
4194 // CTF HUD modicon section
4195 float redflag_prevframe, blueflag_prevframe; // status during previous frame
4196 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
4197 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
4199 void HUD_Mod_CTF_Reset(void)
4201 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
4204 void HUD_Mod_CTF(vector pos, vector mySize)
4206 vector redflag_pos, blueflag_pos;
4208 float f; // every function should have that
4210 float redflag, blueflag; // current status
4211 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
4214 stat_items = getstati(STAT_ITEMS);
4215 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
4216 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
4218 if(redflag || blueflag)
4223 if(autocvar__hud_configure)
4229 // when status CHANGES, set old status into prevstatus and current status into status
4230 if (redflag != redflag_prevframe)
4232 redflag_statuschange_time = time;
4233 redflag_prevstatus = redflag_prevframe;
4234 redflag_prevframe = redflag;
4237 if (blueflag != blueflag_prevframe)
4239 blueflag_statuschange_time = time;
4240 blueflag_prevstatus = blueflag_prevframe;
4241 blueflag_prevframe = blueflag;
4244 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
4245 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
4247 float BLINK_FACTOR = 0.15;
4248 float BLINK_BASE = 0.85;
4250 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
4252 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
4254 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
4256 string red_icon, red_icon_prevstatus;
4257 float red_alpha, red_alpha_prevstatus;
4258 red_alpha = red_alpha_prevstatus = 1;
4260 case 1: red_icon = "flag_red_taken"; break;
4261 case 2: red_icon = "flag_red_lost"; break;
4262 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4264 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
4265 red_icon = "flag_red_shielded";
4267 red_icon = string_null;
4270 switch(redflag_prevstatus) {
4271 case 1: red_icon_prevstatus = "flag_red_taken"; break;
4272 case 2: red_icon_prevstatus = "flag_red_lost"; break;
4273 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4276 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
4277 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
4278 red_icon_prevstatus = "flag_red_shielded";
4280 red_icon_prevstatus = string_null;
4284 string blue_icon, blue_icon_prevstatus;
4285 float blue_alpha, blue_alpha_prevstatus;
4286 blue_alpha = blue_alpha_prevstatus = 1;
4288 case 1: blue_icon = "flag_blue_taken"; break;
4289 case 2: blue_icon = "flag_blue_lost"; break;
4290 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4292 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
4293 blue_icon = "flag_blue_shielded";
4295 blue_icon = string_null;
4298 switch(blueflag_prevstatus) {
4299 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
4300 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
4301 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4304 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
4305 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
4306 blue_icon_prevstatus = "flag_blue_shielded";
4308 blue_icon_prevstatus = string_null;
4312 if(mySize_x > mySize_y) {
4313 if (myteam == COLOR_TEAM1) { // always draw own flag on left
4315 blueflag_pos = pos + eX * 0.5 * mySize_x;
4318 redflag_pos = pos + eX * 0.5 * mySize_x;
4320 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
4322 if (myteam == COLOR_TEAM1) { // always draw own flag on left
4324 blueflag_pos = pos + eY * 0.5 * mySize_y;
4327 redflag_pos = pos + eY * 0.5 * mySize_y;
4329 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
4332 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
4333 if(red_icon_prevstatus && f < 1)
4334 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
4336 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
4338 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
4339 if(blue_icon_prevstatus && f < 1)
4340 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
4342 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
4345 // Keyhunt HUD modicon section
4346 float kh_runheretime;
4348 void HUD_Mod_KH_Reset(void)
4353 void HUD_Mod_KH(vector pos, vector mySize)
4355 mod_active = 1; // keyhunt should never hide the mod icons panel
4359 vector p, pa, kh_size, kh_asize;
4361 kh_keys = getstati(STAT_KH_KEYS);
4364 if(mySize_x > mySize_y)
4366 p_y = pos_y + 0.25 * mySize_y;
4367 pa = p - eY * 0.25 * mySize_y;
4369 kh_size_x = mySize_x * 0.25;
4370 kh_size_y = 0.75 * mySize_y;
4371 kh_asize_x = mySize_x * 0.25;
4372 kh_asize_y = mySize_y * 0.25;
4376 p_y = pos_y + 0.125 * mySize_y;
4377 pa = p - eY * 0.125 * mySize_y;
4379 kh_size_x = mySize_x * 0.5;
4380 kh_size_y = 0.375 * mySize_y;
4381 kh_asize_x = mySize_x * 0.5;
4382 kh_asize_y = mySize_y * 0.125;
4389 for(i = 0; i < 4; ++i)
4391 key = floor(kh_keys / pow(32, i)) & 31;
4393 if(keyteam == 30 && keycount <= 4)
4395 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
4399 // this yields 8 exactly if "RUN HERE" shows
4404 kh_runheretime = time;
4405 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
4410 for(i = 0; i < 4; ++i)
4412 key = floor(kh_keys / pow(32, i)) & 31;
4425 default: // owned or dropped
4430 a = a * panel_fg_alpha;
4431 aa = aa * panel_fg_alpha;
4437 drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4440 drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4443 drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4446 drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4451 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
4454 drawpic_aspect_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4457 drawpic_aspect_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4460 drawpic_aspect_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4463 drawpic_aspect_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4467 if(mySize_x > mySize_y)
4469 p_x += 0.25 * mySize_x;
4470 pa_x += 0.25 * mySize_x;
4476 p_y = pos_y + 0.625 * mySize_y;
4477 pa_y = pos_y + 0.5 * mySize_y;
4483 p_x += 0.5 * mySize_x;
4484 pa_x += 0.5 * mySize_x;
4490 // Keepaway HUD mod icon
4491 float kaball_prevstatus; // last remembered status
4492 float kaball_statuschange_time; // time when the status changed
4494 // we don't need to reset for keepaway since it immediately
4495 // autocorrects prevstatus as to if the player has the ball or not
4497 void HUD_Mod_Keepaway(vector pos, vector mySize)
4499 mod_active = 1; // keepaway should always show the mod HUD
4501 float BLINK_FACTOR = 0.15;
4502 float BLINK_BASE = 0.85;
4503 float BLINK_FREQ = 5;
4504 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
4506 float stat_items = getstati(STAT_ITEMS);
4507 float kaball = (stat_items/IT_KEY1) & 1;
4509 if(kaball != kaball_prevstatus)
4511 kaball_statuschange_time = time;
4512 kaball_prevstatus = kaball;
4515 // todo: Fix the sizing with the expanding image
4517 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
4518 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
4520 if(kaball_prevstatus && f < 1)
4521 drawpic_aspect_skin_expanding(pos + eY * 0.25 * mySize_y, "keepawayball_carrying", eX * mySize_x + eY * mySize_y * 0.5, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
4524 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
4528 // Nexball HUD mod icon
4529 void HUD_Mod_NexBall(vector pos, vector mySize)
4531 float stat_items, nb_pb_starttime, dt, p;
4533 stat_items = getstati(STAT_ITEMS);
4534 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
4536 if (stat_items & IT_KEY1)
4541 //Manage the progress bar if any
4542 if (nb_pb_starttime > 0)
4544 dt = mod(time - nb_pb_starttime, nb_pb_period);
4545 // one period of positive triangle
4546 p = 2 * dt / nb_pb_period;
4551 HUD_Panel_GetProgressBarColor(nexball);
4552 if(mySize_x > mySize_y)
4553 HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", p, 0, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4555 HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", p, 1, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4558 if (stat_items & IT_KEY1)
4559 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4562 // Race/CTS HUD mod icons
4563 float crecordtime_prev; // last remembered crecordtime
4564 float crecordtime_change_time; // time when crecordtime last changed
4565 float srecordtime_prev; // last remembered srecordtime
4566 float srecordtime_change_time; // time when srecordtime last changed
4568 float race_status_time;
4569 float race_status_prev;
4570 string race_status_name_prev;
4571 void HUD_Mod_Race(vector pos, vector mySize)
4573 mod_active = 1; // race should never hide the mod icons panel
4575 me = playerslots[player_localentnum - 1];
4577 float f; // yet another function has this
4578 score = me.(scores[ps_primary]);
4580 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
4581 return; // no records in the actual race
4583 drawfont = hud_bigfont;
4585 // clientside personal record
4587 if(gametype == GAME_CTS)
4591 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
4593 if(score && (score < t || !t)) {
4594 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
4595 if(autocvar_cl_autodemo_delete_keeprecords)
4597 f = autocvar_cl_autodemo_delete;
4599 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
4603 if(t != crecordtime_prev) {
4604 crecordtime_prev = t;
4605 crecordtime_change_time = time;
4608 vector textPos, medalPos;
4610 if(mySize_x > mySize_y) {
4611 // text on left side
4612 squareSize = min(mySize_y, mySize_x/2);
4613 textPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eY * 0.5 * (mySize_y - squareSize);
4614 medalPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eX * 0.5 * mySize_x + eY * 0.5 * (mySize_y - squareSize);
4617 squareSize = min(mySize_x, mySize_y/2);
4618 textPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eX * 0.5 * (mySize_x - squareSize);
4619 medalPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eY * 0.5 * mySize_y + eX * 0.5 * (mySize_x - squareSize);
4622 f = time - crecordtime_change_time;
4625 drawstring_aspect(textPos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4626 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);
4628 drawstring_aspect(textPos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4629 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);
4630 drawstring_aspect_expanding(pos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
4631 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);
4635 t = race_server_record;
4636 if(t != srecordtime_prev) {
4637 srecordtime_prev = t;
4638 srecordtime_change_time = time;
4640 f = time - srecordtime_change_time;
4643 drawstring_aspect(textPos + eY * 0.5 * squareSize, "Server best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4644 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);
4646 drawstring_aspect(textPos + eY * 0.5 * squareSize, "Server best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4647 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);
4648 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);
4649 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);
4652 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
4653 race_status_time = time + 5;
4654 race_status_prev = race_status;
4655 if (race_status_name_prev)
4656 strunzone(race_status_name_prev);
4657 race_status_name_prev = strzone(race_status_name);
4662 a = bound(0, race_status_time - time, 1);
4665 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
4669 rank = race_CheckName(race_status_name);
4671 rankname = race_PlaceName(rank);
4674 namepos = medalPos + '0 0.8 0' * squareSize;
4676 rankpos = medalPos + '0 0.15 0' * squareSize;
4678 if(race_status == 0)
4679 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4680 else if(race_status == 1) {
4681 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);
4682 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4683 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4684 } else if(race_status == 2) {
4685 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
4686 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);
4688 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);
4689 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4690 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4691 } else if(race_status == 3) {
4692 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);
4693 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4694 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4697 if (race_status_time - time <= 0) {
4698 race_status_prev = -1;
4700 if(race_status_name)
4701 strunzone(race_status_name);
4702 race_status_name = string_null;
4703 if(race_status_name_prev)
4704 strunzone(race_status_name_prev);
4705 race_status_name_prev = string_null;
4707 drawfont = hud_font;
4710 float mod_prev; // previous state of mod_active to check for a change
4712 float mod_change; // "time" when mod_active changed
4714 void HUD_ModIcons(void)
4716 if(!autocvar_hud_panel_modicons && !autocvar__hud_configure)
4719 if (gametype != GAME_KEYHUNT && gametype != GAME_CTF && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && gametype != GAME_CA && gametype != GAME_FREEZETAG && gametype != GAME_KEEPAWAY && !autocvar__hud_configure)
4722 active_panel = HUD_PANEL_MODICONS;
4723 HUD_Panel_UpdateCvars(modicons);
4726 mySize = panel_size;
4728 if(mod_active != mod_prev) {
4730 mod_prev = mod_active;
4733 if(mod_active || autocvar__hud_configure)
4734 mod_alpha = bound(0, (time - mod_change) * 2, 1);
4736 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
4739 HUD_Panel_DrawBg(mod_alpha);
4741 if(panel_bg_padding)
4743 pos += '1 1 0' * panel_bg_padding;
4744 mySize -= '2 2 0' * panel_bg_padding;
4747 // these MUST be ran in order to update mod_active
4748 if(gametype == GAME_KEYHUNT)
4749 HUD_Mod_KH(pos, mySize);
4750 else if(gametype == GAME_CTF || autocvar__hud_configure)
4751 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
4752 else if(gametype == GAME_NEXBALL)
4753 HUD_Mod_NexBall(pos, mySize);
4754 else if(gametype == GAME_CTS || gametype == GAME_RACE)
4755 HUD_Mod_Race(pos, mySize);
4756 else if(gametype == GAME_CA || gametype == GAME_FREEZETAG)
4757 HUD_Mod_CA(pos, mySize);
4758 else if(gametype == GAME_KEEPAWAY)
4759 HUD_Mod_Keepaway(pos, mySize);
4762 // Draw pressed keys (#11)
4764 void HUD_DrawPressedKeys(void)
4766 if(!autocvar_hud_panel_pressedkeys && !autocvar__hud_configure)
4769 if(!(spectatee_status > 0 || autocvar_hud_panel_pressedkeys >= 2 || autocvar__hud_configure))
4772 active_panel = HUD_PANEL_PRESSEDKEYS;
4773 HUD_Panel_UpdateCvars(pressedkeys);
4776 mySize = panel_size;
4778 HUD_Panel_DrawBg(1);
4779 if(panel_bg_padding)
4781 pos += '1 1 0' * panel_bg_padding;
4782 mySize -= '2 2 0' * panel_bg_padding;
4785 // force custom aspect
4786 float aspect = autocvar_hud_panel_pressedkeys_aspect;
4790 if(mySize_x/mySize_y > aspect)
4792 newSize_x = aspect * mySize_y;
4793 newSize_y = mySize_y;
4795 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4799 newSize_y = 1/aspect * mySize_x;
4800 newSize_x = mySize_x;
4802 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4808 keysize = eX * mySize_x * (1/3) + eY * mySize_y * 0.5;
4810 pressedkeys = getstatf(STAT_PRESSED_KEYS);
4812 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4813 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);
4814 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);
4816 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4817 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);
4818 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);
4821 // Handle chat as a panel (#12)
4825 if(!autocvar_hud_panel_chat && !autocvar__hud_configure)
4827 cvar_set("con_chatrect", "0");
4831 active_panel = HUD_PANEL_CHAT;
4832 HUD_Panel_UpdateCvars(chat);
4834 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
4836 panel_pos_y = panel_bg_border;
4837 panel_size_y = vid_conheight - panel_bg_border * 2;
4838 if(panel_bg == "0") // force a border when maximized
4840 if(precache_pic(panel_bg) == "") {
4841 panel_bg = strcat(hud_skin_path, "/border_default");
4842 if(precache_pic(panel_bg) == "") {
4843 panel_bg = "gfx/hud/default/border_default";
4847 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an alpha of at least 0.75
4852 mySize = panel_size;
4854 HUD_Panel_DrawBg(1);
4856 if(panel_bg_padding)
4858 pos += '1 1 0' * panel_bg_padding;
4859 mySize -= '2 2 0' * panel_bg_padding;
4862 cvar_set("con_chatrect", "1");
4864 cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
4865 cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
4867 cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
4868 cvar_set("con_chat", ftos(floor(mySize_y/autocvar_con_chatsize - 0.5)));
4870 if(autocvar__hud_configure)
4873 chatsize = autocvar_con_chatsize;
4874 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
4876 for(i = 0; i < autocvar_con_chat; ++i)
4878 if(i == autocvar_con_chat - 1)
4881 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
4882 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);
4887 // Engine info panel (#13)
4894 float frametimeavg1; // 1 frame ago
4895 float frametimeavg2; // 2 frames ago
4896 void HUD_EngineInfo(void)
4898 if(!autocvar_hud_panel_engineinfo && !autocvar__hud_configure)
4901 active_panel = HUD_PANEL_ENGINEINFO;
4902 HUD_Panel_UpdateCvars(engineinfo);
4905 mySize = panel_size;
4907 HUD_Panel_DrawBg(1);
4908 if(panel_bg_padding)
4910 pos += '1 1 0' * panel_bg_padding;
4911 mySize -= '2 2 0' * panel_bg_padding;
4914 float currentTime = gettime(GETTIME_REALTIME);
4915 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
4917 float currentframetime = currentTime - prevfps_time;
4918 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
4919 frametimeavg2 = frametimeavg1;
4920 frametimeavg1 = frametimeavg;
4923 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
4924 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.
4926 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
4927 prevfps = (1/currentframetime);
4928 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"
4930 prevfps_time = currentTime;
4935 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
4937 prevfps = framecounter/(currentTime - prevfps_time);
4939 prevfps_time = currentTime;
4944 color = HUD_Get_Num_Color (prevfps, 100);
4945 drawfont = hud_bigfont;
4946 drawstring_aspect(pos, strcat("FPS: ", ftos_decimals(prevfps, autocvar_hud_panel_engineinfo_framecounter_decimals)), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
4947 drawfont = hud_font;
4950 // Info messages panel (#14)
4952 #define drawInfoMessage(s)\
4953 if(autocvar_hud_panel_infomessages_flip)\
4954 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);\
4955 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);\
4957 void HUD_InfoMessages(void)
4959 if(!autocvar_hud_panel_infomessages && !autocvar__hud_configure)
4962 active_panel = HUD_PANEL_INFOMESSAGES;
4963 HUD_Panel_UpdateCvars(infomessages);
4966 mySize = panel_size;
4968 HUD_Panel_DrawBg(1);
4969 if(panel_bg_padding)
4971 pos += '1 1 0' * panel_bg_padding;
4972 mySize -= '2 2 0' * panel_bg_padding;
4975 // always force 5:1 aspect
4977 if(mySize_x/mySize_y > 5)
4979 newSize_x = 5 * mySize_y;
4980 newSize_y = mySize_y;
4982 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4986 newSize_y = 1/5 * mySize_x;
4987 newSize_x = mySize_x;
4989 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4998 fontsize = '0.20 0.20 0' * mySize_y;
5001 if(spectatee_status != 0)
5007 if(!autocvar__hud_configure)
5009 if(spectatee_status && !intermission)
5011 if(spectatee_status == -1)
5014 s = strcat("^1Spectating: ^7", GetPlayerName(spectatee_status - 1));
5017 if(spectatee_status == -1)
5018 s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 to spectate");
5020 s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 for another player");
5023 if(spectatee_status == -1)
5024 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
5026 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+fire2"), "^1 to observe");
5029 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
5032 if(gametype == GAME_ARENA)
5033 s = "^1Wait for your turn to join";
5034 else if(gametype == GAME_LMS)
5037 sk = playerslots[player_localentnum - 1];
5038 if(sk.(scores[ps_primary]) >= 666)
5039 s = "^1Match has already begun";
5040 else if(sk.(scores[ps_primary]) > 0)
5041 s = "^1You have no more lives left";
5043 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
5046 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
5049 //show restart countdown:
5050 if (time < getstatf(STAT_GAMESTARTTIME)) {
5052 //we need to ceil, otherwise the countdown would be off by .5 when using round()
5053 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
5054 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
5055 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
5059 if(warmup_stage && !intermission)
5061 s = "^2Currently in ^1warmup^2 stage!";
5066 if(mod(time, 1) >= 0.5)
5071 if(ready_waiting && !intermission && !spectatee_status)
5073 if(ready_waiting_for_me)
5076 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
5078 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
5083 s = strcat("^2Waiting for others to ready up to end warmup...");
5085 s = strcat("^2Waiting for others to ready up...");
5089 else if(warmup_stage && !intermission && !spectatee_status)
5091 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
5095 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
5097 float ts_min, ts_max;
5098 tm = teams.sort_next;
5101 for(; tm.sort_next; tm = tm.sort_next)
5103 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
5105 if(!ts_min) ts_min = tm.team_size;
5106 else ts_min = min(ts_min, tm.team_size);
5107 if(!ts_max) ts_max = tm.team_size;
5108 else ts_max = max(ts_max, tm.team_size);
5110 if ((ts_max - ts_min) > 1)
5112 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
5113 tm = GetTeam(myteam, false);
5115 if (tm.team != COLOR_SPECTATOR)
5116 if (tm.team_size == ts_max)
5117 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
5125 s = "^7Press ^3ESC ^7to show HUD options.";
5127 s = "^3Doubleclick ^7a panel for panel-specific options.";
5129 s = "^3CTRL ^7to disable collision testing, ^3SHIFT ^7and";
5131 s = "^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.";
5142 void HUD_ShowSpeed(void)
5145 float pos, conversion_factor;
5146 string speed, zspeed, unit;
5148 switch(autocvar_cl_showspeed_unit)
5153 conversion_factor = 1.0;
5157 conversion_factor = 1.0;
5161 conversion_factor = 0.0254;
5165 conversion_factor = 0.0254 * 3.6;
5169 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
5173 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
5177 speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
5179 numsize_x = numsize_y = autocvar_cl_showspeed_size;
5180 pos = (vid_conheight - numsize_y) * autocvar_cl_showspeed_position;
5182 drawfont = hud_bigfont;
5183 drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
5185 if (autocvar_cl_showspeed_z == 1) {
5186 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
5187 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
5190 drawfont = hud_font;
5193 vector acc_prevspeed;
5197 void HUD_ShowAcceleration(void)
5199 float acceleration, sz, scale, alpha, f;
5200 vector pos, mySize, rgb;
5202 f = time - acc_prevtime;
5203 if(autocvar_cl_showacceleration_z)
5204 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
5206 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
5207 acc_prevspeed = pmove_vel;
5208 acc_prevtime = time;
5210 f = bound(0, f * 10, 1);
5211 acc_avg = acc_avg * (1 - f) + acceleration * f;
5212 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
5213 if (acceleration == 0)
5216 sz = autocvar_cl_showacceleration_size;
5217 scale = autocvar_cl_showacceleration_scale;
5218 alpha = autocvar_cl_showacceleration_alpha;
5219 if (autocvar_cl_showacceleration_color_custom)
5220 rgb = stov(autocvar_cl_showacceleration_color);
5222 if (acceleration < 0)
5223 rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
5225 rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
5228 mySize_x = vid_conwidth/2;
5230 pos_y = autocvar_cl_showacceleration_position * vid_conheight - sz/2;
5231 if (acceleration > 0)
5234 HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", acceleration * scale, 0, 0, rgb, alpha * autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
5239 HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", -acceleration * scale, 0, 1, rgb, alpha * autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
5243 void HUD_Reset (void)
5245 // reset gametype specific icons
5246 if(gametype == GAME_KEYHUNT)
5248 else if(gametype == GAME_CTF)
5249 HUD_Mod_CTF_Reset();
5252 #define HUD_DrawPanel(id)\
5254 case (HUD_PANEL_RADAR):\
5255 HUD_Radar(); break;\
5256 case (HUD_PANEL_WEAPONS):\
5257 HUD_Weapons(); break;\
5258 case (HUD_PANEL_AMMO):\
5260 case (HUD_PANEL_POWERUPS):\
5261 HUD_Powerups(); break;\
5262 case (HUD_PANEL_HEALTHARMOR):\
5263 HUD_HealthArmor(); break;\
5264 case (HUD_PANEL_NOTIFY):\
5265 HUD_Notify(); break;\
5266 case (HUD_PANEL_TIMER):\
5267 HUD_Timer(); break;\
5268 case (HUD_PANEL_SCORE):\
5269 HUD_Score(); break;\
5270 case (HUD_PANEL_RACETIMER):\
5271 HUD_RaceTimer(); break;\
5272 case (HUD_PANEL_VOTE):\
5273 HUD_VoteWindow(); break;\
5274 case (HUD_PANEL_MODICONS):\
5275 HUD_ModIcons(); break;\
5276 case (HUD_PANEL_PRESSEDKEYS):\
5277 HUD_DrawPressedKeys(); break;\
5278 case (HUD_PANEL_CHAT):\
5280 case (HUD_PANEL_ENGINEINFO):\
5281 HUD_EngineInfo(); break;\
5282 case (HUD_PANEL_INFOMESSAGES):\
5283 HUD_InfoMessages(); break;\
5284 } ENDS_WITH_CURLY_BRACE
5286 void HUD_Main (void)
5289 // global hud alpha fade
5290 if(menu_enabled == 1)
5293 hud_fade_alpha = (1 - autocvar__menu_alpha);
5295 if(scoreboard_fade_alpha)
5296 hud_fade_alpha = (1 - scoreboard_fade_alpha);
5298 if(intermission == 2) // no hud during mapvote
5300 else if(autocvar__menu_alpha == 0 && scoreboard_fade_alpha == 0)
5303 if(!autocvar__hud_configure && !hud_fade_alpha)
5307 if (hud_skin_path != autocvar_hud_skin)
5310 strunzone(hud_skin_path);
5311 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
5314 // HUD configure visible grid
5315 float hud_configure_grid_alpha;
5316 if(autocvar__hud_configure && cvar("hud_configure_grid") && (hud_configure_grid_alpha = cvar("hud_configure_grid_alpha")))
5318 hud_configure_gridSize_x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
5319 hud_configure_gridSize_y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
5320 hud_configure_realGridSize_x = hud_configure_gridSize_x * vid_conwidth;
5321 hud_configure_realGridSize_y = hud_configure_gridSize_y * vid_conheight;
5323 for(i = 0; i < 1/hud_configure_gridSize_x; ++i)
5324 drawfill(eX * i * hud_configure_realGridSize_x, eX + eY * vid_conheight, '0.5 0.5 0.5', hud_configure_grid_alpha, DRAWFLAG_NORMAL);
5326 for(i = 0; i < 1/hud_configure_gridSize_y; ++i)
5327 drawfill(eY * i * hud_configure_realGridSize_y, eY + eX * vid_conwidth, '0.5 0.5 0.5', hud_configure_grid_alpha, DRAWFLAG_NORMAL);
5331 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
5335 float hud_dock_color_team = autocvar_hud_dock_color_team;
5336 if((teamplay) && hud_dock_color_team) {
5337 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5338 color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
5340 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
5341 color = '1 0 0' * hud_dock_color_team;
5345 string hud_dock_color = autocvar_hud_dock_color;
5346 if(hud_dock_color == "shirt") {
5347 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5348 color = colormapPaletteColor(floor(f / 16), 0);
5350 else if(hud_dock_color == "pants") {
5351 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5352 color = colormapPaletteColor(mod(f, 16), 1);
5355 color = stov(hud_dock_color);
5359 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
5360 if(precache_pic(pic) == "") {
5361 pic = strcat(hud_skin_path, "/dock_medium");
5362 if(precache_pic(pic) == "") {
5363 pic = "gfx/hud/default/dock_medium";
5366 drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, autocvar_hud_dock_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
5369 // cache the panel order into the panel_order array
5370 if(autocvar__hud_panelorder != hud_panelorder_prev) {
5371 for(i = 0; i < HUD_PANEL_NUM; ++i)
5372 panel_order[i] = -1;
5374 float p_num, warning;
5375 float argc = tokenize_console(autocvar__hud_panelorder);
5376 if (argc > HUD_PANEL_NUM)
5378 //first detect wrong/missing panel numbers
5379 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5380 p_num = stof(argv(i));
5381 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
5382 if (panel_order[p_num] == -1) //found for the first time?
5383 s = strcat(s, ftos(p_num), " ");
5384 panel_order[p_num] = 1; //mark as found
5389 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5390 if (panel_order[i] == -1) {
5392 s = strcat(s, ftos(i), " "); //add missing panel number
5396 print("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
5398 cvar_set("_hud_panelorder", s);
5399 if(hud_panelorder_prev)
5400 strunzone(hud_panelorder_prev);
5401 hud_panelorder_prev = strzone(s);
5403 //now properly set panel_order
5404 tokenize_console(s);
5405 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5406 panel_order[i] = stof(argv(i));
5409 // draw panels in order specified by panel_order array
5410 for(i = HUD_PANEL_NUM - 1; i >= 0; --i) {
5411 if(i != HUD_PANEL_CHAT || !autocvar__con_chat_maximized) // don't draw maximized chat panel twice!
5412 HUD_DrawPanel(panel_order[i]);
5415 // draw chat panel on top if it is maximized
5416 if(autocvar__con_chat_maximized)
5417 HUD_Chat(); // HUD_DrawPanel(HUD_PANEL_CHAT);
5419 // TODO hud_'ify these
5420 if (autocvar_cl_showspeed)
5422 if (autocvar_cl_showacceleration)
5423 HUD_ShowAcceleration();
5425 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)
5426 localcmd("cmd selectteam auto; cmd join\n");
5428 if(autocvar__hud_configure && tab_panel != -1)
5430 HUD_Panel_UpdatePosSizeForId(tab_panel)
5431 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
5434 hud_configure_prev = autocvar__hud_configure;
5436 if (!autocvar__hud_configure) // hud config mode disabled, enable normal alpha stuff again