]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/scoreboard.qc
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / scoreboard.qc
index 7fc4db065e92359da855d61369f1430783d0958f..e6e5f36495c79f90c23356f41737c48c8190f4b8 100644 (file)
@@ -3,6 +3,7 @@
 #include "quickmenu.qh"
 #include <common/ent_cs.qh>
 #include <common/constants.qh>
+#include <common/net_linked.qh>
 #include <common/mapinfo.qh>
 #include <common/minigames/cl_minigames.qh>
 #include <common/stats.qh>
@@ -30,14 +31,14 @@ float sbt_highlight_alpha_self;
 
 // provide basic panel cvars to old clients
 // TODO remove them after a future release (0.8.2+)
-string autocvar_hud_panel_scoreboard_pos = "0.150000 0.150000";
-string autocvar_hud_panel_scoreboard_size = "0.700000 0.700000";
-string autocvar_hud_panel_scoreboard_bg = "border_default";
-string autocvar_hud_panel_scoreboard_bg_color = "0 0.3 0.5";
-string autocvar_hud_panel_scoreboard_bg_color_team = "";
-string autocvar_hud_panel_scoreboard_bg_alpha = "0.7";
-string autocvar_hud_panel_scoreboard_bg_border = "";
-string autocvar_hud_panel_scoreboard_bg_padding = "";
+noref string autocvar_hud_panel_scoreboard_pos = "0.150000 0.150000";
+noref string autocvar_hud_panel_scoreboard_size = "0.700000 0.700000";
+noref string autocvar_hud_panel_scoreboard_bg = "border_default";
+noref string autocvar_hud_panel_scoreboard_bg_color = "0 0.3 0.5";
+noref string autocvar_hud_panel_scoreboard_bg_color_team = "";
+noref string autocvar_hud_panel_scoreboard_bg_alpha = "0.7";
+noref string autocvar_hud_panel_scoreboard_bg_border = "";
+noref string autocvar_hud_panel_scoreboard_bg_padding = "";
 
 float autocvar_hud_panel_scoreboard_fadeinspeed = 10;
 float autocvar_hud_panel_scoreboard_fadeoutspeed = 5;
@@ -55,12 +56,15 @@ float autocvar_hud_panel_scoreboard_namesize = 15;
 bool autocvar_hud_panel_scoreboard_accuracy = true;
 bool autocvar_hud_panel_scoreboard_accuracy_doublerows = false;
 bool autocvar_hud_panel_scoreboard_accuracy_nocolors = false;
+bool autocvar_hud_panel_scoreboard_ctf_leaderboard = true;
 
 bool autocvar_hud_panel_scoreboard_dynamichud = false;
 
-bool autocvar_hud_panel_scoreboard_maxheight = 0.5;
+float autocvar_hud_panel_scoreboard_maxheight = 0.6;
 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;
 
 
 void drawstringright(vector, string, vector, vector, float, float);
@@ -147,12 +151,10 @@ void Scoreboard_UpdatePlayerTeams()
 {
        float Team;
        entity pl, tmp;
-       float num;
-
-       num = 0;
+       //int num = 0;
        for(pl = players.sort_next; pl; pl = pl.sort_next)
        {
-               num += 1;
+               //num += 1;
                Team = entcs_GetScoreTeam(pl.sv_entnum);
                if(SetTeam(pl, Team))
                {
@@ -372,8 +374,8 @@ void Cmd_Scoreboard_SetFields(int argc)
     TC(int, argc);
        int i, slash;
        string str, pattern;
-       float have_name = 0, have_primary = 0, have_secondary = 0, have_separator = 0;
-       float missing;
+       bool have_name = false, have_primary = false, have_secondary = false, have_separator = false;
+       int missing;
 
        if(!gametype)
                return; // do nothing, we don't know gametype and scores yet
@@ -476,9 +478,9 @@ LABEL(notfound)
 LABEL(found)
                                sbt_field[sbt_num_fields] = j;
                                if(j == ps_primary)
-                                       have_primary = 1;
+                                       have_primary = true;
                                if(j == ps_secondary)
-                                       have_secondary = 1;
+                                       have_secondary = true;
 
                        }
                }
@@ -488,11 +490,11 @@ LABEL(found)
        }
 
        if(scores_flags(ps_primary) & SFL_ALLOW_HIDE)
