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