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/voting.h> |
11 | |
12 | class CUIRect; |
13 | |
14 | class CVoting : public CComponent |
15 | { |
16 | CHeap m_Heap; |
17 | |
18 | static void ConCallvote(IConsole::IResult *pResult, void *pUserData); |
19 | static void ConVote(IConsole::IResult *pResult, void *pUserData); |
20 | |
21 | int64_t m_Opentime; |
22 | int64_t m_Closetime; |
23 | char m_aDescription[VOTE_DESC_LENGTH]; |
24 | char m_aReason[VOTE_REASON_LENGTH]; |
25 | int m_Voted; |
26 | int m_Yes, m_No, m_Pass, m_Total; |
27 | bool m_ReceivingOptions; |
28 | |
29 | void AddOption(const char *pDescription); |
30 | void RemoveOption(const char *pDescription); |
31 | void ClearOptions(); |
32 | void Callvote(const char *pType, const char *pValue, const char *pReason); |
33 | |
34 | void RenderBars(CUIRect Bars) const; |
35 | |
36 | public: |
37 | int m_NumVoteOptions; |
38 | CVoteOptionClient *m_pFirst; |
39 | CVoteOptionClient *m_pLast; |
40 | |
41 | CVoteOptionClient *m_pRecycleFirst; |
42 | CVoteOptionClient *m_pRecycleLast; |
43 | |
44 | CVoting(); |
45 | virtual int Sizeof() const override { return sizeof(*this); } |
46 | virtual void OnReset() override; |
47 | virtual void OnConsoleInit() override; |
48 | virtual void OnMessage(int Msgtype, void *pRawMsg) override; |
49 | |
50 | void Render(); |
51 | |
52 | void CallvoteSpectate(int ClientId, const char *pReason, bool ForceVote = false); |
53 | void CallvoteKick(int ClientId, const char *pReason, bool ForceVote = false); |
54 | void CallvoteOption(int OptionId, const char *pReason, bool ForceVote = false); |
55 | void RemovevoteOption(int OptionId); |
56 | void AddvoteOption(const char *pDescription, const char *pCommand); |
57 | |
58 | void Vote(int v); // -1 = no, 1 = yes |
59 | |
60 | int SecondsLeft() const; |
61 | bool IsVoting() const { return m_Closetime != 0; } |
62 | int TakenChoice() const { return m_Voted; } |
63 | const char *VoteDescription() const { return m_aDescription; } |
64 | const char *VoteReason() const { return m_aReason; } |
65 | bool IsReceivingOptions() const { return m_ReceivingOptions; } |
66 | }; |
67 | |
68 | #endif |
69 | |