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