3 #include <client/autocvars.qh>
4 #include <client/defs.qh>
5 #include <client/miscfunctions.qh>
6 #include <client/view.qh>
7 #include <common/t_items.qh>
8 #include <common/wepent.qh>
9 #include <common/mutators/mutator/nades/nades.qh>
13 void DrawNadeProgressBar(vector myPos, vector mySize, float progress, vector color)
15 HUD_Panel_DrawProgressBar(
16 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
17 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
18 autocvar_hud_panel_ammo_progressbar_name,
19 progress, 0, 0, color,
20 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
23 void DrawAmmoItem(vector myPos, vector mySize, int ammoType, bool isCurrent, bool isInfinite)
25 TC(bool, isCurrent); TC(bool, isInfinite);
26 if(ammoType == RESOURCE_NONE)
29 // Initialize variables
32 if(autocvar__hud_configure)
34 isCurrent = (ammoType == RESOURCE_ROCKETS); // Rockets always current
38 ammo = getstati(GetAmmoStat(ammoType));
42 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
43 myPos = myPos + (mySize - mySize * scale) * 0.5;
44 mySize = mySize * scale;
47 vector iconPos, textPos;
48 if(autocvar_hud_panel_ammo_iconalign)
50 iconPos = myPos + eX * 2 * mySize.y;
56 textPos = myPos + eX * mySize.y;
59 bool isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
61 vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
64 textColor = '0.2 0.95 0';
68 textColor = '0.8 0.04 0';
74 alpha = panel_fg_alpha;
76 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
78 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
80 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
85 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
87 if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
88 HUD_Panel_DrawProgressBar(myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x, mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x, autocvar_hud_panel_ammo_progressbar_name, ammo/autocvar_hud_panel_ammo_maxammo, 0, 0, textColor, autocvar_hud_progressbar_alpha * alpha, DRAWFLAG_NORMAL);
90 if(autocvar_hud_panel_ammo_text)
91 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
93 drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
98 float nade_statuschange_time;
102 if(hud != HUD_NORMAL) return;
103 if(!autocvar__hud_configure)
105 if((!autocvar_hud_panel_ammo) || (spectatee_status == -1))
107 if(STAT(HEALTH) < 1 && autocvar_hud_panel_ammo_hide_ondeath)
111 HUD_Panel_LoadCvars();
113 draw_beginBoldFont();
119 if (autocvar_hud_panel_ammo_dynamichud)
126 pos += '1 1 0' * panel_bg_padding;
127 mySize -= '2 2 0' * panel_bg_padding;
130 int rows = 0, columns, row, column;
131 float nade_cnt = STAT(NADE_BONUS), nade_score = STAT(NADE_BONUS_SCORE);
132 bool draw_nades = (nade_cnt > 0 || nade_score > 0);
133 float nade_statuschange_elapsedtime;
134 int total_ammo_count;
137 if (autocvar_hud_panel_ammo_onlycurrent)
138 total_ammo_count = 1;
140 total_ammo_count = AMMO_COUNT;
145 if (nade_cnt != nade_prevframe)
147 nade_statuschange_time = time;
148 nade_prevstatus = nade_prevframe;
149 nade_prevframe = nade_cnt;
153 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
155 rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
156 columns = ceil((total_ammo_count)/rows);
157 ammo_size = vec2(mySize.x / columns, mySize.y / rows);
159 vector offset = '0 0 0';
161 if(ammo_size.x/ammo_size.y > 3)
163 newSize = 3 * ammo_size.y;
164 offset.x = ammo_size.x - newSize;
166 ammo_size.x = newSize;
170 newSize = 1/3 * ammo_size.x;
171 offset.y = ammo_size.y - newSize;
173 ammo_size.y = newSize;
176 entity wepent = viewmodels[0]; // TODO: unhardcode
178 Weapon wep = wepent.switchweapon;
180 bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_WEAPON_AMMO);
182 if(autocvar_hud_panel_ammo_onlycurrent)
184 if(autocvar__hud_configure)
186 DrawAmmoItem(pos, ammo_size, RESOURCE_ROCKETS, true, false);
210 for(i = 0; i < AMMO_COUNT; ++i)
212 ammotype = GetAmmoTypeFromNum(i);
214 pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)),
217 (wep.ammo_type == ammotype),
232 nade_statuschange_elapsedtime = time - nade_statuschange_time;
234 float f = bound(0, nade_statuschange_elapsedtime*2, 1);
236 DrawAmmoNades(pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)), ammo_size, nade_prevstatus < nade_cnt && nade_cnt != 0 && f < 1, f);