]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/scoreboard.qc
Simplify vdist macro and remove a redundant vec2 call
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / scoreboard.qc
index 3649415ccf6cd036a8996c1872878df1e7449885..39deff0d1c36e202696428237d93589679eb4195 100644 (file)
@@ -30,6 +30,7 @@ void Scoreboard_Draw_Export(int fh)
        HUD_Write_Cvar("hud_panel_scoreboard_table_highlight");
        HUD_Write_Cvar("hud_panel_scoreboard_table_highlight_alpha");
        HUD_Write_Cvar("hud_panel_scoreboard_table_highlight_alpha_self");
+       HUD_Write_Cvar("hud_panel_scoreboard_table_highlight_alpha_eliminated");
        HUD_Write_Cvar("hud_panel_scoreboard_bg_teams_color_team");
        HUD_Write_Cvar("hud_panel_scoreboard_accuracy_doublerows");
        HUD_Write_Cvar("hud_panel_scoreboard_accuracy_nocolors");
@@ -52,6 +53,7 @@ float sbt_fg_alpha_self;
 bool sbt_highlight;
 float sbt_highlight_alpha;
 float sbt_highlight_alpha_self;
+float sbt_highlight_alpha_eliminated;
 
 // provide basic panel cvars to old clients
 // TODO remove them after a future release (0.8.2+)
@@ -74,6 +76,7 @@ float autocvar_hud_panel_scoreboard_table_fg_alpha_self = 1;
 bool autocvar_hud_panel_scoreboard_table_highlight = true;
 float autocvar_hud_panel_scoreboard_table_highlight_alpha = 0.2;
 float autocvar_hud_panel_scoreboard_table_highlight_alpha_self = 0.4;
+float autocvar_hud_panel_scoreboard_table_highlight_alpha_eliminated = 0.6;
 float autocvar_hud_panel_scoreboard_bg_teams_color_team = 0;
 float autocvar_hud_panel_scoreboard_namesize = 15;
 float autocvar_hud_panel_scoreboard_team_size_position = 0;
@@ -97,6 +100,9 @@ bool autocvar_hud_panel_scoreboard_others_showscore = true;
 bool autocvar_hud_panel_scoreboard_spectators_showping = true;
 bool autocvar_hud_panel_scoreboard_spectators_aligned = false;
 float autocvar_hud_panel_scoreboard_minwidth = 0.4;
+bool autocvar_hud_panel_scoreboard_playerid = false;
+string autocvar_hud_panel_scoreboard_playerid_prefix = "#";
+string autocvar_hud_panel_scoreboard_playerid_suffix = " ";
 
 // mode 0: returns translated label
 // mode 1: prints name and description of all the labels
@@ -575,6 +581,13 @@ LABEL(found)
        sbt_field[sbt_num_fields] = SP_END;
 }
 
+string Scoreboard_AddPlayerId(string pl_name, entity pl)
+{
+       string pref = autocvar_hud_panel_scoreboard_playerid_prefix;
+       string suf = autocvar_hud_panel_scoreboard_playerid_suffix;
+       return strcat(pref, itos(pl.sv_entnum + 1), suf, pl_name);
+}
+
 // MOVEUP::
 vector sbt_field_rgb;
 string sbt_field_icon0;
@@ -643,7 +656,10 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field)
                        return str;
 
                case SP_NAME:
-                       return Scoreboard_GetName(pl);
+                       str = Scoreboard_GetName(pl);
+                       if (autocvar_hud_panel_scoreboard_playerid)
+                               str = Scoreboard_AddPlayerId(str, pl);
+                       return str;
 
                case SP_FRAGS:
                        f = pl.(scores(SP_KILLS));
@@ -864,7 +880,7 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i
        vector pos = item_pos;
        // put a "self indicator" beside the self row, unicode U+25C0 (black left-pointing triangle)
        if (is_self)
-               drawstring(pos+eX*(panel_size.x+.5*hud_fontsize.x)+eY, "\xE2\x97\x80", vec2(hud_fontsize.x, hud_fontsize.y), rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawstring(pos + eX * (panel_size.x + 0.5 * hud_fontsize.x) + eY, "\xE2\x97\x80", hud_fontsize, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
 
        pos.x += hud_fontsize.x * 0.5;
        pos.y += (1.25 - 1) / 2 * hud_fontsize.y; // center text vertically
@@ -940,7 +956,7 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i
        }
 
        if(pl.eliminated)
-               drawfill(h_pos, h_size, '0 0 0', 0.5 * panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawfill(h_pos, h_size, '0 0 0', sbt_highlight_alpha_eliminated, DRAWFLAG_NORMAL);
 }
 
 vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity ignored_pl, entity pl, int pl_number)
@@ -991,7 +1007,10 @@ vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity
                else if(autocvar_hud_panel_scoreboard_others_showscore)
                        field = Scoreboard_GetField(pl, SP_SCORE);
 
