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