plugins/include/topmenus.inc
author Matt Woodrow <pred@alliedmods.net>
Mon Nov 12 21:51:54 2007 +0000 (2007-11-12)
changeset 1676 df6b4e53cca0
parent 1634 241bf59d8f4d
child 1699 4368f4cc417b
child 1715 f9ecab642e25
permissions -rw-r--r--
Fixed amb1154 and another kick bug with sm_reserve_type 1
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2007 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 TopMenuHandler public(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  * Removes an object from a TopMenu.
   215  *
   216  * Plugins' objects are automatically removed all TopMenus when the given 
   217  * plugin unloads or pauses.  In the case of unpausing, all items are restored.
   218  *
   219  * @param topmenu			TopMenu Handle.
   220  * @param object			TopMenuObject ID.
   221  * @noreturn
   222  * @error					Invalid TopMenu Handle.
   223  */
   224 native RemoveFromTopMenu(Handle:topmenu, TopMenuObject:object);
   225 
   226 /**
   227  * Displays a TopMenu to a client.
   228  *
   229  * @param topmenu			TopMenu Handle.
   230  * @param client			Client index.
   231  * @param position			Position to display from.
   232  * @return					True on success, false on failure.
   233  * @error					Invalid TopMenu Handle or client not in game.
   234  */
   235 native bool:DisplayTopMenu(Handle:topmenu, client, TopMenuPosition:position);
   236 
   237 /**
   238  * Finds a category's object ID in a TopMenu.
   239  *
   240  * @param topmenu			TopMenu Handle.
   241  * @param name				Object's unique name.
   242  * @return					TopMenuObject ID on success, or 
   243  *							INVALID_TOPMENUOBJECT on failure.
   244  * @error					Invalid TopMenu Handle.
   245  */
   246 native TopMenuObject:FindTopMenuCategory(Handle:topmenu, const String:name[]);
   247 
   248 /**
   249  * Do not edit below this line!
   250  */
   251 public Extension:__ext_topmenus = 
   252 {
   253 	name = "TopMenus",
   254 	file = "topmenus.ext",
   255 #if defined AUTOLOAD_EXTENSIONS
   256 	autoload = 1,
   257 #else
   258 	autoload = 0,
   259 #endif
   260 #if defined REQUIRE_EXTENSIONS
   261 	required = 1,
   262 #else
   263 	required = 0,
   264 #endif
   265 };
   266 
   267 #if !defined REQUIRE_EXTENSIONS
   268 public __ext_topmenus_SetNTVOptional()
   269 {
   270 	MarkNativeAsOptional("CreateTopMenu");
   271 	MarkNativeAsOptional("LoadTopMenuConfig");
   272 	MarkNativeAsOptional("AddToTopMenu");
   273 	MarkNativeAsOptional("RemoveFromTopMenu");
   274 	MarkNativeAsOptional("DisplayTopMenu");
   275 	MarkNativeAsOptional("FindTopMenuCategory");
   276 }
   277 #endif