]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
Merge remote-tracking branch 'origin/master' into fruitiex/panelhud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index 9d997e0eb33c13482a6c3611874d8ebecb301277..c224fcd7ccb386855fe0e96bc35d350bf41d5ce8 100644 (file)
@@ -1302,20 +1302,13 @@ void HUD_Powerups(void)
 //
 
 // prev_* vars contain the health/armor at the previous FRAME
-float prev_health, prev_armor;
-
-// *_damagetime vars contain time at which damage happened
 // set to -1 when player is dead or was not playing
+float prev_health, prev_armor;
 float health_damagetime, armor_damagetime;
-
-// *_beforedamage vars contain the old health/armor value (before the damage happened)
-// set to -1 when load or damage effect are ended normally
 float health_beforedamage, armor_beforedamage;
-
 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
 float old_p_health, old_p_armor;
 float old_p_healthtime, old_p_armortime;
-
 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
 float prev_p_health, prev_p_armor;
@@ -1331,13 +1324,13 @@ void HUD_HealthArmor(void)
                health = getstati(STAT_HEALTH);
                if(health <= 0)
                {
-                       health_damagetime = -1;
+                       prev_health = -1;
                        return;
                }
                armor = getstati(STAT_ARMOR);
 
                // code to check for spectatee_status changes is in Ent_ClientData()
-               // prev_p_health and health_damagetime can be set to -1 there
+               // prev_p_health and prev_health can be set to -1 there
 
                if (prev_p_health == -1)
                {
@@ -1353,11 +1346,11 @@ void HUD_HealthArmor(void)
                        prev_p_health = health;
                        prev_p_armor = armor;
                }
-               else if (health_damagetime == -1)
+               else if (prev_health == -1)
                {
                        //start the load effect
-                       health_damagetime = time;
-                       armor_damagetime = time;
+                       health_damagetime = 0;
+                       armor_damagetime = 0;
                        prev_health = 0;
                        prev_armor = 0;
                }
@@ -1483,42 +1476,39 @@ void HUD_HealthArmor(void)
                                pain_health_alpha = 1;
                                if (autocvar_hud_panel_healtharmor_progressbar_gfx)
                                {
-                                       if (fabs(prev_health - health) >= 2)
+                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
                                        {
+                                               if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
+                                               {
+                                                       if (time - old_p_healthtime < 1)
+                                                               old_p_health = prev_p_health;
+                                                       else
+                                                               old_p_health = prev_health;
+                                                       old_p_healthtime = time;
+                                               }
                                                if (time - old_p_healthtime < 1)
-                                                       old_p_health = prev_p_health;
-                                               else
-                                                       old_p_health = prev_health;
-                                               old_p_healthtime = time;
-                                       }
-                                       if (time - old_p_healthtime < 1)
-                                       {
-                                               p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
-                                               prev_p_health = p_health;
+                                               {
+                                                       p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
+                                                       prev_p_health = p_health;
+                                               }
                                        }
-                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0 && health_beforedamage == -1)
+                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
                                        {
-                                               if (prev_health == 0 || prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
+                                               if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
                                                {
+                                                       if (time - health_damagetime >= 1)
+                                                               health_beforedamage = prev_health;
                                                        health_damagetime = time;
-                                                       health_beforedamage = prev_health;
                                                }
-                                       }
-                                       if (health_beforedamage != -1)
-                                       {
-                                               float d = time - health_damagetime;
-                                               if (d < 1)
+                                               if (time - health_damagetime < 1)
                                                {
-                                                       HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
-                                                       if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage) //refresh the effect if repeatedly damaged
-                                                               health_damagetime = time;
+                                                       float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
+                                                       HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL);
                                                }
-                                               else
-                                                       health_beforedamage = -1; //damage effect ended
                                        }
                                        prev_health = health;
 
-                                       if (health <= 40)
+                                       if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
                                        {
                                                float BLINK_FACTOR = 0.15;
                                                float BLINK_BASE = 0.85;
@@ -1541,38 +1531,35 @@ void HUD_HealthArmor(void)
                                p_armor = armor;
                                if (autocvar_hud_panel_healtharmor_progressbar_gfx)
                                {
-                                       if (fabs(prev_armor - armor) >= 2)
+                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
                                        {
+                                               if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
+                                               {
+                                                       if (time - old_p_armortime < 1)
+                                                               old_p_armor = prev_p_armor;
+                                                       else
+                                                               old_p_armor = prev_armor;
+                                                       old_p_armortime = time;
+                                               }
                                                if (time - old_p_armortime < 1)
-                                                       old_p_armor = prev_p_armor;
-                                               else
-                                                       old_p_armor = prev_armor;
-                                               old_p_armortime = time;
-                                       }
-                                       if (time - old_p_armortime < 1)
-                                       {
-                                               p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
-                                               prev_p_armor = p_armor;
+                                               {
+                                                       p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
+                                                       prev_p_armor = p_armor;
+                                               }
                                        }
-                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0 && armor_beforedamage == -1)
+                                       if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
                                        {
-                                               if (prev_armor == 0 || prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
+                                               if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
                                                {
+                                                       if (time - armor_damagetime >= 1)
+                                                               armor_beforedamage = prev_armor;
                                                        armor_damagetime = time;
-                                                       armor_beforedamage = prev_armor;
                                                }
-                                       }
-                                       if (armor_beforedamage != -1)
-                                       {
-                                               float d = time - armor_damagetime;
-                                               if (d < 1)
+                                               if (time - armor_damagetime < 1)
                                                {
-                                                       HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
-                                                       if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage) //refresh the effect if repeatedly damaged
-                                                               armor_damagetime = time;
+                                                       float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
+                                                       HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL);
                                                }
-                                               else
-                                                       armor_beforedamage = -1; //damage effect ended
                                        }
                                        prev_armor = armor;
                                }
