]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/scoreboard.qc
Scoreboard: show number of spectators
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / scoreboard.qc
index 64993010020de2a368fab8b59d71f33621c124cd..52814acb08e91720c69d7cf9b2cbcfeac378ffa8 100644 (file)
@@ -58,9 +58,10 @@ bool autocvar_hud_panel_scoreboard_accuracy_nocolors = false;
 
 bool autocvar_hud_panel_scoreboard_dynamichud = false;
 
-bool autocvar_hud_panel_scoreboard_maxheight = 0.5;
+float autocvar_hud_panel_scoreboard_maxheight = 0.5;
 bool autocvar_hud_panel_scoreboard_others_showscore = true;
 bool autocvar_hud_panel_scoreboard_spectators_showping = true;
+float autocvar_hud_panel_scoreboard_minwidth = 0.4;
 
 
 void drawstringright(vector, string, vector, vector, float, float);
@@ -147,12 +148,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 +371,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 +475,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 +487,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)
@@ -757,7 +756,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)
@@ -1053,22 +1055,23 @@ vector Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
        return end_pos;
 }
 
-float Scoreboard_WouldDraw() {
+bool Scoreboard_WouldDraw()
+{
        if (QuickMenu_IsOpened())
-               return 0;
+               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;
@@ -1322,7 +1325,7 @@ vector Scoreboard_Rankings_Draw(vector pos, entity pl, vector rgb, vector bg_siz
        }
 
        float ranksize = 3 * hud_fontsize.x;
-       float timesize = 5.5 * hud_fontsize.x;
+       float timesize = 5 * hud_fontsize.x;
        vector columnsize = eX * (ranksize + timesize + namesize + hud_fontsize.x) + eY * 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);
@@ -1450,7 +1453,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;
 
@@ -1541,8 +1544,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;