core/MenuStyle_Base.h
author David Anderson <dvander@alliedmods.net>
Sat Feb 16 15:52:11 2013 -0800 (2013-02-16)
changeset 3791 47e1ee9cea86
parent 2289 44045ead61cd
child 4111 34b8688e3bec
permissions -rw-r--r--
Move filesystem natives from Core to Logic (bug 5606, 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_MENUSTYLE_BASE_H
    33 #define _INCLUDE_MENUSTYLE_BASE_H
    34 
    35 #include <IMenuManager.h>
    36 #include <IPlayerHelpers.h>
    37 #include <sh_string.h>
    38 #include <sh_vector.h>
    39 #include "sm_memtable.h"
    40 #include "sm_fastlink.h"
    41 
    42 using namespace SourceMod;
    43 using namespace SourceHook;
    44 
    45 class CItem
    46 {
    47 public:
    48 	CItem()
    49 	{
    50 		infoString = -1;
    51 		displayString = -1;
    52 		style = 0;
    53 		access = 0;
    54 	}
    55 public:
    56 	int infoString;
    57 	int displayString;
    58 	unsigned int style;
    59 	unsigned int access;
    60 };
    61 
    62 class CBaseMenuPlayer
    63 {
    64 public:
    65 	CBaseMenuPlayer() : bInMenu(false), bAutoIgnore(false), bInExternMenu(false)
    66 	{
    67 	}
    68 	menu_states_t states;
    69 	bool bInMenu;
    70 	bool bAutoIgnore;
    71 	float menuStartTime;
    72 	unsigned int menuHoldTime;
    73 	bool bInExternMenu;
    74 };
    75 
    76 class CBaseMenu;
    77 
    78 class BaseMenuStyle : 
    79 	public IMenuStyle,
    80 	public IClientListener
    81 {
    82 public:
    83 	BaseMenuStyle();
    84 public: //IMenuStyle
    85 	bool CancelClientMenu(int client, bool autoIgnore/* =false */);
    86 	MenuSource GetClientMenu(int client, void **object);
    87 	Handle_t GetHandle();
    88 public: //IClientListener
    89 	void OnClientDisconnected(int client);
    90 public: //what derived must implement
    91 	virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0;
    92 	virtual void SendDisplay(int client, IMenuPanel *display) =0;
    93 public: //what derived may implement 
    94 	virtual bool DoClientMenu(int client, 
    95 		CBaseMenu *menu, 
    96 		unsigned int first_item,
    97 		IMenuHandler *mh, 
    98 		unsigned int time);
    99 	virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
   100 	virtual void AddClientToWatch(int client);
   101 	virtual void RemoveClientFromWatch(int client);
   102 	virtual void ProcessWatchList();
   103 public: //helpers
   104 	void CancelMenu(CBaseMenu *menu);
   105 	void ClientPressedKey(int client, unsigned int key_press);
   106 protected:
   107 	void _CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore=false);
   108 	bool RedoClientMenu(int client, ItemOrder order);
   109 protected:
   110 	FastLink<int> m_WatchList;
   111 	Handle_t m_hHandle;
   112 };
   113 
   114 class CBaseMenu : public IBaseMenu
   115 {
   116 public:
   117 	CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner);
   118 	virtual ~CBaseMenu();
   119 public:
   120 	virtual bool AppendItem(const char *info, const ItemDrawInfo &draw);
   121 	virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
   122 	virtual bool RemoveItem(unsigned int position);
   123 	virtual void RemoveAllItems();
   124 	virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL);
   125 	virtual unsigned int GetItemCount();
   126 	virtual bool SetPagination(unsigned int itemsPerPage);
   127 	virtual unsigned int GetPagination();
   128 	virtual IMenuStyle *GetDrawStyle();
   129 	virtual void SetDefaultTitle(const char *message);
   130 	virtual const char *GetDefaultTitle();
   131 	virtual void Cancel();
   132 	virtual void Destroy(bool releaseHandle);
   133 	virtual void Cancel_Finally() =0;
   134 	virtual Handle_t GetHandle();
   135 	virtual unsigned int GetMenuOptionFlags();
   136 	virtual void SetMenuOptionFlags(unsigned int flags);
   137 	virtual IMenuHandler *GetHandler();
   138 	unsigned int GetBaseMemUsage();
   139 private:
   140 	void InternalDelete();
   141 protected:
   142 	String m_Title;
   143 	IMenuStyle *m_pStyle;
   144 	BaseStringTable m_Strings;
   145 	unsigned int m_Pagination;
   146 	CVector<CItem> m_items;
   147 	bool m_bShouldDelete;
   148 	bool m_bCancelling;
   149 	IdentityToken_t *m_pOwner;
   150 	bool m_bDeleting;
   151 	bool m_bWillFreeHandle;
   152 	Handle_t m_hHandle;
   153 	IMenuHandler *m_pHandler;
   154 	unsigned int m_nFlags;
   155 };
   156 
   157 #endif //_INCLUDE_MENUSTYLE_BASE_H