core/MenuStyle_Base.h
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 15 21:22:24 2014 -0400 (2014-05-15)
changeset 4362 8a15e967d983
parent 4175 3ae24e84c028
permissions -rw-r--r--
Update gamedata for CS:S update.
     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 		style = 0;
    49 		access = 0;
    50 	}
    51 	CItem(ke::Moveable<CItem> other)
    52 	: info(ke::Move(other->info)),
    53 	  display(ke::Move(other->display))
    54 	{
    55 		style = other->style;
    56 		access = other->access;
    57 	}
    58 	CItem & operator =(ke::Moveable<CItem> other)
    59 	{
    60 		info = ke::Move(other->info);
    61 		display = ke::Move(other->display);
    62 		style = other->style;
    63 		access = other->access;
    64 		return *this;
    65 	}
    66 
    67 public:
    68 	ke::AString info;
    69 	ke::AutoPtr<ke::AString> display;
    70 	unsigned int style;
    71 	unsigned int access;
    72 
    73 private:
    74 	CItem(const CItem &other) KE_DELETE;
    75 	CItem &operator =(const CItem &other) KE_DELETE;
    76 };
    77 
    78 class CBaseMenuPlayer
    79 {
    80 public:
    81 	CBaseMenuPlayer() : bInMenu(false), bAutoIgnore(false), bInExternMenu(false)
    82 	{
    83 	}
    84 	menu_states_t states;
    85 	bool bInMenu;
    86 	bool bAutoIgnore;
    87 	float menuStartTime;
    88 	unsigned int menuHoldTime;
    89 	bool bInExternMenu;
    90 };
    91 
    92 class CBaseMenu;
    93 
    94 class BaseMenuStyle : 
    95 	public IMenuStyle,
    96 	public IClientListener
    97 {
    98 public:
    99 	BaseMenuStyle();
   100 public: //IMenuStyle
   101 	bool CancelClientMenu(int client, bool autoIgnore/* =false */);
   102 	MenuSource GetClientMenu(int client, void **object);
   103 	Handle_t GetHandle();
   104 public: //IClientListener
   105 	void OnClientDisconnected(int client);
   106 public: //what derived must implement
   107 	virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0;
   108 	virtual void SendDisplay(int client, IMenuPanel *display) =0;
   109 public: //what derived may implement 
   110 	virtual bool DoClientMenu(int client, 
   111 		CBaseMenu *menu, 
   112 		unsigned int first_item,
   113 		IMenuHandler *mh, 
   114 		unsigned int time);
   115 	virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
   116 	virtual void AddClientToWatch(int client);
   117 	virtual void RemoveClientFromWatch(int client);
   118 	virtual void ProcessWatchList();
   119 public: //helpers
   120 	void CancelMenu(CBaseMenu *menu);
   121 	void ClientPressedKey(int client, unsigned int key_press);
   122 protected:
   123 	void _CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore=false);
   124 	bool RedoClientMenu(int client, ItemOrder order);
   125 protected:
   126 	FastLink<int> m_WatchList;
   127 	Handle_t m_hHandle;
   128 };
   129 
   130 class CBaseMenu : public IBaseMenu
   131 {
   132 public:
   133 	CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner);
   134 	virtual ~CBaseMenu();
   135 public:
   136 	virtual bool AppendItem(const char *info, const ItemDrawInfo &draw);
   137 	virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
   138 	virtual bool RemoveItem(unsigned int position);
   139 	virtual void RemoveAllItems();
   140 	virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL);
   141 	virtual unsigned int GetItemCount();
   142 	virtual bool SetPagination(unsigned int itemsPerPage);
   143 	virtual unsigned int GetPagination();
   144 	virtual IMenuStyle *GetDrawStyle();
   145 	virtual void SetDefaultTitle(const char *message);
   146 	virtual const char *GetDefaultTitle();
   147 	virtual void Cancel();
   148 	virtual void Destroy(bool releaseHandle);
   149 	virtual void Cancel_Finally() =0;
   150 	virtual Handle_t GetHandle();
   151 	virtual unsigned int GetMenuOptionFlags();
   152 	virtual void SetMenuOptionFlags(unsigned int flags);
   153 	virtual IMenuHandler *GetHandler();
   154 	unsigned int GetBaseMemUsage();
   155 private:
   156 	void InternalDelete();
   157 protected:
   158 	ke::AString m_Title;
   159 	IMenuStyle *m_pStyle;
   160 	unsigned int m_Pagination;
   161 	ke::Vector<CItem> m_items;
   162 	bool m_bShouldDelete;
   163 	bool m_bCancelling;
   164 	IdentityToken_t *m_pOwner;
   165 	bool m_bDeleting;
   166 	bool m_bWillFreeHandle;
   167 	Handle_t m_hHandle;
   168 	IMenuHandler *m_pHandler;
   169 	unsigned int m_nFlags;
   170 };
   171 
   172 #endif //_INCLUDE_MENUSTYLE_BASE_H