-               have_primary = 1;
+               have_primary = true;
        if(scores_flags(ps_secondary) & SFL_ALLOW_HIDE)
-               have_secondary = 1;
+               have_secondary = true;
        if(ps_primary == ps_secondary)
-               have_secondary = 1;
+               have_secondary = true;
        missing = (!have_primary) + (!have_secondary) + (!have_separator) + (!have_name);
 
        if(sbt_num_fields + missing < MAX_SBT_FIELDS)
@@ -567,6 +569,25 @@ string sbt_field_icon2;
 vector sbt_field_icon0_rgb;
 vector sbt_field_icon1_rgb;
 vector sbt_field_icon2_rgb;
+string Scoreboard_GetName(entity pl)
+{
+       if(ready_waiting && pl.ready)
+       {
+               sbt_field_icon0 = "gfx/scoreboard/player_ready";
+       }
+       else if(!teamplay)
+       {
+               int f = entcs_GetClientColors(pl.sv_entnum);
+               {
+                       sbt_field_icon0 = "gfx/scoreboard/playercolor_base";
+                       sbt_field_icon1 = "gfx/scoreboard/playercolor_shirt";
+                       sbt_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);
+                       sbt_field_icon2 = "gfx/scoreboard/playercolor_pants";
+                       sbt_field_icon2_rgb = colormapPaletteColor(f % 16, 1);
+               }
+       }
+       return entcs_GetName(pl.sv_entnum);
+}
 string Scoreboard_GetField(entity pl, PlayerScoreField field)
 {
        float tmp, num, denom;
@@ -607,22 +628,7 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field)
                        return str;
 
                case SP_NAME:
-                       if(ready_waiting && pl.ready)
-                       {
-                               sbt_field_icon0 = "gfx/scoreboard/player_ready";
-                       }
-                       else if(!teamplay)
-                       {
-                               f = entcs_GetClientColors(pl.sv_entnum);
-                               {
-                                       sbt_field_icon0 = "gfx/scoreboard/playercolor_base";
-                                       sbt_field_icon1 = "gfx/scoreboard/playercolor_shirt";
-                                       sbt_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);
-                                       sbt_field_icon2 = "gfx/scoreboard/playercolor_pants";
-                                       sbt_field_icon2_rgb = colormapPaletteColor(f % 16, 1);
-                               }
-                       }
-                       return entcs_GetName(pl.sv_entnum);
+                       return Scoreboard_GetName(pl);
 
                case SP_FRAGS:
                        f = pl.(scores(SP_KILLS));
@@ -669,7 +675,7 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field)
                case SP_DMG: case SP_DMGTAKEN:
                        return sprintf("%.1f k", pl.(scores(field)) / 1000);
 
-               default:
+               default: case SP_SCORE:
                        tmp = pl.(scores(field));
                        f = scores_flags(field);
                        if(field == ps_primary)
@@ -719,10 +725,11 @@ string Scoreboard_FixColumnWidth(int i, string str)
                        sbt_fixcolumnwidth_iconlen = f;
        }
 
-       sbt_fixcolumnwidth_iconlen *= hud_fontsize.y / hud_fontsize.x; // fix icon aspect
-
        if(sbt_fixcolumnwidth_iconlen != 0)
+       {
+               sbt_fixcolumnwidth_iconlen *= hud_fontsize.y / hud_fontsize.x; // fix icon aspect
                sbt_fixcolumnwidth_marginlen = stringwidth(" ", false, hud_fontsize);
+       }
        else
                sbt_fixcolumnwidth_marginlen = 0;
 
@@ -757,7 +764,10 @@ string Scoreboard_FixColumnWidth(int i, string str)
 void Scoreboard_initFieldSizes()
 {
        for(int i = 0; i < sbt_num_fields; ++i)
+       {
+               sbt_field_size[i] = stringwidth(sbt_field_title[i], false, hud_fontsize);
                Scoreboard_FixColumnWidth(i, "");
+       }
 }
 
 vector Scoreboard_DrawHeader(vector pos, vector rgb, bool other_players)
