]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/scoreboard.qc
Make it compile without XONOTIC defined
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / scoreboard.qc
index c6df590b41ce3fd9111f50c120c7f94e602c41af..ef68e21b2000808fb0a8cec871bb86abda43ea39 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>
@@ -61,6 +62,7 @@ bool autocvar_hud_panel_scoreboard_dynamichud = false;
 float autocvar_hud_panel_scoreboard_maxheight = 0.5;
 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;
 
 
@@ -756,7 +758,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)
@@ -920,8 +925,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)
@@ -929,24 +944,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 = ftos(pl.(scores(ps_primary)));
+
+               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)
@@ -957,12 +978,28 @@ 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);
 }
@@ -1054,7 +1091,9 @@ vector Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
 
 bool Scoreboard_WouldDraw()
 {
-       if (QuickMenu_IsOpened())
+       if (MUTATOR_CALLHOOK(DrawScoreboard))
+               return false;
+       else if (QuickMenu_IsOpened())
                return false;
        else if (HUD_Radar_Clickable())
                return false;
@@ -1322,7 +1361,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);
@@ -1541,8 +1580,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;