plugins/include/topmenus.inc
author David Anderson <dvander@alliedmods.net>
Mon Oct 15 04:06:57 2007 +0000 (2007-10-15)
changeset 1572 adbc41dc9cd0
parent 1526 d7ba44e7a714
child 1634 241bf59d8f4d
permissions -rw-r--r--
fixed an overall deficiency where libraries did not include extensions. extensions can now mark themselves as libraries, and they thus become fully optional just as plugins do. additionally, a bug was fixed where plugins could be accidentally marked as required instead of optional. these changes resulted in a bcompat API bump to the extension/sharesys interface.
     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 /**
    85  * Top menu object types.
    86  */
    87 enum TopMenuObjectType
    88 {
    89 	TopMenuObject_Category = 0,			/**< Category (sub-menu branching from root) */
    90 	TopMenuObject_Item = 1				/**< Item on a sub-menu */
    91 };
    92 
    93 /**
    94  * Top menu starting positions for display.
    95  */
    96 enum TopMenuPosition
    97 {
    98 	TopMenuPosition_Start = 0,			/**< Start/root of the menu */
    99 	TopMenuPosition_LastRoot = 1,		/**< Last position in the root menu */
   100 	TopMenuPosition_LastCategory = 3,	/**< Last position in their last category */
   101 };
   102 
   103 /**
   104  * Top menu object tag for type checking.
   105  */
   106 enum TopMenuObject
   107 {
   108 	INVALID_TOPMENUOBJECT = 0,
   109 }
   110 
   111 /**
   112  * TopMenu callback prototype.
   113  *
   114  * @param topmenu			Handle to the TopMenu.
   115  * @param action			TopMenuAction being performed.
   116  * @param object_id			The object ID (if used).
   117  * @param param				Extra parameter (if used).
   118  * @param buffer			Output buffer (if used).
   119  * @param maxlength			Output buffer (if used).
   120  * @noreturn
   121  */
   122 functag TopMenuHandler public(Handle:topmenu, 
   123 							  TopMenuAction:action,
   124 							  TopMenuObject:object_id,
   125 							  param,
   126 							  String:buffer[],
   127 							  maxlength);
   128 
   129 /**
   130  * Creates a TopMenu.
   131  *
   132  * @param handler			Handler to use for drawing the root title.
   133  * @return					A new TopMenu Handle, or INVALID_HANDLE on failure.
   134  */						  
   135 native Handle:CreateTopMenu(TopMenuHandler:handler);
   136 
   137 /**
   138  * Re-sorts the items in a TopMenu via a configuration file.
   139  *
   140  * The format of the configuration file should be a Valve Key-Values 
   141  * formatted file that SourceMod can parse.  There should be one root 
   142  * section, and one sub-section for each category.  Each sub-section's 
   143  * name should match the category name.
   144  *
   145  * Each sub-section may only contain key/value pairs in the form of:
   146  * key: "item"
   147  * value: Name of the item as passed to AddToTopMenu().
   148  *
   149  * The TopMenu will draw items in the order declared in the configuration 
   150  * file.  If items do not appear in the configuration file, they are sorted 
   151  * per-player based on how the handler function renders for that player.  
   152  * These items appear after the configuration sorted items.
   153  *
   154  * @param topmenu			TopMenu Handle.
   155  * @param file				File path.
   156  * @param error				Error buffer.
   157  * @param maxlength			Maximum size of the error buffer.
   158  *							Error buffer will be filled with a 
   159  *							zero-terminated string if false is 
   160  *							returned.
   161  * @return					True on success, false on failure.
   162  * @error					Invalid TopMenu Handle.
   163  */
   164 native bool:LoadTopMenuConfig(Handle:topmenu, const String:file[], String:error[], maxlength);
   165 
   166 /**
   167  * Adds an object to a TopMenu.
   168  *
   169  * @param topmenu			TopMenu Handle.
   170  * @param name				Object name (MUST be unique).
   171  * @param type				Object type.
   172  * @param handler			Handler for object.
   173  * @param cmdname			Command name (for access overrides).
   174  * @param flags				Default access flags.
   175  * @param parent			Parent object ID, or INVALID_TOPMENUOBJECT for none.
   176  *							Items must have a category parent.
   177  *							Categories must not have a parent.
   178  * @return					A new TopMenuObject ID, or INVALID_TOPMENUOBJECT on
   179  *							failure.
   180  * @error					Invalid TopMenu Handle.
   181  */
   182 native TopMenuObject:AddToTopMenu(Handle:topmenu,
   183 								  const String:name[],
   184 								  TopMenuObjectType:type,
   185 								  TopMenuHandler:handler,
   186 								  TopMenuObject:parent,
   187 								  const String:cmdname[]="",
   188 								  flags=0);
   189 
   190 /**
   191  * Removes an object from a TopMenu.
   192  *
   193  * Plugins' objects are automatically removed all TopMenus when the given 
   194  * plugin unloads or pauses.  In the case of unpausing, all items are restored.
   195  *
   196  * @param topmenu			TopMenu Handle.
   197  * @param object			TopMenuObject ID.
   198  * @noreturn
   199  * @error					Invalid TopMenu Handle.
   200  */
   201 native RemoveFromTopMenu(Handle:topmenu, TopMenuObject:object);
   202 
   203 /**
   204  * Displays a TopMenu to a client.
   205  *
   206  * @param topmenu			TopMenu Handle.
   207  * @param client			Client index.
   208  * @param position			Position to display from.
   209  * @return					True on success, false on failure.
   210  * @error					Invalid TopMenu Handle or client not in game.
   211  */
   212 native bool:DisplayTopMenu(Handle:topmenu, client, TopMenuPosition:position);
   213 
   214 /**
   215  * Finds a category's object ID in a TopMenu.
   216  *
   217  * @param topmenu			TopMenu Handle.
   218  * @param name				Object's unique name.
   219  * @return					TopMenuObject ID on success, or 
   220  *							INVALID_TOPMENUOBJECT on failure.
   221  * @error					Invalid TopMenu Handle.
   222  */
   223 native TopMenuObject:FindTopMenuCategory(Handle:topmenu, const String:name[]);
   224 
   225 /**
   226  * Do not edit below this line!
   227  */
   228 public Extension:__ext_topmenus = 
   229 {
   230 	name = "TopMenus",
   231 	file = "topmenus.ext",
   232 #if defined AUTOLOAD_EXTENSIONS
   233 	autoload = 1,
   234 #else
   235 	autoload = 0,
   236 #endif
   237 #if defined REQUIRE_EXTENSIONS
   238 	required = 1,
   239 #else
   240 	required = 0,
   241 #endif
   242 };
   243 
   244 #if !defined REQUIRE_EXTENSIONS
   245 public __ext_topmenus_SetNTVOptional()
   246 {
   247 	MarkNativeAsOptional("CreateTopMenu");
   248 	MarkNativeAsOptional("LoadTopMenuConfig");
   249 	MarkNativeAsOptional("AddToTopMenu");
   250 	MarkNativeAsOptional("RemoveFromTopMenu");
   251 	MarkNativeAsOptional("DisplayTopMenu");
   252 	MarkNativeAsOptional("FindTopMenuCategory");
   253 }
   254 #endif