From 2369679dc1b017fa22379289a86a247cdb471b30 Mon Sep 17 00:00:00 2001 From: VelocityRa Date: Wed, 4 Jan 2017 21:28:56 +0200 Subject: [PATCH] Use GUI font if spectator string contains special chars. --- Sources/Client/ScoreboardView.cpp | 35 +++++++++++++++++++++++-------- Sources/Client/ScoreboardView.h | 8 ++++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Sources/Client/ScoreboardView.cpp b/Sources/Client/ScoreboardView.cpp index 2c5bb4f7..a026be71 100644 --- a/Sources/Client/ScoreboardView.cpp +++ b/Sources/Client/ScoreboardView.cpp @@ -49,17 +49,32 @@ namespace spades { static const Vector4 spectatorTextColor = {220.f / 255, 220.f / 255, 0, 1}; // Goldish yellow static const auto spectatorTeamId = 255; // Spectators have a team id of 255 + ScoreboardView::ScoreboardView(Client *client) : client(client), renderer(client->GetRenderer()) { SPADES_MARK_FUNCTION(); - ctf = NULL; - tc = NULL; + world = nullptr; + tc = nullptr; + ctf = nullptr; + image = nullptr; + + // Use GUI font if spectator string has special chars + auto spectatorString = _TrN("Client", "Spectator{1}", "Spectators{1}", "", ""); + auto has_special_char = + std::find_if(spectatorString.begin(), spectatorString.end(), + [](char ch) { + return !(isalnum(static_cast(ch)) || ch == '_'); + }) != spectatorString.end(); + + spectatorFont = has_special_char ? + client->fontManager->GetLargeFont() : + client->fontManager->GetSquareDesignFont(); } ScoreboardView::~ScoreboardView() {} - int ScoreboardView::GetTeamScore(int team) { + int ScoreboardView::GetTeamScore(int team) const { if (ctf) { return ctf->GetTeam(team).score; } else if (tc) { @@ -79,7 +94,7 @@ namespace spades { return MakeVector4(c.x / 255.f, c.y / 255.f, c.z / 255.f, 1.f); } - Vector4 ScoreboardView::AdjustColor(spades::Vector4 col, float bright, float saturation) { + Vector4 ScoreboardView::AdjustColor(spades::Vector4 col, float bright, float saturation) const { col.x *= bright; col.y *= bright; col.z *= bright; @@ -294,8 +309,7 @@ namespace spades { } } - void ScoreboardView::DrawSpectators(float top, float centerX) { - IFont *bigFont = client->fontManager->GetSquareDesignFont(); + void ScoreboardView::DrawSpectators(float top, float centerX) const { IFont *font = client->fontManager->GetGuiFont(); char buf[256]; std::vector entries; @@ -330,9 +344,12 @@ namespace spades { strcpy(buf, _TrN("Client", "Spectator{1}", "Spectators{1}", numSpectators, ":").c_str()); - auto sizeSpecString = bigFont->Measure(buf); - bigFont->Draw(buf, MakeVector2(centerX - sizeSpecString.x / 2, top), 1.f, - spectatorTextColor); + auto isSquareFont = spectatorFont == client->fontManager->GetSquareDesignFont(); + auto sizeSpecString = spectatorFont->Measure(buf); + spectatorFont->Draw(buf, + MakeVector2(centerX - sizeSpecString.x / 2, top + (isSquareFont ? 0 : 10)), + 1.f, + spectatorTextColor); auto yOffset = top + sizeSpecString.y; auto halfTotalX = totalPixelWidth / 2; diff --git a/Sources/Client/ScoreboardView.h b/Sources/Client/ScoreboardView.h index 7cb2da07..9629d15b 100644 --- a/Sources/Client/ScoreboardView.h +++ b/Sources/Client/ScoreboardView.h @@ -30,6 +30,7 @@ namespace spades { class World; class CTFGameMode; class TCGameMode; + class IFont; class ScoreboardView { Client *client; IRenderer *renderer; @@ -38,16 +39,17 @@ namespace spades { World *world; CTFGameMode *ctf; TCGameMode *tc; + IFont *spectatorFont; - int GetTeamScore(int); + int GetTeamScore(int) const; Vector4 GetTeamColor(int); Vector4 AdjustColor(Vector4 col, float bright, - float saturation); + float saturation) const; void DrawPlayers(int team, float left, float top, float width, float height); - void DrawSpectators(float top, float width); + void DrawSpectators(float top, float width) const; bool areSpectatorsPresent() const; public: ScoreboardView(Client *);