7 // a border picture is a texture containing nine parts:
8 // 1/4 width: left part
9 // 1/2 width: middle part (stretched)
10 // 1/4 width: right part
12 // 1/4 height: top part
13 // 1/2 height: middle part (stretched)
14 // 1/4 height: bottom part
15 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
17 if (theBorderSize_x <= 0 && theBorderSize_y <= 0) // no border
19 // draw only the central part
20 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
27 //pic = draw_UseSkinFor(pic);
28 width = eX * theSize_x;
29 height = eY * theSize_y;
30 if(theSize_x <= theBorderSize_x * 2)
32 // not wide enough... draw just left and right then
33 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
34 if(theSize_y <= theBorderSize_y * 2)
36 // not high enough... draw just corners
37 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
38 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
39 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
40 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
41 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
45 dY = theBorderSize_x * eY;
46 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
47 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
48 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
49 drawsubpic(theOrigin + width * 0.5 + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0' + eX - bW, '0 0.5 0' + bW, theColor, theAlpha, 0);
50 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
51 drawsubpic(theOrigin + width * 0.5 + height - dY, width * 0.5 + dY, pic, '0 0.75 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
56 if(theSize_y <= theBorderSize_y * 2)
58 // not high enough... draw just top and bottom then
59 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
60 dX = theBorderSize_x * eX;
61 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
62 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
63 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
64 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
65 drawsubpic(theOrigin + dX + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5 0 0' + bH, theColor, theAlpha, 0);
66 drawsubpic(theOrigin + width - dX + height * 0.5, dX + height * 0.5, pic, '0.75 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
70 dX = theBorderSize_x * eX;
71 dY = theBorderSize_x * eY;
72 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
73 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
74 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
75 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
76 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
77 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
78 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
79 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
80 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
85 vector HUD_Get_Num_Color (float x, float maxvalue)
93 else if(x > maxvalue * 0.75) {
94 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
95 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
98 else if(x > maxvalue * 0.5) {
99 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
100 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
101 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
103 else if(x > maxvalue * 0.25) {
106 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
108 else if(x > maxvalue * 0.1) {
110 color_y = (x-20)*90/27/100; // green value between 0 -> 1
111 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
121 float stringwidth_colors(string s, vector theSize)
123 return stringwidth(s, TRUE, theSize);
126 float stringwidth_nocolors(string s, vector theSize)
128 return stringwidth(s, FALSE, theSize);
131 #define CENTERPRINT_MAX_LINES 30
132 string centerprint_messages[CENTERPRINT_MAX_LINES];
133 float centerprint_width[CENTERPRINT_MAX_LINES];
134 vector centerprint_start;
135 float centerprint_expire;
136 float centerprint_num;
137 float centerprint_offset_hint;
138 vector centerprint_fontsize;
140 void centerprint(string strMessage)
142 float i, j, n, hcount;
145 centerprint_fontsize = HUD_GetFontsize("scr_centersize");
147 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
149 if(cvar("scr_centertime") <= 0)
155 // strip trailing newlines
156 j = strlen(strMessage) - 1;
157 while(substring(strMessage, j, 1) == "\n" && j >= 0)
159 strMessage = substring(strMessage, 0, j + 1);
164 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
166 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
168 strMessage = substring(strMessage, j, strlen(strMessage) - j);
169 centerprint_offset_hint = j;
174 // if we get here, we have a message. Initialize its height.
177 n = tokenizebyseparator(strMessage, "\n");
179 for(j = 0; j < n; ++j)
181 getWrappedLine_remaining = argv(j);
182 while(getWrappedLine_remaining)
184 s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
185 if(centerprint_messages[i])
186 strunzone(centerprint_messages[i]);
187 centerprint_messages[i] = strzone(s);
188 centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
191 // half height for empty lines looks better
197 if(i >= CENTERPRINT_MAX_LINES)
203 h = centerprint_fontsize_y*hcount;
205 havail = vid_conheight;
206 if(cvar("con_chatpos") < 0)
207 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
208 if(havail > vid_conheight - 70)
209 havail = vid_conheight - 70; // avoid overlapping HUD
211 centerprint_start_x = 0;
214 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
216 // here, the centerprint would cover the crosshair. REALLY BAD.
217 forbiddenmin = vid_conheight * 0.5 - h - 16;
218 forbiddenmax = vid_conheight * 0.5 + 16;
220 allowedmin = scoreboard_bottom;
221 allowedmax = havail - h;
222 preferred = (havail - h)/2;
225 // possible orderings (total: 4! / 4 = 6)
226 // allowedmin allowedmax forbiddenmin forbiddenmax
227 // forbiddenmin forbiddenmax allowedmin allowedmax
228 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
230 // forbidden doesn't matter in this case
231 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
233 // allowedmin forbiddenmin allowedmax forbiddenmax
234 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
236 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
238 // allowedmin forbiddenmin forbiddenmax allowedmax
239 else if(allowedmin < forbiddenmin)
241 // make sure the forbidden zone is not covered
242 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
243 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
245 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
247 // forbiddenmin allowedmin allowedmax forbiddenmax
248 else if(allowedmax < forbiddenmax)
250 // it's better to leave the allowed zone (overlap with scoreboard) than
251 // to cover the forbidden zone (crosshair)
252 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
253 centerprint_start_y = forbiddenmax;
255 centerprint_start_y = forbiddenmin;
257 // forbiddenmin allowedmin forbiddenmax allowedmax
260 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
263 centerprint_start_y =
266 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
274 centerprint_expire = time + cvar("scr_centertime");
277 void HUD_DrawCenterPrint (void)
284 //if(time > centerprint_expire)
287 //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
288 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
289 //sz = 1.2 / (a + 0.2);
294 pos = centerprint_start;
295 for (i=0; i<centerprint_num; i = i + 1)
297 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
298 ts = centerprint_messages[i];
301 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
302 drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
303 // - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
304 pos_y = pos_y + centerprint_fontsize_y;
307 // half height for empty lines looks better
308 pos_y = pos_y + centerprint_fontsize_y * 0.5;
312 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
314 position_x -= 2 / 3 * strlen(text) * scale_x;
315 drawstring(position, text, scale, rgb, alpha, flag);
318 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
320 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
321 drawstring(position, text, scale, rgb, alpha, flag);
324 // return the string of the given race place
325 string race_PlaceName(float pos) {
333 return strcat(ftos(pos), "th");
336 // return the string of the onscreen race timer
337 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
345 if(histime == 0) // goal hit
349 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
359 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
365 lapstr = strcat(" (-", ftos(lapdelta), "L)");
368 else if(lapdelta < 0)
370 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
374 else if(histime > 0) // anticipation
376 if(mytime >= histime)
377 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
379 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
386 cpname = "Start line";
388 cpname = "Finish line";
390 cpname = strcat("Intermediate ", ftos(cp));
392 cpname = "Finish line";
395 return strcat(col, cpname);
396 else if(hisname == "")
397 return strcat(col, cpname, " (", timestr, ")");
399 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
402 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
403 float race_CheckName(string net_name) {
405 for (i=RANKINGS_CNT-1;i>=0;--i)
406 if(grecordholder[i] == net_name)
418 void HUD_Panel_ExportCfg(string cfgname)
421 fh = fopen(strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg"), FILE_WRITE);
424 fputs(fh, strcat("seta hud_skin \"", cvar_string("hud_skin"), "\"", "\n"));
425 fputs(fh, strcat("seta hud_bg \"", cvar_string("hud_bg"), "\"", "\n"));
426 fputs(fh, strcat("seta hud_bg_color \"", cvar_string("hud_bg_color"), "\"", "\n"));
427 fputs(fh, strcat("seta hud_bg_color_team \"", cvar_string("hud_bg_color_team"), "\"", "\n"));
428 fputs(fh, strcat("seta hud_bg_alpha \"", cvar_string("hud_bg_alpha"), "\"", "\n"));
429 fputs(fh, strcat("seta hud_bg_border \"", cvar_string("hud_bg_border"), "\"", "\n"));
430 fputs(fh, strcat("seta hud_bg_padding \"", cvar_string("hud_bg_padding"), "\"", "\n"));
431 fputs(fh, strcat("seta hud_fg_alpha \"", cvar_string("hud_fg_alpha"), "\"", "\n"));
434 fputs(fh, strcat("seta hud_dock \"", cvar_string("hud_dock"), "\"", "\n"));
435 fputs(fh, strcat("seta hud_dock_color \"", cvar_string("hud_dock_color"), "\"", "\n"));
436 fputs(fh, strcat("seta hud_dock_color_team \"", cvar_string("hud_dock_color_team"), "\"", "\n"));
437 fputs(fh, strcat("seta hud_dock_alpha \"", cvar_string("hud_dock_alpha"), "\"", "\n"));
440 fputs(fh, strcat("seta hud_progressbar_alpha \"", cvar_string("hud_progressbar_alpha"), "\"", "\n"));
441 fputs(fh, strcat("seta hud_progressbar_strength_color \"", cvar_string("hud_progressbar_strength_color"), "\"", "\n"));
442 fputs(fh, strcat("seta hud_progressbar_shield_color \"", cvar_string("hud_progressbar_shield_color"), "\"", "\n"));
443 fputs(fh, strcat("seta hud_progressbar_health_color \"", cvar_string("hud_progressbar_health_color"), "\"", "\n"));
444 fputs(fh, strcat("seta hud_progressbar_armor_color \"", cvar_string("hud_progressbar_armor_color"), "\"", "\n"));
445 fputs(fh, strcat("seta hud_progressbar_fuel_color \"", cvar_string("hud_progressbar_fuel_color"), "\"", "\n"));
446 fputs(fh, strcat("seta hud_progressbar_nexball_color \"", cvar_string("hud_progressbar_nexball_color"), "\"", "\n"));
449 fputs(fh, strcat("seta _hud_panelorder \"", cvar_string("_hud_panelorder"), "\"", "\n"));
452 // common cvars for all panels
454 for (i = 0; i < HUD_PANEL_NUM; ++i)
458 fputs(fh, strcat("seta hud_", panel_name, " ", cvar_string(strcat("hud_", panel_name)), "\n"));
459 fputs(fh, strcat("seta hud_", panel_name, "_pos \"", cvar_string(strcat("hud_", panel_name, "_pos")), "\"", "\n"));
460 fputs(fh, strcat("seta hud_", panel_name, "_size \"", cvar_string(strcat("hud_", panel_name, "_size")), "\"", "\n"));
461 fputs(fh, strcat("seta hud_", panel_name, "_bg \"", cvar_string(strcat("hud_", panel_name, "_bg")), "\"", "\n"));
462 fputs(fh, strcat("seta hud_", panel_name, "_bg_color \"", cvar_string(strcat("hud_", panel_name, "_bg_color")), "\"", "\n"));
463 fputs(fh, strcat("seta hud_", panel_name, "_bg_color_team \"", cvar_string(strcat("hud_", panel_name, "_bg_color_team")), "\"", "\n"));
464 fputs(fh, strcat("seta hud_", panel_name, "_bg_alpha \"", cvar_string(strcat("hud_", panel_name, "_bg_alpha")), "\"", "\n"));
465 fputs(fh, strcat("seta hud_", panel_name, "_bg_border \"", cvar_string(strcat("hud_", panel_name, "_bg_border")), "\"", "\n"));
466 fputs(fh, strcat("seta hud_", panel_name, "_bg_padding \"", cvar_string(strcat("hud_", panel_name, "_bg_padding")), "\"", "\n"));
468 case HUD_PANEL_WEAPONICONS:
469 fputs(fh, strcat("seta hud_", panel_name, "_complainbubble \"", cvar_string(strcat("hud_", panel_name, "_complainbubble")), "\"", "\n"));
470 fputs(fh, strcat("seta hud_", panel_name, "_complainbubble_padding \"", cvar_string(strcat("hud_", panel_name, "_complainbubble_padding")), "\"", "\n"));
472 case HUD_PANEL_INVENTORY:
473 fputs(fh, strcat("seta hud_", panel_name, "_onlycurrent \"", cvar_string(strcat("hud_", panel_name, "_onlycurrent")), "\"", "\n"));
474 fputs(fh, strcat("seta hud_", panel_name, "_iconalign \"", cvar_string(strcat("hud_", panel_name, "_iconalign")), "\"", "\n"));
476 case HUD_PANEL_POWERUPS:
477 fputs(fh, strcat("seta hud_", panel_name, "_flip \"", cvar_string(strcat("hud_", panel_name, "_flip")), "\"", "\n"));
478 fputs(fh, strcat("seta hud_", panel_name, "_iconalign \"", cvar_string(strcat("hud_", panel_name, "_iconalign")), "\"", "\n"));
479 fputs(fh, strcat("seta hud_", panel_name, "_baralign \"", cvar_string(strcat("hud_", panel_name, "_baralign")), "\"", "\n"));
481 case HUD_PANEL_HEALTHARMOR:
482 fputs(fh, strcat("seta hud_", panel_name, "_flip \"", cvar_string(strcat("hud_", panel_name, "_flip")), "\n"));
483 fputs(fh, strcat("seta hud_", panel_name, "_iconalign \"", cvar_string(strcat("hud_", panel_name, "_iconalign")), "\"", "\n"));
484 fputs(fh, strcat("seta hud_", panel_name, "_baralign \"", cvar_string(strcat("hud_", panel_name, "_baralign")), "\"", "\n"));
486 case HUD_PANEL_NOTIFY:
487 fputs(fh, strcat("seta hud_", panel_name, "_flip \"", cvar_string(strcat("hud_", panel_name, "_flip")), "\"", "\n"));
488 fputs(fh, strcat("seta hud_", panel_name, "_print \"", cvar_string(strcat("hud_", panel_name, "_print")), "\"", "\n"));
490 case HUD_PANEL_RADAR:
491 fputs(fh, strcat("seta hud_", panel_name, "_foreground_alpha \"", cvar_string(strcat("hud_", panel_name, "_foreground_alpha")), "\"", "\n"));
494 fputs(fh, strcat("seta hud_", panel_name, "_alreadyvoted_alpha \"", cvar_string(strcat("hud_", panel_name, "_alreadyvoted_alpha")), "\"", "\n"));
500 print("^2Successfully exported to hud_", autocvar_hud_skin, "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
505 const float hlBorderSize = 4;
506 const string hlBorder = "gfx/hud/default/border_highlighted";
507 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
508 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
510 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
511 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);
512 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);
513 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);
514 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);
517 // draw the background/borders
518 #define HUD_Panel_DrawBg(alpha)\
520 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));\
521 if(highlightedPanel_prev == active_panel && autocvar__hud_configure)\
522 HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha) * alpha);
524 void HUD_Panel_DrawProgressBar(vector pos, float vertical, vector mySize, vector color, float alpha, float drawflag)
531 pic = strcat(hud_skin_path, "/statusbar_vertical");
532 if(precache_pic(pic) == "") {
533 pic = "gfx/hud/default/statusbar_vertical";
535 drawsubpic(pos, eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, pic, '0 0 0', '1 0.25 0', color, alpha, drawflag);
536 if(mySize_y/mySize_x > 2)
537 drawsubpic(pos + eY * mySize_x, eY * (mySize_y - 2 * mySize_x) + eX * mySize_x, pic, '0 0.25 0', '1 0.5 0', color, alpha, drawflag);
538 drawsubpic(pos + eY * mySize_y - eY * min(mySize_y * 0.5, mySize_x), eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, pic, '0 0.75 0', '1 0.25 0', color, alpha, drawflag);
540 pic = strcat(hud_skin_path, "/statusbar");
541 if(precache_pic(pic) == "") {
542 pic = "gfx/hud/default/statusbar";
544 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
545 if(mySize_x/mySize_y > 2)
546 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);
547 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);
551 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
557 pic = strcat(hud_skin_path, "/num_leading");
558 if(precache_pic(pic) == "") {
559 pic = "gfx/hud/default/num_leading";
562 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
563 if(mySize_x/mySize_y > 2)
564 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);
565 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);
568 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
569 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
580 myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
581 targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
583 for (i = 0; i < HUD_PANEL_NUM; ++i) {
584 if(i == highlightedPanel || !panel_enabled)
587 HUD_Panel_UpdatePosSizeForId(i)
589 panel_pos -= '1 1 0' * panel_bg_border;
590 panel_size += '2 2 0' * panel_bg_border;
592 if(myPos_y + mySize_y < panel_pos_y)
594 if(myPos_y > panel_pos_y + panel_size_y)
597 if(myPos_x + mySize_x < panel_pos_x)
599 if(myPos_x > panel_pos_x + panel_size_x)
602 // OK, there IS a collision.
604 myCenter_x = myPos_x + 0.5 * mySize_x;
605 myCenter_y = myPos_y + 0.5 * mySize_y;
607 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
608 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
610 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
612 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
613 myTarget_x = panel_pos_x - mySize_x;
614 else // push it upwards
615 myTarget_y = panel_pos_y - mySize_y;
617 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
619 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
620 myTarget_x = panel_pos_x + panel_size_x;
621 else // push it upwards
622 myTarget_y = panel_pos_y - mySize_y;
624 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
626 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
627 myTarget_x = panel_pos_x - mySize_x;
628 else // push it downwards
629 myTarget_y = panel_pos_y + panel_size_y;
631 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
633 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
634 myTarget_x = panel_pos_x + panel_size_x;
635 else // push it downwards
636 myTarget_y = panel_pos_y + panel_size_y;
638 if(cvar("hud_configure_checkcollisions_debug"))
639 drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
645 void HUD_Panel_SetPos(vector pos)
647 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
651 if(cvar("hud_configure_checkcollisions_debug"))
652 drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
654 if(autocvar_hud_configure_grid)
656 pos_x = floor((pos_x/vid_conwidth)/bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) + 0.5) * bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
657 pos_y = floor((pos_y/vid_conheight)/bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) + 0.5) * bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
660 if(hud_configure_checkcollisions)
661 pos = HUD_Panel_CheckMove(pos, mySize);
663 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
664 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
667 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
669 HUD_Panel_GetName(highlightedPanel);
670 cvar_set(strcat("hud_", panel_name, "_pos"), s);
673 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
674 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
684 ratio = mySize_x/mySize_y;
686 for (i = 0; i < HUD_PANEL_NUM; ++i) {
687 if(i == highlightedPanel || !panel_enabled)
690 HUD_Panel_UpdatePosSizeForId(i)
692 panel_pos -= '1 1 0' * panel_bg_border;
693 panel_size += '2 2 0' * panel_bg_border;
695 targEndPos = panel_pos + panel_size;
697 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
698 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
701 if (resizeCorner == 1)
703 // check if this panel is on our way
704 if (resizeorigin_x <= panel_pos_x)
706 if (resizeorigin_y <= panel_pos_y)
708 if (targEndPos_x <= resizeorigin_x - mySize_x)
710 if (targEndPos_y <= resizeorigin_y - mySize_y)
713 // there is a collision:
714 // detect which side of the panel we are facing is actually limiting the resizing
715 // (which side the resize direction finds for first) and reduce the size up to there
717 // dist is the distance between resizeorigin and the "analogous" point of the panel
718 // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
719 dist_x = resizeorigin_x - targEndPos_x;
720 dist_y = resizeorigin_y - targEndPos_y;
721 if (dist_y <= 0 || dist_x / dist_y > ratio)
722 mySize_x = min(mySize_x, dist_x);
724 mySize_y = min(mySize_y, dist_y);
726 else if (resizeCorner == 2)
728 if (resizeorigin_x >= targEndPos_x)
730 if (resizeorigin_y <= panel_pos_y)
732 if (panel_pos_x >= resizeorigin_x + mySize_x)
734 if (targEndPos_y <= resizeorigin_y - mySize_y)
737 dist_x = panel_pos_x - resizeorigin_x;
738 dist_y = resizeorigin_y - targEndPos_y;
739 if (dist_y <= 0 || dist_x / dist_y > ratio)
740 mySize_x = min(mySize_x, dist_x);
742 mySize_y = min(mySize_y, dist_y);
744 else if (resizeCorner == 3)
746 if (resizeorigin_x <= panel_pos_x)
748 if (resizeorigin_y >= targEndPos_y)
750 if (targEndPos_x <= resizeorigin_x - mySize_x)
752 if (panel_pos_y >= resizeorigin_y + mySize_y)
755 dist_x = resizeorigin_x - targEndPos_x;
756 dist_y = panel_pos_y - resizeorigin_y;
757 if (dist_y <= 0 || dist_x / dist_y > ratio)
758 mySize_x = min(mySize_x, dist_x);
760 mySize_y = min(mySize_y, dist_y);
762 else if (resizeCorner == 4)
764 if (resizeorigin_x >= targEndPos_x)
766 if (resizeorigin_y >= targEndPos_y)
768 if (panel_pos_x >= resizeorigin_x + mySize_x)
770 if (panel_pos_y >= resizeorigin_y + mySize_y)
773 dist_x = panel_pos_x - resizeorigin_x;
774 dist_y = panel_pos_y - resizeorigin_y;
775 if (dist_y <= 0 || dist_x / dist_y > ratio)
776 mySize_x = min(mySize_x, dist_x);
778 mySize_y = min(mySize_y, dist_y);
780 if(cvar("hud_configure_checkcollisions_debug"))
781 drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
787 void HUD_Panel_SetPosSize(vector mySize)
789 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
791 resizeorigin = panel_click_resizeorigin;
794 // minimum panel size cap
795 mySize_x = max(0.025 * vid_conwidth, mySize_x);
796 mySize_y = max(0.025 * vid_conheight, mySize_y);
798 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.
800 mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
801 mySize_y = max(2 * cvar("con_chatsize") + 2 * panel_bg_padding, mySize_y);
804 // collision testing|
805 // -----------------+
807 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
808 if(resizeCorner == 1) {
809 myPos_x = resizeorigin_x - mySize_x;
810 myPos_y = resizeorigin_y - mySize_y;
811 } else if(resizeCorner == 2) {
812 myPos_x = resizeorigin_x;
813 myPos_y = resizeorigin_y - mySize_y;
814 } else if(resizeCorner == 3) {
815 myPos_x = resizeorigin_x - mySize_x;
816 myPos_y = resizeorigin_y;
817 } else { // resizeCorner == 4
818 myPos_x = resizeorigin_x;
819 myPos_y = resizeorigin_y;
822 // left/top screen edges
824 mySize_x = mySize_x + myPos_x;
826 mySize_y = mySize_y + myPos_y;
828 // bottom/right screen edges
829 if(myPos_x + mySize_x > vid_conwidth)
830 mySize_x = vid_conwidth - myPos_x;
831 if(myPos_y + mySize_y > vid_conheight)
832 mySize_y = vid_conheight - myPos_y;
834 if(cvar("hud_configure_checkcollisions_debug"))
835 drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
837 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
838 if(autocvar_hud_configure_grid)
840 mySize_x = floor((mySize_x/vid_conwidth)/bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) + 0.5) * bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
841 mySize_y = floor((mySize_y/vid_conheight)/bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) + 0.5) * bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
844 if(hud_configure_checkcollisions)
845 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
847 // 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)
848 mySize_x = max(0.025 * vid_conwidth, mySize_x);
849 mySize_y = max(0.025 * vid_conheight, mySize_y);
851 // do another pos check, as size might have changed by now
852 if(resizeCorner == 1) {
853 myPos_x = resizeorigin_x - mySize_x;
854 myPos_y = resizeorigin_y - mySize_y;
855 } else if(resizeCorner == 2) {
856 myPos_x = resizeorigin_x;
857 myPos_y = resizeorigin_y - mySize_y;
858 } else if(resizeCorner == 3) {
859 myPos_x = resizeorigin_x - mySize_x;
860 myPos_y = resizeorigin_y;
861 } else { // resizeCorner == 4
862 myPos_x = resizeorigin_x;
863 myPos_y = resizeorigin_y;
866 if(cvar("hud_configure_checkcollisions_debug"))
867 drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
869 HUD_Panel_GetName(highlightedPanel);
871 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
872 cvar_set(strcat("hud_", panel_name, "_size"), s);
874 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
875 cvar_set(strcat("hud_", panel_name, "_pos"), s);
879 float prevMouseClicked; // previous state
880 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
881 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
884 float menu_enabled_time;
885 float pressed_key_time;
886 void HUD_Panel_Arrow_Action(float nPrimary)
888 if (highlightedPanel_prev == -1 || mouseClicked)
891 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
894 if(autocvar_hud_configure_grid)
896 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
898 if (hudShiftState & S_SHIFT)
899 step = bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
901 step = 2 * bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
905 if (hudShiftState & S_SHIFT)
906 step = bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
908 step = 2 * bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
913 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
914 step = vid_conheight;
917 if (hudShiftState & S_SHIFT)
918 step = (step / 256); // more precision
920 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
923 highlightedPanel = highlightedPanel_prev;
925 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
927 if (hudShiftState & S_ALT) // resize
929 highlightedAction = 1;
930 if(nPrimary == K_UPARROW)
932 else if(nPrimary == K_RIGHTARROW)
934 else if(nPrimary == K_LEFTARROW)
936 else // if(nPrimary == K_DOWNARROW)
939 // ctrl+arrow reduces the size, instead of increasing it
940 // Note that ctrl disables collisions check too, but it's fine
941 // since we don't collide with anything reducing the size
942 if (hudShiftState & S_CTRL) {
944 resizeCorner = 5 - resizeCorner;
949 panel_click_resizeorigin = panel_pos;
950 if(resizeCorner == 1) {
951 panel_click_resizeorigin += mySize;
953 } else if(resizeCorner == 2) {
954 panel_click_resizeorigin_y += mySize_y;
956 } else if(resizeCorner == 3) {
957 panel_click_resizeorigin_x += mySize_x;
959 } else { // resizeCorner == 4
962 HUD_Panel_SetPosSize(mySize);
966 highlightedAction = 2;
969 if(nPrimary == K_UPARROW)
971 else if(nPrimary == K_DOWNARROW)
973 else if(nPrimary == K_LEFTARROW)
975 else // if(nPrimary == K_RIGHTARROW)
978 HUD_Panel_SetPos(pos);
982 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
984 if(!autocvar__hud_configure)
987 // allow console bind to work
990 con_keys = findkeysforcommand("toggleconsole");
991 keys = tokenize(con_keys);
993 float hit_con_bind, i;
994 for (i = 0; i < keys; ++i)
996 if(nPrimary == stof(argv(i)))
1000 if(bInputType == 0) {
1001 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
1002 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
1003 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
1005 else if(bInputType == 1) {
1006 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
1007 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
1008 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
1011 if(nPrimary == K_MOUSE1)
1013 if(bInputType == 0) { // key pressed
1017 else if(bInputType == 1) {// key released
1022 else if(nPrimary == K_ESCAPE)
1024 if (bInputType == 1)
1026 disable_menu_alphacheck = 1;
1028 menu_enabled_time = time;
1029 localcmd("menu_showhudexit\n");
1031 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
1033 if (bInputType == 1)
1035 pressed_key_time = 0;
1038 else if (pressed_key_time == 0)
1039 pressed_key_time = time;
1041 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
1043 else if(hit_con_bind)
1046 return true; // Suppress ALL other input
1049 float HUD_Panel_HighlightCheck()
1055 while(j <= HUD_PANEL_NUM)
1060 HUD_Panel_UpdatePosSizeForId(i)
1062 panelPos = panel_pos;
1063 panelSize = panel_size;
1064 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1067 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1071 // resize from topleft border
1072 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1076 // resize from topright border
1077 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1081 // resize from bottomleft border
1082 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + panelSize_y + border)
1086 // resize from bottomright border
1087 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + panelSize_y + border)
1095 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
1096 void HUD_Panel_FirstInDrawQ(float id)
1099 var float place = -1;
1100 // find out where in the array our current id is, save into place
1101 for(i = 0; i < HUD_PANEL_NUM; ++i)
1103 if(panel_order[i] == id)
1109 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
1111 place = HUD_PANEL_NUM - 1;
1113 // move all ids up by one step in the array until "place"
1114 for(i = place; i > 0; --i)
1116 panel_order[i] = panel_order[i-1];
1118 // now save the new top id
1119 panel_order[0] = id;
1121 // let's save them into the cvar by some strcat trickery
1123 for(i = 0; i < HUD_PANEL_NUM; ++i)
1125 s = strcat(s, ftos(panel_order[i]), " ");
1127 cvar_set("_hud_panelorder", s);
1128 if(hud_panelorder_prev)
1129 strunzone(hud_panelorder_prev);
1130 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
1133 void HUD_Panel_Highlight()
1139 while(j <= HUD_PANEL_NUM)
1144 HUD_Panel_UpdatePosSizeForId(i)
1146 panelPos = panel_pos;
1147 panelSize = panel_size;
1148 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1151 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1153 highlightedPanel = i;
1154 HUD_Panel_FirstInDrawQ(i);
1155 highlightedAction = 1;
1156 panel_click_distance = mousepos - panelPos;
1159 // resize from topleft border
1160 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1162 highlightedPanel = i;
1163 HUD_Panel_FirstInDrawQ(i);
1164 highlightedAction = 2;
1166 panel_click_distance = mousepos - panelPos;
1167 panel_click_resizeorigin = panelPos + panelSize;
1170 // resize from topright border
1171 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1173 highlightedPanel = i;
1174 HUD_Panel_FirstInDrawQ(i);
1175 highlightedAction = 2;
1177 panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
1178 panel_click_distance_y = mousepos_y - panelPos_y;
1179 panel_click_resizeorigin = panelPos + eY * panelSize_y;
1182 // resize from bottomleft border
1183 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + panelSize_y + border)
1185 highlightedPanel = i;
1186 HUD_Panel_FirstInDrawQ(i);
1187 highlightedAction = 2;
1189 panel_click_distance_x = mousepos_x - panelPos_x;
1190 panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
1191 panel_click_resizeorigin = panelPos + eX * panelSize_x;
1194 // resize from bottomright border
1195 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + panelSize_y + border)
1197 highlightedPanel = i;
1198 HUD_Panel_FirstInDrawQ(i);
1199 highlightedAction = 2;
1201 panel_click_distance = panelSize - mousepos + panelPos;
1202 panel_click_resizeorigin = panelPos;
1207 highlightedPanel_prev = -1;
1212 float highlightcheck;
1213 void HUD_Panel_Mouse()
1215 // 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
1216 if (menu_enabled == 0) // menu dialog closed, enable normal alpha stuff again
1217 disable_menu_alphacheck = 0;
1218 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1222 print("Disable menu_alphacheck: ", ftos(disable_menu_alphacheck), "\n");
1223 print("Highlighted: ", ftos(highlightedPanel), "\n");
1224 print("Menu alpha: ", cvar_string("_menu_alpha"), "\n");
1227 if(mouseClicked == 0 && disable_menu_alphacheck != 2 && highlightedPanel >= 0) { // don't reset these variables in disable_menu_alphacheck mode 2!
1228 highlightedPanel = -1;
1229 highlightedAction = 0;
1231 if(highlightedPanel != -1)
1232 highlightedPanel_prev = highlightedPanel;
1234 mousepos = mousepos + getmousepos();
1236 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1237 mousepos_y = bound(0, mousepos_y, vid_conheight);
1241 if(prevMouseClicked == 0)
1242 HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1244 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1246 if(highlightedAction == 1)
1247 HUD_Panel_SetPos(mousepos - panel_click_distance);
1248 else if(highlightedAction == 2)
1251 if(resizeCorner == 1) {
1252 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1253 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1254 } else if(resizeCorner == 2) {
1255 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1256 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1257 } else if(resizeCorner == 3) {
1258 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1259 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1260 } else { // resizeCorner == 4
1261 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1262 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1264 HUD_Panel_SetPosSize(mySize);
1267 // doubleclick check
1268 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1270 mouseClicked = 0; // to prevent spam, I guess.
1271 disable_menu_alphacheck = 2;
1273 menu_enabled_time = time;
1274 HUD_Panel_GetName(highlightedPanel)
1275 localcmd("menu_showhudoptions ", panel_name, "\n");
1278 if(prevMouseClicked == 0)
1280 prevMouseClickedTime = time;
1281 prevMouseClickedPos = mousepos;
1286 highlightcheck = HUD_Panel_HighlightCheck();
1288 // draw cursor after performing move/resize to have the panel pos/size updated before highlightcheck
1291 cursorsize = '32 32 0';
1293 if(highlightcheck == 0)
1294 drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1295 else if(highlightcheck == 1)
1296 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_move.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1297 else if(highlightcheck == 2)
1298 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_resize.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1300 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_resize2.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1302 prevMouseClicked = mouseClicked;
1305 // Weapon icons (#0)
1307 float weaponspace[10];
1308 #define HUD_WeaponIcons_Clear()\
1310 for(idx = 0; idx < 10; ++idx)\
1311 weaponspace[idx] = 0;
1313 entity weaponorder[WEP_MAXCOUNT];
1314 void weaponorder_swap(float i, float j, entity pass)
1318 weaponorder[i] = weaponorder[j];
1322 string weaponorder_cmp_str_save;
1323 string weaponorder_cmp_str;
1324 float weaponorder_cmp(float i, float j, entity pass)
1327 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1328 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1329 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)
1332 void HUD_WeaponIcons(void)
1334 if(!autocvar_hud_weaponicons && !autocvar__hud_configure)
1337 float id = HUD_PANEL_WEAPONICONS;
1338 HUD_Panel_UpdateCvarsForId(id);
1339 float alpha, stat_weapons; // "constants"
1341 float i, weapid, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1344 mySize = panel_size;
1346 stat_weapons = getstati(STAT_WEAPONS);
1348 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1350 self = get_weaponinfo(i);
1351 if(self.impulse >= 0)
1355 // TODO make this configurable
1356 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1358 if(weaponorder_cmp_str != weaponorder_cmp_str_save)
1360 if(weaponorder_cmp_str_save)
1361 strunzone(weaponorder_cmp_str_save);
1362 weaponorder_cmp_str_save = strzone(weaponorder_cmp_str);
1364 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1366 self = get_weaponinfo(i);
1367 if(self.impulse >= 0)
1369 weaponorder[weapon_cnt] = self;
1373 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1376 HUD_Panel_DrawBg(1);
1377 if(panel_bg_padding)
1379 pos += '1 1 0' * panel_bg_padding;
1380 mySize -= '2 2 0' * panel_bg_padding;
1384 weapon_stats = getstati(STAT_DAMAGE_HITS);
1385 weapon_number = weapon_stats & 63;
1386 weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1388 weapon_stats = getstati(STAT_DAMAGE_FIRED);
1389 weapon_number = weapon_stats & 63;
1390 weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1392 if(cvar_or("hud_weaponicons_fade", 1))
1394 fade = 3.2 - 2 * (time - weapontime);
1395 fade = bound(0.7, fade, 1);
1400 HUD_WeaponIcons_Clear();
1402 float rows, columns;
1403 rows = mySize_y/mySize_x;
1404 rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1405 // ^^^ weapon icon aspect goes here
1407 columns = ceil(WEP_COUNT/rows);
1412 when = autocvar_hud_weaponicons_complainbubble_time;
1414 fadetime = autocvar_hud_weaponicons_complainbubble_fadetime;
1417 for(i = 0; i < weapon_cnt; ++i)
1419 self = weaponorder[i];
1420 weapid = self.impulse;
1422 alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1424 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1425 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1427 // draw background behind currently selected weapon
1428 if(self.weapon == activeweapon)
1429 drawpic_aspect_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "weapon_current_bg", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL);
1431 // draw the weapon accuracy on the HUD
1432 if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1435 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1437 // yellow_accuracy = value at which accuracy becomes yellow
1438 if(weapon_stats >= 100) {
1442 else if(weapon_stats > autocvar_hud_weaponicons_accuracy_yellow) {
1443 color_x = 1 - (weapon_stats-autocvar_hud_weaponicons_accuracy_yellow)/(100-autocvar_hud_weaponicons_accuracy_yellow); // red value between 1 -> 0
1447 color_y = weapon_stats/autocvar_hud_weaponicons_accuracy_yellow; // green value between 0 -> 1
1451 drawpic_aspect_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "weapon_accuracy", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), color, panel_fg_alpha, DRAWFLAG_NORMAL);
1454 // draw the weapon icon
1455 if((self.impulse >= 0) && (stat_weapons & self.weapons))
1457 drawpic_aspect_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL);
1459 if(autocvar_hud_weaponicons_number == 1) // weapon number
1460 drawstring(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), ftos(weapid), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1461 else if(autocvar_hud_weaponicons_number == 2) // bind
1462 drawstring(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1465 // draw a "ghost weapon icon" if you don't have the weapon
1468 drawpic_aspect_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
1471 // draw the complain message
1472 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_weaponicons_complainbubble)
1476 if(complain_weapon_time + when > time)
1479 a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
1483 if(complain_weapon_time + when > time)
1490 if(complain_weapon_type == 0) {
1494 else if(complain_weapon_type == 1) {
1502 drawpic_aspect_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows) + '1 1 0' * autocvar_hud_weaponicons_complainbubble_padding, "weapon_complainbubble", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows) - '2 2 0' * autocvar_hud_weaponicons_complainbubble_padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
1503 drawstring_aspect(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows) + '1 1 0' * autocvar_hud_weaponicons_complainbubble_padding, s, eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows) - '2 2 0' * autocvar_hud_weaponicons_complainbubble_padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
1519 float GetAmmoStat(float i)
1523 case 0: return STAT_SHELLS;
1524 case 1: return STAT_NAILS;
1525 case 2: return STAT_ROCKETS;
1526 case 3: return STAT_CELLS;
1527 case 4: return STAT_FUEL;
1532 float GetAmmoItemCode(float i)
1536 case 0: return IT_SHELLS;
1537 case 1: return IT_NAILS;
1538 case 2: return IT_ROCKETS;
1539 case 3: return IT_CELLS;
1540 case 4: return IT_FUEL;
1545 string GetAmmoPicture(float i)
1549 case 0: return "ammo_shells";
1550 case 1: return "ammo_bullets";
1551 case 2: return "ammo_rockets";
1552 case 3: return "ammo_cells";
1553 case 4: return "ammo_fuel";
1558 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
1561 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
1562 if(autocvar__hud_configure)
1572 if(currently_selected)
1577 vector newSize, newPos;
1578 if(mySize_x/mySize_y > 3)
1580 newSize_x = 3 * mySize_y;
1581 newSize_y = mySize_y;
1583 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1588 newSize_y = 1/3 * mySize_x;
1589 newSize_x = mySize_x;
1591 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1595 vector picpos, numpos;
1596 if(autocvar_hud_inventory_iconalign)
1599 picpos = newPos + eX * 2 * newSize_y;
1603 numpos = newPos + eX * newSize_y;
1607 if (currently_selected)
1608 drawpic_aspect_skin(newPos, "ammo_current_bg", newSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1610 drawfont = hud_bigfont;
1611 drawstring_aspect(numpos, ftos(a), eX * (2/3) * newSize_x + eY * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1612 drawfont = hud_font;
1613 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1616 void HUD_Inventory(void)
1618 if(!autocvar_hud_inventory && !autocvar__hud_configure)
1621 float id = HUD_PANEL_INVENTORY;
1622 HUD_Panel_UpdateCvarsForId(id);
1623 float i, currently_selected;
1627 mySize = panel_size;
1629 HUD_Panel_DrawBg(1);
1630 if(panel_bg_padding)
1632 pos += '1 1 0' * panel_bg_padding;
1633 mySize -= '2 2 0' * panel_bg_padding;
1636 float rows, columns;
1637 rows = mySize_y/mySize_x;
1638 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
1639 // ^^^ ammo item aspect goes here
1641 columns = ceil(AMMO_COUNT/rows);
1645 for (i = 0; i < AMMO_COUNT; ++i) {
1646 currently_selected = getstati(STAT_ITEMS) & GetAmmoItemCode(i);
1647 if(autocvar_hud_inventory_onlycurrent) {
1648 if(autocvar__hud_configure)
1650 if (currently_selected || autocvar__hud_configure)
1652 DrawAmmoItem(pos, mySize, i, currently_selected);
1656 DrawAmmoItem(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), i, currently_selected);
1661 column = column + 1;
1667 void DrawNumIcon(float iconalign, vector myPos, vector mySize, float x, string icon, float left, vector color, float alpha)
1669 vector newSize, newPos;
1670 if(mySize_x/mySize_y > 3)
1672 newSize_x = 3 * mySize_y;
1673 newSize_y = mySize_y;
1675 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1680 newSize_y = 1/3 * mySize_x;
1681 newSize_x = mySize_x;
1683 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1687 vector picpos, numpos;
1690 if(iconalign == 1 || iconalign == 3) // right align
1693 picpos = newPos + eX * 2 * newSize_y;
1697 numpos = newPos + eX * newSize_y;
1703 if(iconalign == 0 || iconalign == 3) // left align
1705 numpos = newPos + eX * newSize_y;
1711 picpos = newPos + eX * 2 * newSize_y;
1715 drawfont = hud_bigfont;
1716 drawstring_aspect(numpos, ftos(x), eX * (2/3) * newSize_x + eY * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1717 drawfont = hud_font;
1718 drawpic_aspect_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1721 void DrawNumIcon_expanding(float iconalign, vector myPos, vector mySize, float x, string icon, float left, vector color, float fadelerp)
1724 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
1726 DrawNumIcon(iconalign, myPos + expandingbox_resize_centered_box_offset(sz, mySize, 1), mySize * sz, x, icon, left, color, (1 - fadelerp));
1731 void HUD_Powerups(void) {
1732 if(!autocvar_hud_powerups && !autocvar__hud_configure)
1735 float id = HUD_PANEL_POWERUPS;
1736 HUD_Panel_UpdateCvarsForId(id);
1738 stat_items = getstati(STAT_ITEMS);
1740 if(!autocvar__hud_configure)
1742 if not(stat_items & IT_STRENGTH)
1743 if not(stat_items & IT_INVINCIBLE)
1746 if (getstati(STAT_HEALTH) <= 0)
1752 mySize = panel_size;
1754 float strength_time, shield_time;
1756 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1757 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1759 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
1760 if(panel_bg_padding)
1762 pos += '1 1 0' * panel_bg_padding;
1763 mySize -= '2 2 0' * panel_bg_padding;
1766 if(autocvar__hud_configure)
1772 vector barpos, barsize;
1776 string leftname, rightname;
1777 float leftcnt, rightcnt;
1778 float leftexact, rightexact;
1779 if (autocvar_hud_powerups_flip) {
1780 leftname = "strength";
1781 leftcnt = ceil(strength_time);
1782 leftexact = strength_time;
1784 rightname = "shield";
1785 rightcnt = ceil(shield_time);
1786 rightexact = shield_time;
1788 leftname = "shield";
1789 leftcnt = ceil(shield_time);
1790 leftexact = shield_time;
1792 rightname = "strength";
1793 rightcnt = ceil(strength_time);
1794 rightexact = strength_time;
1797 drawfont = hud_bigfont;
1798 if (mySize_x/mySize_y > 4)
1802 if(autocvar_hud_powerups_baralign == 1 || autocvar_hud_powerups_baralign == 3) { // right align
1803 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/30);
1804 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1805 } else { // left align
1807 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1810 HUD_Panel_GetProgressBarColor(leftname)
1811 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
1813 DrawNumIcon(autocvar_hud_powerups_iconalign, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, '1 1 1', 1);
1815 DrawNumIcon_expanding(autocvar_hud_powerups_iconalign, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
1820 if(autocvar_hud_powerups_baralign == 0 || autocvar_hud_powerups_baralign == 3) { // left align
1821 barpos = pos + eX * 0.5 * mySize_x;
1822 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1823 } else { // right align
1824 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30);
1825 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1828 HUD_Panel_GetProgressBarColor(rightname)
1829 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
1831 DrawNumIcon(autocvar_hud_powerups_iconalign, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, '1 1 1', 1);
1833 DrawNumIcon_expanding(autocvar_hud_powerups_iconalign, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
1836 else if (mySize_x/mySize_y > 1.5)
1840 if(autocvar_hud_powerups_baralign == 1 || autocvar_hud_powerups_baralign == 3) { // right align
1841 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/30);
1842 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1843 } else { // left align
1845 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1848 HUD_Panel_GetProgressBarColor(leftname)
1849 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
1851 DrawNumIcon(autocvar_hud_powerups_iconalign, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, '1 1 1', 1);
1853 DrawNumIcon_expanding(autocvar_hud_powerups_iconalign, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
1858 if(autocvar_hud_powerups_baralign == 0 || autocvar_hud_powerups_baralign == 3) { // left align
1859 barpos = pos + eY * 0.5 * mySize_y;
1860 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1861 } else { // right align
1862 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1863 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1866 HUD_Panel_GetProgressBarColor(rightname)
1867 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
1869 DrawNumIcon(autocvar_hud_powerups_iconalign, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, '1 1 1', 1);
1871 DrawNumIcon_expanding(autocvar_hud_powerups_iconalign, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
1878 if(autocvar_hud_powerups_baralign == 1 || autocvar_hud_powerups_baralign == 3) { // down align
1879 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30);
1880 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1881 } else { // up align
1883 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1886 if(autocvar_hud_powerups_iconalign == 1 || autocvar_hud_powerups_iconalign == 3) { // down align
1887 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x);
1888 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x;
1889 } else { // up align
1890 picpos = pos + eX * 0.05 * mySize_x;
1891 numpos = pos + eY * 0.4 * mySize_x;
1894 HUD_Panel_GetProgressBarColor(leftname)
1895 HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
1897 drawpic_aspect_skin_expanding(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, bound(0, (leftcnt - leftexact) / 0.5, 1));
1899 drawpic_aspect_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1900 drawstring_aspect(numpos, ftos(leftcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1905 if(autocvar_hud_powerups_baralign == 0 || autocvar_hud_powerups_baralign == 3) { // up align
1906 barpos = pos + eX * 0.5 * mySize_x;
1907 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1908 } else { // down align
1909 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30) + eX * 0.5 * mySize_x;
1910 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1913 if(autocvar_hud_powerups_iconalign == 0 || autocvar_hud_powerups_iconalign == 3) { // up align
1914 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1915 numpos = pos + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1916 } else { // down align
1917 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x) + eX * 0.5 * mySize_x;
1918 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
1921 HUD_Panel_GetProgressBarColor(rightname)
1922 HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
1924 drawpic_aspect_skin_expanding(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, bound(0, (rightcnt - rightexact) / 0.5, 1));
1926 drawpic_aspect_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1927 drawstring_aspect(numpos, ftos(rightcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1930 drawfont = hud_font;
1933 // Health/armor (#3)
1935 void HUD_HealthArmor(void)
1937 if(!autocvar_hud_healtharmor && !autocvar__hud_configure)
1940 float id = HUD_PANEL_HEALTHARMOR;
1941 HUD_Panel_UpdateCvarsForId(id);
1944 mySize = panel_size;
1946 HUD_Panel_DrawBg(1);
1947 if(panel_bg_padding)
1949 pos += '1 1 0' * panel_bg_padding;
1950 mySize -= '2 2 0' * panel_bg_padding;
1953 float armor, health;
1954 armor = getstati(STAT_ARMOR);
1955 health = getstati(STAT_HEALTH);
1958 fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
1960 if(autocvar__hud_configure)
1970 vector barpos, barsize;
1974 drawfont = hud_bigfont;
1975 if(autocvar_hud_healtharmor == 2) // combined health and armor display
1978 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1983 if(autocvar_hud_healtharmor_baralign == 1 || autocvar_hud_healtharmor_baralign == 3) { // right align
1984 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, x/400);
1985 barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
1986 } else { // left align
1988 barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
1992 if(v_z) // NOT fully armored
1994 biggercount = "health";
1995 HUD_Panel_GetProgressBarColor("health")
1996 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1998 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);
2002 biggercount = "armor";
2003 HUD_Panel_GetProgressBarColor("armor")
2004 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2006 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);
2008 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos, mySize, x, biggercount, 1, HUD_Get_Num_Color(x, 2 * 200), 1);
2013 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2014 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2015 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2018 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2020 HUD_Panel_GetProgressBarColor("fuel")
2021 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2026 string leftname, rightname;
2027 float leftcnt, rightcnt;
2028 float leftactive, rightactive;
2029 float leftalpha, rightalpha;
2030 if (autocvar_hud_healtharmor_flip) { // old style layout with armor left/top of health
2035 leftalpha = min((armor+10)/55, 1);
2037 rightname = "health";
2042 leftname = "health";
2047 rightname = "armor";
2051 rightalpha = min((armor+10)/55, 1);
2054 if (mySize_x/mySize_y > 4)
2058 if(autocvar_hud_healtharmor_baralign == 1 || autocvar_hud_healtharmor_baralign == 3) { // right align
2059 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/200);
2060 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
2061 } else { // left align
2063 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
2066 HUD_Panel_GetProgressBarColor(leftname)
2067 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2068 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, HUD_Get_Num_Color(leftcnt, 200), 1);
2073 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2074 barpos = pos + eX * 0.5 * mySize_x;
2075 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
2076 } else { // right align
2077 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200);
2078 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
2081 HUD_Panel_GetProgressBarColor(rightname)
2082 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2083 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, HUD_Get_Num_Color(leftcnt, 200), 1);
2088 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2089 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2090 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2093 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2095 HUD_Panel_GetProgressBarColor("fuel")
2096 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2099 else if (mySize_x/mySize_y > 1.5)
2103 if(autocvar_hud_healtharmor_baralign == 1 || autocvar_hud_healtharmor_baralign == 3) { // right align
2104 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/200);
2105 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2106 } else { // left align
2108 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2111 HUD_Panel_GetProgressBarColor(leftname)
2112 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2113 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, HUD_Get_Num_Color(leftcnt, 200), 1);
2118 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2119 barpos = pos + eY * 0.5 * mySize_y;
2120 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2121 } else { // right align
2122 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2123 barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2126 HUD_Panel_GetProgressBarColor(rightname)
2127 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2128 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, HUD_Get_Num_Color(leftcnt, 200), 1);
2133 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2134 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2135 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2138 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2140 HUD_Panel_GetProgressBarColor("fuel")
2141 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2148 if(autocvar_hud_healtharmor_baralign == 1 || autocvar_hud_healtharmor_baralign == 3) { // down align
2149 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200);
2150 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2151 } else { // up align
2153 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2156 if(autocvar_hud_healtharmor_iconalign == 1 || autocvar_hud_healtharmor_iconalign == 3) { // down align
2157 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x);
2158 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x;
2159 } else { // up align
2160 picpos = pos + eX * 0.05 * mySize_x;
2161 numpos = pos + eY * 0.4 * mySize_x;
2164 HUD_Panel_GetProgressBarColor(leftname)
2165 HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2166 drawpic_aspect_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2167 drawstring_aspect(numpos, ftos(leftcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, HUD_Get_Num_Color(leftcnt, 200), panel_fg_alpha, DRAWFLAG_NORMAL);
2172 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // up align
2173 barpos = pos + eX * 0.5 * mySize_x;
2174 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2175 } else { // down align
2176 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200) + eX * 0.5 * mySize_x;
2177 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2180 if(autocvar_hud_healtharmor_iconalign == 0 || autocvar_hud_healtharmor_iconalign == 3) { // up align
2181 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
2182 numpos = pos + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
2183 } else { // down align
2184 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x) + eX * 0.5 * mySize_x;
2185 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
2188 HUD_Panel_GetProgressBarColor(rightname)
2189 HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2190 drawpic_aspect_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2191 drawstring_aspect(numpos, ftos(rightcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, HUD_Get_Num_Color(rightcnt, 200), panel_fg_alpha, DRAWFLAG_NORMAL);
2196 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2198 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2200 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, fuel/100);
2201 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2203 HUD_Panel_GetProgressBarColor("fuel")
2204 HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2208 drawfont = hud_font;
2211 // Notification area (#4)
2214 string Weapon_SuicideMessage(float deathtype)
2216 w_deathtype = deathtype;
2217 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2218 return w_deathtypestring;
2221 string Weapon_KillMessage(float deathtype)
2223 w_deathtype = deathtype;
2224 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2225 return w_deathtypestring;
2228 float killnotify_times[10];
2229 float killnotify_deathtype[10];
2230 float killnotify_actiontype[10]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2231 string killnotify_attackers[10];
2232 string killnotify_victims[10];
2233 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2236 for (i = 9; i > 0; --i) {
2237 killnotify_times[i] = killnotify_times[i-1];
2238 killnotify_deathtype[i] = killnotify_deathtype[i-1];
2239 killnotify_actiontype[i] = killnotify_actiontype[i-1];
2240 if(killnotify_attackers[i])
2241 strunzone(killnotify_attackers[i]);
2242 killnotify_attackers[i] = strzone(killnotify_attackers[i-1]);
2243 if(killnotify_victims[i])
2244 strunzone(killnotify_victims[i]);
2245 killnotify_victims[i] = strzone(killnotify_victims[i-1]);
2247 killnotify_times[0] = time;
2248 killnotify_deathtype[0] = wpn;
2249 killnotify_actiontype[0] = actiontype;
2250 if(killnotify_attackers[0])
2251 strunzone(killnotify_attackers[0]);
2252 killnotify_attackers[0] = strzone(attacker);
2253 if(killnotify_victims[0])
2254 strunzone(killnotify_victims[0]);
2255 killnotify_victims[0] = strzone(victim);
2258 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
2261 float alsoprint, gentle;
2262 alsoprint = (autocvar_hud_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
2263 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
2265 if(msg == MSG_SUICIDE) {
2267 w = DEATH_WEAPONOF(type);
2269 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2271 print("^1", s1, "^1 ", Weapon_SuicideMessage(type), "\n");
2272 } else if (type == DEATH_KILL) {
2273 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2275 print ("^1",s1, "^1 couldn't take it anymore\n");
2276 } else if (type == DEATH_ROT) {
2277 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2279 print ("^1",s1, "^1 died\n");
2280 } else if (type == DEATH_NOAMMO) {
2281 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2283 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2284 } else if (type == DEATH_CAMP) {
2285 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2287 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2288 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2289 HUD_KillNotify_Push(s1, "", 0, type);
2291 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2292 } else if (type == DEATH_CHEAT) {
2293 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2295 print ("^1",s1, "^1 unfairly eliminated themself\n");
2296 } else if (type == DEATH_FIRE) {
2297 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2299 print ("^1",s1, "^1 burned to death\n");
2300 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2301 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2303 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2306 if (stof(s2) > 2) // killcount > 2
2307 print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2308 } else if(msg == MSG_KILL) {
2309 w = DEATH_WEAPONOF(type);
2311 HUD_KillNotify_Push(s2, s1, 1, w);
2313 print("^1", s1, "^1 ", Weapon_KillMessage(type), "\n");
2315 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2316 HUD_KillNotify_Push(s1, s2, 1, type);
2320 print ("^1", s1, "^1 took action against a team mate\n");
2322 print ("^1", s1, "^1 mows down a team mate\n");
2325 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2327 print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2329 print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2331 else if (stof(s2) > 2) {
2333 print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2335 print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2338 else if(type == KILL_FIRST_BLOOD)
2339 print("^1",s1, "^1 drew first blood", "\n");
2341 else if (type == DEATH_TELEFRAG)
2342 print ("^1",s1, "^1 was telefragged by ", s2, "\n");
2343 else if (type == DEATH_DROWN) {
2344 HUD_KillNotify_Push(s2, s1, 1, DEATH_DROWN);
2346 print ("^1",s1, "^1 was drowned by ", s2, "\n");
2348 else if (type == DEATH_SLIME) {
2349 HUD_KillNotify_Push(s2, s1, 1, DEATH_SLIME);
2351 print ("^1",s1, "^1 was slimed by ", s2, "\n");
2353 else if (type == DEATH_LAVA) {
2354 HUD_KillNotify_Push(s2, s1, 1, DEATH_LAVA);
2356 print ("^1",s1, "^1 was cooked by ", s2, "\n");
2358 else if (type == DEATH_FALL) {
2359 HUD_KillNotify_Push(s2, s1, 1, DEATH_FALL);
2361 print ("^1",s1, "^1 was grounded by ", s2, "\n");
2363 else if (type == DEATH_SHOOTING_STAR) {
2364 HUD_KillNotify_Push(s2, s1, 1, DEATH_SHOOTING_STAR);
2366 print ("^1",s1, "^1 was shot into space by ", s2, "\n");
2368 else if (type == DEATH_SWAMP) {
2369 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2371 print ("^1",s1, "^1 was conserved by ", s2, "\n");
2373 else if (type == DEATH_HURTTRIGGER)
2375 HUD_KillNotify_Push(s2, s1, 1, DEATH_HURTTRIGGER);
2377 print("^1",s1, "^1 was thrown into a world of hurt by ", s2, "\n");
2378 } else if(type == DEATH_SBCRUSH) {
2379 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2381 print ("^1",s1, "^1 was crushed by ^1", s2, "\n");
2382 } else if(type == DEATH_SBMINIGUN) {
2383 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2385 print ("^1",s1, "^1 got shredded by ^1", s2, "\n");
2386 } else if(type == DEATH_SBROCKET) {
2387 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2389 print ("^1",s1, "^1 was blased to bits by ^1", s2, "\n");
2390 } else if(type == DEATH_SBBLOWUP) {
2391 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2393 print ("^1",s1, "^1 got caught in the destruction of ^1", s2, "'s vehicle\n");
2394 } else if(type == DEATH_WAKIGUN) {
2395 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2397 print ("^1",s1, "^1 was bolted down by ^1", s2, "\n");
2398 } else if(type == DEATH_WAKIROCKET) {
2399 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2401 print ("^1",s1, "^1 could find no shelter from ^1", s2, "'s rockets\n");
2402 } else if(type == DEATH_WAKIBLOWUP) {
2403 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2405 print ("^1",s1, "^1 dies when ^1", s2, "'s wakizashi dies.\n");
2406 } else if(type == DEATH_TURRET) {
2407 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2409 print ("^1",s1, "^1 was pushed into the line of fire by ^1", s2, "\n");
2410 } else if(type == DEATH_TOUCHEXPLODE) {
2411 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2413 print ("^1",s1, "^1 was pushed into an accident by ^1", s2, "\n");
2414 } else if(type == DEATH_CHEAT) {
2415 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2417 print ("^1",s1, "^1 was unfairly eliminated by ^1", s2, "\n");
2418 } else if (type == DEATH_FIRE) {
2419 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2421 print ("^1",s1, "^1 was burnt to death by ^1", s2, "\n");
2422 } else if (type == DEATH_CUSTOM) {
2423 HUD_KillNotify_Push(s2, s1, 1, DEATH_CUSTOM);
2425 print ("^1",s1, "^1 ", s2, "\n");
2427 HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2429 print ("^1",s1, "^1 was fragged by ", s2, "\n");
2431 } else if(msg == MSG_SPREE) {
2432 if(type == KILL_END_SPREE) {
2434 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2436 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2437 } else if(type == KILL_SPREE) {
2439 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2441 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2442 } else if(type == KILL_SPREE_3) {
2444 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2446 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2447 } else if(type == KILL_SPREE_5) {
2449 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2451 print (s1,"^7 unleashes ^1RAGE\n");
2452 } else if(type == KILL_SPREE_10) {
2454 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2456 print (s1,"^7 starts the ^1MASSACRE!\n");
2457 } else if(type == KILL_SPREE_15) {
2459 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2461 print (s1,"^7 executes ^1MAYHEM!\n");
2462 } else if(type == KILL_SPREE_20) {
2464 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2466 print (s1,"^7 is a ^1BERSERKER!\n");
2467 } else if(type == KILL_SPREE_25) {
2469 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2471 print (s1,"^7 inflicts ^1CARNAGE!\n");
2472 } else if(type == KILL_SPREE_30) {
2474 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2476 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2478 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2479 if (type == DEATH_DROWN) {
2480 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2484 print ("^1",s1, "^1 was in the water for too long\n");
2486 print ("^1",s1, "^1 drowned\n");
2488 } else if (type == DEATH_SLIME) {
2489 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2491 print ("^1",s1, "^1 was slimed\n");
2492 } else if (type == DEATH_LAVA) {
2493 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2497 print ("^1",s1, "^1 found a hot place\n");
2499 print ("^1",s1, "^1 turned into hot slag\n");
2501 } else if (type == DEATH_FALL) {
2502 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2506 print ("^1",s1, "^1 tested gravity (and it worked)\n");
2508 print ("^1",s1, "^1 hit the ground with a crunch\n");
2510 } else if (type == DEATH_SHOOTING_STAR) {
2511 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2513 print ("^1",s1, "^1 became a shooting star\n");
2514 } else if (type == DEATH_SWAMP) {
2515 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2519 print ("^1",s1, "^1 discovered a swamp\n");
2521 print ("^1",s1, "^1 is now conserved for centuries to come\n");
2523 } else if(type == DEATH_TURRET) {
2524 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2526 print ("^1",s1, "^1 was mowed down by a turret \n");
2527 } else if (type == DEATH_CUSTOM) {
2528 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2530 print ("^1",s1, "^1 ", s2, "\n");
2531 } else if (type == DEATH_HURTTRIGGER) {
2532 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2534 print ("^1",s1, "^1 was in the wrong place\n");
2535 } else if(type == DEATH_TOUCHEXPLODE) {
2536 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2538 print ("^1",s1, "^1 died in an accident\n");
2539 } else if(type == DEATH_CHEAT) {
2540 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2542 print ("^1",s1, "^1 was unfairly eliminated\n");
2543 } else if(type == DEATH_FIRE) {
2544 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2548 print ("^1",s1, "^1 felt a little hot\n");
2550 print ("^1",s1, "^1 burnt to death\n");
2553 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2557 print ("^1",s1, "^1 needs a restart\n");
2559 print ("^1",s1, "^1 died\n");
2562 } else if(msg == MSG_KILL_ACTION_SPREE) {
2564 print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2566 print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2567 } else if(msg == MSG_INFO) {
2568 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2569 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2570 print(s1, "^7 got the ", s2, "\n");
2571 } else if(type == INFO_LOSTFLAG) {
2572 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2573 print(s1, "^7 lost the ", s2, "\n");
2574 } else if(type == INFO_PICKUPFLAG) {
2575 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2576 print(s1, "^7 picked up the ", s2, "\n");
2577 } else if(type == INFO_RETURNFLAG) {
2578 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2579 print(s1, "^7 returned the ", s2, "\n");
2584 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
2586 void HUD_Centerprint(string s1, string s2, float type, float msg)
2589 gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
2590 if(msg == MSG_SUICIDE) {
2591 if (type == DEATH_TEAMCHANGE) {
2592 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
2593 } else if (type == DEATH_AUTOTEAMCHANGE) {
2594 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
2595 } else if (type == DEATH_CAMP) {
2597 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
2599 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
2600 } else if (type == DEATH_NOAMMO) {
2602 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
2604 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
2605 } else if (type == DEATH_ROT) {
2607 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
2609 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
2610 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2612 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
2614 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
2615 } else if (type == DEATH_QUIET) {
2617 } else if (type == DEATH_KILL) {
2619 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
2621 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
2623 } else if(msg == MSG_KILL) {
2624 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2626 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
2628 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
2630 } else if (type == KILL_FIRST_BLOOD) {
2632 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
2634 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
2636 } else if (type == KILL_FIRST_VICTIM) {
2638 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
2640 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
2642 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
2644 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
2646 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
2648 } else if (type == KILL_TYPEFRAGGED) {
2650 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
2652 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
2654 } else if (type == KILL_FRAG) {
2656 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
2658 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
2660 } else if (type == KILL_FRAGGED) {
2662 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
2664 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
2667 } else if(msg == MSG_KILL_ACTION) {
2668 // TODO: invent more centerprints here?
2669 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
2673 void HUD_Notify (void)
2675 if(!autocvar_hud_notify && !autocvar__hud_configure)
2678 float id = HUD_PANEL_NOTIFY;
2679 HUD_Panel_UpdateCvarsForId(id);
2682 mySize = panel_size;
2684 HUD_Panel_DrawBg(1);
2685 if(panel_bg_padding)
2687 pos += '1 1 0' * panel_bg_padding;
2688 mySize -= '2 2 0' * panel_bg_padding;
2691 float entries, height;
2692 entries = bound(1, floor(10 * mySize_y/mySize_x), 10);
2693 height = mySize_y/entries;
2696 fontsize = '0.5 0.5 0' * height;
2700 when = autocvar_hud_notify_time;
2702 fadetime = autocvar_hud_notify_fadetime;
2707 vector pos_attacker, pos_victim;
2709 float width_attacker;
2710 string attacker, victim;
2713 for(j = 0; j < entries; ++j)
2716 if(autocvar_hud_notify_flip)
2718 else // rather nasty hack for ordering items from the bottom up
2719 i = entries - j - 1;
2723 if(killnotify_times[j] + when > time)
2726 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2730 if(killnotify_times[j] + when > time)
2736 // TODO: maybe print in team colors?
2739 if(killnotify_actiontype[j] == 0 && !autocvar__hud_configure)
2741 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2742 pos_attacker = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
2743 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2745 if(killnotify_deathtype[j] == DEATH_GENERIC)
2750 else if(killnotify_deathtype[j] == DEATH_NOAMMO)
2752 s = "notify_outofammo";
2755 else if(killnotify_deathtype[j] == DEATH_KILL)
2757 s = "notify_selfkill";
2760 else if(killnotify_deathtype[j] == DEATH_CAMP)
2762 s = "notify_camping";
2765 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2767 s = "notify_teamkill";
2770 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2772 s = "notify_teamkill";
2775 else if(killnotify_deathtype[j] == DEATH_DROWN)
2780 else if(killnotify_deathtype[j] == DEATH_SLIME)
2785 else if(killnotify_deathtype[j] == DEATH_LAVA)
2790 else if(killnotify_deathtype[j] == DEATH_FALL)
2795 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2800 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
2805 else if(killnotify_deathtype[j] == INFO_GOTFLAG)
2807 if(killnotify_victims[j] == "^1RED^7 flag")
2809 s = "flag_red_carrying";
2814 s = "flag_blue_carrying";
2818 else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
2820 if(killnotify_victims[j] == "^1RED^7 flag")
2822 s = "flag_red_taken";
2827 s = "flag_blue_taken";
2831 else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
2833 if(killnotify_victims[j] == "^1RED^7 flag")
2835 s = "flag_red_lost";
2840 s = "flag_blue_lost";
2846 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, color, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2847 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2850 // X [did action to] Y
2853 if(autocvar__hud_configure)
2855 attacker = textShortenToWidth("Player1", 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2856 victim = textShortenToWidth("Player2", 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2857 a = bound(0, (when - j) / 4, 1);
2861 attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2862 victim = textShortenToWidth(killnotify_victims[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2864 width_attacker = stringwidth(attacker, TRUE, fontsize);
2865 pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * (0.5 * fontsize_y + i * height);
2866 pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * (0.5 * fontsize_y + i * height);
2867 weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2869 if(autocvar__hud_configure) // example actions for config mode
2871 s = "weaponelectro";
2874 else if(WEP_VALID(killnotify_deathtype[j]))
2876 self = get_weaponinfo(killnotify_deathtype[j]);
2877 s = strcat("weapon", self.netname);
2880 else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2882 s = "notify_teamkill";
2885 else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2887 s = "notify_teamkill";
2890 else if(killnotify_deathtype[j] == DEATH_DROWN)
2895 else if(killnotify_deathtype[j] == DEATH_SLIME)
2900 else if(killnotify_deathtype[j] == DEATH_LAVA)
2905 else if(killnotify_deathtype[j] == DEATH_FALL)
2910 else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2912 s = "notify_shootingstar";
2915 else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
2922 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, color, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2923 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2924 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2933 string seconds_tostring(float sec)
2936 minutes = floor(sec / 60);
2938 sec -= minutes * 60;
2941 s = ftos(100 + sec);
2943 return strcat(ftos(minutes), ":", substring(s, 1, 3));
2946 void HUD_Timer(void)
2948 if(!autocvar_hud_timer && !autocvar__hud_configure)
2951 float id = HUD_PANEL_TIMER;
2952 HUD_Panel_UpdateCvarsForId(id);
2955 mySize = panel_size;
2957 HUD_Panel_DrawBg(1);
2958 if(panel_bg_padding)
2960 pos += '1 1 0' * panel_bg_padding;
2961 mySize -= '2 2 0' * panel_bg_padding;
2965 float timelimit, elapsedTime, timeleft, minutesLeft;
2967 timelimit = getstatf(STAT_TIMELIMIT);
2969 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2970 timeleft = ceil(timeleft);
2972 minutesLeft = floor(timeleft / 60);
2975 if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2976 timer_color = '1 1 1'; //white
2977 else if(minutesLeft >= 1)
2978 timer_color = '1 1 0'; //yellow
2980 timer_color = '1 0 0'; //red
2982 if (autocvar_hud_timer_increment || timelimit == 0 || warmup_stage) {
2983 if (time < getstatf(STAT_GAMESTARTTIME)) {
2984 //while restart is still active, show 00:00
2985 timer = seconds_tostring(0);
2987 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2988 timer = seconds_tostring(elapsedTime);
2991 timer = seconds_tostring(timeleft);
2994 drawfont = hud_bigfont;
2995 drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2996 drawfont = hud_font;
3001 void HUD_Radar(void)
3003 if (!(autocvar_hud_radar != 0 && (autocvar_hud_radar == 2 || teamplay || autocvar__hud_configure)))
3006 float id = HUD_PANEL_RADAR;
3007 HUD_Panel_UpdateCvarsForId(id);
3010 mySize = panel_size;
3012 HUD_Panel_DrawBg(1);
3013 if(panel_bg_padding)
3015 pos += '1 1 0' * panel_bg_padding;
3016 mySize -= '2 2 0' * panel_bg_padding;
3019 local float color1, color2; // color already declared as a global in hud.qc
3022 float scale2d, normalsize, bigsize;
3025 teamradar_origin2d = pos + 0.5 * mySize;
3026 teamradar_size2d = mySize;
3028 if(minimapname == "")
3031 teamradar_loadcvars();
3033 switch(hud_radar_zoommode)
3037 f = current_zoomfraction;
3040 f = 1 - current_zoomfraction;
3050 switch(hud_radar_rotation)
3053 teamradar_angle = view_angles_y - 90;
3056 teamradar_angle = 90 * hud_radar_rotation;
3060 scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
3061 teamradar_size2d = mySize;
3063 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
3065 // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
3066 if(hud_radar_rotation == 0)
3068 // max-min distance must fit the radar in any rotation
3069 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
3073 vector c0, c1, c2, c3, span;
3074 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
3075 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
3076 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
3077 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
3079 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
3080 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
3082 // max-min distance must fit the radar in x=x, y=y
3084 teamradar_size2d_x * scale2d / (1.05 * span_x),
3085 teamradar_size2d_y * scale2d / (1.05 * span_y)
3089 normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_radar_scale;
3090 if(bigsize > normalsize)
3091 normalsize = bigsize;
3095 + (1 - f) * normalsize;
3096 teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
3097 f * (mi_min + mi_max) * 0.5
3098 + (1 - f) * view_origin);
3100 color1 = GetPlayerColor(player_localentnum-1);
3101 rgb = GetTeamRGB(color1);
3110 draw_teamradar_background(hud_radar_background_alpha, hud_radar_foreground_alpha);
3112 for(tm = world; (tm = find(tm, classname, "radarlink")); )
3113 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
3114 for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
3115 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
3116 for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
3118 color2 = GetPlayerColor(tm.sv_entnum);
3119 //if(color == COLOR_SPECTATOR || color == color2)
3120 draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
3122 draw_teamradar_player(view_origin, view_angles, '1 1 1');
3124 drawresetcliparea();
3129 void HUD_Score(void)
3131 if(!autocvar_hud_score && !autocvar__hud_configure)
3134 float id = HUD_PANEL_SCORE;
3135 HUD_Panel_UpdateCvarsForId(id);
3138 mySize = panel_size;
3140 HUD_Panel_DrawBg(1);
3141 if(panel_bg_padding)
3143 pos += '1 1 0' * panel_bg_padding;
3144 mySize -= '2 2 0' * panel_bg_padding;
3147 float score, distribution, leader;
3149 vector distribution_color;
3151 me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
3153 // TODO... this (race part) still uses constant coordinates :/
3154 if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
3155 /*pl = players.sort_next;
3158 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
3159 if(pl.scores[ps_primary] == 0)
3162 score = me.(scores[ps_primary]);
3164 float racemin, racesec, racemsec;
3165 float distsec, distmsec, minusplus;
3167 racemin = floor(score/(60 * TIME_FACTOR));
3168 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
3169 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
3171 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
3172 // distribution display
3173 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3175 if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
3176 distmsec = fabs(distribution);
3178 distsec = floor(fabs(distribution)/TIME_FACTOR);
3179 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
3180 if (distribution < 0)
3184 if (distribution <= 0) {
3185 distribution_color = eY;
3186 minusplus = 1; // minusplus 1: always prefix with minus sign
3189 distribution_color = eX;
3190 minusplus = 2; // minusplus 1: always prefix with plus sign
3192 //HUD_DrawXNum(bottomright - '0 48 0' - '16 0 0' * TIME_DECIMALS, distmsec, -TIME_DECIMALS, 0, 16, distribution_color, 0, 0, panel_fg_alpha, DRAWFLAG_NORMAL);
3193 //HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, panel_fg_alpha, DRAWFLAG_NORMAL);
3194 drawpic_aspect_skin(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "num_dot", '16 16 0', distribution_color, panel_fg_alpha, DRAWFLAG_ADDITIVE);
3196 // race record display
3197 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
3198 drawpic_aspect_skin(bottomright - '0 32 0' - '32 0 0' * (4 + TIME_DECIMALS), "num_leading_4", '0 28 0' + '32 0 0' * (4 + TIME_DECIMALS), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3200 //HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0', racemsec, -TIME_DECIMALS, 0, 30, '1 1 1', 0, 0, panel_fg_alpha, DRAWFLAG_NORMAL);
3201 //HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '66 0 0', racesec, -2, 0, 30, '1 1 1', 0, 0, panel_fg_alpha, DRAWFLAG_NORMAL);
3202 drawpic_aspect_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '18 0 0', "num_dot", '30 30 0', '1 1 1', panel_fg_alpha, DRAWFLAG_ADDITIVE);
3204 //HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '132 0 0', racemin, -2, 0, 30, '1 1 1', 0, 0, panel_fg_alpha, DRAWFLAG_NORMAL);
3205 drawpic_aspect_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '84 0 0', "num_colon", '30 30 0', '1 1 1', panel_fg_alpha, DRAWFLAG_ADDITIVE);
3207 } else if (!teamplay) { // non-teamgames
3208 // me vector := [team/connected frags id]
3209 pl = players.sort_next;
3213 if(autocvar__hud_configure)
3216 distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3220 score = me.(scores[ps_primary]);
3221 if(autocvar__hud_configure)
3224 if(distribution >= 5) {
3225 distribution_color = eY;
3227 } else if(distribution >= 0) {
3228 distribution_color = '1 1 1';
3230 } else if(distribution >= -5)
3231 distribution_color = '1 1 0';
3233 distribution_color = eX;
3235 score_len = strlen(ftos(score));
3237 drawstring_aspect(pos + eX * 0.75 * mySize_x, ftos(distribution), eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3239 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3240 drawfont = hud_bigfont;
3241 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
3242 drawfont = hud_font;
3243 } else { // teamgames
3244 float max_fragcount;
3245 max_fragcount = -99;
3248 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3249 if(tm.team == COLOR_SPECTATOR || (!tm.team_size && !autocvar__hud_configure)) // no players? don't display
3251 score = tm.(teamscores[ts_primary]);
3252 if(autocvar__hud_configure)
3256 score_len = strlen(ftos(score));
3258 if (score > max_fragcount)
3259 max_fragcount = score;
3261 if(tm.team == myteam) {
3262 if (max_fragcount == score)
3265 HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3266 drawfont = hud_bigfont;
3267 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3268 drawfont = hud_font;
3270 if (max_fragcount == score)
3273 HUD_Panel_DrawHighlight(pos + eX * 0.75 * mySize_x + eY * (1/3) * teamnum * mySize_y, eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3274 drawstring_aspect(pos + eX * 0.75 * mySize_x + eY * (1/3) * teamnum * mySize_y, ftos(score), eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
3283 void HUD_RaceTimer (void) {
3284 if(!autocvar_hud_racetimer && !(gametype == GAME_RACE || gametype == GAME_CTS) && !autocvar__hud_configure)
3287 float id = HUD_PANEL_RACETIMER;
3288 HUD_Panel_UpdateCvarsForId(id);
3291 mySize = panel_size;
3293 HUD_Panel_DrawBg(1);
3294 if(panel_bg_padding)
3296 pos += '1 1 0' * panel_bg_padding;
3297 mySize -= '2 2 0' * panel_bg_padding;
3300 // always force 4:1 aspect
3302 if(mySize_x/mySize_y > 4)
3304 newSize_x = 4 * mySize_y;
3305 newSize_y = mySize_y;
3307 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3311 newSize_y = 1/4 * mySize_x;
3312 newSize_x = mySize_x;
3314 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3318 drawfont = hud_bigfont;
3320 string s, forcetime;
3322 if(autocvar__hud_configure)
3325 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);
3326 s = "^1Intermediate 1 (+15.42)";
3327 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);
3328 s = strcat("^1PENALTY: ", ftos_decimals(20 * 0.1, 1), " (missing a checkpoint)");
3329 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);
3331 else if(race_checkpointtime)
3333 a = bound(0, 2 - (time - race_checkpointtime), 1);
3336 if(a > 0) // just hit a checkpoint?
3338 if(race_checkpoint != 254)
3340 if(race_time && race_previousbesttime)
3341 s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
3343 s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
3345 forcetime = TIME_ENCODED_TOSTRING(race_time);
3350 if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
3352 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
3353 if(a > 0) // next one?
3355 s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
3360 if(s != "" && a > 0)
3362 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3363 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3364 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);
3367 if(race_penaltytime)
3369 a = bound(0, 2 - (time - race_penaltyeventtime), 1);
3372 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
3373 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3374 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3375 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);
3381 a = bound(0, (time - race_checkpointtime) / 0.5, 1);
3382 //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', panel_fg_alpha, 0, a);
3383 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);
3388 if(race_laptime && race_checkpoint != 255)
3390 s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
3391 //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3392 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);
3397 if(race_mycheckpointtime)
3399 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
3400 s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
3401 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3402 //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3403 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);
3405 if(race_othercheckpointtime && race_othercheckpointenemy != "")
3407 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
3408 s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
3409 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3410 //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3411 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);
3414 if(race_penaltytime && !race_penaltyaccumulator)
3416 t = race_penaltytime * 0.1 + race_penaltyeventtime;
3417 a = bound(0, (1 + t - time), 1);
3421 s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
3423 s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
3424 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3425 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3426 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);
3431 drawfont = hud_font;
3436 float vote_yescount;
3439 float vote_highlighted; // currently selected vote
3441 float vote_active; // is there an active vote?
3442 float vote_prev; // previous state of vote_active to check for a change
3444 float vote_change; // "time" when vote_active changed
3446 void HUD_VoteWindow(void)
3448 if(!autocvar_hud_vote && !autocvar__hud_configure)
3451 float id = HUD_PANEL_VOTE;
3452 HUD_Panel_UpdateCvarsForId(id);
3455 mySize = panel_size;
3459 if(vote_active != vote_prev) {
3461 vote_prev = vote_active;
3464 if(vote_active || autocvar__hud_configure)
3465 vote_alpha = bound(0, (time - vote_change) * 2, 1);
3467 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
3469 if(autocvar__hud_configure)
3479 a = vote_alpha * bound(autocvar_hud_vote_alreadyvoted_alpha, 1 - vote_highlighted, 1);
3481 HUD_Panel_DrawBg(a);
3482 if(panel_bg_padding)
3484 pos += '1 1 0' * panel_bg_padding;
3485 mySize -= '2 2 0' * panel_bg_padding;
3488 // always force 3:1 aspect
3490 if(mySize_x/mySize_y > 3)
3492 newSize_x = 3 * mySize_y;
3493 newSize_y = mySize_y;
3495 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3499 newSize_y = 1/3 * mySize_x;
3500 newSize_x = mySize_x;
3502 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3506 s = "A vote has been called for:";
3507 drawstring_aspect(pos, s, eX * mySize_x + eY * (2/8) * mySize_y, '1 1 1', a * panel_fg_alpha, DRAWFLAG_NORMAL);
3508 s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (1.75/8), stringwidth_colors);
3509 if(autocvar__hud_configure)
3510 s = "^1Configure the HUD";
3511 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a * panel_fg_alpha, DRAWFLAG_NORMAL);
3513 // print the yes/no counts
3514 s = strcat("Yes (", getcommandkey("not bound", "vyes"), "): ", ftos(vote_yescount));
3515 drawstring_aspect(pos + eY * (4/8) * mySize_y, s, eX * 0.5 * mySize_x + eY * (1.5/8) * mySize_y, '0 1 0', a * panel_fg_alpha, DRAWFLAG_NORMAL);
3516 s = strcat("No (", getcommandkey("not bound", "vno"), "): ", ftos(vote_nocount));
3517 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 * panel_fg_alpha, DRAWFLAG_NORMAL);
3519 // draw the progress bar backgrounds
3520 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_back", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a * panel_fg_alpha, DRAWFLAG_NORMAL);
3522 // draw the highlights
3523 if(vote_highlighted == 1) {
3524 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3525 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '0 1 0', a * panel_fg_alpha, DRAWFLAG_NORMAL);
3527 else if(vote_highlighted == 2) {
3528 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3529 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '0 1 0', a * panel_fg_alpha, DRAWFLAG_NORMAL);
3532 // draw the progress bars
3533 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3534 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '0 1 0', a * panel_fg_alpha, DRAWFLAG_NORMAL);
3536 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3537 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 0 0', a * panel_fg_alpha, DRAWFLAG_NORMAL);
3539 drawresetcliparea();
3542 vote_highlighted = 0;
3546 // Mod icons panel (#10)
3549 float mod_active; // is there any active mod icon?
3551 // CTF HUD modicon section
3552 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3553 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3554 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3556 void HUD_Mod_CTF_Reset(void)
3558 redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3561 void HUD_Mod_CTF(vector pos, vector mySize)
3563 vector redflag_pos, blueflag_pos;
3565 float f; // every function should have that
3567 float redflag, blueflag; // current status
3568 float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3571 stat_items = getstati(STAT_ITEMS);
3572 redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3573 blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3575 if(redflag || blueflag)
3580 if(autocvar__hud_configure)
3586 // when status CHANGES, set old status into prevstatus and current status into status
3587 if (redflag != redflag_prevframe)
3589 redflag_statuschange_time = time;
3590 redflag_prevstatus = redflag_prevframe;
3591 redflag_prevframe = redflag;
3594 if (blueflag != blueflag_prevframe)
3596 blueflag_statuschange_time = time;
3597 blueflag_prevstatus = blueflag_prevframe;
3598 blueflag_prevframe = blueflag;
3601 redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
3602 blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
3604 float BLINK_FACTOR = 0.15;
3605 float BLINK_BASE = 0.85;
3607 // RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3609 // BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3611 float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3613 string red_icon, red_icon_prevstatus;
3614 float red_alpha, red_alpha_prevstatus;
3615 red_alpha = red_alpha_prevstatus = 1;
3617 case 1: red_icon = "flag_red_taken"; break;
3618 case 2: red_icon = "flag_red_lost"; break;
3619 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3621 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3622 red_icon = "flag_red_shielded";
3624 red_icon = string_null;
3627 switch(redflag_prevstatus) {
3628 case 1: red_icon_prevstatus = "flag_red_taken"; break;
3629 case 2: red_icon_prevstatus = "flag_red_lost"; break;
3630 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3633 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
3634 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3635 red_icon_prevstatus = "flag_red_shielded";
3637 red_icon_prevstatus = string_null;
3641 string blue_icon, blue_icon_prevstatus;
3642 float blue_alpha, blue_alpha_prevstatus;
3643 blue_alpha = blue_alpha_prevstatus = 1;
3645 case 1: blue_icon = "flag_blue_taken"; break;
3646 case 2: blue_icon = "flag_blue_lost"; break;
3647 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3649 if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3650 blue_icon = "flag_blue_shielded";
3652 blue_icon = string_null;
3655 switch(blueflag_prevstatus) {
3656 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3657 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3658 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3661 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3662 else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3663 blue_icon_prevstatus = "flag_blue_shielded";
3665 blue_icon_prevstatus = string_null;
3669 if(mySize_x > mySize_y) {
3670 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3672 blueflag_pos = pos + eX * 0.5 * mySize_x;
3675 redflag_pos = pos + eX * 0.5 * mySize_x;
3677 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
3679 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3681 blueflag_pos = pos + eY * 0.5 * mySize_y;
3684 redflag_pos = pos + eY * 0.5 * mySize_y;
3686 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
3689 f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3690 if(red_icon_prevstatus && f < 1)
3691 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3693 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
3695 f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3696 if(blue_icon_prevstatus && f < 1)
3697 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3699 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
3702 // Keyhunt HUD modicon section
3703 float kh_runheretime;
3705 void HUD_Mod_KH_Reset(void)
3710 void HUD_Mod_KH(vector pos, vector mySize)
3712 mod_active = 1; // keyhunt should never hide the mod icons panel
3716 vector p, pa, kh_size, kh_asize;
3718 kh_keys = getstati(STAT_KH_KEYS);
3721 if(mySize_x > mySize_y)
3723 p_y = pos_y + 0.25 * mySize_y;
3724 pa = p - eY * 0.25 * mySize_y;
3726 kh_size_x = mySize_x * 0.25;
3727 kh_size_y = 0.75 * mySize_y;
3728 kh_asize_x = mySize_x * 0.25;
3729 kh_asize_y = mySize_y * 0.25;
3733 p_y = pos_y + 0.125 * mySize_y;
3734 pa = p - eY * 0.125 * mySize_y;
3736 kh_size_x = mySize_x * 0.5;
3737 kh_size_y = 0.375 * mySize_y;
3738 kh_asize_x = mySize_x * 0.5;
3739 kh_asize_y = mySize_y * 0.125;
3746 for(i = 0; i < 4; ++i)
3748 key = floor(kh_keys / pow(32, i)) & 31;
3750 if(keyteam == 30 && keycount <= 4)
3752 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
3756 // this yields 8 exactly if "RUN HERE" shows
3761 kh_runheretime = time;
3762 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
3767 for(i = 0; i < 4; ++i)
3769 key = floor(kh_keys / pow(32, i)) & 31;
3782 default: // owned or dropped
3787 a = a * panel_fg_alpha;
3788 aa = aa * panel_fg_alpha;
3794 drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3797 drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3800 drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3803 drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL); // show 30% alpha key
3808 switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
3811 drawpic_aspect_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3814 drawpic_aspect_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3817 drawpic_aspect_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3820 drawpic_aspect_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL); // show 30% alpha key
3824 if(mySize_x > mySize_y)
3826 p_x += 0.25 * mySize_x;
3827 pa_x += 0.25 * mySize_x;
3833 p_y = pos_y + 0.625 * mySize_y;
3834 pa_y = pos_y + 0.5 * mySize_y;
3840 p_x += 0.5 * mySize_x;
3841 pa_x += 0.5 * mySize_x;
3847 // Nexball HUD mod icon
3848 void HUD_Mod_NexBall(vector pos, vector mySize)
3850 float stat_items, nb_pb_starttime, dt, p;
3852 stat_items = getstati(STAT_ITEMS);
3853 nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3855 if (stat_items & IT_KEY1)
3860 //Manage the progress bar if any
3861 if (nb_pb_starttime > 0)
3863 dt = mod(time - nb_pb_starttime, nb_pb_period);
3864 // one period of positive triangle
3865 p = 2 * dt / nb_pb_period;
3872 if(mySize_x > mySize_y)
3874 barsize = eX * p * mySize_x + eY * mySize_y;
3879 barsize = eX * mySize_x + eY * p * mySize_y;
3882 HUD_Panel_GetProgressBarColor("nexball")
3883 HUD_Panel_DrawProgressBar(pos, vertical, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3886 if (stat_items & IT_KEY1)
3887 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3890 // Race/CTS HUD mod icons
3891 float crecordtime_prev; // last remembered crecordtime
3892 float crecordtime_change_time; // time when crecordtime last changed
3893 float srecordtime_prev; // last remembered srecordtime
3894 float srecordtime_change_time; // time when srecordtime last changed
3896 float race_status_time;
3897 float race_status_prev;
3898 string race_status_name_prev;
3899 void HUD_Mod_Race(vector pos, vector mySize)
3901 mod_active = 1; // race should never hide the mod icons panel
3903 me = playerslots[player_localentnum - 1];
3905 float f; // yet another function has this
3906 score = me.(scores[ps_primary]);
3908 if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
3909 return; // no records in the actual race
3911 drawfont = hud_bigfont;
3913 // clientside personal record
3915 if(gametype == GAME_CTS)
3919 t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3921 if(score && (score < t || !t)) {
3922 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3923 if(cvar("cl_autodemo_delete_keeprecords"))
3925 f = cvar("cl_autodemo_delete");
3927 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3931 if(t != crecordtime_prev) {
3932 crecordtime_prev = t;
3933 crecordtime_change_time = time;
3935 f = time - crecordtime_change_time;
3938 drawstring_aspect(pos, "Personal best", eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3939 drawstring_aspect(pos + eY * 0.25 * mySize_y, TIME_ENCODED_TOSTRING(t), eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3941 drawstring_aspect(pos, "Personal best", eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3942 drawstring_aspect(pos + eY * 0.25 * mySize_y, TIME_ENCODED_TOSTRING(t), eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3943 drawstring_aspect_expanding(pos, "Personal best", eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3944 drawstring_aspect_expanding(pos + eY * 0.25 * mySize_y, TIME_ENCODED_TOSTRING(t), eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3948 t = race_server_record;
3949 if(t != srecordtime_prev) {
3950 srecordtime_prev = t;
3951 srecordtime_change_time = time;
3953 f = time - srecordtime_change_time;
3956 drawstring_aspect(pos + eY * 0.5 * mySize_y, "Server best", eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3957 drawstring_aspect(pos + eY * 0.75 * mySize_y, TIME_ENCODED_TOSTRING(t), eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3959 drawstring_aspect(pos + eY * 0.5 * mySize_y, "Server best", eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3960 drawstring_aspect(pos + eY * 0.75 * mySize_y, TIME_ENCODED_TOSTRING(t), eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3961 drawstring_aspect_expanding(pos + eY * 0.5 * mySize_y, "Server best", eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3962 drawstring_aspect_expanding(pos + eY * 0.75 * mySize_y, TIME_ENCODED_TOSTRING(t), eX * 0.5 * mySize_x + eY * 0.25 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3965 if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3966 race_status_time = time + 5;
3967 race_status_prev = race_status;
3968 if (race_status_name_prev)
3969 strunzone(race_status_name_prev);
3970 race_status_name_prev = strzone(race_status_name);
3973 pos_x += mySize_x/2;
3976 a = bound(0, race_status_time - time, 1);
3979 s = textShortenToWidth(race_status_name, mySize_y, '1 1 0' * 0.1 * mySize_y, stringwidth_colors);
3983 rank = race_CheckName(race_status_name);
3985 rankname = race_PlaceName(rank);
3988 namepos = pos + '0.5 0.9 0' * mySize_y - eX * stringwidth(s, TRUE, '1 1 0' * 0.1 * mySize_y);
3990 rankpos = pos + '0.5 0.25 0' * mySize_y - eX * stringwidth(rankname, TRUE, '1 1 0' * 0.15 * mySize_y);
3992 if(race_status == 0)
3993 drawpic_aspect_skin(pos, "race_newfail", '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3994 else if(race_status == 1) {
3995 drawpic_aspect_skin(pos, "race_newtime", '1 1 0' * 0.9 * mySize_y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3996 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3997 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3998 } else if(race_status == 2) {
3999 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
4000 drawpic_aspect_skin(pos, "race_newrankgreen", '1 1 0' * 0.9 * mySize_y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4002 drawpic_aspect_skin(pos, "race_newrankyellow", '1 1 0' * 0.9 * mySize_y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4003 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4004 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4005 } else if(race_status == 3) {
4006 drawpic_aspect_skin(pos, "race_newrecordserver", '1 1 0' * 0.9 * mySize_y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4007 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, panel_fg_alpha * a, DRAWFLAG_NORMAL);
4008 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
4011 if (race_status_time - time <= 0) {
4012 race_status_prev = -1;
4014 if(race_status_name)
4015 strunzone(race_status_name);
4016 race_status_name = string_null;
4017 if(race_status_name_prev)
4018 strunzone(race_status_name_prev);
4019 race_status_name_prev = string_null;
4021 drawfont = hud_font;
4024 float mod_prev; // previous state of mod_active to check for a change
4026 float mod_change; // "time" when mod_active changed
4028 void HUD_ModIcons(void)
4030 if(!autocvar_hud_modicons && !autocvar__hud_configure)
4033 if (gametype != GAME_KEYHUNT && gametype != GAME_CTF && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && !autocvar__hud_configure)
4036 float id = HUD_PANEL_MODICONS;
4037 HUD_Panel_UpdateCvarsForId(id);
4040 mySize = panel_size;
4042 if(mod_active != mod_prev) {
4044 mod_prev = mod_active;
4047 if(mod_active || autocvar__hud_configure)
4048 mod_alpha = bound(0, (time - mod_change) * 2, 1);
4050 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
4053 HUD_Panel_DrawBg(mod_alpha);
4055 if(panel_bg_padding)
4057 pos += '1 1 0' * panel_bg_padding;
4058 mySize -= '2 2 0' * panel_bg_padding;
4061 // these MUST be ran in order to update mod_active
4062 if(gametype == GAME_KEYHUNT)
4063 HUD_Mod_KH(pos, mySize);
4064 else if(gametype == GAME_CTF || autocvar__hud_configure)
4065 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
4066 else if(gametype == GAME_NEXBALL)
4067 HUD_Mod_NexBall(pos, mySize);
4068 else if(gametype == GAME_CTS || gametype == GAME_RACE)
4069 HUD_Mod_Race(pos, mySize);
4072 // Draw pressed keys (#11)
4074 void HUD_DrawPressedKeys(void)
4076 if(!autocvar_hud_pressedkeys && !autocvar__hud_configure)
4079 if(!(spectatee_status > 0 || autocvar_hud_pressedkeys >= 2 || autocvar__hud_configure))
4082 float id = HUD_PANEL_PRESSEDKEYS;
4083 HUD_Panel_UpdateCvarsForId(id);
4086 mySize = panel_size;
4088 HUD_Panel_DrawBg(1);
4089 if(panel_bg_padding)
4091 pos += '1 1 0' * panel_bg_padding;
4092 mySize -= '2 2 0' * panel_bg_padding;
4095 // always force 2:1 aspect
4097 if(mySize_x/mySize_y > 2)
4099 newSize_x = 2 * mySize_y;
4100 newSize_y = mySize_y;
4102 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4106 newSize_y = 1/2 * mySize_x;
4107 newSize_x = mySize_x;
4109 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4114 keysize = eX * mySize_x * (1/3) + eY * mySize_y * 0.5;
4117 pressedkeys = getstatf(STAT_PRESSED_KEYS);
4118 drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4119 drawpic_aspect_skin(pos + eX * mySize_x * (1/3), ((pressedkeys & KEY_FORWARD) ? "key_forward_inv.tga" : "key_forward.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4120 drawpic_aspect_skin(pos + eX * mySize_x * (2/3), ((pressedkeys & KEY_JUMP) ? "key_jump_inv.tga" : "key_jump.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4121 drawpic_aspect_skin(pos + eY * 0.5 * mySize_y, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4122 drawpic_aspect_skin(pos + eY * 0.5 * mySize_y + eX * mySize_x * (1/3), ((pressedkeys & KEY_BACKWARD) ? "key_backward_inv.tga" : "key_backward.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4123 drawpic_aspect_skin(pos + eY * 0.5 * mySize_y + eX * mySize_x * (2/3), ((pressedkeys & KEY_RIGHT) ? "key_right_inv.tga" : "key_right.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4126 // Handle chat as a panel (#12)
4130 if(!autocvar_hud_chat && !autocvar__hud_configure)
4132 cvar_set("con_chatrect", "0");
4136 float id = HUD_PANEL_CHAT;
4137 HUD_Panel_UpdateCvarsForId(id);
4140 mySize = panel_size;
4142 HUD_Panel_DrawBg(1);
4143 if(panel_bg_padding)
4145 pos += '1 1 0' * panel_bg_padding;
4146 mySize -= '2 2 0' * panel_bg_padding;
4149 cvar_set("con_chatrect", "1");
4151 cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
4152 cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
4154 cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
4155 cvar_set("con_chat", ftos(floor(mySize_y/cvar("con_chatsize") - 0.5)));
4157 if(autocvar__hud_configure)
4160 chatsize = cvar("con_chatsize");
4161 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
4163 for(i = 0; i < cvar("con_chat"); ++i)
4165 if(i == cvar("con_chat") - 1)
4168 a = panel_fg_alpha * floor(((i + 1) * 7 + cvar("con_chattime"))/45);
4169 drawcolorcodedstring(pos + eY * i * chatsize, textShortenToWidth("^3Player^7: This is the chat area.", mySize_x, '1 1 0' * chatsize, stringwidth_colors), '1 1 0' * chatsize, a, DRAWFLAG_NORMAL);
4174 // Engine info panel (#13)
4181 float frametimeavg1; // 1 frame ago
4182 float frametimeavg2; // 2 frames ago
4183 void HUD_EngineInfo(void)
4185 if(!autocvar_hud_engineinfo && !autocvar__hud_configure)
4188 float id = HUD_PANEL_ENGINEINFO;
4189 HUD_Panel_UpdateCvarsForId(id);
4192 mySize = panel_size;
4194 HUD_Panel_DrawBg(1);
4195 if(panel_bg_padding)
4197 pos += '1 1 0' * panel_bg_padding;
4198 mySize -= '2 2 0' * panel_bg_padding;
4201 if(cvar("hud_engineinfo_framecounter_exponentialmovingaverage"))
4203 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + frametime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
4204 frametimeavg2 = frametimeavg1;
4205 frametimeavg1 = frametimeavg;
4208 weight = cvar("hud_engineinfo_framecounter_exponentialmovingaverage_new_weight");
4209 if(frametime > 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.
4211 if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/frametime) to make big updates instant
4212 prevfps = (1/frametime);
4213 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"
4219 if(time - prevfps_time > cvar("hud_engineinfo_framecounter_time"))
4221 prevfps = framecounter/cvar("hud_engineinfo_framecounter_time");
4223 prevfps_time = time;
4228 color = HUD_Get_Num_Color (prevfps, 100);
4229 drawfont = hud_bigfont;
4230 drawstring_aspect(pos, strcat("FPS: ", ftos_decimals(prevfps, cvar("hud_engineinfo_framecounter_decimals"))), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
4231 drawfont = hud_font;
4234 // Info messages panel (#14)
4236 void HUD_InfoMessages(void)
4238 if(!autocvar_hud_infomessages && !autocvar__hud_configure)
4241 float id = HUD_PANEL_INFOMESSAGES;
4242 HUD_Panel_UpdateCvarsForId(id);
4245 mySize = panel_size;
4247 HUD_Panel_DrawBg(1);
4248 if(panel_bg_padding)
4250 pos += '1 1 0' * panel_bg_padding;
4251 mySize -= '2 2 0' * panel_bg_padding;
4254 // always force 6:1 aspect
4256 if(mySize_x/mySize_y > 6)
4258 newSize_x = 6 * mySize_y;
4259 newSize_y = mySize_y;
4261 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4265 newSize_y = 1/6 * mySize_x;
4266 newSize_x = mySize_x;
4268 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4277 fontsize = '0.25 0.25 0' * mySize_y;
4280 if(!autocvar__hud_configure)
4282 if(spectatee_status && !intermission)
4284 //drawfont = hud_bigfont;
4285 if(spectatee_status == -1)
4288 s = GetPlayerName(spectatee_status - 1);
4290 //s = textShortenToWidth(s, mySize_y, 0.5 * height, stringwidth_colors);
4291 //drawcolorcodedstring(pos + eY * 0.25 * height, s, 0.5 * height, panel_fg_alpha, DRAWFLAG_NORMAL);
4292 //drawfont = hud_font;
4294 // spectator text in the upper right corner
4295 if(spectatee_status == -1)
4296 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
4298 s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
4299 if(autocvar_hud_infomessages_flip)
4300 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4301 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4302 o += eY * fontsize_y;
4304 if(spectatee_status == -1)
4305 s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
4307 s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
4308 if(autocvar_hud_infomessages_flip)
4309 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4310 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4311 o += eY * fontsize_y;
4313 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
4314 if(autocvar_hud_infomessages_flip)
4315 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4316 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4317 o += eY * fontsize_y;
4319 if(gametype == GAME_ARENA)
4320 s = "^1Wait for your turn to join";
4321 else if(gametype == GAME_LMS)
4324 sk = playerslots[player_localentnum - 1];
4325 if(sk.(scores[ps_primary]) >= 666)
4326 s = "^1Match has already begun";
4327 else if(sk.(scores[ps_primary]) > 0)
4328 s = "^1You have no more lives left";
4330 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
4333 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
4334 if(autocvar_hud_infomessages_flip)
4335 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4336 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4337 o += eY * fontsize_y;
4339 //show restart countdown:
4340 if (time < getstatf(STAT_GAMESTARTTIME)) {
4342 //we need to ceil, otherwise the countdown would be off by .5 when using round()
4343 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
4344 s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
4345 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4346 o += eY * fontsize_y;
4349 if(warmup_stage && !intermission)
4351 s = "^2Currently in ^1warmup^2 stage!";
4352 if(autocvar_hud_infomessages_flip)
4353 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4354 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4355 o += eY * fontsize_y;
4359 if(mod(time, 1) >= 0.5)
4364 if(ready_waiting && !intermission && !spectatee_status)
4366 if(ready_waiting_for_me)
4369 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
4371 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
4376 s = strcat("^2Waiting for others to ready up to end warmup...");
4378 s = strcat("^2Waiting for others to ready up...");
4380 if(autocvar_hud_infomessages_flip)
4381 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4382 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4383 o += eY * fontsize_y;
4385 else if(warmup_stage && !intermission && !spectatee_status)
4387 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
4388 if(autocvar_hud_infomessages_flip)
4389 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4390 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4391 o += eY * fontsize_y;
4394 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
4396 float ts_min, ts_max;
4397 tm = teams.sort_next;
4400 for(; tm.sort_next; tm = tm.sort_next)
4402 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
4404 if(!ts_min) ts_min = tm.team_size;
4405 else ts_min = min(ts_min, tm.team_size);
4406 if(!ts_max) ts_max = tm.team_size;
4407 else ts_max = max(ts_max, tm.team_size);
4409 if ((ts_max - ts_min) > 1)
4411 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
4412 tm = GetTeam(myteam, false);
4414 if (tm.team != COLOR_SPECTATOR)
4415 if (tm.team_size == ts_max)
4416 s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
4418 if(autocvar_hud_infomessages_flip)
4419 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4420 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4421 o += eY * fontsize_y;
4428 s = "^7Press ^3ESC ^7to show HUD options.";
4429 if(autocvar_hud_infomessages_flip)
4430 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4431 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4432 o += eY * fontsize_y;
4433 s = "^3Doubleclick ^7a panel for panel-specific options.";
4434 if(autocvar_hud_infomessages_flip)
4435 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4436 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4437 o += eY * fontsize_y;
4438 s = "^3CTRL ^7to disable collision testing, ^3SHIFT ^7and";
4439 if(autocvar_hud_infomessages_flip)
4440 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4441 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4442 o += eY * fontsize_y;
4443 s = "^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.";
4444 if(autocvar_hud_infomessages_flip)
4445 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);
4446 drawcolorcodedstring(o, s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
4447 o += eY * fontsize_y;
4457 void HUD_ShowSpeed(void)
4460 float pos, conversion_factor;
4461 string speed, zspeed, unit;
4463 switch(cvar("cl_showspeed_unit"))
4468 conversion_factor = 1.0;
4472 conversion_factor = 1.0;
4476 conversion_factor = 0.0254;
4480 conversion_factor = 0.0254 * 3.6;
4484 conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4488 conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4492 speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
4494 numsize_x = numsize_y = cvar("cl_showspeed_size");
4495 pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
4497 drawfont = hud_bigfont;
4498 drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_fg_alpha, DRAWFLAG_NORMAL);
4500 if (cvar("cl_showspeed_z") == 1) {
4501 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
4502 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_fg_alpha, DRAWFLAG_NORMAL);
4505 drawfont = hud_font;
4508 vector acc_prevspeed;
4512 void HUD_ShowAcceleration(void)
4514 float acceleration, sz, scale, alpha, f;
4515 vector pos, top, rgb;
4516 top_x = vid_conwidth/2;
4519 f = time - acc_prevtime;
4520 if(cvar("cl_showacceleration_z"))
4521 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
4523 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
4524 acc_prevspeed = pmove_vel;
4525 acc_prevtime = time;
4527 f = bound(0, f * 10, 1);
4528 acc_avg = acc_avg * (1 - f) + acceleration * f;
4529 acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
4531 pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
4533 sz = cvar("cl_showacceleration_size");
4534 scale = cvar("cl_showacceleration_scale");
4535 alpha = cvar("cl_showacceleration_alpha");
4536 if (cvar("cl_showacceleration_color_custom"))
4537 rgb = stov(cvar_string("cl_showacceleration_color"));
4540 if (acceleration < 0) {
4541 rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
4542 } else if (acceleration > 0) {
4543 rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
4547 if (acceleration > 0)
4548 HUD_Panel_DrawProgressBar(pos, 0, acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_fg_alpha, DRAWFLAG_NORMAL);
4549 else if (acceleration < 0)
4550 HUD_Panel_DrawProgressBar(pos + acceleration * scale * '40 0 0', 0, -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_fg_alpha, DRAWFLAG_NORMAL);
4553 void HUD_Reset (void)
4555 // reset gametype specific icons
4556 if(gametype == GAME_KEYHUNT)
4558 else if(gametype == GAME_CTF)
4559 HUD_Mod_CTF_Reset();
4562 #define HUD_DrawPanel(id)\
4564 case (HUD_PANEL_RADAR):\
4565 HUD_Radar(); break;\
4566 case (HUD_PANEL_WEAPONICONS):\
4567 HUD_WeaponIcons(); break;\
4568 case (HUD_PANEL_INVENTORY):\
4569 HUD_Inventory(); break;\
4570 case (HUD_PANEL_POWERUPS):\
4571 HUD_Powerups(); break;\
4572 case (HUD_PANEL_HEALTHARMOR):\
4573 HUD_HealthArmor(); break;\
4574 case (HUD_PANEL_NOTIFY):\
4575 HUD_Notify(); break;\
4576 case (HUD_PANEL_TIMER):\
4577 HUD_Timer(); break;\
4578 case (HUD_PANEL_SCORE):\
4579 HUD_Score(); break;\
4580 case (HUD_PANEL_RACETIMER):\
4581 HUD_RaceTimer(); break;\
4582 case (HUD_PANEL_VOTE):\
4583 HUD_VoteWindow(); break;\
4584 case (HUD_PANEL_MODICONS):\
4585 HUD_ModIcons(); break;\
4586 case (HUD_PANEL_PRESSEDKEYS):\
4587 HUD_DrawPressedKeys(); break;\
4588 case (HUD_PANEL_CHAT):\
4590 case (HUD_PANEL_ENGINEINFO):\
4591 HUD_EngineInfo(); break;\
4592 case (HUD_PANEL_INFOMESSAGES):\
4593 HUD_InfoMessages(); break;\
4596 void HUD_Main (void)
4598 hud_skin_path = strcat("gfx/hud/", autocvar_hud_skin);
4600 if(disable_menu_alphacheck == 1)
4601 menu_fade_alpha = 1;
4603 menu_fade_alpha = (1 - autocvar__menu_alpha);
4604 hud_fg_alpha = cvar("hud_fg_alpha");
4606 hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
4607 hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
4608 hud_color_bg_team = cvar("hud_color_bg_team");
4610 hud_fontsize = HUD_GetFontsize("hud_fontsize");
4611 hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
4615 // HUD configure visible grid
4616 if(autocvar__hud_configure && autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
4620 for(i = 0; i < 1/bound(0.005, autocvar_hud_configure_grid_xsize, 0.2); ++i)
4622 drawfill(eX * i * vid_conwidth * bound(0.005, autocvar_hud_configure_grid_xsize, 0.2), eX + eY * vid_conheight, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4625 for(i = 0; i < 1/bound(0.005, autocvar_hud_configure_grid_ysize, 0.2); ++i)
4627 drawfill(eY * i * vid_conheight * bound(0.005, autocvar_hud_configure_grid_ysize, 0.2), eY + eX * vid_conwidth, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4633 if(teamplay && autocvar_hud_dock_color_team) {
4634 f = stof(getplayerkey(player_localentnum - 1, "colors"));
4635 color = colormapPaletteColor(mod(f, 16), 1) * autocvar_hud_dock_color_team;
4637 else if(autocvar_hud_dock_color == "shirt") {
4638 f = stof(getplayerkey(player_localentnum - 1, "colors"));
4639 color = colormapPaletteColor(floor(f / 16), 0);
4641 else if(autocvar_hud_dock_color == "pants") {
4642 f = stof(getplayerkey(player_localentnum - 1, "colors"));
4643 color = colormapPaletteColor(mod(f, 16), 1);
4646 color = stov(autocvar_hud_dock_color);
4649 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
4652 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
4653 if(precache_pic(pic) == "") {
4654 pic = "gfx/hud/default/dock";
4656 drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, autocvar_hud_dock_alpha * menu_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
4659 // cache the panel order into the panel_order array
4660 if(autocvar__hud_panelorder != hud_panelorder_prev) {
4661 if(hud_panelorder_prev)
4662 strunzone(hud_panelorder_prev);
4663 hud_panelorder_prev = strzone(autocvar__hud_panelorder);
4664 tokenize_console(autocvar__hud_panelorder);
4665 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4666 panel_order[i] = stof(argv(i));
4669 // draw panels in order specified by panel_order array
4670 for(i = HUD_PANEL_NUM - 1; i >= 0; --i) {
4671 HUD_DrawPanel(panel_order[i]);
4674 // TODO hud_'ify these
4675 if (cvar("cl_showspeed"))
4677 if (cvar("cl_showacceleration"))
4678 HUD_ShowAcceleration();
4680 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)
4681 localcmd("cmd selectteam auto; cmd join\n");
4683 hud_configure_prev = autocvar__hud_configure;
4685 if (!autocvar__hud_configure) // hud config mode disabled, enable normal alpha stuff again
4686 disable_menu_alphacheck = 0;