]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/healtharmor.qc
Merge branch 'master' into terencehill/glowmod_color_fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / healtharmor.qc
1 #include "healtharmor.qh"
2
3 #include <client/draw.qh>
4 #include <common/deathtypes/all.qh>
5
6 // Health/armor (#3)
7
8 void HUD_HealthArmor_Export(int fh)
9 {
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");
21 }
22
23 void HUD_HealthArmor()
24 {
25         int armor, health, fuel, air_time;
26         if(!autocvar__hud_configure)
27         {
28                 if((!autocvar_hud_panel_healtharmor) || (spectatee_status == -1))
29                         return;
30                 if(hud != HUD_NORMAL) return;
31
32                 health = STAT(HEALTH);
33                 if(health <= 0)
34                 {
35                         health = 0;
36                         prev_health = -1;
37                         if(autocvar_hud_panel_healtharmor_hide_ondeath)
38                                 return;
39                 }
40                 armor = STAT(ARMOR);
41
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
44
45                 if (prev_p_health == -1)
46                 {
47                         // no effect
48                         health_beforedamage = 0;
49                         armor_beforedamage = 0;
50                         health_damagetime = 0;
51                         armor_damagetime = 0;
52                         prev_health = health;
53                         prev_armor = armor;
54                         old_p_health = health;
55                         old_p_armor = armor;
56                         prev_p_health = health;
57                         prev_p_armor = armor;
58                 }
59                 else if (prev_health == -1)
60                 {
61                         //start the load effect
62                         health_damagetime = 0;
63                         armor_damagetime = 0;
64                         prev_health = 0;
65                         prev_armor = 0;
66                 }
67                 fuel = STAT(FUEL);
68                 air_time = bound(0, STAT(AIR_FINISHED) - time, 10);
69         }
70         else
71         {
72                 health = 150;
73                 armor = 75;
74                 fuel = 20;
75                 air_time = 6;
76         }
77
78         HUD_Panel_LoadCvars();
79
80         draw_beginBoldFont();
81
82         vector pos, mySize;
83         pos = panel_pos;
84         mySize = panel_size;
85
86         if (autocvar_hud_panel_healtharmor_dynamichud)
87                 HUD_Scale_Enable();
88         else
89                 HUD_Scale_Disable();
90         HUD_Panel_DrawBg();
91         if(panel_bg_padding)
92         {
93                 pos += '1 1 0' * panel_bg_padding;
94                 mySize -= '2 2 0' * panel_bg_padding;
95         }
96
97         float air_alpha = 1;
98         if (STAT(AIR_FINISHED) && time > STAT(AIR_FINISHED))
99         {
100                 air_alpha = blink_synced(0.5, 0.5, 7, STAT(AIR_FINISHED), -1);
101                 air_time = 10;
102         }
103
104         int baralign = autocvar_hud_panel_healtharmor_baralign;
105         int iconalign = autocvar_hud_panel_healtharmor_iconalign;
106
107         int maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
108         int maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
109         if(autocvar_hud_panel_healtharmor_combined) // combined health and armor display
110         {
111                 vector v = healtharmor_maxdamage(health, armor, armorblockpercent, DEATH_WEAPON.m_id);
112                 float hp = floor(v.x + 1);
113
114                 float maxtotal = maxhealth + maxarmor;
115                 string biggercount;
116                 if(v.z) // NOT fully armored
117                 {
118                         biggercount = "health";
119                         if(autocvar_hud_panel_healtharmor_progressbar)
120                                 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);
121                         if(armor && autocvar_hud_panel_healtharmor_text)
122                                 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);
123                 }
124                 else
125                 {
126                         biggercount = "armor";
127                         if(autocvar_hud_panel_healtharmor_progressbar)
128                                 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);
129                         if(health && autocvar_hud_panel_healtharmor_text)
130                                 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);
131                 }
132                 if(autocvar_hud_panel_healtharmor_text)
133                         DrawNumIcon(pos, mySize, hp, biggercount, 0, iconalign, HUD_Get_Num_Color(hp, maxtotal, true), 1);
134
135                 if(fuel)
136                         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);
137                 if(air_time)
138                         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);
139         }
140         else
141         {
142                 float panel_ar = mySize.x/mySize.y;
143                 bool is_vertical = (panel_ar < 1);
144                 vector health_offset = '0 0 0', armor_offset = '0 0 0';
145                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
146                 {
147                         mySize.x *= 0.5;
148                         if (autocvar_hud_panel_healtharmor_flip)
149                                 health_offset.x = mySize.x;
150                         else
151                                 armor_offset.x = mySize.x;
152                 }
153                 else
154                 {
155                         mySize.y *= 0.5;
156                         if (autocvar_hud_panel_healtharmor_flip)
157                                 health_offset.y = mySize.y;
158                         else
159                                 armor_offset.y = mySize.y;
160                 }
161
162                 bool health_baralign, armor_baralign, fuel_baralign, air_align;
163                 bool health_iconalign, armor_iconalign;
164                 if (autocvar_hud_panel_healtharmor_flip)
165                 {
166                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
167                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
168                         air_align = fuel_baralign = health_baralign;
169                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
170                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
171                 }
172                 else
173                 {
174                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
175                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
176                         air_align = fuel_baralign = armor_baralign;
177                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
178                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
179                 }
180
181                 //if(health)
182                 {
183                         if(autocvar_hud_panel_healtharmor_progressbar)
184                         {
185                                 float p_health, pain_health_alpha;
186                                 p_health = health;
187                                 pain_health_alpha = 1;
188                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
189                                 {
190                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
191                                         {
192                                                 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
193                                                 {
194                                                         if (time - old_p_healthtime < 1)
195                                                                 old_p_health = prev_p_health;
196                                                         else
197                                                                 old_p_health = prev_health;
198                                                         old_p_healthtime = time;
199                                                 }
200                                                 if (time - old_p_healthtime < 1)
201                                                 {
202                                                         p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
203                                                         prev_p_health = p_health;
204                                                 }
205                                         }
206                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
207                                         {
208                                                 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
209                                                 {
210                                                         if (time - health_damagetime >= 1)
211                                                                 health_beforedamage = prev_health;
212                                                         health_damagetime = time;
213                                                 }
214                                                 if (time - health_damagetime < 1)
215                                                 {
216                                                         float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
217                                                         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);
218                                                 }
219                                         }
220                                         prev_health = health;
221
222                                         if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
223                                         {
224                                                 pain_health_alpha = blink(0.85, 0.15, 9);
225                                         }
226                                 }
227                                 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);
228                         }
229                         if(autocvar_hud_panel_healtharmor_text)
230                                 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth, true), 1);
231                 }
232
233                 //if(armor)
234                 {
235                         float p_armor = armor;
236                         if(autocvar_hud_panel_healtharmor_progressbar)
237                         {
238                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
239                                 {
240                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
241                                         {
242                                                 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
243                                                 {
244                                                         if (time - old_p_armortime < 1)
245                                                                 old_p_armor = prev_p_armor;
246                                                         else
247                                                                 old_p_armor = prev_armor;
248                                                         old_p_armortime = time;
249                                                 }
250                                                 if (time - old_p_armortime < 1)
251                                                 {
252                                                         p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
253                                                         prev_p_armor = p_armor;
254                                                 }
255                                         }
256                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
257                                         {
258                                                 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
259                                                 {
260                                                         if (time - armor_damagetime >= 1)
261                                                                 armor_beforedamage = prev_armor;
262                                                         armor_damagetime = time;
263                                                 }
264                                                 if (time - armor_damagetime < 1)
265                                                 {
266                                                         float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
267                                                         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);
268                                                 }
269                                         }
270                                         prev_armor = armor;
271                                 }
272                                 if(p_armor)
273                                         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);
274                         }
275                         if(!autocvar_hud_panel_healtharmor_progressbar || p_armor)
276                         if(autocvar_hud_panel_healtharmor_text)
277                                 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor, true), 1);
278                 }
279
280                 vector cell_size = mySize;
281                 if (fuel || air_time)
282                 {
283                         if (is_vertical)
284                                 mySize.x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
285                         else
286                                 mySize.y *= 0.2;
287                         if (panel_ar >= 4)
288                                 mySize.x *= 2; //restore full panel size
289                         else if (panel_ar < 1/4)
290                                 mySize.y *= 2; //restore full panel size
291                         if (fuel)
292                                 HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, autocvar_hud_progressbar_fuel_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
293                         if (air_time)
294                         {
295                                 if (panel_ar > 1 && panel_ar < 4)
296                                         pos.y += cell_size.y;
297                                 else if (panel_ar > 1/4 && panel_ar <= 1)
298                                         pos.x += cell_size.x;
299                                 if (is_vertical)
300                                         pos.x += cell_size.x - mySize.x;
301                                 else
302                                         pos.y += cell_size.y - mySize.y;
303                                 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);
304                         }
305                 }
306         }
307
308         draw_endBoldFont();
309 }