3 entity weaponorder[Weapons_MAX];
4 void weaponorder_swap(int i, int j, entity pass)
6 entity h = weaponorder[i];
7 weaponorder[i] = weaponorder[j];
11 string weaponorder_cmp_str;
12 int weaponorder_cmp(int i, int j, entity pass)
15 ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
16 aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
17 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)
24 WepSet weapons_stat = WepSet_GetFromStat();
28 vector center = '0 0 0';
29 int weapon_count, weapon_id;
30 int row, column, rows = 0, columns = 0;
31 bool vertical_order = true;
32 float aspect = autocvar_hud_panel_weapons_aspect;
34 float timeout = autocvar_hud_panel_weapons_timeout;
35 float timein_effect_length = autocvar_hud_panel_weapons_timeout_speed_in; //? 0.375 : 0);
36 float timeout_effect_length = autocvar_hud_panel_weapons_timeout_speed_out; //? 0.75 : 0);
38 vector barsize = '0 0 0', baroffset = '0 0 0';
39 vector ammo_color = '1 0 1';
42 float when = max(1, autocvar_hud_panel_weapons_complainbubble_time);
43 float fadetime = max(0, autocvar_hud_panel_weapons_complainbubble_fadetime);
45 vector weapon_pos, weapon_size = '0 0 0';
48 // check to see if we want to continue
49 if(hud != HUD_NORMAL) return;
51 if(!autocvar__hud_configure)
53 if((!autocvar_hud_panel_weapons) || (spectatee_status == -1))
55 if(timeout && time >= weapontime + timeout + timeout_effect_length)
56 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)))
58 weaponprevtime = time;
63 // update generic hud functions
64 HUD_Panel_UpdateCvars();
66 // figure out weapon order (how the weapons are sorted) // TODO make this configurable
67 if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
70 if(weaponorder_bypriority)
71 strunzone(weaponorder_bypriority);
72 if(weaponorder_byimpulse)
73 strunzone(weaponorder_byimpulse);
75 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
76 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
77 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
80 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
82 setself(get_weaponinfo(i));
85 weaponorder[weapon_cnt] = self;
89 for(i = weapon_cnt; i < Weapons_MAX; ++i)
90 weaponorder[i] = world;
91 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
93 weaponorder_cmp_str = string_null;
96 if(!autocvar_hud_panel_weapons_complainbubble || autocvar__hud_configure || time - complain_weapon_time >= when + fadetime)
99 if(autocvar__hud_configure)
102 for(i = WEP_FIRST; i <= WEP_LAST; i += floor((WEP_LAST-WEP_FIRST)/5))
103 weapons_stat |= WepSet_FromWeapon(i);
109 weapons_stat = '0 0 0';
110 float countw = 1 + floor((floor(time * cvar("wep_add"))) % (Weapons_COUNT - 1));
111 for(i = WEP_FIRST; i <= countw; ++i)
112 weapons_stat |= WepSet_FromWeapon(i);
117 // determine which weapons are going to be shown
118 if (autocvar_hud_panel_weapons_onlyowned)
120 if(autocvar__hud_configure)
122 if(menu_enabled != 2)
123 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
126 // do we own this weapon?
128 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
129 if((weapons_stat & WepSet_FromWeapon(weaponorder[i].weapon)) || (weaponorder[i].weapon == complain_weapon))
133 // might as well commit suicide now, no reason to live ;)
134 if (weapon_count == 0)
137 vector old_panel_size = panel_size;
138 vector padded_panel_size = panel_size - '2 2 0' * panel_bg_padding;
140 // get the all-weapons layout
142 WepSet weapons_stat = WepSet_GetFromStat();
143 for (int i = WEP_FIRST; i <= WEP_LAST; ++i) {
144 WepSet weapons_wep = WepSet_FromWeapon(i);
145 if (weapons_stat & weapons_wep) continue;
146 Weapon w = get_weaponinfo(i);
147 if (w.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1;
149 vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, padded_panel_size, aspect);
150 columns = table_size.x;
152 weapon_size.x = padded_panel_size.x / columns;
153 weapon_size.y = padded_panel_size.y / rows;
155 // NOTE: although weapons should aways look the same even if onlyowned is enabled,
156 // we enlarge them a bit when possible to better match the desired aspect ratio
157 if(padded_panel_size.x / padded_panel_size.y < aspect)
159 // maximum number of rows that allows to display items with the desired aspect ratio
160 int max_rows = floor(padded_panel_size.y / (weapon_size.x / aspect));
161 columns = min(columns, ceil(weapon_count / max_rows));
162 rows = ceil(weapon_count / columns);
163 weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
164 weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
165 vertical_order = false;
169 int max_columns = floor(padded_panel_size.x / (weapon_size.y * aspect));
170 rows = min(rows, ceil(weapon_count / max_columns));
171 columns = ceil(weapon_count / rows);
172 weapon_size.x = min(padded_panel_size.x / columns, aspect * weapon_size.y);
173 weapon_size.y = min(padded_panel_size.y / rows, weapon_size.x / aspect);
174 vertical_order = true;
177 // reduce size of the panel
178 panel_size.x = columns * weapon_size.x;
179 panel_size.y = rows * weapon_size.y;
180 panel_size += '2 2 0' * panel_bg_padding;
182 // center the resized panel, or snap it to the screen edge when close enough
183 if(panel_pos.x > vid_conwidth * 0.001)
185 if(panel_pos.x + old_panel_size.x > vid_conwidth * 0.999)
186 panel_pos.x += old_panel_size.x - panel_size.x;
188 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
190 else if(old_panel_size.x > vid_conwidth * 0.999)
191 panel_pos.x += (old_panel_size.x - panel_size.x) / 2;
193 if(panel_pos.y > vid_conheight * 0.001)
195 if(panel_pos.y + old_panel_size.y > vid_conheight * 0.999)
196 panel_pos.y += old_panel_size.y - panel_size.y;
198 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
200 else if(old_panel_size.y > vid_conheight * 0.999)
201 panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
204 weapon_count = (Weapons_COUNT - 1);
206 // animation for fading in/out the panel respectively when not in use
207 if(!autocvar__hud_configure)
209 if (timeout && time >= weapontime + timeout) // apply timeout effect if needed
211 f = bound(0, (time - (weapontime + timeout)) / timeout_effect_length, 1);
213 // fade the panel alpha
214 if(autocvar_hud_panel_weapons_timeout_effect == 1)
216 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * f + (1 - f));
217 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * f + (1 - f));
219 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
221 panel_bg_alpha *= (1 - f);
222 panel_fg_alpha *= (1 - f);
225 // move the panel off the screen
226 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
228 f *= f; // for a cooler movement
229 center.x = panel_pos.x + panel_size.x/2;
230 center.y = panel_pos.y + panel_size.y/2;
231 screen_ar = vid_conwidth/vid_conheight;
232 if (center.x/center.y < screen_ar) //bottom left
234 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
235 panel_pos.y += f * (vid_conheight - panel_pos.y);
237 panel_pos.x -= f * (panel_pos.x + panel_size.x);
241 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
242 panel_pos.x += f * (vid_conwidth - panel_pos.x);
244 panel_pos.y -= f * (panel_pos.y + panel_size.y);
247 center.x = -1; // mark the panel as off screen
249 weaponprevtime = time - (1 - f) * timein_effect_length;
251 else if (timeout && time < weaponprevtime + timein_effect_length) // apply timein effect if needed
253 f = bound(0, (time - weaponprevtime) / timein_effect_length, 1);
255 // fade the panel alpha
256 if(autocvar_hud_panel_weapons_timeout_effect == 1)
258 panel_bg_alpha *= (autocvar_hud_panel_weapons_timeout_fadebgmin * (1 - f) + f);
259 panel_fg_alpha *= (autocvar_hud_panel_weapons_timeout_fadefgmin * (1 - f) + f);
261 else if(autocvar_hud_panel_weapons_timeout_effect == 3)
263 panel_bg_alpha *= (f);
264 panel_fg_alpha *= (f);
267 // move the panel back on screen
268 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
270 f *= f; // for a cooler movement
272 center.x = panel_pos.x + panel_size.x/2;
273 center.y = panel_pos.y + panel_size.y/2;
274 screen_ar = vid_conwidth/vid_conheight;
275 if (center.x/center.y < screen_ar) //bottom left
277 if ((vid_conwidth - center.x)/center.y < screen_ar) //bottom
278 panel_pos.y += f * (vid_conheight - panel_pos.y);
280 panel_pos.x -= f * (panel_pos.x + panel_size.x);
284 if ((vid_conwidth - center.x)/center.y < screen_ar) //right
285 panel_pos.x += f * (vid_conwidth - panel_pos.x);
287 panel_pos.y -= f * (panel_pos.y + panel_size.y);
293 // draw the background, then change the virtual size of it to better fit other items inside
301 panel_pos += '1 1 0' * panel_bg_padding;
302 panel_size -= '2 2 0' * panel_bg_padding;
305 // after the sizing and animations are done, update the other values
307 if(!rows) // if rows is > 0 onlyowned code has already updated these vars
309 vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1), panel_size, aspect);
310 columns = table_size.x;
312 weapon_size.x = panel_size.x / columns;
313 weapon_size.y = panel_size.y / rows;
314 vertical_order = (panel_size.x / panel_size.y >= aspect);
317 // calculate position/size for visual bar displaying ammount of ammo status
318 if (autocvar_hud_panel_weapons_ammo)
320 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
321 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
323 if(weapon_size.x/weapon_size.y > aspect)
325 barsize.x = aspect * weapon_size.y;
326 barsize.y = weapon_size.y;
327 baroffset.x = (weapon_size.x - barsize.x) / 2;
331 barsize.y = 1/aspect * weapon_size.x;
332 barsize.x = weapon_size.x;
333 baroffset.y = (weapon_size.y - barsize.y) / 2;
336 if(autocvar_hud_panel_weapons_accuracy)
337 Accuracy_LoadColors();
341 vector label_size = '1 1 0' * min(weapon_size.x, weapon_size.y) * bound(0, autocvar_hud_panel_weapons_label_scale, 1);
342 vector noncurrent_pos = '0 0 0';
343 vector noncurrent_size = weapon_size * bound(0, autocvar_hud_panel_weapons_noncurrent_scale, 1);
344 float noncurrent_alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_weapons_noncurrent_alpha, 1);
347 for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
349 // retrieve information about the current weapon to be drawn
350 setself(weaponorder[i]);
351 weapon_id = self.impulse;
352 isCurrent = (self.weapon == switchweapon);
354 // skip if this weapon doesn't exist
355 if(!self || weapon_id < 0) { continue; }
357 // skip this weapon if we don't own it (and onlyowned is enabled)-- or if weapons_complainbubble is showing for this weapon
358 if(autocvar_hud_panel_weapons_onlyowned)
359 if (!((weapons_stat & WepSet_FromWeapon(self.weapon)) || (self.weapon == complain_weapon)))
362 // figure out the drawing position of weapon
363 weapon_pos = (panel_pos + eX * column * weapon_size.x + eY * row * weapon_size.y);
364 noncurrent_pos.x = weapon_pos.x + (weapon_size.x - noncurrent_size.x) / 2;
365 noncurrent_pos.y = weapon_pos.y + (weapon_size.y - noncurrent_size.y) / 2;
367 // draw background behind currently selected weapon
369 drawpic_aspect_skin(weapon_pos, "weapon_current_bg", weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
371 // draw the weapon accuracy
372 if(autocvar_hud_panel_weapons_accuracy)
374 float panel_weapon_accuracy = weapon_accuracy[self.weapon-WEP_FIRST];
375 if(panel_weapon_accuracy >= 0)
377 color = Accuracy_GetColor(panel_weapon_accuracy);
378 drawpic_aspect_skin(weapon_pos, "weapon_accuracy", weapon_size, color, panel_fg_alpha, DRAWFLAG_NORMAL);
382 // drawing all the weapon items
383 if(weapons_stat & WepSet_FromWeapon(self.weapon))
385 // draw the weapon image
387 drawpic_aspect_skin(weapon_pos, self.model2, weapon_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
389 drawpic_aspect_skin(noncurrent_pos, self.model2, noncurrent_size, '1 1 1', noncurrent_alpha, DRAWFLAG_NORMAL);
391 // draw weapon label string
392 switch(autocvar_hud_panel_weapons_label)
394 case 1: // weapon number
395 drawstring(weapon_pos, ftos(weapon_id), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
399 drawstring(weapon_pos, getcommandkey(ftos(weapon_id), strcat("weapon_group_", ftos(weapon_id))), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
402 case 3: // weapon name
403 drawstring(weapon_pos, strtolower(self.m_name), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
410 // draw ammo status bar
411 if(autocvar_hud_panel_weapons_ammo && (self.ammo_field != ammo_none))
414 a = getstati(GetAmmoStat(self.ammo_field)); // how much ammo do we have?
418 switch(self.ammo_field)
420 case ammo_shells: ammo_full = autocvar_hud_panel_weapons_ammo_full_shells; break;
421 case ammo_nails: ammo_full = autocvar_hud_panel_weapons_ammo_full_nails; break;
422 case ammo_rockets: ammo_full = autocvar_hud_panel_weapons_ammo_full_rockets; break;
423 case ammo_cells: ammo_full = autocvar_hud_panel_weapons_ammo_full_cells; break;
424 case ammo_plasma: ammo_full = autocvar_hud_panel_weapons_ammo_full_plasma; break;
425 case ammo_fuel: ammo_full = autocvar_hud_panel_weapons_ammo_full_fuel; break;
426 default: ammo_full = 60;
430 weapon_pos.x + baroffset.x,
431 weapon_pos.y + baroffset.y,
432 barsize.x * bound(0, a/ammo_full, 1),
449 else // draw a "ghost weapon icon" if you don't have the weapon
451 drawpic_aspect_skin(noncurrent_pos, self.model2, noncurrent_size, '0.2 0.2 0.2', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
454 // draw the complain message
455 if(self.weapon == complain_weapon)
458 a = ((complain_weapon_time + when > time) ? 1 : bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1));
460 a = ((complain_weapon_time + when > time) ? 1 : 0);
463 if(complain_weapon_type == 0) {
464 s = _("Out of ammo");
465 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
467 else if(complain_weapon_type == 1) {
469 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
472 s = _("Unavailable");
473 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
475 float padding = autocvar_hud_panel_weapons_complainbubble_padding;
476 drawpic_aspect_skin(weapon_pos + '1 1 0' * padding, "weapon_complainbubble", weapon_size - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
477 drawstring_aspect(weapon_pos + '1 1 0' * padding, s, weapon_size - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
482 if(!autocvar_hud_panel_weapons_onlyowned)
484 drawfill(weapon_pos + '1 1 0', weapon_size - '2 2 0', '1 1 1', panel_fg_alpha * 0.2, DRAWFLAG_NORMAL);
485 drawstring(weapon_pos, ftos(i + 1), label_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
489 // continue with new position for the next weapon
493 if(column >= columns)