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