3 * =============================================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
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.
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
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/>.
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>.
33 #if defined _menus_included
36 #define _menus_included
39 * Low-level drawing style of the menu.
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 */
49 * Different actions for the menu "pump" callback
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 (param1=reason, param2=cancel reason) */
58 MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has succeeded (param1=chosen item)
59 This is not called if SetVoteResultCallback has been used on the menu. */
60 MenuAction_VoteStart = (1<<6), /**< (VOTE ONLY): A vote sequence has started (nothing passed) */
61 MenuAction_VoteCancel = (1<<7), /**< (VOTE ONLY): A vote sequence has been cancelled (param1=reason) */
62 MenuAction_DrawItem = (1<<8), /**< An item is being drawn; return the new style (param1=client, param2=item) */
63 MenuAction_DisplayItem = (1<<9) /**< Item text is being drawn to the display (param1=client, param2=item)
64 To change the text, use RedrawMenuItem().
65 If you do so, return its return value. Otherwise, return 0.
69 /** Default menu actions */
70 #define MENU_ACTIONS_DEFAULT MenuAction_Select|MenuAction_Cancel|MenuAction_End
71 /** All menu actions */
72 #define MENU_ACTIONS_ALL MenuAction:0xFFFFFFFF
74 #define MENU_NO_PAGINATION 0 /**< Menu should not be paginated (10 items max) */
75 #define MENU_TIME_FOREVER 0 /**< Menu should be displayed as long as possible */
77 #define ITEMDRAW_DEFAULT (0) /**< Item should be drawn normally */
78 #define ITEMDRAW_DISABLED (1<<0) /**< Item is drawn but not selectable */
79 #define ITEMDRAW_RAWLINE (1<<1) /**< Item should be a raw line, without a slot */
80 #define ITEMDRAW_NOTEXT (1<<2) /**< No text should be drawn */
81 #define ITEMDRAW_SPACER (1<<3) /**< Item should be drawn as a spacer, if possible */
82 #define ITEMDRAW_IGNORE ((1<<1)|(1<<2)) /**< Item should be completely ignored (rawline + notext) */
83 #define ITEMDRAW_CONTROL (1<<4) /**< Item is control text (back/next/exit) */
85 #define MENUFLAG_BUTTON_EXIT (1<<0) /**< Menu has an "exit" button */
86 #define MENUFLAG_BUTTON_EXITBACK (1<<1) /**< Menu has an "exit back" button */
87 #define MENUFLAG_NO_SOUND (1<<2) /**< Menu will not have any select sounds */
89 #define VOTEINFO_CLIENT_INDEX 0 /**< Client index */
90 #define VOTEINFO_CLIENT_ITEM 1 /**< Item the client selected, or -1 for none */
91 #define VOTEINFO_ITEM_INDEX 0 /**< Item index */
92 #define VOTEINFO_ITEM_VOTES 1 /**< Number of votes for the item */
95 * Reasons a menu can be cancelled (MenuAction_Cancel).
99 MenuCancel_Disconnected = -1, /**< Client dropped from the server */
100 MenuCancel_Interrupted = -2, /**< Client was interrupted with another menu */
101 MenuCancel_Exit = -3, /**< Client exited via "exit" */
102 MenuCancel_NoDisplay = -4, /**< Menu could not be displayed to the client */
103 MenuCancel_Timeout = -5, /**< Menu timed out */
104 MenuCancel_ExitBack = -6, /**< Client selected "exit back" on a paginated menu */
108 * Reasons a vote can be cancelled (MenuAction_VoteCancel).
112 VoteCancel_Generic = -1, /**< Vote was generically cancelled. */
113 VoteCancel_NoVotes = -2, /**< Vote did not receive any votes. */
117 * Reasons a menu ended (MenuAction_End).
121 MenuEnd_Selected = 0, /**< Menu item was selected */
122 MenuEnd_VotingDone = -1, /**< Voting finished */
123 MenuEnd_VotingCancelled = -2, /**< Voting was cancelled */
124 MenuEnd_Cancelled = -3, /**< Menu was cancelled (reason in param2) */
125 MenuEnd_Exit = -4, /**< Menu was cleanly exited via "exit" */
126 MenuEnd_ExitBack = -5, /**< Menu was cleanly exited via "back" */
130 * Describes a menu's source
134 MenuSource_None = 0, /**< No menu is being displayed */
135 MenuSource_External = 1, /**< External menu */
136 MenuSource_Normal = 2, /**< A basic menu is being displayed */
137 MenuSource_RawPanel = 3, /**< A display is active, but it is not tied to a menu */
141 * Called when a menu action is completed.
143 * @param menu The menu being acted upon.
144 * @param action The action of the menu.
145 * @param param1 First action parameter (usually the client).
146 * @param param2 Second action parameter (usually the item).
149 functag MenuHandler public(Handle:menu, MenuAction:action, param1, param2);
152 * Creates a new, empty menu using the default style.
154 * @param handler Function which will receive menu actions.
155 * @param actions Optionally set which actions to receive. Select,
156 * Cancel, and End will always be received regardless
157 * of whether they are set or not. They are also
158 * the only default actions.
159 * @return A new menu Handle.
161 native Handle:CreateMenu(MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
164 * Displays a menu to a client.
166 * @param menu Menu Handle.
167 * @param client Client index.
168 * @param time Maximum time to leave menu on the screen.
169 * @return True on success, false on failure.
170 * @error Invalid Handle or client not in game.
172 native bool:DisplayMenu(Handle:menu, client, time);
175 * Appends a new item to the end of a menu.
177 * @param menu Menu Handle.
178 * @param info Item information string.
179 * @param display Default item display string.
180 * @param style Drawing style flags. Anything other than DEFAULT or
181 * DISABLED will be completely ignored when paginating.
182 * @return True on success, false on failure.
183 * @error Invalid Handle or item limit reached.
185 native AddMenuItem(Handle:menu,
187 const String:display[],
188 style=ITEMDRAW_DEFAULT);
191 * Inserts an item into the menu before a certain position; the new item will
192 * be at the given position and all next items pushed forward.
194 * @param menu Menu Handle.
195 * @param position Position, starting from 0.
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 menu position.
203 native bool:InsertMenuItem(Handle:menu,
206 const String:display[],
207 style=ITEMDRAW_DEFAULT);
210 * Removes an item from the menu.
212 * @param menu Menu Handle.
213 * @param position Position, starting from 0.
214 * @return True on success, false on failure.
215 * @error Invalid Handle or menu position.
217 native bool:RemoveMenuItem(Handle:menu, position);
220 * Removes all items from a menu.
222 * @param menu Menu Handle.
224 * @error Invalid Handle or menu position.
226 native RemoveAllMenuItems(Handle:menu);
229 * Retrieves information about a menu item.
231 * @param menu Menu Handle.
232 * @param position Position, starting from 0.
233 * @param infoBuf Info buffer.
234 * @param infoBufLen Maximum length of the info buffer.
235 * @param style By-reference variable to store drawing flags.
236 * @param dispBuf Display buffer.
237 * @param dispBufLen Maximum length of the display buffer.
238 * @return True on success, false if position is invalid.
239 * @error Invalid Handle.
241 native bool:GetMenuItem(Handle:menu, position, String:infoBuf[], infoBufLen, &style=0, String:dispBuf[]="", dispBufLen=0);
244 * Returns the number of items in a menu.
246 * @param menu Menu Handle.
247 * @return Number of items in the menu.
248 * @error Invalid Handle.
250 native GetMenuItemCount(Handle:menu);
253 * Sets whether the menu should be paginated or not.
255 * @param menu Handle to the menu.
256 * @param itemsPerPage Number of items per page, or MENU_NO_PAGINATION.
257 * @return True on success, false if pagination is too high or low.
258 * @error Invalid Handle.
260 native bool:SetMenuPagination(Handle:menu, itemsPerPage);
263 * Returns a menu's pagination setting.
265 * @param menu Handle to the menu.
266 * @return Pagination setting.
267 * @error Invalid Handle.
269 native GetMenuPagination(Handle:menu);
272 * Returns a menu's MenuStyle Handle. The Handle
273 * is global and cannot be freed.
275 * @param menu Handle to the menu.
276 * @return Handle to the menu's draw style.
277 * @error Invalid Handle.
279 native Handle:GetMenuStyle(Handle:menu);
282 * Sets the menu's default title/instruction message.
284 * @param menu Menu Handle.
285 * @param fmt Message string format
286 * @param ... Message string arguments.
288 * @error Invalid Handle.
290 native SetMenuTitle(Handle:menu, const String:fmt[], any:...);
293 * Returns the text of a menu's title.
295 * @param menu Menu Handle.
296 * @param buffer Buffer to store title.
297 * @param maxlength Maximum length of the buffer.
298 * @return Number of bytes written.
299 * @error Invalid Handle/
301 native GetMenuTitle(Handle:menu, String:buffer[], maxlength);
304 * Creates a raw MenuPanel based off the menu's style.
305 * The Handle must be freed with CloseHandle().
307 * @return A new MenuPanel Handle.
308 * @error Invalid Handle.
310 native Handle:CreatePanelFromMenu(Handle:menu);
313 * Returns whether or not the menu has an exit button.
314 * By default, menus have an exit button.
316 * @param menu Menu Handle.
317 * @return True if the menu has an exit button; false otherwise.
318 * @error Invalid Handle.
320 native bool:GetMenuExitButton(Handle:menu);
323 * Sets whether or not the menu has an exit button.
324 * By default, menus have an exit button.
326 * @param menu Menu Handle.
327 * @param button True to enable the button, false to remove it.
328 * @return True if allowed; false on failure.
329 * @error Invalid Handle.
331 native bool:SetMenuExitButton(Handle:menu, bool:button);
334 * Returns whether or not the menu has an "exit back" button.
335 * By default, menus do not have an exit back button.
336 * Exit Back buttons appear as "Back" on page 1 of paginated menus and
337 * have functionality defined by the user in MenuEnd_ExitBack.
339 * @param menu Menu Handle.
340 * @return True if the menu has an exit back button; false otherwise.
341 * @error Invalid Handle.
343 native bool:GetMenuExitBackButton(Handle:menu);
346 * Sets whether or not the menu has an "exit back" button.
347 * By default, menus do not have an exit back button.
348 * Exit Back buttons appear as "Back" on page 1 of paginated menus and
349 * have functionality defined by the user in MenuEnd_ExitBack.
351 * @param menu Menu Handle.
352 * @param button True to enable the button, false to remove it.
353 * @error Invalid Handle.
355 native SetMenuExitBackButton(Handle:menu, bool:button);
359 * Cancels a menu from displaying on all clients. While the
360 * cancellation is in progress, this menu cannot be re-displayed
363 * The menu may still exist on the client's screen after this command.
364 * This simply verifies that the menu is not being used anywhere.
366 * If any vote is in progress on a menu, it will be cancelled.
368 * @param menu Menu Handle.
370 * @error Invalid Handle.
372 native CancelMenu(Handle:menu);
375 * Retrieves a menu's option flags.
377 * @param menu Menu Handle.
378 * @return A bitstring of MENUFLAG bits.
379 * @error Invalid Handle.
381 native GetMenuOptionFlags(Handle:menu);
384 * Sets a menu's option flags.
386 * If a certain bit is not supported, it will be stripped before
389 * @param menu Menu Handle.
390 * @param flags A new bitstring of MENUFLAG bits.
392 * @error Invalid Handle.
394 native SetMenuOptionFlags(Handle:menu, flags);
397 * Returns whether a vote is in progress.
399 * @param menu Deprecated; no longer used.
400 * @return True if a vote is in progress, false otherwise.
402 native bool:IsVoteInProgress(Handle:menu=INVALID_HANDLE);
405 * Cancels the vote in progress.
408 * @error If no vote is in progress.
413 * Broadcasts a menu to a list of clients. The most selected item will be
414 * returned through MenuAction_End. On a tie, a random item will be returned
415 * from a list of the tied items.
417 * Note that MenuAction_VoteEnd and MenuAction_VoteStart are both
418 * default callbacks and do not need to be enabled.
420 * @param menu Menu Handle.
421 * @param clients Array of clients to broadcast to.
422 * @param numClients Number of clients in the array.
423 * @param time Maximum time to leave menu on the screen.
424 * @return True on success, false if this menu already has a vote session
426 * @error Invalid Handle, or a vote is already in progress.
428 native bool:VoteMenu(Handle:menu, clients[], numClients, time);
431 * Sends a vote menu to all clients. See VoteMenu() for more information.
433 * @param menu Menu Handle.
434 * @param time Maximum time to leave menu on the screen.
435 * @return True on success, false if this menu already has a vote session
437 * @error Invalid Handle.
439 stock VoteMenuToAll(Handle:menu, time)
441 new num = GetMaxClients();
445 for (new i=1; i<=num; i++)
447 if (!IsClientInGame(i))
451 players[total++] = i;
454 return VoteMenu(menu, players, total, time);
457 * Callback for when a vote has ended and results are available.
459 * @param menu The menu being voted on.
460 * @param num_votes Number of votes tallied in total.
461 * @param num_clients Number of clients who could vote.
462 * @param client_info Array of clients. Use VOTEINFO_CLIENT_ defines.
463 * @param num_items Number of unique items that were selected.
464 * @param item_info Array of items, sorted by count. Use VOTEINFO_ITEM
468 functag VoteHandler public(Handle:menu,
471 const client_info[][2],
473 const item_info[][2]);
476 * Sets an advanced vote handling callback. If this callback is set,
477 * MenuAction_VoteEnd will not be called.
479 * @param menu Menu Handle.
480 * @param callback Callback function.
482 * @error Invalid Handle or callback.
484 native SetVoteResultCallback(Handle:menu, VoteHandler:callback);
487 * Returns the number of seconds you should "wait" before displaying
488 * a publicly invocable menu. This number is the time remaining until
489 * (last_vote + sm_vote_delay).
491 * @return Number of seconds to wait, or 0 for none.
493 native CheckVoteDelay();
496 * Returns a style's global Handle.
498 * @param style Menu Style.
499 * @return A Handle, or INVALID_HANDLE if not found or unusable.
501 native Handle:GetMenuStyleHandle(MenuStyle:style);
504 * Creates a MenuPanel from a MenuStyle. Panels are used for drawing raw
505 * menus without any extra helper functions. The Handle must be closed
506 * with CloseHandle().
508 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
509 * @return A new MenuPanel Handle.
510 * @error Invalid Handle other than INVALID_HANDLE.
512 native Handle:CreatePanel(Handle:hStyle=INVALID_HANDLE);
515 * Creates a Menu from a MenuStyle. The Handle must be closed with
518 * @parma hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
519 * @param handler Function which will receive menu actions.
520 * @param actions Optionally set which actions to receive. Select,
521 * Cancel, and End will always be received regardless
522 * of whether they are set or not. They are also
523 * the only default actions.
524 * @return A new menu Handle.
525 * @error Invalid Handle other than INVALID_HANDLE.
527 native Handle:CreateMenuEx(Handle:hStyle=INVALID_HANDLE, MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
530 * Returns whether a client is viewing a menu. If the menu source
531 * is MenuSource_Normal, a menu Handle will also be returned.
533 * @param client Client index.
534 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
535 * @return A MenuSource value.
536 * @error Invalid Handle other than INVALID_HANDLE.
538 native MenuSource:GetClientMenu(client, Handle:hStyle=INVALID_HANDLE);
541 * Cancels a menu on a client. This will only affect non-external menus.
543 * @param hstyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
544 * @param client Client index.
545 * @param autoIgnore If true, no menus can be re-drawn on the client during
546 * the cancellation process.
547 * @return True if a menu was cancelled, false otherwise.
549 native bool:CancelClientMenu(client, bool:autoIgnore=false, Handle:hStyle=INVALID_HANDLE);
552 * Returns a style's maximum items per page.
554 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
555 * @return Maximum items per page.
556 * @error Invalid Handle other than INVALID_HANDLE.
558 native GetMaxPageItems(Handle:hStyle=INVALID_HANDLE);
561 * Returns a MenuPanel's parent style.
563 * @param panel A MenuPanel Handle.
564 * @return The MenuStyle Handle that created the panel.
565 * @error Invalid Handle.
567 native Handle:GetPanelStyle(Handle:panel);
570 * Sets the panel's title.
572 * @param panel A MenuPanel Handle.
573 * @param title Text to set as the title.
574 * @param onlyIfEmpty If true, the title will only be set if no title is set.
576 * @error Invalid Handle.
578 native Handle:SetPanelTitle(Handle:panel, const String:text[], bool:onlyIfEmpty=false);
581 * Draws an item on a panel. If the item takes up a slot, the position
584 * @param panel A MenuPanel Handle.
585 * @param text Display text to use. If not a raw line,
586 * the style may automatically add color markup.
587 * No numbering or newlines are needed.
588 * @param style ITEMDRAW style flags.
589 * @return A slot position, or 0 if item was a rawline or could not be drawn.
590 * @error Invalid Handle.
592 native DrawPanelItem(Handle:panel, const String:text[], style=ITEMDRAW_DEFAULT);
595 * Draws a raw line of text on a panel, without any markup other than a newline.
597 * @param panel A MenuPanel Handle, or INVALID_HANDLE if inside a
598 * MenuAction_DisplayItem callback.
599 * @param text Display text to use.
600 * @return True on success, false if raw lines are not supported.
601 * @error Invalid Handle.
603 native DrawPanelText(Handle:panel, const String:text[]);
606 * Returns whether or not the given drawing flags are supported by
609 * @param panel A MenuPanel Handle.
610 * @param style ITEMDRAW style flags.
611 * @return True if item is drawable, false otherwise.
612 * @error Invalid Handle.
614 native CanPanelDrawFlags(Handle:panel, style);
617 * Sets the selectable key map of a panel. This is not supported by
618 * all styles (only by Radio, as of this writing).
620 * @param keys An integer where each bit N allows key
621 * N+1 to be selected. If no keys are selectable,
622 * then key 0 (bit 9) is automatically set.
623 * @return True if supported, false otherwise.
625 native bool:SetPanelKeys(Handle:panel, keys);
628 * Sends a panel to a client. Unlike full menus, the handler
629 * function will only receive the following actions, both of
630 * which will have INVALID_HANDLE for a menu, and the client
633 * MenuAction_Select (param2 will be the key pressed)
634 * MenuAction_Cancel (param2 will be the reason)
636 * Also, if the menu fails to display, no callbacks will be called.
638 * @param panel A MenuPanel Handle.
639 * @param client A client to draw to.
640 * @param handler The MenuHandler function to catch actions with.
641 * @param time Time to hold the menu for.
642 * @return True on success, false on failure.
643 * @error Invalid Handle.
645 native bool:SendPanelToClient(Handle:panel, client, MenuHandler:handler, time);
648 * @brief Returns the current key position.
650 * @param panel A MenuPanel Handle.
651 * @return Current key position starting at 1.
652 * @error Invalid Handle.
654 native GetPanelCurrentKey(Handle:panel);
657 * @brief Sets the next key position. This cannot be used
658 * to traverse backwards.
660 * @param panel A MenuPanel Handle.
661 * @param key Key that is greater or equal to
662 * GetPanelCurrentKey().
663 * @return True on success, false otherwise.
664 * @error Invalid Handle.
666 native bool:SetPanelCurrentKey(Handle:panel, key);
669 * @brief Redraws menu text from inside a MenuAction_DisplayItem callback.
671 * @param text Menu text to draw.
672 * @return Item position; must be returned via the callback.
674 native RedrawMenuItem(const String:text[]);
677 * Retrieves voting information from MenuAction_VoteEnd.
679 * @param param2 Second parameter of MenuAction_VoteEnd.
680 * @param winningVotes Number of votes received by the winning option.
681 * @param totalVotes Number of total votes received.
684 stock GetMenuVoteInfo(param2, &winningVotes, &totalVotes)
686 winningVotes = param2 & 0xFFFF;
687 totalVotes = param2 >> 16;