| 1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
| 2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
| 3 | #ifndef GAME_CLIENT_COMPONENTS_VOTING_H |
| 4 | #define GAME_CLIENT_COMPONENTS_VOTING_H |
| 5 | |
| 6 | #include <engine/console.h> |
| 7 | #include <engine/shared/memheap.h> |
| 8 | |
| 9 | #include <game/client/component.h> |
| 10 | #include <game/client/ui_rect.h> |
| 11 | #include <game/voting.h> |
| 12 | |
| 13 | class CVoting : public CComponent |
| 14 | { |
| 15 | CHeap m_Heap; |
| 16 | |
| 17 | static void ConCallvote(IConsole::IResult *pResult, void *pUserData); |
| 18 | static void ConVote(IConsole::IResult *pResult, void *pUserData); |
| 19 | |
| 20 | int64_t m_Opentime; |
| 21 | int64_t m_Closetime; |
| 22 | char m_aDescription[VOTE_DESC_LENGTH]; |
| 23 | char m_aReason[VOTE_REASON_LENGTH]; |
| 24 | int m_Voted; |
| 25 | int m_Yes, m_No, m_Pass, m_Total; |
| 26 | bool m_ReceivingOptions; |
| 27 | |
| 28 | int m_NumVoteOptions; |
| 29 | CVoteOptionClient *m_pFirst; |
| 30 | CVoteOptionClient *m_pLast; |
| 31 | |
| 32 | CVoteOptionClient *m_pRecycleFirst; |
| 33 | CVoteOptionClient *m_pRecycleLast; |
| 34 | |
| 35 | void RemoveOption(const char *pDescription); |
| 36 | void ClearOptions(); |
| 37 | void Callvote(const char *pType, const char *pValue, const char *pReason); |
| 38 | |
| 39 | void RenderBars(CUIRect Bars) const; |
| 40 | |
| 41 | public: |
| 42 | CVoting(); |
| 43 | int Sizeof() const override { return sizeof(*this); } |
| 44 | void OnReset() override; |
| 45 | void OnConsoleInit() override; |
| 46 | void OnMessage(int MsgType, void *pRawMsg) override; |
| 47 | |
| 48 | void Render(); |
| 49 | |
| 50 | void CallvoteSpectate(int ClientId, const char *pReason, bool ForceVote = false); |
| 51 | void CallvoteKick(int ClientId, const char *pReason, bool ForceVote = false); |
| 52 | void CallvoteOption(int OptionId, const char *pReason, bool ForceVote = false); |
| 53 | void RemovevoteOption(int OptionId); |
| 54 | void AddvoteOption(const char *pDescription, const char *pCommand); |
| 55 | void AddOption(const char *pDescription); |
| 56 | |
| 57 | void Vote(int v); // -1 = no, 1 = yes |
| 58 | |
| 59 | int SecondsLeft() const; |
| 60 | bool IsVoting() const { return m_Closetime != 0; } |
| 61 | int TakenChoice() const { return m_Voted; } |
| 62 | const char *VoteDescription() const { return m_aDescription; } |
| 63 | const char *VoteReason() const { return m_aReason; } |
| 64 | bool IsReceivingOptions() const { return m_ReceivingOptions; } |
| 65 | int NumOptions() const { return m_NumVoteOptions; } |
| 66 | const CVoteOptionClient *FirstOption() const { return m_pFirst; } |
| 67 | }; |
| 68 | |
| 69 | #endif |
| 70 | |