plugins/include/menus.inc
author David Anderson <dvander@alliedmods.net>
Sat May 30 19:59:55 2009 -0400 (2009-05-30)
changeset 2737 eb7713d87fa1
parent 2317 a7380514e63c
child 2920 1d5645ab7ae0
permissions -rw-r--r--
Fixed revote bug and inflexibilities in RedrawClientVoteMenu (bug 3834, 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 _menus_included
    34  #endinput
    35 #endif
    36 #define _menus_included
    37 
    38 /**
    39  * Low-level drawing style of the menu.
    40  */
    41 enum MenuStyle
    42 {
    43 	MenuStyle_Default = 0,		/**< The "default" menu style for the mod */
    44 	MenuStyle_Valve = 1,		/**< The Valve provided menu style (Used on HL2DM) */
    45 	MenuStyle_Radio = 2,		/**< The simpler menu style commonly used on CS:S */
    46 };
    47 
    48 /**
    49  * Different actions for the menu "pump" callback
    50  */
    51 enum MenuAction
    52 {
    53 	MenuAction_Start = (1<<0),		/**< A menu has been started (nothing passed) */
    54 	MenuAction_Display = (1<<1),	/**< A menu is about to be displayed (param1=client, param2=MenuPanel Handle) */
    55 	MenuAction_Select = (1<<2),		/**< An item was selected (param1=client, param2=item) */
    56 	MenuAction_Cancel = (1<<3),		/**< The menu was cancelled (param1=client, param2=reason) */
    57 	MenuAction_End = (1<<4),		/**< A menu display has fully ended.
    58 										 param1 is the MenuEnd reason, and if it's MenuEnd_Cancelled, then 
    59 										 param2 is the MenuCancel reason from MenuAction_Cancel.
    60 										 */
    61 	MenuAction_VoteEnd = (1<<5),	/**< (VOTE ONLY): A vote sequence has succeeded (param1=chosen item) 
    62 										 This is not called if SetVoteResultCallback has been used on the menu. */
    63 	MenuAction_VoteStart = (1<<6), 	/**< (VOTE ONLY): A vote sequence has started (nothing passed) */
    64 	MenuAction_VoteCancel = (1<<7),	/**< (VOTE ONLY): A vote sequence has been cancelled (param1=reason) */
    65 	MenuAction_DrawItem = (1<<8),	/**< An item is being drawn; return the new style (param1=client, param2=item) */
    66 	MenuAction_DisplayItem = (1<<9),/**< Item text is being drawn to the display (param1=client, param2=item)
    67 										  To change the text, use RedrawMenuItem().
    68 										  If you do so, return its return value.  Otherwise, return 0.
    69 										  */
    70 };
    71 
    72 /** Default menu actions */
    73 #define MENU_ACTIONS_DEFAULT	MenuAction_Select|MenuAction_Cancel|MenuAction_End
    74 /** All menu actions */
    75 #define MENU_ACTIONS_ALL		MenuAction:0xFFFFFFFF
    76 
    77 #define MENU_NO_PAGINATION		0		/**< Menu should not be paginated (10 items max) */
    78 #define MENU_TIME_FOREVER		0		/**< Menu should be displayed as long as possible */
    79 
    80 #define ITEMDRAW_DEFAULT		(0)		/**< Item should be drawn normally */
    81 #define ITEMDRAW_DISABLED		(1<<0)	/**< Item is drawn but not selectable */
    82 #define ITEMDRAW_RAWLINE		(1<<1)	/**< Item should be a raw line, without a slot */
    83 #define ITEMDRAW_NOTEXT			(1<<2)	/**< No text should be drawn */
    84 #define ITEMDRAW_SPACER			(1<<3)	/**< Item should be drawn as a spacer, if possible */
    85 #define ITEMDRAW_IGNORE	((1<<1)|(1<<2))	/**< Item should be completely ignored (rawline + notext) */
    86 #define ITEMDRAW_CONTROL		(1<<4)	/**< Item is control text (back/next/exit) */
    87 
    88 #define MENUFLAG_BUTTON_EXIT		(1<<0)	/**< Menu has an "exit" button (default if paginated) */
    89 #define MENUFLAG_BUTTON_EXITBACK	(1<<1)	/**< Menu has an "exit back" button */
    90 #define MENUFLAG_NO_SOUND			(1<<2)	/**< Menu will not have any select sounds */
    91 
    92 #define VOTEINFO_CLIENT_INDEX		0		/**< Client index */
    93 #define VOTEINFO_CLIENT_ITEM		1		/**< Item the client selected, or -1 for none */
    94 #define VOTEINFO_ITEM_INDEX			0		/**< Item index */
    95 #define VOTEINFO_ITEM_VOTES			1		/**< Number of votes for the item */
    96 
    97 #define VOTEFLAG_NO_REVOTES			(1<<0)	/**< Players cannot change their votes */
    98 
    99 /**
   100  * Reasons a menu can be cancelled (MenuAction_Cancel).
   101  */
   102 enum
   103 {
   104 	MenuCancel_Disconnected = -1,	/**< Client dropped from the server */
   105 	MenuCancel_Interrupted = -2,	/**< Client was interrupted with another menu */
   106 	MenuCancel_Exit = -3,			/**< Client exited via "exit" */
   107 	MenuCancel_NoDisplay = -4,		/**< Menu could not be displayed to the client */
   108 	MenuCancel_Timeout = -5,		/**< Menu timed out */
   109 	MenuCancel_ExitBack = -6,		/**< Client selected "exit back" on a paginated menu */
   110 };
   111 
   112 /**
   113  * Reasons a vote can be cancelled (MenuAction_VoteCancel).
   114  */
   115 enum
   116 {
   117 	VoteCancel_Generic = -1,		/**< Vote was generically cancelled. */
   118 	VoteCancel_NoVotes = -2,		/**< Vote did not receive any votes. */
   119 };
   120 
   121 /**
   122  * Reasons a menu ended (MenuAction_End).
   123  */
   124 enum
   125 {
   126 	MenuEnd_Selected = 0,			/**< Menu item was selected */
   127 	MenuEnd_VotingDone = -1,		/**< Voting finished */
   128 	MenuEnd_VotingCancelled = -2,	/**< Voting was cancelled */
   129 	MenuEnd_Cancelled = -3,			/**< Menu was cancelled (reason in param2) */
   130 	MenuEnd_Exit = -4,				/**< Menu was cleanly exited via "exit" */
   131 	MenuEnd_ExitBack = -5,			/**< Menu was cleanly exited via "back" */
   132 };
   133 
   134 /**
   135  * Describes a menu's source
   136  */
   137 enum MenuSource
   138 {
   139 	MenuSource_None = 0,			/**< No menu is being displayed */	
   140 	MenuSource_External = 1,		/**< External menu */
   141 	MenuSource_Normal = 2,			/**< A basic menu is being displayed */
   142 	MenuSource_RawPanel = 3,		/**< A display is active, but it is not tied to a menu */
   143 };
   144 
   145 /**
   146  * Called when a menu action is completed.
   147  *
   148  * @param menu				The menu being acted upon.
   149  * @param action			The action of the menu.
   150  * @param param1			First action parameter (usually the client).
   151  * @param param2			Second action parameter (usually the item).
   152  * @noreturn
   153  */
   154 functag public MenuHandler(Handle:menu, MenuAction:action, param1, param2);
   155 
   156 /**
   157  * Creates a new, empty menu using the default style.
   158  * 
   159  * @param handler			Function which will receive menu actions.
   160  * @param actions			Optionally set which actions to receive.  Select, 
   161  *							Cancel, and End will always be received regardless
   162  *							of whether they are set or not.  They are also
   163  *							the only default actions.
   164  * @return					A new menu Handle.
   165  */
   166 native Handle:CreateMenu(MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
   167 
   168 /**
   169  * Displays a menu to a client.
   170  *
   171  * @param menu				Menu Handle.
   172  * @param client			Client index.
   173  * @param time				Maximum time to leave menu on the screen.
   174  * @return					True on success, false on failure.
   175  * @error					Invalid Handle or client not in game.
   176  */
   177 native bool:DisplayMenu(Handle:menu, client, time);
   178 
   179 /**
   180  * Displays a menu to a client, starting from the given item.
   181  *
   182  * @param menu				Menu Handle.
   183  * @param client			Client index.
   184  * @param first_item		First item to begin drawing from.
   185  * @param time				Maximum time to leave menu on the screen.
   186  * @return					True on success, false on failure.
   187  * @error					Invalid Handle or client not in game.
   188  */
   189 native bool:DisplayMenuAtItem(Handle:menu, client, first_item, time);
   190 
   191 /**
   192  * Appends a new item to the end of a menu.
   193  *
   194  * @param menu				Menu Handle.
   195  * @param info				Item information string.
   196  * @param display			Default item display string.
   197  * @param style				Drawing style flags.  Anything other than DEFAULT or 
   198  *							DISABLED will be completely ignored when paginating.
   199  * @return					True on success, false on failure.
   200  * @error					Invalid Handle or item limit reached.
   201  */
   202 native AddMenuItem(Handle:menu, 
   203 					const String:info[], 
   204 					const String:display[], 
   205 					style=ITEMDRAW_DEFAULT);
   206 
   207 /**
   208  * Inserts an item into the menu before a certain position; the new item will
   209  * be at the given position and all next items pushed forward.
   210  *
   211  * @param menu				Menu Handle.
   212  * @param position			Position, starting from 0.
   213  * @param info				Item information string.
   214  * @param display			Default item display string.
   215  * @param style				Drawing style flags.  Anything other than DEFAULT or 
   216  *							DISABLED will be completely ignored when paginating.
   217  * @return					True on success, false on failure.
   218  * @error					Invalid Handle or menu position.
   219  */
   220 native bool:InsertMenuItem(Handle:menu,
   221 						position, 
   222 						const String:info[], 
   223 						const String:display[], 
   224 						style=ITEMDRAW_DEFAULT);
   225 
   226 /**
   227  * Removes an item from the menu.
   228  *
   229  * @param menu				Menu Handle.
   230  * @param position			Position, starting from 0.
   231  * @return					True on success, false on failure.
   232  * @error					Invalid Handle or menu position.
   233  */
   234 native bool:RemoveMenuItem(Handle:menu, position);
   235 
   236 /**
   237  * Removes all items from a menu.
   238  *
   239  * @param menu				Menu Handle.
   240  * @noreturn
   241  * @error					Invalid Handle or menu position.
   242  */
   243 native RemoveAllMenuItems(Handle:menu);
   244 
   245 /**
   246  * Retrieves information about a menu item.
   247  *
   248  * @param menu				Menu Handle.
   249  * @param position			Position, starting from 0.
   250  * @param infoBuf			Info buffer.
   251  * @param infoBufLen		Maximum length of the info buffer.
   252  * @param style				By-reference variable to store drawing flags.
   253  * @param dispBuf			Display buffer.
   254  * @param dispBufLen		Maximum length of the display buffer.
   255  * @return					True on success, false if position is invalid.
   256  * @error					Invalid Handle.
   257  */
   258 native bool:GetMenuItem(Handle:menu, 
   259 						position, 
   260 						String:infoBuf[], 
   261 						infoBufLen, 
   262 						&style=0, 
   263 						String:dispBuf[]="",
   264 						dispBufLen=0);
   265 						
   266 /**
   267  * Returns the first item on the page of a currently selected menu.
   268  *
   269  * This is only valid inside a MenuAction_Select callback.
   270  *
   271  * @return					First item number on the page the client was viewing 
   272  *							before selecting the item in the callback.  This can 
   273  *							be used to re-display the menu from the original 
   274  *							position.
   275  * @error					Not called from inside a MenuAction_Select callback.
   276  */
   277 native GetMenuSelectionPosition();
   278 
   279 /**
   280  * Returns the number of items in a menu.
   281  *
   282  * @param menu				Menu Handle.
   283  * @return					Number of items in the menu.
   284  * @error					Invalid Handle.
   285  */
   286 native GetMenuItemCount(Handle:menu);
   287 
   288 /**
   289  * Sets whether the menu should be paginated or not.
   290  *
   291  * If itemsPerPage is MENU_NO_PAGINATION, and the exit button flag is set, 
   292  * then the exit button flag is removed.  It can be re-applied if desired.
   293  *
   294  * @param menu				Handle to the menu.
   295  * @param itemsPerPage		Number of items per page, or MENU_NO_PAGINATION.
   296  * @return					True on success, false if pagination is too high or 
   297  *							low.
   298  * @error					Invalid Handle.
   299  */
   300 native bool:SetMenuPagination(Handle:menu, itemsPerPage);
   301 
   302 /**
   303  * Returns a menu's pagination setting.
   304  *
   305  * @param menu				Handle to the menu.
   306  * @return					Pagination setting.
   307  * @error					Invalid Handle.
   308  */
   309 native GetMenuPagination(Handle:menu);
   310 
   311 /**
   312  * Returns a menu's MenuStyle Handle.  The Handle
   313  * is global and cannot be freed.
   314  *
   315  * @param menu				Handle to the menu.
   316  * @return 					Handle to the menu's draw style.
   317  * @error					Invalid Handle.
   318  */
   319 native Handle:GetMenuStyle(Handle:menu);
   320 
   321 /**
   322  * Sets the menu's default title/instruction message.
   323  *
   324  * @param menu				Menu Handle.
   325  * @param fmt				Message string format
   326  * @param ...				Message string arguments.
   327  * @noreturn
   328  * @error					Invalid Handle.
   329  */
   330 native SetMenuTitle(Handle:menu, const String:fmt[], any:...);
   331 
   332 /**
   333  * Returns the text of a menu's title.
   334  *
   335  * @param menu				Menu Handle.
   336  * @param buffer			Buffer to store title.
   337  * @param maxlength			Maximum length of the buffer.
   338  * @return					Number of bytes written.
   339  * @error					Invalid Handle/
   340  */
   341 native GetMenuTitle(Handle:menu, String:buffer[], maxlength);
   342 
   343 /**
   344  * Creates a raw MenuPanel based off the menu's style.
   345  * The Handle must be freed with CloseHandle().
   346  *
   347  * @return					A new MenuPanel Handle.
   348  * @error					Invalid Handle.
   349  */
   350 native Handle:CreatePanelFromMenu(Handle:menu);
   351 
   352 /**
   353  * Returns whether or not the menu has an exit button.
   354  * By default, menus have an exit button.
   355  *
   356  * @param menu				Menu Handle.
   357  * @return 					True if the menu has an exit button; false otherwise.
   358  * @error					Invalid Handle.
   359  */
   360 native bool:GetMenuExitButton(Handle:menu);
   361 
   362 /**
   363  * Sets whether or not the menu has an exit button.  By default, paginated menus 
   364  * have an exit button.
   365  *
   366  * If a menu's pagination is changed to MENU_NO_PAGINATION, and the pagination 
   367  * was previously a different value, then the Exit button status is changed to 
   368  * false.  It must be explicitly re-enabled afterwards.
   369  *
   370  * If a non-paginated menu has an exit button, then at most 9 items will be 
   371  * displayed.
   372  *
   373  * @param menu				Menu Handle.
   374  * @param button			True to enable the button, false to remove it.
   375  * @return 					True if allowed; false on failure.
   376  * @error					Invalid Handle.
   377  */
   378 native bool:SetMenuExitButton(Handle:menu, bool:button);
   379 
   380 /**
   381  * Returns whether or not the menu has an "exit back" button.  By default, 
   382  * menus do not have an exit back button.  
   383  *
   384  * Exit Back buttons appear as "Back" on page 1 of paginated menus and have 
   385  * functionality defined by the user in MenuEnd_ExitBack.
   386  *
   387  * @param menu				Menu Handle.
   388  * @return 					True if the menu has an exit back button; false otherwise.
   389  * @error					Invalid Handle.
   390  */
   391 native bool:GetMenuExitBackButton(Handle:menu);
   392 
   393 /**
   394  * Sets whether or not the menu has an "exit back" button. By default, menus 
   395  * do not have an exit back button.
   396  *
   397  * Exit Back buttons appear as "Back" on page 1 of paginated menus and have 
   398  * functionality defined by the user in MenuEnd_ExitBack.
   399  *
   400  * @param menu				Menu Handle.
   401  * @param button			True to enable the button, false to remove it.
   402  * @error					Invalid Handle.
   403  */
   404 native SetMenuExitBackButton(Handle:menu, bool:button);
   405 
   406 
   407 /**
   408  * Cancels a menu from displaying on all clients.  While the
   409  * cancellation is in progress, this menu cannot be re-displayed
   410  * to any clients.
   411  *
   412  * The menu may still exist on the client's screen after this command.
   413  * This simply verifies that the menu is not being used anywhere.
   414  *
   415  * If any vote is in progress on a menu, it will be cancelled.
   416  *
   417  * @param menu				Menu Handle.
   418  * @noreturn
   419  * @error					Invalid Handle.
   420  */
   421 native CancelMenu(Handle:menu);
   422 
   423 /**
   424  * Retrieves a menu's option flags.
   425  *
   426  * @param menu				Menu Handle.
   427  * @return					A bitstring of MENUFLAG bits.
   428  * @error					Invalid Handle.
   429  */
   430 native GetMenuOptionFlags(Handle:menu);
   431 
   432 /**
   433  * Sets a menu's option flags.
   434  *
   435  * If a certain bit is not supported, it will be stripped before being set.
   436  * See SetMenuExitButton() for information on Exit buttons.
   437  * See SetMenuExitBackButton() for information on Exit Back buttons.
   438  *
   439  * @param menu				Menu Handle.
   440  * @param flags				A new bitstring of MENUFLAG bits.
   441  * @noreturn
   442  * @error					Invalid Handle.
   443  */
   444 native SetMenuOptionFlags(Handle:menu, flags);
   445 
   446 /**
   447  * Returns whether a vote is in progress.
   448  *
   449  * @param menu				Deprecated; no longer used.
   450  * @return					True if a vote is in progress, false otherwise.
   451  */
   452 native bool:IsVoteInProgress(Handle:menu=INVALID_HANDLE);
   453 
   454 /**
   455  * Cancels the vote in progress.
   456  *
   457  * @noreturn
   458  * @error					If no vote is in progress.
   459  */
   460 native CancelVote();
   461 
   462 /**
   463  * Broadcasts a menu to a list of clients.  The most selected item will be 
   464  * returned through MenuAction_End.  On a tie, a random item will be returned 
   465  * from a list of the tied items.
   466  *
   467  * Note that MenuAction_VoteEnd and MenuAction_VoteStart are both
   468  * default callbacks and do not need to be enabled.
   469  *
   470  * @param menu				Menu Handle.
   471  * @param clients			Array of clients to broadcast to.
   472  * @param numClients		Number of clients in the array.
   473  * @param time				Maximum time to leave menu on the screen.
   474  * @param flags				Optional voting flags.
   475  * @return					True on success, false if this menu already has a vote session
   476  *							in progress.
   477  * @error					Invalid Handle, or a vote is already in progress.
   478  */
   479 native bool:VoteMenu(Handle:menu, clients[], numClients, time, flags=0);
   480 
   481 /**
   482  * Sends a vote menu to all clients.  See VoteMenu() for more information.
   483  *
   484  * @param menu				Menu Handle.
   485  * @param time				Maximum time to leave menu on the screen.
   486  * @param flags				Optional voting flags.
   487  * @return					True on success, false if this menu already has a vote session
   488  *							in progress.
   489  * @error					Invalid Handle.
   490  */
   491 stock VoteMenuToAll(Handle:menu, time, flags=0)
   492 {
   493 	new num = GetMaxClients();
   494 	new total;
   495 	decl players[num];
   496 	
   497 	for (new i=1; i<=num; i++)
   498 	{
   499 		if (!IsClientInGame(i))
   500 		{
   501 			continue;
   502 		}
   503 		players[total++] = i;
   504 	}
   505 	
   506 	return VoteMenu(menu, players, total, time, flags);
   507 }
   508 /**
   509  * Callback for when a vote has ended and results are available.
   510  *
   511  * @param menu				The menu being voted on.
   512  * @param num_votes			Number of votes tallied in total.
   513  * @param num_clients		Number of clients who could vote.
   514  * @param client_info		Array of clients.  Use VOTEINFO_CLIENT_ defines.
   515  * @param num_items			Number of unique items that were selected.
   516  * @param item_info			Array of items, sorted by count.  Use VOTEINFO_ITEM
   517  *							defines.
   518  * @noreturn
   519  */
   520 functag public VoteHandler(Handle:menu,
   521 						   num_votes, 
   522 						   num_clients,
   523 						   const client_info[][2], 
   524 						   num_items,
   525 						   const item_info[][2]);	   
   526 
   527 /**
   528  * Sets an advanced vote handling callback.  If this callback is set,
   529  * MenuAction_VoteEnd will not be called.
   530  *
   531  * @param menu				Menu Handle.
   532  * @param callback			Callback function.
   533  * @noreturn
   534  * @error					Invalid Handle or callback.
   535  */
   536 native SetVoteResultCallback(Handle:menu, VoteHandler:callback);
   537 
   538 /**
   539  * Returns the number of seconds you should "wait" before displaying
   540  * a publicly invocable menu.  This number is the time remaining until
   541  * (last_vote + sm_vote_delay).
   542  *
   543  * @return					Number of seconds to wait, or 0 for none.
   544  */
   545 native CheckVoteDelay();
   546 
   547 /**
   548  * Returns whether a client is in the pool of clients allowed 
   549  * to participate in the current vote.  This is determined by 
   550  * the client list passed to VoteMenu().
   551  *
   552  * @param client			Client index.
   553  * @return					True if client is allowed to vote, false otherwise.
   554  * @error					If no vote is in progress or client index is invalid.
   555  */
   556 native bool:IsClientInVotePool(client);
   557 
   558 /**
   559  * Redraws the current vote menu to a client in the voting pool.
   560  *
   561  * @param client			Client index.
   562  * @param revotes			True to allow revotes, false otherwise.
   563  * @return					True on success, false if the client is in the vote pool 
   564  *							but cannot vote again.
   565  * @error					No vote in progress, client is not in the voting pool, 
   566  *							or client index is invalid.
   567  */
   568 native bool:RedrawClientVoteMenu(client, bool:revotes=true);
   569 
   570 /**
   571  * Returns a style's global Handle.
   572  *
   573  * @param style			Menu Style.
   574  * @return				A Handle, or INVALID_HANDLE if not found or unusable.
   575  */
   576 native Handle:GetMenuStyleHandle(MenuStyle:style);
   577 
   578 /**
   579  * Creates a MenuPanel from a MenuStyle.  Panels are used for drawing raw 
   580  * menus without any extra helper functions.  The Handle must be closed
   581  * with CloseHandle().
   582  *
   583  * @param hStyle		MenuStyle Handle, or INVALID_HANDLE to use the default style.
   584  * @return				A new MenuPanel Handle.
   585  * @error				Invalid Handle other than INVALID_HANDLE.
   586  */
   587 native Handle:CreatePanel(Handle:hStyle=INVALID_HANDLE);
   588 
   589 /** 
   590  * Creates a Menu from a MenuStyle.  The Handle must be closed with 
   591  * CloseHandle().
   592  *
   593  * @parma hStyle		MenuStyle Handle, or INVALID_HANDLE to use the default style.
   594  * @param handler		Function which will receive menu actions.
   595  * @param actions		Optionally set which actions to receive.  Select, 
   596  *						Cancel, and End will always be received regardless
   597  *						of whether they are set or not.  They are also
   598  *						the only default actions.
   599  * @return				A new menu Handle.
   600  * @error				Invalid Handle other than INVALID_HANDLE.
   601  */
   602 native Handle:CreateMenuEx(Handle:hStyle=INVALID_HANDLE, MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
   603 
   604 /**
   605  * Returns whether a client is viewing a menu.
   606  *
   607  * @param client		Client index.
   608  * @param hStyle		MenuStyle Handle, or INVALID_HANDLE to use the default style.
   609  * @return				A MenuSource value.
   610  * @error				Invalid Handle other than INVALID_HANDLE.
   611  */
   612 native MenuSource:GetClientMenu(client, Handle:hStyle=INVALID_HANDLE);
   613 
   614 /** 
   615  * Cancels a menu on a client.  This will only affect non-external menus.
   616  *
   617  * @param hstyle		MenuStyle Handle, or INVALID_HANDLE to use the default style.
   618  * @param client		Client index.
   619  * @param autoIgnore	If true, no menus can be re-drawn on the client during
   620  *						the cancellation process.
   621  * @return				True if a menu was cancelled, false otherwise.
   622  */
   623 native bool:CancelClientMenu(client, bool:autoIgnore=false, Handle:hStyle=INVALID_HANDLE);
   624 
   625 /**
   626  * Returns a style's maximum items per page.
   627  *
   628  * @param hStyle		MenuStyle Handle, or INVALID_HANDLE to use the default style.
   629  * @return				Maximum items per page.
   630  * @error				Invalid Handle other than INVALID_HANDLE.
   631  */
   632 native GetMaxPageItems(Handle:hStyle=INVALID_HANDLE);
   633 
   634 /**
   635  * Returns a MenuPanel's parent style.
   636  *
   637  * @param panel			A MenuPanel Handle.
   638  * @return				The MenuStyle Handle that created the panel.
   639  * @error				Invalid Handle.
   640  */
   641 native Handle:GetPanelStyle(Handle:panel);
   642 
   643 /**
   644  * Sets the panel's title.
   645  *
   646  * @param panel			A MenuPanel Handle.
   647  * @param title			Text to set as the title.
   648  * @param onlyIfEmpty	If true, the title will only be set if no title is set.
   649  * @noreturn
   650  * @error				Invalid Handle.
   651  */
   652 native Handle:SetPanelTitle(Handle:panel, const String:text[], bool:onlyIfEmpty=false);
   653 
   654 /**
   655  * Draws an item on a panel.  If the item takes up a slot, the position
   656  * is returned.
   657  *
   658  * @param panel			A MenuPanel Handle.
   659  * @param text			Display text to use.  If not a raw line, 
   660  *						the style may automatically add color markup.
   661  *						No numbering or newlines are needed.
   662  * @param style			ITEMDRAW style flags.
   663  * @return				A slot position, or 0 if item was a rawline or could not be drawn.
   664  * @error				Invalid Handle.
   665  */
   666 native DrawPanelItem(Handle:panel, const String:text[], style=ITEMDRAW_DEFAULT);
   667 
   668 /**
   669  * Draws a raw line of text on a panel, without any markup other than a newline.
   670  *
   671  * @param panel			A MenuPanel Handle, or INVALID_HANDLE if inside a 
   672  *						MenuAction_DisplayItem callback.
   673  * @param text			Display text to use.
   674  * @return				True on success, false if raw lines are not supported.
   675  * @error				Invalid Handle.
   676  */
   677 native DrawPanelText(Handle:panel, const String:text[]);
   678 
   679 /**
   680  * Returns whether or not the given drawing flags are supported by
   681  * the menu style.
   682  *
   683  * @param panel			A MenuPanel Handle.
   684  * @param style			ITEMDRAW style flags.
   685  * @return				True if item is drawable, false otherwise.
   686  * @error				Invalid Handle.
   687  */
   688 native CanPanelDrawFlags(Handle:panel, style);
   689 
   690 /**
   691  * Sets the selectable key map of a panel.  This is not supported by
   692  * all styles (only by Radio, as of this writing).  
   693  *
   694  * @param keys			An integer where each bit N allows key
   695  *						N+1 to be selected.  If no keys are selectable,
   696  *						then key 0 (bit 9) is automatically set.
   697  * @return 				True if supported, false otherwise.
   698  */
   699 native bool:SetPanelKeys(Handle:panel, keys);
   700 
   701 /**
   702  * Sends a panel to a client.  Unlike full menus, the handler
   703  * function will only receive the following actions, both of 
   704  * which will have INVALID_HANDLE for a menu, and the client
   705  * as param1.
   706  *
   707  * MenuAction_Select (param2 will be the key pressed)
   708  * MenuAction_Cancel (param2 will be the reason)
   709  *
   710  * Also, if the menu fails to display, no callbacks will be called.
   711  *
   712  * @param panel			A MenuPanel Handle.
   713  * @param client		A client to draw to.
   714  * @param handler		The MenuHandler function to catch actions with.
   715  * @param time			Time to hold the menu for.
   716  * @return				True on success, false on failure.
   717  * @error				Invalid Handle.
   718  */
   719 native bool:SendPanelToClient(Handle:panel, client, MenuHandler:handler, time);
   720 
   721 /**
   722  * @brief Returns the amount of text the menu can still hold.  If this is 
   723  * limit is reached or overflowed, the text is silently truncated.  
   724  *
   725  * Radio menus: Currently 511 characters (512 bytes).
   726  * Valve menus: Currently -1 (no meaning).
   727  *
   728  * @param panel			A MenuPanel Handle.
   729  * @return				Number of characters that the menu can still hold, 
   730  *						or -1 if there is no known limit.
   731  * @error				Invalid Handle.
   732  */
   733 native GetPanelTextRemaining(Handle:panel);
   734 
   735 /**
   736  * @brief Returns the current key position.
   737  *
   738  * @param panel			A MenuPanel Handle.
   739  * @return				Current key position starting at 1.
   740  * @error				Invalid Handle.
   741  */
   742 native GetPanelCurrentKey(Handle:panel);
   743 
   744 /**
   745  * @brief Sets the next key position.  This cannot be used
   746  * to traverse backwards.
   747  *
   748  * @param panel			A MenuPanel Handle.
   749  * @param key			Key that is greater or equal to
   750  *						GetPanelCurrentKey().
   751  * @return				True on success, false otherwise.
   752  * @error				Invalid Handle.
   753  */
   754 native bool:SetPanelCurrentKey(Handle:panel, key);
   755 
   756 /**
   757  * @brief Redraws menu text from inside a MenuAction_DisplayItem callback.
   758  * 
   759  * @param text			Menu text to draw.
   760  * @return				Item position; must be returned via the callback.
   761  */
   762 native RedrawMenuItem(const String:text[]);
   763 
   764 /**
   765  * This function is provided for legacy code only.  Some older plugins may use 
   766  * network messages instead of the panel API.  This function wraps the panel 
   767  * API for eased portability into the SourceMod menu system.  
   768  *
   769  * This function is only usable with the Radio Menu style.  You do not need to 
   770  * split up your menu into multiple packets; SourceMod will break the string 
   771  * up internally.
   772  *
   773  * @param client		Client index.
   774  * @param str			Full menu string as would be passed over the network. 
   775  * @param time			Time to hold the menu for.
   776  * @param keys			Selectable key bitstring.
   777  * @param handler		Optional handler function, with the same rules as
   778  *						SendPanelToClient().
   779  * @return				True on success, false on failure.
   780  * @error				Invalid client index, or radio menus not supported.
   781  */
   782 native bool:InternalShowMenu(client, const String:str[], time, keys=-1, MenuHandler:handler=MenuHandler:-1);
   783 
   784 /**
   785  * Retrieves voting information from MenuAction_VoteEnd.
   786  *
   787  * @param param2		Second parameter of MenuAction_VoteEnd.
   788  * @param winningVotes	Number of votes received by the winning option.
   789  * @param totalVotes	Number of total votes received.
   790  * @noreturn
   791  */
   792 stock GetMenuVoteInfo(param2, &winningVotes, &totalVotes)
   793 {
   794 	winningVotes = param2 & 0xFFFF;
   795 	totalVotes = param2 >> 16;
   796 }
   797 
   798 /**
   799  * Quick stock to determine whether voting is allowed.  This doesn't let you 
   800  * fine-tune a reason for not voting, so it's not recommended for lazily 
   801  * telling clients that voting isn't allowed.
   802  * 
   803  * @return				True if voting is allowed, false if voting is in progress
   804  *						or the cooldown is active.
   805  */
   806 stock bool:IsNewVoteAllowed()
   807 {
   808 	if (IsVoteInProgress() || CheckVoteDelay() != 0)
   809 	{
   810 		return false;
   811 	}
   812 	
   813 	return true;
   814 }
   815