1 #include "healtharmor.qh"
3 #include <client/draw.qh>
4 #include <common/deathtypes/all.qh>
8 void HUD_HealthArmor_Export(int fh)
10 // allow saving cvars that aesthetically change the panel into hud skin files
11 HUD_Write_Cvar("hud_panel_healtharmor_combined");
12 HUD_Write_Cvar("hud_panel_healtharmor_flip");
13 HUD_Write_Cvar("hud_panel_healtharmor_iconalign");
14 HUD_Write_Cvar("hud_panel_healtharmor_baralign");
15 HUD_Write_Cvar("hud_panel_healtharmor_progressbar");
16 HUD_Write_Cvar("hud_panel_healtharmor_progressbar_health");
17 HUD_Write_Cvar("hud_panel_healtharmor_progressbar_armor");
18 HUD_Write_Cvar("hud_panel_healtharmor_progressbar_gfx");
19 HUD_Write_Cvar("hud_panel_healtharmor_progressbar_gfx_smooth");
20 HUD_Write_Cvar("hud_panel_healtharmor_text");
23 void HUD_HealthArmor()
25 int armor, health, fuel, air_time;
26 if(!autocvar__hud_configure)
28 if((!autocvar_hud_panel_healtharmor) || (spectatee_status == -1))
30 if(hud != HUD_NORMAL) return;
32 health = STAT(HEALTH);
37 if(autocvar_hud_panel_healtharmor_hide_ondeath)
42 // code to check for spectatee_status changes is in ENT_CLIENT_CLIENTDATA
43 // prev_p_health and prev_health can be set to -1 there
45 if (prev_p_health == -1)
48 health_beforedamage = 0;
49 armor_beforedamage = 0;
50 health_damagetime = 0;
54 old_p_health = health;
56 prev_p_health = health;
59 else if (prev_health == -1)
61 //start the load effect
62 health_damagetime = 0;
68 air_time = bound(0, STAT(AIR_FINISHED) - time, 10);
78 HUD_Panel_LoadCvars();
86 if (autocvar_hud_panel_healtharmor_dynamichud)
93 pos += '1 1 0' * panel_bg_padding;
94 mySize -= '2 2 0' * panel_bg_padding;
98 if (!STAT(AIR_FINISHED))
100 else if (time > STAT(AIR_FINISHED))
102 air_alpha = blink_synced(0.5, 0.5, 7, STAT(AIR_FINISHED), -1);
107 float fade_time = 10 / 2;
108 float start_alpha = autocvar_hud_panel_healtharmor_oxygenbar_startalpha;
109 float f = (STAT(AIR_FINISHED) - time - fade_time) / fade_time;
110 air_alpha = bound(0, start_alpha + (1 - start_alpha) * (1 - f), 1);
118 float start_alpha = autocvar_hud_panel_healtharmor_fuelbar_startalpha;
119 float f = (100 - fuel) / 50;
120 fuel_alpha = bound(0, start_alpha + (1 - start_alpha) * f, 1);
123 int baralign = autocvar_hud_panel_healtharmor_baralign;
124 int iconalign = autocvar_hud_panel_healtharmor_iconalign;
126 int maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
127 int maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
128 if(autocvar_hud_panel_healtharmor_combined) // combined health and armor display
130 vector v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON.m_id);
131 float hp = floor(v.x + 1);
133 float maxtotal = maxhealth + maxarmor;
135 if(v.z) // NOT fully armored
137 biggercount = "health";
138 if(autocvar_hud_panel_healtharmor_progressbar)
139 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, hp/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
140 if(armor && autocvar_hud_panel_healtharmor_text)
141 drawpic_aspect_skin(pos + eX * mySize.x - eX * 0.5 * mySize.y, "armor", '0.5 0.5 0' * mySize.y, '1 1 1', panel_fg_alpha * armor / health, DRAWFLAG_NORMAL);
145 biggercount = "armor";
146 if(autocvar_hud_panel_healtharmor_progressbar)
147 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, hp/maxtotal, 0, (baralign == 1 || baralign == 2), autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
148 if(health && autocvar_hud_panel_healtharmor_text)
149 drawpic_aspect_skin(pos + eX * mySize.x - eX * 0.5 * mySize.y, "health", '0.5 0.5 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
151 if(autocvar_hud_panel_healtharmor_text)
152 DrawNumIcon(pos, mySize, hp, biggercount, false, false, iconalign, HUD_Get_Num_Color(hp, maxtotal, true), 1);
155 HUD_Panel_DrawProgressBar(pos, vec2(mySize.x, 0.2 * mySize.y), "progressbar", fuel / 100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, fuel_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
157 HUD_Panel_DrawProgressBar(pos + eY * 0.8 * mySize.y, vec2(mySize.x, 0.2 * mySize.y), "progressbar", air_time / 10, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_oxygen_color, air_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
161 float panel_ar = mySize.x/mySize.y;
162 bool is_vertical = (panel_ar < 1);
163 vector health_offset = '0 0 0', armor_offset = '0 0 0';
164 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
167 if (autocvar_hud_panel_healtharmor_flip)
168 health_offset.x = mySize.x;
170 armor_offset.x = mySize.x;
175 if (autocvar_hud_panel_healtharmor_flip)
176 health_offset.y = mySize.y;
178 armor_offset.y = mySize.y;
181 bool health_baralign, armor_baralign, fuel_baralign, air_align;
182 bool health_iconalign, armor_iconalign;
183 if (autocvar_hud_panel_healtharmor_flip)
185 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
186 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
187 air_align = fuel_baralign = health_baralign;
188 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
189 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
193 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
194 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
195 air_align = fuel_baralign = armor_baralign;
196 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
197 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
202 if(autocvar_hud_panel_healtharmor_progressbar)
204 float p_health, pain_health_alpha;
206 pain_health_alpha = 1;
207 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
209 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
211 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
213 if (time - old_p_healthtime < 1)
214 old_p_health = prev_p_health;
216 old_p_health = prev_health;
217 old_p_healthtime = time;
219 if (time - old_p_healthtime < 1)
221 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
222 prev_p_health = p_health;
225 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
227 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
229 if (time - health_damagetime >= 1)
230 health_beforedamage = prev_health;
231 health_damagetime = time;
233 if (time - health_damagetime < 1)
235 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
236 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL);
239 prev_health = health;
241 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
243 pain_health_alpha = blink(0.85, 0.15, 9);
246 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, autocvar_hud_progressbar_health_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL);
248 if(autocvar_hud_panel_healtharmor_text)
249 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, false, health_iconalign, HUD_Get_Num_Color(health, maxhealth, true), 1);
254 float p_armor = armor;
255 if(autocvar_hud_panel_healtharmor_progressbar)
257 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
259 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
261 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
263 if (time - old_p_armortime < 1)
264 old_p_armor = prev_p_armor;
266 old_p_armor = prev_armor;
267 old_p_armortime = time;
269 if (time - old_p_armortime < 1)
271 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
272 prev_p_armor = p_armor;
275 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
277 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
279 if (time - armor_damagetime >= 1)
280 armor_beforedamage = prev_armor;
281 armor_damagetime = time;
283 if (time - armor_damagetime < 1)
285 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
286 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL);
292 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, autocvar_hud_progressbar_armor_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
294 if(!autocvar_hud_panel_healtharmor_progressbar || p_armor)
295 if(autocvar_hud_panel_healtharmor_text)
296 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, false, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor, true), 1);
299 vector cell_size = mySize;
300 if (fuel || air_time)
303 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
307 mySize.x *= 2; //restore full panel size
308 else if (panel_ar < 1/4)
309 mySize.y *= 2; //restore full panel size
311 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel / 100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, fuel_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
314 if (panel_ar > 1 && panel_ar < 4)
315 pos.y += cell_size.y;
316 else if (panel_ar > 1/4 && panel_ar <= 1)
317 pos.x += cell_size.x;
319 pos.x += cell_size.x - mySize.x;
321 pos.y += cell_size.y - mySize.y;
322 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", air_time / 10, is_vertical, air_align, autocvar_hud_progressbar_oxygen_color, air_alpha * panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);