@@ -814,7 +824,7 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i
        bool is_spec = (entcs_GetTeam(pl.sv_entnum) == NUM_SPECTATOR);
 
        vector h_pos = item_pos;
-       vector h_size = eX * panel_size.x + eY * hud_fontsize.y * 1.25;
+       vector h_size = vec2(panel_size.x, hud_fontsize.y * 1.25);
        // alternated rows highlighting
        if(is_self)
                drawfill(h_pos, h_size, rgb, sbt_highlight_alpha_self, DRAWFLAG_NORMAL);
@@ -854,11 +864,11 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i
 
                tmp.x = sbt_field_size[i] + hud_fontsize.x;
                if(sbt_field_icon0 != "")
-                       drawpic(pos - tmp, sbt_field_icon0, eY * hud_fontsize.y + eX * hud_fontsize.x * sbt_fixcolumnwidth_iconlen, sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL);
+                       drawpic(pos - tmp, sbt_field_icon0, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL);
                if(sbt_field_icon1 != "")
-                       drawpic(pos - tmp, sbt_field_icon1, eY * hud_fontsize.y + eX * hud_fontsize.x * sbt_fixcolumnwidth_iconlen, sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL);
+                       drawpic(pos - tmp, sbt_field_icon1, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL);
                if(sbt_field_icon2 != "")
-                       drawpic(pos - tmp, sbt_field_icon2, eY * hud_fontsize.y + eX * hud_fontsize.x * sbt_fixcolumnwidth_iconlen, sbt_field_icon2_rgb, fg_alpha, DRAWFLAG_NORMAL);
+                       drawpic(pos - tmp, sbt_field_icon2, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon2_rgb, fg_alpha, DRAWFLAG_NORMAL);
        }
 
        if(sbt_field[i] == SP_SEPARATOR)
@@ -888,11 +898,11 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i
 
                        tmp.x = sbt_field_size[i];
                        if(sbt_field_icon0 != "")
-                               drawpic(pos - tmp, sbt_field_icon0, eY * hud_fontsize.y + eX * hud_fontsize.x * sbt_fixcolumnwidth_iconlen, sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL);
+                               drawpic(pos - tmp, sbt_field_icon0, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL);
                        if(sbt_field_icon1 != "")
-                               drawpic(pos - tmp, sbt_field_icon1, eY * hud_fontsize.y + eX * hud_fontsize.x * sbt_fixcolumnwidth_iconlen, sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL);
+                               drawpic(pos - tmp, sbt_field_icon1, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon1_rgb, fg_alpha, DRAWFLAG_NORMAL);
                        if(sbt_field_icon2 != "")
-                               drawpic(pos - tmp, sbt_field_icon2, eY * hud_fontsize.y + eX * hud_fontsize.x * sbt_fixcolumnwidth_iconlen, sbt_field_icon2_rgb, fg_alpha, DRAWFLAG_NORMAL);
+                               drawpic(pos - tmp, sbt_field_icon2, vec2(hud_fontsize.x * sbt_fixcolumnwidth_iconlen, hud_fontsize.y), sbt_field_icon2_rgb, fg_alpha, DRAWFLAG_NORMAL);
                        pos.x -= sbt_field_size[i] + hud_fontsize.x;
                }
        }
