]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow to align spectators in columns (hud_panel_scoreboard_spectators_aligned)
authorterencehill <piuntn@gmail.com>
Wed, 14 Sep 2016 14:08:05 +0000 (16:08 +0200)
committerterencehill <piuntn@gmail.com>
Wed, 14 Sep 2016 14:08:05 +0000 (16:08 +0200)
_hud_common.cfg
qcsrc/client/hud/panel/scoreboard.qc

index 3e120e92cbe82bd5c7f2acc7c58a4f7150233076..2d8c5523511574a2f1b36d54784cf719a26edc40 100644 (file)
@@ -111,6 +111,7 @@ seta hud_panel_scoreboard_namesize 15 "size limit of player names and relative c
 seta hud_panel_scoreboard_maxheight 0.5 "max height of the scoreboard; a few players that wouldn't fit into the scoreboard are listed in the last row"
 seta hud_panel_scoreboard_others_showscore 1 "show scores of players listed in the last row when the scoreboard reaches the max height"
 seta hud_panel_scoreboard_spectators_showping 1 "show ping of spectators"
+seta hud_panel_scoreboard_spectators_aligned 0 "align spectators in columns"
 seta hud_panel_scoreboard_minwidth 0.4 "minimum width of the scoreboard"
 
 // hud panel aliases
index f3e198bf8a74848405e4e32d32012a1de245accc..2361ccff7a0a585ed1e5a7d444d4aad051a37612 100644 (file)
@@ -61,6 +61,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;
 
 
@@ -923,6 +924,7 @@ 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;
+       static float max_name_width = 0;
        string field = "";
        float fieldsize = 0;
        float min_fieldsize = 0;
@@ -951,14 +953,20 @@ vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity
                        field = ftos(pl.(scores(ps_primary)));
 
                string str = textShortenToWidth(entcs_GetName(pl.sv_entnum), namesize, hud_fontsize, stringwidth_colors);
-               float str_width = stringwidth(str, true, hud_fontsize);
+               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);
-                       str_width += hud_fontsize.x * 0.25 + max(fieldsize, min_fieldsize) + 2 * fieldpadding;
+                       column_width += hud_fontsize.x * 0.25 + max(fieldsize, min_fieldsize) + 2 * fieldpadding;
                }
 
-               if(pos.x + str_width > width_limit)
+               if(pos.x + column_width > width_limit)
                {
                        ++i;
                        if(!complete)
@@ -972,18 +980,24 @@ vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity
                                pos.y += hud_fontsize.y * 1.25;
                        }
                }
-               drawcolorcodedstring(pos, str, hud_fontsize, sbt_fg_alpha, DRAWFLAG_NORMAL);
-               pos.x += str_width;
+
+               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;
-                       pos.x -= h_size.x;
+                       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(pos, h_size, '1 1 1', sbt_highlight_alpha, DRAWFLAG_NORMAL);
-                       drawstring(pos + eX * (fieldpadding + (max(fieldsize, min_fieldsize) - fieldsize) * 0.5), field, hud_fontsize, sbt_field_rgb, sbt_fg_alpha, DRAWFLAG_NORMAL);
-                       pos.x += h_size.x;
+                               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);