ammo status bar on the weaponicons panel, also commit some icons that i forgot
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
1 /*
2 ==================
3 Misc HUD functions
4 ==================
5 */
6
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
11 // divided into
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)
16 {
17         if (theBorderSize_x <= 0 && theBorderSize_y <= 0) // no border
18         {
19                 // draw only the central part
20                 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
21                 return;
22         }
23
24         vector dX, dY;
25         vector width, height;
26         vector bW, bH;
27         //pic = draw_UseSkinFor(pic);
28         width = eX * theSize_x;
29         height = eY * theSize_y;
30         if(theSize_x <= theBorderSize_x * 2)
31         {
32                 // not wide enough... draw just left and right then
33                 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
34                 if(theSize_y <= theBorderSize_y * 2)
35                 {
36                         // not high enough... draw just corners
37                         bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
38                         drawsubpic(theOrigin,                 width * 0.5 + height * 0.5, pic, '0 0 0',           bW + bH, theColor, theAlpha, 0);
39                         drawsubpic(theOrigin + width   * 0.5, width * 0.5 + height * 0.5, pic, eX - bW,           bW + bH, theColor, theAlpha, 0);
40                         drawsubpic(theOrigin + height  * 0.5, width * 0.5 + height * 0.5, pic, eY - bH,           bW + bH, theColor, theAlpha, 0);
41                         drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
42                 }
43                 else
44                 {
45                         dY = theBorderSize_x * eY;
46                         drawsubpic(theOrigin,                             width * 0.5          +     dY, pic, '0 0    0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
47                         drawsubpic(theOrigin + width * 0.5,               width * 0.5          +     dY, pic, '0 0    0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
48                         drawsubpic(theOrigin                        + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0',           '0 0.5  0' + bW, theColor, theAlpha, 0);
49                         drawsubpic(theOrigin + width * 0.5          + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0' + eX - bW, '0 0.5  0' + bW, theColor, theAlpha, 0);
50                         drawsubpic(theOrigin               + height - dY, width * 0.5          +     dY, pic, '0 0.75 0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
51                         drawsubpic(theOrigin + width * 0.5 + height - dY, width * 0.5          +     dY, pic, '0 0.75 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
52                 }
53         }
54         else
55         {
56                 if(theSize_y <= theBorderSize_y * 2)
57                 {
58                         // not high enough... draw just top and bottom then
59                         bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
60                         dX = theBorderSize_x * eX;
61                         drawsubpic(theOrigin,                                         dX + height * 0.5, pic, '0    0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
62                         drawsubpic(theOrigin + dX,                        width - 2 * dX + height * 0.5, pic, '0.25 0 0',           '0.5  0 0' + bH, theColor, theAlpha, 0);
63                         drawsubpic(theOrigin + width - dX,                            dX + height * 0.5, pic, '0.75 0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
64                         drawsubpic(theOrigin              + height * 0.5,             dX + height * 0.5, pic, '0    0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
65                         drawsubpic(theOrigin + dX         + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5  0 0' + bH, theColor, theAlpha, 0);
66                         drawsubpic(theOrigin + width - dX + height * 0.5,             dX + height * 0.5, pic, '0.75 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
67                 }
68                 else
69                 {
70                         dX = theBorderSize_x * eX;
71                         dY = theBorderSize_x * eY;
72                         drawsubpic(theOrigin,                                        dX          +     dY, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
73                         drawsubpic(theOrigin                  + dX,      width - 2 * dX          +     dY, pic, '0.25 0    0', '0.5  0.25 0', theColor, theAlpha, 0);
74                         drawsubpic(theOrigin          + width - dX,                  dX          +     dY, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
75                         drawsubpic(theOrigin          + dY,                          dX + height - 2 * dY, pic, '0    0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
76                         drawsubpic(theOrigin          + dY         + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5  0.5  0', theColor, theAlpha, 0);
77                         drawsubpic(theOrigin          + dY + width - dX,             dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
78                         drawsubpic(theOrigin + height - dY,                          dX          +     dY, pic, '0    0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
79                         drawsubpic(theOrigin + height - dY         + dX, width - 2 * dX          +     dY, pic, '0.25 0.75 0', '0.5  0.25 0', theColor, theAlpha, 0);
80                         drawsubpic(theOrigin + height - dY + width - dX,             dX          +     dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
81                 }
82         }
83 }
84
85 vector HUD_Get_Num_Color (float x, float maxvalue)
86 {
87         vector color;
88         if(x > maxvalue) {
89                 color_x = 0;
90                 color_y = 1;
91                 color_z = 0;
92         }
93         else if(x > maxvalue * 0.75) {
94                 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
95                 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
96                 color_z = 0;
97         }
98         else if(x > maxvalue * 0.5) {
99                 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
100                 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
101                 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
102         }
103         else if(x > maxvalue * 0.25) {
104                 color_x = 1;
105                 color_y = 1;
106                 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
107         }
108         else if(x > maxvalue * 0.1) {
109                 color_x = 1;
110                 color_y = (x-20)*90/27/100; // green value between 0 -> 1
111                 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
112         }
113         else {
114                 color_x = 1;
115                 color_y = 0;
116                 color_z = 0;
117         }
118         return color;
119 }
120
121 float stringwidth_colors(string s, vector theSize)
122 {
123         return stringwidth(s, TRUE, theSize);
124 }
125
126 float stringwidth_nocolors(string s, vector theSize)
127 {
128         return stringwidth(s, FALSE, theSize);
129 }
130
131 #define CENTERPRINT_MAX_LINES 30
132 string centerprint_messages[CENTERPRINT_MAX_LINES];
133 float centerprint_width[CENTERPRINT_MAX_LINES];
134 vector centerprint_start;
135 float centerprint_expire;
136 float centerprint_num;
137 float centerprint_offset_hint;
138 vector centerprint_fontsize;
139
140 void centerprint(string strMessage)
141 {
142         float i, j, n, hcount;
143         string s;
144
145         centerprint_fontsize = HUD_GetFontsize("scr_centersize");
146
147         centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
148
149         if(cvar("scr_centertime") <= 0)
150                 return;
151
152         if(strMessage == "")
153                 return;
154
155         // strip trailing newlines
156         j = strlen(strMessage) - 1;
157         while(substring(strMessage, j, 1) == "\n" && j >= 0)
158                 j = j - 1;
159         strMessage = substring(strMessage, 0, j + 1);
160
161         if(strMessage == "")
162                 return;
163
164         // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
165         j = 0;
166         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
167                 j = j + 1;
168         strMessage = substring(strMessage, j, strlen(strMessage) - j);
169         centerprint_offset_hint = j;
170
171         if(strMessage == "")
172                 return;
173
174         // if we get here, we have a message. Initialize its height.
175         centerprint_num = 0;
176
177         n = tokenizebyseparator(strMessage, "\n");
178         i = hcount = 0;
179         for(j = 0; j < n; ++j)
180         {
181                 getWrappedLine_remaining = argv(j);
182                 while(getWrappedLine_remaining)
183                 {
184                         s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
185                         if(centerprint_messages[i])
186                                 strunzone(centerprint_messages[i]);
187                         centerprint_messages[i] = strzone(s);
188                         centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
189                         ++i;
190
191                         // half height for empty lines looks better
192                         if(s == "")
193                                 hcount += 0.5;
194                         else
195                                 hcount += 1;
196
197                         if(i >= CENTERPRINT_MAX_LINES)
198                                 break;
199                 }
200         }
201
202         float h, havail;
203         h = centerprint_fontsize_y*hcount;
204
205         havail = vid_conheight;
206         if(cvar("con_chatpos") < 0)
207                 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
208         if(havail > vid_conheight - 70)
209                 havail = vid_conheight - 70; // avoid overlapping HUD
210
211         centerprint_start_x = 0;
212
213 #if 0
214         float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
215
216         // here, the centerprint would cover the crosshair. REALLY BAD.
217         forbiddenmin = vid_conheight * 0.5 - h - 16;
218         forbiddenmax = vid_conheight * 0.5 + 16;
219
220         allowedmin = scoreboard_bottom;
221         allowedmax = havail - h;
222         preferred = (havail - h)/2;
223
224
225         // possible orderings (total: 4! / 4 = 6)
226         //  allowedmin allowedmax forbiddenmin forbiddenmax
227         //  forbiddenmin forbiddenmax allowedmin allowedmax
228         if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
229         {
230                 // forbidden doesn't matter in this case
231                 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
232         }
233         //  allowedmin forbiddenmin allowedmax forbiddenmax
234         else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
235         {
236                 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
237         }
238         //  allowedmin forbiddenmin forbiddenmax allowedmax
239         else if(allowedmin < forbiddenmin)
240         {
241                 // make sure the forbidden zone is not covered
242                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
243                         centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
244                 else
245                         centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
246         }
247         //  forbiddenmin allowedmin allowedmax forbiddenmax
248         else if(allowedmax < forbiddenmax)
249         {
250                 // it's better to leave the allowed zone (overlap with scoreboard) than
251                 // to cover the forbidden zone (crosshair)
252                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
253                         centerprint_start_y = forbiddenmax;
254                 else
255                         centerprint_start_y = forbiddenmin;
256         }
257         //  forbiddenmin allowedmin forbiddenmax allowedmax
258         else
259         {
260                 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
261         }
262 #else
263         centerprint_start_y =
264                 min(
265                         max(
266                                 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
267                                 (havail - h)/2
268                         ),
269                         havail - h
270                 );
271 #endif
272
273         centerprint_num = i;
274         centerprint_expire = time + cvar("scr_centertime");
275 }
276
277 void HUD_DrawCenterPrint (void)
278 {
279         float i;
280         vector pos;
281         string ts;
282         float a;
283
284         //if(time > centerprint_expire)
285         //      return;
286
287         //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
288         a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
289         //sz = 1.2 / (a + 0.2);
290
291         if(a <= 0)
292                 return;
293
294         pos = centerprint_start;
295         for (i=0; i<centerprint_num; i = i + 1)
296         {
297                 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
298                 ts = centerprint_messages[i];
299                 if (ts != "")
300                 {
301                         drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
302                         //  - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
303                         pos_y = pos_y + centerprint_fontsize_y;
304                 }
305                 else
306                         // half height for empty lines looks better
307                         pos_y = pos_y + centerprint_fontsize_y * 0.5;
308         }
309 }
310
311 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
312 {
313         position_x -= 2 / 3 * strlen(text) * scale_x;
314         drawstring(position, text, scale, rgb, alpha, flag);
315 }
316
317 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
318 {
319         position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
320         drawstring(position, text, scale, rgb, alpha, flag);
321 }
322
323 // return the string of the given race place
324 string race_PlaceName(float pos) {
325         if(pos == 1)
326                 return "1st";
327         else if(pos == 2)
328                 return "2nd";
329         else if(pos == 3)
330                 return "3rd";
331         else
332                 return strcat(ftos(pos), "th");
333 }
334
335 // return the string of the onscreen race timer
336 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
337 {
338         string col;
339         string timestr;
340         string cpname;
341         string lapstr;
342         lapstr = "";
343
344         if(histime == 0) // goal hit
345         {
346                 if(mytime > 0)
347                 {
348                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
349                         col = "^1";
350                 }
351                 else if(mytime == 0)
352                 {
353                         timestr = "+0.0";
354                         col = "^3";
355                 }
356                 else
357                 {
358                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
359                         col = "^2";
360                 }
361
362                 if(lapdelta > 0)
363                 {
364                         lapstr = strcat(" (-", ftos(lapdelta), "L)");
365                         col = "^2";
366                 }
367                 else if(lapdelta < 0)
368                 {
369                         lapstr = strcat(" (+", ftos(-lapdelta), "L)");
370                         col = "^1";
371                 }
372         }
373         else if(histime > 0) // anticipation
374         {
375                 if(mytime >= histime)
376                         timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
377                 else
378                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
379                 col = "^3";
380         }
381         else
382                 col = "^7";
383
384         if(cp == 254)
385                 cpname = "Start line";
386         else if(cp == 255)
387                 cpname = "Finish line";
388         else if(cp)
389                 cpname = strcat("Intermediate ", ftos(cp));
390         else
391                 cpname = "Finish line";
392
393         if(histime < 0)
394                 return strcat(col, cpname);
395         else if(hisname == "")
396                 return strcat(col, cpname, " (", timestr, ")");
397         else
398                 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
399 }
400
401 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
402 float race_CheckName(string net_name) {
403         float i;
404         for (i=RANKINGS_CNT-1;i>=0;--i)
405                 if(grecordholder[i] == net_name)
406                         return i+1;
407         return 0;
408 }
409
410 /*
411 ==================
412 HUD panels
413 ==================
414 */
415
416 // Save the config
417 void HUD_Panel_ExportCfg(string cfgname)
418 {
419         float fh;
420         fh = fopen(strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg"), FILE_WRITE);
421         if(fh >= 0)
422         {
423                 fputs(fh, strcat("seta hud_skin \"", cvar_string("hud_skin"), "\"", "\n"));
424                 fputs(fh, strcat("seta hud_bg \"", cvar_string("hud_bg"), "\"", "\n"));
425                 fputs(fh, strcat("seta hud_bg_color \"", cvar_string("hud_bg_color"), "\"", "\n"));
426                 fputs(fh, strcat("seta hud_bg_color_team \"", cvar_string("hud_bg_color_team"), "\"", "\n"));
427                 fputs(fh, strcat("seta hud_bg_alpha \"", cvar_string("hud_bg_alpha"), "\"", "\n"));
428                 fputs(fh, strcat("seta hud_bg_border \"", cvar_string("hud_bg_border"), "\"", "\n"));
429                 fputs(fh, strcat("seta hud_bg_padding \"", cvar_string("hud_bg_padding"), "\"", "\n"));
430                 fputs(fh, strcat("seta hud_fg_alpha \"", cvar_string("hud_fg_alpha"), "\"", "\n"));
431                 fputs(fh, "\n");
432
433                 fputs(fh, strcat("seta hud_dock \"", cvar_string("hud_dock"), "\"", "\n"));
434                 fputs(fh, strcat("seta hud_dock_color \"", cvar_string("hud_dock_color"), "\"", "\n"));
435                 fputs(fh, strcat("seta hud_dock_color_team \"", cvar_string("hud_dock_color_team"), "\"", "\n"));
436                 fputs(fh, strcat("seta hud_dock_alpha \"", cvar_string("hud_dock_alpha"), "\"", "\n"));
437                 fputs(fh, "\n");
438
439                 fputs(fh, strcat("seta hud_progressbar_alpha \"", cvar_string("hud_progressbar_alpha"), "\"", "\n"));
440                 fputs(fh, strcat("seta hud_progressbar_strength_color \"", cvar_string("hud_progressbar_strength_color"), "\"", "\n"));
441                 fputs(fh, strcat("seta hud_progressbar_shield_color \"", cvar_string("hud_progressbar_shield_color"), "\"", "\n"));
442                 fputs(fh, strcat("seta hud_progressbar_health_color \"", cvar_string("hud_progressbar_health_color"), "\"", "\n"));
443                 fputs(fh, strcat("seta hud_progressbar_armor_color \"", cvar_string("hud_progressbar_armor_color"), "\"", "\n"));
444                 fputs(fh, strcat("seta hud_progressbar_fuel_color \"", cvar_string("hud_progressbar_fuel_color"), "\"", "\n"));
445                 fputs(fh, strcat("seta hud_progressbar_nexball_color \"", cvar_string("hud_progressbar_nexball_color"), "\"", "\n"));
446                 fputs(fh, "\n");
447
448                 fputs(fh, strcat("seta _hud_panelorder \"", cvar_string("_hud_panelorder"), "\"", "\n"));
449                 fputs(fh, "\n");
450
451                 // common cvars for all panels
452                 float i;
453                 for (i = 0; i < HUD_PANEL_NUM; ++i)
454                 {
455                         HUD_Panel_GetName(i)
456
457                         fputs(fh, strcat("seta hud_", panel_name, " ", cvar_string(strcat("hud_", panel_name)), "\n"));
458                         fputs(fh, strcat("seta hud_", panel_name, "_pos \"", cvar_string(strcat("hud_", panel_name, "_pos")), "\"", "\n"));
459                         fputs(fh, strcat("seta hud_", panel_name, "_size \"", cvar_string(strcat("hud_", panel_name, "_size")), "\"", "\n"));
460                         fputs(fh, strcat("seta hud_", panel_name, "_bg \"", cvar_string(strcat("hud_", panel_name, "_bg")), "\"", "\n"));
461                         fputs(fh, strcat("seta hud_", panel_name, "_bg_color \"", cvar_string(strcat("hud_", panel_name, "_bg_color")), "\"", "\n"));
462                         fputs(fh, strcat("seta hud_", panel_name, "_bg_color_team \"", cvar_string(strcat("hud_", panel_name, "_bg_color_team")), "\"", "\n"));
463                         fputs(fh, strcat("seta hud_", panel_name, "_bg_alpha \"", cvar_string(strcat("hud_", panel_name, "_bg_alpha")), "\"", "\n"));
464                         fputs(fh, strcat("seta hud_", panel_name, "_bg_border \"", cvar_string(strcat("hud_", panel_name, "_bg_border")), "\"", "\n"));
465                         fputs(fh, strcat("seta hud_", panel_name, "_bg_padding \"", cvar_string(strcat("hud_", panel_name, "_bg_padding")), "\"", "\n"));
466                         switch(i) {
467                                 case HUD_PANEL_WEAPONICONS:
468                                         fputs(fh, strcat("seta hud_", panel_name, "_complainbubble \"", cvar_string(strcat("hud_", panel_name, "_complainbubble")), "\"", "\n"));
469                                         fputs(fh, strcat("seta hud_", panel_name, "_complainbubble_padding \"", cvar_string(strcat("hud_", panel_name, "_complainbubble_padding")), "\"", "\n"));
470                                         fputs(fh, strcat("seta hud_", panel_name, "_ammo_color \"", cvar_string(strcat("hud_", panel_name, "_ammo_color")), "\"", "\n"));
471                                         fputs(fh, strcat("seta hud_", panel_name, "_ammo_alpha \"", cvar_string(strcat("hud_", panel_name, "_ammo_alpha")), "\"", "\n"));
472                                         break;
473                                 case HUD_PANEL_INVENTORY:
474                                         fputs(fh, strcat("seta hud_", panel_name, "_onlycurrent \"", cvar_string(strcat("hud_", panel_name, "_onlycurrent")), "\"", "\n"));
475                                         fputs(fh, strcat("seta hud_", panel_name, "_iconalign \"", cvar_string(strcat("hud_", panel_name, "_iconalign")), "\"", "\n"));
476                                         break;
477                                 case HUD_PANEL_POWERUPS:
478                                         fputs(fh, strcat("seta hud_", panel_name, "_flip \"", cvar_string(strcat("hud_", panel_name, "_flip")), "\"", "\n"));
479                                         fputs(fh, strcat("seta hud_", panel_name, "_iconalign \"", cvar_string(strcat("hud_", panel_name, "_iconalign")), "\"", "\n"));
480                                         fputs(fh, strcat("seta hud_", panel_name, "_baralign \"", cvar_string(strcat("hud_", panel_name, "_baralign")), "\"", "\n"));
481                                         break;
482                                 case HUD_PANEL_HEALTHARMOR:
483                                         fputs(fh, strcat("seta hud_", panel_name, "_flip \"", cvar_string(strcat("hud_", panel_name, "_flip")), "\n"));
484                                         fputs(fh, strcat("seta hud_", panel_name, "_iconalign \"", cvar_string(strcat("hud_", panel_name, "_iconalign")), "\"", "\n"));
485                                         fputs(fh, strcat("seta hud_", panel_name, "_baralign \"", cvar_string(strcat("hud_", panel_name, "_baralign")), "\"", "\n"));
486                                         break;
487                                 case HUD_PANEL_NOTIFY:
488                                         fputs(fh, strcat("seta hud_", panel_name, "_flip \"", cvar_string(strcat("hud_", panel_name, "_flip")), "\"", "\n"));
489                                         fputs(fh, strcat("seta hud_", panel_name, "_print \"", cvar_string(strcat("hud_", panel_name, "_print")), "\"", "\n"));
490                                         break;
491                                 case HUD_PANEL_RADAR:
492                                         fputs(fh, strcat("seta hud_", panel_name, "_foreground_alpha \"", cvar_string(strcat("hud_", panel_name, "_foreground_alpha")), "\"", "\n"));
493                                         break;
494                                 case HUD_PANEL_VOTE:
495                                         fputs(fh, strcat("seta hud_", panel_name, "_alreadyvoted_alpha \"", cvar_string(strcat("hud_", panel_name, "_alreadyvoted_alpha")), "\"", "\n"));
496                                         break;
497                         }
498                         fputs(fh, "\n");
499                 }
500
501                 print("^2Successfully exported to hud_", autocvar_hud_skin, "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
502         }
503         fclose(fh);
504 }
505
506 const float hlBorderSize = 4;
507 const string hlBorder = "gfx/hud/default/border_highlighted";
508 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
509 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
510 {
511         drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
512         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);
513         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);
514         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);
515         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);
516 }
517
518 // draw the background/borders
519 #define HUD_Panel_DrawBg(alpha)\
520 if(panel_bg != "0")\
521         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));\
522 if(highlightedPanel_prev == active_panel && autocvar__hud_configure)\
523         HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha) * alpha);
524
525 void HUD_Panel_DrawProgressBar(vector pos, float vertical, vector mySize, vector color, float alpha, float drawflag)
526 {
527         if(!alpha)
528                 return;
529
530         string pic;
531         if(vertical) {
532                 pic = strcat(hud_skin_path, "/statusbar_vertical");
533                 if(precache_pic(pic) == "") {
534                         pic = "gfx/hud/default/statusbar_vertical";
535                 }
536                 drawsubpic(pos, eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, pic, '0 0 0', '1 0.25 0', color, alpha, drawflag);
537                 if(mySize_y/mySize_x > 2)
538                         drawsubpic(pos + eY * mySize_x, eY * (mySize_y - 2 * mySize_x) + eX * mySize_x, pic, '0 0.25 0', '1 0.5 0', color, alpha, drawflag);
539                 drawsubpic(pos + eY * mySize_y - eY * min(mySize_y * 0.5, mySize_x), eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, pic, '0 0.75 0', '1 0.25 0', color, alpha, drawflag);
540         } else {
541                 pic = strcat(hud_skin_path, "/statusbar");
542                 if(precache_pic(pic) == "") {
543                         pic = "gfx/hud/default/statusbar";
544                 }
545                 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
546                 if(mySize_x/mySize_y > 2)
547                         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);
548                 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);
549         }
550 }
551
552 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
553 {
554         if(!alpha)
555                 return;
556
557         string pic;
558         pic = strcat(hud_skin_path, "/num_leading");
559         if(precache_pic(pic) == "") {
560                 pic = "gfx/hud/default/num_leading";
561         }
562
563         drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
564         if(mySize_x/mySize_y > 2)
565                 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);
566         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);
567 }
568
569 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
570 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
571 {
572         float i;
573
574         vector myTarget;
575         myTarget = myPos;
576
577         vector targPos;
578         vector targSize;
579         vector myCenter;
580         vector targCenter;
581         myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
582         targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
583
584         for (i = 0; i < HUD_PANEL_NUM; ++i) {
585                 if(i == highlightedPanel || !panel_enabled)
586                         continue;
587
588                 HUD_Panel_UpdatePosSizeForId(i)
589
590                 panel_pos -= '1 1 0' * panel_bg_border;
591                 panel_size += '2 2 0' * panel_bg_border;
592
593                 if(myPos_y + mySize_y < panel_pos_y)
594                         continue;
595                 if(myPos_y > panel_pos_y + panel_size_y)
596                         continue;
597
598                 if(myPos_x + mySize_x < panel_pos_x)
599                         continue;
600                 if(myPos_x > panel_pos_x + panel_size_x)
601                         continue;
602
603                 // OK, there IS a collision.
604
605                 myCenter_x = myPos_x + 0.5 * mySize_x;
606                 myCenter_y = myPos_y + 0.5 * mySize_y;
607
608                 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
609                 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
610
611                 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
612                 {
613                         if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
614                                 myTarget_x = panel_pos_x - mySize_x;
615                         else // push it upwards
616                                 myTarget_y = panel_pos_y - mySize_y;
617                 }
618                 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
619                 {
620                         if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
621                                 myTarget_x = panel_pos_x + panel_size_x;
622                         else // push it upwards
623                                 myTarget_y = panel_pos_y - mySize_y;
624                 }
625                 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
626                 {
627                         if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
628                                 myTarget_x = panel_pos_x - mySize_x;
629                         else // push it downwards
630                                 myTarget_y = panel_pos_y + panel_size_y;
631                 }
632                 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
633                 {
634                         if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
635                                 myTarget_x = panel_pos_x + panel_size_x;
636                         else // push it downwards
637                                 myTarget_y = panel_pos_y + panel_size_y;
638                 }
639                 if(cvar("hud_configure_checkcollisions_debug"))
640                         drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
641         }
642
643         return myTarget;
644 }
645
646 void HUD_Panel_SetPos(vector pos)
647 {
648         HUD_Panel_UpdatePosSizeForId(highlightedPanel)
649         vector mySize;
650         mySize = panel_size;
651
652         if(cvar("hud_configure_checkcollisions_debug"))
653                 drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
654
655         if(autocvar_hud_configure_grid)
656         {
657                 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;
658                 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;
659         }
660
661         if(hud_configure_checkcollisions)
662                 pos = HUD_Panel_CheckMove(pos, mySize);
663
664         pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
665         pos_y = bound(0, pos_y, vid_conheight - mySize_y);
666
667         string s;
668         s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
669
670         HUD_Panel_GetName(highlightedPanel);
671         cvar_set(strcat("hud_", panel_name, "_pos"), s);
672 }
673
674 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
675 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
676         float i;
677
678         float targBorder;
679         vector targPos;
680         vector targSize;
681         vector targEndPos;
682
683         vector dist;
684         float ratio;
685         ratio = mySize_x/mySize_y;
686
687         for (i = 0; i < HUD_PANEL_NUM; ++i) {
688                 if(i == highlightedPanel || !panel_enabled)
689                         continue;
690
691                 HUD_Panel_UpdatePosSizeForId(i)
692
693                 panel_pos -= '1 1 0' * panel_bg_border;
694                 panel_size += '2 2 0' * panel_bg_border;
695
696                 targEndPos = panel_pos + panel_size;
697
698                 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
699                 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
700                         continue;
701
702                 if (resizeCorner == 1)
703                 {
704                         // check if this panel is on our way
705                         if (resizeorigin_x <= panel_pos_x)
706                                 continue;
707                         if (resizeorigin_y <= panel_pos_y)
708                                 continue;
709                         if (targEndPos_x <= resizeorigin_x - mySize_x)
710                                 continue;
711                         if (targEndPos_y <= resizeorigin_y - mySize_y)
712                                 continue;
713
714                         // there is a collision:
715                         // detect which side of the panel we are facing is actually limiting the resizing
716                         // (which side the resize direction finds for first) and reduce the size up to there
717                         //
718                         // dist is the distance between resizeorigin and the "analogous" point of the panel
719                         // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
720                         dist_x = resizeorigin_x - targEndPos_x;
721                         dist_y = resizeorigin_y - targEndPos_y;
722                         if (dist_y <= 0 || dist_x / dist_y > ratio)
723                                 mySize_x = min(mySize_x, dist_x);
724                         else
725                                 mySize_y = min(mySize_y, dist_y);
726                 }
727                 else if (resizeCorner == 2)
728                 {
729                         if (resizeorigin_x >= targEndPos_x)
730                                 continue;
731                         if (resizeorigin_y <= panel_pos_y)
732                                 continue;
733                         if (panel_pos_x >= resizeorigin_x + mySize_x)
734                                 continue;
735                         if (targEndPos_y <= resizeorigin_y - mySize_y)
736                                 continue;
737
738                         dist_x = panel_pos_x - resizeorigin_x;
739                         dist_y = resizeorigin_y - targEndPos_y;
740                         if (dist_y <= 0 || dist_x / dist_y > ratio)
741                                 mySize_x = min(mySize_x, dist_x);
742                         else
743                                 mySize_y = min(mySize_y, dist_y);
744                 }
745                 else if (resizeCorner == 3)
746                 {
747                         if (resizeorigin_x <= panel_pos_x)
748                                 continue;
749                         if (resizeorigin_y >= targEndPos_y)
750                                 continue;
751                         if (targEndPos_x <= resizeorigin_x - mySize_x)
752                                 continue;
753                         if (panel_pos_y >= resizeorigin_y + mySize_y)
754                                 continue;
755
756                         dist_x = resizeorigin_x - targEndPos_x;
757                         dist_y = panel_pos_y - resizeorigin_y;
758                         if (dist_y <= 0 || dist_x / dist_y > ratio)
759                                 mySize_x = min(mySize_x, dist_x);
760                         else
761                                 mySize_y = min(mySize_y, dist_y);
762                 }
763                 else if (resizeCorner == 4)
764                 {
765                         if (resizeorigin_x >= targEndPos_x)
766                                 continue;
767                         if (resizeorigin_y >= targEndPos_y)
768                                 continue;
769                         if (panel_pos_x >= resizeorigin_x + mySize_x)
770                                 continue;
771                         if (panel_pos_y >= resizeorigin_y + mySize_y)
772                                 continue;
773
774                         dist_x = panel_pos_x - resizeorigin_x;
775                         dist_y = panel_pos_y - resizeorigin_y;
776                         if (dist_y <= 0 || dist_x / dist_y > ratio)
777                                 mySize_x = min(mySize_x, dist_x);
778                         else
779                                 mySize_y = min(mySize_y, dist_y);
780                 }
781                 if(cvar("hud_configure_checkcollisions_debug"))
782                         drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
783         }
784
785         return mySize;
786 }
787
788 void HUD_Panel_SetPosSize(vector mySize)
789 {
790         HUD_Panel_UpdatePosSizeForId(highlightedPanel)
791         vector resizeorigin;
792         resizeorigin = panel_click_resizeorigin;
793         vector myPos;
794
795         // minimum panel size cap
796         mySize_x = max(0.025 * vid_conwidth, mySize_x);
797         mySize_y = max(0.025 * vid_conheight, mySize_y);
798
799         if(highlightedPanel == HUD_PANEL_CHAT) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small.
800         {
801                 mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
802                 mySize_y = max(2 * cvar("con_chatsize") + 2 * panel_bg_padding, mySize_y);
803         }
804
805         // collision testing|
806         // -----------------+
807
808         // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
809         if(resizeCorner == 1) {
810                 myPos_x = resizeorigin_x - mySize_x;
811                 myPos_y = resizeorigin_y - mySize_y;
812         } else if(resizeCorner == 2) {
813                 myPos_x = resizeorigin_x;
814                 myPos_y = resizeorigin_y - mySize_y;
815         } else if(resizeCorner == 3) {
816                 myPos_x = resizeorigin_x - mySize_x;
817                 myPos_y = resizeorigin_y;
818         } else { // resizeCorner == 4
819                 myPos_x = resizeorigin_x;
820                 myPos_y = resizeorigin_y;
821         }
822
823         // left/top screen edges
824         if(myPos_x < 0)
825                 mySize_x = mySize_x + myPos_x;
826         if(myPos_y < 0)
827                 mySize_y = mySize_y + myPos_y;
828
829         // bottom/right screen edges
830         if(myPos_x + mySize_x > vid_conwidth)
831                 mySize_x = vid_conwidth - myPos_x;
832         if(myPos_y + mySize_y > vid_conheight)
833                 mySize_y = vid_conheight - myPos_y;
834
835         if(cvar("hud_configure_checkcollisions_debug"))
836                 drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
837
838         // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
839         if(autocvar_hud_configure_grid)
840         {
841                 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;
842                 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;
843         }
844
845         if(hud_configure_checkcollisions)
846                 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
847
848         // 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)
849         mySize_x = max(0.025 * vid_conwidth, mySize_x);
850         mySize_y = max(0.025 * vid_conheight, mySize_y);
851
852         // do another pos check, as size might have changed by now
853         if(resizeCorner == 1) {
854                 myPos_x = resizeorigin_x - mySize_x;
855                 myPos_y = resizeorigin_y - mySize_y;
856         } else if(resizeCorner == 2) {
857                 myPos_x = resizeorigin_x;
858                 myPos_y = resizeorigin_y - mySize_y;
859         } else if(resizeCorner == 3) {
860                 myPos_x = resizeorigin_x - mySize_x;
861                 myPos_y = resizeorigin_y;
862         } else { // resizeCorner == 4
863                 myPos_x = resizeorigin_x;
864                 myPos_y = resizeorigin_y;
865         }
866
867         if(cvar("hud_configure_checkcollisions_debug"))
868                 drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
869
870         HUD_Panel_GetName(highlightedPanel);
871         string s;
872         s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
873         cvar_set(strcat("hud_", panel_name, "_size"), s);
874
875         s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
876         cvar_set(strcat("hud_", panel_name, "_pos"), s);
877 }
878
879 float mouseClicked;
880 float prevMouseClicked; // previous state
881 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
882 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
883
884 float menu_enabled;
885 float menu_enabled_time;
886 float pressed_key_time;
887 void HUD_Panel_Arrow_Action(float nPrimary)
888 {
889         if (highlightedPanel_prev == -1 || mouseClicked)
890                 return;
891
892         hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
893
894         float step;
895         if(autocvar_hud_configure_grid)
896         {
897                 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
898                 {
899                         if (hudShiftState & S_SHIFT)
900                                 step = bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
901                         else
902                                 step = 2 * bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
903                 }
904                 else
905                 {
906                         if (hudShiftState & S_SHIFT)
907                                 step = bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
908                         else
909                                 step = 2 * bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
910                 }
911         }
912         else
913         {
914                 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
915                         step = vid_conheight;
916                 else
917                         step = vid_conwidth;
918                 if (hudShiftState & S_SHIFT)
919                         step = (step / 256); // more precision
920                 else
921                         step = (step / 64) * (1 + 2 * (time - pressed_key_time));
922         }
923
924         highlightedPanel = highlightedPanel_prev;
925
926         HUD_Panel_UpdatePosSizeForId(highlightedPanel)
927
928         if (hudShiftState & S_ALT) // resize
929         {
930                 highlightedAction = 1;
931                 if(nPrimary == K_UPARROW)
932                         resizeCorner = 1;
933                 else if(nPrimary == K_RIGHTARROW)
934                         resizeCorner = 2;
935                 else if(nPrimary == K_LEFTARROW)
936                         resizeCorner = 3;
937                 else // if(nPrimary == K_DOWNARROW)
938                         resizeCorner = 4;
939
940                 // ctrl+arrow reduces the size, instead of increasing it
941                 // Note that ctrl disables collisions check too, but it's fine
942                 // since we don't collide with anything reducing the size
943                 if (hudShiftState & S_CTRL) {
944                         step = -step;
945                         resizeCorner = 5 - resizeCorner;
946                 }
947
948                 vector mySize;
949                 mySize = panel_size;
950                 panel_click_resizeorigin = panel_pos;
951                 if(resizeCorner == 1) {
952                         panel_click_resizeorigin += mySize;
953                         mySize_y += step;
954                 } else if(resizeCorner == 2) {
955                         panel_click_resizeorigin_y += mySize_y;
956                         mySize_x += step;
957                 } else if(resizeCorner == 3) {
958                         panel_click_resizeorigin_x += mySize_x;
959                         mySize_x += step;
960                 } else { // resizeCorner == 4
961                         mySize_y += step;
962                 }
963                 HUD_Panel_SetPosSize(mySize);
964         }
965         else // move
966         {
967                 highlightedAction = 2;
968                 vector pos;
969                 pos = panel_pos;
970                 if(nPrimary == K_UPARROW)
971                         pos_y -= step;
972                 else if(nPrimary == K_DOWNARROW)
973                         pos_y += step;
974                 else if(nPrimary == K_LEFTARROW)
975                         pos_x -= step;
976                 else // if(nPrimary == K_RIGHTARROW)
977                         pos_x += step;
978
979                 HUD_Panel_SetPos(pos);
980         }
981 }
982
983 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
984 {
985         if(!autocvar__hud_configure)
986                 return false;
987
988         // allow console bind to work
989         string con_keys;
990         float keys;
991         con_keys = findkeysforcommand("toggleconsole");
992         keys = tokenize(con_keys);
993
994         float hit_con_bind, i;
995         for (i = 0; i < keys; ++i)
996         {
997                 if(nPrimary == stof(argv(i)))
998                         hit_con_bind = 1;
999         }
1000
1001         if(bInputType == 0) {
1002                 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
1003                 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
1004                 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
1005         }
1006         else if(bInputType == 1) {
1007                 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
1008                 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
1009                 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
1010         }
1011
1012         if(nPrimary == K_MOUSE1)
1013         {
1014                 if(bInputType == 0) { // key pressed
1015                         mouseClicked = 1;
1016                         return true;
1017                 }
1018                 else if(bInputType == 1) {// key released
1019                         mouseClicked = 0;
1020                         return true;
1021                 }
1022         }
1023         else if(nPrimary == K_ESCAPE)
1024         {
1025                 if (bInputType == 1)
1026                         return true;
1027                 disable_menu_alphacheck = 1;
1028                 menu_enabled = 1;
1029                 menu_enabled_time = time;
1030                 localcmd("menu_showhudexit\n");
1031         }
1032         else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
1033         {
1034                 if (bInputType == 1)
1035                 {
1036                         pressed_key_time = 0;
1037                         return true;
1038                 }
1039                 else if (pressed_key_time == 0)
1040                         pressed_key_time = time;
1041
1042                 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
1043         }
1044         else if(hit_con_bind)
1045                 return false;
1046
1047         return true; // Suppress ALL other input
1048 }
1049
1050 float HUD_Panel_HighlightCheck()
1051 {
1052         float i, j, border;
1053         vector panelPos;
1054         vector panelSize;
1055
1056         while(j <= HUD_PANEL_NUM)
1057         {
1058                 i = panel_order[j];
1059                 j += 1;
1060
1061                 HUD_Panel_UpdatePosSizeForId(i)
1062
1063                 panelPos = panel_pos;
1064                 panelSize = panel_size;
1065                 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1066
1067                 // move
1068                 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1069                 {
1070                         return 1;
1071                 }
1072                 // resize from topleft border
1073                 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)
1074                 {
1075                         return 2;
1076                 }
1077                 // resize from topright border
1078                 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)
1079                 {
1080                         return 3;
1081                 }
1082                 // resize from bottomleft border
1083                 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)
1084                 {
1085                         return 3;
1086                 }
1087                 // resize from bottomright border
1088                 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)
1089                 {
1090                         return 2;
1091                 }
1092         }
1093         return 0;
1094 }
1095
1096 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
1097 void HUD_Panel_FirstInDrawQ(float id)
1098 {
1099         float i;
1100         var float place = -1;
1101         // find out where in the array our current id is, save into place
1102         for(i = 0; i < HUD_PANEL_NUM; ++i)
1103         {
1104                 if(panel_order[i] == id)
1105                 {
1106                         place = i;
1107                         break;
1108                 }
1109         }
1110         // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
1111         if(place == -1)
1112                 place = HUD_PANEL_NUM - 1;
1113
1114         // move all ids up by one step in the array until "place"
1115         for(i = place; i > 0; --i)
1116         {
1117                 panel_order[i] = panel_order[i-1];
1118         }
1119         // now save the new top id
1120         panel_order[0] = id;
1121         
1122         // let's save them into the cvar by some strcat trickery
1123         string s;
1124         for(i = 0; i < HUD_PANEL_NUM; ++i)
1125         {
1126                 s = strcat(s, ftos(panel_order[i]), " ");
1127         }
1128         cvar_set("_hud_panelorder", s);
1129         if(hud_panelorder_prev)
1130                 strunzone(hud_panelorder_prev);
1131         hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
1132 }
1133
1134 void HUD_Panel_Highlight()
1135 {
1136         float i, j, border;
1137         vector panelPos;
1138         vector panelSize;
1139
1140         while(j <= HUD_PANEL_NUM)
1141         {
1142                 i = panel_order[j];
1143                 j += 1;
1144
1145                 HUD_Panel_UpdatePosSizeForId(i)
1146
1147                 panelPos = panel_pos;
1148                 panelSize = panel_size;
1149                 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
1150
1151                 // move
1152                 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1153                 {
1154                         highlightedPanel = i;
1155                         HUD_Panel_FirstInDrawQ(i);
1156                         highlightedAction = 1;
1157                         panel_click_distance = mousepos - panelPos;
1158                         return;
1159                 }
1160                 // resize from topleft border
1161                 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1162                 {
1163                         highlightedPanel = i;
1164                         HUD_Panel_FirstInDrawQ(i);
1165                         highlightedAction = 2;
1166                         resizeCorner = 1;
1167                         panel_click_distance = mousepos - panelPos;
1168                         panel_click_resizeorigin = panelPos + panelSize;
1169                         return;
1170                 }
1171                 // resize from topright border
1172                 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1173                 {
1174                         highlightedPanel = i;
1175                         HUD_Panel_FirstInDrawQ(i);
1176                         highlightedAction = 2;
1177                         resizeCorner = 2;
1178                         panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
1179                         panel_click_distance_y = mousepos_y - panelPos_y;
1180                         panel_click_resizeorigin = panelPos + eY * panelSize_y;
1181                         return;
1182                 }
1183                 // resize from bottomleft border
1184                 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + panelSize_y + border)
1185                 {
1186                         highlightedPanel = i;
1187                         HUD_Panel_FirstInDrawQ(i);
1188                         highlightedAction = 2;
1189                         resizeCorner = 3;
1190                         panel_click_distance_x = mousepos_x - panelPos_x;
1191                         panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
1192                         panel_click_resizeorigin = panelPos + eX * panelSize_x;
1193                         return;
1194                 }
1195                 // resize from bottomright border
1196                 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + panelSize_y + border)
1197                 {
1198                         highlightedPanel = i;
1199                         HUD_Panel_FirstInDrawQ(i);
1200                         highlightedAction = 2;
1201                         resizeCorner = 4;
1202                         panel_click_distance = panelSize - mousepos + panelPos;
1203                         panel_click_resizeorigin = panelPos;
1204                         return;
1205                 }
1206                 else
1207                 {
1208                         highlightedPanel_prev = -1;
1209                 }
1210         }
1211 }
1212
1213 float highlightcheck;
1214 void HUD_Panel_Mouse()
1215 {
1216         // 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
1217         if (menu_enabled == 0) // menu dialog closed, enable normal alpha stuff again
1218                 disable_menu_alphacheck = 0;
1219         if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1220                 menu_enabled = 0;
1221
1222         /*
1223         print("Disable menu_alphacheck: ", ftos(disable_menu_alphacheck), "\n");
1224         print("Highlighted: ", ftos(highlightedPanel), "\n");
1225         print("Menu alpha: ", cvar_string("_menu_alpha"), "\n");
1226         */
1227
1228         if(mouseClicked == 0 && disable_menu_alphacheck != 2 && highlightedPanel >= 0) { // don't reset these variables in disable_menu_alphacheck mode 2!
1229                 highlightedPanel = -1;
1230                 highlightedAction = 0;
1231         }
1232         if(highlightedPanel != -1)
1233                 highlightedPanel_prev = highlightedPanel;
1234
1235         mousepos = mousepos + getmousepos();
1236
1237         mousepos_x = bound(0, mousepos_x, vid_conwidth);
1238         mousepos_y = bound(0, mousepos_y, vid_conheight);
1239
1240         if(mouseClicked)
1241         {
1242                 if(prevMouseClicked == 0)
1243                         HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1244
1245                 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1246
1247                 if(highlightedAction == 1)
1248                         HUD_Panel_SetPos(mousepos - panel_click_distance);
1249                 else if(highlightedAction == 2)
1250                 {
1251                         vector mySize;
1252                         if(resizeCorner == 1) {
1253                                 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1254                                 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1255                         } else if(resizeCorner == 2) {
1256                                 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1257                                 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1258                         } else if(resizeCorner == 3) {
1259                                 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1260                                 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1261                         } else { // resizeCorner == 4
1262                                 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1263                                 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1264                         }
1265                         HUD_Panel_SetPosSize(mySize);
1266                 }
1267
1268                 // doubleclick check
1269                 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1270                 {
1271                         mouseClicked = 0; // to prevent spam, I guess.
1272                         disable_menu_alphacheck = 2;
1273                         menu_enabled = 1;
1274                         menu_enabled_time = time;
1275                         HUD_Panel_GetName(highlightedPanel)
1276                         localcmd("menu_showhudoptions ", panel_name, "\n");
1277                         return;
1278                 }
1279                 if(prevMouseClicked == 0)
1280                 {
1281                         prevMouseClickedTime = time;
1282                         prevMouseClickedPos = mousepos;
1283                 }
1284         }
1285         else
1286         {
1287                 highlightcheck = HUD_Panel_HighlightCheck();
1288         }
1289         // draw cursor after performing move/resize to have the panel pos/size updated before highlightcheck
1290         string cursor;
1291         vector cursorsize;
1292         cursorsize = '32 32 0';
1293
1294         if(highlightcheck == 0)
1295                 drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1296         else if(highlightcheck == 1)
1297                 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_move.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1298         else if(highlightcheck == 2)
1299                 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_resize.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1300         else
1301                 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor_resize2.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1302
1303         prevMouseClicked = mouseClicked;
1304 }
1305
1306 // Weapon icons (#0)
1307 //
1308 float weaponspace[10];
1309 #define HUD_WeaponIcons_Clear()\
1310         float idx;\
1311         for(idx = 0; idx < 10; ++idx)\
1312                 weaponspace[idx] = 0;
1313
1314 entity weaponorder[WEP_MAXCOUNT];
1315 void weaponorder_swap(float i, float j, entity pass)
1316 {
1317         entity h;
1318         h = weaponorder[i];
1319         weaponorder[i] = weaponorder[j];
1320         weaponorder[j] = h;
1321 }
1322
1323 string weaponorder_cmp_str_save;
1324 string weaponorder_cmp_str;
1325 float weaponorder_cmp(float i, float j, entity pass)
1326 {
1327         float ai, aj;
1328         ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1329         aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1330         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)
1331 }
1332
1333 float GetAmmoStat(float i)
1334 {
1335         switch(i)
1336         {
1337                 case 0: return STAT_SHELLS;
1338                 case 1: return STAT_NAILS;
1339                 case 2: return STAT_ROCKETS;
1340                 case 3: return STAT_CELLS;
1341                 case 4: return STAT_FUEL;
1342                 default: return -1;
1343         }
1344 }
1345
1346 float GetAmmoTypeForWep(float i)
1347 {
1348         switch(i)
1349         {
1350                 case WEP_SHOTGUN: return 0;
1351                 case WEP_UZI: return 1;
1352                 case WEP_CAMPINGRIFLE: return 1;
1353                 case WEP_GRENADE_LAUNCHER: return 2;
1354                 case WEP_ELECTRO: return 3;
1355                 case WEP_CRYLINK: return 3;
1356                 case WEP_HLAC: return 3;
1357                 case WEP_MINSTANEX: return 3;
1358                 case WEP_NEX: return 3;
1359                 case WEP_HAGAR: return 2;
1360                 case WEP_ROCKET_LAUNCHER: return 2;
1361                 case WEP_SEEKER: return 2;
1362                 case WEP_FIREBALL: return 4;
1363                 case WEP_HOOK: return 3;
1364                 default: return -1;
1365         }
1366 }
1367
1368 void HUD_WeaponIcons(void)
1369 {
1370         if(!autocvar_hud_weaponicons && !autocvar__hud_configure)
1371                 return;
1372
1373         float id = HUD_PANEL_WEAPONICONS;
1374         HUD_Panel_UpdateCvarsForId(id);
1375         float alpha, stat_weapons; // "constants"
1376         vector pos, mySize;
1377         float i, weapid, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1378
1379         pos = panel_pos;
1380         mySize = panel_size;
1381
1382         stat_weapons = getstati(STAT_WEAPONS);
1383         weapon_cnt = 0;
1384         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1385         {
1386                 self = get_weaponinfo(i);
1387                 if(self.impulse >= 0)
1388                         ++weapon_cnt;
1389         }
1390
1391         // TODO make this configurable
1392         weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1393
1394         if(weaponorder_cmp_str != weaponorder_cmp_str_save)
1395         {
1396                 if(weaponorder_cmp_str_save)
1397                         strunzone(weaponorder_cmp_str_save);
1398                 weaponorder_cmp_str_save = strzone(weaponorder_cmp_str);
1399                 weapon_cnt = 0;
1400                 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1401                 {
1402                         self = get_weaponinfo(i);
1403                         if(self.impulse >= 0)
1404                         {
1405                                 weaponorder[weapon_cnt] = self;
1406                                 ++weapon_cnt;
1407                         }
1408                 }
1409                 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1410         }
1411
1412         HUD_Panel_DrawBg(1);
1413         if(panel_bg_padding)
1414         {
1415                 pos += '1 1 0' * panel_bg_padding;
1416                 mySize -= '2 2 0' * panel_bg_padding;
1417         }
1418
1419         // hits
1420         weapon_stats = getstati(STAT_DAMAGE_HITS);
1421         weapon_number = weapon_stats & 63;
1422         weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1423         // fired
1424         weapon_stats = getstati(STAT_DAMAGE_FIRED);
1425         weapon_number = weapon_stats & 63;
1426         weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1427
1428         if(cvar_or("hud_weaponicons_fade", 1))
1429         {
1430                 fade = 3.2 - 2 * (time - weapontime);
1431                 fade = bound(0.7, fade, 1);
1432         }
1433         else
1434                 fade = 1;
1435
1436         HUD_WeaponIcons_Clear();
1437
1438         float rows, columns;
1439         rows = mySize_y/mySize_x;
1440         rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1441         //                               ^^^ weapon icon aspect goes here
1442
1443         columns = ceil(WEP_COUNT/rows);
1444         float row, column;
1445
1446         float a, type, fullammo;
1447         float when;
1448         when = autocvar_hud_weaponicons_complainbubble_time;
1449         float fadetime;
1450         fadetime = autocvar_hud_weaponicons_complainbubble_fadetime;
1451
1452         vector color;
1453         vector wpnpos;
1454         vector wpnsize;
1455         for(i = 0; i < weapon_cnt; ++i)
1456         {
1457                 wpnpos = pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
1458                 wpnsize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
1459
1460                 self = weaponorder[i];
1461                 weapid = self.impulse;
1462
1463                 alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1464
1465                 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1466                 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1467
1468                 // draw background behind currently selected weapon
1469                 if(self.weapon == activeweapon)
1470                         drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL);
1471
1472                 // draw the weapon accuracy
1473                 if(autocvar_hud_weaponicons_accuracy && !(gametype == GAME_RACE || gametype == GAME_CTS))
1474                 {
1475                         if(weapon_damage)
1476                                 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1477
1478                         // yellow_accuracy = value at which accuracy becomes yellow
1479                         if(weapon_stats >= 100) {
1480                                 color_x = 0;
1481                                 color_y = 1;
1482                         }
1483                         else if(weapon_stats > autocvar_hud_weaponicons_accuracy_yellow) {
1484                                 color_x = 1 - (weapon_stats-autocvar_hud_weaponicons_accuracy_yellow)/(100-autocvar_hud_weaponicons_accuracy_yellow); // red value between 1 -> 0
1485                                 color_y = 1;
1486                         } else {
1487                                 color_x = 1;
1488                                 color_y = weapon_stats/autocvar_hud_weaponicons_accuracy_yellow; // green value between 0 -> 1
1489                         }
1490                         color_z = 0;
1491
1492                         if(weapon_damage)
1493                                 drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
1494                 }
1495
1496                 // draw the weapon icon
1497                 if((self.impulse >= 0) && (stat_weapons & self.weapons))
1498                 {
1499                         drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL);
1500
1501                         if(autocvar_hud_weaponicons_number == 1) // weapon number
1502                                 drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1503                         else if(autocvar_hud_weaponicons_number == 2) // bind
1504                                 drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1505
1506                         // draw ammo status bar
1507                         if(autocvar_hud_weaponicons_ammo && weapid != WEP_TUBA && weapid != WEP_LASER && weapid != WEP_PORTO)
1508                         {
1509                                 a = 0;
1510                                 type = GetAmmoTypeForWep(weapid);
1511                                 if(type != -1)
1512                                         a = getstati(GetAmmoStat(type)); // how much ammo do we have?
1513
1514                                 if(a > 0)
1515                                 {
1516                                         switch(type) {
1517                                                 case 0: fullammo = autocvar_hud_weaponicons_ammo_full_shells; break;
1518                                                 case 1: fullammo = autocvar_hud_weaponicons_ammo_full_nails; break;
1519                                                 case 2: fullammo = autocvar_hud_weaponicons_ammo_full_rockets; break;
1520                                                 case 3: fullammo = autocvar_hud_weaponicons_ammo_full_cells; break;
1521                                                 case 4: fullammo = autocvar_hud_weaponicons_ammo_full_fuel; break;
1522                                                 default: fullammo = 60;
1523                                         }
1524
1525                                         vector barsize;
1526                                         vector barpos;
1527                                         if(wpnsize_x/wpnsize_y > 2)
1528                                         {
1529                                                 barsize_x = 2 * wpnsize_y;
1530                                                 barsize_y = wpnsize_y;
1531
1532                                                 barpos_x = wpnpos_x + (wpnsize_x - barsize_x) / 2;
1533                                                 barpos_y = wpnpos_y;
1534                                         }
1535                                         else
1536                                         {
1537                                                 barsize_y = 1/2 * wpnsize_x;
1538                                                 barsize_x = wpnsize_x;
1539
1540                                                 barpos_y = wpnpos_y + (wpnsize_y - barsize_y) / 2;
1541                                                 barpos_x = wpnpos_x;
1542                                         }
1543
1544                                         drawsetcliparea(
1545                                                 barpos_x,
1546                                                 barpos_y,
1547                                                 barsize_x * bound(0, a/fullammo, 1),
1548                                                 barsize_y); // use 2x more full ammo for uzi
1549                                         drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, autocvar_hud_weaponicons_ammo_color, panel_fg_alpha * autocvar_hud_weaponicons_ammo_alpha, DRAWFLAG_NORMAL);
1550                                         drawresetcliparea();
1551                                 }
1552                         }
1553                 }
1554
1555                 // draw a "ghost weapon icon" if you don't have the weapon
1556                 else
1557                 {
1558                         drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
1559                 }
1560
1561                 // draw the complain message
1562                 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_weaponicons_complainbubble)
1563                 {
1564                         if(fadetime)
1565                         {
1566                                 if(complain_weapon_time + when > time)
1567                                         a = 1;
1568                                 else
1569                                         a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
1570                         }
1571                         else
1572                         {
1573                                 if(complain_weapon_time + when > time)
1574                                         a = 1;
1575                                 else
1576                                         a = 0;
1577                         }
1578
1579                         string s;
1580                         if(complain_weapon_type == 0) {
1581                                 s = "Out of ammo";
1582                                 color = '1 0 0';
1583                         }
1584                         else if(complain_weapon_type == 1) {
1585                                 s = "Don't have";
1586                                 color = '1 1 0';
1587                         }
1588                         else {
1589                                 s = "Unavailable";
1590                                 color = '1 1 1';
1591                         }
1592                         drawpic_aspect_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows) + '1 1 0' * autocvar_hud_weaponicons_complainbubble_padding, "weapon_complainbubble", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows) - '2 2 0' * autocvar_hud_weaponicons_complainbubble_padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
1593                         drawstring_aspect(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows) + '1 1 0' * autocvar_hud_weaponicons_complainbubble_padding, s, eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows) - '2 2 0' * autocvar_hud_weaponicons_complainbubble_padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
1594                 }
1595
1596                 ++row;
1597                 if(row >= rows)
1598                 {
1599                         row = 0;
1600                         ++column;
1601                 }
1602         }
1603
1604 }
1605
1606 // Inventory (#1)
1607 //
1608 // TODO: macro
1609 float GetAmmoItemCode(float i)
1610 {
1611         switch(i)
1612         {
1613                 case 0: return IT_SHELLS;
1614                 case 1: return IT_NAILS;
1615                 case 2: return IT_ROCKETS;
1616                 case 3: return IT_CELLS;
1617                 case 4: return IT_FUEL;
1618                 default: return -1;
1619         }
1620 }
1621
1622 string GetAmmoPicture(float i)
1623 {
1624         switch(i)
1625         {
1626                 case 0: return "ammo_shells";
1627                 case 1: return "ammo_bullets";
1628                 case 2: return "ammo_rockets";
1629                 case 3: return "ammo_cells";
1630                 case 4: return "ammo_fuel";
1631                 default: return "";
1632         }
1633 }
1634
1635 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
1636 {
1637         float a;
1638         a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
1639         if(autocvar__hud_configure)
1640                 a = 100;
1641
1642         vector color;
1643         if(a < 10)
1644                 color = '0.7 0 0';
1645         else
1646                 color = '1 1 1';
1647
1648         float alpha;
1649         if(currently_selected)
1650                 alpha = 1;
1651         else
1652                 alpha = 0.7;
1653
1654         vector newSize, newPos;
1655         if(mySize_x/mySize_y > 3)
1656         {
1657                 newSize_x = 3 * mySize_y;
1658                 newSize_y = mySize_y;
1659
1660                 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1661                 newPos_y = myPos_y;
1662         }
1663         else
1664         {
1665                 newSize_y = 1/3 * mySize_x;
1666                 newSize_x = mySize_x;
1667
1668                 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1669                 newPos_x = myPos_x;
1670         }
1671
1672         vector picpos, numpos;
1673         if(autocvar_hud_inventory_iconalign)
1674         {
1675                 numpos = newPos;
1676                 picpos = newPos + eX * 2 * newSize_y;
1677         }
1678         else
1679         {
1680                 numpos = newPos + eX * newSize_y;
1681                 picpos = newPos;
1682         }
1683
1684         if (currently_selected)
1685                 drawpic_aspect_skin(newPos, "ammo_current_bg", newSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1686
1687         drawfont = hud_bigfont;
1688         drawstring_aspect(numpos, ftos(a), eX * (2/3) * newSize_x + eY * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1689         drawfont = hud_font;
1690         drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1691 }
1692
1693 void HUD_Inventory(void)
1694 {
1695         if(!autocvar_hud_inventory && !autocvar__hud_configure)
1696                 return;
1697
1698         float id = HUD_PANEL_INVENTORY;
1699         HUD_Panel_UpdateCvarsForId(id);
1700         float i, currently_selected;
1701
1702         vector pos, mySize;
1703         pos = panel_pos;
1704         mySize = panel_size;
1705
1706         HUD_Panel_DrawBg(1);
1707         if(panel_bg_padding)
1708         {
1709                 pos += '1 1 0' * panel_bg_padding;
1710                 mySize -= '2 2 0' * panel_bg_padding;
1711         }
1712
1713         float rows, columns;
1714         rows = mySize_y/mySize_x;
1715         rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
1716         //                               ^^^ ammo item aspect goes here
1717
1718         columns = ceil(AMMO_COUNT/rows);
1719
1720         float row, column;
1721         // ammo
1722         for (i = 0; i < AMMO_COUNT; ++i) {
1723                 currently_selected = getstati(STAT_ITEMS) & GetAmmoItemCode(i);
1724                 if(autocvar_hud_inventory_onlycurrent) {
1725                         if(autocvar__hud_configure)
1726                                 i = 2;
1727                         if (currently_selected || autocvar__hud_configure)
1728                         {
1729                                 DrawAmmoItem(pos, mySize, i, currently_selected);
1730                                 break;
1731                         }
1732                 } else {
1733                         DrawAmmoItem(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), i, currently_selected);
1734                         ++row;
1735                         if(row >= rows)
1736                         {
1737                                 row = 0;
1738                                 column = column + 1;
1739                         }
1740                 }
1741         }
1742 }
1743
1744 void DrawNumIcon(float iconalign, vector myPos, vector mySize, float x, string icon, float left, vector color, float alpha)
1745 {
1746         vector newSize, newPos;
1747         if(mySize_x/mySize_y > 3)
1748         {
1749                 newSize_x = 3 * mySize_y;
1750                 newSize_y = mySize_y;
1751
1752                 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1753                 newPos_y = myPos_y;
1754         }
1755         else
1756         {
1757                 newSize_y = 1/3 * mySize_x;
1758                 newSize_x = mySize_x;
1759
1760                 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1761                 newPos_x = myPos_x;
1762         }
1763
1764         vector picpos, numpos;
1765         if(left)
1766         {
1767                 if(iconalign == 1 || iconalign == 3) // right align
1768                 {
1769                         numpos = newPos;
1770                         picpos = newPos + eX * 2 * newSize_y;
1771                 }
1772                 else // left align
1773                 {
1774                         numpos = newPos + eX * newSize_y;
1775                         picpos = newPos;
1776                 }
1777         }
1778         else
1779         {
1780                 if(iconalign == 0 || iconalign == 3) // left align
1781                 {
1782                         numpos = newPos + eX * newSize_y;
1783                         picpos = newPos;
1784                 } 
1785                 else // right align
1786                 {
1787                         numpos = newPos;
1788                         picpos = newPos + eX * 2 * newSize_y;
1789                 }
1790         }
1791
1792         drawfont = hud_bigfont;
1793         drawstring_aspect(numpos, ftos(x), eX * (2/3) * newSize_x + eY * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1794         drawfont = hud_font;
1795         drawpic_aspect_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1796 }
1797
1798 void DrawNumIcon_expanding(float iconalign, vector myPos, vector mySize, float x, string icon, float left, vector color, float fadelerp)
1799 {
1800         float sz;
1801         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
1802
1803         DrawNumIcon(iconalign, myPos + expandingbox_resize_centered_box_offset(sz, mySize, 1), mySize * sz, x, icon, left, color, (1 - fadelerp));
1804 }
1805
1806 // Powerups (#2)
1807 //
1808 void HUD_Powerups(void) {
1809         if(!autocvar_hud_powerups && !autocvar__hud_configure)
1810                 return;
1811
1812         float id = HUD_PANEL_POWERUPS;
1813         HUD_Panel_UpdateCvarsForId(id);
1814         float stat_items;
1815         stat_items = getstati(STAT_ITEMS);
1816
1817         if(!autocvar__hud_configure)
1818         {
1819                 if not(stat_items & IT_STRENGTH)
1820                         if not(stat_items & IT_INVINCIBLE)
1821                                 return;
1822
1823                 if (getstati(STAT_HEALTH) <= 0)
1824                         return;
1825         }
1826
1827         vector pos, mySize;
1828         pos = panel_pos;
1829         mySize = panel_size;
1830
1831         float strength_time, shield_time;
1832
1833         strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1834         shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1835
1836         HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
1837         if(panel_bg_padding)
1838         {
1839                 pos += '1 1 0' * panel_bg_padding;
1840                 mySize -= '2 2 0' * panel_bg_padding;
1841         }
1842
1843         if(autocvar__hud_configure)
1844         {
1845                 strength_time = 15;
1846                 shield_time = 27;
1847         }
1848
1849         vector barpos, barsize;
1850         vector picpos;
1851         vector numpos;
1852
1853         string leftname, rightname;
1854         float leftcnt, rightcnt;
1855         float leftexact, rightexact;
1856         if (autocvar_hud_powerups_flip) {
1857                 leftname = "strength";
1858                 leftcnt = ceil(strength_time);
1859                 leftexact = strength_time;
1860
1861                 rightname = "shield";
1862                 rightcnt = ceil(shield_time);
1863                 rightexact = shield_time;
1864         } else {
1865                 leftname = "shield";
1866                 leftcnt = ceil(shield_time);
1867                 leftexact = shield_time;
1868
1869                 rightname = "strength";
1870                 rightcnt = ceil(strength_time);
1871                 rightexact = strength_time;
1872         }
1873
1874         drawfont = hud_bigfont;
1875         if (mySize_x/mySize_y > 4)
1876         {
1877                 if(leftcnt)
1878                 {
1879                         if(autocvar_hud_powerups_baralign == 1 || autocvar_hud_powerups_baralign == 3) { // right align
1880                                 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/30);
1881                                 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1882                         } else { // left align
1883                                 barpos = pos;
1884                                 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1885                         }
1886
1887                         HUD_Panel_GetProgressBarColor(leftname)
1888                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
1889                         if(leftcnt > 1)
1890                                 DrawNumIcon(autocvar_hud_powerups_iconalign, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, '1 1 1', 1);
1891                         if(leftcnt <= 5)
1892                                 DrawNumIcon_expanding(autocvar_hud_powerups_iconalign, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
1893                 }
1894
1895                 if(rightcnt)
1896                 {
1897                         if(autocvar_hud_powerups_baralign == 0 || autocvar_hud_powerups_baralign == 3) { // left align
1898                                 barpos = pos + eX * 0.5 * mySize_x;
1899                                 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1900                         } else { // right align
1901                                 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30);
1902                                 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1903                         }
1904
1905                         HUD_Panel_GetProgressBarColor(rightname)
1906                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
1907                         if(rightcnt > 1)
1908                                 DrawNumIcon(autocvar_hud_powerups_iconalign, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, '1 1 1', 1);
1909                         if(rightcnt <= 5)
1910                                 DrawNumIcon_expanding(autocvar_hud_powerups_iconalign, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
1911                 }
1912         }
1913         else if (mySize_x/mySize_y > 1.5)
1914         {
1915                 if(leftcnt)
1916                 {
1917                         if(autocvar_hud_powerups_baralign == 1 || autocvar_hud_powerups_baralign == 3) { // right align
1918                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/30);
1919                                 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1920                         } else { // left align
1921                                 barpos = pos;
1922                                 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1923                         }
1924
1925                         HUD_Panel_GetProgressBarColor(leftname)
1926                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
1927                         if(leftcnt > 1)
1928                                 DrawNumIcon(autocvar_hud_powerups_iconalign, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, '1 1 1', 1);
1929                         if(leftcnt <= 5)
1930                                 DrawNumIcon_expanding(autocvar_hud_powerups_iconalign, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
1931                 }
1932
1933                 if(rightcnt)
1934                 {
1935                         if(autocvar_hud_powerups_baralign == 0 || autocvar_hud_powerups_baralign == 3) { // left align
1936                                 barpos = pos + eY * 0.5 * mySize_y;
1937                                 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1938                         } else { // right align
1939                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1940                                 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1941                         }
1942
1943                         HUD_Panel_GetProgressBarColor(rightname)
1944                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
1945                         if(rightcnt > 1)
1946                                 DrawNumIcon(autocvar_hud_powerups_iconalign, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, '1 1 1', 1);
1947                         if(rightcnt <= 5)
1948                                 DrawNumIcon_expanding(autocvar_hud_powerups_iconalign, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
1949                 }
1950         }
1951         else
1952         {
1953                 if(leftcnt)
1954                 {
1955                         if(autocvar_hud_powerups_baralign == 1 || autocvar_hud_powerups_baralign == 3) { // down align
1956                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30);
1957                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1958                         } else { // up align
1959                                 barpos = pos;
1960                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1961                         }
1962
1963                         if(autocvar_hud_powerups_iconalign == 1 || autocvar_hud_powerups_iconalign == 3) { // down align
1964                                 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x);
1965                                 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x;
1966                         } else { // up align
1967                                 picpos = pos + eX * 0.05 * mySize_x;
1968                                 numpos = pos + eY * 0.4 * mySize_x;
1969                         }
1970
1971                         HUD_Panel_GetProgressBarColor(leftname)
1972                         HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
1973                         if(leftcnt <= 5)
1974                                 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));
1975                         if(leftcnt > 1)
1976                                 drawpic_aspect_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1977                         drawstring_aspect(numpos, ftos(leftcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1978                 }
1979
1980                 if(rightcnt)
1981                 {
1982                         if(autocvar_hud_powerups_baralign == 0 || autocvar_hud_powerups_baralign == 3) { // up align
1983                                 barpos = pos + eX * 0.5 * mySize_x;
1984                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1985                         } else { // down align
1986                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30) + eX * 0.5 * mySize_x;
1987                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1988                         }
1989
1990                         if(autocvar_hud_powerups_iconalign == 0 || autocvar_hud_powerups_iconalign == 3) { // up align
1991                                 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1992                                 numpos = pos + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1993                         } else { // down align
1994                                 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x) + eX * 0.5 * mySize_x;
1995                                 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
1996                         }
1997
1998                         HUD_Panel_GetProgressBarColor(rightname)
1999                         HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1) * panel_fg_alpha, DRAWFLAG_NORMAL);
2000                         if(rightcnt <= 5)
2001                                 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));
2002                         if(rightcnt > 1)
2003                                 drawpic_aspect_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2004                         drawstring_aspect(numpos, ftos(rightcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2005                 }
2006         }
2007         drawfont = hud_font;
2008 }
2009
2010 // Health/armor (#3)
2011 //
2012 void HUD_HealthArmor(void)
2013 {
2014         if(!autocvar_hud_healtharmor && !autocvar__hud_configure)
2015                 return;
2016
2017         float id = HUD_PANEL_HEALTHARMOR;
2018         HUD_Panel_UpdateCvarsForId(id);
2019         vector pos, mySize;
2020         pos = panel_pos;
2021         mySize = panel_size;
2022
2023         HUD_Panel_DrawBg(1);
2024         if(panel_bg_padding)
2025         {
2026                 pos += '1 1 0' * panel_bg_padding;
2027                 mySize -= '2 2 0' * panel_bg_padding;
2028         }
2029
2030         float armor, health;
2031         armor = getstati(STAT_ARMOR);
2032         health = getstati(STAT_HEALTH);
2033
2034         float fuel;
2035         fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
2036
2037         if(autocvar__hud_configure)
2038         {
2039                 armor = 150;
2040                 health = 100;
2041                 fuel = 70;
2042         }
2043
2044         if(health <= 0)
2045                 return;
2046
2047         vector barpos, barsize;
2048         vector picpos;
2049         vector numpos;
2050
2051         drawfont = hud_bigfont;
2052         if(autocvar_hud_healtharmor == 2) // combined health and armor display
2053         {
2054                 vector v;
2055                 v = healtharmor_maxdamage(health, armor, armorblockpercent);
2056
2057                 float x;
2058                 x = floor(v_x + 1);
2059
2060                 if(autocvar_hud_healtharmor_baralign == 1 || autocvar_hud_healtharmor_baralign == 3) { // right align
2061                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, x/400);
2062                         barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
2063                 } else { // left align
2064                         barpos = pos;
2065                         barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
2066                 }
2067
2068                 string biggercount;
2069                 if(v_z) // NOT fully armored
2070                 {
2071                         biggercount = "health";
2072                         HUD_Panel_GetProgressBarColor("health")
2073                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2074                         if(armor)
2075                                 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);
2076                 }
2077                 else
2078                 {
2079                         biggercount = "armor";
2080                         HUD_Panel_GetProgressBarColor("armor")
2081                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2082                         if(health)
2083                                 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);
2084                 }
2085                 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos, mySize, x, biggercount, 1, HUD_Get_Num_Color(x, 2 * 200), 1);
2086
2087                 // fuel
2088                 if(fuel)
2089                 {
2090                         if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2091                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2092                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2093                         } else {
2094                                 barpos = pos;
2095                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2096                         }
2097                         HUD_Panel_GetProgressBarColor("fuel")
2098                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2099                 }
2100         }
2101         else
2102         {
2103                 string leftname, rightname;
2104                 float leftcnt, rightcnt;
2105                 float leftactive, rightactive;
2106                 float leftalpha, rightalpha;
2107                 if (autocvar_hud_healtharmor_flip) { // old style layout with armor left/top of health
2108                         leftname = "armor";
2109                         leftcnt = armor;
2110                         if(leftcnt)
2111                                 leftactive = 1;
2112                         leftalpha = min((armor+10)/55, 1);
2113
2114                         rightname = "health";
2115                         rightcnt = health;
2116                         rightactive = 1;
2117                         rightalpha = 1;
2118                 } else {
2119                         leftname = "health";
2120                         leftcnt = health;
2121                         leftactive = 1;
2122                         leftalpha = 1;
2123
2124                         rightname = "armor";
2125                         rightcnt = armor;
2126                         if(rightcnt)
2127                                 rightactive = 1;
2128                         rightalpha = min((armor+10)/55, 1);
2129                 }
2130
2131                 if (mySize_x/mySize_y > 4)
2132                 {
2133                         if(leftactive)
2134                         {
2135                                 if(autocvar_hud_healtharmor_baralign == 1 || autocvar_hud_healtharmor_baralign == 3) { // right align
2136                                         barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/200);
2137                                         barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
2138                                 } else { // left align
2139                                         barpos = pos;
2140                                         barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
2141                                 }
2142
2143                                 HUD_Panel_GetProgressBarColor(leftname)
2144                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2145                                 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos, eX * 0.5 * mySize_x + eY * mySize_y, leftcnt, leftname, 1, HUD_Get_Num_Color(leftcnt, 200), 1);
2146                         }
2147
2148                         if(rightactive)
2149                         {
2150                                 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2151                                         barpos = pos + eX * 0.5 * mySize_x;
2152                                         barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
2153                                 } else { // right align
2154                                         barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200);
2155                                         barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
2156                                 }
2157
2158                                 HUD_Panel_GetProgressBarColor(rightname)
2159                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2160                                 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, 0, HUD_Get_Num_Color(leftcnt, 200), 1);
2161                         }
2162
2163                         if(fuel)
2164                         {
2165                                 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2166                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2167                                         barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2168                                 } else {
2169                                         barpos = pos;
2170                                         barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2171                                 }
2172                                 HUD_Panel_GetProgressBarColor("fuel")
2173                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2174                         }
2175                 }
2176                 else if (mySize_x/mySize_y > 1.5)
2177                 {
2178                         if(leftactive)
2179                         {
2180                                 if(autocvar_hud_healtharmor_baralign == 1 || autocvar_hud_healtharmor_baralign == 3) { // right align
2181                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/200);
2182                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2183                                 } else { // left align
2184                                         barpos = pos;
2185                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2186                                 }
2187
2188                                 HUD_Panel_GetProgressBarColor(leftname)
2189                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2190                                 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos, eX * mySize_x + eY * 0.5 * mySize_y, leftcnt, leftname, 1, HUD_Get_Num_Color(leftcnt, 200), 1);
2191                         }
2192
2193                         if(rightactive)
2194                         {
2195                                 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2196                                         barpos = pos + eY * 0.5 * mySize_y;
2197                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2198                                 } else { // right align
2199                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2200                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2201                                 }
2202
2203                                 HUD_Panel_GetProgressBarColor(rightname)
2204                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2205                                 DrawNumIcon(autocvar_hud_healtharmor_iconalign, pos + eY * 0.5 * mySize_y, eX * mySize_x + eY * 0.5 * mySize_y, rightcnt, rightname, 0, HUD_Get_Num_Color(leftcnt, 200), 1);
2206                         }
2207
2208                         if(fuel)
2209                         {
2210                                 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2211                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2212                                         barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2213                                 } else {
2214                                         barpos = pos;
2215                                         barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2216                                 }
2217                                 HUD_Panel_GetProgressBarColor("fuel")
2218                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2219                         }
2220                 }
2221                 else
2222                 {
2223                         if(leftactive)
2224                         {
2225                                 if(autocvar_hud_healtharmor_baralign == 1 || autocvar_hud_healtharmor_baralign == 3) { // down align
2226                                         barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200);
2227                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2228                                 } else { // up align
2229                                         barpos = pos;
2230                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2231                                 }
2232
2233                                 if(autocvar_hud_healtharmor_iconalign == 1 || autocvar_hud_healtharmor_iconalign == 3) { // down align
2234                                         picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x);
2235                                         numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x;
2236                                 } else { // up align
2237                                         picpos = pos + eX * 0.05 * mySize_x;
2238                                         numpos = pos + eY * 0.4 * mySize_x;
2239                                 }
2240
2241                                 HUD_Panel_GetProgressBarColor(leftname)
2242                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2243                                 drawpic_aspect_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2244                                 drawstring_aspect(numpos, ftos(leftcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, HUD_Get_Num_Color(leftcnt, 200), panel_fg_alpha, DRAWFLAG_NORMAL);
2245                         }
2246
2247                         if(rightactive)
2248                         {
2249                                 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // up align
2250                                         barpos = pos + eX * 0.5 * mySize_x;
2251                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2252                                 } else { // down align
2253                                         barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200) + eX * 0.5 * mySize_x;
2254                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2255                                 }
2256
2257                                 if(autocvar_hud_healtharmor_iconalign == 0 || autocvar_hud_healtharmor_iconalign == 3) { // up align
2258                                         picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
2259                                         numpos = pos + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
2260                                 } else { // down align
2261                                         picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x) + eX * 0.5 * mySize_x;
2262                                         numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
2263                                 }
2264
2265                                 HUD_Panel_GetProgressBarColor(rightname)
2266                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2267                                 drawpic_aspect_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2268                                 drawstring_aspect(numpos, ftos(rightcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, HUD_Get_Num_Color(rightcnt, 200), panel_fg_alpha, DRAWFLAG_NORMAL);
2269                         }
2270
2271                         if(fuel)
2272                         {
2273                                 if(autocvar_hud_healtharmor_baralign == 0 || autocvar_hud_healtharmor_baralign == 3) { // left align
2274                                         barpos = pos;
2275                                         barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2276                                 } else {
2277                                         barpos = pos + eY * mySize_y - eY * mySize_y * min(1, fuel/100);
2278                                         barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2279                                 }
2280                                 HUD_Panel_GetProgressBarColor("fuel")
2281                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
2282                         }
2283                 }
2284         }
2285         drawfont = hud_font;
2286 }
2287
2288 // Notification area (#4)
2289 //
2290
2291 string Weapon_SuicideMessage(float deathtype)
2292 {
2293         w_deathtype = deathtype;
2294         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2295         return w_deathtypestring;
2296 }
2297
2298 string Weapon_KillMessage(float deathtype)
2299 {
2300         w_deathtype = deathtype;
2301         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2302         return w_deathtypestring;
2303 }
2304
2305 float killnotify_times[10];
2306 float killnotify_deathtype[10];
2307 float killnotify_actiontype[10]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2308 string killnotify_attackers[10];
2309 string killnotify_victims[10];
2310 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2311 {
2312         float i;
2313         for (i = 9; i > 0; --i) {
2314                 killnotify_times[i] = killnotify_times[i-1];
2315                 killnotify_deathtype[i] = killnotify_deathtype[i-1];
2316                 killnotify_actiontype[i] = killnotify_actiontype[i-1];
2317                 if(killnotify_attackers[i])
2318                         strunzone(killnotify_attackers[i]);
2319                 killnotify_attackers[i] = strzone(killnotify_attackers[i-1]);
2320                 if(killnotify_victims[i])
2321                         strunzone(killnotify_victims[i]);
2322                 killnotify_victims[i] = strzone(killnotify_victims[i-1]);
2323         }
2324         killnotify_times[0] = time;
2325         killnotify_deathtype[0] = wpn;
2326         killnotify_actiontype[0] = actiontype;
2327         if(killnotify_attackers[0])
2328                 strunzone(killnotify_attackers[0]);
2329         killnotify_attackers[0] = strzone(attacker);
2330         if(killnotify_victims[0])
2331                 strunzone(killnotify_victims[0]);
2332         killnotify_victims[0] = strzone(victim);
2333 }
2334
2335 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
2336 {
2337         float w;
2338         float alsoprint, gentle;
2339         alsoprint = (autocvar_hud_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
2340         gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
2341         
2342         if(msg == MSG_SUICIDE) {
2343                 w = DEATH_WEAPONOF(type);
2344                 if(WEP_VALID(w)) {
2345                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2346                         if (alsoprint)
2347                                 print("^1", s1, "^1 ", Weapon_SuicideMessage(type), "\n");
2348                 } else if (type == DEATH_KILL) {
2349                         HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2350                         if (alsoprint)
2351                                 print ("^1",s1, "^1 couldn't take it anymore\n");
2352                 } else if (type == DEATH_ROT) {
2353                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2354                         if (alsoprint)
2355                                 print ("^1",s1, "^1 died\n");
2356                 } else if (type == DEATH_NOAMMO) {
2357                         HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2358                         if (alsoprint)
2359                                 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2360                 } else if (type == DEATH_CAMP) {
2361                         HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2362                         if (alsoprint)
2363                                 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2364                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2365                         HUD_KillNotify_Push(s1, "", 0, type);
2366                         if (alsoprint)
2367                                 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2368                 } else if (type == DEATH_CHEAT) {
2369                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2370                         if (alsoprint)
2371                                 print ("^1",s1, "^1 unfairly eliminated themself\n");
2372                 } else if (type == DEATH_FIRE) {
2373                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2374                         if (alsoprint)
2375                                 print ("^1",s1, "^1 burned to death\n");
2376                 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2377                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2378                         if (alsoprint)
2379                                 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2380                 } 
2381                 
2382                 if (stof(s2) > 2) // killcount > 2
2383                         print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2384         } else if(msg == MSG_KILL) {
2385                 w = DEATH_WEAPONOF(type);
2386                 if(WEP_VALID(w)) {
2387                         HUD_KillNotify_Push(s2, s1, 1, w);
2388                         if (alsoprint)
2389                                 print("^1", s1, "^1 ", Weapon_KillMessage(type), "\n");
2390                 }
2391                 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2392                         HUD_KillNotify_Push(s1, s2, 1, type);
2393                         if(alsoprint)
2394                         {
2395                                 if(gentle) {
2396                                         print ("^1", s1, "^1 took action against a team mate\n");
2397                                 } else {
2398                                         print ("^1", s1, "^1 mows down a team mate\n");
2399                                 }
2400                         }
2401                         if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2402                                 if(gentle)
2403                                         print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2404                                 else
2405                                         print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2406                         }
2407                         else if (stof(s2) > 2) {
2408                                 if(gentle)
2409                                         print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2410                                 else
2411                                         print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2412                         }
2413                 }
2414                 else if(type == KILL_FIRST_BLOOD)
2415                         print("^1",s1, "^1 drew first blood", "\n");
2416                 // TODO: icon!
2417                 else if (type == DEATH_TELEFRAG)
2418                         print ("^1",s1, "^1 was telefragged by ", s2, "\n");
2419                 else if (type == DEATH_DROWN) {
2420                         HUD_KillNotify_Push(s2, s1, 1, DEATH_DROWN);
2421                         if(alsoprint)
2422                                 print ("^1",s1, "^1 was drowned by ", s2, "\n");
2423                 }
2424                 else if (type == DEATH_SLIME) {
2425                         HUD_KillNotify_Push(s2, s1, 1, DEATH_SLIME);
2426                         if(alsoprint)
2427                                 print ("^1",s1, "^1 was slimed by ", s2, "\n");
2428                 }
2429                 else if (type == DEATH_LAVA) {
2430                         HUD_KillNotify_Push(s2, s1, 1, DEATH_LAVA);
2431                         if(alsoprint)
2432                                 print ("^1",s1, "^1 was cooked by ", s2, "\n");
2433                 }
2434                 else if (type == DEATH_FALL) {
2435                         HUD_KillNotify_Push(s2, s1, 1, DEATH_FALL);
2436                         if(alsoprint)
2437                                 print ("^1",s1, "^1 was grounded by ", s2, "\n");
2438                 }
2439                 else if (type == DEATH_SHOOTING_STAR) {
2440                         HUD_KillNotify_Push(s2, s1, 1, DEATH_SHOOTING_STAR);
2441                         if(alsoprint)
2442                                 print ("^1",s1, "^1 was shot into space by ", s2, "\n");
2443                 }
2444                 else if (type == DEATH_SWAMP) {
2445                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2446                         if(alsoprint)
2447                                 print ("^1",s1, "^1 was conserved by ", s2, "\n");
2448                 }
2449                 else if (type == DEATH_HURTTRIGGER)
2450                 {
2451                         HUD_KillNotify_Push(s2, s1, 1, DEATH_HURTTRIGGER);
2452                         if(alsoprint)
2453                                 print("^1",s1, "^1 was thrown into a world of hurt by ", s2, "\n");
2454                 } else if(type == DEATH_SBCRUSH) {
2455                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2456                         if(alsoprint)
2457                                 print ("^1",s1, "^1 was crushed by ^1", s2, "\n");
2458                 } else if(type == DEATH_SBMINIGUN) {
2459                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2460                         if(alsoprint)
2461                                 print ("^1",s1, "^1 got shredded by ^1", s2, "\n");
2462                 } else if(type == DEATH_SBROCKET) {
2463                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2464                         if(alsoprint)
2465                                 print ("^1",s1, "^1 was blased to bits by ^1", s2, "\n");
2466                 } else if(type == DEATH_SBBLOWUP) {
2467                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2468                         if(alsoprint)
2469                                 print ("^1",s1, "^1 got caught in the destruction of ^1", s2, "'s vehicle\n");
2470                 } else if(type == DEATH_WAKIGUN) {
2471                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2472                         if(alsoprint)
2473                                 print ("^1",s1, "^1 was bolted down by ^1", s2, "\n");
2474                 } else if(type == DEATH_WAKIROCKET) {
2475                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2476                         if(alsoprint)
2477                                 print ("^1",s1, "^1 could find no shelter from ^1", s2, "'s rockets\n");
2478                 } else if(type == DEATH_WAKIBLOWUP) {
2479                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2480                         if(alsoprint)
2481                                 print ("^1",s1, "^1 dies when ^1", s2, "'s wakizashi dies.\n");
2482                 } else if(type == DEATH_TURRET) {
2483                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2484                         if(alsoprint)
2485                                 print ("^1",s1, "^1 was pushed into the line of fire by ^1", s2, "\n");
2486                 } else if(type == DEATH_TOUCHEXPLODE) {
2487                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2488                         if(alsoprint)
2489                                 print ("^1",s1, "^1 was pushed into an accident by ^1", s2, "\n");
2490                 } else if(type == DEATH_CHEAT) {
2491                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2492                         if(alsoprint)
2493                                 print ("^1",s1, "^1 was unfairly eliminated by ^1", s2, "\n");
2494                 } else if (type == DEATH_FIRE) {
2495                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2496                         if(alsoprint)
2497                                 print ("^1",s1, "^1 was burnt to death by ^1", s2, "\n");
2498                 } else if (type == DEATH_CUSTOM) {
2499                         HUD_KillNotify_Push(s2, s1, 1, DEATH_CUSTOM);
2500                         if(alsoprint)
2501                                 print ("^1",s1, "^1 ", s2, "\n");
2502                 } else {
2503                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2504                         if(alsoprint)
2505                                 print ("^1",s1, "^1 was fragged by ", s2, "\n");
2506                 }
2507         } else if(msg == MSG_SPREE) {
2508                 if(type == KILL_END_SPREE) {
2509                         if(gentle)
2510                                 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2511                         else
2512                                 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2513                 } else if(type == KILL_SPREE) {
2514                         if(gentle)
2515                                 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2516                         else
2517                                 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2518                 } else if(type == KILL_SPREE_3) {
2519                         if(gentle)
2520                                 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2521                         else
2522                                 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2523                 } else if(type == KILL_SPREE_5) {
2524                         if(gentle)
2525                                 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2526                         else
2527                                 print (s1,"^7 unleashes ^1RAGE\n");
2528                 } else if(type == KILL_SPREE_10) {
2529                         if(gentle)
2530                                 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2531                         else
2532                                 print (s1,"^7 starts the ^1MASSACRE!\n");
2533                 } else if(type == KILL_SPREE_15) {
2534                         if(gentle)
2535                                 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2536                         else
2537                                 print (s1,"^7 executes ^1MAYHEM!\n");
2538                 } else if(type == KILL_SPREE_20) {
2539                         if(gentle)
2540                                 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2541                         else
2542                                 print (s1,"^7 is a ^1BERSERKER!\n");
2543                 } else if(type == KILL_SPREE_25) {
2544                         if(gentle)
2545                                 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2546                         else
2547                                 print (s1,"^7 inflicts ^1CARNAGE!\n");
2548                 } else if(type == KILL_SPREE_30) {
2549                         if(gentle)
2550                                 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2551                         else
2552                                 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2553                 }
2554         } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2555                 if (type == DEATH_DROWN) {
2556                         HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2557                         if(alsoprint)
2558                         {
2559                                 if(gentle)
2560                                         print ("^1",s1, "^1 was in the water for too long\n");
2561                                 else
2562                                         print ("^1",s1, "^1 drowned\n");
2563                         }
2564                 } else if (type == DEATH_SLIME) {
2565                         HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2566                         if(alsoprint)
2567                                 print ("^1",s1, "^1 was slimed\n");
2568                 } else if (type == DEATH_LAVA) {
2569                         HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2570                         if(alsoprint)
2571                         {
2572                                 if(gentle)
2573                                         print ("^1",s1, "^1 found a hot place\n");
2574                                 else
2575                                         print ("^1",s1, "^1 turned into hot slag\n");
2576                         }
2577                 } else if (type == DEATH_FALL) {
2578                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2579                         if(alsoprint)
2580                         {
2581                                 if(gentle)
2582                                         print ("^1",s1, "^1 tested gravity (and it worked)\n");
2583                                 else
2584                                         print ("^1",s1, "^1 hit the ground with a crunch\n");
2585                         }
2586                 } else if (type == DEATH_SHOOTING_STAR) {
2587                         HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2588                         if(alsoprint)
2589                                 print ("^1",s1, "^1 became a shooting star\n");
2590                 } else if (type == DEATH_SWAMP) {
2591                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2592                         if(alsoprint)
2593                         {
2594                                 if(gentle)
2595                                         print ("^1",s1, "^1 discovered a swamp\n");
2596                                 else
2597                                         print ("^1",s1, "^1 is now conserved for centuries to come\n");
2598                         }
2599                 } else if(type == DEATH_TURRET) {
2600                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2601                         if(alsoprint)
2602                                 print ("^1",s1, "^1 was mowed down by a turret \n");
2603                 } else if (type == DEATH_CUSTOM) {
2604                         HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2605                         if(alsoprint)
2606                                 print ("^1",s1, "^1 ", s2, "\n");
2607                 } else if (type == DEATH_HURTTRIGGER) {
2608                         HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2609                         if(alsoprint)
2610                                 print ("^1",s1, "^1 was in the wrong place\n");
2611                 } else if(type == DEATH_TOUCHEXPLODE) {
2612                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2613                         if(alsoprint)
2614                                 print ("^1",s1, "^1 died in an accident\n");
2615                 } else if(type == DEATH_CHEAT) {
2616                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2617                         if(alsoprint)
2618                                 print ("^1",s1, "^1 was unfairly eliminated\n");
2619                 } else if(type == DEATH_FIRE) {
2620                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2621                         if(alsoprint)
2622                         {
2623                                 if(gentle)
2624                                         print ("^1",s1, "^1 felt a little hot\n");
2625                                 else
2626                                         print ("^1",s1, "^1 burnt to death\n");
2627                                 }
2628                 } else {
2629                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2630                         if(alsoprint)
2631                         {
2632                                 if(gentle)
2633                                         print ("^1",s1, "^1 needs a restart\n");
2634                                 else
2635                                         print ("^1",s1, "^1 died\n");
2636                         }
2637                 }
2638         } else if(msg == MSG_KILL_ACTION_SPREE) {
2639                 if(gentle)
2640                         print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2641                 else
2642                         print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2643         } else if(msg == MSG_INFO) {
2644                 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2645                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2646                         print(s1, "^7 got the ", s2, "\n");
2647                 } else if(type == INFO_LOSTFLAG) {
2648                         HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2649                         print(s1, "^7 lost the ", s2, "\n");
2650                 } else if(type == INFO_PICKUPFLAG) {
2651                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2652                         print(s1, "^7 picked up the ", s2, "\n");
2653                 } else if(type == INFO_RETURNFLAG) {
2654                         HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2655                         print(s1, "^7 returned the ", s2, "\n");
2656                 } else if(type == INFO_CAPTUREFLAG) {
2657                         HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
2658                         print(s1, "^7 captured the ", s2, s3, "\n");
2659                 }
2660         }
2661 }
2662
2663 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
2664
2665 void HUD_Centerprint(string s1, string s2, float type, float msg)
2666 {
2667         float gentle;
2668         gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
2669         if(msg == MSG_SUICIDE) {
2670                 if (type == DEATH_TEAMCHANGE) {
2671                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
2672                 } else if (type == DEATH_AUTOTEAMCHANGE) {
2673                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
2674                 } else if (type == DEATH_CAMP) {
2675                         if(gentle)
2676                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
2677                         else
2678                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
2679                 } else if (type == DEATH_NOAMMO) {
2680                         if(gentle)
2681                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
2682                         else
2683                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
2684                 } else if (type == DEATH_ROT) {
2685                         if(gentle)
2686                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
2687                         else
2688                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
2689                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2690                         if(gentle)
2691                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
2692                         else
2693                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
2694                 } else if (type == DEATH_QUIET) {
2695                         // do nothing
2696                 } else if (type == DEATH_KILL) {
2697                         if(gentle)
2698                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
2699                         else
2700                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
2701                 }
2702         } else if(msg == MSG_KILL) {
2703                 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2704                         if(gentle) {
2705                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
2706                         } else {
2707                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
2708                         }
2709                 } else if (type == KILL_FIRST_BLOOD) {
2710                         if(gentle) {
2711                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
2712                         } else {
2713                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
2714                         }
2715                 } else if (type == KILL_FIRST_VICTIM) {
2716                         if(gentle) {
2717                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
2718                         } else {
2719                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
2720                         }
2721                 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
2722                         if(gentle) {
2723                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
2724                         } else {
2725                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
2726                         }
2727                 } else if (type == KILL_TYPEFRAGGED) {
2728                         if(gentle) {
2729                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
2730                         } else {
2731                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
2732                         }
2733                 } else if (type == KILL_FRAG) {
2734                         if(gentle) {
2735                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
2736                         } else {
2737                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
2738                         }
2739                 } else if (type == KILL_FRAGGED) {
2740                         if(gentle) {
2741                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
2742                         } else {
2743                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
2744                         }
2745                 }
2746         } else if(msg == MSG_KILL_ACTION) {
2747                 // TODO: invent more centerprints here?
2748                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
2749         }
2750 }
2751
2752 void HUD_Notify (void)
2753 {
2754         if(!autocvar_hud_notify && !autocvar__hud_configure)
2755                 return;
2756
2757         float id = HUD_PANEL_NOTIFY;
2758         HUD_Panel_UpdateCvarsForId(id);
2759         vector pos, mySize;
2760         pos = panel_pos;
2761         mySize = panel_size;
2762
2763         HUD_Panel_DrawBg(1);
2764         if(panel_bg_padding)
2765         {
2766                 pos += '1 1 0' * panel_bg_padding;
2767                 mySize -= '2 2 0' * panel_bg_padding;
2768         }
2769
2770         float entries, height;
2771         entries = bound(1, floor(10 * mySize_y/mySize_x), 10);
2772         height = mySize_y/entries;
2773