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