core/MenuStyle_Base.h
author Peace-Maker <januk@freenet.de>
Wed Apr 23 08:55:09 2014 -0400 (2014-04-23)
changeset 4330 98726cea1607
parent 4175 3ae24e84c028
permissions -rw-r--r--
Mark CS:S as supporting HudMsg (bug 6108, r=psychonic).
dvander@769
     1
/**
dvander@4111
     2
 * vim: set ts=4 sw=4 tw=99 noet :
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@4111
    37
#include <am-string.h>
dvander@4111
    38
#include <am-vector.h>
dvander@775
    39
#include "sm_fastlink.h"
dvander@769
    40
dvander@769
    41
using namespace SourceMod;
dvander@769
    42
dvander@769
    43
class CItem
dvander@769
    44
{
dvander@769
    45
public:
dvander@769
    46
	CItem()
dvander@769
    47
	{
dvander@769
    48
		style = 0;
dvander@1163
    49
		access = 0;
dvander@769
    50
	}
dvander@4111
    51
	CItem(ke::Moveable<CItem> other)
dvander@4111
    52
	: info(ke::Move(other->info)),
dvander@4111
    53
	  display(ke::Move(other->display))
dvander@4111
    54
	{
dvander@4111
    55
		style = other->style;
dvander@4111
    56
		access = other->access;
dvander@4111
    57
	}
dvander@4175
    58
	CItem & operator =(ke::Moveable<CItem> other)
dvander@4175
    59
	{
dvander@4175
    60
		info = ke::Move(other->info);
dvander@4175
    61
		display = ke::Move(other->display);
dvander@4175
    62
		style = other->style;
dvander@4175
    63
		access = other->access;
dvander@4175
    64
		return *this;
dvander@4175
    65
	}
dvander@4175
    66
dvander@769
    67
public:
dvander@4111
    68
	ke::AString info;
dvander@4175
    69
	ke::AutoPtr<ke::AString> display;
dvander@769
    70
	unsigned int style;
dvander@1163
    71
	unsigned int access;
dvander@4175
    72
dvander@4175
    73
private:
dvander@4175
    74
	CItem(const CItem &other) KE_DELETE;
dvander@4175
    75
	CItem &operator =(const CItem &other) KE_DELETE;
dvander@769
    76
};
dvander@769
    77
dvander@775
    78
class CBaseMenuPlayer
dvander@775
    79
{
dvander@775
    80
public:
dvander@780
    81
	CBaseMenuPlayer() : bInMenu(false), bAutoIgnore(false), bInExternMenu(false)
dvander@775
    82
	{
dvander@775
    83
	}
dvander@775
    84
	menu_states_t states;
dvander@775
    85
	bool bInMenu;
dvander@775
    86
	bool bAutoIgnore;
dvander@775
    87
	float menuStartTime;
dvander@775
    88
	unsigned int menuHoldTime;
dvander@780
    89
	bool bInExternMenu;
dvander@775
    90
};
dvander@775
    91
dvander@775
    92
class CBaseMenu;
dvander@775
    93
dvander@775
    94
class BaseMenuStyle : 
dvander@775
    95
	public IMenuStyle,
dvander@775
    96
	public IClientListener
dvander@775
    97
{
dvander@775
    98
public:
dvander@775
    99
	BaseMenuStyle();
dvander@775
   100
public: //IMenuStyle
dvander@775
   101
	bool CancelClientMenu(int client, bool autoIgnore/* =false */);
dvander@775
   102
	MenuSource GetClientMenu(int client, void **object);
dvander@790
   103
	Handle_t GetHandle();
dvander@775
   104
public: //IClientListener
dvander@775
   105
	void OnClientDisconnected(int client);
dvander@775
   106
public: //what derived must implement
dvander@775
   107
	virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0;
dvander@787
   108
	virtual void SendDisplay(int client, IMenuPanel *display) =0;
dvander@775
   109
public: //what derived may implement 
dvander@1474
   110
	virtual bool DoClientMenu(int client, 
dvander@1474
   111
		CBaseMenu *menu, 
dvander@1474
   112
		unsigned int first_item,
dvander@1474
   113
		IMenuHandler *mh, 
dvander@1474
   114
		unsigned int time);
dvander@787
   115
	virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
dvander@775
   116
	virtual void AddClientToWatch(int client);
dvander@775
   117
	virtual void RemoveClientFromWatch(int client);
dvander@775
   118
	virtual void ProcessWatchList();
dvander@775
   119
public: //helpers
dvander@775
   120
	void CancelMenu(CBaseMenu *menu);
dvander@775
   121
	void ClientPressedKey(int client, unsigned int key_press);
dvander@775
   122
protected:
dvander@1005
   123
	void _CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore=false);
dvander@775
   124
	bool RedoClientMenu(int client, ItemOrder order);
dvander@775
   125
protected:
dvander@775
   126
	FastLink<int> m_WatchList;
dvander@790
   127
	Handle_t m_hHandle;
dvander@775
   128
};
dvander@775
   129
dvander@769
   130
class CBaseMenu : public IBaseMenu
dvander@769
   131
{
dvander@769
   132
public:
dvander@790
   133
	CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner);
dvander@769
   134
	virtual ~CBaseMenu();
dvander@769
   135
public:
dvander@769
   136
	virtual bool AppendItem(const char *info, const ItemDrawInfo &draw);
dvander@769
   137
	virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
dvander@769
   138
	virtual bool RemoveItem(unsigned int position);
dvander@769
   139
	virtual void RemoveAllItems();
dvander@769
   140
	virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL);
dvander@769
   141
	virtual unsigned int GetItemCount();
dvander@769
   142
	virtual bool SetPagination(unsigned int itemsPerPage);
dvander@769
   143
	virtual unsigned int GetPagination();
dvander@769
   144
	virtual IMenuStyle *GetDrawStyle();
dvander@769
   145
	virtual void SetDefaultTitle(const char *message);
dvander@769
   146
	virtual const char *GetDefaultTitle();
dvander@775
   147
	virtual void Cancel();
dvander@790
   148
	virtual void Destroy(bool releaseHandle);
dvander@775
   149
	virtual void Cancel_Finally() =0;
dvander@790
   150
	virtual Handle_t GetHandle();
dvander@1259
   151
	virtual unsigned int GetMenuOptionFlags();
dvander@1259
   152
	virtual void SetMenuOptionFlags(unsigned int flags);
dvander@1269
   153
	virtual IMenuHandler *GetHandler();
dvander@1766
   154
	unsigned int GetBaseMemUsage();
dvander@790
   155
private:
dvander@790
   156
	void InternalDelete();
dvander@769
   157
protected:
dvander@4111
   158
	ke::AString m_Title;
dvander@769
   159
	IMenuStyle *m_pStyle;
dvander@769
   160
	unsigned int m_Pagination;
dvander@4111
   161
	ke::Vector<CItem> m_items;
dvander@778
   162
	bool m_bShouldDelete;
dvander@775
   163
	bool m_bCancelling;
dvander@791
   164
	IdentityToken_t *m_pOwner;
dvander@790
   165
	bool m_bDeleting;
dvander@790
   166
	bool m_bWillFreeHandle;
dvander@790
   167
	Handle_t m_hHandle;
dvander@790
   168
	IMenuHandler *m_pHandler;
dvander@1259
   169
	unsigned int m_nFlags;
dvander@769
   170
};
dvander@769
   171
dvander@769
   172
#endif //_INCLUDE_MENUSTYLE_BASE_H