From: terencehill Date: Fri, 26 Jul 2019 14:18:10 +0000 (+0200) Subject: Item stats on the scoreboard by TimePath (rebased into master from TimePath/scoreboar... X-Git-Tag: xonotic-v0.8.5~588^2~25 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f297b7d7d546f2d0165b907985d2d6c53f054d13;p=xonotic%2Fxonotic-data.pk3dir.git Item stats on the scoreboard by TimePath (rebased into master from TimePath/scoreboard_item_stats). Currently it doesn't display anything due to a bug in the algorithm that networks item stats --- diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index 93162f6bc..bb4679e8b 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -13,6 +13,7 @@ #include #include #include +#include // Scoreboard (#24) @@ -1296,6 +1297,71 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size) return initial_pos + (end_pos - initial_pos) * scoreboard_acc_fade_alpha; } +vector Scoreboard_ItemStats_Draw(vector pos, vector rgb, vector bg_size) +{ + float initial_posx = pos.x; + int disownedcnt = 0; + FOREACH(Items, true, { + int q = g_inventory.inv_items[it.m_id]; + if (!q) ++disownedcnt; + }); + + int n = Items_COUNT - disownedcnt; + if (n <= 0) return pos; + + int rows = (autocvar_hud_panel_scoreboard_accuracy_doublerows && n >= floor(Items_COUNT / 2)) ? 2 : 1; + int columnns = ceil(n / rows); + + float height = 40; + float fontsize = height * 1/3; + float item_height = height * 2/3; + float item_width = panel_size.x / columnns / rows; + + drawstring(pos, _("Item stats"), hud_fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); + pos.y += 1.25 * hud_fontsize.y; + vector tmp = '0 0 0'; + tmp.x = panel_size.x; + tmp.y = height * rows; + + drawpic_tiled(pos, "gfx/scoreboard/scoreboard_bg", bg_size, tmp, panel_bg_color, panel_bg_alpha, DRAWFLAG_NORMAL); + + // column highlighting + for (int i = 0; i < columnns; ++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', panel_bg_alpha * 0.2, 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, '1 1 1', sbt_highlight_alpha, DRAWFLAG_NORMAL); + } + + if (rows == 2) pos.x += item_width / 2; + + float oldposx = pos.x; + vector tmpos = pos; + + int column = 0; + FOREACH(Items, true, { + int n = g_inventory.inv_items[it.m_id]; + 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, 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, DRAWFLAG_NORMAL); + tmpos.x += item_width * rows; + pos.x += item_width * rows; + if (rows == 2 && column == columnns - 1) { + tmpos.x = oldposx; + tmpos.y += height; + pos.y += height; + } + ++column; + }); + pos.y += height; + pos.y += 1.25 * hud_fontsize.y; + pos.x = initial_posx; + return pos; +} + vector MapStats_DrawKeyValue(vector pos, string key, string value) { float px = pos.x; pos.x += hud_fontsize.x * 0.25; @@ -1792,6 +1858,7 @@ void Scoreboard_Draw() if (Scoreboard_AccuracyStats_WouldDraw(pos.y)) pos = Scoreboard_AccuracyStats_Draw(pos, panel_bg_color, bg_size); + pos = Scoreboard_ItemStats_Draw(pos, panel_bg_color, bg_size); if(ISGAMETYPE(CTS) || ISGAMETYPE(RACE) || (autocvar_hud_panel_scoreboard_ctf_leaderboard && ISGAMETYPE(CTF) && STAT(CTF_SHOWLEADERBOARD))) { if(race_speedaward) {