core/MenuStyle_Base.h
author David Anderson <dvander@alliedmods.net>
Mon Oct 14 11:56:43 2013 -0700 (2013-10-14)
changeset 4147 ee4b042d33db
parent 4111 34b8688e3bec
child 4175 3ae24e84c028
permissions -rw-r--r--
Update linux dep script (no bug, r=NPOTB).
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@4111
    48
		info.setVoid();
dvander@4111
    49
		display.setVoid();
dvander@769
    50
		style = 0;
dvander@1163
    51
		access = 0;
dvander@769
    52
	}
dvander@4111
    53
	CItem(ke::Moveable<CItem> other)
dvander@4111
    54
	: info(ke::Move(other->info)),
dvander@4111
    55
	  display(ke::Move(other->display))
dvander@4111
    56
	{
dvander@4111
    57
		style = other->style;
dvander@4111
    58
		access = other->access;
dvander@4111
    59
	}
dvander@769
    60
public:
dvander@4111
    61
	ke::AString info;
dvander@4111
    62
	ke::AString display;
dvander@769
    63
	unsigned int style;
dvander@1163
    64
	unsigned int access;
dvander@769
    65
};
dvander@769
    66
dvander@775
    67
class CBaseMenuPlayer
dvander@775
    68
{
dvander@775
    69
public:
dvander@780
    70
	CBaseMenuPlayer() : bInMenu(false), bAutoIgnore(false), bInExternMenu(false)
dvander@775
    71
	{
dvander@775
    72
	}
dvander@775
    73
	menu_states_t states;
dvander@775
    74
	bool bInMenu;
dvander@775
    75
	bool bAutoIgnore;
dvander@775
    76
	float menuStartTime;
dvander@775
    77
	unsigned int menuHoldTime;
dvander@780
    78
	bool bInExternMenu;
dvander@775
    79
};
dvander@775
    80
dvander@775
    81
class CBaseMenu;
dvander@775
    82
dvander@775
    83
class BaseMenuStyle : 
dvander@775
    84
	public IMenuStyle,
dvander@775
    85
	public IClientListener
dvander@775
    86
{
dvander@775
    87
public:
dvander@775
    88
	BaseMenuStyle();
dvander@775
    89
public: //IMenuStyle
dvander@775
    90
	bool CancelClientMenu(int client, bool autoIgnore/* =false */);
dvander@775
    91
	MenuSource GetClientMenu(int client, void **object);
dvander@790
    92
	Handle_t GetHandle();
dvander@775
    93
public: //IClientListener
dvander@775
    94
	void OnClientDisconnected(int client);
dvander@775
    95
public: //what derived must implement
dvander@775
    96
	virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0;
dvander@787
    97
	virtual void SendDisplay(int client, IMenuPanel *display) =0;
dvander@775
    98
public: //what derived may implement 
dvander@1474
    99
	virtual bool DoClientMenu(int client, 
dvander@1474
   100
		CBaseMenu *menu, 
dvander@1474
   101
		unsigned int first_item,
dvander@1474
   102
		IMenuHandler *mh, 
dvander@1474
   103
		unsigned int time);
dvander@787
   104
	virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
dvander@775
   105
	virtual void AddClientToWatch(int client);
dvander@775
   106
	virtual void RemoveClientFromWatch(int client);
dvander@775
   107
	virtual void ProcessWatchList();
dvander@775
   108
public: //helpers
dvander@775
   109
	void CancelMenu(CBaseMenu *menu);
dvander@775
   110
	void ClientPressedKey(int client, unsigned int key_press);
dvander@775
   111
protected:
dvander@1005
   112
	void _CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore=false);
dvander@775
   113
	bool RedoClientMenu(int client, ItemOrder order);
dvander@775
   114
protected:
dvander@775
   115
	FastLink<int> m_WatchList;
dvander@790
   116
	Handle_t m_hHandle;
dvander@775
   117
};
dvander@775
   118
dvander@769
   119
class CBaseMenu : public IBaseMenu
dvander@769
   120
{
dvander@769
   121
public:
dvander@790
   122
	CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner);
dvander@769
   123
	virtual ~CBaseMenu();
dvander@769
   124
public:
dvander@769
   125
	virtual bool AppendItem(const char *info, const ItemDrawInfo &draw);
dvander@769
   126
	virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
dvander@769
   127
	virtual bool RemoveItem(unsigned int position);
dvander@769
   128
	virtual void RemoveAllItems();
dvander@769
   129
	virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL);
dvander@769
   130
	virtual unsigned int GetItemCount();
dvander@769
   131
	virtual bool SetPagination(unsigned int itemsPerPage);
dvander@769
   132
	virtual unsigned int GetPagination();
dvander@769
   133
	virtual IMenuStyle *GetDrawStyle();
dvander@769
   134
	virtual void SetDefaultTitle(const char *message);
dvander@769
   135
	virtual const char *GetDefaultTitle();
dvander@775
   136
	virtual void Cancel();
dvander@790
   137
	virtual void Destroy(bool releaseHandle);
dvander@775
   138
	virtual void Cancel_Finally() =0;
dvander@790
   139
	virtual Handle_t GetHandle();
dvander@1259
   140
	virtual unsigned int GetMenuOptionFlags();
dvander@1259
   141
	virtual void SetMenuOptionFlags(unsigned int flags);
dvander@1269
   142
	virtual IMenuHandler *GetHandler();
dvander@1766
   143
	unsigned int GetBaseMemUsage();
dvander@790
   144
private:
dvander@790
   145
	void InternalDelete();
dvander@769
   146
protected:
dvander@4111
   147
	ke::AString m_Title;
dvander@769
   148
	IMenuStyle *m_pStyle;
dvander@769
   149
	unsigned int m_Pagination;
dvander@4111
   150
	ke::Vector<CItem> m_items;
dvander@778
   151
	bool m_bShouldDelete;
dvander@775
   152
	bool m_bCancelling;
dvander@791
   153
	IdentityToken_t *m_pOwner;
dvander@790
   154
	bool m_bDeleting;
dvander@790
   155
	bool m_bWillFreeHandle;
dvander@790
   156
	Handle_t m_hHandle;
dvander@790
   157
	IMenuHandler *m_pHandler;
dvander@1259
   158
	unsigned int m_nFlags;
dvander@769
   159
};
dvander@769
   160
dvander@769
   161
#endif //_INCLUDE_MENUSTYLE_BASE_H