@@ -905,7 +915,7 @@ vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity
 {
        int i = 0;
        vector h_pos = item_pos;
-       vector h_size = eX * panel_size.x + eY * hud_fontsize.y * 1.25;
+       vector h_size = vec2(panel_size.x, hud_fontsize.y * 1.25);
 
        bool complete = (this_team == NUM_SPECTATOR);
 
@@ -921,8 +931,18 @@ vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity
        if(!complete)
                width_limit -= stringwidth("...", false, hud_fontsize);
        float namesize = autocvar_hud_panel_scoreboard_namesize * hud_fontsize.x;
-       float ping_padding = 0;
-       float min_pingsize = stringwidth("999", false, hud_fontsize);
+       static float max_name_width = 0;
+       string field = "";
+       float fieldsize = 0;
+       float min_fieldsize = 0;
+       float fieldpadding = hud_fontsize.x * 0.25;
+       if(this_team == NUM_SPECTATOR)
+       {
+               if(autocvar_hud_panel_scoreboard_spectators_showping)
+                       min_fieldsize = stringwidth("999", false, hud_fontsize);
+       }
+       else if(autocvar_hud_panel_scoreboard_others_showscore)
+               min_fieldsize = stringwidth("99", false, hud_fontsize);
        for(i = 0; pl; pl = pl.sort_next)
        {
                if(pl.team != this_team)
@@ -930,24 +950,30 @@ vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity
                if(pl == ignored_pl)
                        continue;
 
-               ping_padding = 0;
-               string str = textShortenToWidth(entcs_GetName(pl.sv_entnum), namesize, hud_fontsize, stringwidth_colors);
+               field = "";
                if(this_team == NUM_SPECTATOR)
                {
                        if(autocvar_hud_panel_scoreboard_spectators_showping)
-                       {
-                               string ping = Scoreboard_GetField(pl, SP_PING);
-                               float pingsize = stringwidth(ping, false, hud_fontsize);
-                               if(min_pingsize > pingsize)
-                                       ping_padding = min_pingsize - pingsize;
-                               string col = rgb_to_hexcolor(sbt_field_rgb);
-                               str = sprintf("%s ^7[%s%s^7]", str, col, ping);
-                       }
+                               field = Scoreboard_GetField(pl, SP_PING);
                }
                else if(autocvar_hud_panel_scoreboard_others_showscore)
-                       str = sprintf("%s ^7(^3%s^7)", str, ftos(pl.(scores(ps_primary))));
-               float str_width = stringwidth(str, true, hud_fontsize);
-               if(pos.x + str_width > width_limit)
+                       field = Scoreboard_GetField(pl, SP_SCORE);
+
+               string str = textShortenToWidth(entcs_GetName(pl.sv_entnum), namesize, hud_fontsize, stringwidth_colors);
+               float column_width = stringwidth(str, true, hud_fontsize);
+               if((this_team == NUM_SPECTATOR) && autocvar_hud_panel_scoreboard_spectators_aligned)
+               {
+                       if(column_width > max_name_width)
+                               max_name_width = column_width;
+                       column_width = max_name_width;
+               }
+               if(field != "")
+               {
+                       fieldsize = stringwidth(field, false, hud_fontsize);
+                       column_width += hud_fontsize.x * 0.25 + max(fieldsize, min_fieldsize) + 2 * fieldpadding;
+               }
+
+               if(pos.x + column_width > width_limit)
                {
                        ++i;
                        if(!complete)
@@ -958,14 +984,30 @@ vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity
                        else
                        {
                                pos.x = item_pos.x + hud_fontsize.x * 0.5;
-                               pos.y = item_pos.y + i * (hud_fontsize.y * 1.25);
+                               pos.y += hud_fontsize.y * 1.25;
                        }
                }
-               drawcolorcodedstring(pos, str, hud_fontsize, sbt_fg_alpha, DRAWFLAG_NORMAL);
-               pos.x += str_width + hud_fontsize.x * 0.5;
-               pos.x += ping_padding;
+
+               vector name_pos = pos;
+               if((this_team == NUM_SPECTATOR) && autocvar_hud_panel_scoreboard_spectators_aligned)
+                       name_pos.x += max(fieldsize, min_fieldsize) + 2 * fieldpadding + hud_fontsize.x * 0.25;
+               drawcolorcodedstring(name_pos, str, hud_fontsize, sbt_fg_alpha, DRAWFLAG_NORMAL);
+               if(field != "")
+               {
+                       h_size.x = max(fieldsize, min_fieldsize) + 2 * fieldpadding;
+                       h_size.y = hud_fontsize.y;
+                       vector field_pos = pos;
+                       if(!((this_team == NUM_SPECTATOR) && autocvar_hud_panel_scoreboard_spectators_aligned))
+                               field_pos.x += column_width - h_size.x;
+                       if(sbt_highlight)
+                               drawfill(field_pos, h_size, '1 1 1', sbt_highlight_alpha, DRAWFLAG_NORMAL);
+                       field_pos.x += fieldpadding + (max(fieldsize, min_fieldsize) - fieldsize) * 0.5;
+                       drawstring(field_pos, field, hud_fontsize, sbt_field_rgb, sbt_fg_alpha, DRAWFLAG_NORMAL);
+               }
+               pos.x += column_width;
+               pos.x += hud_fontsize.x;
        }
-       return eX * item_pos.x + eY * (item_pos.y + i * hud_fontsize.y * 1.25);
+       return vec2(item_pos.x, item_pos.y + i * hud_fontsize.y * 1.25);
 }
 
 vector Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