-               string str = textShortenToWidth(entcs_GetName(pl.sv_entnum), namesize, hud_fontsize, stringwidth_colors);
+               string str = entcs_GetName(pl.sv_entnum);
+               if (autocvar_hud_panel_scoreboard_playerid)
+                       str = Scoreboard_AddPlayerId(str, pl);
+               str = textShortenToWidth(str, namesize, hud_fontsize, stringwidth_colors);
                float column_width = stringwidth(str, true, hud_fontsize);
                if((this_team == NUM_SPECTATOR) && autocvar_hud_panel_scoreboard_spectators_aligned)
                {
@@ -1040,7 +1059,7 @@ vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity
                {
                        h_size.x = column_width + hud_fontsize.x * 0.25;
                        h_size.y = hud_fontsize.y;
-                       drawfill(pos - hud_fontsize.x * 0.25 * eX, h_size, '0 0 0', 0.5 * panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawfill(pos - hud_fontsize.x * 0.25 * eX, h_size, '0 0 0', sbt_highlight_alpha_eliminated, DRAWFLAG_NORMAL);
                }
                pos.x += column_width;
                pos.x += hud_fontsize.x;
@@ -1167,7 +1186,6 @@ float average_accuracy;
 vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
 {
        scoreboard_acc_fade_alpha = min(scoreboard_fade_alpha, scoreboard_acc_fade_alpha + frametime * 10);
-       vector initial_pos = pos;
 
        WepSet weapons_stat = WepSet_GetFromStat();
        WepSet weapons_inmap = WepSet_GetFromStat_InMap();
@@ -1308,9 +1326,7 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
 
        panel_size.x += panel_bg_padding * 2; // restore initial width
 
-       if (scoreboard_acc_fade_alpha == 1)
-               return end_pos;
-       return initial_pos + (end_pos - initial_pos) * scoreboard_acc_fade_alpha;
+       return end_pos;
 }
 
 .bool uninteresting;
@@ -1330,7 +1346,6 @@ STATIC_INIT(default_order_items_label)
 vector Scoreboard_ItemStats_Draw(vector pos, vector rgb, vector bg_size)
 {
        scoreboard_itemstats_fade_alpha = min(scoreboard_fade_alpha, scoreboard_itemstats_fade_alpha + frametime * 10);
-       vector initial_pos = pos;
 
        int disowned_cnt = 0;
        int uninteresting_cnt = 0;
@@ -1424,9 +1439,7 @@ vector Scoreboard_ItemStats_Draw(vector pos, vector rgb, vector bg_size)
 
        panel_size.x += panel_bg_padding * 2; // restore initial width
 
-       if (scoreboard_itemstats_fade_alpha == 1)
-               return end_pos;
-       return initial_pos + (end_pos - initial_pos) * scoreboard_itemstats_fade_alpha;
+       return end_pos;
 }
 
 vector MapStats_DrawKeyValue(vector pos, string key, string value) {
@@ -1694,7 +1707,7 @@ void Scoreboard_Draw()
 
                // frametime checks allow to toggle the scoreboard even when the game is paused
                if(scoreboard_active) {
-                       if (scoreboard_fade_alpha < 1)
+                       if (scoreboard_fade_alpha == 0)
                                scoreboard_time = time;
                        if(hud_configure_menu_open == 1)
                                scoreboard_fade_alpha = 1;
@@ -1742,6 +1755,7 @@ void Scoreboard_Draw()
        sbt_highlight = autocvar_hud_panel_scoreboard_table_highlight;
        sbt_highlight_alpha = autocvar_hud_panel_scoreboard_table_highlight_alpha * panel_fg_alpha;
        sbt_highlight_alpha_self = autocvar_hud_panel_scoreboard_table_highlight_alpha_self * panel_fg_alpha;
+       sbt_highlight_alpha_eliminated = autocvar_hud_panel_scoreboard_table_highlight_alpha_eliminated * panel_fg_alpha;
        sbt_fg_alpha = autocvar_hud_panel_scoreboard_table_fg_alpha * panel_fg_alpha;
        sbt_fg_alpha_self = autocvar_hud_panel_scoreboard_table_fg_alpha_self * panel_fg_alpha;
 
@@ -1756,6 +1770,7 @@ void Scoreboard_Draw()
 
        Scoreboard_UpdatePlayerTeams();
 
+       float initial_pos_y = panel_pos.y;
        vector pos = panel_pos;
        entity pl, tm;
        string str;
@@ -2047,5 +2062,14 @@ void Scoreboard_Draw()
                drawcolorcodedstring(pos + '0.5 0 0' * (panel_size.x - stringwidth(str, true, hud_fontsize)), str, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
        }
 
-       scoreboard_bottom = pos.y + 2 * hud_fontsize.y;
+       pos.y += 2 * hud_fontsize.y;
+       if (scoreboard_fade_alpha < 1)
+               scoreboard_bottom = initial_pos_y + (pos.y - initial_pos_y) * scoreboard_fade_alpha;
+       else if (pos.y != scoreboard_bottom)
+       {
+               if (pos.y > scoreboard_bottom)
+                       scoreboard_bottom = min(pos.y, scoreboard_bottom + frametime * 10 * (pos.y - initial_pos_y));
+               else
+                       scoreboard_bottom = max(pos.y, scoreboard_bottom - frametime * 10 * (pos.y - initial_pos_y));
+       }
 }