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/wepent.qh>
11 void HUD_Ammo_Export(int fh)
13 // allow saving cvars that aesthetically change the panel into hud skin files
14 HUD_Write_Cvar("hud_panel_ammo_onlycurrent");
15 HUD_Write_Cvar("hud_panel_ammo_noncurrent_alpha");
16 HUD_Write_Cvar("hud_panel_ammo_noncurrent_scale");
17 HUD_Write_Cvar("hud_panel_ammo_iconalign");
18 HUD_Write_Cvar("hud_panel_ammo_progressbar");
19 HUD_Write_Cvar("hud_panel_ammo_progressbar_name");
20 HUD_Write_Cvar("hud_panel_ammo_progressbar_xoffset");
21 HUD_Write_Cvar("hud_panel_ammo_text");
24 void DrawNadeProgressBar(vector myPos, vector mySize, float progress, vector color)
26 HUD_Panel_DrawProgressBar(
27 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
28 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
29 autocvar_hud_panel_ammo_progressbar_name,
30 progress, 0, 0, color,
31 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
34 void DrawAmmoItem(vector myPos, vector mySize, int ammoType, bool isCurrent, bool isInfinite)
36 TC(bool, isCurrent); TC(bool, isInfinite);
37 if(ammoType == RES_NONE)
40 // Initialize variables
43 if(autocvar__hud_configure)
45 isCurrent = (ammoType == RES_ROCKETS); // Rockets always current
49 ammo = getstati(GetAmmoStat(ammoType));
53 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
54 myPos = myPos + (mySize - mySize * scale) * 0.5;
55 mySize = mySize * scale;
58 vector iconPos, textPos;
59 if(autocvar_hud_panel_ammo_iconalign)
61 iconPos = myPos + eX * 2 * mySize.y;
67 textPos = myPos + eX * mySize.y;
70 bool isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
72 vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
75 textColor = '0.2 0.95 0';
79 textColor = '0.8 0.04 0';
85 alpha = panel_fg_alpha;
87 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
89 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
91 string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
96 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
98 if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
99 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);
101 if(autocvar_hud_panel_ammo_text)
102 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
104 drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
109 float nade_statuschange_time;
113 if(hud != HUD_NORMAL) return;
114 if(!autocvar__hud_configure)
116 if((!autocvar_hud_panel_ammo) || (spectatee_status == -1))
118 if(STAT(HEALTH) <= 0 && autocvar_hud_panel_ammo_hide_ondeath)
122 HUD_Panel_LoadCvars();
124 draw_beginBoldFont();
130 if (autocvar_hud_panel_ammo_dynamichud)
137 pos += '1 1 0' * panel_bg_padding;
138 mySize -= '2 2 0' * panel_bg_padding;
141 int rows = 0, columns, row, column;
142 float nade_cnt = STAT(NADE_BONUS), nade_score = STAT(NADE_BONUS_SCORE);
143 bool draw_nades = (nade_cnt > 0 || nade_score > 0);
144 float nade_statuschange_elapsedtime;
145 int total_ammo_count;
148 if (autocvar_hud_panel_ammo_onlycurrent)
149 total_ammo_count = 1;
151 total_ammo_count = AMMO_COUNT;
156 if (nade_cnt != nade_prevframe)
158 nade_statuschange_time = time;
159 nade_prevstatus = nade_prevframe;
160 nade_prevframe = nade_cnt;
164 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
166 rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
167 columns = ceil((total_ammo_count)/rows);
168 ammo_size = vec2(mySize.x / columns, mySize.y / rows);
170 vector offset = '0 0 0';
172 if(ammo_size.x/ammo_size.y > 3)
174 newSize = 3 * ammo_size.y;
175 offset.x = ammo_size.x - newSize;
177 ammo_size.x = newSize;
181 newSize = 1/3 * ammo_size.x;
182 offset.y = ammo_size.y - newSize;
184 ammo_size.y = newSize;
187 entity wepent = viewmodels[0]; // TODO: unhardcode
189 Weapon wep = wepent.switchweapon;
191 bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_AMMO);
193 if(autocvar_hud_panel_ammo_onlycurrent)
195 if(autocvar__hud_configure)
197 DrawAmmoItem(pos, ammo_size, RES_ROCKETS, true, false);
221 for(i = 0; i < AMMO_COUNT; ++i)
223 ammotype = GetAmmoTypeFromNum(i);
225 pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)),
228 (wep.ammo_type == ammotype),
243 nade_statuschange_elapsedtime = time - nade_statuschange_time;
245 float f = bound(0, nade_statuschange_elapsedtime*2, 1);
247 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);