|
ds@1990
|
1 |
/** |
|
ds@1990
|
2 |
* vim: set ts=4 : |
|
ds@1990
|
3 |
* ============================================================================= |
|
ds@1990
|
4 |
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1990
|
5 |
* ============================================================================= |
|
ds@1990
|
6 |
* |
|
ds@1990
|
7 |
* This file is part of the SourceMod/SourcePawn SDK. |
|
ds@1990
|
8 |
* |
|
ds@1990
|
9 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1990
|
10 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1990
|
11 |
* Free Software Foundation. |
|
ds@1990
|
12 |
* |
|
ds@1990
|
13 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1990
|
14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1990
|
15 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1990
|
16 |
* details. |
|
ds@1990
|
17 |
* |
|
ds@1990
|
18 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1990
|
19 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1990
|
20 |
* |
|
ds@1990
|
21 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1990
|
22 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1990
|
23 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1990
|
24 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1990
|
25 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1990
|
26 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1990
|
27 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1990
|
28 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@1990
|
29 |
* |
|
ds@1990
|
30 |
* Version: $Id$ |
|
ds@1990
|
31 |
*/ |
|
ds@1990
|
32 |
|
|
ds@1990
|
33 |
#if defined _topmenus_included |
|
ds@1990
|
34 |
#endinput |
|
ds@1990
|
35 |
#endif |
|
ds@1990
|
36 |
#define _topmenus_included |
|
ds@1990
|
37 |
|
|
ds@1990
|
38 |
#include <menus> |
|
ds@1990
|
39 |
|
|
ds@1990
|
40 |
/** |
|
ds@1990
|
41 |
* Actions a top menu will take on an object. |
|
ds@1990
|
42 |
*/ |
|
ds@1990
|
43 |
enum TopMenuAction |
|
ds@1990
|
44 |
{ |
|
ds@1990
|
45 |
/** |
|
ds@1990
|
46 |
* An option is being drawn for a menu (or for sorting purposes). |
|
ds@1990
|
47 |
* |
|
ds@1990
|
48 |
* INPUT : TopMenu Handle, object ID, client index. |
|
ds@1990
|
49 |
* OUTPUT: Buffer for rendering, maxlength of buffer. |
|
ds@1990
|
50 |
*/ |
|
ds@1990
|
51 |
TopMenuAction_DisplayOption = 0, |
|
ds@1990
|
52 |
|
|
ds@1990
|
53 |
/** |
|
ds@1990
|
54 |
* The title of a menu is being drawn for a given object. |
|
ds@1990
|
55 |
* |
|
ds@1990
|
56 |
* Note: The Object ID will be INVALID_TOPMENUOBJECT if drawing the |
|
ds@1990
|
57 |
* root title. Otherwise, the Object ID is a category. |
|
ds@1990
|
58 |
* |
|
ds@1990
|
59 |
* INPUT : TopMenu Handle, object ID, client index. |
|
ds@1990
|
60 |
* OUTPUT: Buffer for rendering, maxlength of buffer. |
|
ds@1990
|
61 |
*/ |
|
ds@1990
|
62 |
TopMenuAction_DisplayTitle = 1, |
|
ds@1990
|
63 |
|
|
ds@1990
|
64 |
/** |
|
ds@1990
|
65 |
* A menu option has been selected. |
|
ds@1990
|
66 |
* |
|
ds@1990
|
67 |
* The Object ID will always be an item (not a category). |
|
ds@1990
|
68 |
* |
|
ds@1990
|
69 |
* INPUT : TopMenu Handle, object ID, client index. |
|
ds@1990
|
70 |
*/ |
|
ds@1990
|
71 |
TopMenuAction_SelectOption = 2, |
|
ds@1990
|
72 |
|
|
ds@1990
|
73 |
/** |
|
ds@1990
|
74 |
* A menu option is being drawn and its flags can be overridden. |
|
ds@1990
|
75 |
* |
|
ds@1990
|
76 |
* INPUT : TopMenu Handle, object ID, client index. |
|
ds@1990
|
77 |
* OUTPUT: The first byte of the 'buffer' string should be set |
|
ds@1990
|
78 |
* to the desired flags. By default, it will contain |
|
ds@1990
|
79 |
* ITEMDRAW_DEFAULT. |
|
ds@1990
|
80 |
*/ |
|
ds@1990
|
81 |
TopMenuAction_DrawOption = 3, |
|
ds@1990
|
82 |
|
|
ds@1990
|
83 |
/** |
|
ds@1990
|
84 |
* Called when an object is being removed from the menu. |
|
ds@1990
|
85 |
* This can be used to clean up data stored in the info string. |
|
ds@1990
|
86 |
* |
|
ds@1990
|
87 |
* INPUT : TopMenu Handle, object ID. |
|
ds@1990
|
88 |
*/ |
|
ds@1990
|
89 |
TopMenuAction_RemoveObject = 4, |
|
ds@1990
|
90 |
}; |
|
ds@1990
|
91 |
|
|
ds@1990
|
92 |
/** |
|
ds@1990
|
93 |
* Top menu object types. |
|
ds@1990
|
94 |
*/ |
|
ds@1990
|
95 |
enum TopMenuObjectType |
|
ds@1990
|
96 |
{ |
|
ds@1990
|
97 |
TopMenuObject_Category = 0, /**< Category (sub-menu branching from root) */ |
|
ds@1990
|
98 |
TopMenuObject_Item = 1 /**< Item on a sub-menu */ |
|
ds@1990
|
99 |
}; |
|
ds@1990
|
100 |
|
|
ds@1990
|
101 |
/** |
|
ds@1990
|
102 |
* Top menu starting positions for display. |
|
ds@1990
|
103 |
*/ |
|
ds@1990
|
104 |
enum TopMenuPosition |
|
ds@1990
|
105 |
{ |
|
ds@1990
|
106 |
TopMenuPosition_Start = 0, /**< Start/root of the menu */ |
|
ds@1990
|
107 |
TopMenuPosition_LastRoot = 1, /**< Last position in the root menu */ |
|
ds@1990
|
108 |
TopMenuPosition_LastCategory = 3, /**< Last position in their last category */ |
|
ds@1990
|
109 |
}; |
|
ds@1990
|
110 |
|
|
ds@1990
|
111 |
/** |
|
ds@1990
|
112 |
* Top menu object tag for type checking. |
|
ds@1990
|
113 |
*/ |
|
ds@1990
|
114 |
enum TopMenuObject |
|
ds@1990
|
115 |
{ |
|
ds@1990
|
116 |
INVALID_TOPMENUOBJECT = 0, |
|
ds@1990
|
117 |
} |
|
ds@1990
|
118 |
|
|
ds@1990
|
119 |
/** |
|
ds@1990
|
120 |
* TopMenu callback prototype. |
|
ds@1990
|
121 |
* |
|
ds@1990
|
122 |
* @param topmenu Handle to the TopMenu. |
|
ds@1990
|
123 |
* @param action TopMenuAction being performed. |
|
ds@1990
|
124 |
* @param object_id The object ID (if used). |
|
ds@1990
|
125 |
* @param param Extra parameter (if used). |
|
ds@1990
|
126 |
* @param buffer Output buffer (if used). |
|
ds@1990
|
127 |
* @param maxlength Output buffer (if used). |
|
ds@1990
|
128 |
* @noreturn |
|
ds@1990
|
129 |
*/ |
|
ds@1990
|
130 |
functag TopMenuHandler public(Handle:topmenu, |
|
ds@1990
|
131 |
TopMenuAction:action, |
|
ds@1990
|
132 |
TopMenuObject:object_id, |
|
ds@1990
|
133 |
param, |
|
ds@1990
|
134 |
String:buffer[], |
|
ds@1990
|
135 |
maxlength); |
|
ds@1990
|
136 |
|
|
ds@1990
|
137 |
/** |
|
ds@1990
|
138 |
* Creates a TopMenu. |
|
ds@1990
|
139 |
* |
|
ds@1990
|
140 |
* @param handler Handler to use for drawing the root title. |
|
ds@1990
|
141 |
* @return A new TopMenu Handle, or INVALID_HANDLE on failure. |
|
ds@1990
|
142 |
*/ |
|
ds@1990
|
143 |
native Handle:CreateTopMenu(TopMenuHandler:handler); |
|
ds@1990
|
144 |
|
|
ds@1990
|
145 |
/** |
|
ds@1990
|
146 |
* Re-sorts the items in a TopMenu via a configuration file. |
|
ds@1990
|
147 |
* |
|
ds@1990
|
148 |
* The format of the configuration file should be a Valve Key-Values |
|
ds@1990
|
149 |
* formatted file that SourceMod can parse. There should be one root |
|
ds@1990
|
150 |
* section, and one sub-section for each category. Each sub-section's |
|
ds@1990
|
151 |
* name should match the category name. |
|
ds@1990
|
152 |
* |
|
ds@1990
|
153 |
* Each sub-section may only contain key/value pairs in the form of: |
|
ds@1990
|
154 |
* key: "item" |
|
ds@1990
|
155 |
* value: Name of the item as passed to AddToTopMenu(). |
|
ds@1990
|
156 |
* |
|
ds@1990
|
157 |
* The TopMenu will draw items in the order declared in the configuration |
|
ds@1990
|
158 |
* file. If items do not appear in the configuration file, they are sorted |
|
ds@1990
|
159 |
* per-player based on how the handler function renders for that player. |
|
ds@1990
|
160 |
* These items appear after the configuration sorted items. |
|
ds@1990
|
161 |
* |
|
ds@1990
|
162 |
* @param topmenu TopMenu Handle. |
|
ds@1990
|
163 |
* @param file File path. |
|
ds@1990
|
164 |
* @param error Error buffer. |
|
ds@1990
|
165 |
* @param maxlength Maximum size of the error buffer. |
|
ds@1990
|
166 |
* Error buffer will be filled with a |
|
ds@1990
|
167 |
* zero-terminated string if false is |
|
ds@1990
|
168 |
* returned. |
|
ds@1990
|
169 |
* @return True on success, false on failure. |
|
ds@1990
|
170 |
* @error Invalid TopMenu Handle. |
|
ds@1990
|
171 |
*/ |
|
ds@1990
|
172 |
native bool:LoadTopMenuConfig(Handle:topmenu, const String:file[], String:error[], maxlength); |
|
ds@1990
|
173 |
|
|
ds@1990
|
174 |
/** |
|
ds@1990
|
175 |
* Adds an object to a TopMenu. |
|
ds@1990
|
176 |
* |
|
ds@1990
|
177 |
* @param topmenu TopMenu Handle. |
|
ds@1990
|
178 |
* @param name Object name (MUST be unique). |
|
ds@1990
|
179 |
* @param type Object type. |
|
ds@1990
|
180 |
* @param handler Handler for object. |
|
ds@1990
|
181 |
* @param cmdname Command name (for access overrides). |
|
ds@1990
|
182 |
* @param flags Default access flags. |
|
ds@1990
|
183 |
* @param parent Parent object ID, or INVALID_TOPMENUOBJECT for none. |
|
ds@1990
|
184 |
* Items must have a category parent. |
|
ds@1990
|
185 |
* Categories must not have a parent. |
|
ds@1990
|
186 |
* @param info_string Arbitrary storage (max 255 bytes). |
|
ds@1990
|
187 |
* @return A new TopMenuObject ID, or INVALID_TOPMENUOBJECT on |
|
ds@1990
|
188 |
* failure. |
|
ds@1990
|
189 |
* @error Invalid TopMenu Handle. |
|
ds@1990
|
190 |
*/ |
|
ds@1990
|
191 |
native TopMenuObject:AddToTopMenu(Handle:topmenu, |
|
ds@1990
|
192 |
const String:name[], |
|
ds@1990
|
193 |
TopMenuObjectType:type, |
|
ds@1990
|
194 |
TopMenuHandler:handler, |
|
ds@1990
|
195 |
TopMenuObject:parent, |
|
ds@1990
|
196 |
const String:cmdname[]="", |
|
ds@1990
|
197 |
flags=0, |
|
ds@1990
|
198 |
const String:info_string[]=""); |
|
ds@1990
|
199 |
|
|
ds@1990
|
200 |
/** |
|
ds@1990
|
201 |
* Retrieves the info string of a top menu item. |
|
ds@1990
|
202 |
* |
|
ds@1990
|
203 |
* @param topmenu TopMenu Handle. |
|
ds@1990
|
204 |
* @param object TopMenuObject ID. |
|
ds@1990
|
205 |
* @param buffer Buffer to store info string. |
|
ds@1990
|
206 |
* @param maxlength Maximum size of info string. |
|
ds@1990
|
207 |
* @return Number of bytes written, not including the |
|
ds@1990
|
208 |
* null terminator. |
|
ds@1990
|
209 |
* @error Invalid TopMenu Handle or TopMenuObject ID. |
|
ds@1990
|
210 |
*/ |
|
ds@1990
|
211 |
native GetTopMenuInfoString(Handle:topmenu, TopMenuObject:parent, String:buffer[], maxlength); |
|
ds@1990
|
212 |
|
|
ds@1990
|
213 |
/** |
|
ds@1990
|
214 |
* Retrieves the name string of a top menu item. |
|
ds@1990
|
215 |
* |
|
ds@1990
|
216 |
* @param topmenu TopMenu Handle. |
|
ds@1990
|
217 |
* @param object TopMenuObject ID. |
|
ds@1990
|
218 |
* @param buffer Buffer to store info string. |
|
ds@1990
|
219 |
* @param maxlength Maximum size of info string. |
|
ds@1990
|
220 |
* @return Number of bytes written, not including the |
|
ds@1990
|
221 |
* null terminator. |
|
ds@1990
|
222 |
* @error Invalid TopMenu Handle or TopMenuObject ID. |
|
ds@1990
|
223 |
*/ |
|
ds@1990
|
224 |
native GetTopMenuObjName(Handle:topmenu, TopMenuObject:object, String:buffer[], maxlength); |
|
ds@1990
|
225 |
|
|
ds@1990
|
226 |
/** |
|
ds@1990
|
227 |
* Removes an object from a TopMenu. |
|
ds@1990
|
228 |
* |
|
ds@1990
|
229 |
* Plugins' objects are automatically removed all TopMenus when the given |
|
ds@1990
|
230 |
* plugin unloads or pauses. In the case of unpausing, all items are restored. |
|
ds@1990
|
231 |
* |
|
ds@1990
|
232 |
* @param topmenu TopMenu Handle. |
|
ds@1990
|
233 |
* @param object TopMenuObject ID. |
|
ds@1990
|
234 |
* @noreturn |
|
ds@1990
|
235 |
* @error Invalid TopMenu Handle. |
|
ds@1990
|
236 |
*/ |
|
ds@1990
|
237 |
native RemoveFromTopMenu(Handle:topmenu, TopMenuObject:object); |
|
ds@1990
|
238 |
|
|
ds@1990
|
239 |
/** |
|
ds@1990
|
240 |
* Displays a TopMenu to a client. |
|
ds@1990
|
241 |
* |
|
ds@1990
|
242 |
* @param topmenu TopMenu Handle. |
|
ds@1990
|
243 |
* @param client Client index. |
|
ds@1990
|
244 |
* @param position Position to display from. |
|
ds@1990
|
245 |
* @return True on success, false on failure. |
|
ds@1990
|
246 |
* @error Invalid TopMenu Handle or client not in game. |
|
ds@1990
|
247 |
*/ |
|
ds@1990
|
248 |
native bool:DisplayTopMenu(Handle:topmenu, client, TopMenuPosition:position); |
|
ds@1990
|
249 |
|
|
ds@1990
|
250 |
/** |
|
ds@1990
|
251 |
* Finds a category's object ID in a TopMenu. |
|
ds@1990
|
252 |
* |
|
ds@1990
|
253 |
* @param topmenu TopMenu Handle. |
|
ds@1990
|
254 |
* @param name Object's unique name. |
|
ds@1990
|
255 |
* @return TopMenuObject ID on success, or |
|
ds@1990
|
256 |
* INVALID_TOPMENUOBJECT on failure. |
|
ds@1990
|
257 |
* @error Invalid TopMenu Handle. |
|
ds@1990
|
258 |
*/ |
|
ds@1990
|
259 |
native TopMenuObject:FindTopMenuCategory(Handle:topmenu, const String:name[]); |
|
ds@1990
|
260 |
|
|
ds@1990
|
261 |
/** |
|
ds@1990
|
262 |
* Do not edit below this line! |
|
ds@1990
|
263 |
*/ |
|
ds@1990
|
264 |
public Extension:__ext_topmenus = |
|
ds@1990
|
265 |
{ |
|
ds@1990
|
266 |
name = "TopMenus", |
|
ds@1990
|
267 |
file = "topmenus.ext", |
|
ds@1990
|
268 |
#if defined AUTOLOAD_EXTENSIONS |
|
ds@1990
|
269 |
autoload = 1, |
|
ds@1990
|
270 |
#else |
|
ds@1990
|
271 |
autoload = 0, |
|
ds@1990
|
272 |
#endif |
|
ds@1990
|
273 |
#if defined REQUIRE_EXTENSIONS |
|
ds@1990
|
274 |
required = 1, |
|
ds@1990
|
275 |
#else |
|
ds@1990
|
276 |
required = 0, |
|
ds@1990
|
277 |
#endif |
|
ds@1990
|
278 |
}; |
|
ds@1990
|
279 |
|
|
ds@1990
|
280 |
#if !defined REQUIRE_EXTENSIONS |
|
ds@1990
|
281 |
public __ext_topmenus_SetNTVOptional() |
|
ds@1990
|
282 |
{ |
|
ds@1990
|
283 |
MarkNativeAsOptional("CreateTopMenu"); |
|
ds@1990
|
284 |
MarkNativeAsOptional("LoadTopMenuConfig"); |
|
ds@1990
|
285 |
MarkNativeAsOptional("AddToTopMenu"); |
|
ds@1990
|
286 |
MarkNativeAsOptional("RemoveFromTopMenu"); |
|
ds@1990
|
287 |
MarkNativeAsOptional("DisplayTopMenu"); |
|
ds@1990
|
288 |
MarkNativeAsOptional("FindTopMenuCategory"); |
|
ds@1990
|
289 |
} |
|
ds@1990
|
290 |
#endif |