]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/ammo.qc
client: pass compilation units test
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / ammo.qc
1 #include "ammo.qh"
2
3 #include <common/t_items.qh>
4
5 // Ammo (#1)
6
7 void DrawNadeProgressBar(vector myPos, vector mySize, float progress, vector color)
8 {
9         HUD_Panel_DrawProgressBar(
10                 myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
11                 mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize.x,
12                 autocvar_hud_panel_ammo_progressbar_name,
13                 progress, 0, 0, color,
14                 autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
15 }
16
17 void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expand_time); // TODO: mutator
18
19 void DrawAmmoItem(vector myPos, vector mySize, .int ammoType, bool isCurrent, bool isInfinite)
20 {
21         if(ammoType == ammo_none)
22                 return;
23
24         // Initialize variables
25
26         int ammo;
27         if(autocvar__hud_configure)
28         {
29                 isCurrent = (ammoType == ammo_rockets); // Rockets always current
30                 ammo = 60;
31         }
32         else
33                 ammo = getstati(GetAmmoStat(ammoType));
34
35         if(!isCurrent)
36         {
37                 float scale = bound(0, autocvar_hud_panel_ammo_noncurrent_scale, 1);
38                 myPos = myPos + (mySize - mySize * scale) * 0.5;
39                 mySize = mySize * scale;
40         }
41
42         vector iconPos, textPos;
43         if(autocvar_hud_panel_ammo_iconalign)
44         {
45                 iconPos = myPos + eX * 2 * mySize.y;
46                 textPos = myPos;
47         }
48         else
49         {
50                 iconPos = myPos;
51                 textPos = myPos + eX * mySize.y;
52         }
53
54         bool isShadowed = (ammo <= 0 && !isCurrent && !isInfinite);
55
56         vector iconColor = isShadowed ? '0 0 0' : '1 1 1';
57         vector textColor;
58         if(isInfinite)
59                 textColor = '0.2 0.95 0';
60         else if(isShadowed)
61                 textColor = '0 0 0';
62         else if(ammo < 10)
63                 textColor = '0.8 0.04 0';
64         else
65                 textColor = '1 1 1';
66
67         float alpha;
68         if(isCurrent)
69                 alpha = panel_fg_alpha;
70         else if(isShadowed)
71                 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1) * 0.5;
72         else
73                 alpha = panel_fg_alpha * bound(0, autocvar_hud_panel_ammo_noncurrent_alpha, 1);
74
75         string text = isInfinite ? "\xE2\x88\x9E" : ftos(ammo); // Use infinity symbol (U+221E)
76
77         // Draw item
78
79         if(isCurrent)
80                 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
81
82         if(ammo > 0 && autocvar_hud_panel_ammo_progressbar)
83                 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);
84
85         if(autocvar_hud_panel_ammo_text)
86                 drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
87
88         drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
89 }
90
91 int nade_prevstatus;
92 int nade_prevframe;
93 float nade_statuschange_time;
94
95 void HUD_Ammo()
96 {
97         if(hud != HUD_NORMAL) return;
98         if(!autocvar__hud_configure)
99         {
100                 if(!autocvar_hud_panel_ammo) return;
101                 if(spectatee_status == -1) return;
102         }
103
104         HUD_Panel_UpdateCvars();
105
106         draw_beginBoldFont();
107
108         vector pos, mySize;
109         pos = panel_pos;
110         mySize = panel_size;
111
112         HUD_Panel_DrawBg(1);
113         if(panel_bg_padding)
114         {
115                 pos += '1 1 0' * panel_bg_padding;
116                 mySize -= '2 2 0' * panel_bg_padding;
117         }
118
119         int rows = 0, columns, row, column;
120         float nade_cnt = STAT(NADE_BONUS), nade_score = STAT(NADE_BONUS_SCORE);
121         bool draw_nades = (nade_cnt > 0 || nade_score > 0);
122         float nade_statuschange_elapsedtime;
123         int total_ammo_count;
124
125         vector ammo_size;
126         if (autocvar_hud_panel_ammo_onlycurrent)
127                 total_ammo_count = 1;
128         else
129                 total_ammo_count = AMMO_COUNT;
130
131         if(draw_nades)
132         {
133                 ++total_ammo_count;
134                 if (nade_cnt != nade_prevframe)
135                 {
136                         nade_statuschange_time = time;
137                         nade_prevstatus = nade_prevframe;
138                         nade_prevframe = nade_cnt;
139                 }
140         }
141         else
142                 nade_prevstatus = nade_prevframe = nade_statuschange_time = 0;
143
144         rows = HUD_GetRowCount(total_ammo_count, mySize, 3);
145         columns = ceil((total_ammo_count)/rows);
146         ammo_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
147
148         vector offset = '0 0 0';
149         float newSize;
150         if(ammo_size.x/ammo_size.y > 3)
151         {
152                 newSize = 3 * ammo_size.y;
153                 offset.x = ammo_size.x - newSize;
154                 pos.x += offset.x/2;
155                 ammo_size.x = newSize;
156         }
157         else
158         {
159                 newSize = 1/3 * ammo_size.x;
160                 offset.y = ammo_size.y - newSize;
161                 pos.y += offset.y/2;
162                 ammo_size.y = newSize;
163         }
164
165         Weapon wep = switchweapon;
166         int i;
167         bool infinite_ammo = (STAT(ITEMS) & IT_UNLIMITED_WEAPON_AMMO);
168         row = column = 0;
169         if(autocvar_hud_panel_ammo_onlycurrent)
170         {
171                 if(autocvar__hud_configure)
172                 {
173                         DrawAmmoItem(pos, ammo_size, ammo_rockets, true, false);
174                 }
175                 else
176                 {
177                         DrawAmmoItem(
178                                 pos,
179                                 ammo_size,
180                                 wep.ammo_field,
181                                 true,
182                                 infinite_ammo
183                         );
184                 }
185
186                 ++row;
187                 if(row >= rows)
188                 {
189                         row = 0;
190                         column = column + 1;
191                 }
192         }
193         else
194         {
195                 .int ammotype;
196                 row = column = 0;
197                 for(i = 0; i < AMMO_COUNT; ++i)
198                 {
199                         ammotype = GetAmmoFieldFromNum(i);
200                         DrawAmmoItem(
201                                 pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y),
202                                 ammo_size,
203                                 ammotype,
204                                 (wep.ammo_field == ammotype),
205                                 infinite_ammo
206                         );
207
208                         ++row;
209                         if(row >= rows)
210                         {
211                                 row = 0;
212                                 column = column + 1;
213                         }
214                 }
215         }
216
217         if (draw_nades)
218         {
219                 nade_statuschange_elapsedtime = time - nade_statuschange_time;
220
221                 float f = bound(0, nade_statuschange_elapsedtime*2, 1);
222
223                 DrawAmmoNades(pos + eX * column * (ammo_size.x + offset.x) + eY * row * (ammo_size.y + offset.y), ammo_size, nade_prevstatus < nade_cnt && nade_cnt != 0 && f < 1, f);
224         }
225
226         draw_endBoldFont();
227 }