core/MenuVoting.h
author Drifter <rgr_02@comcast.net>
Wed May 30 23:00:16 2012 -0400 (2012-05-30)
changeset 3543 9287a18e9a33
parent 2801 f70c4df158b3
permissions -rw-r--r--
Fix for SDKTools TeamScore natives crash on CS:GO (bug 5319, r=psychonic).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 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 #include <TimerSys.h>
    40 
    41 using namespace SourceHook;
    42 using namespace SourceMod;
    43 
    44 class VoteMenuHandler : 
    45 	public IMenuHandler, 
    46 	public SMGlobalClass,
    47 	public IClientListener,
    48 	public ITimedEvent
    49 {
    50 public: //SMGlobalClass
    51 	void OnSourceModAllInitialized();
    52 	void OnSourceModShutdown();
    53 	void OnSourceModLevelChange(const char *mapName);
    54 public: //IClientListener
    55 	void OnClientDisconnected(int client);
    56 public: //IMenuHandler
    57 	unsigned int GetMenuAPIVersion2();
    58 	void OnMenuStart(IBaseMenu *menu);
    59 	void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display);
    60 	void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item);
    61 	void OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page);
    62 	void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason);
    63 	void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason);
    64 	void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style);
    65 	unsigned int OnMenuDisplayItem(IBaseMenu *menu, int client, IMenuPanel *panel, unsigned int item, const ItemDrawInfo &dr);
    66 public: //ITimedEvent
    67 	ResultType OnTimer(ITimer *pTimer, void *pData);
    68 	void OnTimerEnd(ITimer *pTimer, void *pData);
    69 public:
    70 	bool StartVote(IBaseMenu *menu,
    71 		unsigned int num_clients,
    72 		int clients[],
    73 		unsigned int max_time,
    74 		unsigned int flags=0);
    75 	bool IsVoteInProgress();
    76 	void CancelVoting();
    77 	IBaseMenu *GetCurrentMenu();
    78 	bool IsCancelling();
    79 	unsigned int GetRemainingVoteDelay();
    80 	bool IsClientInVotePool(int client);
    81 	bool GetClientVoteChoice(int client, unsigned int *pItem);
    82 	bool RedrawToClient(int client, bool revote);
    83 private:
    84 	void Reset(IMenuHandler *mh);
    85 	void DecrementPlayerCount();
    86 	void EndVoting();
    87 	void InternalReset();
    88 	bool InitializeVoting(IBaseMenu *menu, 
    89 		IMenuHandler *handler,
    90 		unsigned int time,
    91 		unsigned int flags);
    92 	void StartVoting();
    93 	void DrawHintProgress();
    94 	void BuildVoteLeaders();
    95 private:
    96 	IMenuHandler *m_pHandler;
    97 	unsigned int m_Clients;
    98 	unsigned int m_TotalClients;
    99 	unsigned int m_Items;
   100 	CVector<unsigned int> m_Votes;
   101 	IBaseMenu *m_pCurMenu;
   102 	bool m_bStarted;
   103 	bool m_bCancelled;
   104 	unsigned int m_NumVotes;
   105 	unsigned int m_VoteTime;
   106 	unsigned int m_VoteFlags;
   107 	float m_fStartTime;
   108 	unsigned int m_nMenuTime;
   109 	int m_ClientVotes[256+1];
   110 	bool m_Revoting[256+1];
   111 	char m_leaderList[1024];
   112 	ITimer *m_displayTimer;
   113 };
   114 
   115 #endif //_INCLUDE_SOURCEMOD_MENUVOTING_H_
   116