plugins/include/topmenus.inc
author Nicholas Hastings <skamonkey@gmail.com>
Wed Jul 06 22:34:21 2011 -0400 (2011-07-06)
changeset 3340 7eb2b72e42d8
parent 2317 a7380514e63c
child 3967 ceafb87d38a7
permissions -rw-r--r--
Added native interface for Basecomm plugin (bug 2594, r=fyren).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     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.
    12  * 
    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
    16  * details.
    17  *
    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/>.
    20  *
    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>.
    29  *
    30  * Version: $Id$
    31  */
    32  
    33 #if defined _topmenus_included
    34  #endinput
    35 #endif
    36 #define _topmenus_included
    37 
    38 #include <menus>
    39 
    40 /**
    41  * Actions a top menu will take on an object.
    42  */
    43 enum TopMenuAction
    44 {
    45 	/**
    46 	 * An option is being drawn for a menu (or for sorting purposes).
    47 	 *
    48 	 * INPUT : TopMenu Handle, object ID, client index.
    49 	 * OUTPUT: Buffer for rendering, maxlength of buffer.
    50 	 */
    51 	TopMenuAction_DisplayOption = 0,
    52 	
    53 	/**
    54 	 * The title of a menu is being drawn for a given object.
    55 	 *
    56 	 * Note: The Object ID will be INVALID_TOPMENUOBJECT if drawing the 
    57 	 * root title.  Otherwise, the Object ID is a category.
    58 	 *
    59 	 * INPUT : TopMenu Handle, object ID, client index.
    60 	 * OUTPUT: Buffer for rendering, maxlength of buffer.
    61 	 */
    62 	TopMenuAction_DisplayTitle = 1,
    63 	
    64 	/**
    65 	 * A menu option has been selected.
    66 	 *
    67 	 * The Object ID will always be an item (not a category).
    68 	 *
    69 	 * INPUT : TopMenu Handle, object ID, client index.
    70 	 */
    71 	TopMenuAction_SelectOption = 2,
    72 
    73 	/**
    74 	 * A menu option is being drawn and its flags can be overridden.
    75 	 *
    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
    79 	 *		   ITEMDRAW_DEFAULT.
    80 	 */
    81 	 TopMenuAction_DrawOption = 3,
    82 	 
    83 	/**
    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.
    86 	 *
    87 	 * INPUT : TopMenu Handle, object ID.
    88 	 */
    89 	 TopMenuAction_RemoveObject = 4,
    90 };
    91 
    92 /**
    93  * Top menu object types.
    94  */
    95 enum TopMenuObjectType
    96 {
    97 	TopMenuObject_Category = 0,			/**< Category (sub-menu branching from root) */
    98 	TopMenuObject_Item = 1				/**< Item on a sub-menu */
    99 };
   100 
   101 /**
   102  * Top menu starting positions for display.
   103  */
   104 enum TopMenuPosition
   105 {
   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 */
   109 };
   110 
   111 /**
   112  * Top menu object tag for type checking.
   113  */
   114 enum TopMenuObject
   115 {
   116 	INVALID_TOPMENUOBJECT = 0,
   117 };
   118 
   119 /**
   120  * TopMenu callback prototype.
   121  *
   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).
   128  * @noreturn
   129  */
   130 functag public TopMenuHandler(Handle:topmenu, 
   131 							  TopMenuAction:action,
   132 							  TopMenuObject:object_id,
   133 							  param,
   134 							  String:buffer[],
   135 							  maxlength);
   136 
   137 /**
   138  * Creates a TopMenu.
   139  *
   140  * @param handler			Handler to use for drawing the root title.
   141  * @return					A new TopMenu Handle, or INVALID_HANDLE on failure.
   142  */						  
   143 native Handle:CreateTopMenu(TopMenuHandler:handler);
   144 
   145 /**
   146  * Re-sorts the items in a TopMenu via a configuration file.
   147  *
   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.
   152  *
   153  * Each sub-section may only contain key/value pairs in the form of:
   154  * key: "item"
   155  * value: Name of the item as passed to AddToTopMenu().
   156  *
   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.
   161  *
   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 
   168  *							returned.
   169  * @return					True on success, false on failure.
   170  * @error					Invalid TopMenu Handle.
   171  */
   172 native bool:LoadTopMenuConfig(Handle:topmenu, const String:file[], String:error[], maxlength);
   173 
   174 /**
   175  * Adds an object to a TopMenu.
   176  *
   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
   188  *							failure.
   189  * @error					Invalid TopMenu Handle.
   190  */
   191 native TopMenuObject:AddToTopMenu(Handle:topmenu,
   192 								  const String:name[],
   193 								  TopMenuObjectType:type,
   194 								  TopMenuHandler:handler,
   195 								  TopMenuObject:parent,
   196 								  const String:cmdname[]="",
   197 								  flags=0,
   198 								  const String:info_string[]="");
   199 								  
   200 /**
   201  * Retrieves the info string of a top menu item.
   202  *
   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 
   208  *							null terminator.
   209  * @error					Invalid TopMenu Handle or TopMenuObject ID.
   210  */
   211 native GetTopMenuInfoString(Handle:topmenu, TopMenuObject:parent, String:buffer[], maxlength);
   212 
   213 /**
   214  * Retrieves the name string of a top menu item.
   215  *
   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 
   221  *							null terminator.
   222  * @error					Invalid TopMenu Handle or TopMenuObject ID.
   223  */
   224 native GetTopMenuObjName(Handle:topmenu, TopMenuObject:object, String:buffer[], maxlength);
   225 
   226 /**
   227  * Removes an object from a TopMenu.
   228  *
   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.
   231  *
   232  * @param topmenu			TopMenu Handle.
   233  * @param object			TopMenuObject ID.
   234  * @noreturn
   235  * @error					Invalid TopMenu Handle.
   236  */
   237 native RemoveFromTopMenu(Handle:topmenu, TopMenuObject:object);
   238 
   239 /**
   240  * Displays a TopMenu to a client.
   241  *
   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.
   247  */
   248 native bool:DisplayTopMenu(Handle:topmenu, client, TopMenuPosition:position);
   249 
   250 /**
   251  * Finds a category's object ID in a TopMenu.
   252  *
   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.
   258  */
   259 native TopMenuObject:FindTopMenuCategory(Handle:topmenu, const String:name[]);
   260 
   261 /**
   262  * Do not edit below this line!
   263  */
   264 public Extension:__ext_topmenus = 
   265 {
   266 	name = "TopMenus",
   267 	file = "topmenus.ext",
   268 #if defined AUTOLOAD_EXTENSIONS
   269 	autoload = 1,
   270 #else
   271 	autoload = 0,
   272 #endif
   273 #if defined REQUIRE_EXTENSIONS
   274 	required = 1,
   275 #else
   276 	required = 0,
   277 #endif
   278 };
   279 
   280 #if !defined REQUIRE_EXTENSIONS
   281 public __ext_topmenus_SetNTVOptional()
   282 {
   283 	MarkNativeAsOptional("CreateTopMenu");
   284 	MarkNativeAsOptional("LoadTopMenuConfig");
   285 	MarkNativeAsOptional("AddToTopMenu");
   286 	MarkNativeAsOptional("RemoveFromTopMenu");
   287 	MarkNativeAsOptional("DisplayTopMenu");
   288 	MarkNativeAsOptional("FindTopMenuCategory");
   289 }
   290 #endif