From 1c0f5303809fd9b3c5cd32ffe8a620e56432b84e Mon Sep 17 00:00:00 2001 From: siecvi <25997662+siecvi@users.noreply.github.com> Date: Fri, 25 Oct 2024 20:34:12 -0300 Subject: [PATCH] draw alive player count on scoreboard --- Sources/Client/Client_Draw.cpp | 30 +++++++------ Sources/Client/ScoreboardView.cpp | 71 ++++++++++++++++++++++++------- Sources/Client/ScoreboardView.h | 1 + 3 files changed, 72 insertions(+), 30 deletions(-) diff --git a/Sources/Client/Client_Draw.cpp b/Sources/Client/Client_Draw.cpp index 38608de..9a4af76 100644 --- a/Sources/Client/Client_Draw.cpp +++ b/Sources/Client/Client_Draw.cpp @@ -258,6 +258,9 @@ namespace spades { void Client::DrawAlivePlayersCount() { int playerCountStyle = cg_hudPlayerCount; + if (playerCountStyle >= 3) + return; // draw on scoreboard + int statsStyle = cg_stats; bool isSmallFont = cg_statsSmallFont; @@ -265,7 +268,7 @@ namespace spades { float sh = renderer->ScreenHeight(); float teamBarW = 30.0F; - float teamBarH = 45.0F; + float teamBarH = 40.0F; float spacing = isSmallFont ? 40.0F : 50.0F; @@ -280,7 +283,7 @@ namespace spades { float teamBarY = (playerCountStyle < 2) ? y : ((sh - y) - teamBarH); Handle img; - IFont& font = fontManager->GetMediumFont(); + IFont& font = fontManager->GetHeadingFont(); Vector2 pos, size; std::string str; @@ -300,25 +303,25 @@ namespace spades { } // draw team bar - renderer->SetColorAlphaPremultiplied(col1); + renderer->SetColorAlphaPremultiplied(brightCol1); renderer->DrawImage(img, AABB2(x - teamBarW, teamBarY, teamBarW, 2)); - renderer->SetColorAlphaPremultiplied(col2); + renderer->SetColorAlphaPremultiplied(brightCol2); renderer->DrawImage(img, AABB2(x, teamBarY, teamBarW, 2)); // draw player icon img = renderer->RegisterImage("Gfx/User.png"); - Vector2 iconSize = MakeVector2(12.0F, 10.0F); + + float iconSize = 12.0F; float iconSpacing = 5.0F; - - pos.x = x - (teamBarW * 0.5F) - (iconSize.x * 0.5F); - pos.y = teamBarY + iconSize.y - iconSpacing; + + pos.x = x - (teamBarW * 0.5F) - (iconSize * 0.5F); + pos.y = (teamBarY - 2.0F) + iconSize - iconSpacing; renderer->SetColorAlphaPremultiplied(shadowColor); renderer->DrawImage(img, pos + MakeVector2(1, 1)); renderer->SetColorAlphaPremultiplied(brightCol1); renderer->DrawImage(img, pos); - pos.x = x + (teamBarW * 0.5F) - (iconSize.x * 0.5F); - pos.y = teamBarY + iconSize.y - iconSpacing; + pos.x = x + (teamBarW * 0.5F) - (iconSize * 0.5F); renderer->SetColorAlphaPremultiplied(shadowColor); renderer->DrawImage(img, pos + MakeVector2(1, 1)); renderer->SetColorAlphaPremultiplied(brightCol2); @@ -327,15 +330,14 @@ namespace spades { // draw player count str = ToString(world->GetNumPlayersAlive(0)); size = font.Measure(str); - pos.x = x - (teamBarW * 0.5F) - size.x * 0.5F; - pos.y = teamBarY + iconSize.y + iconSpacing; + pos.x = x - (teamBarW * 0.5F) - (size.x * 0.5F); + pos.y = (teamBarY - 2.0F) + iconSize + iconSpacing; font.Draw(str, pos + MakeVector2(1, 1), 1.0F, shadowColor); font.Draw(str, pos, 1.0F, brightCol1); str = ToString(world->GetNumPlayersAlive(1)); size = font.Measure(str); - pos.x = x + (teamBarW * 0.5F) - size.x * 0.5F; - pos.y = teamBarY + iconSize.y + iconSpacing; + pos.x = x + (teamBarW * 0.5F) - (size.x * 0.5F); font.Draw(str, pos + MakeVector2(1, 1), 1.0F, shadowColor); font.Draw(str, pos, 1.0F, brightCol2); } diff --git a/Sources/Client/ScoreboardView.cpp b/Sources/Client/ScoreboardView.cpp index 0826f3c..69b68ed 100644 --- a/Sources/Client/ScoreboardView.cpp +++ b/Sources/Client/ScoreboardView.cpp @@ -40,6 +40,7 @@ #include SPADES_SETTING(cg_minimapPlayerColor); +SPADES_SETTING(cg_hudPlayerCount); namespace spades { namespace client { @@ -87,6 +88,16 @@ namespace spades { } } + int ScoreboardView::GetCaptureLimit() const { + if (ctf) { + return ctf->GetCaptureLimit(); + } else if (tc) { + return tc->GetNumTerritories(); + } else { + return -1; + } + } + Vector4 ScoreboardView::GetTeamColor(int team) { return ConvertColorRGBA(world->GetTeamColor(team)); } @@ -116,6 +127,8 @@ namespace spades { float sw = renderer.ScreenWidth(); float sh = renderer.ScreenHeight(); + Vector2 scrCenter = MakeVector2(sw, sh) * 0.5F; + float contentsWidth = sw + 8.0F; float maxContentsWidth = 800.0F; if (contentsWidth > maxContentsWidth) @@ -147,9 +160,9 @@ namespace spades { // draw team bar img = renderer.RegisterImage("Gfx/White.tga"); renderer.SetColorAlphaPremultiplied(AdjustColor(GetTeamColor(0), 0.8F, 0.3F)); - renderer.DrawImage(img, AABB2(0, teamBarTop, sw * 0.5F, teamBarHeight)); + renderer.DrawImage(img, AABB2(0, teamBarTop, scrCenter.x, teamBarHeight)); renderer.SetColorAlphaPremultiplied(AdjustColor(GetTeamColor(1), 0.8F, 0.3F)); - renderer.DrawImage(img, AABB2(sw * 0.5F, teamBarTop, sw * 0.5F, teamBarHeight)); + renderer.DrawImage(img, AABB2(scrCenter.x, teamBarTop, scrCenter.x, teamBarHeight)); img = renderer.RegisterImage("Gfx/Scoreboard/Grunt.png"); size.x = 120.0F; @@ -157,6 +170,7 @@ namespace spades { renderer.DrawImage(img, AABB2(contentsLeft, playersTop - size.y, size.x, size.y)); renderer.DrawImage(img, AABB2(contentsRight, playersTop - size.y, -size.x, size.y)); + // draw team name str = world->GetTeamName(0); pos.x = contentsLeft + 120.0F; pos.y = teamBarTop + 5.0F; @@ -164,29 +178,54 @@ namespace spades { font.Draw(str, pos, 1.0F, white); str = world->GetTeamName(1); - pos.x = contentsRight - 120.0F - font.Measure(str).x; + pos.x = contentsRight - font.Measure(str).x - 120.0F; pos.y = teamBarTop + 5.0F; font.Draw(str, pos + MakeVector2(1, 2), 1.0F, MakeVector4(0, 0, 0, 0.5)); font.Draw(str, pos, 1.0F, white); - // draw scores - int capLimit; - if (ctf) - capLimit = ctf->GetCaptureLimit(); - else if (tc) - capLimit = tc->GetNumTerritories(); - else - capLimit = -1; + // draw alive player count + if ((int)cg_hudPlayerCount >= 3) { + img = renderer.RegisterImage("Gfx/User.png"); + + IFont& guiFont = client->fontManager->GetGuiFont(); + + float iconSize = 12.0F; + float counterTop = playersTop - 10.0F; + + // team 1 + str = ToString(world->GetNumPlayersAlive(0)); + size = guiFont.Measure(str); + pos.x = scrCenter.x - 5.0F - iconSize; + pos.y = counterTop - 2.0F - (size.y - iconSize) * 0.5F; + renderer.SetColorAlphaPremultiplied(white * 0.5F); + renderer.DrawImage(img, pos); + + pos.x -= size.x + 2.0F; + pos.y = counterTop - size.y * 0.5F; + guiFont.Draw(str, pos, 1.0F, MakeVector4(1, 1, 1, 0.5)); + + // team 2 + str = ToString(world->GetNumPlayersAlive(1)); + pos.x = scrCenter.x + 5.0F; + pos.y = counterTop - 2.0F - (size.y - iconSize) * 0.5F; + renderer.SetColorAlphaPremultiplied(white * 0.5F); + renderer.DrawImage(img, pos); + + pos.x += iconSize + 2.0F; + pos.y = counterTop - size.y * 0.5F; + guiFont.Draw(str, pos, 1.0F, MakeVector4(1, 1, 1, 0.5)); + } + // draw scores + int capLimit = GetCaptureLimit(); if (capLimit != -1) { str = Format("{0}-{1}", GetTeamScore(0), capLimit); - pos.x = sw * 0.5F - font.Measure(str).x - 15.0F; + pos.x = scrCenter.x - font.Measure(str).x - 15.0F; pos.y = teamBarTop + 5.0F; font.Draw(str, pos, 1.0F, MakeVector4(1, 1, 1, 0.5)); str = Format("{0}-{1}", GetTeamScore(1), capLimit); - pos.x = sw * 0.5F + 15.0F; - pos.y = teamBarTop + 5.0F; + pos.x = scrCenter.x + 15.0F; font.Draw(str, pos, 1.0F, MakeVector4(1, 1, 1, 0.5)); } @@ -197,9 +236,9 @@ namespace spades { // draw players DrawPlayers(0, contentsLeft, playersTop, (contentsRight - contentsLeft) * 0.5F, playersHeight); - DrawPlayers(1, (sw - 8.0F) * 0.5F, playersTop, (contentsRight - contentsLeft) * 0.5F, playersHeight); + DrawPlayers(1, scrCenter.x - 8.0F, playersTop, (contentsRight - contentsLeft) * 0.5F, playersHeight); if (areSpectatorsPr) - DrawSpectators(playersBottom, sw * 0.5F); + DrawSpectators(playersBottom, scrCenter.x); } struct ScoreboardEntry { diff --git a/Sources/Client/ScoreboardView.h b/Sources/Client/ScoreboardView.h index d1cf6c6..5b44c4a 100644 --- a/Sources/Client/ScoreboardView.h +++ b/Sources/Client/ScoreboardView.h @@ -41,6 +41,7 @@ namespace spades { Handle spectatorFont; Handle intelIcon; + int GetCaptureLimit() const; int GetTeamScore(int) const; Vector4 GetTeamColor(int); void DrawPlayers(int team, float left, float top, float width, float height);