@@ -973,10 +1015,16 @@ vector Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
        int max_players = 999;
        if(autocvar_hud_panel_scoreboard_maxheight > 0)
        {
-               max_players = autocvar_hud_panel_scoreboard_maxheight * vid_conheight;
+               float height = autocvar_hud_panel_scoreboard_maxheight * vid_conheight;
                if(teamplay)
-                       max_players = (max_players - hud_fontsize.y * 1.25 - panel_bg_padding * 2) / 2;
-               max_players = floor(max_players / (hud_fontsize.y * 1.25));
+               {
+                       height -= (panel_bg_padding * 2 + hud_fontsize.y * 1.25) * team_count; // - padding and header
+                       height -= hud_fontsize.y * (team_count - 1); // - spacing between tables
+                       height /= team_count;
+               }
+               else
+                       height -= panel_bg_padding * 2; // - padding
+               max_players = floor(height / (hud_fontsize.y * 1.25));
                if(max_players <= 1)
                        max_players = 1;
                if(max_players == tm.team_size)
@@ -1001,7 +1049,7 @@ vector Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
        }
 
        pos = panel_pos;
-       vector tmp = eX * panel_size.x + eY * 1.25 * hud_fontsize.y;
+       vector tmp = vec2(panel_size.x, 1.25 * hud_fontsize.y);
 
        // rounded header
        if (sbt_bg_alpha)
@@ -1053,22 +1101,25 @@ vector Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
        return end_pos;
 }
 
-float Scoreboard_WouldDraw() {
-       if (QuickMenu_IsOpened())
-               return 0;
+bool Scoreboard_WouldDraw()
+{
+       if (MUTATOR_CALLHOOK(DrawScoreboard))
+               return false;
+       else if (QuickMenu_IsOpened())
+               return false;
        else if (HUD_Radar_Clickable())
-               return 0;
+               return false;
        else if (scoreboard_showscores)
-               return 1;
+               return true;
        else if (intermission == 1)
-               return 1;
+               return true;
        else if (intermission == 2)
-               return 0;
+               return false;
        else if (spectatee_status != -1 && STAT(HEALTH) <= 0 && autocvar_cl_deathscoreboard && gametype != MAPINFO_TYPE_CTS && !active_minigame)
-               return 1;
+               return true;
        else if (scoreboard_showscores_force)
-               return 1;
-       return 0;
+               return true;
+       return false;
 }
 
 float average_accuracy;
@@ -1082,11 +1133,11 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
                int weapon_stats = weapon_accuracy[i - WEP_FIRST];
 
                WepSet set = it.m_wepset;
-               if (weapon_stats < 0)
+               if (weapon_stats < 0 && !((weapons_stat & set) || (weapons_inmap & set)))
                {
-                       if (!(weapons_stat & set) && (it.spawnflags & WEP_FLAG_HIDDEN || it.spawnflags & WEP_FLAG_MUTATORBLOCKED))
-                               nHidden += 1;
-                       else if (!(weapons_stat & set || weapons_inmap & set))
+                       if (((it.spawnflags & WEP_FLAG_HIDDEN) || (it.spawnflags & WEP_FLAG_MUTATORBLOCKED)))
+                               ++nHidden;
+                       else
                                ++disownedcnt;
                }
        });
