]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/weapons.qc
Merge branch 'terencehill/spectate_player' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / weapons.qc
1 #include "weapons.qh"
2
3 #include <client/autocvars.qh>
4 #include <client/defs.qh>
5 #include <client/miscfunctions.qh>
6 #include <client/view.qh>
7 #include <common/wepent.qh>
8
9 // Weapons (#0)
10
11 entity weaponorder[Weapons_MAX];
12 void weaponorder_swap(int i, int j, entity pass)
13 {
14         TC(int, i); TC(int, j);
15         entity h = weaponorder[i];
16         weaponorder[i] = weaponorder[j];
17         weaponorder[j] = h;
18 }
19
20 string weaponorder_cmp_str;
21 int weaponorder_cmp(int i, int j, entity pass)
22 {
23         TC(int, i); TC(int, j);
24         int ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].m_id), 0);
25         int aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].m_id), 0);
26         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)
27 }
28
29 #define HUD_WEAPONS_GET_FULL_LAYOUT() MACRO_BEGIN \
30         int nHidden = 0; \
31         FOREACH(Weapons, it != WEP_Null, { \
32                 if (weapons_stat & WepSet_FromWeapon(it)) continue; \
33                 if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)) nHidden += 1; \
34         }); \
35         vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, panel_size, aspect); \
36         columns = table_size.x; \
37         rows = table_size.y; \
38         weapon_size.x = panel_size.x / columns; \
39         weapon_size.y = panel_size.y / rows; \
40 MACRO_END
41
42 string cl_weaponpriority_old;
43 bool weapons_orderbyimpulse_old;
44 void HUD_Weapons()
45 {
46         // declarations
47         WepSet weapons_stat = WepSet_GetFromStat();
48         int i;
49         float f, a;
50         float screen_ar;
51         vector center = '0 0 0';
52         int weapon_count, weapon_id;
53         int row, column, rows = 0, columns = 0;
54         bool vertical_order = true;
55         float aspect = autocvar_hud_panel_weapons_aspect;
56
57         float timeout = autocvar_hud_panel_weapons_timeout;
58         float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
59         float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
60
61         vector barsize = '0 0 0', baroffset = '0 0 0';
62         vector ammo_color = '1 0 1';
63         float ammo_alpha = 1;
64
65         float when = max(1, autocvar_hud_panel_weapons_complainbubble_time);
66         float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime);
67
68         bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO);
69
70         vector weapon_pos, weapon_size = '0 0 0';
71         vector color;
72
73         entity panel_switchweapon = NULL;
74
75         // check to see if we want to continue
76         if(hud != HUD_NORMAL) return;
77
78         if(!autocvar__hud_configure)
79         {
80                 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
81                         return;
82                 if(STAT(HEALTH) <= 0 && autocvar_hud_panel_weapons_hide_ondeath)
83                         return;
84                 if(timeout && time >= weapontime + timeout + timeout_effect_length)
85                 if(autocvar_hud_panel_weapons_timeout_effect == 3 || (autocvar_hud_panel_weapons_timeout_effect == 1 && !(autocvar_hud_panel_weapons_timeout_fadebgmin + autocvar_hud_panel_weapons_timeout_fadefgmin)))
86                 {
87                         weaponprevtime = time;
88                         return;
89                 }
90         }
91
92         // update generic hud functions
93         HUD_Panel_LoadCvars();
94
95         if(cl_weaponpriority_old != autocvar_cl_weaponpriority || weapons_orderbyimpulse_old != autocvar_hud_panel_weapons_orderbyimpulse || weaponorder[0] == NULL)
96         {
97                 weapons_orderbyimpulse_old = autocvar_hud_panel_weapons_orderbyimpulse;
98                 strcpy(cl_weaponpriority_old, autocvar_cl_weaponpriority);
99                 string weporder = W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(cl_weaponpriority_old));
100                 if(autocvar_hud_panel_weapons_orderbyimpulse)
101                 {
102                         weporder = W_FixWeaponOrder_BuildImpulseList(weporder);
103                 }
104
105                 weaponorder_cmp_str = strcat(" ", weporder, " ");
106
107                 int weapon_cnt = 0;
108                 FOREACH(Weapons, it != WEP_Null && it.impulse >= 0, weaponorder[weapon_cnt++] = it);
109                 for(i = weapon_cnt; i < Weapons_MAX; ++i)
110                         weaponorder[i] = NULL;
111                 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, NULL);
112
113                 weaponorder_cmp_str = string_null;
114         }
115
116         if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime)
117                 complain_weapon = NULL;
118
119         entity wepent = viewmodels[0]; // TODO: unhardcode
120
121         if (wepent.switchweapon == WEP_Null)
122                 panel_switchweapon = NULL;
123         else if (!panel_switchweapon)
124                 panel_switchweapon = wepent.switchweapon;
125
126         if(autocvar__hud_configure)
127         {
128                 if(!weapons_stat)
129                 {
130                         int j = 0;
131                         FOREACH(Weapons, it != WEP_Null && it.impulse >= 0 && (it.impulse % 3 != 0) && j < 6, {
132                                 if(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & WEP_FLAG_SPECIALATTACK))
133                                 {
134                                         if(!panel_switchweapon || j < 4)
135                                                 panel_switchweapon = it;
136                                         weapons_stat |= it.m_wepset;
137                                         ++j;
138                                 }
139                         });
140                 }
141
142                 #if 0
143                 /// debug code
144                 if(cvar("wep_add"))
145                 {
146                         int j;
147                         int nHidden = 0;
148                         FOREACH(Weapons, it != WEP_Null, {
149                                 if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1;
150                         });
151                         weapons_stat = '0 0 0';
152                         float countw = 1 + floor((floor(time * cvar("wep_add"))) % ((Weapons_COUNT - 1) - nHidden));
153                         for(i = 0, j = 0; i <= (Weapons_COUNT - 1) && j < countw; ++i)
154                         {
155                                 if(weaponorder[i].spawnflags & WEP_FLAG_MUTATORBLOCKED)
156                                         continue;
157                                 weapons_stat |= weaponorder[i].m_wepset;
158                                 ++j;
159                         }
160                 }
161                 #endif
162         }
163
164         // determine which weapons are going to be shown
165         if (autocvar_hud_panel_weapons_onlyowned)
166         {
167                 if(autocvar__hud_configure)
168                 {
169                         if(hud_configure_menu_open != 2)
170                                 HUD_Panel_DrawBg(); // also draw the bg of the entire panel
171                 }
172
173                 // do we own this weapon?
174                 weapon_count = 0;
175                 if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current
176                 {
177                         for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
178                                 if (weaponorder[i] == panel_switchweapon || weaponorder[i] == complain_weapon)
179                                         ++weapon_count;
180                 }
181                 else
182                 {
183                         for (i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
184                                 if ((weapons_stat & WepSet_FromWeapon(weaponorder[i])) || weaponorder[i] == complain_weapon)
185                                         ++weapon_count;
186                 }
187
188                 // might as well commit suicide now, no reason to live ;)
189                 if (weapon_count == 0)
190                         return;
191
192                 vector old_panel_size = panel_size;
193                 panel_size -= '2 2 0' * panel_bg_padding;
194
195                 HUD_WEAPONS_GET_FULL_LAYOUT();
196
197                 // NOTE: although weapons should aways look the same even if onlyowned is enabled,
198                 // we enlarge them a bit when possible to better match the desired aspect ratio
199                 if(panel_size.x / panel_size.y < aspect)
200                 {
201                         // maximum number of rows that allows to display items with the desired aspect ratio
202                         int max_rows = floor(panel_size.y / (weapon_size.x / aspect));
203                         columns = min(columns, ceil(weapon_count / max_rows));
204                         rows = ceil(weapon_count / columns);
205                         weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
206                         weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
207                         vertical_order = false;
208                 }
209                 else
210                 {
211                         int max_columns = floor(panel_size.x / (weapon_size.y * aspect));
212                         rows = min(rows, ceil(weapon_count / max_columns));
213                         columns = ceil(weapon_count / rows);
214                         weapon_size.x = min(panel_size.x / columns, aspect * weapon_size.y);
215                         weapon_size.y = min(panel_size.y / rows, weapon_size.x / aspect);
216                         vertical_order = true;
217                 }
218
219                 // reduce size of the panel
220                 panel_size.x = columns * weapon_size.x;
221                 panel_size.y = rows * weapon_size.y;
222                 panel_size += '2 2 0' * panel_bg_padding;
223
224                 // center the resized panel, or snap it to the screen edge when close enough
225                 if(panel_pos.x > vid_conwidth * 0.001)
226                 {
227                         if(panel_pos.x + old_panel_size.x > vid_conwidth * 0.999)
228                                 panel_pos.x += old_panel_size.x - panel_size.x;
229                         else
230                                 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
231                 }
232                 else if(old_panel_size.x > vid_conwidth * 0.999)
233                         panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
234
235                 if(panel_pos.y > vid_conheight * 0.001)
236                 {
237                         if(panel_pos.y + old_panel_size.y > vid_conheight * 0.999)
238                                 panel_pos.y += old_panel_size.y - panel_size.y;
239                         else
240                                 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
241                 }
242                 else if(old_panel_size.y > vid_conheight * 0.999)
243                         panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
244         }
245         else
246                 weapon_count = (Weapons_COUNT - 1);
247
248         // animation for fading in/out the panel respectively when not in use
249         if(!autocvar__hud_configure)
250         {
251                 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
252                 {
253                         f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
254
255                         // fade the panel alpha
256                         if(autocvar_hud_panel_weapons_timeout_effect == 1)
257                         {
258                                 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
259                                 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
260                         }
261                         else if(autocvar_hud_panel_weapons_timeout_effect == 3)
262                         {
263                                 panel_bg_alpha *= (1 - f);
264                                 panel_fg_alpha *= (1 - f);
265                         }
266
267                         // move the panel off the screen
268                         if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
269                         {
270                                 f *= f; // for a cooler movement
271                                 center.x = panel_pos.x + panel_size.x/2;
272                                 center.y = panel_pos.y + panel_size.y/2;
273                                 screen_ar = vid_conwidth/vid_conheight;
274                                 if (center.x/center.y < screen_ar) //bottom left
275                                 {
276                                         if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
277                                                 panel_pos.y += f * (vid_conheight - panel_pos.y);
278                                         else //left
279                                                 panel_pos.x -= f * (panel_pos.x + panel_size.x);
280                                 }
281                                 else //top right
282                                 {
283                                         if ((vid_conwidth - center.x)/center.y < screen_ar) //right
284                                                 panel_pos.x += f * (vid_conwidth - panel_pos.x);
285                                         else //top
286                                                 panel_pos.y -= f * (panel_pos.y + panel_size.y);
287                                 }
288                                 if(f == 1)
289                                         center.x = -1; // mark the panel as off screen
290                         }
291                         weaponprevtime = time - (1 - f) * timein_effect_length;
292                 }
293                 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
294                 {
295                         f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
296
297                         // fade the panel alpha
298                         if(autocvar_hud_panel_weapons_timeout_effect == 1)
299                         {
300                                 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
301                                 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
302                         }
303                         else if(autocvar_hud_panel_weapons_timeout_effect == 3)
304                         {
305                                 panel_bg_alpha *= (f);
306                                 panel_fg_alpha *= (f);
307                         }
308
309                         // move the panel back on screen
310                         if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
311                         {
312                                 f *= f; // for a cooler movement
313                                 f = 1 - f;
314                                 center.x = panel_pos.x + panel_size.x/2;
315                                 center.y = panel_pos.y + panel_size.y/2;
316                                 screen_ar = vid_conwidth/vid_conheight;
317                                 if (center.x/center.y < screen_ar) //bottom left
318                                 {
319                                         if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
320                                                 panel_pos.y += f * (vid_conheight - panel_pos.y);
321                                         else //left
322                                                 panel_pos.x -= f * (panel_pos.x + panel_size.x);
323                                 }
324                                 else //top right
325                                 {
326                                         if ((vid_conwidth - center.x)/center.y < screen_ar) //right
327                                                 panel_pos.x += f * (vid_conwidth - panel_pos.x);
328                                         else //top
329                                                 panel_pos.y -= f * (panel_pos.y + panel_size.y);
330                                 }
331                         }
332                 }
333         }
334
335         // draw the background, then change the virtual size of it to better fit other items inside
336         if (autocvar_hud_panel_weapons_dynamichud)
337                 HUD_Scale_Enable();
338         else
339                 HUD_Scale_Disable();
340         HUD_Panel_DrawBg();
341
342         if(center.x == -1)
343                 return; // panel has gone off screen
344
345         if(panel_bg_padding)
346         {
347                 panel_pos += '1 1 0' * panel_bg_padding;
348                 panel_size -= '2 2 0' * panel_bg_padding;
349         }
350
351         // after the sizing and animations are done, update the other values
352
353         if(!rows) // if rows is > 0 onlyowned code has already updated these vars
354         {
355                 HUD_WEAPONS_GET_FULL_LAYOUT();
356                 vertical_order = (panel_size.x / panel_size.y >= aspect);
357         }
358
359         // calculate position/size for visual bar displaying ammount of ammo status
360         if (!infinite_ammo && autocvar_hud_panel_weapons_ammo)
361         {
362                 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
363                 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
364
365                 if(weapon_size.x/weapon_size.y > aspect)
366                 {
367                         barsize.x = aspect * weapon_size.y;
368                         barsize.y = weapon_size.y;
369                         baroffset.x = (weapon_size.x - barsize.x) / 2;
370                 }
371                 else
372                 {
373                         barsize.y = 1/aspect * weapon_size.x;
374                         barsize.x = weapon_size.x;
375                         baroffset.y = (weapon_size.y - barsize.y) / 2;
376                 }
377         }
378         if(autocvar_hud_panel_weapons_accuracy)
379                 Accuracy_LoadColors();
380
381         // draw items
382         row = column = 0;
383         vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
384         vector noncurrent_size = weapon_size * bound(0.01, autocvar_hud_panel_weapons_noncurrent_scale, 1);
385         float noncurrent_alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_weapons_noncurrent_alpha, 1);
386         static vector weapon_pos_current = '-1 0 0';
387         if(weapon_pos_current.x == -1)
388                 weapon_pos_current = panel_pos;
389
390         float switch_speed;
391         if(autocvar_hud_panel_weapons_selection_speed <= 0 || autocvar__hud_configure)
392                 switch_speed = 999;
393         else
394                 switch_speed = frametime * autocvar_hud_panel_weapons_selection_speed;
395         vector radius_size = weapon_size * (autocvar_hud_panel_weapons_selection_radius + 1);
396
397         // draw background behind currently selected weapon
398         // do it earlier to make sure bg is drawn behind every weapon icons while it's moving
399         if(panel_switchweapon)
400                 drawpic_aspect_skin(weapon_pos_current, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
401
402         for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
403         {
404                 // retrieve information about the current weapon to be drawn
405                 entity it = weaponorder[i];
406                 weapon_id = it.impulse;
407
408                 // skip if this weapon doesn't exist
409                 if(!it || weapon_id < 0) { continue; }
410
411                 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
412                 if (autocvar_hud_panel_weapons_onlyowned)
413                 {
414                         if (autocvar_hud_panel_weapons_onlyowned >= 2) // only current
415                         {
416                                 if (!(it == panel_switchweapon || it == complain_weapon))
417                                         continue;
418                         }
419                         else
420                         {
421                                 if (!((weapons_stat & WepSet_FromWeapon(it)) || (it == complain_weapon)))
422                                         continue;
423                         }
424                 }
425                 else
426                 {
427                         if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)
428                                 && !(weapons_stat & WepSet_FromWeapon(it)))
429                         {
430                                 continue;
431                         }
432                 }
433
434                 // figure out the drawing position of weapon
435                 weapon_pos = panel_pos + vec2(column * weapon_size.x, row * weapon_size.y);
436
437                 // update position of the currently selected weapon
438                 if(it == panel_switchweapon)
439                 {
440                         if(weapon_pos_current.y > weapon_pos.y)
441                                 weapon_pos_current.y = max(weapon_pos.y, weapon_pos_current.y - switch_speed * (weapon_pos_current.y - weapon_pos.y));
442                         else if(weapon_pos_current.y < weapon_pos.y)
443                                 weapon_pos_current.y = min(weapon_pos.y, weapon_pos_current.y + switch_speed * (weapon_pos.y - weapon_pos_current.y));
444                         if(weapon_pos_current.x > weapon_pos.x)
445                                 weapon_pos_current.x = max(weapon_pos.x, weapon_pos_current.x - switch_speed * (weapon_pos_current.x - weapon_pos.x));
446                         else if(weapon_pos_current.x < weapon_pos.x)
447                                 weapon_pos_current.x = min(weapon_pos.x, weapon_pos_current.x + switch_speed * (weapon_pos.x - weapon_pos_current.x));
448                 }
449
450                 // draw the weapon accuracy
451                 if(autocvar_hud_panel_weapons_accuracy)
452                 {
453                         float panel_weapon_accuracy = weapon_accuracy[it.m_id-WEP_FIRST];
454                         if(panel_weapon_accuracy >= 0)
455                         {
456                                 color = Accuracy_GetColor(panel_weapon_accuracy);
457                                 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
458                         }
459                 }
460
461                 vector weapon_size_real = noncurrent_size;
462                 float weapon_alpha_real = noncurrent_alpha;
463                 float radius_factor_x = 1 - bound(0, fabs(weapon_pos.x - weapon_pos_current.x) / radius_size.x, 1);
464                 float radius_factor_y = 1 - bound(0, fabs(weapon_pos.y - weapon_pos_current.y) / radius_size.y, 1);
465                 if(radius_factor_x || radius_factor_y)
466                 {
467                         weapon_size_real.x += (weapon_size.x - noncurrent_size.x) * radius_factor_x;
468                         weapon_size_real.y += (weapon_size.y - noncurrent_size.y) * radius_factor_y;
469                         weapon_alpha_real += (panel_fg_alpha - noncurrent_alpha) * min(radius_factor_x, radius_factor_y);
470                 }
471
472                 vector weapon_pos_real = weapon_pos;
473                 weapon_pos_real.x = weapon_pos.x + (weapon_size.x - weapon_size_real.x) / 2;
474                 weapon_pos_real.y = weapon_pos.y + (weapon_size.y - weapon_size_real.y) / 2;
475
476                 // drawing all the weapon items
477                 if(weapons_stat & WepSet_FromWeapon(it))
478                 {
479                         // draw the weapon image
480                         drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '1 1 1', weapon_alpha_real, DRAWFLAG_NORMAL);
481
482                         // draw weapon label string
483                         switch(autocvar_hud_panel_weapons_label)
484                         {
485                                 case 1: // weapon number
486                                         drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
487                                         break;
488
489                                 case 2: // bind
490                                         drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
491                                         break;
492
493                                 case 3: // weapon name
494                                         drawstring(weapon_pos, strtolower(it.m_name), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
495                                         break;
496
497                                 default: // nothing
498                                         break;
499                         }
500
501                         // draw ammo status bar
502                         if(!infinite_ammo && autocvar_hud_panel_weapons_ammo && (it.ammo_type != RES_NONE))
503                         {
504                                 float ammo_full;
505                                 a = getstati(GetAmmoStat(it.ammo_type)); // how much ammo do we have?
506
507                                 if(a > 0)
508                                 {
509                                         switch (it.ammo_type)
510                                         {
511                                                 case RES_SHELLS:  ammo_full = autocvar_hud_panel_weapons_ammo_full_shells;  break;
512                                                 case RES_BULLETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails;   break;
513                                                 case RES_ROCKETS: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
514                                                 case RES_CELLS:   ammo_full = autocvar_hud_panel_weapons_ammo_full_cells;   break;
515                                                 case RES_PLASMA:  ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma;  break;
516                                                 case RES_FUEL:    ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel;    break;
517                                                 default: ammo_full = 60;
518                                         }
519
520                                         drawsetcliparea(
521                                                 weapon_pos.x + baroffset.x,
522                                                 weapon_pos.y + baroffset.y,
523                                                 barsize.x * bound(0, a/ammo_full, 1),
524                                                 barsize.y
525                                         );
526
527                                         drawpic_aspect_skin(
528                                                 weapon_pos,
529                                                 "weapon_ammo",
530                                                 weapon_size,
531                                                 ammo_color,
532                                                 ammo_alpha,
533                                                 DRAWFLAG_NORMAL
534                                         );
535
536                                         drawresetcliparea();
537                                 }
538                         }
539                 }
540                 else // draw a "ghost weapon icon" if you don't have the weapon
541                 {
542                         drawpic_aspect_skin(weapon_pos_real, it.model2, weapon_size_real, '0.2 0.2 0.2', weapon_alpha_real * 0.5, DRAWFLAG_NORMAL);
543                 }
544
545                 // draw the complain message
546                 if(it == complain_weapon)
547                 {
548                         if(fadetime)
549                                 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
550                         else
551                                 a = ((complain_weapon_time + when > time) ? 1 : 0);
552
553                         string s;
554                         if(complain_weapon_type == 0) {
555                                 s = _("Out of ammo");
556                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
557                         }
558                         else if(complain_weapon_type == 1) {
559                                 s = _("Don't have");
560                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
561                         }
562                         else {
563                                 s = _("Unavailable");
564                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
565                         }
566                         float padding = autocvar_hud_panel_weapons_complainbubble_padding;
567                         drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
568                         drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
569                 }
570
571                 #if 0
572                 /// debug code
573                 if(!autocvar_hud_panel_weapons_onlyowned)
574                 {
575                         drawfill(weapon_pos + '1 1 0', weapon_size - '2 2 0', '1 1 1', panel_fg_alpha * 0.2, DRAWFLAG_NORMAL);
576                         drawstring(weapon_pos, ftos(i + 1), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
577                 }
578                 #endif
579
580                 // continue with new position for the next weapon
581                 if(vertical_order)
582                 {
583                         ++column;
584                         if(column >= columns)
585                         {
586                                 column = 0;
587                                 ++row;
588                         }
589                 }
590                 else
591                 {
592                         ++row;
593                         if(row >= rows)
594                         {
595                                 row = 0;
596                                 ++column;
597                         }
598                 }
599         }
600 }