3 #include <client/draw.qh>
4 #include <client/items/items.qh>
5 #include <client/view.qh>
6 #include <common/mutators/mutator/nades/nades.qh>
7 #include <common/resources/resources.qh>
8 #include <common/wepent.qh>
12 void HUD_Ammo_Export(int fh)
14 // allow saving cvars that aesthetically change the panel into hud skin files
15 HUD_Write_Cvar("hud_panel_ammo_onlycurrent");
16 HUD_Write_Cvar("hud_panel_ammo_noncurrent_alpha");
17 HUD_Write_Cvar("hud_panel_ammo_noncurrent_scale");
18 HUD_Write_Cvar("hud_panel_ammo_iconalign");
19 HUD_Write_Cvar("hud_panel_ammo_progressbar");
20 HUD_Write_Cvar("hud_panel_ammo_progressbar_name");
21 HUD_Write_Cvar("hud_panel_ammo_progressbar_xoffset");
22 HUD_Write_Cvar("hud_panel_ammo_text");
25 void DrawNadeProgressBar(vector myPos, vector mySize, float progress, vector color)
27 HUD_Panel_DrawProgressBar(
28 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
29 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
30 autocvar_hud_panel_ammo_progressbar_name,
31 progress, 0, 0, color,
32 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
35 void DrawAmmoItem(vector myPos, vector mySize, Resource ammoType, bool isCurrent, bool isInfinite)
37 TC(bool, isCurrent); TC(bool, isInfinite);
38 if(ammoType == RES_NONE)
41 // Initialize variables
44 if(autocvar__hud_configure)
46 isCurrent = (ammoType == RES_ROCKETS); // Rockets always current
50 ammo = getstati(GetAmmoStat(ammoType));
54 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
55 myPos = myPos + (mySize - mySize * scale) * 0.5;
56 mySize = mySize * scale;
59 vector iconPos, textPos;
60 if(autocvar_hud_panel_ammo_iconalign)
62 iconPos = myPos + eX * 2 * mySize.y;
68 textPos = myPos + eX * mySize.y;
71 bool isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
73 vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
76 textColor = '0.2 0.95 0';
80 textColor = '0.8 0.04 0';
86 alpha = panel_fg_alpha;
88 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
90 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
92 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
97 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
99 if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
100 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);
102 if(autocvar_hud_panel_ammo_text)
103 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
105 drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
110 float nade_statuschange_time;
114 if(hud != HUD_NORMAL) return;
115 if(!autocvar__hud_configure)
117 if((!autocvar_hud_panel_ammo) || (spectatee_status == -1))
119 if(STAT(HEALTH) <= 0 && autocvar_hud_panel_ammo_hide_ondeath)
123 HUD_Panel_LoadCvars();
125 draw_beginBoldFont();
131 if (autocvar_hud_panel_ammo_dynamichud)
138 pos += '1 1 0' * panel_bg_padding;
139 mySize -= '2 2 0' * panel_bg_padding;
142 int rows = 0, columns, row, column;
143 float nade_cnt = STAT(NADE_BONUS), nade_score = STAT(NADE_BONUS_SCORE);
144 bool draw_nades = (nade_cnt > 0 || nade_score > 0);
145 float nade_statuschange_elapsedtime;
146 int total_ammo_count;
149 if (autocvar_hud_panel_ammo_onlycurrent)
150 total_ammo_count = 1;
152 total_ammo_count = AMMO_COUNT;
157 if (nade_cnt != nade_prevframe)
159 nade_statuschange_time = time;
160 nade_prevstatus = nade_prevframe;
161 nade_prevframe = nade_cnt;
165 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
167 rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
168 columns = ceil((total_ammo_count)/rows);
169 ammo_size = vec2(mySize.x / columns, mySize.y / rows);
171 vector offset = '0 0 0';
173 if(ammo_size.x/ammo_size.y > 3)
175 newSize = 3 * ammo_size.y;
176 offset.x = ammo_size.x - newSize;
178 ammo_size.x = newSize;
182 newSize = 1/3 * ammo_size.x;
183 offset.y = ammo_size.y - newSize;
185 ammo_size.y = newSize;
188 entity wepent = viewmodels[0]; // TODO: unhardcode
190 Weapon wep = wepent.switchweapon;
192 bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO);
194 if(autocvar_hud_panel_ammo_onlycurrent)
196 if(autocvar__hud_configure)
198 DrawAmmoItem(pos, ammo_size, RES_ROCKETS, true, false);
221 // disabling new-style loop for now to restore original order of ammo types
222 //FOREACH(Resources, it.instanceOfAmmoResource && !it.m_hidden,
223 for(int j = 0; j < AMMO_COUNT; ++j)
225 Resource ammotype = GetAmmoTypeFromNum(j);
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);