]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
Access directly these autocvars
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index f64f38492b70c484487ea92511e95f56b46e48f5..8f690bb18adfcd3132832dae5f854393eac4a6ba 100644 (file)
@@ -773,7 +773,6 @@ void HUD_Weapons(void)
        }
 
        float weapons_st = getstati(STAT_WEAPONS);
-       float label = autocvar_hud_panel_weapons_label;
 
        for(i = 0; i < weapon_cnt; ++i)
        {
@@ -813,9 +812,9 @@ void HUD_Weapons(void)
                {
                        drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
 
-                       if(label == 1) // weapon number
+                       if(autocvar_hud_panel_weapons_label == 1) // weapon number
                                drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-                       else if(label == 2) // bind
+                       else if(autocvar_hud_panel_weapons_label == 2) // bind
                                drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
 
                        // draw ammo status bar
@@ -1190,117 +1189,86 @@ void HUD_Powerups(void)
                mySize -= '2 2 0' * panel_bg_padding;
        }
 
-       vector barsize;
-       vector picpos;
-       vector numpos;
-
-       string leftname, rightname;
-    string leftprogressname, rightprogressname;
-       float leftcnt, rightcnt;
-       float leftexact, rightexact;
-       if (autocvar_hud_panel_powerups_flip) {
-               leftname = "strength";
-        leftprogressname = autocvar_hud_panel_powerups_progressbar_strength;
-               leftcnt = ceil(strength_time);
-               leftexact = strength_time;
-
-               rightname = "shield";
-        rightprogressname = autocvar_hud_panel_powerups_progressbar_shield;
-               rightcnt = ceil(shield_time);
-               rightexact = shield_time;
-       } else {
-               leftname = "shield";
-        leftprogressname = autocvar_hud_panel_powerups_progressbar_shield;
-               leftcnt = ceil(shield_time);
-               leftexact = shield_time;
-
-               rightname = "strength";
-        rightprogressname = autocvar_hud_panel_powerups_progressbar_strength;
-               rightcnt = ceil(strength_time);
-               rightexact = strength_time;
-       }
-
-       float baralign = autocvar_hud_panel_powerups_baralign;
-       float iconalign = autocvar_hud_panel_powerups_iconalign;
-
        float panel_ar = mySize_x/mySize_y;
        float is_vertical = (panel_ar < 1);
+       vector shield_offset, strength_offset;
        if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
        {
-        barsize = eX * 0.5 * mySize_x + eY * mySize_y;
-               if(leftcnt)
+               mySize_x *= 0.5;
+               if (autocvar_hud_panel_powerups_flip)
+                       shield_offset_x = mySize_x;
+               else
+                       strength_offset_x = mySize_x;
+       }
+       else
+       {
+               mySize_y *= 0.5;
+               if (autocvar_hud_panel_powerups_flip)
+                       shield_offset_y = mySize_y;
+               else
+                       strength_offset_y = mySize_y;
+       }
+
+       float shield_baralign, strength_baralign;
+       float shield_iconalign, strength_iconalign;
+       if (autocvar_hud_panel_powerups_flip)
+       {
+               strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
+               shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
+               strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
+               shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
+       }
+       else
+       {
+               shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
+               strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
+               shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
+               strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
+       }
+
+       if(shield_time)
+       {
+               const float maxshield = 30;
+               float shield = ceil(shield_time);
+               if(autocvar_hud_panel_powerups_progressbar)
                {
-                       if(autocvar_hud_panel_powerups_progressbar)
-                       {
-                               HUD_Panel_GetProgressBarColorForString(leftname);
-                               HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, leftcnt/30, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
-                       }
-            if(autocvar_hud_panel_powerups_text)
-            {
-                               if(leftcnt > 1)
-                                       DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
-                               if(leftcnt <= 5)
-                                       DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
-                       }
+                       HUD_Panel_GetProgressBarColor(shield);
+                       HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                }
-
-               if(rightcnt)
+               if(autocvar_hud_panel_powerups_text)
                {
-                       pos_x += barsize_x;
-                       if(autocvar_hud_panel_powerups_progressbar)
-                       {
-                               HUD_Panel_GetProgressBarColorForString(rightname);
-                               HUD_Panel_DrawProgressBar(pos, barsize, rightprogressname, rightcnt/30, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
-                       }
-            if(autocvar_hud_panel_powerups_text)
-            {
-                               if(rightcnt > 1)
-                                       DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
-                               if(rightcnt <= 5)
-                                       DrawNumIcon_expanding(pos, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
-                       }
+                       if(shield > 1)
+                               DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
+                       if(shield <= 5)
+                               DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', bound(0, (shield - shield_time) / 0.5, 1));
                }
        }
-       else
+
+       if(strength_time)
        {
-        barsize = eX * mySize_x + eY * 0.5 * mySize_y;
-               if(leftcnt)
+               const float maxstrength = 30;
+               float strength = ceil(strength_time);
+               if(autocvar_hud_panel_powerups_progressbar)
                {
-                       if(autocvar_hud_panel_powerups_progressbar)
-                       {
-                               HUD_Panel_GetProgressBarColorForString(leftname);
-                               HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, leftcnt/30, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
-                       }
-            if(autocvar_hud_panel_powerups_text)
-            {
-                               if(leftcnt > 1)
-                                       DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
-                               if(leftcnt <= 5)
-                                       DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
-                       }
+                       HUD_Panel_GetProgressBarColor(strength);
+                       HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                }
-
-               if(rightcnt)
+               if(autocvar_hud_panel_powerups_text)
                {
-                       pos_y += barsize_y;
-                       if(autocvar_hud_panel_powerups_progressbar)
-                       {
-                               HUD_Panel_GetProgressBarColorForString(rightname);
-                               HUD_Panel_DrawProgressBar(pos, barsize, rightprogressname, rightcnt/30, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
-                       }
-            if(autocvar_hud_panel_powerups_text)
-            {
-                               if(rightcnt > 1)
-                                       DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
-                               if(rightcnt <= 5)
-                                       DrawNumIcon_expanding(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
-                       }
+                       if(strength > 1)
+                               DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
+                       if(strength <= 5)
+                               DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', bound(0, (strength - strength_time) / 0.5, 1));
                }
        }
 }
 
 // Health/armor (#3)
 //
+float health_time, prev_health;
+float armor_time, prev_armor;
+var float saved_health = -2;
+var float saved_armor = -2;
 void HUD_HealthArmor(void)
 {
        float armor, health, fuel;
@@ -1311,7 +1279,36 @@ void HUD_HealthArmor(void)
 
                health = getstati(STAT_HEALTH);
                if(health <= 0)
+               {
+                       health_time = -1;
                        return;
+               }
+               if (autocvar_hud_panel_healtharmor_progressbar_gfx)
+               {
+                       if ( (prev_spectatee_status == -1 && spectatee_status > 0) //before observing, now spectating
+                         || (prev_spectatee_status > 0 && spectatee_status > 0 && prev_spectatee_status != spectatee_status) //changed spectated player
+                       )
+                       {
+                               //no effect
+                               saved_health = 0;
+                               saved_armor = 0;
+                               health_time = 0;
+                               armor_time = 0;
+                       }
+                       else if(prev_spectatee_status == -1 || (prev_spectatee_status > 0 && !spectatee_status)) //before spectating/observing, now playing
+                               health_time = -1;
+
+                       if (health_time == -1)
+                       {
+                               //start the load effect
+                               saved_health = -2;
+                               saved_armor = -2;
+                               health_time = time;
+                               armor_time = time;
+                               prev_health = 0;
+                               prev_armor = 0;
+                       }
+               }
                armor = getstati(STAT_ARMOR);
                fuel = getstati(STAT_FUEL);
        }
@@ -1430,7 +1427,38 @@ void HUD_HealthArmor(void)
                        if(autocvar_hud_panel_healtharmor_progressbar)
                        {
                                HUD_Panel_GetProgressBarColor(health);
-                               HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                               float p_health;
+                               p_health = health;
+                               if (autocvar_hud_panel_healtharmor_progressbar_gfx)
+                               {
+                                       if (saved_health == -1)
+                                       {
+                                               if (prev_health == 0 || prev_health - health >= 3)
+                                               {
+                                                       health_time = time;
+                                                       saved_health = prev_health;
+                                               }
+                                       }
+                                       if (saved_health != -1)
+                                       {
+                                               float d = time - health_time;
+                                               if (d < 1)
+                                               {
+                                                       if (saved_health == -2)
+                                                               p_health *= sqrt(d);
+                                                       else
+                                                       {
+                                                               HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, saved_health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
+                                                               if (prev_health - health >= 1) //refresh the effect if repeatedly damaged
+                                                                       health_time = time;
+                                                       }
+                                               }
+                                               else
+                                                       saved_health = -1; //damage effect ended
+                                       }
+                                       prev_health = health;
+                               }
+                               HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                        }
                        if(autocvar_hud_panel_healtharmor_text)
                                DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
@@ -1441,7 +1469,38 @@ void HUD_HealthArmor(void)
                        if(autocvar_hud_panel_healtharmor_progressbar)
                        {
                                HUD_Panel_GetProgressBarColor(armor);
-                               HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                               float p_armor;
+                               p_armor = armor;
+                               if (autocvar_hud_panel_healtharmor_progressbar_gfx)
+                               {
+                                       if (saved_armor == -1)
+                                       {
+                                               if (prev_armor == 0 || prev_armor - armor >= 3)
+                                               {
+                                                       armor_time = time;
+                                                       saved_armor = prev_armor;
+                                               }
+                                       }
+                                       if (saved_armor != -1)
+                                       {
+                                               float d = time - armor_time;
+                                               if (d < 1)
+                                               {
+                                                       if (saved_armor == -2)
+                                                               p_armor *= sqrt(d);
+                                                       else
+                                                       {
+                                                               HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, saved_armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
+                                                               if (prev_armor - armor >= 1) //refresh the effect if repeatedly damaged
+                                                                       armor_time = time;
+                                                       }
+                                               }
+                                               else
+                                                       saved_armor = -1; //damage effect ended
+                                       }
+                                       prev_armor = armor;
+                               }
+                               HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                        }
                        if(autocvar_hud_panel_healtharmor_text)
                                DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
@@ -4110,7 +4169,7 @@ void HUD_Physics(void)
        if(!autocvar__hud_configure)
        {
                if(!autocvar_hud_panel_physics) return;
-               if(spectatee_status <= 0 && autocvar_hud_panel_physics < 2) return;
+               if(spectatee_status == -1 && autocvar_hud_panel_physics < 2) return;
        }
        else
                hud_configure_active_panel = HUD_PANEL_PHYSICS;