From dfc2e807014cdfbcfa3bcc6be2daf9ff5fc23990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 29 Jan 2024 21:59:20 +0100 Subject: [PATCH] Move voting rendering from `CHud` to `CVoting` --- src/game/client/components/hud.cpp | 53 +---------------------- src/game/client/components/voting.cpp | 62 ++++++++++++++++++++++++--- src/game/client/components/voting.h | 5 ++- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 434e0736c..d0b9e7b8e 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -562,57 +562,6 @@ void CHud::RenderTeambalanceWarning() } } -void CHud::RenderVoting() -{ - if((!g_Config.m_ClShowVotesAfterVoting && !m_pClient->m_Scoreboard.Active() && m_pClient->m_Voting.TakenChoice()) || !m_pClient->m_Voting.IsVoting() || Client()->State() == IClient::STATE_DEMOPLAYBACK) - return; - - Graphics()->DrawRect(-10, 60 - 2, 100 + 10 + 4 + 5, 46, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_ALL, 5.0f); - - TextRender()->TextColor(TextRender()->DefaultTextColor()); - - CTextCursor Cursor; - char aBuf[512]; - str_format(aBuf, sizeof(aBuf), Localize("%ds left"), m_pClient->m_Voting.SecondsLeft()); - float tw = TextRender()->TextWidth(6, aBuf, -1, -1.0f); - TextRender()->SetCursor(&Cursor, 5.0f + 100.0f - tw, 60.0f, 6.0f, TEXTFLAG_RENDER); - TextRender()->TextEx(&Cursor, aBuf, -1); - - TextRender()->SetCursor(&Cursor, 5.0f, 60.0f, 6.0f, TEXTFLAG_RENDER); - Cursor.m_LineWidth = 100.0f - tw; - Cursor.m_MaxLines = 3; - TextRender()->TextEx(&Cursor, m_pClient->m_Voting.VoteDescription(), -1); - - // reason - str_format(aBuf, sizeof(aBuf), "%s %s", Localize("Reason:"), m_pClient->m_Voting.VoteReason()); - TextRender()->SetCursor(&Cursor, 5.0f, 79.0f, 6.0f, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END); - Cursor.m_LineWidth = 100.0f; - TextRender()->TextEx(&Cursor, aBuf, -1); - - CUIRect Base = {5, 88, 100, 4}; - m_pClient->m_Voting.RenderBars(Base); - - char aKey[64]; - m_pClient->m_Binds.GetKey("vote yes", aKey, sizeof(aKey)); - - str_format(aBuf, sizeof(aBuf), "%s - %s", aKey, Localize("Vote yes")); - Base.y += Base.h; - Base.h = 12.0f; - if(m_pClient->m_Voting.TakenChoice() == 1) - TextRender()->TextColor(ColorRGBA(0.2f, 0.9f, 0.2f, 0.85f)); - UI()->DoLabel(&Base, aBuf, 6.0f, TEXTALIGN_ML); - - TextRender()->TextColor(TextRender()->DefaultTextColor()); - - m_pClient->m_Binds.GetKey("vote no", aKey, sizeof(aKey)); - str_format(aBuf, sizeof(aBuf), "%s - %s", Localize("Vote no"), aKey); - if(m_pClient->m_Voting.TakenChoice() == -1) - TextRender()->TextColor(ColorRGBA(0.9f, 0.2f, 0.2f, 0.85f)); - UI()->DoLabel(&Base, aBuf, 6.0f, TEXTALIGN_MR); - - TextRender()->TextColor(TextRender()->DefaultTextColor()); -} - void CHud::RenderCursor() { if(!m_pClient->m_Snap.m_pLocalCharacter || Client()->State() == IClient::STATE_DEMOPLAYBACK) @@ -1497,7 +1446,7 @@ void CHud::OnRender() if(Client()->State() != IClient::STATE_DEMOPLAYBACK) RenderConnectionWarning(); RenderTeambalanceWarning(); - RenderVoting(); + m_pClient->m_Voting.Render(); if(g_Config.m_ClShowRecord) RenderRecord(); } diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp index 180851ce1..bdd6a154d 100644 --- a/src/game/client/components/voting.cpp +++ b/src/game/client/components/voting.cpp @@ -1,13 +1,16 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ -#include - #include "voting.h" + +#include +#include + +#include #include +#include #include #include - -#include +#include void CVoting::ConCallvote(IConsole::IResult *pResult, void *pUserData) { @@ -311,11 +314,58 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) } } -void CVoting::OnRender() +void CVoting::Render() { + if((!g_Config.m_ClShowVotesAfterVoting && !m_pClient->m_Scoreboard.Active() && TakenChoice()) || !IsVoting() || Client()->State() == IClient::STATE_DEMOPLAYBACK) + return; + + Graphics()->DrawRect(-10, 60 - 2, 100 + 10 + 4 + 5, 46, ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), IGraphics::CORNER_ALL, 5.0f); + + TextRender()->TextColor(TextRender()->DefaultTextColor()); + + CTextCursor Cursor; + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), Localize("%ds left"), SecondsLeft()); + float tw = TextRender()->TextWidth(6, aBuf, -1, -1.0f); + TextRender()->SetCursor(&Cursor, 5.0f + 100.0f - tw, 60.0f, 6.0f, TEXTFLAG_RENDER); + TextRender()->TextEx(&Cursor, aBuf, -1); + + TextRender()->SetCursor(&Cursor, 5.0f, 60.0f, 6.0f, TEXTFLAG_RENDER); + Cursor.m_LineWidth = 100.0f - tw; + Cursor.m_MaxLines = 3; + TextRender()->TextEx(&Cursor, VoteDescription(), -1); + + // reason + str_format(aBuf, sizeof(aBuf), "%s %s", Localize("Reason:"), VoteReason()); + TextRender()->SetCursor(&Cursor, 5.0f, 79.0f, 6.0f, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END); + Cursor.m_LineWidth = 100.0f; + TextRender()->TextEx(&Cursor, aBuf, -1); + + CUIRect Base = {5, 88, 100, 4}; + RenderBars(Base); + + char aKey[64]; + m_pClient->m_Binds.GetKey("vote yes", aKey, sizeof(aKey)); + + str_format(aBuf, sizeof(aBuf), "%s - %s", aKey, Localize("Vote yes")); + Base.y += Base.h; + Base.h = 12.0f; + if(TakenChoice() == 1) + TextRender()->TextColor(ColorRGBA(0.2f, 0.9f, 0.2f, 0.85f)); + UI()->DoLabel(&Base, aBuf, 6.0f, TEXTALIGN_ML); + + TextRender()->TextColor(TextRender()->DefaultTextColor()); + + m_pClient->m_Binds.GetKey("vote no", aKey, sizeof(aKey)); + str_format(aBuf, sizeof(aBuf), "%s - %s", Localize("Vote no"), aKey); + if(TakenChoice() == -1) + TextRender()->TextColor(ColorRGBA(0.9f, 0.2f, 0.2f, 0.85f)); + UI()->DoLabel(&Base, aBuf, 6.0f, TEXTALIGN_MR); + + TextRender()->TextColor(TextRender()->DefaultTextColor()); } -void CVoting::RenderBars(CUIRect Bars) +void CVoting::RenderBars(CUIRect Bars) const { Bars.Draw(ColorRGBA(0.8f, 0.8f, 0.8f, 0.5f), IGraphics::CORNER_ALL, Bars.h / 3); diff --git a/src/game/client/components/voting.h b/src/game/client/components/voting.h index 930e197ab..978463c6b 100644 --- a/src/game/client/components/voting.h +++ b/src/game/client/components/voting.h @@ -29,6 +29,8 @@ class CVoting : public CComponent void ClearOptions(); void Callvote(const char *pType, const char *pValue, const char *pReason); + void RenderBars(CUIRect Bars) const; + public: int m_NumVoteOptions; CVoteOptionClient *m_pFirst; @@ -42,9 +44,8 @@ public: virtual void OnReset() override; virtual void OnConsoleInit() override; virtual void OnMessage(int Msgtype, void *pRawMsg) override; - virtual void OnRender() override; - void RenderBars(CUIRect Bars); + void Render(); void CallvoteSpectate(int ClientID, const char *pReason, bool ForceVote = false); void CallvoteKick(int ClientID, const char *pReason, bool ForceVote = false);