7 // a border picture is a texture containing nine parts:
8 // 1/4 width: left part
9 // 1/2 width: middle part (stretched)
10 // 1/4 width: right part
12 // 1/4 height: top part
13 // 1/2 height: middle part (stretched)
14 // 1/4 height: bottom part
15 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
17 if (theBorderSize_x < 0 && theBorderSize_y < 0) // draw whole image as it is
19 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
22 if (theBorderSize_x == 0 && theBorderSize_y == 0) // no border
24 // draw only the central part
25 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
32 //pic = draw_UseSkinFor(pic);
33 width = eX * theSize_x;
34 height = eY * theSize_y;
35 if(theSize_x <= theBorderSize_x * 2)
37 // not wide enough... draw just left and right then
38 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
39 if(theSize_y <= theBorderSize_y * 2)
41 // not high enough... draw just corners
42 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
43 drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0);
44 drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0);
45 drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0);
46 drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
50 dY = theBorderSize_x * eY;
51 drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
52 drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
53 drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0);
54 drawsubpic(theOrigin + width * 0.5 + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0' + eX - bW, '0 0.5 0' + bW, theColor, theAlpha, 0);
55 drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0);
56 drawsubpic(theOrigin + width * 0.5 + height - dY, width * 0.5 + dY, pic, '0 0.75 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
61 if(theSize_y <= theBorderSize_y * 2)
63 // not high enough... draw just top and bottom then
64 bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
65 dX = theBorderSize_x * eX;
66 drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
67 drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0);
68 drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0);
69 drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
70 drawsubpic(theOrigin + dX + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5 0 0' + bH, theColor, theAlpha, 0);
71 drawsubpic(theOrigin + width - dX + height * 0.5, dX + height * 0.5, pic, '0.75 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
75 dX = theBorderSize_x * eX;
76 dY = theBorderSize_x * eY;
77 drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
78 drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0);
79 drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0);
80 drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
81 drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
82 drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0);
83 drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
84 drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0);
85 drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
90 vector HUD_Get_Num_Color (float x, float maxvalue)
98 else if(x > maxvalue * 0.75) {
99 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
100 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
103 else if(x > maxvalue * 0.5) {
104 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
105 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
106 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
108 else if(x > maxvalue * 0.25) {
111 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
113 else if(x > maxvalue * 0.1) {
115 color_y = (x-20)*90/27/100; // green value between 0 -> 1
116 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
126 float stringwidth_colors(string s, vector theSize)
128 return stringwidth(s, TRUE, theSize);
131 float stringwidth_nocolors(string s, vector theSize)
133 return stringwidth(s, FALSE, theSize);
136 #define CENTERPRINT_MAX_LINES 30
137 string centerprint_messages[CENTERPRINT_MAX_LINES];
138 float centerprint_width[CENTERPRINT_MAX_LINES];
139 float centerprint_time;
140 float centerprint_expire;
141 float centerprint_num;
142 float centerprint_offset_hint;
143 vector centerprint_fontsize;
145 void centerprint(string strMessage)
147 float i, j, n, hcount;
150 centerprint_fontsize = HUD_GetFontsize("scr_centersize");
152 centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
154 if(cvar("scr_centertime") <= 0)
160 // strip trailing newlines
161 j = strlen(strMessage) - 1;
162 while(substring(strMessage, j, 1) == "\n" && j >= 0)
164 strMessage = substring(strMessage, 0, j + 1);
169 // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
171 while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
173 strMessage = substring(strMessage, j, strlen(strMessage) - j);
174 centerprint_offset_hint = j;
179 // if we get here, we have a message. Initialize its height.
182 n = tokenizebyseparator(strMessage, "\n");
184 for(j = 0; j < n; ++j)
186 getWrappedLine_remaining = argv(j);
187 while(getWrappedLine_remaining)
189 s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
190 if(centerprint_messages[i] != s) // don't fade the same message in, looks stupid
191 centerprint_time = time;
192 if(centerprint_messages[i])
193 strunzone(centerprint_messages[i]);
194 centerprint_messages[i] = strzone(s);
195 centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
198 // half height for empty lines looks better
204 if(i >= CENTERPRINT_MAX_LINES)
210 h = centerprint_fontsize_y*hcount;
212 havail = vid_conheight;
213 if(cvar("con_chatpos") < 0)
214 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
215 if(havail > vid_conheight - 70)
216 havail = vid_conheight - 70; // avoid overlapping HUD
219 float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
221 // here, the centerprint would cover the crosshair. REALLY BAD.
222 forbiddenmin = vid_conheight * 0.5 - h - 16;
223 forbiddenmax = vid_conheight * 0.5 + 16;
225 allowedmin = scoreboard_bottom;
226 allowedmax = havail - h;
227 preferred = (havail - h)/2;
230 // possible orderings (total: 4! / 4 = 6)
231 // allowedmin allowedmax forbiddenmin forbiddenmax
232 // forbiddenmin forbiddenmax allowedmin allowedmax
233 if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
235 // forbidden doesn't matter in this case
236 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
238 // allowedmin forbiddenmin allowedmax forbiddenmax
239 else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
241 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
243 // allowedmin forbiddenmin forbiddenmax allowedmax
244 else if(allowedmin < forbiddenmin)
246 // make sure the forbidden zone is not covered
247 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
248 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
250 centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
252 // forbiddenmin allowedmin allowedmax forbiddenmax
253 else if(allowedmax < forbiddenmax)
255 // it's better to leave the allowed zone (overlap with scoreboard) than
256 // to cover the forbidden zone (crosshair)
257 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
258 centerprint_start_y = forbiddenmax;
260 centerprint_start_y = forbiddenmin;
262 // forbiddenmin allowedmin forbiddenmax allowedmax
265 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
272 centerprint_expire = time + cvar("scr_centertime");
275 void HUD_DrawCenterPrint (void)
282 if(time - centerprint_time < 0.25)
283 a = (time - centerprint_time) / 0.25;
285 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
292 if(centerprint_num * cvar("scr_centersize") > 24 && scoreboard_active) // 24 = height of Scoreboard text
293 centerprint_start_y = scoreboard_bottom + centerprint_fontsize_y;
295 pos = centerprint_start;
296 for (i=0; i<centerprint_num; i = i + 1)
298 ts = centerprint_messages[i];
299 drawfontscale = sz * '1 1 0';
300 drawfont = hud_bigfont;
301 pos_x = (vid_conwidth - stringwidth(ts, TRUE, centerprint_fontsize)) * 0.5;
304 drawcolorcodedstring(pos + '0 1 0' * (1 - sz) * 0.5 *centerprint_fontsize_y, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
305 pos_y = pos_y + centerprint_fontsize_y;
308 // half height for empty lines looks better
309 pos_y = pos_y + sz * centerprint_fontsize_y * 0.5;
310 drawfontscale = '1 1 0';
315 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
317 position_x -= 2 / 3 * strlen(text) * scale_x;
318 drawstring(position, text, scale, rgb, alpha, flag);
321 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
323 position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
324 drawstring(position, text, scale, rgb, alpha, flag);
327 // return the string of the given race place
328 string race_PlaceName(float pos) {
336 return strcat(ftos(pos), "th");
339 // return the string of the onscreen race timer
340 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
348 if(histime == 0) // goal hit
352 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
362 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
368 lapstr = strcat(" (-", ftos(lapdelta), "L)");
371 else if(lapdelta < 0)
373 lapstr = strcat(" (+", ftos(-lapdelta), "L)");
377 else if(histime > 0) // anticipation
379 if(mytime >= histime)
380 timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
382 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
389 cpname = "Start line";
391 cpname = "Finish line";
393 cpname = strcat("Intermediate ", ftos(cp));
395 cpname = "Finish line";
398 return strcat(col, cpname);
399 else if(hisname == "")
400 return strcat(col, cpname, " (", timestr, ")");
402 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
405 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
406 float race_CheckName(string net_name) {
408 for (i=RANKINGS_CNT-1;i>=0;--i)
409 if(grecordholder[i] == net_name)
420 #define HUD_Write(s) fputs(fh, s)
421 // q: quoted, n: not quoted
422 #define HUD_Write_Cvar_n(cvar) HUD_Write(strcat("seta ", cvar, " ", cvar_string(cvar), "\n"))
423 #define HUD_Write_Cvar_q(cvar) HUD_Write(strcat("seta ", cvar, " \"", cvar_string(cvar), "\"\n"))
424 #define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel_name, cvar_suf))
425 #define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel_name, cvar_suf))
427 void HUD_Panel_ExportCfg(string cfgname)
430 string filename = strcat("hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg");
431 fh = fopen(filename, FILE_WRITE);
434 HUD_Write_Cvar_q("hud_skin");
435 HUD_Write_Cvar_q("hud_panel_bg");
436 HUD_Write_Cvar_q("hud_panel_bg_color");
437 HUD_Write_Cvar_q("hud_panel_bg_color_team");
438 HUD_Write_Cvar_q("hud_panel_bg_alpha");
439 HUD_Write_Cvar_q("hud_panel_bg_border");
440 HUD_Write_Cvar_q("hud_panel_bg_padding");
441 HUD_Write_Cvar_q("hud_panel_fg_alpha");
444 HUD_Write_Cvar_q("hud_dock");
445 HUD_Write_Cvar_q("hud_dock_color");
446 HUD_Write_Cvar_q("hud_dock_color_team");
447 HUD_Write_Cvar_q("hud_dock_alpha");
450 HUD_Write_Cvar_q("hud_progressbar_alpha");
451 HUD_Write_Cvar_q("hud_progressbar_strength_color");
452 HUD_Write_Cvar_q("hud_progressbar_shield_color");
453 HUD_Write_Cvar_q("hud_progressbar_health_color");
454 HUD_Write_Cvar_q("hud_progressbar_armor_color");
455 HUD_Write_Cvar_q("hud_progressbar_fuel_color");
456 HUD_Write_Cvar_q("hud_progressbar_nexball_color");
459 HUD_Write_Cvar_q("_hud_panelorder");
462 HUD_Write_Cvar_q("hud_configure_grid");
463 HUD_Write_Cvar_q("hud_configure_grid_xsize");
464 HUD_Write_Cvar_q("hud_configure_grid_ysize");
467 HUD_Write_Cvar_q("scr_centerpos");
470 // common cvars for all panels
472 for (i = 0; i < HUD_PANEL_NUM; ++i)
474 HUD_Panel_GetName(i);
476 HUD_Write_PanelCvar_n("");
477 HUD_Write_PanelCvar_q("_pos");
478 HUD_Write_PanelCvar_q("_size");
479 HUD_Write_PanelCvar_q("_bg");
480 HUD_Write_PanelCvar_q("_bg_color");
481 HUD_Write_PanelCvar_q("_bg_color_team");
482 HUD_Write_PanelCvar_q("_bg_alpha");
483 HUD_Write_PanelCvar_q("_bg_border");
484 HUD_Write_PanelCvar_q("_bg_padding");
486 case HUD_PANEL_WEAPONS:
487 HUD_Write_PanelCvar_q("_complainbubble");
488 HUD_Write_PanelCvar_q("_complainbubble_padding");
489 HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
490 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
491 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
492 HUD_Write_PanelCvar_q("_ammo_color");
493 HUD_Write_PanelCvar_q("_ammo_alpha");
494 HUD_Write_PanelCvar_q("_aspect");
497 HUD_Write_PanelCvar_q("_onlycurrent");
498 HUD_Write_PanelCvar_q("_iconalign");
499 HUD_Write_PanelCvar_q("_progressbar");
500 HUD_Write_PanelCvar_q("_progressbar_name");
501 HUD_Write_PanelCvar_q("_text");
503 case HUD_PANEL_POWERUPS:
504 HUD_Write_PanelCvar_q("_flip");
505 HUD_Write_PanelCvar_q("_iconalign");
506 HUD_Write_PanelCvar_q("_baralign");
507 HUD_Write_PanelCvar_q("_progressbar");
508 HUD_Write_PanelCvar_q("_progressbar_strength");
509 HUD_Write_PanelCvar_q("_progressbar_shield");
511 case HUD_PANEL_HEALTHARMOR:
512 HUD_Write_PanelCvar_q("_flip");
513 HUD_Write_PanelCvar_q("_iconalign");
514 HUD_Write_PanelCvar_q("_baralign");
515 HUD_Write_PanelCvar_q("_progressbar");
516 HUD_Write_PanelCvar_q("_progressbar_health");
517 HUD_Write_PanelCvar_q("_progressbar_armor");
518 HUD_Write_PanelCvar_q("_text");
520 case HUD_PANEL_NOTIFY:
521 HUD_Write_PanelCvar_q("_flip");
522 HUD_Write_PanelCvar_q("_print");
524 case HUD_PANEL_RADAR:
525 HUD_Write_PanelCvar_q("_foreground_alpha");
528 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
530 case HUD_PANEL_PRESSEDKEYS:
531 HUD_Write_PanelCvar_q("_aspect");
533 case HUD_PANEL_INFOMESSAGES:
534 HUD_Write_PanelCvar_q("_flip");
539 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
541 print("^2Successfully exported to ", filename, "! (Note: It's saved in data/data/)\n");
545 print("^1Couldn't write to ", filename, "\n");
548 const float hlBorderSize = 4;
549 const string hlBorder = "gfx/hud/default/border_highlighted";
550 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
551 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
553 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
554 drawpic_tiled(panel_pos - '1 1 0' * myBorder, hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
555 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * (panel_size_y + 2 * myBorder - hlBorderSize), hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
556 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize, hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
557 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize + eX * (panel_size_x + 2 * myBorder - hlBorderSize), hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
560 // draw the background/borders
561 #define HUD_Panel_DrawBg(alpha)\
563 draw_BorderPicture(panel_pos - '1 1 0' * panel_bg_border, panel_bg, panel_size + '1 1 0' * 2 * panel_bg_border, panel_bg_color, panel_bg_alpha * alpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER));\
564 if(highlightedPanel_prev == active_panel && autocvar__hud_configure)\
566 HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha) * alpha);\
567 } ENDS_WITH_CURLY_BRACE
569 void HUD_Panel_DrawProgressBar(vector pos, vector mySize, string pic, float vertical, float barflip, float x, vector color, float alpha, float drawflag)
577 pic = strcat(hud_skin_path, "/", pic, "_vertical");
578 if(precache_pic(pic) == "") {
579 pic = "gfx/hud/default/statusbar_vertical";
583 drawsetcliparea(pos_x, pos_y + mySize_y * (1 - x), mySize_x, mySize_y * x);
585 drawsetcliparea(pos_x, pos_y, mySize_x, mySize_y * x);
587 pic = strcat(hud_skin_path, "/", pic);
588 if(precache_pic(pic) == "") {
589 pic = "gfx/hud/default/statusbar";
593 drawsetcliparea(pos_x + mySize_x * (1 - x), pos_y, mySize_x * x, mySize_y);
595 drawsetcliparea(pos_x, pos_y, mySize_x * x, mySize_y);
598 drawpic(pos, pic, mySize, color, alpha, drawflag);
602 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
608 pic = strcat(hud_skin_path, "/num_leading");
609 if(precache_pic(pic) == "") {
610 pic = "gfx/hud/default/num_leading";
613 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
614 if(mySize_x/mySize_y > 2)
615 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);
616 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);
619 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
620 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
629 myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
630 targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
632 for (i = 0; i < HUD_PANEL_NUM; ++i) {
633 if(i == highlightedPanel || !panel_enabled)
636 HUD_Panel_UpdatePosSizeForId(i);
638 panel_pos -= '1 1 0' * panel_bg_border;
639 panel_size += '2 2 0' * panel_bg_border;
641 if(myPos_y + mySize_y < panel_pos_y)
643 if(myPos_y > panel_pos_y + panel_size_y)
646 if(myPos_x + mySize_x < panel_pos_x)
648 if(myPos_x > panel_pos_x + panel_size_x)
651 // OK, there IS a collision.
653 myCenter_x = myPos_x + 0.5 * mySize_x;
654 myCenter_y = myPos_y + 0.5 * mySize_y;
656 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
657 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
659 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
661 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
662 myTarget_x = panel_pos_x - mySize_x;
663 else // push it upwards
664 myTarget_y = panel_pos_y - mySize_y;
666 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
668 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
669 myTarget_x = panel_pos_x + panel_size_x;
670 else // push it upwards
671 myTarget_y = panel_pos_y - mySize_y;
673 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
675 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
676 myTarget_x = panel_pos_x - mySize_x;
677 else // push it downwards
678 myTarget_y = panel_pos_y + panel_size_y;
680 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
682 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
683 myTarget_x = panel_pos_x + panel_size_x;
684 else // push it downwards
685 myTarget_y = panel_pos_y + panel_size_y;
687 //if(cvar("hud_configure_checkcollisions_debug"))
688 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
694 void HUD_Panel_SetPos(vector pos)
696 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
700 //if(cvar("hud_configure_checkcollisions_debug"))
701 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
703 if(autocvar_hud_configure_grid)
705 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;
706 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;
709 if(hud_configure_checkcollisions)
710 pos = HUD_Panel_CheckMove(pos, mySize);
712 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
713 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
716 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
718 HUD_Panel_GetName(highlightedPanel);
719 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
722 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
723 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
728 float dist_x, dist_y;
730 ratio = mySize_x/mySize_y;
732 for (i = 0; i < HUD_PANEL_NUM; ++i) {
733 if(i == highlightedPanel || !panel_enabled)
736 HUD_Panel_UpdatePosSizeForId(i);
738 panel_pos -= '1 1 0' * panel_bg_border;
739 panel_size += '2 2 0' * panel_bg_border;
741 targEndPos = panel_pos + panel_size;
743 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
744 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
747 if (resizeCorner == 1)
749 // check if this panel is on our way
750 if (resizeorigin_x <= panel_pos_x)
752 if (resizeorigin_y <= panel_pos_y)
754 if (targEndPos_x <= resizeorigin_x - mySize_x)
756 if (targEndPos_y <= resizeorigin_y - mySize_y)
759 // there is a collision:
760 // detect which side of the panel we are facing is actually limiting the resizing
761 // (which side the resize direction finds for first) and reduce the size up to there
763 // dist is the distance between resizeorigin and the "analogous" point of the panel
764 // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
765 dist_x = resizeorigin_x - targEndPos_x;
766 dist_y = resizeorigin_y - targEndPos_y;
767 if (dist_y <= 0 || dist_x / dist_y > ratio)
768 mySize_x = min(mySize_x, dist_x);
770 mySize_y = min(mySize_y, dist_y);
772 else if (resizeCorner == 2)
774 if (resizeorigin_x >= targEndPos_x)
776 if (resizeorigin_y <= panel_pos_y)
778 if (panel_pos_x >= resizeorigin_x + mySize_x)
780 if (targEndPos_y <= resizeorigin_y - mySize_y)
783 dist_x = panel_pos_x - resizeorigin_x;
784 dist_y = resizeorigin_y - targEndPos_y;
785 if (dist_y <= 0 || dist_x / dist_y > ratio)
786 mySize_x = min(mySize_x, dist_x);
788 mySize_y = min(mySize_y, dist_y);
790 else if (resizeCorner == 3)
792 if (resizeorigin_x <= panel_pos_x)
794 if (resizeorigin_y >= targEndPos_y)
796 if (targEndPos_x <= resizeorigin_x - mySize_x)
798 if (panel_pos_y >= resizeorigin_y + mySize_y)
801 dist_x = resizeorigin_x - targEndPos_x;
802 dist_y = panel_pos_y - resizeorigin_y;
803 if (dist_y <= 0 || dist_x / dist_y > ratio)
804 mySize_x = min(mySize_x, dist_x);
806 mySize_y = min(mySize_y, dist_y);
808 else if (resizeCorner == 4)
810 if (resizeorigin_x >= targEndPos_x)
812 if (resizeorigin_y >= targEndPos_y)
814 if (panel_pos_x >= resizeorigin_x + mySize_x)
816 if (panel_pos_y >= resizeorigin_y + mySize_y)
819 dist_x = panel_pos_x - resizeorigin_x;
820 dist_y = panel_pos_y - resizeorigin_y;
821 if (dist_y <= 0 || dist_x / dist_y > ratio)
822 mySize_x = min(mySize_x, dist_x);
824 mySize_y = min(mySize_y, dist_y);
826 //if(cvar("hud_configure_checkcollisions_debug"))
827 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
833 void HUD_Panel_SetPosSize(vector mySize)
835 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
837 resizeorigin = panel_click_resizeorigin;
840 // minimum panel size cap
841 mySize_x = max(0.025 * vid_conwidth, mySize_x);
842 mySize_y = max(0.025 * vid_conheight, mySize_y);
844 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.
846 mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
847 mySize_y = max(2 * cvar("con_chatsize") + 2 * panel_bg_padding, mySize_y);
850 // collision testing|
851 // -----------------+
853 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
854 if(resizeCorner == 1) {
855 myPos_x = resizeorigin_x - mySize_x;
856 myPos_y = resizeorigin_y - mySize_y;
857 } else if(resizeCorner == 2) {
858 myPos_x = resizeorigin_x;
859 myPos_y = resizeorigin_y - mySize_y;
860 } else if(resizeCorner == 3) {
861 myPos_x = resizeorigin_x - mySize_x;
862 myPos_y = resizeorigin_y;
863 } else { // resizeCorner == 4
864 myPos_x = resizeorigin_x;
865 myPos_y = resizeorigin_y;
868 // left/top screen edges
870 mySize_x = mySize_x + myPos_x;
872 mySize_y = mySize_y + myPos_y;
874 // bottom/right screen edges
875 if(myPos_x + mySize_x > vid_conwidth)
876 mySize_x = vid_conwidth - myPos_x;
877 if(myPos_y + mySize_y > vid_conheight)
878 mySize_y = vid_conheight - myPos_y;
880 //if(cvar("hud_configure_checkcollisions_debug"))
881 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
883 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
884 if(autocvar_hud_configure_grid)
886 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;
887 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;
890 if(hud_configure_checkcollisions)
891 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
893 // 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)
894 mySize_x = max(0.025 * vid_conwidth, mySize_x);
895 mySize_y = max(0.025 * vid_conheight, mySize_y);
897 // do another pos check, as size might have changed by now
898 if(resizeCorner == 1) {
899 myPos_x = resizeorigin_x - mySize_x;
900 myPos_y = resizeorigin_y - mySize_y;
901 } else if(resizeCorner == 2) {
902 myPos_x = resizeorigin_x;
903 myPos_y = resizeorigin_y - mySize_y;
904 } else if(resizeCorner == 3) {
905 myPos_x = resizeorigin_x - mySize_x;
906 myPos_y = resizeorigin_y;
907 } else { // resizeCorner == 4
908 myPos_x = resizeorigin_x;
909 myPos_y = resizeorigin_y;
912 //if(cvar("hud_configure_checkcollisions_debug"))
913 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
915 HUD_Panel_GetName(highlightedPanel);
917 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
918 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
920 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
921 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
925 float prevMouseClicked; // previous state
926 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
927 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
929 float pressed_key_time;
930 void HUD_Panel_Arrow_Action(float nPrimary)
932 if (highlightedPanel_prev == -1 || mouseClicked)
935 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
938 if(autocvar_hud_configure_grid)
940 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
942 if (hudShiftState & S_SHIFT)
943 step = bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
945 step = 2 * bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
949 if (hudShiftState & S_SHIFT)
950 step = bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
952 step = 2 * bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
957 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
958 step = vid_conheight;
961 if (hudShiftState & S_SHIFT)
962 step = (step / 256); // more precision
964 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
967 highlightedPanel = highlightedPanel_prev;
969 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
971 vector prev_pos, prev_size;
972 prev_pos = panel_pos;
973 prev_size = panel_size;
975 if (hudShiftState & S_ALT) // resize
977 highlightedAction = 1;
978 if(nPrimary == K_UPARROW)
980 else if(nPrimary == K_RIGHTARROW)
982 else if(nPrimary == K_LEFTARROW)
984 else // if(nPrimary == K_DOWNARROW)
987 // ctrl+arrow reduces the size, instead of increasing it
988 // Note that ctrl disables collisions check too, but it's fine
989 // since we don't collide with anything reducing the size
990 if (hudShiftState & S_CTRL) {
992 resizeCorner = 5 - resizeCorner;
997 panel_click_resizeorigin = panel_pos;
998 if(resizeCorner == 1) {
999 panel_click_resizeorigin += mySize;
1001 } else if(resizeCorner == 2) {
1002 panel_click_resizeorigin_y += mySize_y;
1004 } else if(resizeCorner == 3) {
1005 panel_click_resizeorigin_x += mySize_x;
1007 } else { // resizeCorner == 4
1010 HUD_Panel_SetPosSize(mySize);
1014 highlightedAction = 2;
1017 if(nPrimary == K_UPARROW)
1019 else if(nPrimary == K_DOWNARROW)
1021 else if(nPrimary == K_LEFTARROW)
1023 else // if(nPrimary == K_RIGHTARROW)
1026 HUD_Panel_SetPos(pos);
1029 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1031 if (prev_pos != panel_pos || prev_size != panel_size)
1034 panel_pos_backup = prev_pos;
1035 panel_size_backup = prev_size;
1036 highlightedPanel_backup = highlightedPanel;
1040 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1044 if(!autocvar__hud_configure)
1047 // allow console bind to work
1050 con_keys = findkeysforcommand("toggleconsole");
1051 keys = tokenize(con_keys);
1053 float hit_con_bind, i;
1054 for (i = 0; i < keys; ++i)
1056 if(nPrimary == stof(argv(i)))
1060 if(bInputType == 0) {
1061 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
1062 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
1063 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
1065 else if(bInputType == 1) {
1066 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
1067 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
1068 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
1071 if(nPrimary == K_MOUSE1)
1073 if(bInputType == 0) { // key pressed
1077 else if(bInputType == 1) {// key released
1082 else if(nPrimary == K_ESCAPE)
1084 if (bInputType == 1)
1087 menu_enabled_time = time;
1088 localcmd("menu_showhudexit\n");
1090 else if(hudShiftState & S_CTRL)
1095 if(nPrimary == K_SPACE) // enable/disable highlighted panel or dock
1097 if (bInputType == 1)
1100 if (highlightedPanel_prev != -1)
1101 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
1103 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
1105 if(nPrimary == 'c') // copy highlighted panel size
1107 if (bInputType == 1)
1110 if (highlightedPanel_prev != -1)
1112 panel_size_copied = panel_size;
1113 highlightedPanel_copied = highlightedPanel_prev;
1116 else if(nPrimary == 'v') // past copied size on the highlighted panel
1118 if (bInputType == 1)
1121 if (highlightedPanel_copied == -1 || highlightedPanel_prev == -1)
1124 HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev);
1126 // reduce size if it'd go beyond screen boundaries
1127 vector tmp_size = panel_size_copied;
1128 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
1129 tmp_size_x = vid_conwidth - panel_pos_x;
1130 if (panel_pos_y + panel_size_copied_y > vid_conheight)
1131 tmp_size_y = vid_conheight - panel_pos_y;
1133 if (panel_size == tmp_size)
1137 panel_pos_backup = panel_pos;
1138 panel_size_backup = panel_size;
1139 highlightedPanel_backup = highlightedPanel_prev;
1141 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
1142 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1144 else if(nPrimary == 'z') // undo last action
1146 if (bInputType == 1)
1148 //restore previous values
1149 if (highlightedPanel_backup != -1)
1151 HUD_Panel_GetName(highlightedPanel_backup);
1152 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
1153 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
1154 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
1155 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
1156 highlightedPanel_backup = -1;
1160 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
1162 if (bInputType == 1)
1164 pressed_key_time = 0;
1167 else if (pressed_key_time == 0)
1168 pressed_key_time = time;
1170 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
1172 else if(hit_con_bind)
1175 return true; // Suppress ALL other input
1178 float HUD_Panel_HighlightCheck()
1184 while(j <= HUD_PANEL_NUM)
1189 HUD_Panel_UpdatePosSizeForId(i);
1191 panelPos = panel_pos;
1192 panelSize = panel_size;
1193 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1196 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1200 // resize from topleft border
1201 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)
1205 // resize from topright border
1206 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)
1210 // resize from bottomleft border
1211 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)
1215 // resize from bottomright border
1216 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)
1224 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
1225 void HUD_Panel_FirstInDrawQ(float id)
1228 var float place = -1;
1229 // find out where in the array our current id is, save into place
1230 for(i = 0; i < HUD_PANEL_NUM; ++i)
1232 if(panel_order[i] == id)
1238 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
1240 place = HUD_PANEL_NUM - 1;
1242 // move all ids up by one step in the array until "place"
1243 for(i = place; i > 0; --i)
1245 panel_order[i] = panel_order[i-1];
1247 // now save the new top id
1248 panel_order[0] = id;
1250 // let's save them into the cvar by some strcat trickery
1252 for(i = 0; i < HUD_PANEL_NUM; ++i)
1254 s = strcat(s, ftos(panel_order[i]), " ");
1256 cvar_set("_hud_panelorder", s);
1257 if(hud_panelorder_prev)
1258 strunzone(hud_panelorder_prev);
1259 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
1262 void HUD_Panel_Highlight()
1268 while(j <= HUD_PANEL_NUM)
1273 HUD_Panel_UpdatePosSizeForId(i);
1275 panelPos = panel_pos;
1276 panelSize = panel_size;
1277 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1280 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1282 highlightedPanel = i;
1283 HUD_Panel_FirstInDrawQ(i);
1284 highlightedAction = 1;
1285 panel_click_distance = mousepos - panelPos;
1288 // resize from topleft border
1289 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)
1291 highlightedPanel = i;
1292 HUD_Panel_FirstInDrawQ(i);
1293 highlightedAction = 2;
1295 panel_click_distance = mousepos - panelPos;
1296 panel_click_resizeorigin = panelPos + panelSize;
1299 // resize from topright border
1300 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)
1302 highlightedPanel = i;
1303 HUD_Panel_FirstInDrawQ(i);
1304 highlightedAction = 2;
1306 panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
1307 panel_click_distance_y = mousepos_y - panelPos_y;
1308 panel_click_resizeorigin = panelPos + eY * panelSize_y;
1311 // resize from bottomleft border
1312 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)
1314 highlightedPanel = i;
1315 HUD_Panel_FirstInDrawQ(i);
1316 highlightedAction = 2;
1318 panel_click_distance_x = mousepos_x - panelPos_x;
1319 panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
1320 panel_click_resizeorigin = panelPos + eX * panelSize_x;
1323 // resize from bottomright border
1324 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)
1326 highlightedPanel = i;
1327 HUD_Panel_FirstInDrawQ(i);
1328 highlightedAction = 2;
1330 panel_click_distance = panelSize - mousepos + panelPos;
1331 panel_click_resizeorigin = panelPos;
1336 highlightedPanel_prev = -1;
1341 float highlightcheck;
1342 vector prev_pos, prev_size;
1343 void HUD_Panel_Mouse()
1345 // 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
1346 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1350 print("menu_enabled: ", ftos(menu_enabled), "\n");
1351 print("Highlighted: ", ftos(highlightedPanel), "\n");
1352 print("Menu alpha: ", cvar_string("_menu_alpha"), "\n");
1355 // instantly hide the editor cursor if we open the HUDExit dialog
1356 // as hud_fade_alpha doesn't decrease to 0 in this case
1357 // TODO: find a way to fade the cursor out even in this case
1358 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1361 if(mouseClicked == 0 && menu_enabled != 2 && highlightedPanel >= 0) { // don't reset these variables in menu_enabled mode 2!
1362 highlightedPanel = -1;
1363 highlightedAction = 0;
1365 if(highlightedPanel != -1)
1366 highlightedPanel_prev = highlightedPanel;
1368 mousepos = mousepos + getmousepos() * cvar("menu_mouse_speed");
1370 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1371 mousepos_y = bound(0, mousepos_y, vid_conheight);
1375 if(prevMouseClicked == 0)
1377 HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1378 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1379 prev_pos = panel_pos;
1380 prev_size = panel_size;
1383 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1385 if (prev_pos != panel_pos || prev_size != panel_size)
1387 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
1389 panel_pos_backup = prev_pos;
1390 panel_size_backup = prev_size;
1391 highlightedPanel_backup = highlightedPanel;
1394 // in case the clicked panel is inside another panel and we aren't
1395 // moving it, avoid the immediate "fix" of its position/size
1396 // (often unwanted and hateful) by disabling collisions check
1397 hud_configure_checkcollisions = false;
1399 if(highlightedAction == 1)
1400 HUD_Panel_SetPos(mousepos - panel_click_distance);
1401 else if(highlightedAction == 2)
1404 if(resizeCorner == 1) {
1405 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1406 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1407 } else if(resizeCorner == 2) {
1408 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1409 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1410 } else if(resizeCorner == 3) {
1411 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1412 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1413 } else { // resizeCorner == 4
1414 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1415 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1417 HUD_Panel_SetPosSize(mySize);
1420 // doubleclick check
1421 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1423 mouseClicked = 0; // to prevent spam, I guess.
1425 menu_enabled_time = time;
1426 HUD_Panel_GetName(highlightedPanel);
1427 localcmd("menu_showhudoptions ", panel_name, "\n");
1430 if(prevMouseClicked == 0)
1432 prevMouseClickedTime = time;
1433 prevMouseClickedPos = mousepos;
1438 highlightcheck = HUD_Panel_HighlightCheck();
1440 // draw cursor after performing move/resize to have the panel pos/size updated before highlightcheck
1442 cursorsize = '32 32 0';
1444 if(highlightcheck == 0)
1445 drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1446 else if(highlightcheck == 1)
1447 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_move.tga"), '32 32 0', '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1448 else if(highlightcheck == 2)
1449 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_resize.tga"), '32 32 0', '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1451 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_resize2.tga"), '32 32 0', '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1453 prevMouseClicked = mouseClicked;
1456 // Weapon icons (#0)
1458 float weaponspace[10];
1459 #define HUD_Weapons_Clear()\
1461 for(idx = 0; idx < 10; ++idx)\
1462 weaponspace[idx] = 0
1464 entity weaponorder[WEP_MAXCOUNT];
1465 void weaponorder_swap(float i, float j, entity pass)
1469 weaponorder[i] = weaponorder[j];
1473 string weaponorder_cmp_str;
1474 float weaponorder_cmp(float i, float j, entity pass)
1477 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1478 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1479 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)
1482 float GetAmmoStat(float i)
1486 case 0: return STAT_SHELLS;
1487 case 1: return STAT_NAILS;
1488 case 2: return STAT_ROCKETS;
1489 case 3: return STAT_CELLS;
1490 case 4: return STAT_FUEL;
1495 float GetAmmoTypeForWep(float i)
1499 case WEP_SHOTGUN: return 0;
1500 case WEP_UZI: return 1;
1501 case WEP_GRENADE_LAUNCHER: return 2;
1502 case WEP_MINE_LAYER: return 2;
1503 case WEP_ELECTRO: return 3;
1504 case WEP_CRYLINK: return 3;
1505 case WEP_HLAC: return 3;
1506 case WEP_MINSTANEX: return 3;
1507 case WEP_NEX: return 3;
1508 case WEP_CAMPINGRIFLE: return 1;
1509 case WEP_HAGAR: return 2;
1510 case WEP_ROCKET_LAUNCHER: return 2;
1511 case WEP_SEEKER: return 2;
1512 case WEP_FIREBALL: return 4;
1513 case WEP_HOOK: return 3;
1518 void HUD_Weapons(void)
1521 float center_x, center_y;
1523 if(!autocvar_hud_panel_weapons && !autocvar__hud_configure)
1526 float timeout = cvar("hud_panel_weapons_timeout");
1527 float timeout_effect_length, timein_effect_length;
1528 if (cvar("hud_panel_weapons_timeout_effect") == 0)
1530 timeout_effect_length = 0;
1531 timein_effect_length = 0;
1535 timeout_effect_length = 0.75;
1536 timein_effect_length = 0.375;
1539 if (timeout && time >= weapontime + timeout + timeout_effect_length && !autocvar__hud_configure)
1541 weaponprevtime = time;
1545 active_panel = HUD_PANEL_WEAPONS;
1546 HUD_Panel_UpdateCvars(weapons);
1548 if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
1550 f = (time - (weapontime + timeout)) / timeout_effect_length;
1551 if (cvar("hud_panel_weapons_timeout_effect"))
1553 panel_bg_alpha *= (1 - f);
1554 panel_fg_alpha *= (1 - f);
1556 if (cvar("hud_panel_weapons_timeout_effect") == 1)
1558 f *= f; // for a cooler movement
1559 center_x = panel_pos_x + panel_size_x/2;
1560 center_y = panel_pos_y + panel_size_y/2;
1561 screen_ar = vid_conwidth/vid_conheight;
1562 if (center_x/center_y < screen_ar) //bottom left
1564 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1565 panel_pos_y += f * (vid_conheight - panel_pos_y);
1567 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1571 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1572 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1574 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1577 weaponprevtime = time - (1 - f) * timein_effect_length;
1579 else if (timeout && time < weaponprevtime + timein_effect_length && !autocvar__hud_configure)
1581 f = (time - weaponprevtime) / timein_effect_length;
1582 if (cvar("hud_panel_weapons_timeout_effect"))
1584 panel_bg_alpha *= (f);
1585 panel_fg_alpha *= (f);
1587 if (cvar("hud_panel_weapons_timeout_effect") == 1)
1589 f *= f; // for a cooler movement
1591 center_x = panel_pos_x + panel_size_x/2;
1592 center_y = panel_pos_y + panel_size_y/2;
1593 screen_ar = vid_conwidth/vid_conheight;
1594 if (center_x/center_y < screen_ar) //bottom left
1596 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
1597 panel_pos_y += f * (vid_conheight - panel_pos_y);
1599 panel_pos_x -= f * (panel_pos_x + panel_size_x);
1603 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
1604 panel_pos_x += f * (vid_conwidth - panel_pos_x);
1606 panel_pos_y -= f * (panel_pos_y + panel_size_y);
1611 float i, weapid, wpnalpha, weapon_cnt;
1613 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1615 self = get_weaponinfo(i);
1616 if(self.impulse >= 0)
1620 // TODO make this configurable
1621 if(weaponorder_bypriority != cvar_string("cl_weaponpriority"))
1623 if(weaponorder_bypriority)
1624 strunzone(weaponorder_bypriority);
1625 if(weaponorder_byimpulse)
1626 strunzone(weaponorder_byimpulse);
1628 weaponorder_bypriority = strzone(cvar_string("cl_weaponpriority"));
1629 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
1630 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1633 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1635 self = get_weaponinfo(i);
1636 if(self.impulse >= 0)
1638 weaponorder[weapon_cnt] = self;
1642 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1644 weaponorder_cmp_str = string_null;
1647 HUD_Panel_DrawBg(1);
1648 if(panel_bg_padding)
1650 panel_pos += '1 1 0' * panel_bg_padding;
1651 panel_size -= '2 2 0' * panel_bg_padding;
1654 if(cvar_or("hud_panel_weapons_fade", 1))
1656 wpnalpha = 3.2 - 2 * (time - weapontime);
1657 wpnalpha = bound(0.7, wpnalpha, 1) * panel_fg_alpha;
1660 wpnalpha = panel_fg_alpha;
1662 HUD_Weapons_Clear();
1664 float rows, columns;
1665 float aspect = cvar("hud_panel_weapons_aspect");
1666 rows = panel_size_y/panel_size_x;
1667 rows = bound(1, floor((sqrt(4 * aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1669 columns = ceil(WEP_COUNT/rows);
1672 float a, type, fullammo;
1674 when = cvar("hud_panel_weapons_complainbubble_time");
1676 fadetime = cvar("hud_panel_weapons_complainbubble_fadetime");
1682 float fullammo_shells, fullammo_nails, fullammo_rockets, fullammo_cells, fullammo_fuel;
1685 wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
1686 float barsize_x, barsize_y, baroffset_x, baroffset_y;
1687 float show_ammo = cvar("hud_panel_weapons_ammo");
1690 fullammo_shells = cvar("hud_panel_weapons_ammo_full_shells");
1691 fullammo_nails = cvar("hud_panel_weapons_ammo_full_nails");
1692 fullammo_rockets = cvar("hud_panel_weapons_ammo_full_rockets");
1693 fullammo_cells = cvar("hud_panel_weapons_ammo_full_cells");
1694 fullammo_fuel = cvar("hud_panel_weapons_ammo_full_fuel");
1695 ammo_color = stov(cvar_string("hud_panel_weapons_ammo_color"));
1696 ammo_alpha = panel_fg_alpha * cvar("hud_panel_weapons_ammo_alpha");
1699 if(wpnsize_x/wpnsize_y > aspect)
1701 barsize_x = aspect * wpnsize_y;
1702 barsize_y = wpnsize_y;
1703 baroffset_x = (wpnsize_x - barsize_x) / 2;
1707 barsize_y = 1/aspect * wpnsize_x;
1708 barsize_x = wpnsize_x;
1709 baroffset_y = (wpnsize_y - barsize_y) / 2;
1713 float show_accuracy;
1715 if(cvar("hud_panel_weapons_accuracy") && acc_levels)
1717 show_accuracy = true;
1718 if (acc_col_x[0] == -1)
1719 for (i = 0; i < acc_levels; ++i)
1720 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
1723 float weapons_st = getstati(STAT_WEAPONS);
1724 float label = cvar("hud_panel_weapons_label");
1726 for(i = 0; i < weapon_cnt; ++i)
1728 wpnpos = panel_pos + eX * column * wpnsize_x + eY * row * wpnsize_y;
1730 self = weaponorder[i];
1731 weapid = self.impulse;
1733 // draw background behind currently selected weapon
1734 if(self.weapon == activeweapon)
1735 drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1737 // draw the weapon accuracy
1740 weapon_stats = weapon_accuracy[self.weapon-WEP_FIRST];
1741 if(weapon_stats >= 0)
1743 // find the max level lower than weapon_stats
1746 while ( j && weapon_stats < acc_lev[j] )
1749 // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
1751 factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
1753 color = color + factor * (acc_col[j+1] - color);
1755 drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
1759 // draw the weapon icon
1760 if((weapid >= 0) && (weapons_st & self.weapons))
1762 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
1764 if(label == 1) // weapon number
1765 drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1766 else if(label == 2) // bind
1767 drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1769 // draw ammo status bar
1770 if(show_ammo && weapid != WEP_TUBA && weapid != WEP_LASER && weapid != WEP_PORTO)
1773 type = GetAmmoTypeForWep(weapid);
1775 a = getstati(GetAmmoStat(type)); // how much ammo do we have?
1780 case 0: fullammo = fullammo_shells; break;
1781 case 1: fullammo = fullammo_nails; break;
1782 case 2: fullammo = fullammo_rockets; break;
1783 case 3: fullammo = fullammo_cells; break;
1784 case 4: fullammo = fullammo_fuel; break;
1785 default: fullammo = 60;
1789 wpnpos_x + baroffset_x,
1790 wpnpos_y + baroffset_y,
1791 barsize_x * bound(0, a/fullammo, 1),
1793 drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
1794 drawresetcliparea();
1799 // draw a "ghost weapon icon" if you don't have the weapon
1802 drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
1805 // draw the complain message
1806 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && cvar("hud_panel_weapons_complainbubble"))
1810 if(complain_weapon_time + when > time)
1813 a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
1817 if(complain_weapon_time + when > time)
1824 if(complain_weapon_type == 0) {
1826 color = stov(cvar_string("hud_panel_weapons_complainbubble_color_outofammo"));
1828 else if(complain_weapon_type == 1) {
1830 color = stov(cvar_string("hud_panel_weapons_complainbubble_color_donthave"));
1834 color = stov(cvar_string("hud_panel_weapons_complainbubble_color_unavailable"));
1836 float padding = cvar("hud_panel_weapons_complainbubble_padding");
1837 drawpic_aspect_skin(wpnpos + '1 1 0' * padding, "weapon_complainbubble", wpnsize - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
1838 drawstring_aspect(wpnpos + '1 1 0' * padding, s, wpnsize - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
1854 float GetAmmoItemCode(float i)
1858 case 0: return IT_SHELLS;
1859 case 1: return IT_NAILS;
1860 case 2: return IT_ROCKETS;
1861 case 3: return IT_CELLS;
1862 case 4: return IT_FUEL;
1867 string GetAmmoPicture(float i)
1871 case 0: return "ammo_shells";
1872 case 1: return "ammo_bullets";
1873 case 2: return "ammo_rockets";
1874 case 3: return "ammo_cells";
1875 case 4: return "ammo_fuel";
1880 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
1883 if(autocvar__hud_configure)
1885 currently_selected = (itemcode == 2); //rockets always selected
1889 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
1898 if(currently_selected)
1903 vector picpos, numpos;
1904 if(autocvar_hud_panel_ammo_iconalign)
1907 picpos = myPos + eX * 2 * mySize_y;
1911 numpos = myPos + eX * mySize_y;
1915 if (currently_selected)
1916 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1918 if(a > 0 && cvar("hud_panel_ammo_progressbar"))
1919 HUD_Panel_DrawProgressBar(myPos + eX * cvar("hud_panel_ammo_progressbar_xoffset") * mySize_x, mySize - eX * cvar("hud_panel_ammo_progressbar_xoffset") * mySize_x, cvar_string("hud_panel_ammo_progressbar_name"), 0, 0, min(1, a/cvar("hud_panel_ammo_maxammo")), color, autocvar_hud_progressbar_alpha * panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1921 if(cvar("hud_panel_ammo_text"))
1924 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1925 else // "ghost" ammo count
1926 drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
1929 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1930 else // "ghost" ammo icon
1931 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
1936 if(!autocvar_hud_panel_ammo && !autocvar__hud_configure)
1939 active_panel = HUD_PANEL_AMMO;
1940 HUD_Panel_UpdateCvars(ammo);
1943 mySize = panel_size;
1945 HUD_Panel_DrawBg(1);
1946 if(panel_bg_padding)
1948 pos += '1 1 0' * panel_bg_padding;
1949 mySize -= '2 2 0' * panel_bg_padding;
1952 float rows, columns, row, column;
1954 if (autocvar_hud_panel_ammo_onlycurrent)
1958 rows = mySize_y/mySize_x;
1959 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
1960 // ^^^ ammo item aspect goes here
1962 columns = ceil(AMMO_COUNT/rows);
1964 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
1969 if(ammo_size_x/ammo_size_y > 3)
1971 newSize = 3 * ammo_size_y;
1972 offset_x = ammo_size_x - newSize;
1973 pos_x += offset_x/2;
1974 ammo_size_x = newSize;
1978 newSize = 1/3 * ammo_size_x;
1979 offset_y = ammo_size_y - newSize;
1980 pos_y += offset_y/2;
1981 ammo_size_y = newSize;
1984 drawfont = hud_bigfont;
1985 float i, stat_items, currently_selected;
1986 if (autocvar_hud_panel_ammo_onlycurrent)
1988 if(autocvar__hud_configure)
1990 DrawAmmoItem(pos, ammo_size, 2, true); //show rockets
1993 stat_items = getstati(STAT_ITEMS);
1994 for (i = 0; i < AMMO_COUNT; ++i) {
1995 currently_selected = stat_items & GetAmmoItemCode(i);
1996 if (currently_selected)
1998 DrawAmmoItem(pos, ammo_size, i, true);
2002 return; // nothing to display
2005 stat_items = getstati(STAT_ITEMS);
2006 for (i = 0; i < AMMO_COUNT; ++i) {
2007 currently_selected = stat_items & GetAmmoItemCode(i);
2008 DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected);
2013 column = column + 1;
2016 drawfont = hud_font;
2019 void DrawNumIcon(float iconalign, vector myPos, vector mySize, float x, string icon, float left, vector color, float alpha)
2022 float newSize_x, newSize_y;
2023 if(mySize_x/mySize_y > 3)
2025 newSize_x = 3 * mySize_y;
2026 newSize_y = mySize_y;
2028 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
2033 newSize_y = 1/3 * mySize_x;
2034 newSize_x = mySize_x;
2036 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
2040 vector picpos, numpos;
2043 if(iconalign == 1 || iconalign == 3) // right align
2046 picpos = newPos + eX * 2 * newSize_y;
2050 numpos = newPos + eX * newSize_y;
2056 if(iconalign == 0 || iconalign == 3) // left align
2058 numpos = newPos + eX * newSize_y;
2064 picpos = newPos + eX * 2 * newSize_y;
2068 drawfont = hud_bigfont;
2069 drawstring_aspect(numpos, ftos(x), eX * (2/3) * newSize_x + eY * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2070 drawfont = hud_font;
2071 drawpic_aspect_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
2074 void DrawNumIcon_expanding(float iconalign, vector myPos, vector mySize, float x, string icon, float left, vector color, float fadelerp)
2077 sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
2079 DrawNumIcon(iconalign, myPos + expandingbox_resize_centered_box_offset(sz, mySize, 1), mySize * sz, x, icon, left, color, (1 - fadelerp));
2084 void HUD_Powerups(void) {
2085 if(!autocvar_hud_panel_powerups && !autocvar__hud_configure)
2088 if(!autocvar__hud_configure)
2090 if not(getstati(STAT_ITEMS) & (IT_STRENGTH | IT_INVINCIBLE))
2093 if (getstati(STAT_HEALTH) <= 0)
2097 active_panel = HUD_PANEL_POWERUPS;
2098 HUD_Panel_UpdateCvars(powerups);
2101 mySize = panel_size;
2103 float strength_time, shield_time;
2104 if(autocvar__hud_configure)
2111 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
2112 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
2115 HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
2116 if(panel_bg_padding)
2118 pos += '1 1 0' * panel_bg_padding;
2119 mySize -= '2 2 0' * panel_bg_padding;
2122 vector barpos, barsize;
2126 string leftname, rightname;
2127 string leftprogressname, rightprogressname;
2128 float leftcnt, rightcnt;
2129 float leftexact, rightexact;
2130 float flip = cvar("hud_panel_powerups_flip");
2132 leftname = "strength";
2133 leftprogressname = cvar_string("hud_panel_powerups_progressbar_strength");
2134 leftcnt = ceil(strength_time);
2135 leftexact = strength_time;
2137 rightname = "shield";
2138 rightprogressname = cvar_string("hud_panel_powerups_progressbar_shield");
2139 rightcnt = ceil(shield_time);
2140 rightexact = shield_time;
2142 leftname = "shield";
2143 leftprogressname = cvar_string("hud_panel_powerups_progressbar_shield");
2144 leftcnt = ceil(shield_time);
2145 leftexact = shield_time;
2147 rightname = "strength";
2148 rightprogressname = cvar_string("hud_panel_powerups_progressbar_strength");
2149 rightcnt = ceil(strength_time);
2150 rightexact = strength_time;
2153 drawfont = hud_bigfont;
2154 float baralign = cvar("hud_panel_powerups_baralign");
2156 float iconalign = cvar("hud_panel_powerups_iconalign");
2157 float progressbar = cvar("hud_panel_powerups_progressbar");
2158 if (mySize_x/mySize_y > 4)
2160 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2163 if(baralign == 1 || baralign == 3) { // right align
2164 barpos = pos + eX * 0.5 * mySize_x;
2166 } else { // left align
2173 HUD_Panel_GetProgressBarColorForString(leftname);
2174 HUD_Panel_DrawProgressBar(barpos, barsize, leftprogressname, 0, barflip, min(1, leftcnt/30), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2176 if(cvar("hud_panel_powerups_text"))
2179 DrawNumIcon(iconalign, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, '1 1 1', 1);
2181 DrawNumIcon_expanding(iconalign, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2187 if(baralign == 0 || baralign == 3) { // left align
2190 } else { // right align
2191 barpos = pos + eX * 0.5 * mySize_x;
2197 HUD_Panel_GetProgressBarColorForString(rightname);
2198 HUD_Panel_DrawProgressBar(barpos, barsize, rightprogressname, 0, barflip, min(1, rightcnt/30), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2200 if(cvar("hud_panel_powerups_text"))
2203 DrawNumIcon(iconalign, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, '1 1 1', 1);
2205 DrawNumIcon_expanding(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));
2209 else if (mySize_x/mySize_y > 1.5)
2211 barsize = eX * mySize_x + eY * 0.5 * mySize_y;
2215 if(baralign == 1 || baralign == 3) { // right/down align
2217 } else { // left/up align
2223 HUD_Panel_GetProgressBarColorForString(leftname);
2224 HUD_Panel_DrawProgressBar(barpos, barsize, leftprogressname, 0, barflip, min(1, leftcnt/30), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2226 if(cvar("hud_panel_powerups_text"))
2229 DrawNumIcon(iconalign, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, '1 1 1', 1);
2231 DrawNumIcon_expanding(iconalign, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
2237 barpos = pos + eY * 0.5 * mySize_y;
2238 if(baralign == 0 || baralign == 3) { // left align
2240 } else { // right align
2246 HUD_Panel_GetProgressBarColorForString(rightname);
2247 HUD_Panel_DrawProgressBar(barpos, barsize, rightprogressname, 0, barflip, min(1, rightcnt/30), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2249 if(cvar("hud_panel_powerups_text"))
2252 DrawNumIcon(iconalign, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, '1 1 1', 1);
2254 DrawNumIcon_expanding(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));
2260 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2264 if(baralign == 1 || baralign == 3) { // down align
2266 } else { // up align
2270 if(iconalign == 1 || iconalign == 3) { // down align
2271 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x);
2272 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x;
2273 } else { // up align
2274 picpos = pos + eX * 0.05 * mySize_x;
2275 numpos = pos + eY * 0.4 * mySize_x;
2280 HUD_Panel_GetProgressBarColorForString(leftname);
2281 HUD_Panel_DrawProgressBar(barpos, barsize, leftprogressname, 1, barflip, min(1, leftcnt/30), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2283 if(cvar("hud_panel_powerups_text"))
2286 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));
2288 drawpic_aspect_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2289 drawstring_aspect(numpos, ftos(leftcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2295 barpos = pos + eX * 0.5 * mySize_x;
2296 if(baralign == 0 || baralign == 3) { // down align
2298 } else { // up align
2302 if(iconalign == 0 || iconalign == 3) { // up align
2303 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
2304 numpos = pos + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
2305 } else { // down align
2306 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x) + eX * 0.5 * mySize_x;
2307 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
2312 HUD_Panel_GetProgressBarColorForString(rightname);
2313 HUD_Panel_DrawProgressBar(barpos, barsize, rightprogressname, 1, barflip, min(1, rightcnt/30), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
2315 if(cvar("hud_panel_powerups_text"))
2318 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));
2320 drawpic_aspect_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2321 drawstring_aspect(numpos, ftos(rightcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2325 drawfont = hud_font;
2328 // Health/armor (#3)
2330 void HUD_HealthArmor(void)
2332 if(!autocvar_hud_panel_healtharmor && !autocvar__hud_configure)
2335 active_panel = HUD_PANEL_HEALTHARMOR;
2336 HUD_Panel_UpdateCvars(healtharmor);
2339 mySize = panel_size;
2341 HUD_Panel_DrawBg(1);
2342 if(panel_bg_padding)
2344 pos += '1 1 0' * panel_bg_padding;
2345 mySize -= '2 2 0' * panel_bg_padding;
2348 float armor, health, fuel;
2349 armor = getstati(STAT_ARMOR);
2350 health = getstati(STAT_HEALTH);
2351 fuel = getstati(STAT_FUEL);
2353 if(autocvar__hud_configure)
2363 vector barpos, barsize;
2367 drawfont = hud_bigfont;
2368 float baralign = cvar("hud_panel_healtharmor_baralign");
2369 float iconalign = cvar("hud_panel_healtharmor_iconalign");
2370 float progressbar = cvar("hud_panel_healtharmor_progressbar");
2372 float maxhealth = cvar("hud_panel_healtharmor_maxhealth");
2373 float maxarmor = cvar("hud_panel_healtharmor_maxarmor");
2374 if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
2377 v = healtharmor_maxdamage(health, armor, armorblockpercent);
2382 float maxtotal = maxhealth + maxarmor;
2388 if(v_z) // NOT fully armored
2390 biggercount = "health";
2393 HUD_Panel_GetProgressBarColor(health);
2394 HUD_Panel_DrawProgressBar(barpos, barsize, cvar_string("hud_panel_healtharmor_progressbar_health"), 0, mod(baralign, 2), x/maxtotal, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2397 if(cvar("hud_panel_healtharmor_text"))
2398 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);
2402 biggercount = "armor";
2405 HUD_Panel_GetProgressBarColor(armor);
2406 HUD_Panel_DrawProgressBar(barpos, barsize, cvar_string("hud_panel_healtharmor_progressbar_armor"), 0, mod(baralign, 2), x/maxtotal, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2409 if(cvar("hud_panel_healtharmor_text"))
2410 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);
2412 if(cvar("hud_panel_healtharmor_text"))
2413 DrawNumIcon(iconalign, pos, mySize, x, biggercount, 1, HUD_Get_Num_Color(x, maxtotal), 1);
2419 barsize = eX * mySize_x + eY * 0.2 * mySize_y;
2420 HUD_Panel_GetProgressBarColor(fuel);
2421 HUD_Panel_DrawProgressBar(barpos, barsize, "progressbar", 0, mod(baralign, 2), min(1, fuel/100), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2426 string leftname, rightname;
2427 string leftprogressname, rightprogressname;
2428 float leftcnt, rightcnt;
2429 float leftmax, rightmax;
2430 float leftactive, rightactive;
2431 float leftalpha, rightalpha;
2432 float flip = cvar("hud_panel_healtharmor_flip");
2434 if (flip) { // old style layout with armor left/top of health
2436 leftprogressname = cvar_string("hud_panel_healtharmor_progressbar_armor");
2440 leftalpha = min((armor+10)/55, 1);
2443 rightname = "health";
2444 rightprogressname = cvar_string("hud_panel_healtharmor_progressbar_health");
2448 rightmax = maxhealth;
2450 leftname = "health";
2451 leftprogressname = cvar_string("hud_panel_healtharmor_progressbar_health");
2455 leftmax = maxhealth;
2457 rightname = "armor";
2458 rightprogressname = cvar_string("hud_panel_healtharmor_progressbar_armor");
2462 rightalpha = min((armor+10)/55, 1);
2463 rightmax = maxarmor;
2466 if (mySize_x/mySize_y > 4)
2468 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2472 if(baralign == 1 || baralign == 3) { // right align
2474 } else { // left align
2480 HUD_Panel_GetProgressBarColorForString(leftname);
2481 HUD_Panel_DrawProgressBar(barpos, barsize, leftprogressname, 0, barflip, min(1, leftcnt/leftmax), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2483 if(cvar("hud_panel_healtharmor_text"))
2484 DrawNumIcon(iconalign, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, HUD_Get_Num_Color(leftcnt, leftmax), 1);
2489 barpos = pos + eX * 0.5 * mySize_x;
2490 if(baralign == 0 || baralign == 3) { // left align
2492 } else { // right align
2498 HUD_Panel_GetProgressBarColorForString(rightname);
2499 HUD_Panel_DrawProgressBar(barpos, barsize, rightprogressname, 0, barflip, min(1, rightcnt/rightmax), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2501 if(cvar("hud_panel_healtharmor_text"))
2502 DrawNumIcon(iconalign, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, HUD_Get_Num_Color(rightcnt, rightmax), 1);
2508 barsize = eX * mySize_x + eY * 0.2 * mySize_y;
2509 HUD_Panel_GetProgressBarColor(fuel);
2510 HUD_Panel_DrawProgressBar(barpos, barsize, "progressbar", 0, mod(baralign, 2), min(1, fuel/100), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2513 else if (mySize_x/mySize_y > 1.5)
2515 barsize = eX * mySize_x + eY * 0.5 * mySize_y;
2519 if(baralign == 1 || baralign == 3) { // right align
2521 } else { // left align
2527 HUD_Panel_GetProgressBarColorForString(leftname);
2528 HUD_Panel_DrawProgressBar(barpos, barsize, leftprogressname, 0, barflip, min(1, leftcnt/leftmax), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2530 if(cvar("hud_panel_healtharmor_text"))
2531 DrawNumIcon(iconalign, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, HUD_Get_Num_Color(leftcnt, leftmax), 1);
2536 barpos = pos + eY * 0.5 * mySize_y;
2537 if(baralign == 0 || baralign == 3) { // left align
2539 } else { // right align
2545 HUD_Panel_GetProgressBarColorForString(rightname);
2546 HUD_Panel_DrawProgressBar(barpos, barsize, rightprogressname, 0, barflip, min(1, rightcnt/rightmax), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2548 if(cvar("hud_panel_healtharmor_text"))
2549 DrawNumIcon(iconalign, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, HUD_Get_Num_Color(rightcnt, rightmax), 1);
2555 barsize = eX * mySize_x + eY * 0.2 * mySize_y;
2556 HUD_Panel_GetProgressBarColor(fuel);
2557 HUD_Panel_DrawProgressBar(barpos, barsize, "progressbar", 0, mod(baralign, 2), min(1, fuel/100), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2562 barsize = eX * 0.5 * mySize_x + eY * mySize_y;
2566 if(baralign == 1 || baralign == 3) { // right align
2568 } else { // left align
2572 if(iconalign == 1 || iconalign == 3) { // down align
2573 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x);
2574 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x;
2575 } else { // up align
2576 picpos = pos + eX * 0.05 * mySize_x;
2577 numpos = pos + eY * 0.4 * mySize_x;
2582 HUD_Panel_GetProgressBarColorForString(leftname);
2583 HUD_Panel_DrawProgressBar(barpos, barsize, leftprogressname, 1, barflip, min(1, leftcnt/leftmax), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2585 if(cvar("hud_panel_healtharmor_text"))
2587 drawpic_aspect_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2588 drawstring_aspect(numpos, ftos(leftcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, HUD_Get_Num_Color(leftcnt, leftmax), panel_fg_alpha, DRAWFLAG_NORMAL);
2594 barpos = pos + eX * 0.5 * mySize_x;
2595 if(baralign == 0 || baralign == 3) { // left align
2597 } else { // right align
2601 if(iconalign == 0 || iconalign == 3) { // up align
2602 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
2603 numpos = pos + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
2604 } else { // down align
2605 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x) + eX * 0.5 * mySize_x;
2606 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
2611 HUD_Panel_GetProgressBarColorForString(rightname);
2612 HUD_Panel_DrawProgressBar(barpos, barsize, rightprogressname, 1, barflip, min(1, rightcnt/rightmax), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2614 if(cvar("hud_panel_healtharmor_text"))
2616 drawpic_aspect_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2617 drawstring_aspect(numpos, ftos(rightcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, HUD_Get_Num_Color(rightcnt, rightmax), panel_fg_alpha, DRAWFLAG_NORMAL);
2624 barsize = eX * 0.05 * mySize_x + eY * mySize_y;
2625 HUD_Panel_GetProgressBarColor(fuel);
2626 HUD_Panel_DrawProgressBar(barpos, barsize, "progressbar", 1, mod(baralign, 2), min(1, fuel/100), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2630 drawfont = hud_font;
2633 // Notification area (#4)
2636 string Weapon_SuicideMessage(float deathtype)
2638 w_deathtype = deathtype;
2639 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2640 return w_deathtypestring;
2643 string Weapon_KillMessage(float deathtype)
2645 w_deathtype = deathtype;
2646 get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2647 return w_deathtypestring;
2650 #define KN_MAX_ENTRIES 10
2652 float killnotify_times[KN_MAX_ENTRIES];
2653 float killnotify_deathtype[KN_MAX_ENTRIES];
2654 float killnotify_actiontype[KN_MAX_ENTRIES]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2655 string killnotify_attackers[KN_MAX_ENTRIES];
2656 string killnotify_victims[KN_MAX_ENTRIES];
2657 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2661 kn_index = KN_MAX_ENTRIES-1;
2662 killnotify_times[kn_index] = time;
2663 killnotify_deathtype[kn_index] = wpn;
2664 killnotify_actiontype[kn_index] = actiontype;
2665 if(killnotify_attackers[kn_index])
2666 strunzone(killnotify_attackers[kn_index]);
2667 killnotify_attackers[kn_index] = strzone(attacker);
2668 if(killnotify_victims[kn_index])
2669 strunzone(killnotify_victims[kn_index]);
2670 killnotify_victims[kn_index] = strzone(victim);
2673 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
2676 float alsoprint, gentle;
2677 alsoprint = (cvar("hud_panel_notify_print") || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
2678 gentle = (cvar("cl_gentle") || cvar("cl_gentle_messages"));
2680 if ((msg == MSG_SUICIDE || msg == MSG_KILL || msg == MSG_KILL_ACTION) && gametype == GAME_CTS) // selfkill isn't interesting in CTS and only spams up the notify panel
2683 if(msg == MSG_SUICIDE) {
2684 w = DEATH_WEAPONOF(type);
2686 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2688 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
2689 } else if (type == DEATH_KILL) {
2690 HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2692 print ("^1",s1, "^1 couldn't take it anymore\n");
2693 } else if (type == DEATH_ROT) {
2694 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2696 print ("^1",s1, "^1 died\n");
2697 } else if (type == DEATH_NOAMMO) {
2698 HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2700 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2701 } else if (type == DEATH_CAMP) {
2702 HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2704 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2705 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2706 HUD_KillNotify_Push(s1, "", 0, type);
2708 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2709 } else if (type == DEATH_CHEAT) {
2710 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2712 print ("^1",s1, "^1 unfairly eliminated themself\n");
2713 } else if (type == DEATH_FIRE) {
2714 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2716 print ("^1",s1, "^1 burned to death\n");
2717 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2718 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2720 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2723 if (stof(s2) > 2) // killcount > 2
2724 print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2725 } else if(msg == MSG_KILL) {
2726 w = DEATH_WEAPONOF(type);
2728 if((w == WEP_CAMPINGRIFLE || w == WEP_MINSTANEX) && type & HITTYPE_HEADSHOT) // all headshot weapons go here
2729 HUD_KillNotify_Push(s1, s2, 1, DEATH_HEADSHOT);
2731 HUD_KillNotify_Push(s1, s2, 1, type);
2734 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
2736 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2737 HUD_KillNotify_Push(s1, s2, 1, type);
2741 print ("^1", s1, "^1 took action against a team mate\n");
2743 print ("^1", s1, "^1 mows down a team mate\n");
2746 if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2748 print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2750 print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2752 else if (stof(s2) > 2) {
2754 print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2756 print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2759 else if(type == KILL_FIRST_BLOOD)
2760 print("^1",s1, "^1 drew first blood", "\n");
2761 else if (type == DEATH_TELEFRAG) {
2762 HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
2764 print ("^1",s2, "^1 tried to occupy ", s1, "^1's teleport destination space\n");
2766 print ("^1",s2, "^1 was telefragged by ", s1, "\n");
2768 else if (type == DEATH_DROWN) {
2769 HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
2771 print ("^1",s2, "^1 was drowned by ", s1, "\n");
2773 else if (type == DEATH_SLIME) {
2774 HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
2776 print ("^1",s2, "^1 was slimed by ", s1, "\n");
2778 else if (type == DEATH_LAVA) {
2779 HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
2781 print ("^1",s2, "^1 was cooked by ", s1, "\n");
2783 else if (type == DEATH_FALL) {
2784 HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
2786 print ("^1",s2, "^1 was grounded by ", s1, "\n");
2788 else if (type == DEATH_SHOOTING_STAR) {
2789 HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
2791 print ("^1",s2, "^1 was shot into space by ", s1, "\n");
2793 else if (type == DEATH_SWAMP) {
2794 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2796 print ("^1",s2, "^1 was conserved by ", s1, "\n");
2798 else if (type == DEATH_HURTTRIGGER)
2800 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2802 print("^1",s2, "^1 was thrown into a world of hurt by ", s1, "\n");
2803 } else if(type == DEATH_SBCRUSH) {
2804 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2806 print ("^1",s2, "^1 was crushed by ^1", s1, "\n");
2807 } else if(type == DEATH_SBMINIGUN) {
2808 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2810 print ("^1",s2, "^1 got shredded by ^1", s1, "\n");
2811 } else if(type == DEATH_SBROCKET) {
2812 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2814 print ("^1",s2, "^1 was blased to bits by ^1", s1, "\n");
2815 } else if(type == DEATH_SBBLOWUP) {
2816 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2818 print ("^1",s2, "^1 got caught in the destruction of ^1", s1, "'s vehicle\n");
2819 } else if(type == DEATH_WAKIGUN) {
2820 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2822 print ("^1",s2, "^1 was bolted down by ^1", s1, "\n");
2823 } else if(type == DEATH_WAKIROCKET) {
2824 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2826 print ("^1",s2, "^1 could find no shelter from ^1", s1, "'s rockets\n");
2827 } else if(type == DEATH_WAKIBLOWUP) {
2828 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2830 print ("^1",s2, "^1 dies when ^1", s1, "'s wakizashi dies.\n");
2831 } else if(type == DEATH_TURRET) {
2832 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2834 print ("^1",s2, "^1 was pushed into the line of fire by ^1", s1, "\n");
2835 } else if(type == DEATH_TOUCHEXPLODE) {
2836 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2838 print ("^1",s2, "^1 was pushed into an accident by ^1", s1, "\n");
2839 } else if(type == DEATH_CHEAT) {
2840 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2842 print ("^1",s2, "^1 was unfairly eliminated by ^1", s1, "\n");
2843 } else if (type == DEATH_FIRE) {
2844 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2846 print ("^1",s2, "^1 was burnt to death by ^1", s1, "\n");
2847 } else if (type == DEATH_CUSTOM) {
2848 HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
2850 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2851 } else if (type == DEATH_HURTTRIGGER) {
2852 HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
2854 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
2856 HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
2858 print ("^1",s2, "^1 was fragged by ", s1, "\n");
2860 } else if(msg == MSG_SPREE) {
2861 if(type == KILL_END_SPREE) {
2863 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2865 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2866 } else if(type == KILL_SPREE) {
2868 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2870 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2871 } else if(type == KILL_SPREE_3) {
2873 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2875 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2876 } else if(type == KILL_SPREE_5) {
2878 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2880 print (s1,"^7 unleashes ^1RAGE\n");
2881 } else if(type == KILL_SPREE_10) {
2883 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2885 print (s1,"^7 starts the ^1MASSACRE!\n");
2886 } else if(type == KILL_SPREE_15) {
2888 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2890 print (s1,"^7 executes ^1MAYHEM!\n");
2891 } else if(type == KILL_SPREE_20) {
2893 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2895 print (s1,"^7 is a ^1BERSERKER!\n");
2896 } else if(type == KILL_SPREE_25) {
2898 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2900 print (s1,"^7 inflicts ^1CARNAGE!\n");
2901 } else if(type == KILL_SPREE_30) {
2903 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2905 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2907 } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2908 if (type == DEATH_DROWN) {
2909 HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2913 print ("^1",s1, "^1 was in the water for too long\n");
2915 print ("^1",s1, "^1 drowned\n");
2917 } else if (type == DEATH_SLIME) {
2918 HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2920 print ("^1",s1, "^1 was slimed\n");
2921 } else if (type == DEATH_LAVA) {
2922 HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2926 print ("^1",s1, "^1 found a hot place\n");
2928 print ("^1",s1, "^1 turned into hot slag\n");
2930 } else if (type == DEATH_FALL) {
2931 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2935 print ("^1",s1, "^1 tested gravity (and it worked)\n");
2937 print ("^1",s1, "^1 hit the ground with a crunch\n");
2939 } else if (type == DEATH_SHOOTING_STAR) {
2940 HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2942 print ("^1",s1, "^1 became a shooting star\n");
2943 } else if (type == DEATH_SWAMP) {
2944 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2948 print ("^1",s1, "^1 discovered a swamp\n");
2950 print ("^1",s1, "^1 is now conserved for centuries to come\n");
2952 } else if(type == DEATH_TURRET) {
2953 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2955 print ("^1",s1, "^1 was mowed down by a turret \n");
2956 } else if (type == DEATH_CUSTOM) {
2957 HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2959 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2960 } else if (type == DEATH_HURTTRIGGER) {
2961 HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2963 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
2964 } else if(type == DEATH_TOUCHEXPLODE) {
2965 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2967 print ("^1",s1, "^1 died in an accident\n");
2968 } else if(type == DEATH_CHEAT) {
2969 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2971 print ("^1",s1, "^1 was unfairly eliminated\n");
2972 } else if(type == DEATH_FIRE) {
2973 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2977 print ("^1",s1, "^1 felt a little hot\n");
2979 print ("^1",s1, "^1 burnt to death\n");
2982 HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2986 print ("^1",s1, "^1 needs a restart\n");
2988 print ("^1",s1, "^1 died\n");
2991 } else if(msg == MSG_KILL_ACTION_SPREE) {
2993 print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2995 print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2996 } else if(msg == MSG_INFO) {
2997 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2998 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2999 print(s1, "^7 got the ", s2, "\n");
3000 } else if(type == INFO_LOSTFLAG) {
3001 HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
3002 print(s1, "^7 lost the ", s2, "\n");
3003 } else if(type == INFO_PICKUPFLAG) {
3004 HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
3005 print(s1, "^7 picked up the ", s2, "\n");
3006 } else if(type == INFO_RETURNFLAG) {
3007 HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
3008 print(s1, "^7 returned the ", s2, "\n");
3009 } else if(type == INFO_CAPTUREFLAG) {
3010 HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
3011 print(s1, "^7 captured the ", s2, s3, "\n");
3013 } else if(msg == MSG_RACE) {
3014 if(type == RACE_SERVER_RECORD) {
3015 HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
3017 else if(type == RACE_NEW_RANK) {
3018 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
3020 else if(type == RACE_NEW_TIME) {
3021 HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
3023 else if(type == RACE_FAIL) {
3024 HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
3029 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
3031 void HUD_Centerprint(string s1, string s2, float type, float msg)
3034 gentle = (cvar("cl_gentle") || cvar("cl_gentle_messages"));
3035 if(msg == MSG_SUICIDE) {
3036 if (type == DEATH_TEAMCHANGE) {
3037 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
3038 } else if (type == DEATH_AUTOTEAMCHANGE) {
3039 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
3040 } else if (type == DEATH_CAMP) {
3042 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
3044 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
3045 } else if (type == DEATH_NOAMMO) {
3047 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
3049 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
3050 } else if (type == DEATH_ROT) {
3052 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
3054 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
3055 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
3057 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
3059 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
3060 } else if (type == DEATH_QUIET) {
3062 } else { // generic message
3064 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
3066 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
3068 } else if(msg == MSG_KILL) {
3069 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
3071 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
3073 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
3075 } else if (type == KILL_FIRST_BLOOD) {
3077 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
3079 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
3081 } else if (type == KILL_FIRST_VICTIM) {
3083 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
3085 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
3087 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
3089 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
3091 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
3093 } else if (type == KILL_TYPEFRAGGED) {
3095 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
3097 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
3099 } else if (type == KILL_FRAG) {
3101 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
3103 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
3105 } else { // generic message
3107 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
3109 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
3112 } else if(msg == MSG_KILL_ACTION) {
3113 // TODO: invent more centerprints here?
3114 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
3118 void HUD_Notify (void)
3120 if(!autocvar_hud_panel_notify && !autocvar__hud_configure)
3123 active_panel = HUD_PANEL_NOTIFY;
3124 HUD_Panel_UpdateCvars(notify);
3127 mySize = panel_size;
3129 HUD_Panel_DrawBg(1);
3130 if(panel_bg_padding)
3132 pos += '1 1 0' * panel_bg_padding;
3133 mySize -= '2 2 0' * panel_bg_padding;
3136 float entries, height;
3137 entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
3138 height = mySize_y/entries;
3141 fontsize = '0.5 0.5 0' * height;
3145 when = cvar("hud_panel_notify_time");
3147 fadetime = cvar("hud_panel_notify_fadetime");
3151 vector pos_attacker, pos_victim;
3153 float width_attacker;
3154 string attacker, victim;
3156 float i, j, w, step, limit;
3157 if(cvar("hud_panel_notify_flip")) //order items from the top down
3163 else //order items from the bottom up
3170 for(j = kn_index; i != limit; i += step, ++j)
3172 if(autocvar__hud_configure)
3176 else // inverse order
3177 a = entries - 1 - i;
3178 attacker = textShortenToWidth(strcat("Player", ftos(a+1)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3179 victim = textShortenToWidth(strcat("Player", ftos(a+2)), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
3180 s = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
3181 a = bound(0, (when - a) / 4, 1);
3182 goto hud_config_notifyprint;
3185 if (j == KN_MAX_ENTRIES)
3188 if(killnotify_times[j] + when > time)
3192 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
3206 w = DEATH_WEAPONOF(killnotify_deathtype[j]);
3208 // TODO: maybe print in team colors?
3211 if(killnotify_actiontype[j] == 0)
3213 if(killnotify_deathtype[j] == DEATH_GENERIC)
3217 else if(killnotify_deathtype[j] == DEATH_NOAMMO)
3219 s = "notify_outofammo";
3221 else if(killnotify_deathtype[j] == DEATH_KILL)
3223 s = "notify_selfkill";
3225 else if(killnotify_deathtype[j] == DEATH_CAMP)
3227 s = "notify_camping";
3229 else if(killnotify_deathtype[j] == KILL_TEAM_RED)