]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/scoreboard.qc
Merge branch 'bones_was_here/matchid_eventlog' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / scoreboard.qc
index 13319d3a9d2d69b496e3ce98e3b116de0f75533a..0d0a44b6a295f839a7516ac210f96a685edee8bc 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <client/draw.qh>
 #include <client/hud/panel/chat.qh>
+#include <client/hud/panel/physics.qh>
 #include <client/hud/panel/quickmenu.qh>
 #include <client/hud/panel/racetimer.qh>
 #include <client/hud/panel/weapons.qh>
@@ -208,6 +209,11 @@ void Scoreboard_InitScores()
 //float lastpnum;
 void Scoreboard_UpdatePlayerTeams()
 {
+       static float update_time;
+       if (time <= update_time)
+               return;
+       update_time = time;
+
        entity pl, tmp;
        //int num = 0;
        for(pl = players.sort_next; pl; pl = pl.sort_next)
@@ -1240,10 +1246,11 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
        int rows = 1;
        if (autocvar_hud_panel_scoreboard_accuracy_doublerows && weapon_cnt >= floor((REGISTRY_COUNT(Weapons) - nHidden - 1) * 0.5))
                rows = 2;
-       int columnns = ceil(weapon_cnt / rows);
+       int columns = ceil(weapon_cnt / rows);
 
-       float weapon_height = 29;
-       float height = hud_fontsize.y + weapon_height;
+       float aspect = max(0.001, autocvar_hud_panel_weapons_aspect);
+       float weapon_height = hud_fontsize.y * 2.3 / aspect;
+       float height = weapon_height + hud_fontsize.y;
 
        drawstring(pos + eX * panel_bg_padding, sprintf(_("Accuracy stats (average %d%%)"), average_accuracy), hud_fontsize, '1 1 1', panel_fg_alpha * scoreboard_acc_fade_alpha, DRAWFLAG_NORMAL);
        pos.y += 1.25 * hud_fontsize.y;
@@ -1272,7 +1279,7 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
        pos = panel_pos;
        vector tmp = panel_size;
 
-       float weapon_width = tmp.x / columnns / rows;
+       float weapon_width = tmp.x / columns / rows;
 
        if (sbt_bg_alpha)
                drawpic_tiled(pos, "gfx/scoreboard/scoreboard_bg", bg_size, tmp, rgb, sbt_bg_alpha * scoreboard_acc_fade_alpha, DRAWFLAG_NORMAL);
@@ -1280,7 +1287,7 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
        if(sbt_highlight)
        {
                // column highlighting
-               for (int i = 0; i < columnns; ++i)
+               for (int i = 0; i < columns; ++i)
                        if ((i % 2) == 0)
                                drawfill(pos + eX * weapon_width * rows * i, vec2(weapon_width * rows, height * rows), '0 0 0', sbt_highlight_alpha * scoreboard_acc_fade_alpha, DRAWFLAG_NORMAL);
 
@@ -1325,11 +1332,8 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
                        weapons_with_stats += 1;
                        average_accuracy += weapon_stats; // store sum of all accuracies in average_accuracy
 
-                       string s;
-                       s = sprintf("%d%%", weapon_stats * 100);
-
-                       float padding;
-                       padding = (weapon_width - stringwidth(s, false, hud_fontsize)) / 2; // center the accuracy value
+                       string s = sprintf("%d%%", weapon_stats * 100);
+                       float padding = (weapon_width - stringwidth(s, false, hud_fontsize)) / 2;
 
                        if(!autocvar_hud_panel_scoreboard_accuracy_nocolors)
                                rgb = Accuracy_GetColor(weapon_stats);
@@ -1338,7 +1342,7 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
                }
                tmpos.x += weapon_width * rows;
                pos.x += weapon_width * rows;
-               if (rows == 2 && column == columnns - 1) {
+               if (rows == 2 && column == columns - 1) {
                        tmpos.x = oldposx;
                        tmpos.y += height;
                        pos.y += height;
@@ -1400,11 +1404,10 @@ vector Scoreboard_ItemStats_Draw(vector pos, vector rgb, vector bg_size)
        if (n <= 0) return pos;
 
        int rows = (autocvar_hud_panel_scoreboard_itemstats_doublerows && n >= floor(REGISTRY_COUNT(Items) / 2)) ? 2 : 1;
-       int columnns = max(6, ceil(n / rows));
+       int columns = max(6, ceil(n / rows));
 
-       float height = 40;
-       float fontsize = height * 1/3;
-       float item_height = height * 2/3;
+       float item_height = hud_fontsize.y * 2.3;
+       float height = item_height + hud_fontsize.y;
 
        drawstring(pos + eX * panel_bg_padding, _("Item stats"), hud_fontsize, '1 1 1', panel_fg_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
        pos.y += 1.25 * hud_fontsize.y;
@@ -1433,7 +1436,7 @@ vector Scoreboard_ItemStats_Draw(vector pos, vector rgb, vector bg_size)
        pos = panel_pos;
        vector tmp = panel_size;
 
-       float item_width = tmp.x / columnns / rows;
+       float item_width = tmp.x / columns / rows;
 
        if (sbt_bg_alpha)
                drawpic_tiled(pos, "gfx/scoreboard/scoreboard_bg", bg_size, tmp, rgb, sbt_bg_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
@@ -1441,13 +1444,13 @@ vector Scoreboard_ItemStats_Draw(vector pos, vector rgb, vector bg_size)
        if(sbt_highlight)
        {
                // column highlighting
-               for (int i = 0; i < columnns; ++i)
+               for (int i = 0; i < columns; ++i)
                        if ((i % 2) == 0)
-                               drawfill(pos + '1 0 0' * item_width * rows * i, '0 1 0' * height * rows + '1 0 0' * item_width * rows, '0 0 0', sbt_highlight_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
+                               drawfill(pos + eX * item_width * rows * i, vec2(item_width * rows, height * rows), '0 0 0', sbt_highlight_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
 
                // row highlighting
                for (int i = 0; i < rows; ++i)
-                       drawfill(pos + '0 1 0' * item_height + '0 1 0' * height * i, '1 0 0' * panel_size.x + '0 1 0' * fontsize, rgb, sbt_highlight_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
+                       drawfill(pos + eY * (item_height + height * i), vec2(panel_size.x, hud_fontsize.y), rgb, sbt_highlight_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
        }
 
        if (rows == 2)
@@ -1461,13 +1464,13 @@ vector Scoreboard_ItemStats_Draw(vector pos, vector rgb, vector bg_size)
                int n = g_inventory.inv_items[it.m_id];
                //n = 1 + floor(i * 3 + 4.8) % 7; // debug: display a value for each item
                if (n <= 0) continue;
-               drawpic_aspect_skin(tmpos, it.m_icon, '1 0 0' * item_width + '0 1 0' * item_height, '1 1 1', panel_fg_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
+               drawpic_aspect_skin(tmpos, it.m_icon, eX * item_width + eY * item_height, '1 1 1', panel_fg_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
                string s = ftos(n);
-               float padding = (item_width - stringwidth(s, false, '1 0 0' * fontsize)) / 2; // center
-               drawstring(tmpos + '1 0 0' * padding + '0 1 0' * item_height, s, '1 1 0' * fontsize, '1 1 1', panel_fg_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
+               float padding = (item_width - stringwidth(s, false, hud_fontsize)) / 2;
+               drawstring(tmpos + vec2(padding, item_height), s, hud_fontsize, '1 1 1', panel_fg_alpha * scoreboard_itemstats_fade_alpha, DRAWFLAG_NORMAL);
                tmpos.x += item_width * rows;
                pos.x += item_width * rows;
-               if (rows == 2 && column == columnns - 1) {
+               if (rows == 2 && column == columns - 1) {
                        tmpos.x = oldposx;
                        tmpos.y += height;
                        pos.y += height;
@@ -1561,7 +1564,9 @@ vector Scoreboard_MapStats_Draw(vector pos, vector rgb, vector bg_size) {
        return end_pos;
 }
 
-
+int rankings_rows = 0;
+int rankings_columns = 0;
+int rankings_cnt = 0;
 vector Scoreboard_Rankings_Draw(vector pos, string ranktitle, entity pl, vector rgb, vector bg_size)
 {
        int i;
@@ -1575,7 +1580,6 @@ vector Scoreboard_Rankings_Draw(vector pos, string ranktitle, entity pl, vector
 
        vector hl_rgb = rgb + '0.5 0.5 0.5';
 
-       pos.y += hud_fontsize.y;
        drawstring(pos + eX * panel_bg_padding, ranktitle, hud_fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
        pos.y += 1.25 * hud_fontsize.y;
        if(panel.current_panel_bg != "0")
@@ -1600,16 +1604,20 @@ vector Scoreboard_Rankings_Draw(vector pos, string ranktitle, entity pl, vector
        float ranksize = 3 * hud_fontsize.x;
        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);
-       int rows = ceil(RANKINGS_RECEIVED_CNT / columns);
+       rankings_columns = max(1, floor((panel_size.x - 2 * panel_bg_padding) / columnsize.x));
+       rankings_columns = min(rankings_columns, RANKINGS_RECEIVED_CNT);
+       if (!rankings_cnt)
+       {
+               rankings_cnt = RANKINGS_RECEIVED_CNT;
+               rankings_rows = ceil(rankings_cnt / rankings_columns);
+       }
 
        // expand name column to fill the entire row
-       float available_space = (panel_size.x - 2 * panel_bg_padding - columnsize.x * columns) / columns;
+       float available_space = (panel_size.x - 2 * panel_bg_padding - columnsize.x * rankings_columns) / rankings_columns;
        namesize += available_space;
        columnsize.x += available_space;
 
-       panel_size.y = rows * 1.25 * hud_fontsize.y;
+       panel_size.y = rankings_rows * 1.25 * hud_fontsize.y;
        panel_size.y += panel_bg_padding * 2;
 
        HUD_Panel_DrawBg();
@@ -1633,7 +1641,7 @@ vector Scoreboard_Rankings_Draw(vector pos, string ranktitle, entity pl, vector
        string str = "";
        int column = 0, j = 0;
        string zoned_name_self = strzone(strdecolorize(entcs_GetName(player_localnum)));
-       for(i = 0; i < RANKINGS_RECEIVED_CNT; ++i)
+       for(i = 0; i < rankings_cnt; ++i)
        {
                float t;
                t = grecordtime[i];
@@ -1655,11 +1663,11 @@ vector Scoreboard_Rankings_Draw(vector pos, string ranktitle, entity pl, vector
 
                pos.y += 1.25 * hud_fontsize.y;
                j++;
-               if(j >= rows)
+               if(j >= rankings_rows)
                {
                        column++;
                        j = 0;
-                       pos.x += panel_size.x / columns;
+                       pos.x += panel_size.x / rankings_columns;
                        pos.y = panel_pos.y;
                }
        }
@@ -1762,6 +1770,8 @@ vector Scoreboard_Spectators_Draw(vector pos) {
                        break;
                }
        }
+       if (str != "") // if there's at least one spectator
+               pos.y += 0.5 * hud_fontsize.y;
 
        return pos;
 }
@@ -2069,16 +2079,21 @@ void Scoreboard_Draw()
 
        if(MUTATOR_CALLHOOK(ShowRankings)) {
                string ranktitle = M_ARGV(0, string);
+               string unit = GetSpeedUnit(autocvar_hud_panel_physics_speed_unit);
                if(race_speedaward) {
-                       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);
+                       drawcolorcodedstring(pos, sprintf(_("Speed award: %d%s ^7(%s^7)"), 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, ColorTranslateRGB(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, unit, ColorTranslateRGB(race_speedaward_alltimebest_holder)), hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
                        pos.y += 1.25 * hud_fontsize.y;
                }
+               if (race_speedaward || race_speedaward_alltimebest)
+                       pos.y += 0.25 * hud_fontsize.y;
                pos = Scoreboard_Rankings_Draw(pos, ranktitle, playerslots[player_localnum], panel_bg_color, bg_size);
        }
+       else
+               rankings_cnt = 0;
 
        // draw scoreboard spectators after rankings
        if (autocvar_hud_panel_scoreboard_spectators_position == 2) {
@@ -2095,8 +2110,7 @@ void Scoreboard_Draw()
 
        // print information about respawn status
        float respawn_time = STAT(RESPAWN_TIME);
-       if(!intermission)
-       if(respawn_time)
+       if(!intermission && respawn_time)
        {
                if(respawn_time < 0)
                {
@@ -2131,7 +2145,7 @@ void Scoreboard_Draw()
                drawcolorcodedstring(pos + '0.5 0 0' * (panel_size.x - stringwidth(str, true, hud_fontsize)), str, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
        }
 
-       pos.y += 2 * hud_fontsize.y;
+       pos.y += hud_fontsize.y;
        if (scoreboard_fade_alpha < 1)
                scoreboard_bottom = scoreboard_top + (pos.y - scoreboard_top) * scoreboard_fade_alpha;
        else if (pos.y != scoreboard_bottom)
@@ -2141,4 +2155,16 @@ void Scoreboard_Draw()
                else
                        scoreboard_bottom = max(pos.y, scoreboard_bottom - frametime * 10 * (pos.y - scoreboard_top));
        }
+
+       if (rankings_cnt)
+       {
+               if (scoreboard_fade_alpha == 1)
+               {
+                       if (scoreboard_bottom > 0.95 * vid_conheight)
+                               rankings_rows = max(1, rankings_rows - 1);
+                       else if (scoreboard_bottom + 1.25 * hud_fontsize.y < 0.95 * vid_conheight)
+                               rankings_rows = min(ceil(RANKINGS_RECEIVED_CNT / rankings_columns), rankings_rows + 1);
+               }
+               rankings_cnt = rankings_rows * rankings_columns;
+       }
 }