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