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