core/MenuVoting.h
author David Anderson <dvander@alliedmods.net>
Sun Oct 21 17:58:35 2007 +0000 (2007-10-21)
changeset 1620 fd5c786ca8e5
parent 1474 a3b73df84d88
child 1947 e73a1e51833b
permissions -rw-r--r--
atcprintf() is now fully re-entrant, meaning translations can be used from inside translations
dvander@1269
     1
/**
dvander@1269
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1269
     4
 * SourceMod
dvander@1269
     5
 * Copyright (C) 2004-2007 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"
dvander@1269
    39
dvander@1269
    40
using namespace SourceHook;
dvander@1269
    41
using namespace SourceMod;
dvander@1269
    42
dvander@1269
    43
class VoteMenuHandler : 
dvander@1269
    44
	public IMenuHandler, 
dvander@1269
    45
	public SMGlobalClass,
dvander@1269
    46
	public IClientListener
dvander@1269
    47
{
dvander@1269
    48
public: //SMGlobalClass
dvander@1269
    49
	void OnSourceModAllInitialized();
dvander@1269
    50
	void OnSourceModShutdown();
dvander@1291
    51
	void OnSourceModLevelChange(const char *mapName);
dvander@1269
    52
public: //IClientListener
dvander@1269
    53
	void OnClientDisconnected(int client);
dvander@1269
    54
public: //IMenuHandler
dvander@1269
    55
	unsigned int GetMenuAPIVersion2();
dvander@1269
    56
	void OnMenuStart(IBaseMenu *menu);
dvander@1269
    57
	void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display);
dvander@1269
    58
	void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item);
dvander@1474
    59
	void OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page);
dvander@1269
    60
	void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason);
dvander@1269
    61
	void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason);
dvander@1269
    62
	void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style);
dvander@1269
    63
	unsigned int OnMenuDisplayItem(IBaseMenu *menu, int client, IMenuPanel *panel, unsigned int item, const ItemDrawInfo &dr);
dvander@1269
    64
public:
dvander@1269
    65
	bool StartVote(IBaseMenu *menu,
dvander@1269
    66
		unsigned int num_clients,
dvander@1269
    67
		int clients[],
dvander@1269
    68
		unsigned int max_time,
dvander@1269
    69
		unsigned int flags=0);
dvander@1269
    70
	bool IsVoteInProgress();
dvander@1269
    71
	void CancelVoting();
dvander@1269
    72
	IBaseMenu *GetCurrentMenu();
dvander@1269
    73
	bool IsCancelling();
dvander@1291
    74
	unsigned int GetRemainingVoteDelay();
dvander@1269
    75
private:
dvander@1269
    76
	void Reset(IMenuHandler *mh);
dvander@1269
    77
	void DecrementPlayerCount();
dvander@1269
    78
	void EndVoting();
dvander@1269
    79
	void InternalReset();
dvander@1269
    80
	bool InitializeVoting(IBaseMenu *menu, 
dvander@1269
    81
		IMenuHandler *handler,
dvander@1269
    82
		unsigned int time,
dvander@1269
    83
		unsigned int flags);
dvander@1269
    84
	void StartVoting();
dvander@1269
    85
private:
dvander@1269
    86
	IMenuHandler *m_pHandler;
dvander@1269
    87
	unsigned int m_Clients;
dvander@1269
    88
	unsigned int m_Items;
dvander@1269
    89
	CVector<unsigned int> m_Votes;
dvander@1269
    90
	IBaseMenu *m_pCurMenu;
dvander@1269
    91
	bool m_bStarted;
dvander@1269
    92
	bool m_bCancelled;
dvander@1269
    93
	unsigned int m_NumVotes;
dvander@1269
    94
	unsigned int m_VoteTime;
dvander@1269
    95
	unsigned int m_VoteFlags;
dvander@1269
    96
	int m_ClientVotes[256+1];
dvander@1269
    97
};
dvander@1269
    98
dvander@1269
    99
#endif //_INCLUDE_SOURCEMOD_MENUVOTING_H_