diff options
| author | oy <Tom_Adams@web.de> | 2011-03-26 17:44:34 +0100 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-03-26 17:44:34 +0100 |
| commit | fbeace52723509604e390f0a20e9f922aa26d1d6 (patch) | |
| tree | ea60feca2bf3346ef62ce12339e40573dfea9762 /src/game/client/components | |
| parent | b8f144ba811708bfac82faed438ce389f3d01863 (diff) | |
| download | zcatch-fbeace52723509604e390f0a20e9f922aa26d1d6.tar.gz zcatch-fbeace52723509604e390f0a20e9f922aa26d1d6.zip | |
cleaned up some voting code
Diffstat (limited to 'src/game/client/components')
| -rw-r--r-- | src/game/client/components/menus.h | 3 | ||||
| -rw-r--r-- | src/game/client/components/menus_ingame.cpp | 8 | ||||
| -rw-r--r-- | src/game/client/components/voting.cpp | 13 | ||||
| -rw-r--r-- | src/game/client/components/voting.h | 26 |
4 files changed, 23 insertions, 27 deletions
diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index a9921655..f9a0fea1 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -8,6 +8,7 @@ #include <engine/demo.h> +#include <game/voting.h> #include <game/client/component.h> #include <game/client/ui.h> @@ -170,7 +171,7 @@ class CMenus : public CComponent // for call vote int m_CallvoteSelectedOption; int m_CallvoteSelectedPlayer; - char m_aCallvoteReason[16]; + char m_aCallvoteReason[VOTE_REASON_LENGTH]; // demo struct CDemoItem diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 4b593989..01efda0a 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -325,16 +325,12 @@ void CMenus::RenderServerInfo(CUIRect MainView) void CMenus::RenderServerControlServer(CUIRect MainView) { - int NumOptions = 0; - for(CVoting::CVoteOption *pOption = m_pClient->m_pVoting->m_pFirst; pOption; pOption = pOption->m_pNext) - NumOptions++; - static int s_VoteList = 0; static float s_ScrollValue = 0; CUIRect List = MainView; - UiDoListboxStart(&s_VoteList, &List, 24.0f, Localize("Settings"), "", NumOptions, 1, m_CallvoteSelectedOption, s_ScrollValue); + UiDoListboxStart(&s_VoteList, &List, 24.0f, Localize("Settings"), "", m_pClient->m_pVoting->m_NumVoteOptions, 1, m_CallvoteSelectedOption, s_ScrollValue); - for(CVoting::CVoteOption *pOption = m_pClient->m_pVoting->m_pFirst; pOption; pOption = pOption->m_pNext) + for(CVoteOptionClient *pOption = m_pClient->m_pVoting->m_pFirst; pOption; pOption = pOption->m_pNext) { CListboxItem Item = UiDoListboxNextItem(pOption); diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp index d8c87855..55343313 100644 --- a/src/game/client/components/voting.cpp +++ b/src/game/client/components/voting.cpp @@ -65,7 +65,7 @@ void CVoting::CallvoteKick(int ClientID, const char *pReason, bool ForceVote) void CVoting::CallvoteOption(int OptionId, const char *pReason, bool ForceVote) { - CVoteOption *pOption = m_pFirst; + CVoteOptionClient *pOption = m_pFirst; while(pOption && OptionId >= 0) { if(OptionId == 0) @@ -102,7 +102,8 @@ CVoting::CVoting() void CVoting::ClearOptions() { m_Heap.Reset(); - + + m_NumVoteOptions = 0; m_pFirst = 0; m_pLast = 0; @@ -156,7 +157,7 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) { CNetMsg_Sv_VoteOptionAdd *pMsg = (CNetMsg_Sv_VoteOptionAdd *)pRawMsg; - CVoteOption *pOption; + CVoteOptionClient *pOption; if(m_pRecycleFirst) { pOption = m_pRecycleFirst; @@ -167,7 +168,7 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) m_pRecycleLast = 0; } else - pOption = (CVoteOption *)m_Heap.Allocate(sizeof(CVoteOption)); + pOption = (CVoteOptionClient *)m_Heap.Allocate(sizeof(CVoteOptionClient)); pOption->m_pNext = 0; pOption->m_pPrev = m_pLast; @@ -178,12 +179,13 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) m_pFirst = pOption; str_copy(pOption->m_aDescription, pMsg->m_pDescription, sizeof(pOption->m_aDescription)); + ++m_NumVoteOptions; } else if(MsgType == NETMSGTYPE_SV_VOTEOPTIONREMOVE) { CNetMsg_Sv_VoteOptionRemove *pMsg = (CNetMsg_Sv_VoteOptionRemove *)pRawMsg; - for(CVoteOption *pOption = m_pFirst; pOption; pOption = pOption->m_pNext) + for(CVoteOptionClient *pOption = m_pFirst; pOption; pOption = pOption->m_pNext) { if(str_comp(pOption->m_aDescription, pMsg->m_pDescription) == 0) { @@ -196,6 +198,7 @@ void CVoting::OnMessage(int MsgType, void *pRawMsg) pOption->m_pPrev->m_pNext = pOption->m_pNext; if(pOption->m_pNext) pOption->m_pNext->m_pPrev = pOption->m_pPrev; + --m_NumVoteOptions; // add it to recycle list pOption->m_pNext = 0; diff --git a/src/game/client/components/voting.h b/src/game/client/components/voting.h index 9e7da2dc..d2a88883 100644 --- a/src/game/client/components/voting.h +++ b/src/game/client/components/voting.h @@ -2,9 +2,12 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #ifndef GAME_CLIENT_COMPONENTS_VOTING_H #define GAME_CLIENT_COMPONENTS_VOTING_H + +#include <engine/shared/memheap.h> + +#include <game/voting.h> #include <game/client/component.h> #include <game/client/ui.h> -#include <engine/shared/memheap.h> class CVoting : public CComponent { @@ -14,8 +17,8 @@ class CVoting : public CComponent static void ConVote(IConsole::IResult *pResult, void *pUserData); int64 m_Closetime; - char m_aDescription[64]; - char m_aReason[16]; + char m_aDescription[VOTE_DESC_LENGTH]; + char m_aReason[VOTE_REASON_LENGTH]; int m_Voted; int m_Yes, m_No, m_Pass, m_Total; @@ -23,19 +26,12 @@ class CVoting : public CComponent void Callvote(const char *pType, const char *pValue, const char *pReason); public: + int m_NumVoteOptions; + CVoteOptionClient *m_pFirst; + CVoteOptionClient *m_pLast; - struct CVoteOption - { - CVoteOption *m_pNext; - CVoteOption *m_pPrev; - char m_aDescription[64]; - }; - - CVoteOption *m_pFirst; - CVoteOption *m_pLast; - - CVoteOption *m_pRecycleFirst; - CVoteOption *m_pRecycleLast; + CVoteOptionClient *m_pRecycleFirst; + CVoteOptionClient *m_pRecycleLast; CVoting(); virtual void OnReset(); |