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