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