Skip to content

Commit

Permalink
draw alive player count on scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
siecvi committed Oct 25, 2024
1 parent fdbe854 commit 1c0f530
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 30 deletions.
30 changes: 16 additions & 14 deletions Sources/Client/Client_Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,17 @@ namespace spades {

void Client::DrawAlivePlayersCount() {
int playerCountStyle = cg_hudPlayerCount;
if (playerCountStyle >= 3)
return; // draw on scoreboard

int statsStyle = cg_stats;
bool isSmallFont = cg_statsSmallFont;

float sw = renderer->ScreenWidth();
float sh = renderer->ScreenHeight();

float teamBarW = 30.0F;
float teamBarH = 45.0F;
float teamBarH = 40.0F;

float spacing = isSmallFont ? 40.0F : 50.0F;

Expand All @@ -280,7 +283,7 @@ namespace spades {
float teamBarY = (playerCountStyle < 2) ? y : ((sh - y) - teamBarH);

Handle<IImage> img;
IFont& font = fontManager->GetMediumFont();
IFont& font = fontManager->GetHeadingFont();
Vector2 pos, size;
std::string str;

Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
71 changes: 55 additions & 16 deletions Sources/Client/ScoreboardView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <Core/Strings.h>

SPADES_SETTING(cg_minimapPlayerColor);
SPADES_SETTING(cg_hudPlayerCount);

namespace spades {
namespace client {
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -147,46 +160,72 @@ 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;
size.y = 60.0F;
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;
font.Draw(str, pos + MakeVector2(1, 2), 1.0F, MakeVector4(0, 0, 0, 0.5));
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));
}

Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions Sources/Client/ScoreboardView.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace spades {
Handle<IFont> spectatorFont;
Handle<IImage> intelIcon;

int GetCaptureLimit() const;
int GetTeamScore(int) const;
Vector4 GetTeamColor(int);
void DrawPlayers(int team, float left, float top, float width, float height);
Expand Down

0 comments on commit 1c0f530

Please sign in to comment.