@@ -1135,11 +1186,11 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
                // column highlighting
                for (int i = 0; i < columnns; ++i)
                        if ((i % 2) == 0)
-                               drawfill(pos + eX * weapon_width * rows * i, eY * height * rows + eX * weapon_width * rows, '0 0 0', sbt_highlight_alpha, DRAWFLAG_NORMAL);
+                               drawfill(pos + eX * weapon_width * rows * i, vec2(weapon_width * rows, height * rows), '0 0 0', sbt_highlight_alpha, DRAWFLAG_NORMAL);
 
                // row highlighting
                for (int i = 0; i < rows; ++i)
-                       drawfill(pos + eY * weapon_height + eY * height * i, eX * tmp.x + eY * hud_fontsize.y, rgb, sbt_highlight_alpha, DRAWFLAG_NORMAL);
+                       drawfill(pos + eY * (weapon_height + height * i), vec2(tmp.x, hud_fontsize.y), rgb, sbt_highlight_alpha, DRAWFLAG_NORMAL);
        }
 
        average_accuracy = 0;
@@ -1160,7 +1211,7 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
                int weapon_stats = weapon_accuracy[i - WEP_FIRST];
 
                WepSet set = it.m_wepset;
-               if (weapon_stats < 0 && !(weapons_stat & set || weapons_inmap & set))
+               if (weapon_stats < 0 && !((weapons_stat & set) || (weapons_inmap & set)))
                        continue;
 
                float weapon_alpha;
@@ -1170,7 +1221,7 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
                        weapon_alpha = 0.2 * sbt_fg_alpha;
 
                // weapon icon
-               drawpic_aspect_skin(tmpos, it.model2, eX * weapon_width + eY * weapon_height, '1 1 1', weapon_alpha, DRAWFLAG_NORMAL);
+               drawpic_aspect_skin(tmpos, it.model2, vec2(weapon_width, weapon_height), '1 1 1', weapon_alpha, DRAWFLAG_NORMAL);
                // the accuracy
                if (weapon_stats >= 0) {
                        weapons_with_stats += 1;
@@ -1185,7 +1236,7 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
                        if(!autocvar_hud_panel_scoreboard_accuracy_nocolors)
                                rgb = Accuracy_GetColor(weapon_stats);
 
-                       drawstring(tmpos + eX * padding + eY * weapon_height, s, hud_fontsize, rgb, sbt_fg_alpha, DRAWFLAG_NORMAL);
+                       drawstring(tmpos + vec2(padding, weapon_height), s, hud_fontsize, rgb, sbt_fg_alpha, DRAWFLAG_NORMAL);
                }
                tmpos.x += weapon_width * rows;
                pos.x += weapon_width * rows;
