core/MenuVoting.h
author Asher Baker <asherkin@gmail.com>
Sun Aug 14 21:42:32 2011 +0100 (2011-08-14)
changeset 3367 18eb63085ca4
parent 2801 f70c4df158b3
permissions -rw-r--r--
Added a reset argument to 'sm cvars' (bug 5043, r=psychonic).
dvander@1269
     1
/**
dvander@1269
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1269
     4
 * SourceMod
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@1269
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1269
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1269
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1269
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@1269
    28
 *
dvander@1269
    29
 * Version: $Id$
dvander@1269
    30
 */
dvander@1269
    31
dvander@1269
    32
#ifndef _INCLUDE_SOURCEMOD_MENUVOTING_H_
dvander@1269
    33
#define _INCLUDE_SOURCEMOD_MENUVOTING_H_
dvander@1269
    34
dvander@1269
    35
#include <IMenuManager.h>
dvander@1269
    36
#include <IPlayerHelpers.h>
dvander@1269
    37
#include <sh_vector.h>
dvander@1269
    38
#include "sm_globals.h"
pred@2801
    39
#include <TimerSys.h>
dvander@1269
    40
dvander@1269
    41
using namespace SourceHook;
dvander@1269
    42
using namespace SourceMod;
dvander@1269
    43
dvander@1269
    44
class VoteMenuHandler : 
dvander@1269
    45
	public IMenuHandler, 
dvander@1269
    46
	public SMGlobalClass,
pred@2801
    47
	public IClientListener,
pred@2801
    48
	public ITimedEvent
dvander@1269
    49
{
dvander@1269
    50
public: //SMGlobalClass
dvander@1269
    51
	void OnSourceModAllInitialized();
dvander@1269
    52
	void OnSourceModShutdown();
dvander@1291
    53
	void OnSourceModLevelChange(const char *mapName);
dvander@1269
    54
public: //IClientListener
dvander@1269
    55
	void OnClientDisconnected(int client);
dvander@1269
    56
public: //IMenuHandler
dvander@1269
    57
	unsigned int GetMenuAPIVersion2();
dvander@1269
    58
	void OnMenuStart(IBaseMenu *menu);
dvander@1269
    59
	void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display);
dvander@1269
    60
	void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item);
dvander@1474
    61
	void OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page);
dvander@1269
    62
	void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason);
dvander@1269
    63
	void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason);
dvander@1269
    64
	void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style);
dvander@1269
    65
	unsigned int OnMenuDisplayItem(IBaseMenu *menu, int client, IMenuPanel *panel, unsigned int item, const ItemDrawInfo &dr);
pred@2801
    66
public: //ITimedEvent
pred@2801
    67
	ResultType OnTimer(ITimer *pTimer, void *pData);
pred@2801
    68
	void OnTimerEnd(ITimer *pTimer, void *pData);
dvander@1269
    69
public:
dvander@1269
    70
	bool StartVote(IBaseMenu *menu,
dvander@1269
    71
		unsigned int num_clients,
dvander@1269
    72
		int clients[],
dvander@1269
    73
		unsigned int max_time,
dvander@1269
    74
		unsigned int flags=0);
dvander@1269
    75
	bool IsVoteInProgress();
dvander@1269
    76
	void CancelVoting();
dvander@1269
    77
	IBaseMenu *GetCurrentMenu();
dvander@1269
    78
	bool IsCancelling();
dvander@1291
    79
	unsigned int GetRemainingVoteDelay();
dvander@2056
    80
	bool IsClientInVotePool(int client);
dvander@2056
    81
	bool GetClientVoteChoice(int client, unsigned int *pItem);
dvander@2737
    82
	bool RedrawToClient(int client, bool revote);
dvander@1269
    83
private:
dvander@1269
    84
	void Reset(IMenuHandler *mh);
dvander@1269
    85
	void DecrementPlayerCount();
dvander@1269
    86
	void EndVoting();
dvander@1269
    87
	void InternalReset();
dvander@1269
    88
	bool InitializeVoting(IBaseMenu *menu, 
dvander@1269
    89
		IMenuHandler *handler,
dvander@1269
    90
		unsigned int time,
dvander@1269
    91
		unsigned int flags);
dvander@1269
    92
	void StartVoting();
pred@2801
    93
	void DrawHintProgress();
pred@2801
    94
	void BuildVoteLeaders();
dvander@1269
    95
private:
dvander@1269
    96
	IMenuHandler *m_pHandler;
dvander@1269
    97
	unsigned int m_Clients;
pred@2801
    98
	unsigned int m_TotalClients;
dvander@1269
    99
	unsigned int m_Items;
dvander@1269
   100
	CVector<unsigned int> m_Votes;
dvander@1269
   101
	IBaseMenu *m_pCurMenu;
dvander@1269
   102
	bool m_bStarted;
dvander@1269
   103
	bool m_bCancelled;
dvander@1269
   104
	unsigned int m_NumVotes;
dvander@1269
   105
	unsigned int m_VoteTime;
dvander@1269
   106
	unsigned int m_VoteFlags;
dvander@2056
   107
	float m_fStartTime;
dvander@2056
   108
	unsigned int m_nMenuTime;
dvander@1269
   109
	int m_ClientVotes[256+1];
pred@2801
   110
	bool m_Revoting[256+1];
pred@2801
   111
	char m_leaderList[1024];
pred@2801
   112
	ITimer *m_displayTimer;
dvander@1269
   113
};
dvander@1269
   114
dvander@1269
   115
#endif //_INCLUDE_SOURCEMOD_MENUVOTING_H_
dvander@2737
   116