ddnet/src/game/client/components/voting.h

63 lines
2 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (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. */
2010-05-29 07:25:38 +00:00
#ifndef GAME_CLIENT_COMPONENTS_VOTING_H
#define GAME_CLIENT_COMPONENTS_VOTING_H
2011-03-26 16:44:34 +00:00
2022-05-29 16:33:38 +00:00
#include <engine/console.h>
2011-03-26 16:44:34 +00:00
#include <engine/shared/memheap.h>
2010-05-29 07:25:38 +00:00
#include <game/client/component.h>
#include <game/client/ui.h>
#include <game/voting.h>
2010-05-29 07:25:38 +00:00
class CVoting : public CComponent
{
CHeap m_Heap;
static void ConCallvote(IConsole::IResult *pResult, void *pUserData);
static void ConVote(IConsole::IResult *pResult, void *pUserData);
2021-06-23 05:05:49 +00:00
int64_t m_Closetime;
2011-03-26 16:44:34 +00:00
char m_aDescription[VOTE_DESC_LENGTH];
char m_aReason[VOTE_REASON_LENGTH];
2010-05-29 07:25:38 +00:00
int m_Voted;
int m_Yes, m_No, m_Pass, m_Total;
void AddOption(const char *pDescription);
2010-05-29 07:25:38 +00:00
void ClearOptions();
void Callvote(const char *pType, const char *pValue, const char *pReason);
2010-05-29 07:25:38 +00:00
public:
int m_NumVoteOptions;
2011-03-26 16:44:34 +00:00
CVoteOptionClient *m_pFirst;
CVoteOptionClient *m_pLast;
2010-05-29 07:25:38 +00:00
2011-03-26 16:44:34 +00:00
CVoteOptionClient *m_pRecycleFirst;
CVoteOptionClient *m_pRecycleLast;
2010-05-29 07:25:38 +00:00
CVoting();
virtual int Sizeof() const override { return sizeof(*this); }
virtual void OnReset() override;
virtual void OnConsoleInit() override;
virtual void OnMessage(int Msgtype, void *pRawMsg) override;
virtual void OnRender() override;
2010-05-29 07:25:38 +00:00
void RenderBars(CUIRect Bars, bool Text);
void CallvoteSpectate(int ClientID, const char *pReason, bool ForceVote = false);
2011-03-25 11:06:45 +00:00
void CallvoteKick(int ClientID, const char *pReason, bool ForceVote = false);
void CallvoteOption(int OptionID, const char *pReason, bool ForceVote = false);
void RemovevoteOption(int OptionID);
void AddvoteOption(const char *pDescription, const char *pCommand);
2010-05-29 07:25:38 +00:00
void Vote(int v); // -1 = no, 1 = yes
int SecondsLeft() { return (m_Closetime - time()) / time_freq(); }
2010-05-29 07:25:38 +00:00
bool IsVoting() { return m_Closetime != 0; }
int TakenChoice() const { return m_Voted; }
const char *VoteDescription() const { return m_aDescription; }
const char *VoteReason() const { return m_aReason; }
2010-05-29 07:25:38 +00:00
};
#endif