core/MenuStyle_Base.h
author David Anderson <dvander@alliedmods.net>
Sun Aug 19 18:34:36 2007 +0000 (2007-08-19)
changeset 1361 591f6d2fd11d
parent 1330 ab94316bb52b
child 1474 a3b73df84d88
permissions -rw-r--r--
added helper function for panel text
dvander@769
     1
/**
dvander@769
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 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@775
    94
	virtual bool DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time);
dvander@787
    95
	virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
dvander@775
    96
	virtual void AddClientToWatch(int client);
dvander@775
    97
	virtual void RemoveClientFromWatch(int client);
dvander@775
    98
	virtual void ProcessWatchList();
dvander@775
    99
public: //helpers
dvander@775
   100
	void CancelMenu(CBaseMenu *menu);
dvander@775
   101
	void ClientPressedKey(int client, unsigned int key_press);
dvander@775
   102
protected:
dvander@1005
   103
	void _CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore=false);
dvander@775
   104
	bool RedoClientMenu(int client, ItemOrder order);
dvander@775
   105
protected:
dvander@775
   106
	FastLink<int> m_WatchList;
dvander@790
   107
	Handle_t m_hHandle;
dvander@775
   108
};
dvander@775
   109
dvander@769
   110
class CBaseMenu : public IBaseMenu
dvander@769
   111
{
dvander@769
   112
public:
dvander@790
   113
	CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner);
dvander@769
   114
	virtual ~CBaseMenu();
dvander@769
   115
public:
dvander@769
   116
	virtual bool AppendItem(const char *info, const ItemDrawInfo &draw);
dvander@769
   117
	virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
dvander@769
   118
	virtual bool RemoveItem(unsigned int position);
dvander@769
   119
	virtual void RemoveAllItems();
dvander@769
   120
	virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL);
dvander@769
   121
	virtual unsigned int GetItemCount();
dvander@769
   122
	virtual bool SetPagination(unsigned int itemsPerPage);
dvander@769
   123
	virtual unsigned int GetPagination();
dvander@769
   124
	virtual IMenuStyle *GetDrawStyle();
dvander@769
   125
	virtual void SetDefaultTitle(const char *message);
dvander@769
   126
	virtual const char *GetDefaultTitle();
dvander@775
   127
	virtual void Cancel();
dvander@790
   128
	virtual void Destroy(bool releaseHandle);
dvander@775
   129
	virtual void Cancel_Finally() =0;
dvander@790
   130
	virtual Handle_t GetHandle();
dvander@1259
   131
	virtual unsigned int GetMenuOptionFlags();
dvander@1259
   132
	virtual void SetMenuOptionFlags(unsigned int flags);
dvander@1269
   133
	virtual IMenuHandler *GetHandler();
dvander@790
   134
private:
dvander@790
   135
	void InternalDelete();
dvander@769
   136
protected:
dvander@769
   137
	String m_Title;
dvander@769
   138
	IMenuStyle *m_pStyle;
dvander@778
   139
	BaseStringTable m_Strings;
dvander@769
   140
	unsigned int m_Pagination;
dvander@769
   141
	CVector<CItem> m_items;
dvander@778
   142
	bool m_bShouldDelete;
dvander@775
   143
	bool m_bCancelling;
dvander@791
   144
	IdentityToken_t *m_pOwner;
dvander@790
   145
	bool m_bDeleting;
dvander@790
   146
	bool m_bWillFreeHandle;
dvander@790
   147
	Handle_t m_hHandle;
dvander@790
   148
	IMenuHandler *m_pHandler;
dvander@1259
   149
	unsigned int m_nFlags;
dvander@769
   150
};
dvander@769
   151
dvander@769
   152
#endif //_INCLUDE_MENUSTYLE_BASE_H