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