diff options
Diffstat (limited to 'src/game/client')
| -rw-r--r-- | src/game/client/components/hud.cpp | 34 | ||||
| -rw-r--r-- | src/game/client/components/menus_ingame.cpp | 42 | ||||
| -rw-r--r-- | src/game/client/components/voting.cpp | 24 | ||||
| -rw-r--r-- | src/game/client/components/voting.h | 11 |
4 files changed, 51 insertions, 60 deletions
diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index a9869bb3..c0273cfe 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -293,34 +293,40 @@ void CHud::RenderVoting() Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); Graphics()->SetColor(0,0,0,0.40f); - RenderTools()->DrawRoundRect(-10, 60-2, 100+10+4+5, 28, 5.0f); + RenderTools()->DrawRoundRect(-10, 60-2, 100+10+4+5, 46, 5.0f); Graphics()->QuadsEnd(); TextRender()->TextColor(1,1,1,1); - char Buf[512]; - str_format(Buf, sizeof(Buf), Localize("%ds left"), m_pClient->m_pVoting->SecondsLeft()); - float tw = TextRender()->TextWidth(0x0, 6, Buf, -1); - CTextCursor Cursor; - TextRender()->SetCursor(&Cursor, 5.0f, 60.0f, 6.0f, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END); - Cursor.m_LineWidth = 100-tw; + char aBuf[512]; + str_format(aBuf, sizeof(aBuf), Localize("%ds left"), m_pClient->m_pVoting->SecondsLeft()); + float tw = TextRender()->TextWidth(0x0, 6, aBuf, -1); + 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_pVoting->VoteDescription(), -1); - - TextRender()->Text(0x0, 5+100-tw, 60, 6, Buf, -1); + // reason + str_format(aBuf, sizeof(aBuf), "%s %s", Localize("Reason:"), m_pClient->m_pVoting->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, 70, 100, 4}; + CUIRect Base = {5, 88, 100, 4}; m_pClient->m_pVoting->RenderBars(Base, false); const char *pYesKey = m_pClient->m_pBinds->GetKey("vote yes"); const char *pNoKey = m_pClient->m_pBinds->GetKey("vote no"); - str_format(Buf, sizeof(Buf), "%s - %s", pYesKey, Localize("Vote yes")); + str_format(aBuf, sizeof(aBuf), "%s - %s", pYesKey, Localize("Vote yes")); Base.y += Base.h+1; - UI()->DoLabel(&Base, Buf, 6.0f, -1); + UI()->DoLabel(&Base, aBuf, 6.0f, -1); - str_format(Buf, sizeof(Buf), "%s - %s", Localize("Vote no"), pNoKey); - UI()->DoLabel(&Base, Buf, 6.0f, 1); + str_format(aBuf, sizeof(aBuf), "%s - %s", Localize("Vote no"), pNoKey); + UI()->DoLabel(&Base, aBuf, 6.0f, 1); } void CHud::RenderCursor() diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index c9d39be1..ad43fc20 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -323,11 +323,6 @@ void CMenus::RenderServerInfo(CUIRect MainView) TextRender()->Text(0, Motd.x+x, Motd.y+y, 16, m_pClient->m_pMotd->m_aServerMotd, (int)Motd.w); } -static const char *FormatCommand(const char *pCmd) -{ - return pCmd; -} - void CMenus::RenderServerControlServer(CUIRect MainView) { int NumOptions = 0; @@ -344,7 +339,7 @@ void CMenus::RenderServerControlServer(CUIRect MainView) CListboxItem Item = UiDoListboxNextItem(pOption); if(Item.m_Visible) - UI()->DoLabelScaled(&Item.m_Rect, FormatCommand(pOption->m_aDescription), 16.0f, -1); + UI()->DoLabelScaled(&Item.m_Rect, pOption->m_aDescription, 16.0f, -1); } m_CallvoteSelectedOption = UiDoListboxEnd(&s_ScrollValue, 0); @@ -440,13 +435,7 @@ void CMenus::RenderServerControl(CUIRect MainView) if(DoButton_Menu(&s_CallVoteButton, Localize("Call vote"), 0, &Button)) { if(s_ControlPage == 0) - { - // - m_pClient->m_pVoting->CallvoteOption(m_CallvoteSelectedOption); - /* - if(callvote_selectedmap >= 0 && callvote_selectedmap < gameclient.maplist->num()) - gameclient.voting->callvote_map(gameclient.maplist->name(callvote_selectedmap));*/ - } + m_pClient->m_pVoting->CallvoteOption(m_CallvoteSelectedOption, m_aCallvoteReason); else if(s_ControlPage == 1) { if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS && @@ -460,19 +449,16 @@ void CMenus::RenderServerControl(CUIRect MainView) } // render kick reason - if(s_ControlPage == 1) - { - CUIRect Reason; - Bottom.VSplitRight(40.0f, &Bottom, 0); - Bottom.VSplitRight(160.0f, &Bottom, &Reason); - Reason.HSplitTop(5.0f, 0, &Reason); - const char *pLabel = Localize("Reason:"); - UI()->DoLabelScaled(&Reason, pLabel, 14.0f, -1); - float w = TextRender()->TextWidth(0, 14.0f, pLabel, -1); - Reason.VSplitLeft(w+10.0f, 0, &Reason); - static float s_Offset = 0.0f; - DoEditBox(&m_aCallvoteReason, &Reason, m_aCallvoteReason, sizeof(m_aCallvoteReason), 14.0f, &s_Offset, false, CUI::CORNER_ALL); - } + CUIRect Reason; + Bottom.VSplitRight(40.0f, &Bottom, 0); + Bottom.VSplitRight(160.0f, &Bottom, &Reason); + Reason.HSplitTop(5.0f, 0, &Reason); + const char *pLabel = Localize("Reason:"); + UI()->DoLabelScaled(&Reason, pLabel, 14.0f, -1); + float w = TextRender()->TextWidth(0, 14.0f, pLabel, -1); + Reason.VSplitLeft(w+10.0f, 0, &Reason); + static float s_Offset = 0.0f; + DoEditBox(&m_aCallvoteReason, &Reason, m_aCallvoteReason, sizeof(m_aCallvoteReason), 14.0f, &s_Offset, false, CUI::CORNER_ALL); // force vote button (only available when authed in rcon) if(Client()->RconAuthed()) @@ -483,9 +469,7 @@ void CMenus::RenderServerControl(CUIRect MainView) if(DoButton_Menu(&s_ForceVoteButton, Localize("Force vote"), 0, &Button)) { if(s_ControlPage == 0) - { - m_pClient->m_pVoting->ForcevoteOption(m_CallvoteSelectedOption); - } + m_pClient->m_pVoting->ForcevoteOption(m_CallvoteSelectedOption, m_aCallvoteReason); else if(s_ControlPage == 1) { if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS && diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp index 3718a20a..1f99f4b3 100644 --- a/src/game/client/components/voting.cpp +++ b/src/game/client/components/voting.cpp @@ -5,13 +5,12 @@ #include <game/generated/protocol.h> #include <base/vmath.h> #include <game/client/render.h> -//#include <game/client/gameclient.h> #include "voting.h" void CVoting::ConCallvote(IConsole::IResult *pResult, void *pUserData) { CVoting *pSelf = (CVoting*)pUserData; - pSelf->Callvote(pResult->GetString(0), pResult->GetString(1)); + pSelf->Callvote(pResult->GetString(0), pResult->GetString(1), pResult->NumArguments() > 2 ? pResult->GetString(2) : ""); } void CVoting::ConVote(IConsole::IResult *pResult, void *pUserData) @@ -23,32 +22,30 @@ void CVoting::ConVote(IConsole::IResult *pResult, void *pUserData) pSelf->Vote(-1); } -void CVoting::Callvote(const char *pType, const char *pValue) +void CVoting::Callvote(const char *pType, const char *pValue, const char *pReason) { CNetMsg_Cl_CallVote Msg = {0}; Msg.m_Type = pType; Msg.m_Value = pValue; + Msg.m_Reason = pReason; Client()->SendPackMsg(&Msg, MSGFLAG_VITAL); } void CVoting::CallvoteKick(int ClientID, const char *pReason) { char aBuf[32]; - if(pReason[0]) - str_format(aBuf, sizeof(aBuf), "%d %s", ClientID, pReason); - else - str_format(aBuf, sizeof(aBuf), "%d", ClientID); - Callvote("kick", aBuf); + str_format(aBuf, sizeof(aBuf), "%d", ClientID); + Callvote("kick", aBuf, pReason); } -void CVoting::CallvoteOption(int OptionId) +void CVoting::CallvoteOption(int OptionId, const char *pReason) { CVoteOption *pOption = m_pFirst; while(pOption && OptionId >= 0) { if(OptionId == 0) { - Callvote("option", pOption->m_aDescription); + Callvote("option", pOption->m_aDescription, pReason); break; } @@ -57,6 +54,7 @@ void CVoting::CallvoteOption(int OptionId) } } +// TODO: fix these two void CVoting::ForcevoteKick(int ClientID, const char *pReason) { char aBuf[32]; @@ -67,7 +65,7 @@ void CVoting::ForcevoteKick(int ClientID, const char *pReason) Client()->Rcon(aBuf); } -void CVoting::ForcevoteOption(int OptionId) +void CVoting::ForcevoteOption(int OptionId, const char *pReason) { CVoteOption *pOption = m_pFirst; while(pOption && OptionId >= 0) @@ -108,13 +106,14 @@ void CVoting::OnReset() { m_Closetime = 0; m_aDescription[0] = 0; + m_aReason[0] = 0; m_Yes = m_No = m_Pass = m_Total = 0; m_Voted = 0; } void CVoting::OnConsoleInit() { - Console()->Register("callvote", "sr", CFGFLAG_CLIENT, ConCallvote, this, "Call vote"); + Console()->Register("callvote", "ss?r", CFGFLAG_CLIENT, ConCallvote, this, "Call vote"); Console()->Register("vote", "r", CFGFLAG_CLIENT, ConVote, this, "Vote yes/no"); } @@ -127,6 +126,7 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) { OnReset(); str_copy(m_aDescription, pMsg->m_pDescription, sizeof(m_aDescription)); + str_copy(m_aReason, pMsg->m_pReason, sizeof(m_aReason)); m_Closetime = time_get() + time_freq() * pMsg->m_Timeout; } else diff --git a/src/game/client/components/voting.h b/src/game/client/components/voting.h index 151ecbfc..10e0512c 100644 --- a/src/game/client/components/voting.h +++ b/src/game/client/components/voting.h @@ -15,10 +15,12 @@ class CVoting : public CComponent int64 m_Closetime; char m_aDescription[64]; + char m_aReason[16]; int m_Voted; + int m_Yes, m_No, m_Pass, m_Total; void ClearOptions(); - void Callvote(const char *pType, const char *pValue); + void Callvote(const char *pType, const char *pValue, const char *pReason); public: @@ -41,9 +43,9 @@ public: void RenderBars(CUIRect Bars, bool Text); void CallvoteKick(int ClientID, const char *pReason); - void CallvoteOption(int Option); + void CallvoteOption(int Option, const char *pReason); void ForcevoteKick(int ClientID, const char *pReason); - void ForcevoteOption(int Option); + void ForcevoteOption(int Option, const char *pReason); void Vote(int v); // -1 = no, 1 = yes @@ -51,8 +53,7 @@ public: bool IsVoting() { return m_Closetime != 0; } int TakenChoice() const { return m_Voted; } const char *VoteDescription() const { return m_aDescription; } - - int m_Yes, m_No, m_Pass, m_Total; + const char *VoteReason() const { return m_aReason; } }; #endif |