core/MenuStyle_Base.h
author David Anderson <dvander@alliedmods.net>
Wed Jun 06 22:31:54 2007 +0000 (2007-06-06)
changeset 896 e30eef2642ba
parent 884 a5f3239cef1a
child 1005 b15b5682d181
permissions -rw-r--r--
added config options for chat triggers
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_MENUSTYLE_BASE_H
    16 #define _INCLUDE_MENUSTYLE_BASE_H
    17 
    18 #include <IMenuManager.h>
    19 #include <IPlayerHelpers.h>
    20 #include <sh_string.h>
    21 #include <sh_vector.h>
    22 #include "sm_memtable.h"
    23 #include "sm_fastlink.h"
    24 
    25 using namespace SourceMod;
    26 using namespace SourceHook;
    27 
    28 class CItem
    29 {
    30 public:
    31 	CItem()
    32 	{
    33 		infoString = -1;
    34 		displayString = -1;
    35 		style = 0;
    36 	}
    37 public:
    38 	int infoString;
    39 	int displayString;
    40 	unsigned int style;
    41 };
    42 
    43 class CBaseMenuPlayer
    44 {
    45 public:
    46 	CBaseMenuPlayer() : bInMenu(false), bAutoIgnore(false), bInExternMenu(false)
    47 	{
    48 	}
    49 	menu_states_t states;
    50 	bool bInMenu;
    51 	bool bAutoIgnore;
    52 	float menuStartTime;
    53 	unsigned int menuHoldTime;
    54 	bool bInExternMenu;
    55 };
    56 
    57 class CBaseMenu;
    58 
    59 class BaseMenuStyle : 
    60 	public IMenuStyle,
    61 	public IClientListener
    62 {
    63 public:
    64 	BaseMenuStyle();
    65 public: //IMenuStyle
    66 	bool CancelClientMenu(int client, bool autoIgnore/* =false */);
    67 	MenuSource GetClientMenu(int client, void **object);
    68 	Handle_t GetHandle();
    69 public: //IClientListener
    70 	void OnClientDisconnected(int client);
    71 public: //what derived must implement
    72 	virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0;
    73 	virtual void SendDisplay(int client, IMenuPanel *display) =0;
    74 public: //what derived may implement 
    75 	virtual bool DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time);
    76 	virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
    77 	virtual void AddClientToWatch(int client);
    78 	virtual void RemoveClientFromWatch(int client);
    79 	virtual void ProcessWatchList();
    80 public: //helpers
    81 	void CancelMenu(CBaseMenu *menu);
    82 	void ClientPressedKey(int client, unsigned int key_press);
    83 protected:
    84 	void _CancelClientMenu(int client, bool bAutoIgnore=false, MenuCancelReason reason=MenuCancel_Interrupt);
    85 	bool RedoClientMenu(int client, ItemOrder order);
    86 protected:
    87 	FastLink<int> m_WatchList;
    88 	Handle_t m_hHandle;
    89 };
    90 
    91 class CBaseMenu : public IBaseMenu
    92 {
    93 public:
    94 	CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner);
    95 	virtual ~CBaseMenu();
    96 public:
    97 	virtual bool AppendItem(const char *info, const ItemDrawInfo &draw);
    98 	virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
    99 	virtual bool RemoveItem(unsigned int position);
   100 	virtual void RemoveAllItems();
   101 	virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL);
   102 	virtual unsigned int GetItemCount();
   103 	virtual bool SetPagination(unsigned int itemsPerPage);
   104 	virtual unsigned int GetPagination();
   105 	virtual IMenuStyle *GetDrawStyle();
   106 	virtual void SetDefaultTitle(const char *message);
   107 	virtual const char *GetDefaultTitle();
   108 	virtual bool GetExitButton();
   109 	virtual bool SetExitButton(bool set);
   110 	virtual void Cancel();
   111 	virtual void Destroy(bool releaseHandle);
   112 	virtual void Cancel_Finally() =0;
   113 	virtual Handle_t GetHandle();
   114 	bool BroadcastVote(int clients[], 
   115 		unsigned int numClients, 
   116 		unsigned int maxTime,
   117 		unsigned int flags=0);
   118 	bool IsVoteInProgress();
   119 public:
   120 	virtual void VoteDisplay(int client, unsigned int maxTime) =0;
   121 private:
   122 	void InternalDelete();
   123 protected:
   124 	String m_Title;
   125 	IMenuStyle *m_pStyle;
   126 	BaseStringTable m_Strings;
   127 	unsigned int m_Pagination;
   128 	CVector<CItem> m_items;
   129 	bool m_ExitButton;
   130 	bool m_bShouldDelete;
   131 	bool m_bCancelling;
   132 	IdentityToken_t *m_pOwner;
   133 	bool m_bDeleting;
   134 	bool m_bWillFreeHandle;
   135 	Handle_t m_hHandle;
   136 	IMenuHandler *m_pHandler;
   137 	IVoteMenuHandler *m_pVoteHandler;
   138 };
   139 
   140 #endif //_INCLUDE_MENUSTYLE_BASE_H