From 135cc6c1992a4055cb45cd4ca19a332258acc110 Mon Sep 17 00:00:00 2001 From: terencehill Date: Tue, 30 Aug 2016 02:02:39 +0200 Subject: [PATCH] Scoreboard: add a customizable size limit of player names and relative column; scoreboard width is now based on this value --- _hud_common.cfg | 2 ++ qcsrc/client/hud/panel/scoreboard.qc | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index 725bfe4e3..b8bcec7a5 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -107,6 +107,8 @@ seta hud_panel_infomessages_group0 1 "show group 0 messages (showing keys for no seta hud_panel_infomessages_group_time 6 "number of seconds a message of a group lasts before it gets changed" seta hud_panel_infomessages_group_fadetime 0.4 "group message fade in/out time" +seta hud_panel_scoreboard_namesize "15" "size limit of player names and relative column (multiplied by fontsize)" + // hud panel aliases alias quickmenu "cl_cmd hud quickmenu ${* ?}" diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index acbc2e45c..5f7a35dc2 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -12,6 +12,7 @@ string autocvar_hud_fontsize; string hud_fontsize_str; +float max_namesize; float sbt_bg_alpha; float sbt_fg_alpha; @@ -42,6 +43,7 @@ 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_bg_teams_color_team = 0; +float autocvar_hud_panel_scoreboard_namesize = 15; bool autocvar_hud_panel_scoreboard_accuracy = true; bool autocvar_hud_panel_scoreboard_accuracy_doublerows = false; @@ -722,18 +724,20 @@ string Scoreboard_FixColumnWidth(int i, string str) if(sbt_field[i] == SP_NAME) // name gets all remaining space { int j; - float namesize; - namesize = panel_size.x; + float remaining_space = 0; for(j = 0; j < sbt_num_fields; ++j) if(j != i) if (sbt_field[i] != SP_SEPARATOR) - namesize -= sbt_field_size[j] + hud_fontsize.x; - sbt_field_size[i] = namesize; + remaining_space += sbt_field_size[j] + hud_fontsize.x; + sbt_field_size[i] = panel_size.x - remaining_space; if (sbt_fixcolumnwidth_iconlen != 0) - namesize -= sbt_fixcolumnwidth_marginlen + sbt_fixcolumnwidth_iconlen * hud_fontsize.x; + remaining_space += sbt_fixcolumnwidth_marginlen + sbt_fixcolumnwidth_iconlen * hud_fontsize.x; + float namesize = panel_size.x - remaining_space; str = textShortenToWidth(str, namesize, hud_fontsize, stringwidth_colors); sbt_fixcolumnwidth_len = stringwidth(str, true, hud_fontsize); + + max_namesize = vid_conwidth - remaining_space; } else sbt_fixcolumnwidth_len = stringwidth(str, false, hud_fontsize); @@ -1336,6 +1340,11 @@ void Scoreboard_Draw() if(!autocvar__hud_configure) 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); + panel_pos.x = 0.5 * (vid_conwidth - fixed_scoreboard_width); + panel_size.x = fixed_scoreboard_width; + Scoreboard_UpdatePlayerTeams(); vector pos, tmp; -- 2.39.2