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");
536 case HUD_PANEL_PHYSICS:
537 HUD_Write_PanelCvar_q("_flip");
538 HUD_Write_PanelCvar_q("_baralign");
539 HUD_Write_PanelCvar_q("_progressbar");
544 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
546 print("^2Successfully exported to ", filename, "! (Note: It's saved in data/data/)\n");
550 print("^1Couldn't write to ", filename, "\n");
553 const float hlBorderSize = 4;
554 const string hlBorder = "gfx/hud/default/border_highlighted";
555 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
556 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
558 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
559 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);
560 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);
561 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);
562 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);
565 // draw the background/borders
566 #define HUD_Panel_DrawBg(alpha)\
568 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));\
569 if(highlightedPanel_prev == active_panel && autocvar__hud_configure)\
571 HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha) * alpha);\
572 } ENDS_WITH_CURLY_BRACE
574 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
575 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float lenght_ratio, float vertical, float right_align, vector theColor, float theAlpha, float drawflag)
577 if(lenght_ratio <= 0 || !theAlpha)
583 vector width, height;
585 pic = strcat(hud_skin_path, "/", pic, "_vertical");
586 if(precache_pic(pic) == "") {
587 pic = "gfx/hud/default/statusbar_vertical";
591 theOrigin_y += (1 - lenght_ratio) * theSize_y;
592 theSize_y *= lenght_ratio;
595 width = eX * theSize_x;
596 height = eY * theSize_y;
597 if(theSize_y <= theSize_x * 2)
599 // button not high enough
600 // draw just upper and lower part then
601 square = eY * theSize_y * 0.5;
602 bH = eY * (0.25 * theSize_y / (theSize_x * 2));
603 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
604 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
608 square = eY * theSize_x;
609 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
610 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
611 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
614 pic = strcat(hud_skin_path, "/", pic);
615 if(precache_pic(pic) == "") {
616 pic = "gfx/hud/default/statusbar";
620 theOrigin_x += (1 - lenght_ratio) * theSize_x;
621 theSize_x *= lenght_ratio;
624 width = eX * theSize_x;
625 height = eY * theSize_y;
626 if(theSize_x <= theSize_y * 2)
628 // button not wide enough
629 // draw just left and right part then
630 square = eX * theSize_x * 0.5;
631 bW = eX * (0.25 * theSize_x / (theSize_y * 2));
632 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
633 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
637 square = eX * theSize_y;
638 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
639 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
640 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
645 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
651 pic = strcat(hud_skin_path, "/num_leading");
652 if(precache_pic(pic) == "") {
653 pic = "gfx/hud/default/num_leading";
656 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
657 if(mySize_x/mySize_y > 2)
658 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);
659 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);
662 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
663 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
672 myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
673 targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
675 for (i = 0; i < HUD_PANEL_NUM; ++i) {
676 if(i == highlightedPanel || !panel_enabled)
679 HUD_Panel_UpdatePosSizeForId(i);
681 panel_pos -= '1 1 0' * panel_bg_border;
682 panel_size += '2 2 0' * panel_bg_border;
684 if(myPos_y + mySize_y < panel_pos_y)
686 if(myPos_y > panel_pos_y + panel_size_y)
689 if(myPos_x + mySize_x < panel_pos_x)
691 if(myPos_x > panel_pos_x + panel_size_x)
694 // OK, there IS a collision.
696 myCenter_x = myPos_x + 0.5 * mySize_x;
697 myCenter_y = myPos_y + 0.5 * mySize_y;
699 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
700 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
702 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
704 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
705 myTarget_x = panel_pos_x - mySize_x;
706 else // push it upwards
707 myTarget_y = panel_pos_y - mySize_y;
709 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
711 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
712 myTarget_x = panel_pos_x + panel_size_x;
713 else // push it upwards
714 myTarget_y = panel_pos_y - mySize_y;
716 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
718 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
719 myTarget_x = panel_pos_x - mySize_x;
720 else // push it downwards
721 myTarget_y = panel_pos_y + panel_size_y;
723 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
725 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
726 myTarget_x = panel_pos_x + panel_size_x;
727 else // push it downwards
728 myTarget_y = panel_pos_y + panel_size_y;
730 //if(cvar("hud_configure_checkcollisions_debug"))
731 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
737 void HUD_Panel_SetPos(vector pos)
739 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
743 //if(cvar("hud_configure_checkcollisions_debug"))
744 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
746 if(cvar("hud_configure_grid"))
748 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
749 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
752 if(hud_configure_checkcollisions)
753 pos = HUD_Panel_CheckMove(pos, mySize);
755 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
756 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
759 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
761 HUD_Panel_GetName(highlightedPanel);
762 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
765 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
766 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
771 float dist_x, dist_y;
773 ratio = mySize_x/mySize_y;
775 for (i = 0; i < HUD_PANEL_NUM; ++i) {
776 if(i == highlightedPanel || !panel_enabled)
779 HUD_Panel_UpdatePosSizeForId(i);
781 panel_pos -= '1 1 0' * panel_bg_border;
782 panel_size += '2 2 0' * panel_bg_border;
784 targEndPos = panel_pos + panel_size;
786 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
787 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
790 if (resizeCorner == 1)
792 // check if this panel is on our way
793 if (resizeorigin_x <= panel_pos_x)
795 if (resizeorigin_y <= panel_pos_y)
797 if (targEndPos_x <= resizeorigin_x - mySize_x)
799 if (targEndPos_y <= resizeorigin_y - mySize_y)
802 // there is a collision:
803 // detect which side of the panel we are facing is actually limiting the resizing
804 // (which side the resize direction finds for first) and reduce the size up to there
806 // dist is the distance between resizeorigin and the "analogous" point of the panel
807 // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
808 dist_x = resizeorigin_x - targEndPos_x;
809 dist_y = resizeorigin_y - targEndPos_y;
810 if (dist_y <= 0 || dist_x / dist_y > ratio)
811 mySize_x = min(mySize_x, dist_x);
813 mySize_y = min(mySize_y, dist_y);
815 else if (resizeCorner == 2)
817 if (resizeorigin_x >= targEndPos_x)
819 if (resizeorigin_y <= panel_pos_y)
821 if (panel_pos_x >= resizeorigin_x + mySize_x)
823 if (targEndPos_y <= resizeorigin_y - mySize_y)
826 dist_x = panel_pos_x - resizeorigin_x;
827 dist_y = resizeorigin_y - targEndPos_y;
828 if (dist_y <= 0 || dist_x / dist_y > ratio)
829 mySize_x = min(mySize_x, dist_x);
831 mySize_y = min(mySize_y, dist_y);
833 else if (resizeCorner == 3)
835 if (resizeorigin_x <= panel_pos_x)
837 if (resizeorigin_y >= targEndPos_y)
839 if (targEndPos_x <= resizeorigin_x - mySize_x)
841 if (panel_pos_y >= resizeorigin_y + mySize_y)
844 dist_x = resizeorigin_x - targEndPos_x;
845 dist_y = panel_pos_y - resizeorigin_y;
846 if (dist_y <= 0 || dist_x / dist_y > ratio)
847 mySize_x = min(mySize_x, dist_x);
849 mySize_y = min(mySize_y, dist_y);
851 else if (resizeCorner == 4)
853 if (resizeorigin_x >= targEndPos_x)
855 if (resizeorigin_y >= targEndPos_y)
857 if (panel_pos_x >= resizeorigin_x + mySize_x)
859 if (panel_pos_y >= resizeorigin_y + mySize_y)
862 dist_x = panel_pos_x - resizeorigin_x;
863 dist_y = panel_pos_y - resizeorigin_y;
864 if (dist_y <= 0 || dist_x / dist_y > ratio)
865 mySize_x = min(mySize_x, dist_x);
867 mySize_y = min(mySize_y, dist_y);
869 //if(cvar("hud_configure_checkcollisions_debug"))
870 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
876 void HUD_Panel_SetPosSize(vector mySize)
878 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
880 resizeorigin = panel_click_resizeorigin;
883 // minimum panel size cap
884 mySize_x = max(0.025 * vid_conwidth, mySize_x);
885 mySize_y = max(0.025 * vid_conheight, mySize_y);
887 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.
889 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
890 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
893 // collision testing|
894 // -----------------+
896 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
897 if(resizeCorner == 1) {
898 myPos_x = resizeorigin_x - mySize_x;
899 myPos_y = resizeorigin_y - mySize_y;
900 } else if(resizeCorner == 2) {
901 myPos_x = resizeorigin_x;
902 myPos_y = resizeorigin_y - mySize_y;
903 } else if(resizeCorner == 3) {
904 myPos_x = resizeorigin_x - mySize_x;
905 myPos_y = resizeorigin_y;
906 } else { // resizeCorner == 4
907 myPos_x = resizeorigin_x;
908 myPos_y = resizeorigin_y;
911 // left/top screen edges
913 mySize_x = mySize_x + myPos_x;
915 mySize_y = mySize_y + myPos_y;
917 // bottom/right screen edges
918 if(myPos_x + mySize_x > vid_conwidth)
919 mySize_x = vid_conwidth - myPos_x;
920 if(myPos_y + mySize_y > vid_conheight)
921 mySize_y = vid_conheight - myPos_y;
923 //if(cvar("hud_configure_checkcollisions_debug"))
924 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
926 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
927 if(cvar("hud_configure_grid"))
929 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
930 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
933 if(hud_configure_checkcollisions)
934 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
936 // 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)
937 mySize_x = max(0.025 * vid_conwidth, mySize_x);
938 mySize_y = max(0.025 * vid_conheight, mySize_y);
940 // do another pos check, as size might have changed by now
941 if(resizeCorner == 1) {
942 myPos_x = resizeorigin_x - mySize_x;
943 myPos_y = resizeorigin_y - mySize_y;
944 } else if(resizeCorner == 2) {
945 myPos_x = resizeorigin_x;
946 myPos_y = resizeorigin_y - mySize_y;
947 } else if(resizeCorner == 3) {
948 myPos_x = resizeorigin_x - mySize_x;
949 myPos_y = resizeorigin_y;
950 } else { // resizeCorner == 4
951 myPos_x = resizeorigin_x;
952 myPos_y = resizeorigin_y;
955 //if(cvar("hud_configure_checkcollisions_debug"))
956 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
958 HUD_Panel_GetName(highlightedPanel);
960 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
961 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
963 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
964 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
968 float prevMouseClicked; // previous state
969 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
970 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
972 float pressed_key_time;
973 void HUD_Panel_Arrow_Action(float nPrimary)
975 if (highlightedPanel_prev == -1 || mouseClicked)
978 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
981 if(cvar("hud_configure_grid"))
983 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
985 if (hudShiftState & S_SHIFT)
986 step = hud_configure_realGridSize_y;
988 step = 2 * hud_configure_realGridSize_y;
992 if (hudShiftState & S_SHIFT)
993 step = hud_configure_realGridSize_x;
995 step = 2 * hud_configure_realGridSize_x;
1000 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
1001 step = vid_conheight;
1003 step = vid_conwidth;
1004 if (hudShiftState & S_SHIFT)
1005 step = (step / 256); // more precision
1007 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
1010 highlightedPanel = highlightedPanel_prev;
1012 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1014 vector prev_pos, prev_size;
1015 prev_pos = panel_pos;
1016 prev_size = panel_size;
1018 if (hudShiftState & S_ALT) // resize
1020 highlightedAction = 1;
1021 if(nPrimary == K_UPARROW)
1023 else if(nPrimary == K_RIGHTARROW)
1025 else if(nPrimary == K_LEFTARROW)
1027 else // if(nPrimary == K_DOWNARROW)
1030 // ctrl+arrow reduces the size, instead of increasing it
1031 // Note that ctrl disables collisions check too, but it's fine
1032 // since we don't collide with anything reducing the size
1033 if (hudShiftState & S_CTRL) {
1035 resizeCorner = 5 - resizeCorner;
1039 mySize = panel_size;
1040 panel_click_resizeorigin = panel_pos;
1041 if(resizeCorner == 1) {
1042 panel_click_resizeorigin += mySize;
1044 } else if(resizeCorner == 2) {
1045 panel_click_resizeorigin_y += mySize_y;
1047 } else if(resizeCorner == 3) {
1048 panel_click_resizeorigin_x += mySize_x;
1050 } else { // resizeCorner == 4
1053 HUD_Panel_SetPosSize(mySize);
1057 highlightedAction = 2;
1060 if(nPrimary == K_UPARROW)
1062 else if(nPrimary == K_DOWNARROW)
1064 else if(nPrimary == K_LEFTARROW)
1066 else // if(nPrimary == K_RIGHTARROW)
1069 HUD_Panel_SetPos(pos);
1072 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1074 if (prev_pos != panel_pos || prev_size != panel_size)
1077 panel_pos_backup = prev_pos;
1078 panel_size_backup = prev_size;
1079 highlightedPanel_backup = highlightedPanel;
1083 void HUD_Panel_EnableMenu();
1084 float tab_panels[HUD_PANEL_NUM];
1085 float tab_panel, tab_backward;
1086 vector tab_panel_pos;
1087 void HUD_Panel_FirstInDrawQ(float id);
1088 void reset_tab_panels()
1091 for(i = 0; i < HUD_PANEL_NUM; ++i)
1094 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1098 if(!autocvar__hud_configure)
1101 // allow console bind to work
1104 con_keys = findkeysforcommand("toggleconsole");
1105 keys = tokenize(con_keys);
1107 float hit_con_bind, i;
1108 for (i = 0; i < keys; ++i)
1110 if(nPrimary == stof(argv(i)))
1114 if(bInputType == 0) {
1115 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
1116 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
1117 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
1119 else if(bInputType == 1) {
1120 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
1121 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
1122 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
1125 if(nPrimary == K_CTRL)
1127 if (bInputType == 1) //ctrl has been released
1129 if (tab_panel != -1)
1131 //switch to selected panel
1132 highlightedPanel = tab_panel;
1133 highlightedPanel_prev = tab_panel;
1134 HUD_Panel_FirstInDrawQ(highlightedPanel_prev);
1141 if(nPrimary == K_MOUSE1)
1143 if(bInputType == 0) { // key pressed
1147 else if(bInputType == 1) {// key released
1152 else if(nPrimary == K_ESCAPE)
1154 if (bInputType == 1)
1157 menu_enabled_time = time;
1158 localcmd("menu_showhudexit\n");
1160 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
1162 if (bInputType == 1 || mouseClicked)
1165 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
1166 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
1167 //(it should only after every other panel of the hud)
1168 //It's a minor bug anyway, we can live with it
1170 float starting_panel;
1171 float old_tab_panel = tab_panel;
1172 if (tab_panel == -1) //first press of TAB
1174 if (highlightedPanel_prev != -1)
1175 HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev)
1177 panel_pos = '0 0 0';
1178 starting_panel = highlightedPanel_prev; //can be -1, it means no starting panel
1179 tab_panel_pos = panel_pos; //to compute level
1183 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
1185 starting_panel = tab_panel;
1187 tab_backward = (hudShiftState & S_SHIFT);
1189 float k, level, start_pos_x;
1190 vector candidate_pos;
1191 const float LEVELS_NUM = 4;
1192 const float level_height = vid_conheight / LEVELS_NUM;
1194 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
1195 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
1196 start_pos_x = tab_panel_pos_x;
1201 for(i = 0; i < HUD_PANEL_NUM; ++i)
1203 if (i == tab_panels[i] || i == starting_panel)
1205 HUD_Panel_UpdatePosSizeForId(i)
1206 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
1207 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)) )
1208 || ( 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)) ) )
1211 tab_panel_pos = candidate_pos = panel_pos;
1214 if (tab_panel != -1)
1216 if (k == LEVELS_NUM) //tab_panel not found
1219 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
1224 starting_panel = old_tab_panel;
1226 goto find_tab_panel; //u must find tab_panel!
1230 level = mod(level + level_height, vid_conheight);
1232 candidate_pos_x = vid_conwidth;
1236 level = mod(level - level_height, vid_conheight);
1237 start_pos_x = vid_conwidth;
1238 candidate_pos_x = 0;
1242 tab_panels[tab_panel] = tab_panel;
1244 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
1246 if (bInputType == 1 || mouseClicked)
1249 if (highlightedPanel_prev != -1)
1251 HUD_Panel_GetName(highlightedPanel_prev);
1252 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
1255 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
1257 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
1259 if (bInputType == 1 || mouseClicked)
1262 if (highlightedPanel_prev != -1)
1264 HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev);
1265 panel_size_copied = panel_size;
1266 highlightedPanel_copied = highlightedPanel_prev;
1269 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
1271 if (bInputType == 1 || mouseClicked)
1274 if (highlightedPanel_copied == -1 || highlightedPanel_prev == -1)
1277 HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev);
1279 // reduce size if it'd go beyond screen boundaries
1280 vector tmp_size = panel_size_copied;
1281 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
1282 tmp_size_x = vid_conwidth - panel_pos_x;
1283 if (panel_pos_y + panel_size_copied_y > vid_conheight)
1284 tmp_size_y = vid_conheight - panel_pos_y;
1286 if (panel_size == tmp_size)
1290 panel_pos_backup = panel_pos;
1291 panel_size_backup = panel_size;
1292 highlightedPanel_backup = highlightedPanel_prev;
1294 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
1295 HUD_Panel_GetName(highlightedPanel_prev);
1296 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1298 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
1300 if (bInputType == 1 || mouseClicked)
1302 //restore previous values
1303 if (highlightedPanel_backup != -1)
1305 HUD_Panel_GetName(highlightedPanel_backup);
1306 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
1307 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
1308 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
1309 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1310 highlightedPanel_backup = -1;
1313 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
1315 if (bInputType == 1)
1317 pressed_key_time = 0;
1320 else if (pressed_key_time == 0)
1321 pressed_key_time = time;
1323 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
1325 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
1327 if (bInputType == 1)
1329 if (highlightedPanel_prev != -1)
1331 highlightedPanel = highlightedPanel_prev;
1332 HUD_Panel_EnableMenu();
1335 else if(hit_con_bind)
1341 float HUD_Panel_HighlightCheck()
1345 while(j < HUD_PANEL_NUM)
1350 HUD_Panel_UpdatePosSizeForId(i);
1352 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1355 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)
1359 // resize from topleft border
1360 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)
1364 // resize from topright border
1365 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)
1369 // resize from bottomleft border
1370 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)
1374 // resize from bottomright border
1375 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)
1383 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
1384 void HUD_Panel_FirstInDrawQ(float id)
1387 var float place = -1;
1388 // find out where in the array our current id is, save into place
1389 for(i = 0; i < HUD_PANEL_NUM; ++i)
1391 if(panel_order[i] == id)
1397 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
1399 place = HUD_PANEL_NUM - 1;
1401 // move all ids up by one step in the array until "place"
1402 for(i = place; i > 0; --i)
1404 panel_order[i] = panel_order[i-1];
1406 // now save the new top id
1407 panel_order[0] = id;
1409 // let's save them into the cvar by some strcat trickery
1411 for(i = 0; i < HUD_PANEL_NUM; ++i)
1413 s = strcat(s, ftos(panel_order[i]), " ");
1415 cvar_set("_hud_panelorder", s);
1416 if(hud_panelorder_prev)
1417 strunzone(hud_panelorder_prev);
1418 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
1421 void HUD_Panel_Highlight()
1425 while(j < HUD_PANEL_NUM)
1430 HUD_Panel_UpdatePosSizeForId(i);
1432 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1435 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)
1437 highlightedPanel = i;
1438 HUD_Panel_FirstInDrawQ(i);
1439 highlightedAction = 1;
1440 panel_click_distance = mousepos - panel_pos;
1443 // resize from topleft border
1444 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)
1446 highlightedPanel = i;
1447 HUD_Panel_FirstInDrawQ(i);
1448 highlightedAction = 2;
1450 panel_click_distance = mousepos - panel_pos;
1451 panel_click_resizeorigin = panel_pos + panel_size;
1454 // resize from topright border
1455 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)
1457 highlightedPanel = i;
1458 HUD_Panel_FirstInDrawQ(i);
1459 highlightedAction = 2;
1461 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
1462 panel_click_distance_y = mousepos_y - panel_pos_y;
1463 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
1466 // resize from bottomleft border
1467 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)
1469 highlightedPanel = i;
1470 HUD_Panel_FirstInDrawQ(i);
1471 highlightedAction = 2;
1473 panel_click_distance_x = mousepos_x - panel_pos_x;
1474 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
1475 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
1478 // resize from bottomright border
1479 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)
1481 highlightedPanel = i;
1482 HUD_Panel_FirstInDrawQ(i);
1483 highlightedAction = 2;
1485 panel_click_distance = panel_size - mousepos + panel_pos;
1486 panel_click_resizeorigin = panel_pos;
1491 highlightedPanel_prev = -1;
1496 void HUD_Panel_EnableMenu()
1499 menu_enabled_time = time;
1500 HUD_Panel_GetName(highlightedPanel);
1501 localcmd("menu_showhudoptions ", panel_name, "\n");
1503 float highlightcheck;
1504 vector prev_pos, prev_size;
1505 void HUD_Panel_Mouse()
1507 // 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
1508 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1512 print("menu_enabled: ", ftos(menu_enabled), "\n");
1513 print("Highlighted: ", ftos(highlightedPanel), "\n");
1514 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1517 // instantly hide the editor cursor if we open the HUDExit dialog
1518 // as hud_fade_alpha doesn't decrease to 0 in this case
1519 // TODO: find a way to fade the cursor out even in this case
1520 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1523 if(mouseClicked == 0 && menu_enabled != 2 && highlightedPanel >= 0) { // don't reset these variables in menu_enabled mode 2!
1524 highlightedPanel = -1;
1525 highlightedAction = 0;
1527 if(highlightedPanel != -1)
1528 highlightedPanel_prev = highlightedPanel;
1530 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1532 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1533 mousepos_y = bound(0, mousepos_y, vid_conheight);
1537 if (tab_panel != -1)
1539 //stop ctrl-tab selection
1543 if(prevMouseClicked == 0)
1545 HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1546 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1547 prev_pos = panel_pos;
1548 prev_size = panel_size;
1551 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1553 if (prev_pos != panel_pos || prev_size != panel_size)
1555 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1557 panel_pos_backup = prev_pos;
1558 panel_size_backup = prev_size;
1559 highlightedPanel_backup = highlightedPanel;
1562 // in case the clicked panel is inside another panel and we aren't
1563 // moving it, avoid the immediate "fix" of its position/size
1564 // (often unwanted and hateful) by disabling collisions check
1565 hud_configure_checkcollisions = false;
1567 if(highlightedAction == 1)
1568 HUD_Panel_SetPos(mousepos - panel_click_distance);
1569 else if(highlightedAction == 2)
1572 if(resizeCorner == 1) {
1573 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1574 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1575 } else if(resizeCorner == 2) {
1576 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1577 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1578 } else if(resizeCorner == 3) {
1579 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1580 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1581 } else { // resizeCorner == 4
1582 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1583 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1585 HUD_Panel_SetPosSize(mySize);
1588 // doubleclick check
1589 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1591 mouseClicked = 0; // to prevent spam, I guess.
1592 HUD_Panel_EnableMenu();
1595 if(prevMouseClicked == 0)
1597 prevMouseClickedTime = time;
1598 prevMouseClickedPos = mousepos;
1603 highlightcheck = HUD_Panel_HighlightCheck();
1605 // draw cursor after performing move/resize to have the panel pos/size updated before highlightcheck
1607 cursorsize = '32 32 0';
1609 if(highlightcheck == 0)
1610 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1611 else if(highlightcheck == 1)
1612 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1613 else if(highlightcheck == 2)
1614 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1616 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1618 prevMouseClicked = mouseClicked;
1621 // Weapon icons (#0)
1623 float weaponspace[10];
1624 #define HUD_Weapons_Clear()\
1626 for(idx = 0; idx < 10; ++idx)\
1627 weaponspace[idx] = 0
1629 entity weaponorder[WEP_MAXCOUNT];
1630 void weaponorder_swap(float i, float j, entity pass)
1634 weaponorder[i] = weaponorder[j];
1638 string weaponorder_cmp_str;
1639 float weaponorder_cmp(float i, float j, entity pass)
1642 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1643 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1644 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)
1647 float GetAmmoStat(float i)
1651 case 0: return STAT_SHELLS;
1652 case 1: return STAT_NAILS;
1653 case 2: return STAT_ROCKETS;
1654 case 3: return STAT_CELLS;
1655 case 4: return STAT_FUEL;
1660 float GetAmmoTypeForWep(float i)
1664 case WEP_SHOTGUN: return 0;
1665 case WEP_UZI: return 1;
1666 case WEP_GRENADE_LAUNCHER: return 2;
1667 case WEP_MINE_LAYER: return 2;
1668 case WEP_ELECTRO: return 3;
1669 case WEP_CRYLINK: return 3;
1670 case WEP_HLAC: return 3;
1671 case WEP_MINSTANEX: return 3;
1672 case WEP_NEX: return 3;
1673 case WEP_CAMPINGRIFLE: return 1;
1674 case WEP_HAGAR: return 2;
1675 case WEP_ROCKET_LAUNCHER: return 2;
1676 case WEP_SEEKER: return 2;
1677 case WEP_FIREBALL: return 4;
1678 case WEP_HOOK: return 3;
1683 void HUD_Weapons(void)
1686 float center_x, center_y;
1688 if(!autocvar__hud_configure)
1690 if(!autocvar_hud_panel_weapons) return;
1691 if(spectatee_status == -1) return;
1694 float timeout = autocvar_hud_panel_weapons_timeout;
1695 float timeout_effect_length, timein_effect_length;
1696 if (autocvar_hud_panel_weapons_timeout_effect == 0)
1698 timeout_effect_length = 0;
1699 timein_effect_length = 0;
1703 timeout_effect_length = 0.75;
1704 timein_effect_length = 0.375;
1707 if (timeout && time >= weapontime + timeout + timeout_effect_length && !autocvar__hud_configure)
1709 weaponprevtime = time;
1713 active_panel = HUD_PANEL_WEAPONS;
1714 HUD_Panel_UpdateCvars(weapons);
1716 if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
1718 f = (time - (weapontime + timeout)) / timeout_effect_length;
1719 if (autocvar_hud_panel_weapons_timeout_effect)
1721 panel_bg_alpha *= (1 - f);
1722 panel_fg_alpha *= (1 - f);
1724 if (autocvar_hud_panel_weapons_timeout_effect == 1)
1726 f *= f; // for a cooler movement
1727 center_x = panel_pos_x + panel_size_x/2;
1728 center_y = panel_pos_y + panel_size_y/2;
1729 screen_ar = vid_conwidth/vid_conheight;
1730 if (center_x/center_y < screen_ar) //bottom left
1732 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1733 panel_pos_y += f * (vid_conheight - panel_pos_y);
1735 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1739 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1740 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1742 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1745 weaponprevtime = time - (1 - f) * timein_effect_length;
1747 else if (timeout && time < weaponprevtime + timein_effect_length && !autocvar__hud_configure)
1749 f = (time - weaponprevtime) / timein_effect_length;
1750 if (autocvar_hud_panel_weapons_timeout_effect)
1752 panel_bg_alpha *= (f);
1753 panel_fg_alpha *= (f);
1755 if (autocvar_hud_panel_weapons_timeout_effect == 1)
1757 f *= f; // for a cooler movement
1759 center_x = panel_pos_x + panel_size_x/2;
1760 center_y = panel_pos_y + panel_size_y/2;
1761 screen_ar = vid_conwidth/vid_conheight;
1762 if (center_x/center_y < screen_ar) //bottom left
1764 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1765 panel_pos_y += f * (vid_conheight - panel_pos_y);
1767 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1771 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1772 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1774 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1779 float i, weapid, wpnalpha, weapon_cnt;
1781 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1783 self = get_weaponinfo(i);
1784 if(self.impulse >= 0)
1788 // TODO make this configurable
1789 if(weaponorder_bypriority != autocvar_cl_weaponpriority)
1791 if(weaponorder_bypriority)
1792 strunzone(weaponorder_bypriority);
1793 if(weaponorder_byimpulse)
1794 strunzone(weaponorder_byimpulse);
1796 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
1797 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
1798 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1801 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1803 self = get_weaponinfo(i);
1804 if(self.impulse >= 0)
1806 weaponorder[weapon_cnt] = self;
1810 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1812 weaponorder_cmp_str = string_null;
1815 HUD_Panel_DrawBg(1);
1816 if(panel_bg_padding)
1818 panel_pos += '1 1 0' * panel_bg_padding;
1819 panel_size -= '2 2 0' * panel_bg_padding;
1822 if(autocvar_hud_panel_weapons_fade)
1824 wpnalpha = 3.2 - 2 * (time - weapontime);
1825 wpnalpha = bound(0.7, wpnalpha, 1) * panel_fg_alpha;
1828 wpnalpha = panel_fg_alpha;
1830 HUD_Weapons_Clear();
1832 float rows, columns;
1833 float aspect = autocvar_hud_panel_weapons_aspect;
1834 rows = panel_size_y/panel_size_x;
1835 rows = bound(1, floor((sqrt(4 * aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1837 columns = ceil(WEP_COUNT/rows);
1840 float a, type, fullammo;
1842 when = autocvar_hud_panel_weapons_complainbubble_time;
1844 fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
1852 wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
1853 float barsize_x, barsize_y, baroffset_x, baroffset_y;
1854 if (autocvar_hud_panel_weapons_ammo)
1856 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
1857 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
1860 if(wpnsize_x/wpnsize_y > aspect)
1862 barsize_x = aspect * wpnsize_y;
1863 barsize_y = wpnsize_y;
1864 baroffset_x = (wpnsize_x - barsize_x) / 2;
1868 barsize_y = 1/aspect * wpnsize_x;
1869 barsize_x = wpnsize_x;
1870 baroffset_y = (wpnsize_y - barsize_y) / 2;
1874 float show_accuracy;
1876 if(autocvar_hud_panel_weapons_accuracy && acc_levels)
1878 show_accuracy = true;
1879 if (acc_col_x[0] == -1)
1880 for (i = 0; i < acc_levels; ++i)
1881 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
1884 float weapons_st = getstati(STAT_WEAPONS);
1885 float label = autocvar_hud_panel_weapons_label;
1887 for(i = 0; i < weapon_cnt; ++i)
1889 wpnpos = panel_pos + eX * column * wpnsize_x + eY * row * wpnsize_y;
1891 self = weaponorder[i];
1892 weapid = self.impulse;
1894 // draw background behind currently selected weapon
1895 if(self.weapon == activeweapon)
1896 drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1898 // draw the weapon accuracy
1901 weapon_stats = weapon_accuracy[self.weapon-WEP_FIRST];
1902 if(weapon_stats >= 0)
1904 // find the max level lower than weapon_stats
1907 while ( j && weapon_stats < acc_lev[j] )
1910 // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
1912 factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
1914 color = color + factor * (acc_col[j+1] - color);
1916 drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
1920 // draw the weapon icon
1921 if((weapid >= 0) && (weapons_st & self.weapons))
1923 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1925 if(label == 1) // weapon number
1926 drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1927 else if(label == 2) // bind
1928 drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1930 // draw ammo status bar
1931 if(autocvar_hud_panel_weapons_ammo && weapid != WEP_TUBA && weapid != WEP_LASER && weapid != WEP_PORTO)
1934 type = GetAmmoTypeForWep(weapid);
1936 a = getstati(GetAmmoStat(type)); // how much ammo do we have?
1941 case 0: fullammo = autocvar_hud_panel_weapons_ammo_full_shells; break;
1942 case 1: fullammo = autocvar_hud_panel_weapons_ammo_full_nails; break;
1943 case 2: fullammo = autocvar_hud_panel_weapons_ammo_full_rockets; break;
1944 case 3: fullammo = autocvar_hud_panel_weapons_ammo_full_cells; break;
1945 case 4: fullammo = autocvar_hud_panel_weapons_ammo_full_fuel; break;
1946 default: fullammo = 60;
1950 wpnpos_x + baroffset_x,
1951 wpnpos_y + baroffset_y,
1952 barsize_x * bound(0, a/fullammo, 1),
1954 drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
1955 drawresetcliparea();
1960 // draw a "ghost weapon icon" if you don't have the weapon
1963 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
1966 // draw the complain message
1967 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
1971 if(complain_weapon_time + when > time)
1974 a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
1978 if(complain_weapon_time + when > time)
1985 if(complain_weapon_type == 0) {
1987 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
1989 else if(complain_weapon_type == 1) {
1991 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
1995 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
1997 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
1998 drawpic_aspect_skin(wpnpos + '1 1 0' * padding, "weapon_complainbubble", wpnsize - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
1999 drawstring_aspect(wpnpos + '1 1 0' * padding, s, wpnsize - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2015 float GetAmmoItemCode(float i)
2019 case 0: return IT_SHELLS;
2020 case 1: return IT_NAILS;
2021 case 2: return IT_ROCKETS;
2022 case 3: return IT_CELLS;
2023 case 4: return IT_FUEL;
2028 string GetAmmoPicture(float i)
2032 case 0: return "ammo_shells";
2033 case 1: return "ammo_bullets";
2034 case 2: return "ammo_rockets";
2035 case 3: return "ammo_cells";
2036 case 4: return "ammo_fuel";
2041 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
2044 if(autocvar__hud_configure)
2046 currently_selected = (itemcode == 2); //rockets always selected
2047 a = 31 + mod(itemcode*93, 128);
2050 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
2059 if(currently_selected)
2064 vector picpos, numpos;
2065 if(autocvar_hud_panel_ammo_iconalign)
2068 picpos = myPos + eX * 2 * mySize_y;
2072 numpos = myPos + eX * mySize_y;
2076 if (currently_selected)
2077 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2079 if(a > 0 && autocvar_hud_panel_ammo_progressbar)
2080 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);
2082 if(autocvar_hud_panel_ammo_text)
2085 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2086 else // "ghost" ammo count
2087 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
2090 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2091 else // "ghost" ammo icon
2092 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
2097 if(!autocvar__hud_configure)
2099 if(!autocvar_hud_panel_ammo) return;
2100 if(spectatee_status == -1) return;
2103 active_panel = HUD_PANEL_AMMO;
2104 HUD_Panel_UpdateCvars(ammo);
2107 mySize = panel_size;
2109 HUD_Panel_DrawBg(1);
2110 if(panel_bg_padding)
2112 pos += '1 1 0' * panel_bg_padding;
2113 mySize -= '2 2 0' * panel_bg_padding;
2116 float rows, columns, row, column;
2118 if (autocvar_hud_panel_ammo_onlycurrent)
2122 rows = mySize_y/mySize_x;
2123 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
2124 // ^^^ ammo item aspect goes here
2126 columns = ceil(AMMO_COUNT/rows);
2128 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
2133 if(ammo_size_x/ammo_size_y > 3)
2135 newSize = 3 * ammo_size_y;
2136 offset_x = ammo_size_x - newSize;
2137 pos_x += offset_x/2;
2138 ammo_size_x = newSize;
2142 newSize = 1/3 * ammo_size_x;
2143 offset_y = ammo_size_y - newSize;
2144 pos_y += offset_y/2;
2145 ammo_size_y = newSize;
2148 drawfont = hud_bigfont;
2149 float i, stat_items, currently_selected;
2150 if (autocvar_hud_panel_ammo_onlycurrent)
2152 if(autocvar__hud_configure)
2154 DrawAmmoItem(pos, ammo_size, 2, true); //show rockets
2157 stat_items = getstati(STAT_ITEMS);
2158 for (i = 0; i < AMMO_COUNT; ++i) {
2159 currently_selected = stat_items & GetAmmoItemCode(i);
2160 if (currently_selected)
2162 DrawAmmoItem(pos, ammo_size, i, true);
2166 return; // nothing to display
2169 stat_items = getstati(STAT_ITEMS);
2170 for (i = 0; i < AMMO_COUNT; ++i) {
2171 currently_selected = stat_items & GetAmmoItemCode(i);
2172 DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected);
2177 column = column + 1;
2180 drawfont = hud_font;
2183 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float alpha)
2185 vector newPos, newSize;
2186 vector picpos, numpos;
2190 if(mySize_y/mySize_x > 2)
2192 newSize_y = 2 * mySize_x;
2193 newSize_x = mySize_x;
2195 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
2200 newSize_x = 1/2 * mySize_y;
2201 newSize_y = mySize_y;
2203 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
2207 if(icon_right_align)
2210 picpos = newPos + eY * newSize_x;
2215 numpos = newPos + eY * newSize_x;
2219 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2220 // make number smaller than icon, it looks better
2221 // reduce only y to draw numbers with different number of digits with the same y size
2222 numpos_y += newSize_y * ((1 - 0.7) / 2);
2224 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2228 if(mySize_x/mySize_y > 3)
2230 newSize_x = 3 * mySize_y;
2231 newSize_y = mySize_y;
2233 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
2238 newSize_y = 1/3 * mySize_x;
2239 newSize_x = mySize_x;
2241 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
2245 if(icon_right_align) // right align
2248 picpos = newPos + eX * 2 * newSize_y;
2252 numpos = newPos + eX * newSize_y;
2256 drawstring_aspect(numpos, ftos(x), '2 1 0' * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2257 drawpic_aspect_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2260 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float fadelerp)
2263 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
2265 DrawNumIcon(myPos + expandingbox_resize_centered_box_offset(sz, mySize, 1), mySize * sz, x, icon, vertical, icon_right_align, color, (1 - fadelerp));
2270 void HUD_Powerups(void) {
2271 if(!autocvar__hud_configure)
2273 if(!autocvar_hud_panel_powerups) return;
2274 if(spectatee_status == -1) return;
2275 if not(getstati(STAT_ITEMS) & (IT_STRENGTH | IT_INVINCIBLE)) return;
2276 if (getstati(STAT_HEALTH) <= 0) return;
2279 active_panel = HUD_PANEL_POWERUPS;
2280 HUD_Panel_UpdateCvars(powerups);
2283 mySize = panel_size;
2285 float strength_time, shield_time;
2286 if(autocvar__hud_configure)
2293 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
2294 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
2297 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
2298 if(panel_bg_padding)
2300 pos += '1 1 0' * panel_bg_padding;
2301 mySize -= '2 2 0' * panel_bg_padding;
2308 string leftname, rightname;
2309 string leftprogressname, rightprogressname;
2310 float leftcnt, rightcnt;
2311 float leftexact, rightexact;
2312 if (autocvar_hud_panel_powerups_flip) {
2313 leftname = "strength";
2314 leftprogressname = autocvar_hud_panel_powerups_progressbar_strength;
2315 leftcnt = ceil(strength_time);
2316 leftexact = strength_time;
2318 rightname = "shield";
2319 rightprogressname = autocvar_hud_panel_powerups_progressbar_shield;
2320 rightcnt = ceil(shield_time);
2321 rightexact = shield_time;
2323 leftname = "shield";
2324 leftprogressname = autocvar_hud_panel_powerups_progressbar_shield;
2325 leftcnt = ceil(shield_time);
2326 leftexact = shield_time;
2328 rightname = "strength";
2329 rightprogressname = autocvar_hud_panel_powerups_progressbar_strength;
2330 rightcnt = ceil(strength_time);
2331 rightexact = strength_time;
2334 drawfont = hud_bigfont;
2335 float baralign = autocvar_hud_panel_powerups_baralign;
2336 float iconalign = autocvar_hud_panel_powerups_iconalign;
2338 float panel_ar = mySize_x/mySize_y;
2339 float is_vertical = (panel_ar < 1);
2340 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
2342 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2345 if(autocvar_hud_panel_powerups_progressbar)
2347 HUD_Panel_GetProgressBarColorForString(leftname);
2348 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);
2350 if(autocvar_hud_panel_powerups_text)
2353 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
2355 DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2362 if(autocvar_hud_panel_powerups_progressbar)
2364 HUD_Panel_GetProgressBarColorForString(rightname);
2365 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);
2367 if(autocvar_hud_panel_powerups_text)
2370 DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
2372 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));
2378 barsize = eX * mySize_x + eY * 0.5 * mySize_y;
2381 if(autocvar_hud_panel_powerups_progressbar)
2383 HUD_Panel_GetProgressBarColorForString(leftname);
2384 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);
2386 if(autocvar_hud_panel_powerups_text)
2389 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
2391 DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2398 if(autocvar_hud_panel_powerups_progressbar)
2400 HUD_Panel_GetProgressBarColorForString(rightname);
2401 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);
2403 if(autocvar_hud_panel_powerups_text)
2406 DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
2408 DrawNumIcon_expanding(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
2412 drawfont = hud_font;
2415 // Health/armor (#3)
2417 void HUD_HealthArmor(void)
2419 if(!autocvar__hud_configure)
2421 if(!autocvar_hud_panel_healtharmor) return;
2422 if(spectatee_status == -1) return;
2425 active_panel = HUD_PANEL_HEALTHARMOR;
2426 HUD_Panel_UpdateCvars(healtharmor);
2429 mySize = panel_size;
2431 HUD_Panel_DrawBg(1);
2432 if(panel_bg_padding)
2434 pos += '1 1 0' * panel_bg_padding;
2435 mySize -= '2 2 0' * panel_bg_padding;
2438 float armor, health, fuel;
2439 armor = getstati(STAT_ARMOR);
2440 health = getstati(STAT_HEALTH);
2441 fuel = getstati(STAT_FUEL);
2443 if(autocvar__hud_configure)
2454 vector picpos, numpos;
2456 drawfont = hud_bigfont;
2457 float baralign = autocvar_hud_panel_healtharmor_baralign;
2458 float iconalign = autocvar_hud_panel_healtharmor_iconalign;
2460 float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
2461 float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
2462 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
2465 v = healtharmor_maxdamage(health, armor, armorblockpercent);
2470 float maxtotal = maxhealth + maxarmor;
2472 if(v_z) // NOT fully armored
2474 biggercount = "health";
2475 if(autocvar_hud_panel_healtharmor_progressbar)
2477 HUD_Panel_GetProgressBarColor(health);
2478 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);
2481 if(autocvar_hud_panel_healtharmor_text)
2482 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);
2486 biggercount = "armor";
2487 if(autocvar_hud_panel_healtharmor_progressbar)
2489 HUD_Panel_GetProgressBarColor(armor);
2490 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);
2493 if(autocvar_hud_panel_healtharmor_text)
2494 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);
2496 if(autocvar_hud_panel_healtharmor_text)
2497 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
2501 HUD_Panel_GetProgressBarColor(fuel);
2502 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);
2507 string leftname, rightname;
2508 string leftprogressname, rightprogressname;
2509 float leftcnt, rightcnt;
2510 float leftmax, rightmax;
2511 float leftactive, rightactive;
2512 float leftalpha, rightalpha;
2513 if (autocvar_hud_panel_healtharmor_flip) { // old style layout with armor left/top of health
2515 leftprogressname = autocvar_hud_panel_healtharmor_progressbar_armor;
2519 leftalpha = min((armor+10)/55, 1);
2522 rightname = "health";
2523 rightprogressname = autocvar_hud_panel_healtharmor_progressbar_health;
2527 rightmax = maxhealth;
2529 leftname = "health";
2530 leftprogressname = autocvar_hud_panel_healtharmor_progressbar_health;
2534 leftmax = maxhealth;
2536 rightname = "armor";
2537 rightprogressname = autocvar_hud_panel_healtharmor_progressbar_armor;
2541 rightalpha = min((armor+10)/55, 1);
2542 rightmax = maxarmor;
2545 float panel_ar = mySize_x/mySize_y;
2546 float is_vertical = (panel_ar < 1);
2547 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
2549 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2552 if(autocvar_hud_panel_healtharmor_progressbar)
2554 HUD_Panel_GetProgressBarColorForString(leftname);
2555 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);
2557 if(autocvar_hud_panel_healtharmor_text)
2558 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, leftmax), 1);
2563 if(autocvar_hud_panel_healtharmor_progressbar)
2565 HUD_Panel_GetProgressBarColorForString(rightname);
2566 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);
2568 if(autocvar_hud_panel_healtharmor_text)
2569 DrawNumIcon(pos + eX * 0.5 * mySize_x, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, rightmax), 1);
2574 HUD_Panel_GetProgressBarColor(fuel);
2575 if (is_vertical) //if vertical always halve x to not cover too much numbers with 3 digits
2576 mySize_x *= 0.2 * 0.5 / 2;
2579 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2584 barsize = eX * mySize_x + eY * 0.5 * mySize_y;
2587 if(autocvar_hud_panel_healtharmor_progressbar)
2589 HUD_Panel_GetProgressBarColorForString(leftname);
2590 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);
2592 if(autocvar_hud_panel_healtharmor_text)
2593 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, leftmax), 1);
2598 if(autocvar_hud_panel_healtharmor_progressbar)
2600 HUD_Panel_GetProgressBarColorForString(rightname);
2601 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);
2603 if(autocvar_hud_panel_healtharmor_text)
2604 DrawNumIcon(pos + eY * 0.5 * mySize_y, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, rightmax), 1);
2609 HUD_Panel_GetProgressBarColor(fuel);
2610 if (is_vertical) //if vertical always halve x to not cover numbers with 3 digits
2611 mySize_x *= 0.2 / 2;
2613 mySize_y *= 0.2 * 0.5;
2614 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2618 drawfont = hud_font;
2621 // Notification area (#4)
2624 string Weapon_SuicideMessage(float deathtype)
2626 w_deathtype = deathtype;
2627 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2628 return w_deathtypestring;
2631 string Weapon_KillMessage(float deathtype)
2633 w_deathtype = deathtype;
2634 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2635 return w_deathtypestring;
2638 #define KN_MAX_ENTRIES 10
2640 float killnotify_times[KN_MAX_ENTRIES];
2641 float killnotify_deathtype[KN_MAX_ENTRIES];
2642 float killnotify_actiontype[KN_MAX_ENTRIES]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2643 string killnotify_attackers[KN_MAX_ENTRIES];
2644 string killnotify_victims[KN_MAX_ENTRIES];
2645 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2649 kn_index = KN_MAX_ENTRIES-1;
2650 killnotify_times[kn_index] = time;
2651 killnotify_deathtype[kn_index] = wpn;
2652 killnotify_actiontype[kn_index] = actiontype;
2653 if(killnotify_attackers[kn_index])
2654 strunzone(killnotify_attackers[kn_index]);
2655 killnotify_attackers[kn_index] = strzone(attacker);
2656 if(killnotify_victims[kn_index])
2657 strunzone(killnotify_victims[kn_index]);
2658 killnotify_victims[kn_index] = strzone(victim);
2661 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
2664 float alsoprint, gentle;
2665 alsoprint = (autocvar_hud_panel_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
2666 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
2668 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
2671 if(msg == MSG_SUICIDE) {
2672 w = DEATH_WEAPONOF(type);
2674 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2676 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
2677 } else if (type == DEATH_KILL) {
2678 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2680 print ("^1",s1, "^1 couldn't take it anymore\n");
2681 } else if (type == DEATH_ROT) {
2682 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2684 print ("^1",s1, "^1 died\n");
2685 } else if (type == DEATH_NOAMMO) {
2686 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2688 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2689 } else if (type == DEATH_CAMP) {
2690 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2692 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2693 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2694 HUD_KillNotify_Push(s1, "", 0, type);
2696 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2697 } else if (type == DEATH_CHEAT) {
2698 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2700 print ("^1",s1, "^1 unfairly eliminated themself\n");
2701 } else if (type == DEATH_FIRE) {
2702 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2704 print ("^1",s1, "^1 burned to death\n");
2705 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2706 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2708 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2711 if (stof(s2) > 2) // killcount > 2
2712 print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2713 } else if(msg == MSG_KILL) {
2714 w = DEATH_WEAPONOF(type);
2716 if((w == WEP_CAMPINGRIFLE || w == WEP_MINSTANEX) && type & HITTYPE_HEADSHOT) // all headshot weapons go here
2717 HUD_KillNotify_Push(s1, s2, 1, DEATH_HEADSHOT);
2719 HUD_KillNotify_Push(s1, s2, 1, type);
2722 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
2724 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2725 HUD_KillNotify_Push(s1, s2, 1, type);
2729 print ("^1", s1, "^1 took action against a team mate\n");
2731 print ("^1", s1, "^1 mows down a team mate\n");
2734 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2736 print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2738 print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2740 else if (stof(s2) > 2) {
2742 print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2744 print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2747 else if(type == KILL_FIRST_BLOOD)
2748 print("^1",s1, "^1 drew first blood", "\n");
2749 else if (type == DEATH_TELEFRAG) {
2750 HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
2752 print ("^1",s2, "^1 tried to occupy ", s1, "^1's teleport destination space\n");
2754 print ("^1",s2, "^1 was telefragged by ", s1, "\n");
2756 else if (type == DEATH_DROWN) {
2757 HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
2759 print ("^1",s2, "^1 was drowned by ", s1, "\n");
2761 else if (type == DEATH_SLIME) {
2762 HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
2764 print ("^1",s2, "^1 was slimed by ", s1, "\n");
2766 else if (type == DEATH_LAVA) {
2767 HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
2769 print ("^1",s2, "^1 was cooked by ", s1, "\n");
2771 else if (type == DEATH_FALL) {
2772 HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
2774 print ("^1",s2, "^1 was grounded by ", s1, "\n");
2776 else if (type == DEATH_SHOOTING_STAR) {
2777 HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
2779 print ("^1",s2, "^1 was shot into space by ", s1, "\n");
2781 else if (type == DEATH_SWAMP) {
2782 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2784 print ("^1",s2, "^1 was conserved by ", s1, "\n");
2786 else if (type == DEATH_HURTTRIGGER)
2788 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2790 print("^1",s2, "^1 was thrown into a world of hurt by ", s1, "\n");
2791 } else if(type == DEATH_SBCRUSH) {
2792 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2794 print ("^1",s2, "^1 was crushed by ^1", s1, "\n");
2795 } else if(type == DEATH_SBMINIGUN) {
2796 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2798 print ("^1",s2, "^1 got shredded by ^1", s1, "\n");
2799 } else if(type == DEATH_SBROCKET) {
2800 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2802 print ("^1",s2, "^1 was blased to bits by ^1", s1, "\n");
2803 } else if(type == DEATH_SBBLOWUP) {
2804 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2806 print ("^1",s2, "^1 got caught in the destruction of ^1", s1, "'s vehicle\n");
2807 } else if(type == DEATH_WAKIGUN) {
2808 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2810 print ("^1",s2, "^1 was bolted down by ^1", s1, "\n");
2811 } else if(type == DEATH_WAKIROCKET) {
2812 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2814 print ("^1",s2, "^1 could find no shelter from ^1", s1, "'s rockets\n");
2815 } else if(type == DEATH_WAKIBLOWUP) {
2816 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2818 print ("^1",s2, "^1 dies when ^1", s1, "'s wakizashi dies.\n");
2819 } else if(type == DEATH_TURRET) {
2820 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2822 print ("^1",s2, "^1 was pushed into the line of fire by ^1", s1, "\n");
2823 } else if(type == DEATH_TOUCHEXPLODE) {
2824 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2826 print ("^1",s2, "^1 was pushed into an accident by ^1", s1, "\n");
2827 } else if(type == DEATH_CHEAT) {
2828 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2830 print ("^1",s2, "^1 was unfairly eliminated by ^1", s1, "\n");
2831 } else if (type == DEATH_FIRE) {
2832 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2834 print ("^1",s2, "^1 was burnt to death by ^1", s1, "\n");
2835 } else if (type == DEATH_CUSTOM) {
2836 HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
2838 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2839 } else if (type == DEATH_HURTTRIGGER) {
2840 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2842 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2844 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2846 print ("^1",s2, "^1 was fragged by ", s1, "\n");
2848 } else if(msg == MSG_SPREE) {
2849 if(type == KILL_END_SPREE) {
2851 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2853 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2854 } else if(type == KILL_SPREE) {
2856 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2858 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2859 } else if(type == KILL_SPREE_3) {
2861 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2863 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2864 } else if(type == KILL_SPREE_5) {
2866 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2868 print (s1,"^7 unleashes ^1RAGE\n");
2869 } else if(type == KILL_SPREE_10) {
2871 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2873 print (s1,"^7 starts the ^1MASSACRE!\n");
2874 } else if(type == KILL_SPREE_15) {
2876 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2878 print (s1,"^7 executes ^1MAYHEM!\n");
2879 } else if(type == KILL_SPREE_20) {
2881 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2883 print (s1,"^7 is a ^1BERSERKER!\n");
2884 } else if(type == KILL_SPREE_25) {
2886 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2888 print (s1,"^7 inflicts ^1CARNAGE!\n");
2889 } else if(type == KILL_SPREE_30) {
2891 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2893 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2895 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2896 if (type == DEATH_DROWN) {
2897 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2901 print ("^1",s1, "^1 was in the water for too long\n");
2903 print ("^1",s1, "^1 drowned\n");
2905 } else if (type == DEATH_SLIME) {
2906 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2908 print ("^1",s1, "^1 was slimed\n");
2909 } else if (type == DEATH_LAVA) {
2910 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2914 print ("^1",s1, "^1 found a hot place\n");
2916 print ("^1",s1, "^1 turned into hot slag\n");
2918 } else if (type == DEATH_FALL) {
2919 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2923 print ("^1",s1, "^1 tested gravity (and it worked)\n");
2925 print ("^1",s1, "^1 hit the ground with a crunch\n");
2927 } else if (type == DEATH_SHOOTING_STAR) {
2928 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2930 print ("^1",s1, "^1 became a shooting star\n");
2931 } else if (type == DEATH_SWAMP) {
2932 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2936 print ("^1",s1, "^1 discovered a swamp\n");
2938 print ("^1",s1, "^1 is now conserved for centuries to come\n");
2940 } else if(type == DEATH_TURRET) {
2941 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2943 print ("^1",s1, "^1 was mowed down by a turret \n");
2944 } else if (type == DEATH_CUSTOM) {
2945 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2947 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2948 } else if (type == DEATH_HURTTRIGGER) {
2949 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2951 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2952 } else if(type == DEATH_TOUCHEXPLODE) {
2953 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2955 print ("^1",s1, "^1 died in an accident\n");
2956 } else if(type == DEATH_CHEAT) {
2957 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2959 print ("^1",s1, "^1 was unfairly eliminated\n");
2960 } else if(type == DEATH_FIRE) {
2961 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2965 print ("^1",s1, "^1 felt a little hot\n");
2967 print ("^1",s1, "^1 burnt to death\n");
2970 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2974 print ("^1",s1, "^1 needs a restart\n");
2976 print ("^1",s1, "^1 died\n");
2979 } else if(msg == MSG_KILL_ACTION_SPREE) {
2981 print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2983 print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2984 } else if(msg == MSG_INFO) {
2985 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2986 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2987 print(s1, "^7 got the ", s2, "\n");
2988 } else if(type == INFO_LOSTFLAG) {
2989 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2990 print(s1, "^7 lost the ", s2, "\n");
2991 } else if(type == INFO_PICKUPFLAG) {
2992 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2993 print(s1, "^7 picked up the ", s2, "\n");
2994 } else if(type == INFO_RETURNFLAG) {
2995 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2996 print(s1, "^7 returned the ", s2, "\n");
2997 } else if(type == INFO_CAPTUREFLAG) {
2998 HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
2999 print(s1, "^7 captured the ", s2, s3, "\n");
3001 } else if(msg == MSG_RACE) {
3002 if(type == RACE_SERVER_RECORD) {
3003 HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
3005 else if(type == RACE_NEW_RANK) {
3006 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
3008 else if(type == RACE_NEW_TIME) {
3009 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
3011 else if(type == RACE_FAIL) {
3012 HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
3014 } else if(msg == MSG_KA) {
3015 if(type == KA_PICKUPBALL) {
3016 HUD_KillNotify_Push(s1, s2, 0, KA_PICKUPBALL);
3018 print (s1, "^7 has picked up the ball!\n");
3020 else if(type == KA_DROPBALL) {
3021 HUD_KillNotify_Push(s1, s2, 0, KA_DROPBALL);
3023 print(s1, "^7 has dropped the ball!\n");
3028 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
3030 void HUD_Centerprint(string s1, string s2, float type, float msg)
3033 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
3034 if(msg == MSG_SUICIDE) {
3035 if (type == DEATH_TEAMCHANGE) {
3036 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
3037 } else if (type == DEATH_AUTOTEAMCHANGE) {
3038 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
3039 } else if (type == DEATH_CAMP) {
3041 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
3043 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
3044 } else if (type == DEATH_NOAMMO) {
3046 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
3048 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
3049 } else if (type == DEATH_ROT) {
3051 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
3053 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
3054 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
3056 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
3058 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
3059 } else if (type == DEATH_QUIET) {
3061 } else { // generic message
3063 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
3065 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
3067 } else if(msg == MSG_KILL) {
3068 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
3070 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
3072 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
3074 } else if (type == KILL_FIRST_BLOOD) {
3076 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
3078 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
3080 } else if (type == KILL_FIRST_VICTIM) {
3082 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
3084 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
3086 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
3088 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
3090 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
3092 } else if (type == KILL_TYPEFRAGGED) {
3094 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
3096 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
3098 } else if (type == KILL_FRAG) {
3100 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
3102 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
3104 } else { // generic message
3106 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
3108 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
3111 } else if(msg == MSG_KILL_ACTION) {
3112 // TODO: invent more centerprints here?
3113 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
3117 void HUD_Notify (void)
3119 if(!autocvar_hud_panel_notify && !autocvar__hud_configure)
3122 active_panel = HUD_PANEL_NOTIFY;
3123 HUD_Panel_UpdateCvars(notify);
3126 mySize = panel_size;
3128 HUD_Panel_DrawBg(1);
3129 if(panel_bg_padding)
3131 pos += '1 1 0' * panel_bg_padding;
3132 mySize -= '2 2 0' * panel_bg_padding;
3135 float entries, height;
3136 entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
3137 height = mySize_y/entries;
3140 fontsize = '0.5 0.5 0' * height;
3144 when = autocvar_hud_panel_notify_time;
3146 fadetime = autocvar_hud_panel_notify_fadetime;
3150 vector pos_attacker, pos_victim;
3152 float width_attacker;
3153 string attacker, victim;
3155 float i, j, w, step, limit;
3156 if(autocvar_hud_panel_notify_flip) //order items from the top down
3162 else //order items from the bottom up
3169 for(j = kn_index; i != limit; i += step, ++j)
3171 if(autocvar__hud_configure)
3175 else // inverse order
3176 a = entries - 1 - i;
3177 attacker = textShortenToWidth(strcat("Player", ftos(a+1)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3178 victim = textShortenToWidth(strcat("Player", ftos(a+2)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3179 s = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
3180 a = bound(0, (when - a) / 4, 1);
3181 goto hud_config_notifyprint;
3184 if (j == KN_MAX_ENTRIES)
3187 if(killnotify_times[j] + when > time)
3191 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
3205 w = DEATH_WEAPONOF(killnotify_deathtype[j]);
3207 // TODO: maybe print in team colors?
3210 if(killnotify_actiontype[j] == 0)
3212 if(killnotify_deathtype[j] == DEATH_GENERIC)
3216 else if(killnotify_deathtype[j] == DEATH_NOAMMO)
3218 s = "notify_outofammo";
3220 else if(killnotify_deathtype[j] == DEATH_KILL)
3222 s = "notify_selfkill";
3224 else if(killnotify_deathtype[j] == DEATH_CAMP)
3226 s = "notify_camping";
3228 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
3230 s = "notify_teamkill_red";
3232 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
3234 s = "notify_teamkill_blue";
3236 else if(killnotify_deathtype[j] == DEATH_DROWN)
3240 else if(killnotify_deathtype[j] == DEATH_SLIME)
3244 else if(killnotify_deathtype[j] == DEATH_LAVA)
3248 else if(killnotify_deathtype[j] == DEATH_FALL)
3252 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
3254 s = "notify_shootingstar";
3256 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
3260 else if(killnotify_deathtype[j] == INFO_GOTFLAG)
3262 if(killnotify_victims[j] == "^1RED^7 flag")
3264 s = "notify_red_taken";
3268 s = "notify_blue_taken";
3271 else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
3273 if(killnotify_victims[j] == "^1RED^7 flag")
3275 s = "notify_red_returned";
3279 s = "notify_blue_returned";
3282 else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
3284 if(killnotify_victims[j] == "^1RED^7 flag")
3286 s = "notify_red_lost";
3290 s = "notify_blue_lost";
3293 else if(killnotify_deathtype[j] == INFO_CAPTUREFLAG)
3295 if(killnotify_victims[j] == "^1RED^7 flag")
3297 s = "notify_red_captured";
3301 s = "notify_blue_captured";
3304 else if(killnotify_deathtype[j] == KA_DROPBALL)
3306 s = "notify_balldropped";
3308 else if(killnotify_deathtype[j] == KA_PICKUPBALL)
3310 s = "notify_ballpickedup";
3313 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3314 pos_attacker = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
3315 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
3319 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3320 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3323 // X [did action to] Y
3326 if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_LASER)
3328 s = "notify_melee_laser";
3330 else if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_SHOTGUN)
3332 s = "notify_melee_shotgun";
3334 else if(WEP_VALID(w))
3336 self = get_weaponinfo(w);
3337 s = strcat("weapon", self.netname);
3339 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
3341 s = "notify_teamkill_red";
3343 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
3345 s = "notify_teamkill_red";
3347 else if(killnotify_deathtype[j] == DEATH_TELEFRAG)
3349 s = "notify_telefrag";
3351 else if(killnotify_deathtype[j] == DEATH_DROWN)
3355 else if(killnotify_deathtype[j] == DEATH_SLIME)
3359 else if(killnotify_deathtype[j] == DEATH_LAVA)
3363 else if(killnotify_deathtype[j] == DEATH_FALL)
3367 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
3369 s = "notify_shootingstar";
3371 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
3375 else if(killnotify_deathtype[j] == DEATH_HEADSHOT)
3377 s = "notify_headshot";
3379 else if(killnotify_deathtype[j] == RACE_SERVER_RECORD)
3381 s = "race_newrecordserver";
3383 else if(killnotify_deathtype[j] == RACE_NEW_RANK)
3385 s = "race_newrankyellow";
3387 else if(killnotify_deathtype[j] == RACE_NEW_TIME)
3391 else if(killnotify_deathtype[j] == RACE_FAIL)
3396 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3397 victim = textShortenToWidth(killnotify_victims[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3398 :hud_config_notifyprint
3399 width_attacker = stringwidth(attacker, TRUE, fontsize);
3400 pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * (0.5 * fontsize_y + i * height);
3401 pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
3402 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
3406 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3407 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3408 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3417 string seconds_tostring(float sec)
3420 minutes = floor(sec / 60);
3422 sec -= minutes * 60;
3425 s = ftos(100 + sec);
3427 return strcat(ftos(minutes), ":", substring(s, 1, 3));
3430 void HUD_Timer(void)
3432 if(!autocvar_hud_panel_timer && !autocvar__hud_configure)
3435 active_panel = HUD_PANEL_TIMER;
3436 HUD_Panel_UpdateCvars(timer);
3439 mySize = panel_size;
3441 HUD_Panel_DrawBg(1);
3442 if(panel_bg_padding)
3444 pos += '1 1 0' * panel_bg_padding;
3445 mySize -= '2 2 0' * panel_bg_padding;
3449 float timelimit, elapsedTime, timeleft, minutesLeft;
3451 timelimit = getstatf(STAT_TIMELIMIT);
3453 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
3454 timeleft = ceil(timeleft);
3456 minutesLeft = floor(timeleft / 60);
3459 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
3460 timer_color = '1 1 1'; //white
3461 else if(minutesLeft >= 1)
3462 timer_color = '1 1 0'; //yellow
3464 timer_color = '1 0 0'; //red
3466 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
3467 if (time < getstatf(STAT_GAMESTARTTIME)) {
3468 //while restart is still active, show 00:00
3469 timer = seconds_tostring(0);
3471 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
3472 timer = seconds_tostring(elapsedTime);
3475 timer = seconds_tostring(timeleft);
3478 drawfont = hud_bigfont;
3479 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3480 drawfont = hud_font;
3485 void HUD_Radar(void)
3487 if ((autocvar_hud_panel_radar == 0 || (autocvar_hud_panel_radar != 2 && !teamplay)) && !autocvar__hud_configure)
3490 active_panel = HUD_PANEL_RADAR;
3491 HUD_Panel_UpdateCvars(radar);
3494 mySize = panel_size;
3496 HUD_Panel_DrawBg(1);
3497 if(panel_bg_padding)
3499 pos += '1 1 0' * panel_bg_padding;
3500 mySize -= '2 2 0' * panel_bg_padding;
3505 float scale2d, normalsize, bigsize;
3508 teamradar_origin2d = pos + 0.5 * mySize;
3509 teamradar_size2d = mySize;
3511 if(minimapname == "")
3514 teamradar_loadcvars();
3516 switch(hud_panel_radar_zoommode)
3520 f = current_zoomfraction;
3523 f = 1 - current_zoomfraction;
3533 switch(hud_panel_radar_rotation)
3536 teamradar_angle = view_angles_y - 90;
3539 teamradar_angle = 90 * hud_panel_radar_rotation;
3543 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
3544 teamradar_size2d = mySize;
3546 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
3548 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
3549 if(hud_panel_radar_rotation == 0)
3551 // max-min distance must fit the radar in any rotation
3552 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
3556 vector c0, c1, c2, c3, span;
3557 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
3558 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
3559 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
3560 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
3562 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
3563 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
3565 // max-min distance must fit the radar in x=x, y=y
3567 teamradar_size2d_x * scale2d / (1.05 * span_x),
3568 teamradar_size2d_y * scale2d / (1.05 * span_y)
3572 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
3573 if(bigsize > normalsize)
3574 normalsize = bigsize;
3578 + (1 - f) * normalsize;
3579 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
3580 f * (mi_min + mi_max) * 0.5
3581 + (1 - f) * view_origin);
3590 draw_teamradar_background(hud_panel_radar_foreground_alpha);
3592 for(tm = world; (tm = find(tm, classname, "radarlink")); )
3593 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
3594 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
3595 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
3596 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
3598 color2 = GetPlayerColor(tm.sv_entnum);
3599 //if(color == COLOR_SPECTATOR || color == color2)
3600 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
3602 draw_teamradar_player(view_origin, view_angles, '1 1 1');
3604 drawresetcliparea();
3609 void HUD_UpdatePlayerTeams();
3610 void HUD_Score(void)
3612 if(!autocvar__hud_configure && !autocvar_hud_panel_score)
3615 active_panel = HUD_PANEL_SCORE;
3616 HUD_Panel_UpdateCvars(score);
3619 mySize = panel_size;
3621 HUD_Panel_DrawBg(1);
3622 if(panel_bg_padding)
3624 pos += '1 1 0' * panel_bg_padding;
3625 mySize -= '2 2 0' * panel_bg_padding;
3628 float score, distribution;
3630 vector distribution_color;
3632 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
3634 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
3635 string timer, distrtimer;
3637 pl = players.sort_next;
3640 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
3641 if(pl.scores[ps_primary] == 0)
3644 score = me.(scores[ps_primary]);
3645 timer = TIME_ENCODED_TOSTRING(score);
3647 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
3648 // distribution display
3649 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3651 distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
3653 if (distribution <= 0) {
3654 distribution_color = '0 1 0';
3658 distribution_color = '1 0 0';
3661 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);
3663 // race record display
3664 if (distribution <= 0)
3665 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3666 drawfont = hud_bigfont;
3667 drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3668 drawfont = hud_font;
3669 } else if (!teamplay) { // non-teamgames
3670 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
3672 #define SCOREPANEL_MAX_ENTRIES 6
3673 #define SCOREPANEL_ASPECTRATIO 2
3674 float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
3675 float height = mySize_y/entries;
3676 vector fontsize = '0.9 0.9 0' * height;
3677 pos_y += height * (1 - 0.9) / 2;
3682 float name_size = mySize_x*0.75;
3683 float i, me_printed;
3685 if (autocvar__hud_configure)
3687 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
3688 for (i=0; i<entries; ++i)
3690 //simulate my score is lower than all displayed players,
3691 //so that I don't appear at all showing pure rankings.
3692 //This is to better show the difference between the 2 ranking views
3693 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
3696 drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, 0.3 * panel_fg_alpha, DRAWFLAG_NORMAL);
3697 s = GetPlayerName(pl.sv_entnum);
3702 s = strcat("Player", ftos(i+1));
3706 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
3707 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
3708 drawstring(pos + eX * mySize_x*0.79, ftos(score), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3714 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
3715 HUD_UpdatePlayerTeams();
3717 for (pl = players.sort_next, i=0; pl && i<entries; pl = pl.sort_next, ++i)
3719 if (pl.team == COLOR_SPECTATOR)
3722 if (i == entries-1 && !me_printed && pl != me)
3723 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
3725 for (pl = me.sort_next; pl; pl = pl.sort_next)
3726 if (pl.team != COLOR_SPECTATOR)
3730 rgb = '1 1 0'; //not last but not among the leading players: yellow
3732 rgb = '1 0 0'; //last: red
3739 rgb = '0 1 0'; //first: green
3741 drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, 0.3 * panel_fg_alpha, DRAWFLAG_NORMAL);
3743 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
3744 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
3745 drawstring(pos + eX * mySize_x*0.79, ftos(pl.(scores[ps_primary])), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3750 // me vector := [team/connected frags id]
3751 pl = players.sort_next;
3755 if(autocvar__hud_configure)
3758 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3762 score = me.(scores[ps_primary]);
3763 if(autocvar__hud_configure)
3766 if(distribution >= 5)
3767 distribution_color = eY;
3768 else if(distribution >= 0)
3769 distribution_color = '1 1 1';
3770 else if(distribution >= -5)
3771 distribution_color = '1 1 0';
3773 distribution_color = eX;
3775 string distribution_str;
3776 distribution_str = ftos(distribution);
3777 if (distribution >= 0)
3779 if (distribution > 0)
3780 distribution_str = strcat("+", distribution_str);
3781 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3783 drawfont = hud_bigfont;
3784 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3785 drawfont = hud_font;
3786 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);
3787 } else { // teamgames
3788 float max_fragcount;
3789 max_fragcount = -99;
3791 float scores_count, row, column, rows, columns;
3793 vector score_pos, score_size; //for scores other than myteam
3794 if (spectatee_status == -1)
3796 if (autocvar__hud_configure)
3798 else for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3799 if(tm.team == COLOR_SPECTATOR)
3803 rows = mySize_y/mySize_x;
3804 rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
3805 // ^^^ ammo item aspect goes here
3807 columns = ceil(scores_count/rows);
3809 score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
3812 if(score_size_x/score_size_y > 3)
3814 newSize = 3 * score_size_y;
3815 offset_x = score_size_x - newSize;
3816 pos_x += offset_x/2;
3817 score_size_x = newSize;
3821 newSize = 1/3 * score_size_x;
3822 offset_y = score_size_y - newSize;
3823 pos_y += offset_y/2;
3824 score_size_y = newSize;
3828 score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
3829 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3830 if(tm.team == COLOR_SPECTATOR)
3832 score = tm.(teamscores[ts_primary]);
3833 if(autocvar__hud_configure)
3836 if (score > max_fragcount)
3837 max_fragcount = score;
3839 if (spectatee_status == -1)
3841 score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
3842 if (max_fragcount == score)
3843 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3844 drawfont = hud_bigfont;
3845 drawstring_aspect(score_pos, ftos(score), score_size, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3846 drawfont = hud_font;
3854 else if(tm.team == myteam) {
3855 if (max_fragcount == score)
3856 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3857 drawfont = hud_bigfont;
3858 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3859 drawfont = hud_font;
3861 if (max_fragcount == score)
3862 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);
3863 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);
3872 void HUD_RaceTimer (void) {
3873 if(!autocvar__hud_configure)
3875 if(!autocvar_hud_panel_racetimer) return;
3876 if(!(gametype == GAME_RACE || gametype == GAME_CTS)) return;
3877 if(spectatee_status == -1) return;
3880 active_panel = HUD_PANEL_RACETIMER;
3881 HUD_Panel_UpdateCvars(racetimer);
3884 mySize = panel_size;
3886 HUD_Panel_DrawBg(1);
3887 if(panel_bg_padding)
3889 pos += '1 1 0' * panel_bg_padding;
3890 mySize -= '2 2 0' * panel_bg_padding;
3893 // always force 4:1 aspect
3895 if(mySize_x/mySize_y > 4)
3897 newSize_x = 4 * mySize_y;
3898 newSize_y = mySize_y;
3900 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3904 newSize_y = 1/4 * mySize_x;
3905 newSize_x = mySize_x;
3907 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3911 drawfont = hud_bigfont;
3913 string s, forcetime;
3915 if(autocvar__hud_configure)
3918 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);
3919 s = "^1Intermediate 1 (+15.42)";
3920 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);
3921 s = strcat("^1PENALTY: ", ftos_decimals(20 * 0.1, 1), " (missing a checkpoint)");
3922 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);
3924 else if(race_checkpointtime)
3926 a = bound(0, 2 - (time - race_checkpointtime), 1);
3929 if(a > 0) // just hit a checkpoint?
3931 if(race_checkpoint != 254)
3933 if(race_time && race_previousbesttime)
3934 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
3936 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
3938 forcetime = TIME_ENCODED_TOSTRING(race_time);
3943 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
3945 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
3946 if(a > 0) // next one?
3948 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
3953 if(s != "" && a > 0)
3955 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);
3958 if(race_penaltytime)
3960 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
3963 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
3964 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);
3970 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
3971 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);
3976 if(race_laptime && race_checkpoint != 255)
3978 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
3979 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);
3984 if(race_mycheckpointtime)
3986 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
3987 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
3988 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);
3990 if(race_othercheckpointtime && race_othercheckpointenemy != "")
3992 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
3993 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
3994 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);
3997 if(race_penaltytime && !race_penaltyaccumulator)
3999 t = race_penaltytime * 0.1 + race_penaltyeventtime;
4000 a = bound(0, (1 + t - time), 1);
4004 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
4006 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
4007 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);
4012 drawfont = hud_font;
4017 float vote_yescount;
4020 float vote_highlighted; // currently selected vote
4022 float vote_active; // is there an active vote?
4023 float vote_prev; // previous state of vote_active to check for a change
4025 float vote_change; // "time" when vote_active changed
4027 void HUD_VoteWindow(void)
4029 if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
4032 if (autocvar__hud_configure)
4036 print("^1You have to answer before entering hud configure mode\n");
4037 cvar_set("_hud_configure", "0");
4039 vote_called_vote = strzone("^2Name ^7instead of \"^1Unregistered player^7\" in stats");
4040 uid2name_dialog = 1;
4043 if(!autocvar_hud_panel_vote && !autocvar__hud_configure)
4046 if(!autocvar__hud_configure)
4048 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
4049 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
4051 if(panel_bg_alpha_str == "") {
4052 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
4054 panel_bg_alpha = stof(panel_bg_alpha_str);
4059 if(vote_active != vote_prev) {
4061 vote_prev = vote_active;
4064 if(vote_active || autocvar__hud_configure)
4065 vote_alpha = bound(0, (time - vote_change) * 2, 1);
4067 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
4069 if(autocvar__hud_configure)
4079 active_panel = HUD_PANEL_VOTE;
4080 HUD_Panel_UpdateCvars(vote);
4084 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
4085 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
4088 // these must be below above block
4091 mySize = panel_size;
4093 a = vote_alpha * bound(autocvar_hud_panel_vote_alreadyvoted_alpha, 1 - vote_highlighted, 1);
4094 HUD_Panel_DrawBg(a);
4095 a = panel_fg_alpha * a;
4097 if(panel_bg_padding)
4099 pos += '1 1 0' * panel_bg_padding;
4100 mySize -= '2 2 0' * panel_bg_padding;
4103 // always force 3:1 aspect
4105 if(mySize_x/mySize_y > 3)
4107 newSize_x = 3 * mySize_y;
4108 newSize_y = mySize_y;
4110 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4114 newSize_y = 1/3 * mySize_x;
4115 newSize_x = mySize_x;
4117 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4121 s = "A vote has been called for:";
4123 s = "Allow servers to store and display your name?";
4124 drawstring_aspect(pos, s, eX * mySize_x + eY * (2/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4125 s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (1/8), stringwidth_colors);
4126 if(autocvar__hud_configure)
4127 s = "^1Configure the HUD";
4128 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a, DRAWFLAG_NORMAL);
4130 // print the yes/no counts
4131 s = strcat("Yes (", getcommandkey("vyes", "vyes"), "): ", ftos(vote_yescount));
4132 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);
4133 s = strcat("No (", getcommandkey("vno", "vno"), "): ", ftos(vote_nocount));
4134 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);
4136 // draw the progress bar backgrounds
4137 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_back", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4139 // draw the highlights
4140 if(vote_highlighted == 1) {
4141 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
4142 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4144 else if(vote_highlighted == 2) {
4145 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
4146 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4149 // draw the progress bars
4150 if(vote_yescount && vote_needed)
4152 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
4153 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4156 if(vote_nocount && vote_needed)
4158 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
4159 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4162 drawresetcliparea();
4165 vote_highlighted = 0;
4169 // Mod icons panel (#10)
4172 float mod_active; // is there any active mod icon?
4174 // Clan Arena HUD modicons
4175 void HUD_Mod_CA(vector pos, vector mySize)
4177 mod_active = 1; // CA should never hide the mod icons panel
4178 float redalive, bluealive;
4179 redalive = getstati(STAT_REDALIVE);
4180 bluealive = getstati(STAT_BLUEALIVE);
4182 drawfont = hud_bigfont;
4183 vector redpos, bluepos;
4184 if(mySize_x > mySize_y)
4187 bluepos = pos + eY * 0.5 * mySize_y;
4188 drawpic_aspect_skin(redpos, "player_red.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4189 drawstring_aspect(redpos + eX * 0.5 * mySize_x, ftos(redalive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4190 drawpic_aspect_skin(bluepos, "player_blue.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4191 drawstring_aspect(bluepos + eX * 0.5 * mySize_x, ftos(bluealive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4196 bluepos = pos + eY * 0.5 * mySize_y;
4197 drawpic_aspect_skin(redpos, "player_red.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4198 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);
4199 drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4200 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);
4202 drawfont = hud_font;
4205 // CTF HUD modicon section
4206 float redflag_prevframe, blueflag_prevframe; // status during previous frame
4207 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
4208 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
4210 void HUD_Mod_CTF_Reset(void)
4212 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
4215 void HUD_Mod_CTF(vector pos, vector mySize)
4217 vector redflag_pos, blueflag_pos;
4219 float f; // every function should have that
4221 float redflag, blueflag; // current status
4222 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
4225 stat_items = getstati(STAT_ITEMS);
4226 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
4227 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
4229 if(redflag || blueflag)
4234 if(autocvar__hud_configure)
4240 // when status CHANGES, set old status into prevstatus and current status into status
4241 if (redflag != redflag_prevframe)
4243 redflag_statuschange_time = time;
4244 redflag_prevstatus = redflag_prevframe;
4245 redflag_prevframe = redflag;
4248 if (blueflag != blueflag_prevframe)
4250 blueflag_statuschange_time = time;
4251 blueflag_prevstatus = blueflag_prevframe;
4252 blueflag_prevframe = blueflag;
4255 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
4256 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
4258 float BLINK_FACTOR = 0.15;
4259 float BLINK_BASE = 0.85;
4261 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
4263 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
4265 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
4267 string red_icon, red_icon_prevstatus;
4268 float red_alpha, red_alpha_prevstatus;
4269 red_alpha = red_alpha_prevstatus = 1;
4271 case 1: red_icon = "flag_red_taken"; break;
4272 case 2: red_icon = "flag_red_lost"; break;
4273 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4275 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
4276 red_icon = "flag_red_shielded";
4278 red_icon = string_null;
4281 switch(redflag_prevstatus) {
4282 case 1: red_icon_prevstatus = "flag_red_taken"; break;
4283 case 2: red_icon_prevstatus = "flag_red_lost"; break;
4284 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4287 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
4288 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
4289 red_icon_prevstatus = "flag_red_shielded";
4291 red_icon_prevstatus = string_null;
4295 string blue_icon, blue_icon_prevstatus;
4296 float blue_alpha, blue_alpha_prevstatus;
4297 blue_alpha = blue_alpha_prevstatus = 1;
4299 case 1: blue_icon = "flag_blue_taken"; break;
4300 case 2: blue_icon = "flag_blue_lost"; break;
4301 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4303 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
4304 blue_icon = "flag_blue_shielded";
4306 blue_icon = string_null;
4309 switch(blueflag_prevstatus) {
4310 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
4311 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
4312 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4315 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
4316 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
4317 blue_icon_prevstatus = "flag_blue_shielded";
4319 blue_icon_prevstatus = string_null;
4323 if(mySize_x > mySize_y) {
4324 if (myteam == COLOR_TEAM1) { // always draw own flag on left
4326 blueflag_pos = pos + eX * 0.5 * mySize_x;
4329 redflag_pos = pos + eX * 0.5 * mySize_x;
4331 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
4333 if (myteam == COLOR_TEAM1) { // always draw own flag on left
4335 blueflag_pos = pos + eY * 0.5 * mySize_y;
4338 redflag_pos = pos + eY * 0.5 * mySize_y;
4340 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
4343 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
4344 if(red_icon_prevstatus && f < 1)
4345 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
4347 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
4349 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
4350 if(blue_icon_prevstatus && f < 1)
4351 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
4353 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
4356 // Keyhunt HUD modicon section
4357 float kh_runheretime;
4359 void HUD_Mod_KH_Reset(void)
4364 void HUD_Mod_KH(vector pos, vector mySize)
4366 mod_active = 1; // keyhunt should never hide the mod icons panel
4370 vector p, pa, kh_size, kh_asize;
4372 kh_keys = getstati(STAT_KH_KEYS);
4375 if(mySize_x > mySize_y)
4377 p_y = pos_y + 0.25 * mySize_y;
4378 pa = p - eY * 0.25 * mySize_y;
4380 kh_size_x = mySize_x * 0.25;
4381 kh_size_y = 0.75 * mySize_y;
4382 kh_asize_x = mySize_x * 0.25;
4383 kh_asize_y = mySize_y * 0.25;
4387 p_y = pos_y + 0.125 * mySize_y;
4388 pa = p - eY * 0.125 * mySize_y;
4390 kh_size_x = mySize_x * 0.5;
4391 kh_size_y = 0.375 * mySize_y;
4392 kh_asize_x = mySize_x * 0.5;
4393 kh_asize_y = mySize_y * 0.125;
4400 for(i = 0; i < 4; ++i)
4402 key = floor(kh_keys / pow(32, i)) & 31;
4404 if(keyteam == 30 && keycount <= 4)
4406 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
4410 // this yields 8 exactly if "RUN HERE" shows
4415 kh_runheretime = time;
4416 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
4421 for(i = 0; i < 4; ++i)
4423 key = floor(kh_keys / pow(32, i)) & 31;
4436 default: // owned or dropped
4441 a = a * panel_fg_alpha;
4442 aa = aa * panel_fg_alpha;
4448 drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4451 drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4454 drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4457 drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4462 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
4465 drawpic_aspect_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4468 drawpic_aspect_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4471 drawpic_aspect_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4474 drawpic_aspect_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4478 if(mySize_x > mySize_y)
4480 p_x += 0.25 * mySize_x;
4481 pa_x += 0.25 * mySize_x;
4487 p_y = pos_y + 0.625 * mySize_y;
4488 pa_y = pos_y + 0.5 * mySize_y;
4494 p_x += 0.5 * mySize_x;
4495 pa_x += 0.5 * mySize_x;
4501 // Keepaway HUD mod icon
4502 float kaball_prevstatus; // last remembered status
4503 float kaball_statuschange_time; // time when the status changed
4505 // we don't need to reset for keepaway since it immediately
4506 // autocorrects prevstatus as to if the player has the ball or not
4508 void HUD_Mod_Keepaway(vector pos, vector mySize)
4510 mod_active = 1; // keepaway should always show the mod HUD
4512 float BLINK_FACTOR = 0.15;
4513 float BLINK_BASE = 0.85;
4514 float BLINK_FREQ = 5;
4515 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
4517 float stat_items = getstati(STAT_ITEMS);
4518 float kaball = (stat_items/IT_KEY1) & 1;
4520 if(kaball != kaball_prevstatus)
4522 kaball_statuschange_time = time;
4523 kaball_prevstatus = kaball;
4526 // todo: Fix the sizing with the expanding image
4528 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
4529 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
4531 if(kaball_prevstatus && f < 1)
4532 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);
4535 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
4539 // Nexball HUD mod icon
4540 void HUD_Mod_NexBall(vector pos, vector mySize)
4542 float stat_items, nb_pb_starttime, dt, p;
4544 stat_items = getstati(STAT_ITEMS);
4545 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
4547 if (stat_items & IT_KEY1)
4552 //Manage the progress bar if any
4553 if (nb_pb_starttime > 0)
4555 dt = mod(time - nb_pb_starttime, nb_pb_period);
4556 // one period of positive triangle
4557 p = 2 * dt / nb_pb_period;
4562 HUD_Panel_GetProgressBarColor(nexball);
4563 if(mySize_x > mySize_y)
4564 HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", p, 0, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4566 HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", p, 1, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4569 if (stat_items & IT_KEY1)
4570 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4573 // Race/CTS HUD mod icons
4574 float crecordtime_prev; // last remembered crecordtime
4575 float crecordtime_change_time; // time when crecordtime last changed
4576 float srecordtime_prev; // last remembered srecordtime
4577 float srecordtime_change_time; // time when srecordtime last changed
4579 float race_status_time;
4580 float race_status_prev;
4581 string race_status_name_prev;
4582 void HUD_Mod_Race(vector pos, vector mySize)
4584 mod_active = 1; // race should never hide the mod icons panel
4586 me = playerslots[player_localentnum - 1];
4588 float f; // yet another function has this
4589 score = me.(scores[ps_primary]);
4591 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
4592 return; // no records in the actual race
4594 drawfont = hud_bigfont;
4596 // clientside personal record
4598 if(gametype == GAME_CTS)
4602 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
4604 if(score && (score < t || !t)) {
4605 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
4606 if(autocvar_cl_autodemo_delete_keeprecords)
4608 f = autocvar_cl_autodemo_delete;
4610 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
4614 if(t != crecordtime_prev) {
4615 crecordtime_prev = t;
4616 crecordtime_change_time = time;
4619 vector textPos, medalPos;
4621 if(mySize_x > mySize_y) {
4622 // text on left side
4623 squareSize = min(mySize_y, mySize_x/2);
4624 textPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eY * 0.5 * (mySize_y - squareSize);
4625 medalPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eX * 0.5 * mySize_x + eY * 0.5 * (mySize_y - squareSize);
4628 squareSize = min(mySize_x, mySize_y/2);
4629 textPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eX * 0.5 * (mySize_x - squareSize);
4630 medalPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eY * 0.5 * mySize_y + eX * 0.5 * (mySize_x - squareSize);
4633 f = time - crecordtime_change_time;
4636 drawstring_aspect(textPos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4637 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);
4639 drawstring_aspect(textPos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4640 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);
4641 drawstring_aspect_expanding(pos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
4642 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);
4646 t = race_server_record;
4647 if(t != srecordtime_prev) {
4648 srecordtime_prev = t;
4649 srecordtime_change_time = time;
4651 f = time - srecordtime_change_time;
4654 drawstring_aspect(textPos + eY * 0.5 * squareSize, "Server best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4655 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);
4657 drawstring_aspect(textPos + eY * 0.5 * squareSize, "Server best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4658 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);
4659 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);
4660 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);
4663 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
4664 race_status_time = time + 5;
4665 race_status_prev = race_status;
4666 if (race_status_name_prev)
4667 strunzone(race_status_name_prev);
4668 race_status_name_prev = strzone(race_status_name);
4673 a = bound(0, race_status_time - time, 1);
4676 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
4680 rank = race_CheckName(race_status_name);
4682 rankname = race_PlaceName(rank);
4685 namepos = medalPos + '0 0.8 0' * squareSize;
4687 rankpos = medalPos + '0 0.15 0' * squareSize;
4689 if(race_status == 0)
4690 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4691 else if(race_status == 1) {
4692 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);
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);
4695 } else if(race_status == 2) {
4696 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
4697 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);
4699 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);
4700 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4701 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4702 } else if(race_status == 3) {
4703 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);
4704 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4705 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4708 if (race_status_time - time <= 0) {
4709 race_status_prev = -1;
4711 if(race_status_name)
4712 strunzone(race_status_name);
4713 race_status_name = string_null;
4714 if(race_status_name_prev)
4715 strunzone(race_status_name_prev);
4716 race_status_name_prev = string_null;
4718 drawfont = hud_font;
4721 float mod_prev; // previous state of mod_active to check for a change
4723 float mod_change; // "time" when mod_active changed
4725 void HUD_ModIcons(void)
4727 if(!autocvar_hud_panel_modicons && !autocvar__hud_configure)
4730 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)
4733 active_panel = HUD_PANEL_MODICONS;
4734 HUD_Panel_UpdateCvars(modicons);
4737 mySize = panel_size;
4739 if(mod_active != mod_prev) {
4741 mod_prev = mod_active;
4744 if(mod_active || autocvar__hud_configure)
4745 mod_alpha = bound(0, (time - mod_change) * 2, 1);
4747 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
4750 HUD_Panel_DrawBg(mod_alpha);
4752 if(panel_bg_padding)
4754 pos += '1 1 0' * panel_bg_padding;
4755 mySize -= '2 2 0' * panel_bg_padding;
4758 // these MUST be ran in order to update mod_active
4759 if(gametype == GAME_KEYHUNT)
4760 HUD_Mod_KH(pos, mySize);
4761 else if(gametype == GAME_CTF || autocvar__hud_configure)
4762 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
4763 else if(gametype == GAME_NEXBALL)
4764 HUD_Mod_NexBall(pos, mySize);
4765 else if(gametype == GAME_CTS || gametype == GAME_RACE)
4766 HUD_Mod_Race(pos, mySize);
4767 else if(gametype == GAME_CA || gametype == GAME_FREEZETAG)
4768 HUD_Mod_CA(pos, mySize);
4769 else if(gametype == GAME_KEEPAWAY)
4770 HUD_Mod_Keepaway(pos, mySize);
4773 // Draw pressed keys (#11)
4775 void HUD_DrawPressedKeys(void)
4777 if(!autocvar_hud_panel_pressedkeys && !autocvar__hud_configure)
4780 if(!(spectatee_status > 0 || autocvar_hud_panel_pressedkeys >= 2 || autocvar__hud_configure))
4783 active_panel = HUD_PANEL_PRESSEDKEYS;
4784 HUD_Panel_UpdateCvars(pressedkeys);
4787 mySize = panel_size;
4789 HUD_Panel_DrawBg(1);
4790 if(panel_bg_padding)
4792 pos += '1 1 0' * panel_bg_padding;
4793 mySize -= '2 2 0' * panel_bg_padding;
4796 // force custom aspect
4797 float aspect = autocvar_hud_panel_pressedkeys_aspect;
4801 if(mySize_x/mySize_y > aspect)
4803 newSize_x = aspect * mySize_y;
4804 newSize_y = mySize_y;
4806 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4810 newSize_y = 1/aspect * mySize_x;
4811 newSize_x = mySize_x;
4813 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4819 keysize = eX * mySize_x * (1/3) + eY * mySize_y * 0.5;
4821 pressedkeys = getstatf(STAT_PRESSED_KEYS);
4823 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4824 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);
4825 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);
4827 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4828 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);
4829 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);
4832 // Handle chat as a panel (#12)
4836 if(!autocvar_hud_panel_chat && !autocvar__hud_configure)
4838 cvar_set("con_chatrect", "0");
4842 active_panel = HUD_PANEL_CHAT;
4843 HUD_Panel_UpdateCvars(chat);
4845 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
4847 panel_pos_y = panel_bg_border;
4848 panel_size_y = vid_conheight - panel_bg_border * 2;
4849 if(panel_bg == "0") // force a border when maximized
4851 if(precache_pic(panel_bg) == "") {
4852 panel_bg = strcat(hud_skin_path, "/border_default");
4853 if(precache_pic(panel_bg) == "") {
4854 panel_bg = "gfx/hud/default/border_default";
4858 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an alpha of at least 0.75
4863 mySize = panel_size;
4865 HUD_Panel_DrawBg(1);
4867 if(panel_bg_padding)
4869 pos += '1 1 0' * panel_bg_padding;
4870 mySize -= '2 2 0' * panel_bg_padding;
4873 cvar_set("con_chatrect", "1");
4875 cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
4876 cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
4878 cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
4879 cvar_set("con_chat", ftos(floor(mySize_y/autocvar_con_chatsize - 0.5)));
4881 if(autocvar__hud_configure)
4884 chatsize = autocvar_con_chatsize;
4885 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
4887 for(i = 0; i < autocvar_con_chat; ++i)
4889 if(i == autocvar_con_chat - 1)
4892 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
4893 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);
4898 // Engine info panel (#13)
4905 float frametimeavg1; // 1 frame ago
4906 float frametimeavg2; // 2 frames ago
4907 void HUD_EngineInfo(void)
4909 if(!autocvar_hud_panel_engineinfo && !autocvar__hud_configure)
4912 active_panel = HUD_PANEL_ENGINEINFO;
4913 HUD_Panel_UpdateCvars(engineinfo);
4916 mySize = panel_size;
4918 HUD_Panel_DrawBg(1);
4919 if(panel_bg_padding)
4921 pos += '1 1 0' * panel_bg_padding;
4922 mySize -= '2 2 0' * panel_bg_padding;
4925 float currentTime = gettime(GETTIME_REALTIME);
4926 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
4928 float currentframetime = currentTime - prevfps_time;
4929 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
4930 frametimeavg2 = frametimeavg1;
4931 frametimeavg1 = frametimeavg;
4934 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
4935 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.
4937 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
4938 prevfps = (1/currentframetime);
4939 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"
4941 prevfps_time = currentTime;
4946 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
4948 prevfps = framecounter/(currentTime - prevfps_time);
4950 prevfps_time = currentTime;
4955 color = HUD_Get_Num_Color (prevfps, 100);
4956 drawfont = hud_bigfont;
4957 drawstring_aspect(pos, strcat("FPS: ", ftos_decimals(prevfps, autocvar_hud_panel_engineinfo_framecounter_decimals)), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
4958 drawfont = hud_font;
4961 // Info messages panel (#14)
4963 #define drawInfoMessage(s)\
4964 if(autocvar_hud_panel_infomessages_flip)\
4965 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);\
4966 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);\
4968 void HUD_InfoMessages(void)
4970 if(!autocvar_hud_panel_infomessages && !autocvar__hud_configure)
4973 active_panel = HUD_PANEL_INFOMESSAGES;
4974 HUD_Panel_UpdateCvars(infomessages);
4977 mySize = panel_size;
4979 HUD_Panel_DrawBg(1);
4980 if(panel_bg_padding)
4982 pos += '1 1 0' * panel_bg_padding;
4983 mySize -= '2 2 0' * panel_bg_padding;
4986 // always force 5:1 aspect
4988 if(mySize_x/mySize_y > 5)
4990 newSize_x = 5 * mySize_y;
4991 newSize_y = mySize_y;
4993 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4997 newSize_y = 1/5 * mySize_x;
4998 newSize_x = mySize_x;
5000 pos_y = pos_y + (mySize_y - newSize_y) / 2;
5009 fontsize = '0.20 0.20 0' * mySize_y;
5012 if(spectatee_status != 0)
5018 if(!autocvar__hud_configure)
5020 if(spectatee_status && !intermission)
5022 if(spectatee_status == -1)
5025 s = strcat("^1Spectating: ^7", GetPlayerName(spectatee_status - 1));
5028 if(spectatee_status == -1)
5029 s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 to spectate");
5031 s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 for another player");
5034 if(spectatee_status == -1)
5035 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
5037 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+fire2"), "^1 to observe");
5040 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
5043 if(gametype == GAME_ARENA)
5044 s = "^1Wait for your turn to join";
5045 else if(gametype == GAME_LMS)
5048 sk = playerslots[player_localentnum - 1];
5049 if(sk.(scores[ps_primary]) >= 666)
5050 s = "^1Match has already begun";
5051 else if(sk.(scores[ps_primary]) > 0)
5052 s = "^1You have no more lives left";
5054 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
5057 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
5060 //show restart countdown:
5061 if (time < getstatf(STAT_GAMESTARTTIME)) {
5063 //we need to ceil, otherwise the countdown would be off by .5 when using round()
5064 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
5065 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
5066 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
5070 if(warmup_stage && !intermission)
5072 s = "^2Currently in ^1warmup^2 stage!";
5077 if(mod(time, 1) >= 0.5)
5082 if(ready_waiting && !intermission && !spectatee_status)
5084 if(ready_waiting_for_me)
5087 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
5089 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
5094 s = strcat("^2Waiting for others to ready up to end warmup...");
5096 s = strcat("^2Waiting for others to ready up...");
5100 else if(warmup_stage && !intermission && !spectatee_status)
5102 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
5106 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
5108 float ts_min, ts_max;
5109 tm = teams.sort_next;
5112 for(; tm.sort_next; tm = tm.sort_next)
5114 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
5116 if(!ts_min) ts_min = tm.team_size;
5117 else ts_min = min(ts_min, tm.team_size);
5118 if(!ts_max) ts_max = tm.team_size;
5119 else ts_max = max(ts_max, tm.team_size);
5121 if ((ts_max - ts_min) > 1)
5123 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
5124 tm = GetTeam(myteam, false);
5126 if (tm.team != COLOR_SPECTATOR)
5127 if (tm.team_size == ts_max)
5128 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
5136 s = "^7Press ^3ESC ^7to show HUD options.";
5138 s = "^3Doubleclick ^7a panel for panel-specific options.";
5140 s = "^3CTRL ^7to disable collision testing, ^3SHIFT ^7and";
5142 s = "^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.";
5147 // Physics panel (#15)
5149 vector acc_prevspeed;
5150 float acc_prevtime, acc_avg, top_speed, top_speed_time;
5152 void HUD_Physics(void)
5154 if(!autocvar_hud_panel_physics && !autocvar__hud_configure)
5157 active_panel = HUD_PANEL_PHYSICS;
5158 HUD_Panel_UpdateCvars(physics);
5160 HUD_Panel_DrawBg(1);
5161 if(panel_bg_padding)
5163 panel_pos += '1 1 0' * panel_bg_padding;
5164 panel_size -= '2 2 0' * panel_bg_padding;
5168 float speed, conversion_factor;
5171 switch(autocvar_cl_showspeed_unit)
5176 conversion_factor = 1.0;
5180 conversion_factor = 0.0254;
5184 conversion_factor = 0.0254 * 3.6;
5188 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
5192 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
5196 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
5197 if (autocvar__hud_configure)
5198 speed = floor( max_speed * 0.65 + 0.5 );
5199 else if(autocvar_hud_panel_physics_speed_z)
5200 speed = floor( vlen(pmove_vel) * conversion_factor + 0.5 );
5202 speed = floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 );
5204 //compute acceleration
5205 float acceleration, f;
5206 if (autocvar__hud_configure)
5207 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
5210 f = time - acc_prevtime;
5211 if(autocvar_hud_panel_physics_acceleration_z)
5212 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
5214 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
5215 acc_prevspeed = pmove_vel;
5216 acc_prevtime = time;
5218 f = bound(0, f * 10, 1);
5219 acc_avg = acc_avg * (1 - f) + acceleration * f;
5220 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
5224 drawfont = hud_bigfont;
5225 float panel_ar = panel_size_x/panel_size_y;
5226 vector speed_offset, acceleration_offset;
5229 panel_size_x *= 0.5;
5230 if (autocvar_hud_panel_physics_flip)
5231 speed_offset_x = panel_size_x;
5233 acceleration_offset_x = panel_size_x;
5237 panel_size_y *= 0.5;
5238 if (autocvar_hud_panel_physics_flip)
5239 speed_offset_y = panel_size_y;
5241 acceleration_offset_y = panel_size_y;
5243 float speed_baralign, acceleration_baralign;
5244 if (autocvar_hud_panel_physics_baralign == 1)
5245 acceleration_baralign = speed_baralign = 1;
5246 else if (autocvar_hud_panel_physics_flip)
5248 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
5249 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
5253 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
5254 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
5258 if(speed && autocvar_hud_panel_physics_progressbar)
5260 HUD_Panel_GetProgressBarColor(speed);
5261 HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
5264 vector tmp_offset, tmp_size;
5265 tmp_size_x = panel_size_x * 0.75;
5266 tmp_size_y = panel_size_y;
5268 tmp_offset_x = panel_size_x - tmp_size_x;
5271 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
5277 tmp_offset_x = tmp_size_x;
5278 if (autocvar_hud_panel_physics_speed_unit_show)
5281 tmp_size_x = panel_size_x * (1 - 0.75);
5282 tmp_size_y = panel_size_y * 0.4;
5283 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
5286 //compute and draw top speed
5287 if (autocvar_hud_panel_physics_topspeed)
5289 if (autocvar__hud_configure)
5291 top_speed = floor( max_speed * 0.75 + 0.5 );
5296 if (speed >= top_speed)
5299 top_speed_time = time;
5301 if (top_speed == 0) //hide top speed 0, it would be stupid
5305 f = max(1, autocvar_hud_panel_physics_topspeed_time);
5306 // divide by f to make it start from 1
5307 f = cos( ((time - top_speed_time) / f) * PI/2 );
5312 //top speed progressbar peek
5313 if(autocvar_hud_panel_physics_progressbar && speed < top_speed)
5315 float peek_offset_x, peek_size_x;
5317 peek_offset_x = (1 - min(top_speed, max_speed)/max_speed) * panel_size_x;
5319 peek_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x;
5320 //if speed is not 0 the speed progressbar already fetched the color
5322 HUD_Panel_GetProgressBarColor(speed);
5323 peek_size_x = panel_size_x * 0.01;
5324 drawfill(panel_pos + speed_offset + eX * (peek_offset_x - peek_size_x), eX * peek_size_x + eY * panel_size_y, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
5328 tmp_offset_y = panel_size_y * 0.4;
5329 tmp_size_x = panel_size_x * (1 - 0.75);
5330 tmp_size_y = panel_size_y - tmp_offset_y;
5331 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
5338 if(acceleration && autocvar_hud_panel_physics_progressbar)
5340 if (acceleration < 0)
5341 HUD_Panel_GetProgressBarColor(acceleration_neg);
5343 HUD_Panel_GetProgressBarColor(acceleration);
5344 HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset, panel_size, "progressbar", fabs(acceleration)/autocvar_hud_panel_physics_acceleration_max, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
5346 drawstring_aspect(panel_pos + acceleration_offset, ftos_decimals(acceleration, 3), panel_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
5347 drawfont = hud_font;
5356 void HUD_Reset (void)
5358 // reset gametype specific icons
5359 if(gametype == GAME_KEYHUNT)
5361 else if(gametype == GAME_CTF)
5362 HUD_Mod_CTF_Reset();
5365 #define HUD_DrawPanel(id)\
5367 case (HUD_PANEL_RADAR):\
5368 HUD_Radar(); break;\
5369 case (HUD_PANEL_WEAPONS):\
5370 HUD_Weapons(); break;\
5371 case (HUD_PANEL_AMMO):\
5373 case (HUD_PANEL_POWERUPS):\
5374 HUD_Powerups(); break;\
5375 case (HUD_PANEL_HEALTHARMOR):\
5376 HUD_HealthArmor(); break;\
5377 case (HUD_PANEL_NOTIFY):\
5378 HUD_Notify(); break;\
5379 case (HUD_PANEL_TIMER):\
5380 HUD_Timer(); break;\
5381 case (HUD_PANEL_SCORE):\
5382 HUD_Score(); break;\
5383 case (HUD_PANEL_RACETIMER):\
5384 HUD_RaceTimer(); break;\
5385 case (HUD_PANEL_VOTE):\
5386 HUD_VoteWindow(); break;\
5387 case (HUD_PANEL_MODICONS):\
5388 HUD_ModIcons(); break;\
5389 case (HUD_PANEL_PRESSEDKEYS):\
5390 HUD_DrawPressedKeys(); break;\
5391 case (HUD_PANEL_CHAT):\
5393 case (HUD_PANEL_ENGINEINFO):\
5394 HUD_EngineInfo(); break;\
5395 case (HUD_PANEL_INFOMESSAGES):\
5396 HUD_InfoMessages(); break;\
5397 case (HUD_PANEL_PHYSICS):\
5398 HUD_Physics(); break;\
5399 } ENDS_WITH_CURLY_BRACE
5401 void HUD_Main (void)
5404 // global hud alpha fade
5405 if(menu_enabled == 1)
5408 hud_fade_alpha = (1 - autocvar__menu_alpha);
5410 if(scoreboard_fade_alpha)
5411 hud_fade_alpha = (1 - scoreboard_fade_alpha);
5413 if(intermission == 2) // no hud during mapvote
5415 else if(autocvar__menu_alpha == 0 && scoreboard_fade_alpha == 0)
5418 if(!autocvar__hud_configure && !hud_fade_alpha)
5422 if (hud_skin_path != autocvar_hud_skin)
5425 strunzone(hud_skin_path);
5426 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
5429 // HUD configure visible grid
5430 float hud_configure_grid_alpha;
5431 if(autocvar__hud_configure && cvar("hud_configure_grid") && (hud_configure_grid_alpha = cvar("hud_configure_grid_alpha")))
5433 hud_configure_gridSize_x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
5434 hud_configure_gridSize_y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
5435 hud_configure_realGridSize_x = hud_configure_gridSize_x * vid_conwidth;
5436 hud_configure_realGridSize_y = hud_configure_gridSize_y * vid_conheight;
5438 for(i = 0; i < 1/hud_configure_gridSize_x; ++i)
5439 drawfill(eX * i * hud_configure_realGridSize_x, eX + eY * vid_conheight, '0.5 0.5 0.5', hud_configure_grid_alpha, DRAWFLAG_NORMAL);
5441 for(i = 0; i < 1/hud_configure_gridSize_y; ++i)
5442 drawfill(eY * i * hud_configure_realGridSize_y, eY + eX * vid_conwidth, '0.5 0.5 0.5', hud_configure_grid_alpha, DRAWFLAG_NORMAL);
5446 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
5450 float hud_dock_color_team = autocvar_hud_dock_color_team;
5451 if((teamplay) && hud_dock_color_team) {
5452 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5453 color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
5455 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
5456 color = '1 0 0' * hud_dock_color_team;
5460 string hud_dock_color = autocvar_hud_dock_color;
5461 if(hud_dock_color == "shirt") {
5462 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5463 color = colormapPaletteColor(floor(f / 16), 0);
5465 else if(hud_dock_color == "pants") {
5466 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5467 color = colormapPaletteColor(mod(f, 16), 1);
5470 color = stov(hud_dock_color);
5474 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
5475 if(precache_pic(pic) == "") {
5476 pic = strcat(hud_skin_path, "/dock_medium");
5477 if(precache_pic(pic) == "") {
5478 pic = "gfx/hud/default/dock_medium";
5481 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...
5484 // cache the panel order into the panel_order array
5485 if(autocvar__hud_panelorder != hud_panelorder_prev) {
5486 for(i = 0; i < HUD_PANEL_NUM; ++i)
5487 panel_order[i] = -1;
5489 float p_num, warning;
5490 float argc = tokenize_console(autocvar__hud_panelorder);
5491 if (argc > HUD_PANEL_NUM)
5493 //first detect wrong/missing panel numbers
5494 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5495 p_num = stof(argv(i));
5496 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
5497 if (panel_order[p_num] == -1) //found for the first time?
5498 s = strcat(s, ftos(p_num), " ");
5499 panel_order[p_num] = 1; //mark as found
5504 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5505 if (panel_order[i] == -1) {
5507 s = strcat(s, ftos(i), " "); //add missing panel number
5511 print("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
5513 cvar_set("_hud_panelorder", s);
5514 if(hud_panelorder_prev)
5515 strunzone(hud_panelorder_prev);
5516 hud_panelorder_prev = strzone(s);
5518 //now properly set panel_order
5519 tokenize_console(s);
5520 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5521 panel_order[i] = stof(argv(i));
5524 // draw panels in order specified by panel_order array
5525 for(i = HUD_PANEL_NUM - 1; i >= 0; --i) {
5526 if(i != HUD_PANEL_CHAT || !autocvar__con_chat_maximized) // don't draw maximized chat panel twice!
5527 HUD_DrawPanel(panel_order[i]);
5530 // draw chat panel on top if it is maximized
5531 if(autocvar__con_chat_maximized)
5532 HUD_Chat(); // HUD_DrawPanel(HUD_PANEL_CHAT);
5534 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)
5535 localcmd("cmd selectteam auto; cmd join\n");
5537 if(autocvar__hud_configure && tab_panel != -1)
5539 HUD_Panel_UpdatePosSizeForId(tab_panel)
5540 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
5543 hud_configure_prev = autocvar__hud_configure;
5545 if (!autocvar__hud_configure) // hud config mode disabled, enable normal alpha stuff again