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("_progressbar_xoffset");
502 HUD_Write_PanelCvar_q("_text");
504 case HUD_PANEL_POWERUPS:
505 HUD_Write_PanelCvar_q("_flip");
506 HUD_Write_PanelCvar_q("_iconalign");
507 HUD_Write_PanelCvar_q("_baralign");
508 HUD_Write_PanelCvar_q("_progressbar");
509 HUD_Write_PanelCvar_q("_progressbar_strength");
510 HUD_Write_PanelCvar_q("_progressbar_shield");
512 case HUD_PANEL_HEALTHARMOR:
513 HUD_Write_PanelCvar_q("_flip");
514 HUD_Write_PanelCvar_q("_iconalign");
515 HUD_Write_PanelCvar_q("_baralign");
516 HUD_Write_PanelCvar_q("_progressbar");
517 HUD_Write_PanelCvar_q("_progressbar_health");
518 HUD_Write_PanelCvar_q("_progressbar_armor");
519 HUD_Write_PanelCvar_q("_text");
521 case HUD_PANEL_NOTIFY:
522 HUD_Write_PanelCvar_q("_flip");
523 HUD_Write_PanelCvar_q("_print");
525 case HUD_PANEL_RADAR:
526 HUD_Write_PanelCvar_q("_foreground_alpha");
529 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
531 case HUD_PANEL_PRESSEDKEYS:
532 HUD_Write_PanelCvar_q("_aspect");
534 case HUD_PANEL_INFOMESSAGES:
535 HUD_Write_PanelCvar_q("_flip");
537 case HUD_PANEL_PHYSICS:
538 HUD_Write_PanelCvar_q("_flip");
539 HUD_Write_PanelCvar_q("_baralign");
540 HUD_Write_PanelCvar_q("_progressbar");
545 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
547 print("^2Successfully exported to ", filename, "! (Note: It's saved in data/data/)\n");
551 print("^1Couldn't write to ", filename, "\n");
554 const float hlBorderSize = 4;
555 const string hlBorder = "gfx/hud/default/border_highlighted";
556 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
557 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
559 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
560 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);
561 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);
562 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);
563 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);
566 // draw the background/borders
567 #define HUD_Panel_DrawBg(alpha)\
569 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));\
570 if(highlightedPanel == hud_configure_active_panel && autocvar__hud_configure)\
572 HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha) * alpha);\
573 } ENDS_WITH_CURLY_BRACE
575 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
576 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float lenght_ratio, float vertical, float right_align, vector theColor, float theAlpha, float drawflag)
578 if(lenght_ratio <= 0 || !theAlpha)
584 vector width, height;
586 pic = strcat(hud_skin_path, "/", pic, "_vertical");
587 if(precache_pic(pic) == "") {
588 pic = "gfx/hud/default/statusbar_vertical";
592 theOrigin_y += (1 - lenght_ratio) * theSize_y;
593 theSize_y *= lenght_ratio;
596 width = eX * theSize_x;
597 height = eY * theSize_y;
598 if(theSize_y <= theSize_x * 2)
600 // button not high enough
601 // draw just upper and lower part then
602 square = eY * theSize_y * 0.5;
603 bH = eY * (0.25 * theSize_y / (theSize_x * 2));
604 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
605 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
609 square = eY * theSize_x;
610 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
611 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
612 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
615 pic = strcat(hud_skin_path, "/", pic);
616 if(precache_pic(pic) == "") {
617 pic = "gfx/hud/default/statusbar";
621 theOrigin_x += (1 - lenght_ratio) * theSize_x;
622 theSize_x *= lenght_ratio;
625 width = eX * theSize_x;
626 height = eY * theSize_y;
627 if(theSize_x <= theSize_y * 2)
629 // button not wide enough
630 // draw just left and right part then
631 square = eX * theSize_x * 0.5;
632 bW = eX * (0.25 * theSize_x / (theSize_y * 2));
633 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
634 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
638 square = eX * theSize_y;
639 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
640 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
641 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
646 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
652 pic = strcat(hud_skin_path, "/num_leading");
653 if(precache_pic(pic) == "") {
654 pic = "gfx/hud/default/num_leading";
657 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
658 if(mySize_x/mySize_y > 2)
659 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);
660 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);
663 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
664 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
667 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
671 for (i = 0; i < HUD_PANEL_NUM; ++i) {
672 if(i == highlightedPanel || !panel_enabled)
675 HUD_Panel_UpdatePosSizeForId(i);
677 panel_pos -= '1 1 0' * panel_bg_border;
678 panel_size += '2 2 0' * panel_bg_border;
680 if(myPos_y + mySize_y < panel_pos_y)
682 if(myPos_y > panel_pos_y + panel_size_y)
685 if(myPos_x + mySize_x < panel_pos_x)
687 if(myPos_x > panel_pos_x + panel_size_x)
690 // OK, there IS a collision.
692 myCenter_x = myPos_x + 0.5 * mySize_x;
693 myCenter_y = myPos_y + 0.5 * mySize_y;
695 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
696 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
698 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
700 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
701 myTarget_x = panel_pos_x - mySize_x;
702 else // push it upwards
703 myTarget_y = panel_pos_y - mySize_y;
705 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
707 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
708 myTarget_x = panel_pos_x + panel_size_x;
709 else // push it upwards
710 myTarget_y = panel_pos_y - mySize_y;
712 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
714 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
715 myTarget_x = panel_pos_x - mySize_x;
716 else // push it downwards
717 myTarget_y = panel_pos_y + panel_size_y;
719 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
721 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
722 myTarget_x = panel_pos_x + panel_size_x;
723 else // push it downwards
724 myTarget_y = panel_pos_y + panel_size_y;
726 //if(cvar("hud_configure_checkcollisions_debug"))
727 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
733 void HUD_Panel_SetPos(vector pos)
735 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
739 //if(cvar("hud_configure_checkcollisions_debug"))
740 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
742 if(autocvar_hud_configure_grid)
744 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
745 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
748 if(hud_configure_checkcollisions)
749 pos = HUD_Panel_CheckMove(pos, mySize);
751 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
752 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
755 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
757 HUD_Panel_GetName(highlightedPanel);
758 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
761 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
762 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
767 float dist_x, dist_y;
769 ratio = mySize_x/mySize_y;
771 for (i = 0; i < HUD_PANEL_NUM; ++i) {
772 if(i == highlightedPanel || !panel_enabled)
775 HUD_Panel_UpdatePosSizeForId(i);
777 panel_pos -= '1 1 0' * panel_bg_border;
778 panel_size += '2 2 0' * panel_bg_border;
780 targEndPos = panel_pos + panel_size;
782 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
783 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
786 if (resizeCorner == 1)
788 // check if this panel is on our way
789 if (resizeorigin_x <= panel_pos_x)
791 if (resizeorigin_y <= panel_pos_y)
793 if (targEndPos_x <= resizeorigin_x - mySize_x)
795 if (targEndPos_y <= resizeorigin_y - mySize_y)
798 // there is a collision:
799 // detect which side of the panel we are facing is actually limiting the resizing
800 // (which side the resize direction finds for first) and reduce the size up to there
802 // dist is the distance between resizeorigin and the "analogous" point of the panel
803 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
804 dist_x = resizeorigin_x - targEndPos_x;
805 dist_y = resizeorigin_y - targEndPos_y;
806 if (dist_y <= 0 || dist_x / dist_y > ratio)
807 mySize_x = min(mySize_x, dist_x);
809 mySize_y = min(mySize_y, dist_y);
811 else if (resizeCorner == 2)
813 if (resizeorigin_x >= targEndPos_x)
815 if (resizeorigin_y <= panel_pos_y)
817 if (panel_pos_x >= resizeorigin_x + mySize_x)
819 if (targEndPos_y <= resizeorigin_y - mySize_y)
822 dist_x = panel_pos_x - resizeorigin_x;
823 dist_y = resizeorigin_y - targEndPos_y;
824 if (dist_y <= 0 || dist_x / dist_y > ratio)
825 mySize_x = min(mySize_x, dist_x);
827 mySize_y = min(mySize_y, dist_y);
829 else if (resizeCorner == 3)
831 if (resizeorigin_x <= panel_pos_x)
833 if (resizeorigin_y >= targEndPos_y)
835 if (targEndPos_x <= resizeorigin_x - mySize_x)
837 if (panel_pos_y >= resizeorigin_y + mySize_y)
840 dist_x = resizeorigin_x - targEndPos_x;
841 dist_y = panel_pos_y - resizeorigin_y;
842 if (dist_y <= 0 || dist_x / dist_y > ratio)
843 mySize_x = min(mySize_x, dist_x);
845 mySize_y = min(mySize_y, dist_y);
847 else if (resizeCorner == 4)
849 if (resizeorigin_x >= targEndPos_x)
851 if (resizeorigin_y >= targEndPos_y)
853 if (panel_pos_x >= resizeorigin_x + mySize_x)
855 if (panel_pos_y >= resizeorigin_y + mySize_y)
858 dist_x = panel_pos_x - resizeorigin_x;
859 dist_y = panel_pos_y - resizeorigin_y;
860 if (dist_y <= 0 || dist_x / dist_y > ratio)
861 mySize_x = min(mySize_x, dist_x);
863 mySize_y = min(mySize_y, dist_y);
865 //if(cvar("hud_configure_checkcollisions_debug"))
866 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
872 void HUD_Panel_SetPosSize(vector mySize)
874 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
876 resizeorigin = panel_click_resizeorigin;
879 // minimum panel size cap
880 mySize_x = max(0.025 * vid_conwidth, mySize_x);
881 mySize_y = max(0.025 * vid_conheight, mySize_y);
883 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.
885 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
886 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
889 // collision testing|
890 // -----------------+
892 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
893 if(resizeCorner == 1) {
894 myPos_x = resizeorigin_x - mySize_x;
895 myPos_y = resizeorigin_y - mySize_y;
896 } else if(resizeCorner == 2) {
897 myPos_x = resizeorigin_x;
898 myPos_y = resizeorigin_y - mySize_y;
899 } else if(resizeCorner == 3) {
900 myPos_x = resizeorigin_x - mySize_x;
901 myPos_y = resizeorigin_y;
902 } else { // resizeCorner == 4
903 myPos_x = resizeorigin_x;
904 myPos_y = resizeorigin_y;
907 // left/top screen edges
909 mySize_x = mySize_x + myPos_x;
911 mySize_y = mySize_y + myPos_y;
913 // bottom/right screen edges
914 if(myPos_x + mySize_x > vid_conwidth)
915 mySize_x = vid_conwidth - myPos_x;
916 if(myPos_y + mySize_y > vid_conheight)
917 mySize_y = vid_conheight - myPos_y;
919 //if(cvar("hud_configure_checkcollisions_debug"))
920 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
922 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
923 if(autocvar_hud_configure_grid)
925 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
926 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
929 if(hud_configure_checkcollisions)
930 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
932 // 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)
933 mySize_x = max(0.025 * vid_conwidth, mySize_x);
934 mySize_y = max(0.025 * vid_conheight, mySize_y);
936 // do another pos check, as size might have changed by now
937 if(resizeCorner == 1) {
938 myPos_x = resizeorigin_x - mySize_x;
939 myPos_y = resizeorigin_y - mySize_y;
940 } else if(resizeCorner == 2) {
941 myPos_x = resizeorigin_x;
942 myPos_y = resizeorigin_y - mySize_y;
943 } else if(resizeCorner == 3) {
944 myPos_x = resizeorigin_x - mySize_x;
945 myPos_y = resizeorigin_y;
946 } else { // resizeCorner == 4
947 myPos_x = resizeorigin_x;
948 myPos_y = resizeorigin_y;
951 //if(cvar("hud_configure_checkcollisions_debug"))
952 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
954 HUD_Panel_GetName(highlightedPanel);
956 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
957 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
959 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
960 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
964 float prevMouseClicked; // previous state
965 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
966 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
968 float pressed_key_time;
969 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
970 void HUD_Panel_Arrow_Action(float nPrimary)
972 if (highlightedPanel == -1 || mouseClicked)
975 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
978 if(autocvar_hud_configure_grid)
980 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
982 if (hudShiftState & S_SHIFT)
983 step = hud_configure_realGridSize_y;
985 step = 2 * hud_configure_realGridSize_y;
989 if (hudShiftState & S_SHIFT)
990 step = hud_configure_realGridSize_x;
992 step = 2 * hud_configure_realGridSize_x;
997 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
998 step = vid_conheight;
1000 step = vid_conwidth;
1001 if (hudShiftState & S_SHIFT)
1002 step = (step / 256); // more precision
1004 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
1007 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1009 highlightedPanel_initial_pos = panel_pos;
1010 highlightedPanel_initial_size = panel_size;
1012 if (hudShiftState & S_ALT) // resize
1014 highlightedAction = 1;
1015 if(nPrimary == K_UPARROW)
1017 else if(nPrimary == K_RIGHTARROW)
1019 else if(nPrimary == K_LEFTARROW)
1021 else // if(nPrimary == K_DOWNARROW)
1024 // ctrl+arrow reduces the size, instead of increasing it
1025 // Note that ctrl disables collisions check too, but it's fine
1026 // since we don't collide with anything reducing the size
1027 if (hudShiftState & S_CTRL) {
1029 resizeCorner = 5 - resizeCorner;
1033 mySize = panel_size;
1034 panel_click_resizeorigin = panel_pos;
1035 if(resizeCorner == 1) {
1036 panel_click_resizeorigin += mySize;
1038 } else if(resizeCorner == 2) {
1039 panel_click_resizeorigin_y += mySize_y;
1041 } else if(resizeCorner == 3) {
1042 panel_click_resizeorigin_x += mySize_x;
1044 } else { // resizeCorner == 4
1047 HUD_Panel_SetPosSize(mySize);
1051 highlightedAction = 2;
1054 if(nPrimary == K_UPARROW)
1056 else if(nPrimary == K_DOWNARROW)
1058 else if(nPrimary == K_LEFTARROW)
1060 else // if(nPrimary == K_RIGHTARROW)
1063 HUD_Panel_SetPos(pos);
1066 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1068 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1071 panel_pos_backup = highlightedPanel_initial_pos;
1072 panel_size_backup = highlightedPanel_initial_size;
1073 highlightedPanel_backup = highlightedPanel;
1077 void HUD_Panel_EnableMenu();
1078 float tab_panels[HUD_PANEL_NUM];
1079 float tab_panel, tab_backward;
1080 vector tab_panel_pos;
1081 void HUD_Panel_FirstInDrawQ(float id);
1082 void reset_tab_panels()
1085 for(i = 0; i < HUD_PANEL_NUM; ++i)
1088 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1092 if(!autocvar__hud_configure)
1095 // allow console bind to work
1098 con_keys = findkeysforcommand("toggleconsole");
1099 keys = tokenize(con_keys);
1101 float hit_con_bind, i;
1102 for (i = 0; i < keys; ++i)
1104 if(nPrimary == stof(argv(i)))
1108 if(bInputType == 0) {
1109 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
1110 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
1111 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
1113 else if(bInputType == 1) {
1114 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
1115 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
1116 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
1119 if(nPrimary == K_CTRL)
1121 if (bInputType == 1) //ctrl has been released
1123 if (tab_panel != -1)
1125 //switch to selected panel
1126 highlightedPanel = tab_panel;
1127 highlightedAction = 0;
1128 HUD_Panel_FirstInDrawQ(highlightedPanel);
1135 if(nPrimary == K_MOUSE1)
1137 if(bInputType == 0) { // key pressed
1141 else if(bInputType == 1) {// key released
1146 else if(nPrimary == K_ESCAPE)
1148 if (bInputType == 1)
1151 menu_enabled_time = time;
1152 localcmd("menu_showhudexit\n");
1154 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
1156 if (bInputType == 1 || mouseClicked)
1159 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
1160 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
1161 //(it should only after every other panel of the hud)
1162 //It's a minor bug anyway, we can live with it
1164 float starting_panel;
1165 float old_tab_panel = tab_panel;
1166 if (tab_panel == -1) //first press of TAB
1168 if (highlightedPanel != -1)
1169 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
1171 panel_pos = '0 0 0';
1172 starting_panel = highlightedPanel; //can be -1, it means no starting panel
1173 tab_panel_pos = panel_pos; //to compute level
1177 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
1179 starting_panel = tab_panel;
1181 tab_backward = (hudShiftState & S_SHIFT);
1183 float k, level, start_pos_x;
1184 vector candidate_pos;
1185 const float LEVELS_NUM = 4;
1186 const float level_height = vid_conheight / LEVELS_NUM;
1188 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
1189 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
1190 start_pos_x = tab_panel_pos_x;
1195 for(i = 0; i < HUD_PANEL_NUM; ++i)
1197 if (i == tab_panels[i] || i == starting_panel)
1199 HUD_Panel_UpdatePosSizeForId(i)
1200 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
1201 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)) )
1202 || ( 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)) ) )
1205 tab_panel_pos = candidate_pos = panel_pos;
1208 if (tab_panel != -1)
1210 if (k == LEVELS_NUM) //tab_panel not found
1213 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
1218 starting_panel = old_tab_panel;
1220 goto find_tab_panel; //u must find tab_panel!
1224 level = mod(level + level_height, vid_conheight);
1226 candidate_pos_x = vid_conwidth;
1230 level = mod(level - level_height, vid_conheight);
1231 start_pos_x = vid_conwidth;
1232 candidate_pos_x = 0;
1236 tab_panels[tab_panel] = tab_panel;
1238 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
1240 if (bInputType == 1 || mouseClicked)
1243 if (highlightedPanel != -1)
1245 HUD_Panel_GetName(highlightedPanel);
1246 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
1249 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
1251 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
1253 if (bInputType == 1 || mouseClicked)
1256 if (highlightedPanel != -1)
1258 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1259 panel_size_copied = panel_size;
1260 highlightedPanel_copied = highlightedPanel;
1263 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
1265 if (bInputType == 1 || mouseClicked)
1268 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
1271 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1273 // reduce size if it'd go beyond screen boundaries
1274 vector tmp_size = panel_size_copied;
1275 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
1276 tmp_size_x = vid_conwidth - panel_pos_x;
1277 if (panel_pos_y + panel_size_copied_y > vid_conheight)
1278 tmp_size_y = vid_conheight - panel_pos_y;
1280 if (panel_size == tmp_size)
1284 panel_pos_backup = panel_pos;
1285 panel_size_backup = panel_size;
1286 highlightedPanel_backup = highlightedPanel;
1288 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
1289 HUD_Panel_GetName(highlightedPanel);
1290 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1292 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
1294 if (bInputType == 1 || mouseClicked)
1296 //restore previous values
1297 if (highlightedPanel_backup != -1)
1299 HUD_Panel_GetName(highlightedPanel_backup);
1300 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
1301 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
1302 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
1303 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1304 highlightedPanel_backup = -1;
1307 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
1309 if (bInputType == 1)
1311 pressed_key_time = 0;
1314 else if (pressed_key_time == 0)
1315 pressed_key_time = time;
1317 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
1319 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
1321 if (bInputType == 1)
1323 if (highlightedPanel != -1)
1324 HUD_Panel_EnableMenu();
1326 else if(hit_con_bind)
1332 float HUD_Panel_HighlightCheck()
1336 while(j < HUD_PANEL_NUM)
1341 HUD_Panel_UpdatePosSizeForId(i);
1343 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1346 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)
1350 // resize from topleft border
1351 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)
1355 // resize from topright border
1356 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)
1360 // resize from bottomleft border
1361 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)
1365 // resize from bottomright border
1366 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)
1374 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
1375 void HUD_Panel_FirstInDrawQ(float id)
1378 var float place = -1;
1379 // find out where in the array our current id is, save into place
1380 for(i = 0; i < HUD_PANEL_NUM; ++i)
1382 if(panel_order[i] == id)
1388 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
1390 place = HUD_PANEL_NUM - 1;
1392 // move all ids up by one step in the array until "place"
1393 for(i = place; i > 0; --i)
1395 panel_order[i] = panel_order[i-1];
1397 // now save the new top id
1398 panel_order[0] = id;
1400 // let's save them into the cvar by some strcat trickery
1402 for(i = 0; i < HUD_PANEL_NUM; ++i)
1404 s = strcat(s, ftos(panel_order[i]), " ");
1406 cvar_set("_hud_panelorder", s);
1407 if(hud_panelorder_prev)
1408 strunzone(hud_panelorder_prev);
1409 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
1412 void HUD_Panel_Highlight()
1416 while(j < HUD_PANEL_NUM)
1421 HUD_Panel_UpdatePosSizeForId(i);
1423 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1426 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)
1428 highlightedPanel = i;
1429 HUD_Panel_FirstInDrawQ(i);
1430 highlightedAction = 1;
1431 panel_click_distance = mousepos - panel_pos;
1434 // resize from topleft border
1435 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)
1437 highlightedPanel = i;
1438 HUD_Panel_FirstInDrawQ(i);
1439 highlightedAction = 2;
1441 panel_click_distance = mousepos - panel_pos;
1442 panel_click_resizeorigin = panel_pos + panel_size;
1445 // resize from topright border
1446 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)
1448 highlightedPanel = i;
1449 HUD_Panel_FirstInDrawQ(i);
1450 highlightedAction = 2;
1452 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
1453 panel_click_distance_y = mousepos_y - panel_pos_y;
1454 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
1457 // resize from bottomleft border
1458 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)
1460 highlightedPanel = i;
1461 HUD_Panel_FirstInDrawQ(i);
1462 highlightedAction = 2;
1464 panel_click_distance_x = mousepos_x - panel_pos_x;
1465 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
1466 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
1469 // resize from bottomright border
1470 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)
1472 highlightedPanel = i;
1473 HUD_Panel_FirstInDrawQ(i);
1474 highlightedAction = 2;
1476 panel_click_distance = panel_size - mousepos + panel_pos;
1477 panel_click_resizeorigin = panel_pos;
1481 highlightedPanel = -1;
1482 highlightedAction = 0;
1485 void HUD_Panel_EnableMenu()
1488 menu_enabled_time = time;
1489 HUD_Panel_GetName(highlightedPanel);
1490 localcmd("menu_showhudoptions ", panel_name, "\n");
1492 float highlightcheck;
1493 void HUD_Panel_Mouse()
1495 // 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
1496 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1500 print("menu_enabled: ", ftos(menu_enabled), "\n");
1501 print("Highlighted: ", ftos(highlightedPanel), "\n");
1502 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1505 // instantly hide the editor cursor if we open the HUDExit dialog
1506 // as hud_fade_alpha doesn't decrease to 0 in this case
1507 // TODO: find a way to fade the cursor out even in this case
1508 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1511 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1513 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1514 mousepos_y = bound(0, mousepos_y, vid_conheight);
1518 if(prevMouseClicked == 0)
1520 if (tab_panel != -1)
1522 //stop ctrl-tab selection
1526 HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1527 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1528 if (highlightedPanel != -1)
1530 highlightedPanel_initial_pos = panel_pos;
1531 highlightedPanel_initial_size = panel_size;
1535 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1537 if (highlightedPanel != -1)
1539 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1541 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1543 panel_pos_backup = highlightedPanel_initial_pos;
1544 panel_size_backup = highlightedPanel_initial_size;
1545 highlightedPanel_backup = highlightedPanel;
1548 // in case the clicked panel is inside another panel and we aren't
1549 // moving it, avoid the immediate "fix" of its position/size
1550 // (often unwanted and hateful) by disabling collisions check
1551 hud_configure_checkcollisions = false;
1554 if(highlightedAction == 1)
1555 HUD_Panel_SetPos(mousepos - panel_click_distance);
1556 else if(highlightedAction == 2)
1559 if(resizeCorner == 1) {
1560 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1561 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1562 } else if(resizeCorner == 2) {
1563 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1564 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1565 } else if(resizeCorner == 3) {
1566 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1567 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1568 } else { // resizeCorner == 4
1569 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1570 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1572 HUD_Panel_SetPosSize(mySize);
1575 // doubleclick check
1576 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1578 mouseClicked = 0; // to prevent spam, I guess.
1579 HUD_Panel_EnableMenu();
1582 if(prevMouseClicked == 0)
1584 prevMouseClickedTime = time;
1585 prevMouseClickedPos = mousepos;
1590 highlightcheck = HUD_Panel_HighlightCheck();
1592 // draw cursor after performing move/resize to have the panel pos/size updated before highlightcheck
1594 cursorsize = '32 32 0';
1596 if(highlightcheck == 0)
1597 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1598 else if(highlightcheck == 1)
1599 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1600 else if(highlightcheck == 2)
1601 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1603 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1605 prevMouseClicked = mouseClicked;
1608 // Weapon icons (#0)
1610 float weaponspace[10];
1611 #define HUD_Weapons_Clear()\
1613 for(idx = 0; idx < 10; ++idx)\
1614 weaponspace[idx] = 0
1616 entity weaponorder[WEP_MAXCOUNT];
1617 void weaponorder_swap(float i, float j, entity pass)
1621 weaponorder[i] = weaponorder[j];
1625 string weaponorder_cmp_str;
1626 float weaponorder_cmp(float i, float j, entity pass)
1629 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1630 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1631 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)
1634 float GetAmmoStat(float i)
1638 case 0: return STAT_SHELLS;
1639 case 1: return STAT_NAILS;
1640 case 2: return STAT_ROCKETS;
1641 case 3: return STAT_CELLS;
1642 case 4: return STAT_FUEL;
1647 float GetAmmoTypeForWep(float i)
1651 case WEP_SHOTGUN: return 0;
1652 case WEP_UZI: return 1;
1653 case WEP_GRENADE_LAUNCHER: return 2;
1654 case WEP_MINE_LAYER: return 2;
1655 case WEP_ELECTRO: return 3;
1656 case WEP_CRYLINK: return 3;
1657 case WEP_HLAC: return 3;
1658 case WEP_MINSTANEX: return 3;
1659 case WEP_NEX: return 3;
1660 case WEP_CAMPINGRIFLE: return 1;
1661 case WEP_HAGAR: return 2;
1662 case WEP_ROCKET_LAUNCHER: return 2;
1663 case WEP_SEEKER: return 2;
1664 case WEP_FIREBALL: return 4;
1665 case WEP_HOOK: return 3;
1670 void HUD_Weapons(void)
1673 float center_x, center_y;
1675 if(!autocvar__hud_configure)
1677 if(!autocvar_hud_panel_weapons) return;
1678 if(spectatee_status == -1) return;
1681 hud_configure_active_panel = HUD_PANEL_WEAPONS;
1683 float timeout = autocvar_hud_panel_weapons_timeout;
1684 float timeout_effect_length, timein_effect_length;
1685 if (autocvar_hud_panel_weapons_timeout_effect == 0)
1687 timeout_effect_length = 0;
1688 timein_effect_length = 0;
1692 timeout_effect_length = 0.75;
1693 timein_effect_length = 0.375;
1696 if (timeout && time >= weapontime + timeout + timeout_effect_length && !autocvar__hud_configure)
1698 weaponprevtime = time;
1702 HUD_Panel_UpdateCvars(weapons);
1704 if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
1706 f = (time - (weapontime + timeout)) / timeout_effect_length;
1707 if (autocvar_hud_panel_weapons_timeout_effect)
1709 panel_bg_alpha *= (1 - f);
1710 panel_fg_alpha *= (1 - f);
1712 if (autocvar_hud_panel_weapons_timeout_effect == 1)
1714 f *= f; // for a cooler movement
1715 center_x = panel_pos_x + panel_size_x/2;
1716 center_y = panel_pos_y + panel_size_y/2;
1717 screen_ar = vid_conwidth/vid_conheight;
1718 if (center_x/center_y < screen_ar) //bottom left
1720 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1721 panel_pos_y += f * (vid_conheight - panel_pos_y);
1723 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1727 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1728 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1730 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1733 weaponprevtime = time - (1 - f) * timein_effect_length;
1735 else if (timeout && time < weaponprevtime + timein_effect_length && !autocvar__hud_configure)
1737 f = (time - weaponprevtime) / timein_effect_length;
1738 if (autocvar_hud_panel_weapons_timeout_effect)
1740 panel_bg_alpha *= (f);
1741 panel_fg_alpha *= (f);
1743 if (autocvar_hud_panel_weapons_timeout_effect == 1)
1745 f *= f; // for a cooler movement
1747 center_x = panel_pos_x + panel_size_x/2;
1748 center_y = panel_pos_y + panel_size_y/2;
1749 screen_ar = vid_conwidth/vid_conheight;
1750 if (center_x/center_y < screen_ar) //bottom left
1752 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1753 panel_pos_y += f * (vid_conheight - panel_pos_y);
1755 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1759 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1760 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1762 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1767 float i, weapid, wpnalpha, weapon_cnt;
1769 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1771 self = get_weaponinfo(i);
1772 if(self.impulse >= 0)
1776 // TODO make this configurable
1777 if(weaponorder_bypriority != autocvar_cl_weaponpriority)
1779 if(weaponorder_bypriority)
1780 strunzone(weaponorder_bypriority);
1781 if(weaponorder_byimpulse)
1782 strunzone(weaponorder_byimpulse);
1784 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
1785 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
1786 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1789 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1791 self = get_weaponinfo(i);
1792 if(self.impulse >= 0)
1794 weaponorder[weapon_cnt] = self;
1798 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1800 weaponorder_cmp_str = string_null;
1803 HUD_Panel_DrawBg(1);
1804 if(panel_bg_padding)
1806 panel_pos += '1 1 0' * panel_bg_padding;
1807 panel_size -= '2 2 0' * panel_bg_padding;
1810 if(autocvar_hud_panel_weapons_fade)
1812 wpnalpha = 3.2 - 2 * (time - weapontime);
1813 wpnalpha = bound(0.7, wpnalpha, 1) * panel_fg_alpha;
1816 wpnalpha = panel_fg_alpha;
1818 HUD_Weapons_Clear();
1820 float rows, columns;
1821 float aspect = autocvar_hud_panel_weapons_aspect;
1822 rows = panel_size_y/panel_size_x;
1823 rows = bound(1, floor((sqrt(4 * aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1825 columns = ceil(WEP_COUNT/rows);
1828 float a, type, fullammo;
1830 when = autocvar_hud_panel_weapons_complainbubble_time;
1832 fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
1840 wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
1841 float barsize_x, barsize_y, baroffset_x, baroffset_y;
1842 if (autocvar_hud_panel_weapons_ammo)
1844 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
1845 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
1848 if(wpnsize_x/wpnsize_y > aspect)
1850 barsize_x = aspect * wpnsize_y;
1851 barsize_y = wpnsize_y;
1852 baroffset_x = (wpnsize_x - barsize_x) / 2;
1856 barsize_y = 1/aspect * wpnsize_x;
1857 barsize_x = wpnsize_x;
1858 baroffset_y = (wpnsize_y - barsize_y) / 2;
1862 float show_accuracy;
1864 if(autocvar_hud_panel_weapons_accuracy && acc_levels)
1866 show_accuracy = true;
1867 if (acc_col_x[0] == -1)
1868 for (i = 0; i < acc_levels; ++i)
1869 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
1872 float weapons_st = getstati(STAT_WEAPONS);
1873 float label = autocvar_hud_panel_weapons_label;
1875 for(i = 0; i < weapon_cnt; ++i)
1877 wpnpos = panel_pos + eX * column * wpnsize_x + eY * row * wpnsize_y;
1879 self = weaponorder[i];
1880 weapid = self.impulse;
1882 // draw background behind currently selected weapon
1883 if(self.weapon == activeweapon)
1884 drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1886 // draw the weapon accuracy
1889 weapon_stats = weapon_accuracy[self.weapon-WEP_FIRST];
1890 if(weapon_stats >= 0)
1892 // find the max level lower than weapon_stats
1895 while ( j && weapon_stats < acc_lev[j] )
1898 // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
1900 factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
1902 color = color + factor * (acc_col[j+1] - color);
1904 drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
1908 // draw the weapon icon
1909 if((weapid >= 0) && (weapons_st & self.weapons))
1911 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1913 if(label == 1) // weapon number
1914 drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1915 else if(label == 2) // bind
1916 drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1918 // draw ammo status bar
1919 if(autocvar_hud_panel_weapons_ammo && weapid != WEP_TUBA && weapid != WEP_LASER && weapid != WEP_PORTO)
1922 type = GetAmmoTypeForWep(weapid);
1924 a = getstati(GetAmmoStat(type)); // how much ammo do we have?
1929 case 0: fullammo = autocvar_hud_panel_weapons_ammo_full_shells; break;
1930 case 1: fullammo = autocvar_hud_panel_weapons_ammo_full_nails; break;
1931 case 2: fullammo = autocvar_hud_panel_weapons_ammo_full_rockets; break;
1932 case 3: fullammo = autocvar_hud_panel_weapons_ammo_full_cells; break;
1933 case 4: fullammo = autocvar_hud_panel_weapons_ammo_full_fuel; break;
1934 default: fullammo = 60;
1938 wpnpos_x + baroffset_x,
1939 wpnpos_y + baroffset_y,
1940 barsize_x * bound(0, a/fullammo, 1),
1942 drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
1943 drawresetcliparea();
1948 // draw a "ghost weapon icon" if you don't have the weapon
1951 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
1954 // draw the complain message
1955 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
1959 if(complain_weapon_time + when > time)
1962 a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
1966 if(complain_weapon_time + when > time)
1973 if(complain_weapon_type == 0) {
1975 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
1977 else if(complain_weapon_type == 1) {
1979 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
1983 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
1985 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
1986 drawpic_aspect_skin(wpnpos + '1 1 0' * padding, "weapon_complainbubble", wpnsize - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
1987 drawstring_aspect(wpnpos + '1 1 0' * padding, s, wpnsize - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2003 float GetAmmoItemCode(float i)
2007 case 0: return IT_SHELLS;
2008 case 1: return IT_NAILS;
2009 case 2: return IT_ROCKETS;
2010 case 3: return IT_CELLS;
2011 case 4: return IT_FUEL;
2016 string GetAmmoPicture(float i)
2020 case 0: return "ammo_shells";
2021 case 1: return "ammo_bullets";
2022 case 2: return "ammo_rockets";
2023 case 3: return "ammo_cells";
2024 case 4: return "ammo_fuel";
2029 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
2032 if(autocvar__hud_configure)
2034 currently_selected = (itemcode == 2); //rockets always selected
2035 a = 31 + mod(itemcode*93, 128);
2038 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
2047 if(currently_selected)
2052 vector picpos, numpos;
2053 if(autocvar_hud_panel_ammo_iconalign)
2056 picpos = myPos + eX * 2 * mySize_y;
2060 numpos = myPos + eX * mySize_y;
2064 if (currently_selected)
2065 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2067 if(a > 0 && autocvar_hud_panel_ammo_progressbar)
2068 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);
2070 if(autocvar_hud_panel_ammo_text)
2073 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2074 else // "ghost" ammo count
2075 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
2078 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2079 else // "ghost" ammo icon
2080 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
2085 if(!autocvar__hud_configure)
2087 if(!autocvar_hud_panel_ammo) return;
2088 if(spectatee_status == -1) return;
2091 hud_configure_active_panel = HUD_PANEL_AMMO;
2093 HUD_Panel_UpdateCvars(ammo);
2096 mySize = panel_size;
2098 HUD_Panel_DrawBg(1);
2099 if(panel_bg_padding)
2101 pos += '1 1 0' * panel_bg_padding;
2102 mySize -= '2 2 0' * panel_bg_padding;
2105 float rows, columns, row, column;
2107 if (autocvar_hud_panel_ammo_onlycurrent)
2111 rows = mySize_y/mySize_x;
2112 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
2113 // ^^^ ammo item aspect goes here
2115 columns = ceil(AMMO_COUNT/rows);
2117 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
2122 if(ammo_size_x/ammo_size_y > 3)
2124 newSize = 3 * ammo_size_y;
2125 offset_x = ammo_size_x - newSize;
2126 pos_x += offset_x/2;
2127 ammo_size_x = newSize;
2131 newSize = 1/3 * ammo_size_x;
2132 offset_y = ammo_size_y - newSize;
2133 pos_y += offset_y/2;
2134 ammo_size_y = newSize;
2137 drawfont = hud_bigfont;
2138 float i, stat_items, currently_selected;
2139 if (autocvar_hud_panel_ammo_onlycurrent)
2141 if(autocvar__hud_configure)
2143 DrawAmmoItem(pos, ammo_size, 2, true); //show rockets
2146 stat_items = getstati(STAT_ITEMS);
2147 for (i = 0; i < AMMO_COUNT; ++i) {
2148 currently_selected = stat_items & GetAmmoItemCode(i);
2149 if (currently_selected)
2151 DrawAmmoItem(pos, ammo_size, i, true);
2155 return; // nothing to display
2158 stat_items = getstati(STAT_ITEMS);
2159 for (i = 0; i < AMMO_COUNT; ++i) {
2160 currently_selected = stat_items & GetAmmoItemCode(i);
2161 DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected);
2166 column = column + 1;
2169 drawfont = hud_font;
2172 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float alpha)
2174 vector newPos, newSize;
2175 vector picpos, numpos;
2179 if(mySize_y/mySize_x > 2)
2181 newSize_y = 2 * mySize_x;
2182 newSize_x = mySize_x;
2184 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
2189 newSize_x = 1/2 * mySize_y;
2190 newSize_y = mySize_y;
2192 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
2196 if(icon_right_align)
2199 picpos = newPos + eY * newSize_x;
2204 numpos = newPos + eY * newSize_x;
2208 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2209 // make number smaller than icon, it looks better
2210 // reduce only y to draw numbers with different number of digits with the same y size
2211 numpos_y += newSize_y * ((1 - 0.7) / 2);
2213 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2217 if(mySize_x/mySize_y > 3)
2219 newSize_x = 3 * mySize_y;
2220 newSize_y = mySize_y;
2222 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
2227 newSize_y = 1/3 * mySize_x;
2228 newSize_x = mySize_x;
2230 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
2234 if(icon_right_align) // right align
2237 picpos = newPos + eX * 2 * newSize_y;
2241 numpos = newPos + eX * newSize_y;
2245 drawstring_aspect(numpos, ftos(x), '2 1 0' * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2246 drawpic_aspect_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2249 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float fadelerp)
2252 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
2254 DrawNumIcon(myPos + expandingbox_resize_centered_box_offset(sz, mySize, 1), mySize * sz, x, icon, vertical, icon_right_align, color, (1 - fadelerp));
2259 void HUD_Powerups(void)
2261 float strength_time, shield_time;
2262 if(!autocvar__hud_configure)
2264 if(!autocvar_hud_panel_powerups) return;
2265 if(spectatee_status == -1) return;
2266 if not(getstati(STAT_ITEMS) & (IT_STRENGTH | IT_INVINCIBLE)) return;
2267 if (getstati(STAT_HEALTH) <= 0) return;
2269 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
2270 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
2274 hud_configure_active_panel = HUD_PANEL_POWERUPS;
2280 HUD_Panel_UpdateCvars(powerups);
2283 mySize = panel_size;
2285 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
2286 if(panel_bg_padding)
2288 pos += '1 1 0' * panel_bg_padding;
2289 mySize -= '2 2 0' * panel_bg_padding;
2296 string leftname, rightname;
2297 string leftprogressname, rightprogressname;
2298 float leftcnt, rightcnt;
2299 float leftexact, rightexact;
2300 if (autocvar_hud_panel_powerups_flip) {
2301 leftname = "strength";
2302 leftprogressname = autocvar_hud_panel_powerups_progressbar_strength;
2303 leftcnt = ceil(strength_time);
2304 leftexact = strength_time;
2306 rightname = "shield";
2307 rightprogressname = autocvar_hud_panel_powerups_progressbar_shield;
2308 rightcnt = ceil(shield_time);
2309 rightexact = shield_time;
2311 leftname = "shield";
2312 leftprogressname = autocvar_hud_panel_powerups_progressbar_shield;
2313 leftcnt = ceil(shield_time);
2314 leftexact = shield_time;
2316 rightname = "strength";
2317 rightprogressname = autocvar_hud_panel_powerups_progressbar_strength;
2318 rightcnt = ceil(strength_time);
2319 rightexact = strength_time;
2322 drawfont = hud_bigfont;
2323 float baralign = autocvar_hud_panel_powerups_baralign;
2324 float iconalign = autocvar_hud_panel_powerups_iconalign;
2326 float panel_ar = mySize_x/mySize_y;
2327 float is_vertical = (panel_ar < 1);
2328 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
2330 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2333 if(autocvar_hud_panel_powerups_progressbar)
2335 HUD_Panel_GetProgressBarColorForString(leftname);
2336 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);
2338 if(autocvar_hud_panel_powerups_text)
2341 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
2343 DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2350 if(autocvar_hud_panel_powerups_progressbar)
2352 HUD_Panel_GetProgressBarColorForString(rightname);
2353 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);
2355 if(autocvar_hud_panel_powerups_text)
2358 DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
2360 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));
2366 barsize = eX * mySize_x + eY * 0.5 * mySize_y;
2369 if(autocvar_hud_panel_powerups_progressbar)
2371 HUD_Panel_GetProgressBarColorForString(leftname);
2372 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);
2374 if(autocvar_hud_panel_powerups_text)
2377 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
2379 DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2386 if(autocvar_hud_panel_powerups_progressbar)
2388 HUD_Panel_GetProgressBarColorForString(rightname);
2389 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);
2391 if(autocvar_hud_panel_powerups_text)
2394 DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
2396 DrawNumIcon_expanding(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
2400 drawfont = hud_font;
2403 // Health/armor (#3)
2405 void HUD_HealthArmor(void)
2407 float armor, health, fuel;
2408 if(!autocvar__hud_configure)
2410 if(!autocvar_hud_panel_healtharmor) return;
2411 if(spectatee_status == -1) return;
2413 health = getstati(STAT_HEALTH);
2416 armor = getstati(STAT_ARMOR);
2417 fuel = getstati(STAT_FUEL);
2421 hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
2428 HUD_Panel_UpdateCvars(healtharmor);
2431 mySize = panel_size;
2433 HUD_Panel_DrawBg(1);
2434 if(panel_bg_padding)
2436 pos += '1 1 0' * panel_bg_padding;
2437 mySize -= '2 2 0' * panel_bg_padding;
2441 vector picpos, numpos;
2443 drawfont = hud_bigfont;
2444 float baralign = autocvar_hud_panel_healtharmor_baralign;
2445 float iconalign = autocvar_hud_panel_healtharmor_iconalign;
2447 float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
2448 float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
2449 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
2452 v = healtharmor_maxdamage(health, armor, armorblockpercent);
2457 float maxtotal = maxhealth + maxarmor;
2459 if(v_z) // NOT fully armored
2461 biggercount = "health";
2462 if(autocvar_hud_panel_healtharmor_progressbar)
2464 HUD_Panel_GetProgressBarColor(health);
2465 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);
2468 if(autocvar_hud_panel_healtharmor_text)
2469 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);
2473 biggercount = "armor";
2474 if(autocvar_hud_panel_healtharmor_progressbar)
2476 HUD_Panel_GetProgressBarColor(armor);
2477 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);
2480 if(autocvar_hud_panel_healtharmor_text)
2481 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);
2483 if(autocvar_hud_panel_healtharmor_text)
2484 DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
2488 HUD_Panel_GetProgressBarColor(fuel);
2489 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);
2494 string leftname, rightname;
2495 string leftprogressname, rightprogressname;
2496 float leftcnt, rightcnt;
2497 float leftmax, rightmax;
2498 float leftactive, rightactive;
2499 float leftalpha, rightalpha;
2500 if (autocvar_hud_panel_healtharmor_flip) { // old style layout with armor left/top of health
2502 leftprogressname = autocvar_hud_panel_healtharmor_progressbar_armor;
2506 leftalpha = min((armor+10)/55, 1);
2509 rightname = "health";
2510 rightprogressname = autocvar_hud_panel_healtharmor_progressbar_health;
2514 rightmax = maxhealth;
2516 leftname = "health";
2517 leftprogressname = autocvar_hud_panel_healtharmor_progressbar_health;
2521 leftmax = maxhealth;
2523 rightname = "armor";
2524 rightprogressname = autocvar_hud_panel_healtharmor_progressbar_armor;
2528 rightalpha = min((armor+10)/55, 1);
2529 rightmax = maxarmor;
2532 float panel_ar = mySize_x/mySize_y;
2533 float is_vertical = (panel_ar < 1);
2534 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
2536 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2539 if(autocvar_hud_panel_healtharmor_progressbar)
2541 HUD_Panel_GetProgressBarColorForString(leftname);
2542 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);
2544 if(autocvar_hud_panel_healtharmor_text)
2545 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, leftmax), 1);
2550 if(autocvar_hud_panel_healtharmor_progressbar)
2552 HUD_Panel_GetProgressBarColorForString(rightname);
2553 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);
2555 if(autocvar_hud_panel_healtharmor_text)
2556 DrawNumIcon(pos + eX * 0.5 * mySize_x, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, rightmax), 1);
2561 HUD_Panel_GetProgressBarColor(fuel);
2562 if (is_vertical) //if vertical always halve x to not cover too much numbers with 3 digits
2563 mySize_x *= 0.2 * 0.5 / 2;
2566 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2571 barsize = eX * mySize_x + eY * 0.5 * mySize_y;
2574 if(autocvar_hud_panel_healtharmor_progressbar)
2576 HUD_Panel_GetProgressBarColorForString(leftname);
2577 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);
2579 if(autocvar_hud_panel_healtharmor_text)
2580 DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, leftmax), 1);
2585 if(autocvar_hud_panel_healtharmor_progressbar)
2587 HUD_Panel_GetProgressBarColorForString(rightname);
2588 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);
2590 if(autocvar_hud_panel_healtharmor_text)
2591 DrawNumIcon(pos + eY * 0.5 * mySize_y, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, rightmax), 1);
2596 HUD_Panel_GetProgressBarColor(fuel);
2597 if (is_vertical) //if vertical always halve x to not cover numbers with 3 digits
2598 mySize_x *= 0.2 / 2;
2600 mySize_y *= 0.2 * 0.5;
2601 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2605 drawfont = hud_font;
2608 // Notification area (#4)
2611 string Weapon_SuicideMessage(float deathtype)
2613 w_deathtype = deathtype;
2614 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2615 return w_deathtypestring;
2618 string Weapon_KillMessage(float deathtype)
2620 w_deathtype = deathtype;
2621 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2622 return w_deathtypestring;
2625 #define KN_MAX_ENTRIES 10
2627 float killnotify_times[KN_MAX_ENTRIES];
2628 float killnotify_deathtype[KN_MAX_ENTRIES];
2629 float killnotify_actiontype[KN_MAX_ENTRIES]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2630 string killnotify_attackers[KN_MAX_ENTRIES];
2631 string killnotify_victims[KN_MAX_ENTRIES];
2632 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2636 kn_index = KN_MAX_ENTRIES-1;
2637 killnotify_times[kn_index] = time;
2638 killnotify_deathtype[kn_index] = wpn;
2639 killnotify_actiontype[kn_index] = actiontype;
2640 if(killnotify_attackers[kn_index])
2641 strunzone(killnotify_attackers[kn_index]);
2642 killnotify_attackers[kn_index] = strzone(attacker);
2643 if(killnotify_victims[kn_index])
2644 strunzone(killnotify_victims[kn_index]);
2645 killnotify_victims[kn_index] = strzone(victim);
2648 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
2651 float alsoprint, gentle;
2652 alsoprint = (autocvar_hud_panel_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
2653 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
2655 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
2658 if(msg == MSG_SUICIDE) {
2659 w = DEATH_WEAPONOF(type);
2661 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2663 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
2664 } else if (type == DEATH_KILL) {
2665 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2667 print ("^1",s1, "^1 couldn't take it anymore\n");
2668 } else if (type == DEATH_ROT) {
2669 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2671 print ("^1",s1, "^1 died\n");
2672 } else if (type == DEATH_NOAMMO) {
2673 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2675 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2676 } else if (type == DEATH_CAMP) {
2677 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2679 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2680 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2681 HUD_KillNotify_Push(s1, "", 0, type);
2683 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2684 } else if (type == DEATH_CHEAT) {
2685 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2687 print ("^1",s1, "^1 unfairly eliminated themself\n");
2688 } else if (type == DEATH_FIRE) {
2689 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2691 print ("^1",s1, "^1 burned to death\n");
2692 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2693 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2695 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2698 if (stof(s2) > 2) // killcount > 2
2699 print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2700 } else if(msg == MSG_KILL) {
2701 w = DEATH_WEAPONOF(type);
2703 if((w == WEP_CAMPINGRIFLE || w == WEP_MINSTANEX) && type & HITTYPE_HEADSHOT) // all headshot weapons go here
2704 HUD_KillNotify_Push(s1, s2, 1, DEATH_HEADSHOT);
2706 HUD_KillNotify_Push(s1, s2, 1, type);
2709 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
2711 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2712 HUD_KillNotify_Push(s1, s2, 1, type);
2716 print ("^1", s1, "^1 took action against a team mate\n");
2718 print ("^1", s1, "^1 mows down a team mate\n");
2721 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2723 print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2725 print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2727 else if (stof(s2) > 2) {
2729 print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2731 print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2734 else if(type == KILL_FIRST_BLOOD)
2735 print("^1",s1, "^1 drew first blood", "\n");
2736 else if (type == DEATH_TELEFRAG) {
2737 HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
2739 print ("^1",s2, "^1 tried to occupy ", s1, "^1's teleport destination space\n");
2741 print ("^1",s2, "^1 was telefragged by ", s1, "\n");
2743 else if (type == DEATH_DROWN) {
2744 HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
2746 print ("^1",s2, "^1 was drowned by ", s1, "\n");
2748 else if (type == DEATH_SLIME) {
2749 HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
2751 print ("^1",s2, "^1 was slimed by ", s1, "\n");
2753 else if (type == DEATH_LAVA) {
2754 HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
2756 print ("^1",s2, "^1 was cooked by ", s1, "\n");
2758 else if (type == DEATH_FALL) {
2759 HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
2761 print ("^1",s2, "^1 was grounded by ", s1, "\n");
2763 else if (type == DEATH_SHOOTING_STAR) {
2764 HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
2766 print ("^1",s2, "^1 was shot into space by ", s1, "\n");
2768 else if (type == DEATH_SWAMP) {
2769 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2771 print ("^1",s2, "^1 was conserved by ", s1, "\n");
2773 else if (type == DEATH_HURTTRIGGER)
2775 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2777 print("^1",s2, "^1 was thrown into a world of hurt by ", s1, "\n");
2778 } else if(type == DEATH_SBCRUSH) {
2779 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2781 print ("^1",s2, "^1 was crushed by ^1", s1, "\n");
2782 } else if(type == DEATH_SBMINIGUN) {
2783 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2785 print ("^1",s2, "^1 got shredded by ^1", s1, "\n");
2786 } else if(type == DEATH_SBROCKET) {
2787 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2789 print ("^1",s2, "^1 was blased to bits by ^1", s1, "\n");
2790 } else if(type == DEATH_SBBLOWUP) {
2791 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2793 print ("^1",s2, "^1 got caught in the destruction of ^1", s1, "'s vehicle\n");
2794 } else if(type == DEATH_WAKIGUN) {
2795 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2797 print ("^1",s2, "^1 was bolted down by ^1", s1, "\n");
2798 } else if(type == DEATH_WAKIROCKET) {
2799 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2801 print ("^1",s2, "^1 could find no shelter from ^1", s1, "'s rockets\n");
2802 } else if(type == DEATH_WAKIBLOWUP) {
2803 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2805 print ("^1",s2, "^1 dies when ^1", s1, "'s wakizashi dies.\n");
2806 } else if(type == DEATH_TURRET) {
2807 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2809 print ("^1",s2, "^1 was pushed into the line of fire by ^1", s1, "\n");
2810 } else if(type == DEATH_TOUCHEXPLODE) {
2811 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2813 print ("^1",s2, "^1 was pushed into an accident by ^1", s1, "\n");
2814 } else if(type == DEATH_CHEAT) {
2815 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2817 print ("^1",s2, "^1 was unfairly eliminated by ^1", s1, "\n");
2818 } else if (type == DEATH_FIRE) {
2819 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2821 print ("^1",s2, "^1 was burnt to death by ^1", s1, "\n");
2822 } else if (type == DEATH_CUSTOM) {
2823 HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
2825 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2826 } else if (type == DEATH_HURTTRIGGER) {
2827 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2829 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2831 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2833 print ("^1",s2, "^1 was fragged by ", s1, "\n");
2835 } else if(msg == MSG_SPREE) {
2836 if(type == KILL_END_SPREE) {
2838 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2840 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2841 } else if(type == KILL_SPREE) {
2843 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2845 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2846 } else if(type == KILL_SPREE_3) {
2848 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2850 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2851 } else if(type == KILL_SPREE_5) {
2853 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2855 print (s1,"^7 unleashes ^1RAGE\n");
2856 } else if(type == KILL_SPREE_10) {
2858 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2860 print (s1,"^7 starts the ^1MASSACRE!\n");
2861 } else if(type == KILL_SPREE_15) {
2863 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2865 print (s1,"^7 executes ^1MAYHEM!\n");
2866 } else if(type == KILL_SPREE_20) {
2868 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2870 print (s1,"^7 is a ^1BERSERKER!\n");
2871 } else if(type == KILL_SPREE_25) {
2873 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2875 print (s1,"^7 inflicts ^1CARNAGE!\n");
2876 } else if(type == KILL_SPREE_30) {
2878 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2880 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2882 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2883 if (type == DEATH_DROWN) {
2884 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2888 print ("^1",s1, "^1 was in the water for too long\n");
2890 print ("^1",s1, "^1 drowned\n");
2892 } else if (type == DEATH_SLIME) {
2893 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2895 print ("^1",s1, "^1 was slimed\n");
2896 } else if (type == DEATH_LAVA) {
2897 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2901 print ("^1",s1, "^1 found a hot place\n");
2903 print ("^1",s1, "^1 turned into hot slag\n");
2905 } else if (type == DEATH_FALL) {
2906 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2910 print ("^1",s1, "^1 tested gravity (and it worked)\n");
2912 print ("^1",s1, "^1 hit the ground with a crunch\n");
2914 } else if (type == DEATH_SHOOTING_STAR) {
2915 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2917 print ("^1",s1, "^1 became a shooting star\n");
2918 } else if (type == DEATH_SWAMP) {
2919 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2923 print ("^1",s1, "^1 discovered a swamp\n");
2925 print ("^1",s1, "^1 is now conserved for centuries to come\n");
2927 } else if(type == DEATH_TURRET) {
2928 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2930 print ("^1",s1, "^1 was mowed down by a turret \n");
2931 } else if (type == DEATH_CUSTOM) {
2932 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2934 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2935 } else if (type == DEATH_HURTTRIGGER) {
2936 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2938 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2939 } else if(type == DEATH_TOUCHEXPLODE) {
2940 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2942 print ("^1",s1, "^1 died in an accident\n");
2943 } else if(type == DEATH_CHEAT) {
2944 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2946 print ("^1",s1, "^1 was unfairly eliminated\n");
2947 } else if(type == DEATH_FIRE) {
2948 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2952 print ("^1",s1, "^1 felt a little hot\n");
2954 print ("^1",s1, "^1 burnt to death\n");
2957 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2961 print ("^1",s1, "^1 needs a restart\n");
2963 print ("^1",s1, "^1 died\n");
2966 } else if(msg == MSG_KILL_ACTION_SPREE) {
2968 print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2970 print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2971 } else if(msg == MSG_INFO) {
2972 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2973 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2974 print(s1, "^7 got the ", s2, "\n");
2975 } else if(type == INFO_LOSTFLAG) {
2976 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2977 print(s1, "^7 lost the ", s2, "\n");
2978 } else if(type == INFO_PICKUPFLAG) {
2979 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2980 print(s1, "^7 picked up the ", s2, "\n");
2981 } else if(type == INFO_RETURNFLAG) {
2982 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2983 print(s1, "^7 returned the ", s2, "\n");
2984 } else if(type == INFO_CAPTUREFLAG) {
2985 HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
2986 print(s1, "^7 captured the ", s2, s3, "\n");
2988 } else if(msg == MSG_RACE) {
2989 if(type == RACE_SERVER_RECORD) {
2990 HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
2992 else if(type == RACE_NEW_RANK) {
2993 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
2995 else if(type == RACE_NEW_TIME) {
2996 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
2998 else if(type == RACE_FAIL) {
2999 HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
3001 } else if(msg == MSG_KA) {
3002 if(type == KA_PICKUPBALL) {
3003 HUD_KillNotify_Push(s1, s2, 0, KA_PICKUPBALL);
3005 print (s1, "^7 has picked up the ball!\n");
3007 else if(type == KA_DROPBALL) {
3008 HUD_KillNotify_Push(s1, s2, 0, KA_DROPBALL);
3010 print(s1, "^7 has dropped the ball!\n");
3015 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
3017 void HUD_Centerprint(string s1, string s2, float type, float msg)
3020 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
3021 if(msg == MSG_SUICIDE) {
3022 if (type == DEATH_TEAMCHANGE) {
3023 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
3024 } else if (type == DEATH_AUTOTEAMCHANGE) {
3025 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
3026 } else if (type == DEATH_CAMP) {
3028 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
3030 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
3031 } else if (type == DEATH_NOAMMO) {
3033 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
3035 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
3036 } else if (type == DEATH_ROT) {
3038 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
3040 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
3041 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
3043 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
3045 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
3046 } else if (type == DEATH_QUIET) {
3048 } else { // generic message
3050 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
3052 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
3054 } else if(msg == MSG_KILL) {
3055 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
3057 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
3059 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
3061 } else if (type == KILL_FIRST_BLOOD) {
3063 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
3065 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
3067 } else if (type == KILL_FIRST_VICTIM) {
3069 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
3071 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
3073 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
3075 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
3077 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
3079 } else if (type == KILL_TYPEFRAGGED) {
3081 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
3083 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
3085 } else if (type == KILL_FRAG) {
3087 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
3089 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
3091 } else { // generic message
3093 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
3095 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
3098 } else if(msg == MSG_KILL_ACTION) {
3099 // TODO: invent more centerprints here?
3100 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
3104 void HUD_Notify (void)
3106 if(!autocvar__hud_configure)
3108 if(!autocvar_hud_panel_notify) return;
3111 hud_configure_active_panel = HUD_PANEL_NOTIFY;
3113 HUD_Panel_UpdateCvars(notify);
3116 mySize = panel_size;
3118 HUD_Panel_DrawBg(1);
3119 if(panel_bg_padding)
3121 pos += '1 1 0' * panel_bg_padding;
3122 mySize -= '2 2 0' * panel_bg_padding;
3125 float entries, height;
3126 entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
3127 height = mySize_y/entries;
3130 fontsize = '0.5 0.5 0' * height;
3134 when = autocvar_hud_panel_notify_time;
3136 fadetime = autocvar_hud_panel_notify_fadetime;
3140 vector pos_attacker, pos_victim;
3142 float width_attacker;
3143 string attacker, victim;
3145 float i, j, w, step, limit;
3146 if(autocvar_hud_panel_notify_flip) //order items from the top down
3152 else //order items from the bottom up
3159 for(j = kn_index; i != limit; i += step, ++j)
3161 if(autocvar__hud_configure)
3165 else // inverse order
3166 a = entries - 1 - i;
3167 attacker = textShortenToWidth(strcat("Player", ftos(a+1)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3168 victim = textShortenToWidth(strcat("Player", ftos(a+2)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3169 s = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
3170 a = bound(0, (when - a) / 4, 1);
3171 goto hud_config_notifyprint;
3174 if (j == KN_MAX_ENTRIES)
3177 if(killnotify_times[j] + when > time)
3181 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
3195 w = DEATH_WEAPONOF(killnotify_deathtype[j]);
3197 // TODO: maybe print in team colors?
3200 if(killnotify_actiontype[j] == 0)
3202 if(killnotify_deathtype[j] == DEATH_GENERIC)
3206 else if(killnotify_deathtype[j] == DEATH_NOAMMO)
3208 s = "notify_outofammo";
3210 else if(killnotify_deathtype[j] == DEATH_KILL)
3212 s = "notify_selfkill";
3214 else if(killnotify_deathtype[j] == DEATH_CAMP)
3216 s = "notify_camping";
3218 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
3220 s = "notify_teamkill_red";
3222 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
3224 s = "notify_teamkill_blue";
3226 else if(killnotify_deathtype[j] == DEATH_DROWN)
3230 else if(killnotify_deathtype[j] == DEATH_SLIME)
3234 else if(killnotify_deathtype[j] == DEATH_LAVA)
3238 else if(killnotify_deathtype[j] == DEATH_FALL)
3242 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
3244 s = "notify_shootingstar";
3246 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
3250 else if(killnotify_deathtype[j] == INFO_GOTFLAG)
3252 if(killnotify_victims[j] == "^1RED^7 flag")
3254 s = "notify_red_taken";
3258 s = "notify_blue_taken";
3261 else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
3263 if(killnotify_victims[j] == "^1RED^7 flag")
3265 s = "notify_red_returned";
3269 s = "notify_blue_returned";
3272 else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
3274 if(killnotify_victims[j] == "^1RED^7 flag")
3276 s = "notify_red_lost";
3280 s = "notify_blue_lost";
3283 else if(killnotify_deathtype[j] == INFO_CAPTUREFLAG)
3285 if(killnotify_victims[j] == "^1RED^7 flag")
3287 s = "notify_red_captured";
3291 s = "notify_blue_captured";
3294 else if(killnotify_deathtype[j] == KA_DROPBALL)
3296 s = "notify_balldropped";
3298 else if(killnotify_deathtype[j] == KA_PICKUPBALL)
3300 s = "notify_ballpickedup";
3303 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3304 pos_attacker = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
3305 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
3309 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3310 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3313 // X [did action to] Y
3316 if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_LASER)
3318 s = "notify_melee_laser";
3320 else if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_SHOTGUN)
3322 s = "notify_melee_shotgun";
3324 else if(WEP_VALID(w))
3326 self = get_weaponinfo(w);
3327 s = strcat("weapon", self.netname);
3329 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
3331 s = "notify_teamkill_red";
3333 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
3335 s = "notify_teamkill_red";
3337 else if(killnotify_deathtype[j] == DEATH_TELEFRAG)
3339 s = "notify_telefrag";
3341 else if(killnotify_deathtype[j] == DEATH_DROWN)
3345 else if(killnotify_deathtype[j] == DEATH_SLIME)
3349 else if(killnotify_deathtype[j] == DEATH_LAVA)
3353 else if(killnotify_deathtype[j] == DEATH_FALL)
3357 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
3359 s = "notify_shootingstar";
3361 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
3365 else if(killnotify_deathtype[j] == DEATH_HEADSHOT)
3367 s = "notify_headshot";
3369 else if(killnotify_deathtype[j] == RACE_SERVER_RECORD)
3371 s = "race_newrecordserver";
3373 else if(killnotify_deathtype[j] == RACE_NEW_RANK)
3375 s = "race_newrankyellow";
3377 else if(killnotify_deathtype[j] == RACE_NEW_TIME)
3381 else if(killnotify_deathtype[j] == RACE_FAIL)
3386 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3387 victim = textShortenToWidth(killnotify_victims[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3388 :hud_config_notifyprint
3389 width_attacker = stringwidth(attacker, TRUE, fontsize);
3390 pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * (0.5 * fontsize_y + i * height);
3391 pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
3392 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
3396 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3397 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3398 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3407 string seconds_tostring(float sec)
3410 minutes = floor(sec / 60);
3412 sec -= minutes * 60;
3415 s = ftos(100 + sec);
3417 return strcat(ftos(minutes), ":", substring(s, 1, 3));
3420 void HUD_Timer(void)
3422 if(!autocvar__hud_configure)
3424 if(!autocvar_hud_panel_timer) return;
3427 hud_configure_active_panel = HUD_PANEL_TIMER;
3429 HUD_Panel_UpdateCvars(timer);
3432 mySize = panel_size;
3434 HUD_Panel_DrawBg(1);
3435 if(panel_bg_padding)
3437 pos += '1 1 0' * panel_bg_padding;
3438 mySize -= '2 2 0' * panel_bg_padding;
3442 float timelimit, elapsedTime, timeleft, minutesLeft;
3444 timelimit = getstatf(STAT_TIMELIMIT);
3446 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
3447 timeleft = ceil(timeleft);
3449 minutesLeft = floor(timeleft / 60);
3452 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
3453 timer_color = '1 1 1'; //white
3454 else if(minutesLeft >= 1)
3455 timer_color = '1 1 0'; //yellow
3457 timer_color = '1 0 0'; //red
3459 if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
3460 if (time < getstatf(STAT_GAMESTARTTIME)) {
3461 //while restart is still active, show 00:00
3462 timer = seconds_tostring(0);
3464 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
3465 timer = seconds_tostring(elapsedTime);
3468 timer = seconds_tostring(timeleft);
3471 drawfont = hud_bigfont;
3472 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3473 drawfont = hud_font;
3478 void HUD_Radar(void)
3480 if (!autocvar__hud_configure)
3482 if (autocvar_hud_panel_radar == 0) return;
3483 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
3486 hud_configure_active_panel = HUD_PANEL_RADAR;
3488 HUD_Panel_UpdateCvars(radar);
3491 mySize = panel_size;
3493 HUD_Panel_DrawBg(1);
3494 if(panel_bg_padding)
3496 pos += '1 1 0' * panel_bg_padding;
3497 mySize -= '2 2 0' * panel_bg_padding;
3502 float scale2d, normalsize, bigsize;
3505 teamradar_origin2d = pos + 0.5 * mySize;
3506 teamradar_size2d = mySize;
3508 if(minimapname == "")
3511 teamradar_loadcvars();
3513 switch(hud_panel_radar_zoommode)
3517 f = current_zoomfraction;
3520 f = 1 - current_zoomfraction;
3530 switch(hud_panel_radar_rotation)
3533 teamradar_angle = view_angles_y - 90;
3536 teamradar_angle = 90 * hud_panel_radar_rotation;
3540 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
3541 teamradar_size2d = mySize;
3543 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
3545 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
3546 if(hud_panel_radar_rotation == 0)
3548 // max-min distance must fit the radar in any rotation
3549 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
3553 vector c0, c1, c2, c3, span;
3554 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
3555 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
3556 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
3557 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
3559 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
3560 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
3562 // max-min distance must fit the radar in x=x, y=y
3564 teamradar_size2d_x * scale2d / (1.05 * span_x),
3565 teamradar_size2d_y * scale2d / (1.05 * span_y)
3569 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
3570 if(bigsize > normalsize)
3571 normalsize = bigsize;
3575 + (1 - f) * normalsize;
3576 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
3578 + (1 - f) * view_origin);
3587 draw_teamradar_background(hud_panel_radar_foreground_alpha);
3589 for(tm = world; (tm = find(tm, classname, "radarlink")); )
3590 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
3591 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
3592 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
3593 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
3595 color2 = GetPlayerColor(tm.sv_entnum);
3596 //if(color == COLOR_SPECTATOR || color == color2)
3597 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
3599 draw_teamradar_player(view_origin, view_angles, '1 1 1');
3601 drawresetcliparea();
3606 void HUD_UpdatePlayerTeams();
3607 void HUD_Score(void)
3609 if(!autocvar__hud_configure)
3611 if(!autocvar_hud_panel_score) return;
3614 hud_configure_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 const float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
3675 const float height = mySize_y/entries;
3676 const vector fontsize = '0.9 0.9 0' * height;
3677 pos_y += height * (1 - 0.9) / 2;
3682 const float name_size = mySize_x*0.75;
3683 const float highlight_alpha = 0.2;
3684 float i, me_printed;
3686 if (autocvar__hud_configure)
3688 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
3689 for (i=0; i<entries; ++i)
3691 //simulate my score is lower than all displayed players,
3692 //so that I don't appear at all showing pure rankings.
3693 //This is to better show the difference between the 2 ranking views
3694 if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
3697 drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3698 s = GetPlayerName(pl.sv_entnum);
3703 s = strcat("Player", ftos(i+1));
3707 s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
3708 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
3709 drawstring(pos + eX * mySize_x*0.79, ftos(score), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3715 if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
3716 HUD_UpdatePlayerTeams();
3718 for (pl = players.sort_next, i=0; pl && i<entries; pl = pl.sort_next, ++i)
3720 if (pl.team == COLOR_SPECTATOR)
3723 if (i == entries-1 && !me_printed && pl != me)
3724 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
3726 for (pl = me.sort_next; pl; pl = pl.sort_next)
3727 if (pl.team != COLOR_SPECTATOR)
3731 rgb = '1 1 0'; //not last but not among the leading players: yellow
3733 rgb = '1 0 0'; //last: red
3740 rgb = '0 1 0'; //first: green
3742 drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3744 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
3745 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
3746 drawstring(pos + eX * mySize_x*0.79, ftos(pl.(scores[ps_primary])), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3751 // me vector := [team/connected frags id]
3752 pl = players.sort_next;
3756 if(autocvar__hud_configure)
3759 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3763 score = me.(scores[ps_primary]);
3764 if(autocvar__hud_configure)
3767 if(distribution >= 5)
3768 distribution_color = eY;
3769 else if(distribution >= 0)
3770 distribution_color = '1 1 1';
3771 else if(distribution >= -5)
3772 distribution_color = '1 1 0';
3774 distribution_color = eX;
3776 string distribution_str;
3777 distribution_str = ftos(distribution);
3778 if (distribution >= 0)
3780 if (distribution > 0)
3781 distribution_str = strcat("+", distribution_str);
3782 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3784 drawfont = hud_bigfont;
3785 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3786 drawfont = hud_font;
3787 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);
3788 } else { // teamgames
3789 float max_fragcount;
3790 max_fragcount = -99;
3792 float scores_count, row, column, rows, columns;
3794 vector score_pos, score_size; //for scores other than myteam
3795 if (spectatee_status == -1)
3797 if (autocvar__hud_configure)
3799 else for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3800 if(tm.team == COLOR_SPECTATOR)
3804 rows = mySize_y/mySize_x;
3805 rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
3806 // ^^^ ammo item aspect goes here
3808 columns = ceil(scores_count/rows);
3810 score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
3813 if(score_size_x/score_size_y > 3)
3815 newSize = 3 * score_size_y;
3816 offset_x = score_size_x - newSize;
3817 pos_x += offset_x/2;
3818 score_size_x = newSize;
3822 newSize = 1/3 * score_size_x;
3823 offset_y = score_size_y - newSize;
3824 pos_y += offset_y/2;
3825 score_size_y = newSize;
3829 score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
3830 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3831 if(tm.team == COLOR_SPECTATOR)
3833 score = tm.(teamscores[ts_primary]);
3834 if(autocvar__hud_configure)
3837 if (score > max_fragcount)
3838 max_fragcount = score;
3840 if (spectatee_status == -1)
3842 score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
3843 if (max_fragcount == score)
3844 HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3845 drawfont = hud_bigfont;
3846 drawstring_aspect(score_pos, ftos(score), score_size, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3847 drawfont = hud_font;
3855 else if(tm.team == myteam) {
3856 if (max_fragcount == score)
3857 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3858 drawfont = hud_bigfont;
3859 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3860 drawfont = hud_font;
3862 if (max_fragcount == score)
3863 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);
3864 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);
3873 void HUD_RaceTimer (void)
3875 if(!autocvar__hud_configure)
3877 if(!autocvar_hud_panel_racetimer) return;
3878 if(!(gametype == GAME_RACE || gametype == GAME_CTS)) return;
3879 if(spectatee_status == -1) return;
3882 hud_configure_active_panel = HUD_PANEL_RACETIMER;
3884 HUD_Panel_UpdateCvars(racetimer);
3887 mySize = panel_size;
3889 HUD_Panel_DrawBg(1);
3890 if(panel_bg_padding)
3892 pos += '1 1 0' * panel_bg_padding;
3893 mySize -= '2 2 0' * panel_bg_padding;
3896 // always force 4:1 aspect
3898 if(mySize_x/mySize_y > 4)
3900 newSize_x = 4 * mySize_y;
3901 newSize_y = mySize_y;
3903 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3907 newSize_y = 1/4 * mySize_x;
3908 newSize_x = mySize_x;
3910 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3914 drawfont = hud_bigfont;
3916 string s, forcetime;
3918 if(autocvar__hud_configure)
3921 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);
3922 s = "^1Intermediate 1 (+15.42)";
3923 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);
3924 s = strcat("^1PENALTY: ", ftos_decimals(20 * 0.1, 1), " (missing a checkpoint)");
3925 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);
3927 else if(race_checkpointtime)
3929 a = bound(0, 2 - (time - race_checkpointtime), 1);
3932 if(a > 0) // just hit a checkpoint?
3934 if(race_checkpoint != 254)
3936 if(race_time && race_previousbesttime)
3937 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
3939 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
3941 forcetime = TIME_ENCODED_TOSTRING(race_time);
3946 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
3948 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
3949 if(a > 0) // next one?
3951 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
3956 if(s != "" && a > 0)
3958 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);
3961 if(race_penaltytime)
3963 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
3966 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
3967 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);
3973 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
3974 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);
3979 if(race_laptime && race_checkpoint != 255)
3981 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
3982 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);
3987 if(race_mycheckpointtime)
3989 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
3990 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
3991 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);
3993 if(race_othercheckpointtime && race_othercheckpointenemy != "")
3995 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
3996 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
3997 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);
4000 if(race_penaltytime && !race_penaltyaccumulator)
4002 t = race_penaltytime * 0.1 + race_penaltyeventtime;
4003 a = bound(0, (1 + t - time), 1);
4007 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
4009 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
4010 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);
4015 drawfont = hud_font;
4020 float vote_yescount;
4023 float vote_highlighted; // currently selected vote
4025 float vote_active; // is there an active vote?
4026 float vote_prev; // previous state of vote_active to check for a change
4028 float vote_change; // "time" when vote_active changed
4030 void HUD_VoteWindow(void)
4032 if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
4035 if (autocvar__hud_configure)
4039 print("^1You have to answer before entering hud configure mode\n");
4040 cvar_set("_hud_configure", "0");
4042 vote_called_vote = strzone("^2Name ^7instead of \"^1Unregistered player^7\" in stats");
4043 uid2name_dialog = 1;
4046 if(!autocvar__hud_configure)
4048 if(!autocvar_hud_panel_vote) return;
4050 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
4051 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
4053 if(panel_bg_alpha_str == "") {
4054 panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
4056 panel_bg_alpha = stof(panel_bg_alpha_str);
4060 hud_configure_active_panel = HUD_PANEL_VOTE;
4069 if(vote_active != vote_prev) {
4071 vote_prev = vote_active;
4074 if(vote_active || autocvar__hud_configure)
4075 vote_alpha = bound(0, (time - vote_change) * 2, 1);
4077 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
4082 HUD_Panel_UpdateCvars(vote);
4086 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
4087 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
4090 // these must be below above block
4093 mySize = panel_size;
4095 a = vote_alpha * bound(autocvar_hud_panel_vote_alreadyvoted_alpha, 1 - vote_highlighted, 1);
4096 HUD_Panel_DrawBg(a);
4097 a = panel_fg_alpha * a;
4099 if(panel_bg_padding)
4101 pos += '1 1 0' * panel_bg_padding;
4102 mySize -= '2 2 0' * panel_bg_padding;
4105 // always force 3:1 aspect
4107 if(mySize_x/mySize_y > 3)
4109 newSize_x = 3 * mySize_y;
4110 newSize_y = mySize_y;
4112 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4116 newSize_y = 1/3 * mySize_x;
4117 newSize_x = mySize_x;
4119 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4123 s = "A vote has been called for:";
4125 s = "Allow servers to store and display your name?";
4126 drawstring_aspect(pos, s, eX * mySize_x + eY * (2/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4127 s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (1/8), stringwidth_colors);
4128 if(autocvar__hud_configure)
4129 s = "^1Configure the HUD";
4130 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a, DRAWFLAG_NORMAL);
4132 // print the yes/no counts
4133 s = strcat("Yes (", getcommandkey("vyes", "vyes"), "): ", ftos(vote_yescount));
4134 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);
4135 s = strcat("No (", getcommandkey("vno", "vno"), "): ", ftos(vote_nocount));
4136 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);
4138 // draw the progress bar backgrounds
4139 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_back", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4141 // draw the highlights
4142 if(vote_highlighted == 1) {
4143 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
4144 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4146 else if(vote_highlighted == 2) {
4147 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
4148 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4151 // draw the progress bars
4152 if(vote_yescount && vote_needed)
4154 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
4155 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4158 if(vote_nocount && vote_needed)
4160 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
4161 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
4164 drawresetcliparea();
4167 vote_highlighted = 0;
4171 // Mod icons panel (#10)
4174 float mod_active; // is there any active mod icon?
4176 // Clan Arena HUD modicons
4177 void HUD_Mod_CA(vector pos, vector mySize)
4179 mod_active = 1; // CA should never hide the mod icons panel
4180 float redalive, bluealive;
4181 redalive = getstati(STAT_REDALIVE);
4182 bluealive = getstati(STAT_BLUEALIVE);
4184 drawfont = hud_bigfont;
4185 vector redpos, bluepos;
4186 if(mySize_x > mySize_y)
4189 bluepos = pos + eY * 0.5 * mySize_y;
4190 drawpic_aspect_skin(redpos, "player_red.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4191 drawstring_aspect(redpos + eX * 0.5 * mySize_x, ftos(redalive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4192 drawpic_aspect_skin(bluepos, "player_blue.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4193 drawstring_aspect(bluepos + eX * 0.5 * mySize_x, ftos(bluealive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4198 bluepos = pos + eY * 0.5 * mySize_y;
4199 drawpic_aspect_skin(redpos, "player_red.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4200 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);
4201 drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4202 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);
4204 drawfont = hud_font;
4207 // CTF HUD modicon section
4208 float redflag_prevframe, blueflag_prevframe; // status during previous frame
4209 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
4210 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
4212 void HUD_Mod_CTF_Reset(void)
4214 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
4217 void HUD_Mod_CTF(vector pos, vector mySize)
4219 vector redflag_pos, blueflag_pos;
4221 float f; // every function should have that
4223 float redflag, blueflag; // current status
4224 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
4227 stat_items = getstati(STAT_ITEMS);
4228 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
4229 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
4231 if(redflag || blueflag)
4236 if(autocvar__hud_configure)
4242 // when status CHANGES, set old status into prevstatus and current status into status
4243 if (redflag != redflag_prevframe)
4245 redflag_statuschange_time = time;
4246 redflag_prevstatus = redflag_prevframe;
4247 redflag_prevframe = redflag;
4250 if (blueflag != blueflag_prevframe)
4252 blueflag_statuschange_time = time;
4253 blueflag_prevstatus = blueflag_prevframe;
4254 blueflag_prevframe = blueflag;
4257 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
4258 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
4260 float BLINK_FACTOR = 0.15;
4261 float BLINK_BASE = 0.85;
4263 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
4265 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
4267 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
4269 string red_icon, red_icon_prevstatus;
4270 float red_alpha, red_alpha_prevstatus;
4271 red_alpha = red_alpha_prevstatus = 1;
4273 case 1: red_icon = "flag_red_taken"; break;
4274 case 2: red_icon = "flag_red_lost"; break;
4275 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4277 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
4278 red_icon = "flag_red_shielded";
4280 red_icon = string_null;
4283 switch(redflag_prevstatus) {
4284 case 1: red_icon_prevstatus = "flag_red_taken"; break;
4285 case 2: red_icon_prevstatus = "flag_red_lost"; break;
4286 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4289 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
4290 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
4291 red_icon_prevstatus = "flag_red_shielded";
4293 red_icon_prevstatus = string_null;
4297 string blue_icon, blue_icon_prevstatus;
4298 float blue_alpha, blue_alpha_prevstatus;
4299 blue_alpha = blue_alpha_prevstatus = 1;
4301 case 1: blue_icon = "flag_blue_taken"; break;
4302 case 2: blue_icon = "flag_blue_lost"; break;
4303 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4305 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
4306 blue_icon = "flag_blue_shielded";
4308 blue_icon = string_null;
4311 switch(blueflag_prevstatus) {
4312 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
4313 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
4314 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
4317 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
4318 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
4319 blue_icon_prevstatus = "flag_blue_shielded";
4321 blue_icon_prevstatus = string_null;
4325 if(mySize_x > mySize_y) {
4326 if (myteam == COLOR_TEAM1) { // always draw own flag on left
4328 blueflag_pos = pos + eX * 0.5 * mySize_x;
4331 redflag_pos = pos + eX * 0.5 * mySize_x;
4333 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
4335 if (myteam == COLOR_TEAM1) { // always draw own flag on left
4337 blueflag_pos = pos + eY * 0.5 * mySize_y;
4340 redflag_pos = pos + eY * 0.5 * mySize_y;
4342 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
4345 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
4346 if(red_icon_prevstatus && f < 1)
4347 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
4349 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
4351 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
4352 if(blue_icon_prevstatus && f < 1)
4353 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
4355 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
4358 // Keyhunt HUD modicon section
4359 float kh_runheretime;
4361 void HUD_Mod_KH_Reset(void)
4366 void HUD_Mod_KH(vector pos, vector mySize)
4368 mod_active = 1; // keyhunt should never hide the mod icons panel
4372 vector p, pa, kh_size, kh_asize;
4374 kh_keys = getstati(STAT_KH_KEYS);
4377 if(mySize_x > mySize_y)
4379 p_y = pos_y + 0.25 * mySize_y;
4380 pa = p - eY * 0.25 * mySize_y;
4382 kh_size_x = mySize_x * 0.25;
4383 kh_size_y = 0.75 * mySize_y;
4384 kh_asize_x = mySize_x * 0.25;
4385 kh_asize_y = mySize_y * 0.25;
4389 p_y = pos_y + 0.125 * mySize_y;
4390 pa = p - eY * 0.125 * mySize_y;
4392 kh_size_x = mySize_x * 0.5;
4393 kh_size_y = 0.375 * mySize_y;
4394 kh_asize_x = mySize_x * 0.5;
4395 kh_asize_y = mySize_y * 0.125;
4402 for(i = 0; i < 4; ++i)
4404 key = floor(kh_keys / pow(32, i)) & 31;
4406 if(keyteam == 30 && keycount <= 4)
4408 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
4412 // this yields 8 exactly if "RUN HERE" shows
4417 kh_runheretime = time;
4418 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
4423 for(i = 0; i < 4; ++i)
4425 key = floor(kh_keys / pow(32, i)) & 31;
4438 default: // owned or dropped
4443 a = a * panel_fg_alpha;
4444 aa = aa * panel_fg_alpha;
4450 drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4453 drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4456 drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4459 drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
4464 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
4467 drawpic_aspect_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4470 drawpic_aspect_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4473 drawpic_aspect_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4476 drawpic_aspect_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
4480 if(mySize_x > mySize_y)
4482 p_x += 0.25 * mySize_x;
4483 pa_x += 0.25 * mySize_x;
4489 p_y = pos_y + 0.625 * mySize_y;
4490 pa_y = pos_y + 0.5 * mySize_y;
4496 p_x += 0.5 * mySize_x;
4497 pa_x += 0.5 * mySize_x;
4503 // Keepaway HUD mod icon
4504 float kaball_prevstatus; // last remembered status
4505 float kaball_statuschange_time; // time when the status changed
4507 // we don't need to reset for keepaway since it immediately
4508 // autocorrects prevstatus as to if the player has the ball or not
4510 void HUD_Mod_Keepaway(vector pos, vector mySize)
4512 mod_active = 1; // keepaway should always show the mod HUD
4514 float BLINK_FACTOR = 0.15;
4515 float BLINK_BASE = 0.85;
4516 float BLINK_FREQ = 5;
4517 float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
4519 float stat_items = getstati(STAT_ITEMS);
4520 float kaball = (stat_items/IT_KEY1) & 1;
4522 if(kaball != kaball_prevstatus)
4524 kaball_statuschange_time = time;
4525 kaball_prevstatus = kaball;
4528 // todo: Fix the sizing with the expanding image
4530 float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
4531 float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
4533 if(kaball_prevstatus && f < 1)
4534 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);
4537 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
4541 // Nexball HUD mod icon
4542 void HUD_Mod_NexBall(vector pos, vector mySize)
4544 float stat_items, nb_pb_starttime, dt, p;
4546 stat_items = getstati(STAT_ITEMS);
4547 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
4549 if (stat_items & IT_KEY1)
4554 //Manage the progress bar if any
4555 if (nb_pb_starttime > 0)
4557 dt = mod(time - nb_pb_starttime, nb_pb_period);
4558 // one period of positive triangle
4559 p = 2 * dt / nb_pb_period;
4564 HUD_Panel_GetProgressBarColor(nexball);
4565 if(mySize_x > mySize_y)
4566 HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", p, 0, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4568 HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", p, 1, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
4571 if (stat_items & IT_KEY1)
4572 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4575 // Race/CTS HUD mod icons
4576 float crecordtime_prev; // last remembered crecordtime
4577 float crecordtime_change_time; // time when crecordtime last changed
4578 float srecordtime_prev; // last remembered srecordtime
4579 float srecordtime_change_time; // time when srecordtime last changed
4581 float race_status_time;
4582 float race_status_prev;
4583 string race_status_name_prev;
4584 void HUD_Mod_Race(vector pos, vector mySize)
4586 mod_active = 1; // race should never hide the mod icons panel
4588 me = playerslots[player_localentnum - 1];
4590 float f; // yet another function has this
4591 score = me.(scores[ps_primary]);
4593 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
4594 return; // no records in the actual race
4596 drawfont = hud_bigfont;
4598 // clientside personal record
4600 if(gametype == GAME_CTS)
4604 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
4606 if(score && (score < t || !t)) {
4607 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
4608 if(autocvar_cl_autodemo_delete_keeprecords)
4610 f = autocvar_cl_autodemo_delete;
4612 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
4616 if(t != crecordtime_prev) {
4617 crecordtime_prev = t;
4618 crecordtime_change_time = time;
4621 vector textPos, medalPos;
4623 if(mySize_x > mySize_y) {
4624 // text on left side
4625 squareSize = min(mySize_y, mySize_x/2);
4626 textPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eY * 0.5 * (mySize_y - squareSize);
4627 medalPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eX * 0.5 * mySize_x + eY * 0.5 * (mySize_y - squareSize);
4630 squareSize = min(mySize_x, mySize_y/2);
4631 textPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eX * 0.5 * (mySize_x - squareSize);
4632 medalPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eY * 0.5 * mySize_y + eX * 0.5 * (mySize_x - squareSize);
4635 f = time - crecordtime_change_time;
4638 drawstring_aspect(textPos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4639 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(textPos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4642 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);
4643 drawstring_aspect_expanding(pos, "Personal best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
4644 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);
4648 t = race_server_record;
4649 if(t != srecordtime_prev) {
4650 srecordtime_prev = t;
4651 srecordtime_change_time = time;
4653 f = time - srecordtime_change_time;
4656 drawstring_aspect(textPos + eY * 0.5 * squareSize, "Server best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4657 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(textPos + eY * 0.5 * squareSize, "Server best", eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4660 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);
4661 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);
4662 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);
4665 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
4666 race_status_time = time + 5;
4667 race_status_prev = race_status;
4668 if (race_status_name_prev)
4669 strunzone(race_status_name_prev);
4670 race_status_name_prev = strzone(race_status_name);
4675 a = bound(0, race_status_time - time, 1);
4678 s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
4682 rank = race_CheckName(race_status_name);
4684 rankname = race_PlaceName(rank);
4687 namepos = medalPos + '0 0.8 0' * squareSize;
4689 rankpos = medalPos + '0 0.15 0' * squareSize;
4691 if(race_status == 0)
4692 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4693 else if(race_status == 1) {
4694 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);
4695 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4696 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4697 } else if(race_status == 2) {
4698 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
4699 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);
4701 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);
4702 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4703 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4704 } else if(race_status == 3) {
4705 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);
4706 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4707 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4710 if (race_status_time - time <= 0) {
4711 race_status_prev = -1;
4713 if(race_status_name)
4714 strunzone(race_status_name);
4715 race_status_name = string_null;
4716 if(race_status_name_prev)
4717 strunzone(race_status_name_prev);
4718 race_status_name_prev = string_null;
4720 drawfont = hud_font;
4723 float mod_prev; // previous state of mod_active to check for a change
4725 float mod_change; // "time" when mod_active changed
4727 void HUD_ModIcons(void)
4729 if(!autocvar__hud_configure)
4731 if(!autocvar_hud_panel_modicons) return;
4732 if (gametype != GAME_CTF && gametype != GAME_KEYHUNT && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && gametype != GAME_CA && gametype != GAME_FREEZETAG && gametype != GAME_KEEPAWAY) return;
4735 hud_configure_active_panel = HUD_PANEL_MODICONS;
4737 HUD_Panel_UpdateCvars(modicons);
4740 mySize = panel_size;
4742 if(mod_active != mod_prev) {
4744 mod_prev = mod_active;
4747 if(mod_active || autocvar__hud_configure)
4748 mod_alpha = bound(0, (time - mod_change) * 2, 1);
4750 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
4753 HUD_Panel_DrawBg(mod_alpha);
4755 if(panel_bg_padding)
4757 pos += '1 1 0' * panel_bg_padding;
4758 mySize -= '2 2 0' * panel_bg_padding;
4761 // these MUST be ran in order to update mod_active
4762 if(gametype == GAME_KEYHUNT)
4763 HUD_Mod_KH(pos, mySize);
4764 else if(gametype == GAME_CTF || autocvar__hud_configure)
4765 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
4766 else if(gametype == GAME_NEXBALL)
4767 HUD_Mod_NexBall(pos, mySize);
4768 else if(gametype == GAME_CTS || gametype == GAME_RACE)
4769 HUD_Mod_Race(pos, mySize);
4770 else if(gametype == GAME_CA || gametype == GAME_FREEZETAG)
4771 HUD_Mod_CA(pos, mySize);
4772 else if(gametype == GAME_KEEPAWAY)
4773 HUD_Mod_Keepaway(pos, mySize);
4776 // Draw pressed keys (#11)
4778 void HUD_DrawPressedKeys(void)
4780 if(!autocvar__hud_configure)
4782 if(!autocvar_hud_panel_pressedkeys) return;
4783 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
4786 hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS;
4789 HUD_Panel_UpdateCvars(pressedkeys);
4792 mySize = panel_size;
4794 HUD_Panel_DrawBg(1);
4795 if(panel_bg_padding)
4797 pos += '1 1 0' * panel_bg_padding;
4798 mySize -= '2 2 0' * panel_bg_padding;
4801 // force custom aspect
4802 float aspect = autocvar_hud_panel_pressedkeys_aspect;
4806 if(mySize_x/mySize_y > aspect)
4808 newSize_x = aspect * mySize_y;
4809 newSize_y = mySize_y;
4811 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4815 newSize_y = 1/aspect * mySize_x;
4816 newSize_x = mySize_x;
4818 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4824 keysize = eX * mySize_x * (1/3) + eY * mySize_y * 0.5;
4826 pressedkeys = getstatf(STAT_PRESSED_KEYS);
4828 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4829 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);
4830 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);
4832 drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4833 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);
4834 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);
4837 // Handle chat as a panel (#12)
4841 if(!autocvar__hud_configure)
4843 if (!autocvar_hud_panel_chat)
4845 if (!autocvar_con_chatrect)
4846 cvar_set("con_chatrect", "0");
4851 hud_configure_active_panel = HUD_PANEL_CHAT;
4853 HUD_Panel_UpdateCvars(chat);
4855 if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
4857 panel_pos_y = panel_bg_border;
4858 panel_size_y = vid_conheight - panel_bg_border * 2;
4859 if(panel_bg == "0") // force a border when maximized
4861 if(precache_pic(panel_bg) == "") {
4862 panel_bg = strcat(hud_skin_path, "/border_default");
4863 if(precache_pic(panel_bg) == "") {
4864 panel_bg = "gfx/hud/default/border_default";
4868 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an alpha of at least 0.75
4873 mySize = panel_size;
4875 HUD_Panel_DrawBg(1);
4877 if(panel_bg_padding)
4879 pos += '1 1 0' * panel_bg_padding;
4880 mySize -= '2 2 0' * panel_bg_padding;
4883 if (!autocvar_con_chatrect)
4884 cvar_set("con_chatrect", "1");
4886 cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
4887 cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
4889 cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
4890 cvar_set("con_chat", ftos(floor(mySize_y/autocvar_con_chatsize - 0.5)));
4892 if(autocvar__hud_configure)
4895 chatsize = '1 1 0' * autocvar_con_chatsize;
4896 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
4898 for(i = 0; i < autocvar_con_chat; ++i)
4900 if(i == autocvar_con_chat - 1)
4903 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
4904 drawcolorcodedstring(pos, textShortenToWidth("^3Player^7: This is the chat area.", mySize_x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
4905 pos_y += chatsize_y;
4910 // Engine info panel (#13)
4917 float frametimeavg1; // 1 frame ago
4918 float frametimeavg2; // 2 frames ago
4919 void HUD_EngineInfo(void)
4921 if(!autocvar__hud_configure)
4923 if(!autocvar_hud_panel_engineinfo) return;
4926 hud_configure_active_panel = HUD_PANEL_ENGINEINFO;
4928 HUD_Panel_UpdateCvars(engineinfo);
4931 mySize = panel_size;
4933 HUD_Panel_DrawBg(1);
4934 if(panel_bg_padding)
4936 pos += '1 1 0' * panel_bg_padding;
4937 mySize -= '2 2 0' * panel_bg_padding;
4940 float currentTime = gettime(GETTIME_REALTIME);
4941 if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
4943 float currentframetime = currentTime - prevfps_time;
4944 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
4945 frametimeavg2 = frametimeavg1;
4946 frametimeavg1 = frametimeavg;
4949 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
4950 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.
4952 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
4953 prevfps = (1/currentframetime);
4954 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"
4956 prevfps_time = currentTime;
4961 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
4963 prevfps = framecounter/(currentTime - prevfps_time);
4965 prevfps_time = currentTime;
4970 color = HUD_Get_Num_Color (prevfps, 100);
4971 drawfont = hud_bigfont;
4972 drawstring_aspect(pos, strcat("FPS: ", ftos_decimals(prevfps, autocvar_hud_panel_engineinfo_framecounter_decimals)), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
4973 drawfont = hud_font;
4976 // Info messages panel (#14)
4978 #define drawInfoMessage(s)\
4979 if(autocvar_hud_panel_infomessages_flip)\
4980 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);\
4981 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);\
4983 void HUD_InfoMessages(void)
4985 if(!autocvar__hud_configure)
4987 if(!autocvar_hud_panel_infomessages) return;
4990 hud_configure_active_panel = HUD_PANEL_INFOMESSAGES;
4992 HUD_Panel_UpdateCvars(infomessages);
4995 mySize = panel_size;
4997 HUD_Panel_DrawBg(1);
4998 if(panel_bg_padding)
5000 pos += '1 1 0' * panel_bg_padding;
5001 mySize -= '2 2 0' * panel_bg_padding;
5004 // always force 5:1 aspect
5006 if(mySize_x/mySize_y > 5)
5008 newSize_x = 5 * mySize_y;
5009 newSize_y = mySize_y;
5011 pos_x = pos_x + (mySize_x - newSize_x) / 2;
5015 newSize_y = 1/5 * mySize_x;
5016 newSize_x = mySize_x;
5018 pos_y = pos_y + (mySize_y - newSize_y) / 2;
5027 fontsize = '0.20 0.20 0' * mySize_y;
5030 if(spectatee_status != 0)
5036 if(!autocvar__hud_configure)
5038 if(spectatee_status && !intermission)
5040 if(spectatee_status == -1)
5043 s = strcat("^1Spectating: ^7", GetPlayerName(spectatee_status - 1));
5046 if(spectatee_status == -1)
5047 s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 to spectate");
5049 s = strcat("^1Press ^3", getcommandkey("primary fire", "+fire"), "^1 for another player");
5052 if(spectatee_status == -1)
5053 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
5055 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+fire2"), "^1 to observe");
5058 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
5061 if(gametype == GAME_ARENA)
5062 s = "^1Wait for your turn to join";
5063 else if(gametype == GAME_LMS)
5066 sk = playerslots[player_localentnum - 1];
5067 if(sk.(scores[ps_primary]) >= 666)
5068 s = "^1Match has already begun";
5069 else if(sk.(scores[ps_primary]) > 0)
5070 s = "^1You have no more lives left";
5072 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
5075 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
5078 //show restart countdown:
5079 if (time < getstatf(STAT_GAMESTARTTIME)) {
5081 //we need to ceil, otherwise the countdown would be off by .5 when using round()
5082 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
5083 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
5084 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
5088 if(warmup_stage && !intermission)
5090 s = "^2Currently in ^1warmup^2 stage!";
5095 if(mod(time, 1) >= 0.5)
5100 if(ready_waiting && !intermission && !spectatee_status)
5102 if(ready_waiting_for_me)
5105 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
5107 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
5112 s = strcat("^2Waiting for others to ready up to end warmup...");
5114 s = strcat("^2Waiting for others to ready up...");
5118 else if(warmup_stage && !intermission && !spectatee_status)
5120 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
5124 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
5126 float ts_min, ts_max;
5127 tm = teams.sort_next;
5130 for(; tm.sort_next; tm = tm.sort_next)
5132 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
5134 if(!ts_min) ts_min = tm.team_size;
5135 else ts_min = min(ts_min, tm.team_size);
5136 if(!ts_max) ts_max = tm.team_size;
5137 else ts_max = max(ts_max, tm.team_size);
5139 if ((ts_max - ts_min) > 1)
5141 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
5142 tm = GetTeam(myteam, false);
5144 if (tm.team != COLOR_SPECTATOR)
5145 if (tm.team_size == ts_max)
5146 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
5154 s = "^7Press ^3ESC ^7to show HUD options.";
5156 s = "^3Doubleclick ^7a panel for panel-specific options.";
5158 s = "^3CTRL ^7to disable collision testing, ^3SHIFT ^7and";
5160 s = "^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.";
5165 // Physics panel (#15)
5167 vector acc_prevspeed;
5168 float acc_prevtime, acc_avg, top_speed, top_speed_time;
5170 void HUD_Physics(void)
5172 if(!autocvar_hud_panel_physics)
5174 if(!autocvar__hud_configure) return;
5177 hud_configure_active_panel = HUD_PANEL_PHYSICS;
5179 HUD_Panel_UpdateCvars(physics);
5181 HUD_Panel_DrawBg(1);
5182 if(panel_bg_padding)
5184 panel_pos += '1 1 0' * panel_bg_padding;
5185 panel_size -= '2 2 0' * panel_bg_padding;
5189 float speed, conversion_factor;
5192 switch(autocvar_cl_showspeed_unit)
5197 conversion_factor = 1.0;
5201 conversion_factor = 0.0254;
5205 conversion_factor = 0.0254 * 3.6;
5209 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
5213 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
5217 float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
5218 if (autocvar__hud_configure)
5219 speed = floor( max_speed * 0.65 + 0.5 );
5220 else if(autocvar_hud_panel_physics_speed_z)
5221 speed = floor( vlen(pmove_vel) * conversion_factor + 0.5 );
5223 speed = floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 );
5225 //compute acceleration
5226 float acceleration, f;
5227 if (autocvar__hud_configure)
5228 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
5231 f = time - acc_prevtime;
5232 if(autocvar_hud_panel_physics_acceleration_z)
5233 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
5235 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
5236 acc_prevspeed = pmove_vel;
5237 acc_prevtime = time;
5239 f = bound(0, f * 10, 1);
5240 acc_avg = acc_avg * (1 - f) + acceleration * f;
5241 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
5245 drawfont = hud_bigfont;
5246 float panel_ar = panel_size_x/panel_size_y;
5247 vector speed_offset, acceleration_offset;
5250 panel_size_x *= 0.5;
5251 if (autocvar_hud_panel_physics_flip)
5252 speed_offset_x = panel_size_x;
5254 acceleration_offset_x = panel_size_x;
5258 panel_size_y *= 0.5;
5259 if (autocvar_hud_panel_physics_flip)
5260 speed_offset_y = panel_size_y;
5262 acceleration_offset_y = panel_size_y;
5264 float speed_baralign, acceleration_baralign;
5265 if (autocvar_hud_panel_physics_baralign == 1)
5266 acceleration_baralign = speed_baralign = 1;
5267 else if (autocvar_hud_panel_physics_flip)
5269 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
5270 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
5274 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
5275 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
5279 if(speed && autocvar_hud_panel_physics_progressbar)
5281 HUD_Panel_GetProgressBarColor(speed);
5282 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);
5285 vector tmp_offset, tmp_size;
5286 tmp_size_x = panel_size_x * 0.75;
5287 tmp_size_y = panel_size_y;
5289 tmp_offset_x = panel_size_x - tmp_size_x;
5292 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
5298 tmp_offset_x = tmp_size_x;
5299 if (autocvar_hud_panel_physics_speed_unit_show)
5302 tmp_size_x = panel_size_x * (1 - 0.75);
5303 tmp_size_y = panel_size_y * 0.4;
5304 drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
5307 //compute and draw top speed
5308 if (autocvar_hud_panel_physics_topspeed)
5310 if (autocvar__hud_configure)
5312 top_speed = floor( max_speed * 0.75 + 0.5 );
5317 if (speed >= top_speed)
5320 top_speed_time = time;
5322 if (top_speed == 0) //hide top speed 0, it would be stupid
5326 f = max(1, autocvar_hud_panel_physics_topspeed_time);
5327 // divide by f to make it start from 1
5328 f = cos( ((time - top_speed_time) / f) * PI/2 );
5333 //top speed progressbar peek
5334 if(autocvar_hud_panel_physics_progressbar && speed < top_speed)
5336 float peek_offset_x, peek_size_x;
5338 peek_offset_x = (1 - min(top_speed, max_speed)/max_speed) * panel_size_x;
5340 peek_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x;
5341 //if speed is not 0 the speed progressbar already fetched the color
5343 HUD_Panel_GetProgressBarColor(speed);
5344 peek_size_x = panel_size_x * 0.01;
5345 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);
5349 tmp_offset_y = panel_size_y * 0.4;
5350 tmp_size_x = panel_size_x * (1 - 0.75);
5351 tmp_size_y = panel_size_y - tmp_offset_y;
5352 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
5359 if(acceleration && autocvar_hud_panel_physics_progressbar)
5361 if (acceleration < 0)
5362 HUD_Panel_GetProgressBarColor(acceleration_neg);
5364 HUD_Panel_GetProgressBarColor(acceleration);
5365 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);
5367 drawstring_aspect(panel_pos + acceleration_offset, ftos_decimals(acceleration, 3), panel_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
5368 drawfont = hud_font;
5377 void HUD_Reset (void)
5379 // reset gametype specific icons
5380 if(gametype == GAME_KEYHUNT)
5382 else if(gametype == GAME_CTF)
5383 HUD_Mod_CTF_Reset();
5386 #define HUD_DrawPanel(id)\
5388 case (HUD_PANEL_RADAR):\
5389 HUD_Radar(); break;\
5390 case (HUD_PANEL_WEAPONS):\
5391 HUD_Weapons(); break;\
5392 case (HUD_PANEL_AMMO):\
5394 case (HUD_PANEL_POWERUPS):\
5395 HUD_Powerups(); break;\
5396 case (HUD_PANEL_HEALTHARMOR):\
5397 HUD_HealthArmor(); break;\
5398 case (HUD_PANEL_NOTIFY):\
5399 HUD_Notify(); break;\
5400 case (HUD_PANEL_TIMER):\
5401 HUD_Timer(); break;\
5402 case (HUD_PANEL_SCORE):\
5403 HUD_Score(); break;\
5404 case (HUD_PANEL_RACETIMER):\
5405 HUD_RaceTimer(); break;\
5406 case (HUD_PANEL_VOTE):\
5407 HUD_VoteWindow(); break;\
5408 case (HUD_PANEL_MODICONS):\
5409 HUD_ModIcons(); break;\
5410 case (HUD_PANEL_PRESSEDKEYS):\
5411 HUD_DrawPressedKeys(); break;\
5412 case (HUD_PANEL_CHAT):\
5414 case (HUD_PANEL_ENGINEINFO):\
5415 HUD_EngineInfo(); break;\
5416 case (HUD_PANEL_INFOMESSAGES):\
5417 HUD_InfoMessages(); break;\
5418 case (HUD_PANEL_PHYSICS):\
5419 HUD_Physics(); break;\
5420 } ENDS_WITH_CURLY_BRACE
5422 void HUD_Main (void)
5425 // global hud alpha fade
5426 if(menu_enabled == 1)
5429 hud_fade_alpha = (1 - autocvar__menu_alpha);
5431 if(scoreboard_fade_alpha)
5432 hud_fade_alpha = (1 - scoreboard_fade_alpha);
5434 if(intermission == 2) // no hud during mapvote
5436 else if(autocvar__menu_alpha == 0 && scoreboard_fade_alpha == 0)
5439 if(!autocvar__hud_configure && !hud_fade_alpha)
5443 if (hud_skin_path != autocvar_hud_skin)
5446 strunzone(hud_skin_path);
5447 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
5450 // HUD configure visible grid
5451 if(autocvar__hud_configure && autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
5453 hud_configure_gridSize_x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
5454 hud_configure_gridSize_y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
5455 hud_configure_realGridSize_x = hud_configure_gridSize_x * vid_conwidth;
5456 hud_configure_realGridSize_y = hud_configure_gridSize_y * vid_conheight;
5458 for(i = 0; i < 1/hud_configure_gridSize_x; ++i)
5459 drawfill(eX * i * hud_configure_realGridSize_x, eX + eY * vid_conheight, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
5461 for(i = 0; i < 1/hud_configure_gridSize_y; ++i)
5462 drawfill(eY * i * hud_configure_realGridSize_y, eY + eX * vid_conwidth, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
5466 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
5470 float hud_dock_color_team = autocvar_hud_dock_color_team;
5471 if((teamplay) && hud_dock_color_team) {
5472 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5473 color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
5475 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
5476 color = '1 0 0' * hud_dock_color_team;
5480 string hud_dock_color = autocvar_hud_dock_color;
5481 if(hud_dock_color == "shirt") {
5482 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5483 color = colormapPaletteColor(floor(f / 16), 0);
5485 else if(hud_dock_color == "pants") {
5486 f = stof(getplayerkey(player_localentnum - 1, "colors"));
5487 color = colormapPaletteColor(mod(f, 16), 1);
5490 color = stov(hud_dock_color);
5494 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
5495 if(precache_pic(pic) == "") {
5496 pic = strcat(hud_skin_path, "/dock_medium");
5497 if(precache_pic(pic) == "") {
5498 pic = "gfx/hud/default/dock_medium";
5501 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...
5504 // cache the panel order into the panel_order array
5505 if(autocvar__hud_panelorder != hud_panelorder_prev) {
5506 for(i = 0; i < HUD_PANEL_NUM; ++i)
5507 panel_order[i] = -1;
5509 float p_num, warning;
5510 float argc = tokenize_console(autocvar__hud_panelorder);
5511 if (argc > HUD_PANEL_NUM)
5513 //first detect wrong/missing panel numbers
5514 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5515 p_num = stof(argv(i));
5516 if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
5517 if (panel_order[p_num] == -1) //found for the first time?
5518 s = strcat(s, ftos(p_num), " ");
5519 panel_order[p_num] = 1; //mark as found
5524 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5525 if (panel_order[i] == -1) {
5527 s = strcat(s, ftos(i), " "); //add missing panel number
5531 print("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
5533 cvar_set("_hud_panelorder", s);
5534 if(hud_panelorder_prev)
5535 strunzone(hud_panelorder_prev);
5536 hud_panelorder_prev = strzone(s);
5538 //now properly set panel_order
5539 tokenize_console(s);
5540 for(i = 0; i < HUD_PANEL_NUM; ++i) {
5541 panel_order[i] = stof(argv(i));
5545 // draw panels in order specified by panel_order array
5546 for(i = HUD_PANEL_NUM - 1; i >= 0; --i) {
5547 if(i != HUD_PANEL_CHAT || !autocvar__con_chat_maximized) // don't draw maximized chat panel twice!
5548 HUD_DrawPanel(panel_order[i]);
5551 // draw chat panel on top if it is maximized
5552 if(autocvar__con_chat_maximized)
5553 HUD_Chat(); // HUD_DrawPanel(HUD_PANEL_CHAT);
5555 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)
5556 localcmd("cmd selectteam auto; cmd join\n");
5558 if(autocvar__hud_configure && tab_panel != -1)
5560 HUD_Panel_UpdatePosSizeForId(tab_panel)
5561 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
5564 hud_configure_prev = autocvar__hud_configure;
5566 if (!autocvar__hud_configure) // hud config mode disabled, enable normal alpha stuff again