3 #include <client/autocvars.qh>
4 #include <client/draw.qh>
5 #include <client/items/items.qh>
6 #include <client/main.qh>
7 #include <client/view.qh>
8 #include <common/wepent.qh>
9 #include <common/mutators/mutator/nades/nades.qh>
13 void HUD_Ammo_Export(int fh)
15 // allow saving cvars that aesthetically change the panel into hud skin files
16 HUD_Write_Cvar("hud_panel_ammo_onlycurrent");
17 HUD_Write_Cvar("hud_panel_ammo_noncurrent_alpha");
18 HUD_Write_Cvar("hud_panel_ammo_noncurrent_scale");
19 HUD_Write_Cvar("hud_panel_ammo_iconalign");
20 HUD_Write_Cvar("hud_panel_ammo_progressbar");
21 HUD_Write_Cvar("hud_panel_ammo_progressbar_name");
22 HUD_Write_Cvar("hud_panel_ammo_progressbar_xoffset");
23 HUD_Write_Cvar("hud_panel_ammo_text");
26 void DrawNadeProgressBar(vector myPos, vector mySize, float progress, vector color)
28 HUD_Panel_DrawProgressBar(
29 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
30 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
31 autocvar_hud_panel_ammo_progressbar_name,
32 progress, 0, 0, color,
33 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
36 void DrawAmmoItem(vector myPos, vector mySize, int ammoType, bool isCurrent, bool isInfinite)
38 TC(bool, isCurrent); TC(bool, isInfinite);
39 if(ammoType == RES_NONE)
42 // Initialize variables
45 if(autocvar__hud_configure)
47 isCurrent = (ammoType == RES_ROCKETS); // Rockets always current
51 ammo = getstati(GetAmmoStat(ammoType));
55 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
56 myPos = myPos + (mySize - mySize * scale) * 0.5;
57 mySize = mySize * scale;
60 vector iconPos, textPos;
61 if(autocvar_hud_panel_ammo_iconalign)
63 iconPos = myPos + eX * 2 * mySize.y;
69 textPos = myPos + eX * mySize.y;
72 bool isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
74 vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
77 textColor = '0.2 0.95 0';
81 textColor = '0.8 0.04 0';
87 alpha = panel_fg_alpha;
89 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
91 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
93 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
98 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
100 if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
101 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);
103 if(autocvar_hud_panel_ammo_text)
104 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
106 drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
111 float nade_statuschange_time;
115 if(hud != HUD_NORMAL) return;
116 if(!autocvar__hud_configure)
118 if((!autocvar_hud_panel_ammo) || (spectatee_status == -1))
120 if(STAT(HEALTH) < 1 && autocvar_hud_panel_ammo_hide_ondeath)
124 HUD_Panel_LoadCvars();
126 draw_beginBoldFont();
132 if (autocvar_hud_panel_ammo_dynamichud)
139 pos += '1 1 0' * panel_bg_padding;
140 mySize -= '2 2 0' * panel_bg_padding;
143 int rows = 0, columns, row, column;
144 float nade_cnt = STAT(NADE_BONUS), nade_score = STAT(NADE_BONUS_SCORE);
145 bool draw_nades = (nade_cnt > 0 || nade_score > 0);
146 float nade_statuschange_elapsedtime;
147 int total_ammo_count;
150 if (autocvar_hud_panel_ammo_onlycurrent)
151 total_ammo_count = 1;
153 total_ammo_count = AMMO_COUNT;
158 if (nade_cnt != nade_prevframe)
160 nade_statuschange_time = time;
161 nade_prevstatus = nade_prevframe;
162 nade_prevframe = nade_cnt;
166 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
168 rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
169 columns = ceil((total_ammo_count)/rows);
170 ammo_size = vec2(mySize.x / columns, mySize.y / rows);
172 vector offset = '0 0 0';
174 if(ammo_size.x/ammo_size.y > 3)
176 newSize = 3 * ammo_size.y;
177 offset.x = ammo_size.x - newSize;
179 ammo_size.x = newSize;
183 newSize = 1/3 * ammo_size.x;
184 offset.y = ammo_size.y - newSize;
186 ammo_size.y = newSize;
189 entity wepent = viewmodels[0]; // TODO: unhardcode
191 Weapon wep = wepent.switchweapon;
193 bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO);
195 if(autocvar_hud_panel_ammo_onlycurrent)
197 if(autocvar__hud_configure)
199 DrawAmmoItem(pos, ammo_size, RES_ROCKETS, true, false);
223 for(i = 0; i < AMMO_COUNT; ++i)
225 ammotype = GetAmmoTypeFromNum(i);
227 pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)),
230 (wep.ammo_type == ammotype),
245 nade_statuschange_elapsedtime = time - nade_statuschange_time;
247 float f = bound(0, nade_statuschange_elapsedtime*2, 1);
249 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);