Move voting rendering from CHud to CVoting

This commit is contained in:
Robert Müller 2024-01-29 21:59:20 +01:00
parent df95ca74ec
commit dfc2e80701
3 changed files with 60 additions and 60 deletions

View file

@ -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();
}

View file

@ -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 <engine/shared/config.h>
#include "voting.h"
#include <engine/shared/config.h>
#include <engine/textrender.h>
#include <game/client/components/scoreboard.h>
#include <game/client/components/sounds.h>
#include <game/client/gameclient.h>
#include <game/client/render.h>
#include <game/generated/protocol.h>
#include <game/client/gameclient.h>
#include <game/localization.h>
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);

View file

@ -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);