-
-
Notifications
You must be signed in to change notification settings - Fork 438
/
Copy pathMenuStyle_Base.h
184 lines (172 loc) · 5.69 KB
/
MenuStyle_Base.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#ifndef _INCLUDE_MENUSTYLE_BASE_H
#define _INCLUDE_MENUSTYLE_BASE_H
#include <memory>
#include <utility>
#include <IMenuManager.h>
#include <IPlayerHelpers.h>
#include <am-string.h>
#include <am-vector.h>
#include "sm_fastlink.h"
using namespace SourceMod;
class CItem
{
public:
CItem(unsigned int index)
{
this->index = index;
style = 0;
access = 0;
}
CItem(CItem &&other)
: info(std::move(other.info)),
display(std::move(other.display))
{
index = other.index;
style = other.style;
access = other.access;
}
CItem & operator =(CItem &&other)
{
index = other.index;
info = std::move(other.info);
display = std::move(other.display);
style = other.style;
access = other.access;
return *this;
}
public:
unsigned int index;
std::string info;
std::unique_ptr<std::string> display;
unsigned int style;
unsigned int access;
private:
CItem(const CItem &other) = delete;
CItem &operator =(const CItem &other) = delete;
};
class CBaseMenuPlayer
{
public:
CBaseMenuPlayer() : bInMenu(false), bAutoIgnore(false), bInExternMenu(false)
{
}
menu_states_t states;
bool bInMenu;
bool bAutoIgnore;
float menuStartTime;
unsigned int menuHoldTime;
bool bInExternMenu;
};
class CBaseMenu;
class BaseMenuStyle :
public IMenuStyle,
public IClientListener
{
public:
BaseMenuStyle();
public: //IMenuStyle
bool CancelClientMenu(int client, bool autoIgnore/* =false */);
MenuSource GetClientMenu(int client, void **object);
Handle_t GetHandle();
public: //IClientListener
void OnClientDisconnected(int client);
public: //what derived must implement
virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0;
virtual void SendDisplay(int client, IMenuPanel *display) =0;
public: //what derived may implement
virtual bool DoClientMenu(int client,
CBaseMenu *menu,
unsigned int first_item,
IMenuHandler *mh,
unsigned int time);
virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time);
virtual void AddClientToWatch(int client);
virtual void RemoveClientFromWatch(int client);
virtual void ProcessWatchList();
public: //helpers
void CancelMenu(CBaseMenu *menu);
void ClientPressedKey(int client, unsigned int key_press);
protected:
void _CancelClientMenu(int client, MenuCancelReason reason, bool bAutoIgnore=false);
bool RedoClientMenu(int client, ItemOrder order);
protected:
FastLink<int> m_WatchList;
Handle_t m_hHandle;
};
class CBaseMenu : public IBaseMenu
{
public:
CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner);
virtual ~CBaseMenu();
public:
virtual bool AppendItem(const char *info, const ItemDrawInfo &draw);
virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
virtual bool RemoveItem(unsigned int position);
virtual void RemoveAllItems();
virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL, int client=0);
virtual unsigned int GetItemCount();
virtual bool SetPagination(unsigned int itemsPerPage);
virtual unsigned int GetPagination();
virtual IMenuStyle *GetDrawStyle();
virtual void SetDefaultTitle(const char *message);
virtual const char *GetDefaultTitle();
virtual void Cancel();
virtual void Destroy(bool releaseHandle);
virtual void Cancel_Finally() =0;
virtual Handle_t GetHandle();
virtual unsigned int GetMenuOptionFlags();
virtual void SetMenuOptionFlags(unsigned int flags);
virtual IMenuHandler *GetHandler();
virtual void ShufflePerClient(int start, int stop);
virtual void SetClientMapping(int client, int *array, int length);
virtual bool IsPerClientShuffled();
virtual unsigned int GetRealItemIndex(int client, unsigned int position);
unsigned int GetBaseMemUsage();
private:
void InternalDelete();
protected:
std::string m_Title;
IMenuStyle *m_pStyle;
unsigned int m_Pagination;
std::vector<CItem> m_items;
bool m_bShouldDelete;
bool m_bCancelling;
IdentityToken_t *m_pOwner;
bool m_bDeleting;
bool m_bWillFreeHandle;
Handle_t m_hHandle;
IMenuHandler *m_pHandler;
unsigned int m_nFlags;
std::vector<uint8_t> m_RandomMaps[SM_MAXPLAYERS+1];
};
#endif //_INCLUDE_MENUSTYLE_BASE_H