@@ -1863,7 +1850,7 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s
                                print (sprintf(_("%s^7 is a ^1BERSERKER!\n"), s1));
                } else if(type == KILL_SPREE_25) {
                        if(gentle)
-                               print (sprintf(_("%s^7 made ^1TWENTY FIFE SCORES IN A ROW!\n"), s1));
+                               print (sprintf(_("%s^7 made ^1TWENTY FIVE SCORES IN A ROW!\n"), s1));
                        else
                                print (sprintf(_("%s^7 inflicts ^1CARNAGE!\n"), s1));
                } else if(type == KILL_SPREE_30) {
@@ -2592,6 +2579,126 @@ void HUD_Radar(void)
 // Score (#7)
 //
 void HUD_UpdatePlayerTeams();
+void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
+{
+       float score;
+       entity tm, pl;
+#define SCOREPANEL_MAX_ENTRIES 6
+#define SCOREPANEL_ASPECTRATIO 2
+       const float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
+       const float height = mySize_y/entries;
+       const vector fontsize = '0.9 0.9 0' * height;
+       pos_y += height * (1 - 0.9) / 2;
+
+       vector rgb, score_color;
+       rgb = '1 1 1';
+       score_color = '1 1 1';
+
+       const float name_size = mySize_x*0.75;
+       const float spacing_size = mySize_x*0.04;
+       const float highlight_alpha = 0.2;
+       float i, me_printed, first_pl;
+       string s;
+       i, first_pl = 0;
+       if (autocvar__hud_configure)
+       {
+               if (team_count)
+               {
+                       // show team scores in the first line
+                       float score_size = mySize_x / team_count;
+                       for(tm = teams.sort_next; tm; tm = tm.sort_next) {
+                               if(tm.team == COLOR_SPECTATOR)
+                                       continue;
+                               if (tm.team == myteam)
+                                       HUD_Panel_DrawHighlight(pos - eY * (height * (1 - 0.9) / 2) + eX * score_size * i, eX * score_size + eY * height, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+                               drawstring_aspect(pos + eX * score_size * i, ftos(123), eX * score_size + eY * fontsize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
+                               ++i;
+                       }
+                       first_pl = 1;
+                       pos_y += height;
+               }
+               score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
+               for (i=first_pl; i<entries; ++i)
+               {
+                       //simulate my score is lower than all displayed players,
+                       //so that I don't appear at all showing pure rankings.
+                       //This is to better show the difference between the 2 ranking views
+                       if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
+                       {
+                               rgb = '1 1 0';
+                               drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                               s = GetPlayerName(pl.sv_entnum);
+                               score = 7;
+                       }
+                       else
+                       {
+                               s = sprintf(_("Player %d"), i + 1 - first_pl);
+                               score -= 3;
+                       }
+
+                       if (team_count)
+                               score_color = GetTeamRGB(ColorByTeam(mod(i + 2, team_count))) * 0.8;
+                       s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
+                       drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       pos_y += height;
+               }
+               return;
+       }
+
+       if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
+               HUD_UpdatePlayerTeams();
+       if (team_count)
+       {
+               // show team scores in the first line
+               float score_size = mySize_x / team_count;
+               for(tm = teams.sort_next; tm; tm = tm.sort_next) {
+                       if(tm.team == COLOR_SPECTATOR)
+                               continue;
+                       if (tm.team == myteam)
+                               drawfill(pos - eY * (height * (1 - 0.9) / 2) + eX * score_size * i, eX * score_size + eY * height, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores[ts_primary])), eX * score_size + eY * fontsize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       ++i;
+               }
+               first_pl = 1;
+               pos_y += height;
+       }
+       i = first_pl;
+       for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next, ++i)
+       {
+               if (pl.team == COLOR_SPECTATOR)
+                       continue;
+
+               if (i == entries-1 && !me_printed && pl != me)
+               if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
+               {
+                       for (pl = me.sort_next; pl; pl = pl.sort_next)
+                               if (pl.team != COLOR_SPECTATOR)
+                                       break;
+
+                       if (pl)
+                               rgb = '1 1 0'; //not last but not among the leading players: yellow
+                       else
+                               rgb = '1 0 0'; //last: red
+                       pl = me;
+               }
+
+               if (pl == me)
+               {
+                       if (i == first_pl)
+                               rgb = '0 1 0'; //first: green
+                       me_printed = 1;
+                       drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+               }
+               if (team_count)
+                       score_color = GetTeamRGB(pl.team) * 0.8;
+               s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
+               drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
+               pos_y += height;
+       }
+}
+
 void HUD_Score(void)
 {
        if(!autocvar__hud_configure)
@@ -2656,83 +2763,7 @@ void HUD_Score(void)
        } else if (!teamplay) { // non-teamgames
                if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
                {
-#define SCOREPANEL_MAX_ENTRIES 6
-#define SCOREPANEL_ASPECTRATIO 2
-                       const float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
-                       const float height = mySize_y/entries;
-                       const vector fontsize = '0.9 0.9 0' * height;
-                       pos_y += height * (1 - 0.9) / 2;
-
-                       vector rgb;
-                       rgb = '1 1 1';
-
-                       const float name_size = mySize_x*0.75;
-                       const float highlight_alpha = 0.2;
-                       float i, me_printed;
-                       string s;
-                       if (autocvar__hud_configure)
-                       {
-                               score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
-                               for (i=0; i<entries; ++i)
-                               {
-                                       //simulate my score is lower than all displayed players,
-                                       //so that I don't appear at all showing pure rankings.
-                                       //This is to better show the difference between the 2 ranking views
-                                       if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
-                                       {
-                                               rgb = '1 1 0';
-                                               drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
-                                               s = GetPlayerName(pl.sv_entnum);
-                                               score = 7;
-                                       }
-                                       else
-                                       {
-                                               s = sprintf(_("Player %d"), i+1);
-                                               score -= 3;
-                                       }
-
-                                       s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
-                                       drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
-                                       drawstring(pos + eX * mySize_x*0.79, ftos(score), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-                                       pos_y += height;
-                               }
-                               return;
-                       }
-
-                       if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
-                               HUD_UpdatePlayerTeams();
-
-                       for (pl = players.sort_next, i=0; pl && i<entries; pl = pl.sort_next, ++i)
-                       {
-                               if (pl.team == COLOR_SPECTATOR)
-                                       continue;
-
-                               if (i == entries-1 && !me_printed && pl != me)
-                               if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
-                               {
-                                       for (pl = me.sort_next; pl; pl = pl.sort_next)
-                                               if (pl.team != COLOR_SPECTATOR)
-                                                       break;
-
-                                       if (pl)
-                                               rgb = '1 1 0'; //not last but not among the leading players: yellow
-                                       else
-                                               rgb = '1 0 0'; //last: red
-                                       pl = me;
-                               }
-
-                               if (pl == me)
-                               {
-                                       if (i == 0)
-                                               rgb = '0 1 0'; //first: green
-                                       me_printed = 1;
-                                       drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
-                               }
-                               s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
-                               drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
-                               drawstring(pos + eX * mySize_x*0.79, ftos(pl.(scores[ps_primary])), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-                               pos_y += height;
-                       }
+                       HUD_Score_Rankings(pos, mySize, me, 0);
                        return;
                }
                // me vector := [team/connected frags id]
@@ -2771,20 +2802,17 @@ void HUD_Score(void)
                drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
                drawstring_aspect(pos + eX * 0.75 * mySize_x, distribution_str, eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
        } else { // teamgames
-               float max_fragcount;
-               max_fragcount = -99;
-
                float scores_count, row, column, rows, columns;
                vector offset;
                vector score_pos, score_size; //for scores other than myteam
-               if (spectatee_status == -1)
+               if (spectatee_status == -1 || autocvar_hud_panel_score_rankings)
                {
-                       if (autocvar__hud_configure)
-                               scores_count = 4;
-                       else for(tm = teams.sort_next; tm; tm = tm.sort_next) {
-                               if(tm.team == COLOR_SPECTATOR)
-                                       continue;
+                       for(tm = teams.sort_next; tm, tm.team != COLOR_SPECTATOR; tm = tm.sort_next)
                                ++scores_count;
+                       if (autocvar_hud_panel_score_rankings)
+                       {
+                               HUD_Score_Rankings(pos, mySize, me, scores_count);
+                               return;
                        }
                        rows = mySize_y/mySize_x;
                        rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
@@ -2812,6 +2840,9 @@ void HUD_Score(void)
                }
                else
                        score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
+
+               float max_fragcount;
+               max_fragcount = -99;
                for(tm = teams.sort_next; tm; tm = tm.sort_next) {
                        if(tm.team == COLOR_SPECTATOR)
                                continue;