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