3 * =============================================================================
4 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _topmenus_included
36 #define _topmenus_included
41 * Actions a top menu will take on an object.
46 * An option is being drawn for a menu (or for sorting purposes).
48 * INPUT : TopMenu Handle, object ID, client index.
49 * OUTPUT: Buffer for rendering, maxlength of buffer.
51 TopMenuAction_DisplayOption = 0,
54 * The title of a menu is being drawn for a given object.
56 * Note: The Object ID will be INVALID_TOPMENUOBJECT if drawing the
57 * root title. Otherwise, the Object ID is a category.
59 * INPUT : TopMenu Handle, object ID, client index.
60 * OUTPUT: Buffer for rendering, maxlength of buffer.
62 TopMenuAction_DisplayTitle = 1,
65 * A menu option has been selected.
67 * The Object ID will always be an item (not a category).
69 * INPUT : TopMenu Handle, object ID, client index.
71 TopMenuAction_SelectOption = 2,
74 * A menu option is being drawn and its flags can be overridden.
76 * INPUT : TopMenu Handle, object ID, client index.
77 * OUTPUT: The first byte of the 'buffer' string should be set
78 * to the desired flags. By default, it will contain
81 TopMenuAction_DrawOption = 3,
84 * Called when an object is being removed from the menu.
85 * This can be used to clean up data stored in the info string.
87 * INPUT : TopMenu Handle, object ID.
89 TopMenuAction_RemoveObject = 4,
93 * Top menu object types.
95 enum TopMenuObjectType
97 TopMenuObject_Category = 0, /**< Category (sub-menu branching from root) */
98 TopMenuObject_Item = 1 /**< Item on a sub-menu */
102 * Top menu starting positions for display.
106 TopMenuPosition_Start = 0, /**< Start/root of the menu */
107 TopMenuPosition_LastRoot = 1, /**< Last position in the root menu */
108 TopMenuPosition_LastCategory = 3, /**< Last position in their last category */
112 * Top menu object tag for type checking.
116 INVALID_TOPMENUOBJECT = 0,
120 * TopMenu callback prototype.
122 * @param topmenu Handle to the TopMenu.
123 * @param action TopMenuAction being performed.
124 * @param object_id The object ID (if used).
125 * @param param Extra parameter (if used).
126 * @param buffer Output buffer (if used).
127 * @param maxlength Output buffer (if used).
130 functag public TopMenuHandler(Handle:topmenu,
131 TopMenuAction:action,
132 TopMenuObject:object_id,
140 * @param handler Handler to use for drawing the root title.
141 * @return A new TopMenu Handle, or INVALID_HANDLE on failure.
143 native Handle:CreateTopMenu(TopMenuHandler:handler);
146 * Re-sorts the items in a TopMenu via a configuration file.
148 * The format of the configuration file should be a Valve Key-Values
149 * formatted file that SourceMod can parse. There should be one root
150 * section, and one sub-section for each category. Each sub-section's
151 * name should match the category name.
153 * Each sub-section may only contain key/value pairs in the form of:
155 * value: Name of the item as passed to AddToTopMenu().
157 * The TopMenu will draw items in the order declared in the configuration
158 * file. If items do not appear in the configuration file, they are sorted
159 * per-player based on how the handler function renders for that player.
160 * These items appear after the configuration sorted items.
162 * @param topmenu TopMenu Handle.
163 * @param file File path.
164 * @param error Error buffer.
165 * @param maxlength Maximum size of the error buffer.
166 * Error buffer will be filled with a
167 * zero-terminated string if false is
169 * @return True on success, false on failure.
170 * @error Invalid TopMenu Handle.
172 native bool:LoadTopMenuConfig(Handle:topmenu, const String:file[], String:error[], maxlength);
175 * Adds an object to a TopMenu.
177 * @param topmenu TopMenu Handle.
178 * @param name Object name (MUST be unique).
179 * @param type Object type.
180 * @param handler Handler for object.
181 * @param cmdname Command name (for access overrides).
182 * @param flags Default access flags.
183 * @param parent Parent object ID, or INVALID_TOPMENUOBJECT for none.
184 * Items must have a category parent.
185 * Categories must not have a parent.
186 * @param info_string Arbitrary storage (max 255 bytes).
187 * @return A new TopMenuObject ID, or INVALID_TOPMENUOBJECT on
189 * @error Invalid TopMenu Handle.
191 native TopMenuObject:AddToTopMenu(Handle:topmenu,
193 TopMenuObjectType:type,
194 TopMenuHandler:handler,
195 TopMenuObject:parent,
196 const String:cmdname[]="",
198 const String:info_string[]="");
201 * Retrieves the info string of a top menu item.
203 * @param topmenu TopMenu Handle.
204 * @param object TopMenuObject ID.
205 * @param buffer Buffer to store info string.
206 * @param maxlength Maximum size of info string.
207 * @return Number of bytes written, not including the
209 * @error Invalid TopMenu Handle or TopMenuObject ID.
211 native GetTopMenuInfoString(Handle:topmenu, TopMenuObject:parent, String:buffer[], maxlength);
214 * Retrieves the name string of a top menu item.
216 * @param topmenu TopMenu Handle.
217 * @param object TopMenuObject ID.
218 * @param buffer Buffer to store info string.
219 * @param maxlength Maximum size of info string.
220 * @return Number of bytes written, not including the
222 * @error Invalid TopMenu Handle or TopMenuObject ID.
224 native GetTopMenuObjName(Handle:topmenu, TopMenuObject:object, String:buffer[], maxlength);
227 * Removes an object from a TopMenu.
229 * Plugins' objects are automatically removed all TopMenus when the given
230 * plugin unloads or pauses. In the case of unpausing, all items are restored.
232 * @param topmenu TopMenu Handle.
233 * @param object TopMenuObject ID.
235 * @error Invalid TopMenu Handle.
237 native RemoveFromTopMenu(Handle:topmenu, TopMenuObject:object);
240 * Displays a TopMenu to a client.
242 * @param topmenu TopMenu Handle.
243 * @param client Client index.
244 * @param position Position to display from.
245 * @return True on success, false on failure.
246 * @error Invalid TopMenu Handle or client not in game.
248 native bool:DisplayTopMenu(Handle:topmenu, client, TopMenuPosition:position);
251 * Finds a category's object ID in a TopMenu.
253 * @param topmenu TopMenu Handle.
254 * @param name Object's unique name.
255 * @return TopMenuObject ID on success, or
256 * INVALID_TOPMENUOBJECT on failure.
257 * @error Invalid TopMenu Handle.
259 native TopMenuObject:FindTopMenuCategory(Handle:topmenu, const String:name[]);
262 * Do not edit below this line!
264 public Extension:__ext_topmenus =
267 file = "topmenus.ext",
268 #if defined AUTOLOAD_EXTENSIONS
273 #if defined REQUIRE_EXTENSIONS
280 #if !defined REQUIRE_EXTENSIONS
281 public __ext_topmenus_SetNTVOptional()
283 MarkNativeAsOptional("CreateTopMenu");
284 MarkNativeAsOptional("LoadTopMenuConfig");
285 MarkNativeAsOptional("AddToTopMenu");
286 MarkNativeAsOptional("RemoveFromTopMenu");
287 MarkNativeAsOptional("DisplayTopMenu");
288 MarkNativeAsOptional("FindTopMenuCategory");