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