1 #include "healtharmor.qh"
3 #include <client/defs.qh>
4 #include <client/miscfunctions.qh>
6 #include <common/deathtypes/all.qh>
10 void HUD_HealthArmor_Export(int fh)
12 // allow saving cvars that aesthetically change the panel into hud skin files
13 HUD_Write_Cvar("hud_panel_healtharmor_combined");
14 HUD_Write_Cvar("hud_panel_healtharmor_flip");
15 HUD_Write_Cvar("hud_panel_healtharmor_iconalign");
16 HUD_Write_Cvar("hud_panel_healtharmor_baralign");
17 HUD_Write_Cvar("hud_panel_healtharmor_progressbar");
18 HUD_Write_Cvar("hud_panel_healtharmor_progressbar_health");
19 HUD_Write_Cvar("hud_panel_healtharmor_progressbar_armor");
20 HUD_Write_Cvar("hud_panel_healtharmor_progressbar_gfx");
21 HUD_Write_Cvar("hud_panel_healtharmor_progressbar_gfx_smooth");
22 HUD_Write_Cvar("hud_panel_healtharmor_text");
25 void HUD_HealthArmor()
27 int armor, health, fuel, air_time;
28 if(!autocvar__hud_configure)
30 if((!autocvar_hud_panel_healtharmor) || (spectatee_status == -1))
32 if(hud != HUD_NORMAL) return;
34 health = STAT(HEALTH);
39 if(autocvar_hud_panel_healtharmor_hide_ondeath)
44 // code to check for spectatee_status changes is in ENT_CLIENT_CLIENTDATA
45 // prev_p_health and prev_health can be set to -1 there
47 if (prev_p_health == -1)
50 health_beforedamage = 0;
51 armor_beforedamage = 0;
52 health_damagetime = 0;
56 old_p_health = health;
58 prev_p_health = health;
61 else if (prev_health == -1)
63 //start the load effect
64 health_damagetime = 0;
70 air_time = bound(0, STAT(AIR_FINISHED) - time, 10);
80 HUD_Panel_LoadCvars();
88 if (autocvar_hud_panel_healtharmor_dynamichud)
95 pos += '1 1 0' * panel_bg_padding;
96 mySize -= '2 2 0' * panel_bg_padding;
100 if (STAT(AIR_FINISHED) && time > STAT(AIR_FINISHED))
102 air_alpha = blink_synced(0.5, 0.5, 7, STAT(AIR_FINISHED), -1);
106 int baralign = autocvar_hud_panel_healtharmor_baralign;
107 int iconalign = autocvar_hud_panel_healtharmor_iconalign;
109 int maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
110 int maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
111 if(autocvar_hud_panel_healtharmor_combined) // combined health and armor display
113 vector v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON.m_id);
114 float hp = floor(v.x + 1);
116 float maxtotal = maxhealth + maxarmor;
118 if(v.z) // NOT fully armored
120 biggercount = "health";
121 if(autocvar_hud_panel_healtharmor_progressbar)
122 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);
123 if(armor && autocvar_hud_panel_healtharmor_text)
124 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);
128 biggercount = "armor";
129 if(autocvar_hud_panel_healtharmor_progressbar)
130 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);
131 if(health && autocvar_hud_panel_healtharmor_text)
132 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);
134 if(autocvar_hud_panel_healtharmor_text)
135 DrawNumIcon(pos, mySize, hp, biggercount, 0, iconalign, HUD_Get_Num_Color(hp, maxtotal, true), 1);
138 HUD_Panel_DrawProgressBar(pos, vec2(mySize.x, 0.2 * mySize.y), "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
140 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);
144 float panel_ar = mySize.x/mySize.y;
145 bool is_vertical = (panel_ar < 1);
146 vector health_offset = '0 0 0', armor_offset = '0 0 0';
147 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
150 if (autocvar_hud_panel_healtharmor_flip)
151 health_offset.x = mySize.x;
153 armor_offset.x = mySize.x;
158 if (autocvar_hud_panel_healtharmor_flip)
159 health_offset.y = mySize.y;
161 armor_offset.y = mySize.y;
164 bool health_baralign, armor_baralign, fuel_baralign, air_align;
165 bool health_iconalign, armor_iconalign;
166 if (autocvar_hud_panel_healtharmor_flip)
168 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
169 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
170 air_align = fuel_baralign = health_baralign;
171 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
172 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
176 health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
177 armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
178 air_align = fuel_baralign = armor_baralign;
179 health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
180 armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
185 if(autocvar_hud_panel_healtharmor_progressbar)
187 float p_health, pain_health_alpha;
189 pain_health_alpha = 1;
190 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
192 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
194 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
196 if (time - old_p_healthtime < 1)
197 old_p_health = prev_p_health;
199 old_p_health = prev_health;
200 old_p_healthtime = time;
202 if (time - old_p_healthtime < 1)
204 p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
205 prev_p_health = p_health;
208 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
210 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
212 if (time - health_damagetime >= 1)
213 health_beforedamage = prev_health;
214 health_damagetime = time;
216 if (time - health_damagetime < 1)
218 float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
219 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);
222 prev_health = health;
224 if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
226 pain_health_alpha = blink(0.85, 0.15, 9);
229 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);
231 if(autocvar_hud_panel_healtharmor_text)
232 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth, true), 1);
237 float p_armor = armor;
238 if(autocvar_hud_panel_healtharmor_progressbar)
240 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
242 if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
244 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
246 if (time - old_p_armortime < 1)
247 old_p_armor = prev_p_armor;
249 old_p_armor = prev_armor;
250 old_p_armortime = time;
252 if (time - old_p_armortime < 1)
254 p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
255 prev_p_armor = p_armor;
258 if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
260 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
262 if (time - armor_damagetime >= 1)
263 armor_beforedamage = prev_armor;
264 armor_damagetime = time;
266 if (time - armor_damagetime < 1)
268 float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
269 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);
275 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);
277 if(!autocvar_hud_panel_healtharmor_progressbar || p_armor)
278 if(autocvar_hud_panel_healtharmor_text)
279 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor, true), 1);
282 vector cell_size = mySize;
283 if (fuel || air_time)
286 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
290 mySize.x *= 2; //restore full panel size
291 else if (panel_ar < 1/4)
292 mySize.y *= 2; //restore full panel size
294 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
297 if (panel_ar > 1 && panel_ar < 4)
298 pos.y += cell_size.y;
299 else if (panel_ar > 1/4 && panel_ar <= 1)
300 pos.x += cell_size.x;
302 pos.x += cell_size.x - mySize.x;
304 pos.y += cell_size.y - mySize.y;
305 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);