1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/include/topmenus.inc Sun Jul 06 04:49:55 2008 +0000
1.3 @@ -0,0 +1,290 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.8 + * =============================================================================
1.9 + *
1.10 + * This file is part of the SourceMod/SourcePawn SDK.
1.11 + *
1.12 + * This program is free software; you can redistribute it and/or modify it under
1.13 + * the terms of the GNU General Public License, version 3.0, as published by the
1.14 + * Free Software Foundation.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 + * details.
1.20 + *
1.21 + * You should have received a copy of the GNU General Public License along with
1.22 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.23 + *
1.24 + * As a special exception, AlliedModders LLC gives you permission to link the
1.25 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.26 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.27 + * by the Valve Corporation. You must obey the GNU General Public License in
1.28 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.29 + * this exception to all derivative works. AlliedModders LLC defines further
1.30 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.31 + * or <http://www.sourcemod.net/license.php>.
1.32 + *
1.33 + * Version: $Id$
1.34 + */
1.35 +
1.36 +#if defined _topmenus_included
1.37 + #endinput
1.38 +#endif
1.39 +#define _topmenus_included
1.40 +
1.41 +#include <menus>
1.42 +
1.43 +/**
1.44 + * Actions a top menu will take on an object.
1.45 + */
1.46 +enum TopMenuAction
1.47 +{
1.48 + /**
1.49 + * An option is being drawn for a menu (or for sorting purposes).
1.50 + *
1.51 + * INPUT : TopMenu Handle, object ID, client index.
1.52 + * OUTPUT: Buffer for rendering, maxlength of buffer.
1.53 + */
1.54 + TopMenuAction_DisplayOption = 0,
1.55 +
1.56 + /**
1.57 + * The title of a menu is being drawn for a given object.
1.58 + *
1.59 + * Note: The Object ID will be INVALID_TOPMENUOBJECT if drawing the
1.60 + * root title. Otherwise, the Object ID is a category.
1.61 + *
1.62 + * INPUT : TopMenu Handle, object ID, client index.
1.63 + * OUTPUT: Buffer for rendering, maxlength of buffer.
1.64 + */
1.65 + TopMenuAction_DisplayTitle = 1,
1.66 +
1.67 + /**
1.68 + * A menu option has been selected.
1.69 + *
1.70 + * The Object ID will always be an item (not a category).
1.71 + *
1.72 + * INPUT : TopMenu Handle, object ID, client index.
1.73 + */
1.74 + TopMenuAction_SelectOption = 2,
1.75 +
1.76 + /**
1.77 + * A menu option is being drawn and its flags can be overridden.
1.78 + *
1.79 + * INPUT : TopMenu Handle, object ID, client index.
1.80 + * OUTPUT: The first byte of the 'buffer' string should be set
1.81 + * to the desired flags. By default, it will contain
1.82 + * ITEMDRAW_DEFAULT.
1.83 + */
1.84 + TopMenuAction_DrawOption = 3,
1.85 +
1.86 + /**
1.87 + * Called when an object is being removed from the menu.
1.88 + * This can be used to clean up data stored in the info string.
1.89 + *
1.90 + * INPUT : TopMenu Handle, object ID.
1.91 + */
1.92 + TopMenuAction_RemoveObject = 4,
1.93 +};
1.94 +
1.95 +/**
1.96 + * Top menu object types.
1.97 + */
1.98 +enum TopMenuObjectType
1.99 +{
1.100 + TopMenuObject_Category = 0, /**< Category (sub-menu branching from root) */
1.101 + TopMenuObject_Item = 1 /**< Item on a sub-menu */
1.102 +};
1.103 +
1.104 +/**
1.105 + * Top menu starting positions for display.
1.106 + */
1.107 +enum TopMenuPosition
1.108 +{
1.109 + TopMenuPosition_Start = 0, /**< Start/root of the menu */
1.110 + TopMenuPosition_LastRoot = 1, /**< Last position in the root menu */
1.111 + TopMenuPosition_LastCategory = 3, /**< Last position in their last category */
1.112 +};
1.113 +
1.114 +/**
1.115 + * Top menu object tag for type checking.
1.116 + */
1.117 +enum TopMenuObject
1.118 +{
1.119 + INVALID_TOPMENUOBJECT = 0,
1.120 +};
1.121 +
1.122 +/**
1.123 + * TopMenu callback prototype.
1.124 + *
1.125 + * @param topmenu Handle to the TopMenu.
1.126 + * @param action TopMenuAction being performed.
1.127 + * @param object_id The object ID (if used).
1.128 + * @param param Extra parameter (if used).
1.129 + * @param buffer Output buffer (if used).
1.130 + * @param maxlength Output buffer (if used).
1.131 + * @noreturn
1.132 + */
1.133 +functag TopMenuHandler public(Handle:topmenu,
1.134 + TopMenuAction:action,
1.135 + TopMenuObject:object_id,
1.136 + param,
1.137 + String:buffer[],
1.138 + maxlength);
1.139 +
1.140 +/**
1.141 + * Creates a TopMenu.
1.142 + *
1.143 + * @param handler Handler to use for drawing the root title.
1.144 + * @return A new TopMenu Handle, or INVALID_HANDLE on failure.
1.145 + */
1.146 +native Handle:CreateTopMenu(TopMenuHandler:handler);
1.147 +
1.148 +/**
1.149 + * Re-sorts the items in a TopMenu via a configuration file.
1.150 + *
1.151 + * The format of the configuration file should be a Valve Key-Values
1.152 + * formatted file that SourceMod can parse. There should be one root
1.153 + * section, and one sub-section for each category. Each sub-section's
1.154 + * name should match the category name.
1.155 + *
1.156 + * Each sub-section may only contain key/value pairs in the form of:
1.157 + * key: "item"
1.158 + * value: Name of the item as passed to AddToTopMenu().
1.159 + *
1.160 + * The TopMenu will draw items in the order declared in the configuration
1.161 + * file. If items do not appear in the configuration file, they are sorted
1.162 + * per-player based on how the handler function renders for that player.
1.163 + * These items appear after the configuration sorted items.
1.164 + *
1.165 + * @param topmenu TopMenu Handle.
1.166 + * @param file File path.
1.167 + * @param error Error buffer.
1.168 + * @param maxlength Maximum size of the error buffer.
1.169 + * Error buffer will be filled with a
1.170 + * zero-terminated string if false is
1.171 + * returned.
1.172 + * @return True on success, false on failure.
1.173 + * @error Invalid TopMenu Handle.
1.174 + */
1.175 +native bool:LoadTopMenuConfig(Handle:topmenu, const String:file[], String:error[], maxlength);
1.176 +
1.177 +/**
1.178 + * Adds an object to a TopMenu.
1.179 + *
1.180 + * @param topmenu TopMenu Handle.
1.181 + * @param name Object name (MUST be unique).
1.182 + * @param type Object type.
1.183 + * @param handler Handler for object.
1.184 + * @param cmdname Command name (for access overrides).
1.185 + * @param flags Default access flags.
1.186 + * @param parent Parent object ID, or INVALID_TOPMENUOBJECT for none.
1.187 + * Items must have a category parent.
1.188 + * Categories must not have a parent.
1.189 + * @param info_string Arbitrary storage (max 255 bytes).
1.190 + * @return A new TopMenuObject ID, or INVALID_TOPMENUOBJECT on
1.191 + * failure.
1.192 + * @error Invalid TopMenu Handle.
1.193 + */
1.194 +native TopMenuObject:AddToTopMenu(Handle:topmenu,
1.195 + const String:name[],
1.196 + TopMenuObjectType:type,
1.197 + TopMenuHandler:handler,
1.198 + TopMenuObject:parent,
1.199 + const String:cmdname[]="",
1.200 + flags=0,
1.201 + const String:info_string[]="");
1.202 +
1.203 +/**
1.204 + * Retrieves the info string of a top menu item.
1.205 + *
1.206 + * @param topmenu TopMenu Handle.
1.207 + * @param object TopMenuObject ID.
1.208 + * @param buffer Buffer to store info string.
1.209 + * @param maxlength Maximum size of info string.
1.210 + * @return Number of bytes written, not including the
1.211 + * null terminator.
1.212 + * @error Invalid TopMenu Handle or TopMenuObject ID.
1.213 + */
1.214 +native GetTopMenuInfoString(Handle:topmenu, TopMenuObject:parent, String:buffer[], maxlength);
1.215 +
1.216 +/**
1.217 + * Retrieves the name string of a top menu item.
1.218 + *
1.219 + * @param topmenu TopMenu Handle.
1.220 + * @param object TopMenuObject ID.
1.221 + * @param buffer Buffer to store info string.
1.222 + * @param maxlength Maximum size of info string.
1.223 + * @return Number of bytes written, not including the
1.224 + * null terminator.
1.225 + * @error Invalid TopMenu Handle or TopMenuObject ID.
1.226 + */
1.227 +native GetTopMenuObjName(Handle:topmenu, TopMenuObject:object, String:buffer[], maxlength);
1.228 +
1.229 +/**
1.230 + * Removes an object from a TopMenu.
1.231 + *
1.232 + * Plugins' objects are automatically removed all TopMenus when the given
1.233 + * plugin unloads or pauses. In the case of unpausing, all items are restored.
1.234 + *
1.235 + * @param topmenu TopMenu Handle.
1.236 + * @param object TopMenuObject ID.
1.237 + * @noreturn
1.238 + * @error Invalid TopMenu Handle.
1.239 + */
1.240 +native RemoveFromTopMenu(Handle:topmenu, TopMenuObject:object);
1.241 +
1.242 +/**
1.243 + * Displays a TopMenu to a client.
1.244 + *
1.245 + * @param topmenu TopMenu Handle.
1.246 + * @param client Client index.
1.247 + * @param position Position to display from.
1.248 + * @return True on success, false on failure.
1.249 + * @error Invalid TopMenu Handle or client not in game.
1.250 + */
1.251 +native bool:DisplayTopMenu(Handle:topmenu, client, TopMenuPosition:position);
1.252 +
1.253 +/**
1.254 + * Finds a category's object ID in a TopMenu.
1.255 + *
1.256 + * @param topmenu TopMenu Handle.
1.257 + * @param name Object's unique name.
1.258 + * @return TopMenuObject ID on success, or
1.259 + * INVALID_TOPMENUOBJECT on failure.
1.260 + * @error Invalid TopMenu Handle.
1.261 + */
1.262 +native TopMenuObject:FindTopMenuCategory(Handle:topmenu, const String:name[]);
1.263 +
1.264 +/**
1.265 + * Do not edit below this line!
1.266 + */
1.267 +public Extension:__ext_topmenus =
1.268 +{
1.269 + name = "TopMenus",
1.270 + file = "topmenus.ext",
1.271 +#if defined AUTOLOAD_EXTENSIONS
1.272 + autoload = 1,
1.273 +#else
1.274 + autoload = 0,
1.275 +#endif
1.276 +#if defined REQUIRE_EXTENSIONS
1.277 + required = 1,
1.278 +#else
1.279 + required = 0,
1.280 +#endif
1.281 +};
1.282 +
1.283 +#if !defined REQUIRE_EXTENSIONS
1.284 +public __ext_topmenus_SetNTVOptional()
1.285 +{
1.286 + MarkNativeAsOptional("CreateTopMenu");
1.287 + MarkNativeAsOptional("LoadTopMenuConfig");
1.288 + MarkNativeAsOptional("AddToTopMenu");
1.289 + MarkNativeAsOptional("RemoveFromTopMenu");
1.290 + MarkNativeAsOptional("DisplayTopMenu");
1.291 + MarkNativeAsOptional("FindTopMenuCategory");
1.292 +}
1.293 +#endif