core/MenuStyle_Base.h
author Phong Dang <teame06@gmail.com>
Wed Aug 01 04:17:36 2007 +0000 (2007-08-01)
changeset 1235 88bb46f9731e
parent 1231 17badaf66ce4
child 1259 472c5e61cdc8
permissions -rw-r--r--
Implemented requested amb603. Added voice natives.
     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 
     9  * modify it under the terms of the GNU General Public License, 
    10  * version 3.0, as published by the Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to 
    21  * link the code of this program (as well as its derivative works) to 
    22  * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
    23  * Game MODs that run on software by the Valve Corporation.  You must 
    24  * obey the GNU General Public License in all respects for all other 
    25  * code used. Additionally, AlliedModders LLC grants this exception 
    26  * to all derivative works. AlliedModders LLC defines further 
    27  * exceptions, found in LICENSE.txt (as of this writing, version 
    28  * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #ifndef _INCLUDE_MENUSTYLE_BASE_H
    34 #define _INCLUDE_MENUSTYLE_BASE_H
    35 
    36 #include <IMenuManager.h>
    37 #include <IPlayerHelpers.h>
    38 #include <sh_string.h>
    39 #include <sh_vector.h>
    40 #include "sm_memtable.h"
    41 #include "sm_fastlink.h"
    42 
    43 using namespace SourceMod;
    44 using namespace SourceHook;
    45 
    46 class CItem
    47 {
    48 public:
    49 	CItem()
    50 	{
    51 		infoString = -1;
    52 		displayString = -1;
    53 		style = 0;
    54 		access = 0;
    55 	}
    56 public:
    57 	int infoString;
    58 	int displayString;
    59 	unsigned int style;
    60 	unsigned int access;
    61 };
    62 
    63 class CBaseMenuPlayer
    64 {
    65 public:
    66 	CBaseMenuPlayer() : bInMenu(false), bAutoIgnore(false), bInExternMenu(false)
    67 	{
    68 	}
    69 	menu_states_t states;
    70 	bool bInMenu;
    71 	bool bAutoIgnore;
    72 	float menuStartTime;
    73 	unsigned int menuHoldTime;
    74 	bool bInExternMenu;
    75 };
    76 
    77 class CBaseMenu;
    78 
    79 class BaseMenuStyle : 
    80 	public IMenuStyle,
    81 	public IClientListener
    82 {
    83 public:
    84 	BaseMenuStyle();
    85 public: //IMenuStyle
    86 	bool CancelClientMenu(int client, bool autoIgnore/* =false */);
    87 	MenuSource GetClientMenu(int client, void **object);
    88 	Handle_t GetHandle();
    89 public: //IClientListener
    90 	void OnClientDisconnected(int client);
    91 public: //what derived must implement
    92 	virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0;
    93 	virtual void SendDisplay(int client, IMenuPanel *display) =0;
    94 public: //what derived may implement 
    95 	virtual bool DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time);
    96 	virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
    97 	virtual void AddClientToWatch(int client);
    98 	virtual void RemoveClientFromWatch(int client);
    99 	virtual void ProcessWatchList();
   100 public: //helpers
   101 	void CancelMenu(CBaseMenu *menu);
   102 	void ClientPressedKey(int client, unsigned int key_press);
   103 protected:
   104 	void _CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore=false);
   105 	bool RedoClientMenu(int client, ItemOrder order);
   106 protected:
   107 	FastLink<int> m_WatchList;
   108 	Handle_t m_hHandle;
   109 };
   110 
   111 class CBaseMenu : public IBaseMenu
   112 {
   113 public:
   114 	CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner);
   115 	virtual ~CBaseMenu();
   116 public:
   117 	virtual bool AppendItem(const char *info, const ItemDrawInfo &draw);
   118 	virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
   119 	virtual bool RemoveItem(unsigned int position);
   120 	virtual void RemoveAllItems();
   121 	virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL);
   122 	virtual unsigned int GetItemCount();
   123 	virtual bool SetPagination(unsigned int itemsPerPage);
   124 	virtual unsigned int GetPagination();
   125 	virtual IMenuStyle *GetDrawStyle();
   126 	virtual void SetDefaultTitle(const char *message);
   127 	virtual const char *GetDefaultTitle();
   128 	virtual bool GetExitButton();
   129 	virtual bool SetExitButton(bool set);
   130 	virtual void Cancel();
   131 	virtual void Destroy(bool releaseHandle);
   132 	virtual void Cancel_Finally() =0;
   133 	virtual Handle_t GetHandle();
   134 	virtual bool BroadcastVote(int clients[], 
   135 		unsigned int numClients, 
   136 		unsigned int maxTime,
   137 		unsigned int flags=0);
   138 	virtual bool IsVoteInProgress();
   139 	virtual bool GetExitBackButton();
   140 	virtual void SetExitBackButton(bool set);
   141 public:
   142 	virtual void VoteDisplay(int client, unsigned int maxTime) =0;
   143 private:
   144 	void InternalDelete();
   145 protected:
   146 	String m_Title;
   147 	IMenuStyle *m_pStyle;
   148 	BaseStringTable m_Strings;
   149 	unsigned int m_Pagination;
   150 	CVector<CItem> m_items;
   151 	bool m_ExitButton;
   152 	bool m_bShouldDelete;
   153 	bool m_bCancelling;
   154 	IdentityToken_t *m_pOwner;
   155 	bool m_bDeleting;
   156 	bool m_bWillFreeHandle;
   157 	Handle_t m_hHandle;
   158 	IMenuHandler *m_pHandler;
   159 	IVoteMenuHandler *m_pVoteHandler;
   160 	bool m_ExitBackButton;
   161 };
   162 
   163 #endif //_INCLUDE_MENUSTYLE_BASE_H