@@ -1300,17 +1351,30 @@ vector Scoreboard_Rankings_Draw(vector pos, entity pl, vector rgb, vector bg_siz
        vector hl_rgb = rgb + '0.5 0.5 0.5';
 
        pos.y += hud_fontsize.y;
-       drawstring(pos + eX * panel_bg_padding, _("Rankings"), hud_fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+       drawstring(pos + eX * panel_bg_padding, ((gametype == MAPINFO_TYPE_CTF) ? _("Capture time rankings") : _("Rankings")), hud_fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
        pos.y += 1.25 * hud_fontsize.y;
        if(panel.current_panel_bg != "0")
                pos.y += panel_bg_border;
 
        panel_pos = pos;
 
+       float namesize = 0;
+       for(i = 0; i < RANKINGS_RECEIVED_CNT; ++i)
+       {
+               float f = stringwidth(ColorTranslateRGB(grecordholder[i]), true, hud_fontsize);
+               if(f > namesize)
+                       namesize = f;
+       }
+       bool cut = false;
+       if(namesize > autocvar_hud_panel_scoreboard_namesize * hud_fontsize.x)
+       {
+               namesize = autocvar_hud_panel_scoreboard_namesize * hud_fontsize.x;
+               cut = true;
+       }
+
        float ranksize = 3 * hud_fontsize.x;
-       float timesize = 5.5 * hud_fontsize.x;
-       float namesize = autocvar_hud_panel_scoreboard_namesize * hud_fontsize.x;
-       vector columnsize = eX * (ranksize + timesize + namesize) + eY * 1.25 * hud_fontsize.y;
+       float timesize = 5 * hud_fontsize.x;
+       vector columnsize = vec2(ranksize + timesize + namesize + hud_fontsize.x, 1.25 * hud_fontsize.y);
        int columns = max(1, floor((panel_size.x - 2 * panel_bg_padding) / columnsize.x));
        columns = min(columns, RANKINGS_RECEIVED_CNT);
 
@@ -1339,6 +1403,7 @@ vector Scoreboard_Rankings_Draw(vector pos, entity pl, vector rgb, vector bg_siz
        if (sbt_bg_alpha)
                drawpic_tiled(pos, "gfx/scoreboard/scoreboard_bg", bg_size, panel_size, rgb, sbt_bg_alpha, DRAWFLAG_NORMAL);
 
+       vector text_ofs = vec2(0.5 * hud_fontsize.x, (1.25 - 1) / 2 * hud_fontsize.y); // center text vertically
        string str = "";
        int column = 0, j = 0;
        for(i = 0; i < RANKINGS_RECEIVED_CNT; ++i)
@@ -1348,16 +1413,18 @@ vector Scoreboard_Rankings_Draw(vector pos, entity pl, vector rgb, vector bg_siz
                if (t == 0)
                        continue;
 
-               if(grecordholder[i] == entcs_GetName(player_localnum))
+               if(strdecolorize(grecordholder[i]) == strdecolorize(entcs_GetName(player_localnum)))
                        drawfill(pos, columnsize, hl_rgb, sbt_highlight_alpha_self, DRAWFLAG_NORMAL);
                else if(!((j + column) & 1) && sbt_highlight)
                        drawfill(pos, columnsize, hl_rgb, sbt_highlight_alpha, DRAWFLAG_NORMAL);
 
                str = count_ordinal(i+1);
-               drawstring(pos, str, hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL);
-               drawstring(pos + eX * ranksize, TIME_ENCODED_TOSTRING(t), hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL);
-               str = textShortenToWidth(grecordholder[i], namesize, hud_fontsize, stringwidth_colors);
-               drawcolorcodedstring(pos + eX * (ranksize + timesize), str, hud_fontsize, sbt_fg_alpha, DRAWFLAG_NORMAL);
+               drawstring(pos + text_ofs, str, hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL);
+               drawstring(pos + text_ofs + eX * ranksize, TIME_ENCODED_TOSTRING(t), hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL);
+               str = ColorTranslateRGB(grecordholder[i]);
+               if(cut)
+                       str = textShortenToWidth(str, namesize, hud_fontsize, stringwidth_colors);
+               drawcolorcodedstring(pos + text_ofs + eX * (ranksize + timesize), str, hud_fontsize, sbt_fg_alpha, DRAWFLAG_NORMAL);
 
                pos.y += 1.25 * hud_fontsize.y;
                j++;
@@ -1434,7 +1501,7 @@ void Scoreboard_Draw()
                panel_pos.y = max((autocvar_con_notify * autocvar_con_notifysize), panel_pos.y);
 
        float excess = max(0, max_namesize - autocvar_hud_panel_scoreboard_namesize * hud_fontsize.x);
-       float fixed_scoreboard_width = bound(vid_conwidth * 0.4, vid_conwidth - excess, vid_conwidth * 0.93);
+       float fixed_scoreboard_width = bound(vid_conwidth * autocvar_hud_panel_scoreboard_minwidth, vid_conwidth - excess, vid_conwidth * 0.93);
        panel_pos.x = 0.5 * (vid_conwidth - fixed_scoreboard_width);
        panel_size.x = fixed_scoreboard_width;
 
@@ -1443,6 +1510,7 @@ void Scoreboard_Draw()
        vector pos = panel_pos;
        entity pl, tm;
        string str;
+       vector str_pos;
 
        // Heading
        vector sb_heading_fontsize;
@@ -1477,12 +1545,14 @@ void Scoreboard_Draw()
                        draw_beginBoldFont();
                        vector rgb = Team_ColorRGB(tm.team);
                        str = ftos(tm.(teamscores(ts_primary)));
-                       drawstring(pos + team_score_baseoffset - eX * stringwidth(str, false, hud_fontsize * 1.5), str, hud_fontsize * 1.5, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       str_pos = pos + team_score_baseoffset - eX * stringwidth(str, false, hud_fontsize * 1.5);
+                       drawstring(str_pos, str, hud_fontsize * 1.5, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
 
                        if(ts_primary != ts_secondary)
                        {
                                str = ftos(tm.(teamscores(ts_secondary)));
-                               drawstring(pos + team_score_baseoffset - eX * stringwidth(str, false, hud_fontsize) + eY * hud_fontsize.y * 1.5, str, hud_fontsize, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
+                               str_pos = pos + team_score_baseoffset - vec2(stringwidth(str, false, hud_fontsize), hud_fontsize.y * 1.5);
+                               drawstring(str_pos, str, hud_fontsize, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
                        }
                        draw_endBoldFont();
                        if(autocvar_hud_panel_scoreboard_bg_teams_color_team > 0)
@@ -1504,19 +1574,22 @@ void Scoreboard_Draw()
                pos = Scoreboard_MakeTable(pos, tm, panel_bg_color, bg_size);
        }
 
-       if(gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE) {
+       bool show_accuracy = (gametype != MAPINFO_TYPE_CTS && gametype != MAPINFO_TYPE_RACE && gametype != MAPINFO_TYPE_NEXBALL);
+
+       if (show_accuracy && autocvar_hud_panel_scoreboard_accuracy && !warmup_stage)
+               pos = Scoreboard_AccuracyStats_Draw(pos, panel_bg_color, bg_size);
+
+       if(gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (autocvar_hud_panel_scoreboard_ctf_leaderboard && gametype == MAPINFO_TYPE_CTF && STAT(CTF_SHOWLEADERBOARD))) {
                if(race_speedaward) {
-                       drawcolorcodedstring(pos, sprintf(_("Speed award: %d%s ^7(%s^7)"), race_speedaward, race_speedaward_unit, race_speedaward_holder), hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(pos, sprintf(_("Speed award: %d%s ^7(%s^7)"), race_speedaward, race_speedaward_unit, ColorTranslateRGB(race_speedaward_holder)), hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
                        pos.y += 1.25 * hud_fontsize.y;
                }
                if(race_speedaward_alltimebest) {
-                       drawcolorcodedstring(pos, sprintf(_("All-time fastest: %d%s ^7(%s^7)"), race_speedaward_alltimebest, race_speedaward_alltimebest_unit, race_speedaward_alltimebest_holder), hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(pos, sprintf(_("All-time fastest: %d%s ^7(%s^7)"), race_speedaward_alltimebest, race_speedaward_alltimebest_unit, ColorTranslateRGB(race_speedaward_alltimebest_holder)), hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
                        pos.y += 1.25 * hud_fontsize.y;
                }
                pos = Scoreboard_Rankings_Draw(pos, playerslots[player_localnum], panel_bg_color, bg_size);
        }
-       else if (autocvar_hud_panel_scoreboard_accuracy && !warmup_stage && gametype != MAPINFO_TYPE_NEXBALL)
-               pos = Scoreboard_AccuracyStats_Draw(pos, panel_bg_color, bg_size);
 
        pos = Scoreboard_MapStats_Draw(pos, panel_bg_color, bg_size);
 
@@ -1525,8 +1598,12 @@ void Scoreboard_Draw()
        {
                if(pl.team == NUM_SPECTATOR)
                {
+                       for(tm = teams.sort_next; tm; tm = tm.sort_next)
+                               if(tm.team == NUM_SPECTATOR)
+                                       break;
+                       str = sprintf("%s (%d)", _("Spectators"), tm.team_size);
                        draw_beginBoldFont();
-                       drawstring(pos, _("Spectators"), hud_fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawstring(pos, str, hud_fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
                        draw_endBoldFont();
                        pos.y += 1.25 * hud_fontsize.y;