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 * Displays a menu to a client, starting from the given item.
177 * @param menu Menu Handle.
178 * @param client Client index.
179 * @param first_item First item to begin drawing from.
180 * @param time Maximum time to leave menu on the screen.
181 * @return True on success, false on failure.
182 * @error Invalid Handle or client not in game.
184 native bool:DisplayMenuAtItem(Handle:menu, client, first_item, time);
187 * Appends a new item to the end of a menu.
189 * @param menu Menu Handle.
190 * @param info Item information string.
191 * @param display Default item display string.
192 * @param style Drawing style flags. Anything other than DEFAULT or
193 * DISABLED will be completely ignored when paginating.
194 * @return True on success, false on failure.
195 * @error Invalid Handle or item limit reached.
197 native AddMenuItem(Handle:menu,
199 const String:display[],
200 style=ITEMDRAW_DEFAULT);
203 * Inserts an item into the menu before a certain position; the new item will
204 * be at the given position and all next items pushed forward.
206 * @param menu Menu Handle.
207 * @param position Position, starting from 0.
208 * @param info Item information string.
209 * @param display Default item display string.
210 * @param style Drawing style flags. Anything other than DEFAULT or
211 * DISABLED will be completely ignored when paginating.
212 * @return True on success, false on failure.
213 * @error Invalid Handle or menu position.
215 native bool:InsertMenuItem(Handle:menu,
218 const String:display[],
219 style=ITEMDRAW_DEFAULT);
222 * Removes an item from the menu.
224 * @param menu Menu Handle.
225 * @param position Position, starting from 0.
226 * @return True on success, false on failure.
227 * @error Invalid Handle or menu position.
229 native bool:RemoveMenuItem(Handle:menu, position);
232 * Removes all items from a menu.
234 * @param menu Menu Handle.
236 * @error Invalid Handle or menu position.
238 native RemoveAllMenuItems(Handle:menu);
241 * Retrieves information about a menu item.
243 * @param menu Menu Handle.
244 * @param position Position, starting from 0.
245 * @param infoBuf Info buffer.
246 * @param infoBufLen Maximum length of the info buffer.
247 * @param style By-reference variable to store drawing flags.
248 * @param dispBuf Display buffer.
249 * @param dispBufLen Maximum length of the display buffer.
250 * @return True on success, false if position is invalid.
251 * @error Invalid Handle.
253 native bool:GetMenuItem(Handle:menu,
262 * Returns the first item on the page of a currently selected menu.
264 * This is only valid inside a MenuAction_Select callback.
266 * @return First item number on the page the client was viewing
267 * before selecting the item in the callback. This can
268 * be used to re-display the menu from the original
270 * @error Not called from inside a MenuAction_Select callback.
272 native GetMenuSelectionPosition();
275 * Returns the number of items in a menu.
277 * @param menu Menu Handle.
278 * @return Number of items in the menu.
279 * @error Invalid Handle.
281 native GetMenuItemCount(Handle:menu);
284 * Sets whether the menu should be paginated or not.
286 * @param menu Handle to the menu.
287 * @param itemsPerPage Number of items per page, or MENU_NO_PAGINATION.
288 * @return True on success, false if pagination is too high or low.
289 * @error Invalid Handle.
291 native bool:SetMenuPagination(Handle:menu, itemsPerPage);
294 * Returns a menu's pagination setting.
296 * @param menu Handle to the menu.
297 * @return Pagination setting.
298 * @error Invalid Handle.
300 native GetMenuPagination(Handle:menu);
303 * Returns a menu's MenuStyle Handle. The Handle
304 * is global and cannot be freed.
306 * @param menu Handle to the menu.
307 * @return Handle to the menu's draw style.
308 * @error Invalid Handle.
310 native Handle:GetMenuStyle(Handle:menu);
313 * Sets the menu's default title/instruction message.
315 * @param menu Menu Handle.
316 * @param fmt Message string format
317 * @param ... Message string arguments.
319 * @error Invalid Handle.
321 native SetMenuTitle(Handle:menu, const String:fmt[], any:...);
324 * Returns the text of a menu's title.
326 * @param menu Menu Handle.
327 * @param buffer Buffer to store title.
328 * @param maxlength Maximum length of the buffer.
329 * @return Number of bytes written.
330 * @error Invalid Handle/
332 native GetMenuTitle(Handle:menu, String:buffer[], maxlength);
335 * Creates a raw MenuPanel based off the menu's style.
336 * The Handle must be freed with CloseHandle().
338 * @return A new MenuPanel Handle.
339 * @error Invalid Handle.
341 native Handle:CreatePanelFromMenu(Handle:menu);
344 * Returns whether or not the menu has an exit button.
345 * By default, menus have an exit button.
347 * @param menu Menu Handle.
348 * @return True if the menu has an exit button; false otherwise.
349 * @error Invalid Handle.
351 native bool:GetMenuExitButton(Handle:menu);
354 * Sets whether or not the menu has an exit button.
355 * By default, menus have an exit button.
357 * @param menu Menu Handle.
358 * @param button True to enable the button, false to remove it.
359 * @return True if allowed; false on failure.
360 * @error Invalid Handle.
362 native bool:SetMenuExitButton(Handle:menu, bool:button);
365 * Returns whether or not the menu has an "exit back" button.
366 * By default, menus do not have an exit back button.
367 * Exit Back buttons appear as "Back" on page 1 of paginated menus and
368 * have functionality defined by the user in MenuEnd_ExitBack.
370 * @param menu Menu Handle.
371 * @return True if the menu has an exit back button; false otherwise.
372 * @error Invalid Handle.
374 native bool:GetMenuExitBackButton(Handle:menu);
377 * Sets whether or not the menu has an "exit back" button.
378 * By default, menus do not have an exit back button.
379 * Exit Back buttons appear as "Back" on page 1 of paginated menus and
380 * have functionality defined by the user in MenuEnd_ExitBack.
382 * @param menu Menu Handle.
383 * @param button True to enable the button, false to remove it.
384 * @error Invalid Handle.
386 native SetMenuExitBackButton(Handle:menu, bool:button);
390 * Cancels a menu from displaying on all clients. While the
391 * cancellation is in progress, this menu cannot be re-displayed
394 * The menu may still exist on the client's screen after this command.
395 * This simply verifies that the menu is not being used anywhere.
397 * If any vote is in progress on a menu, it will be cancelled.
399 * @param menu Menu Handle.
401 * @error Invalid Handle.
403 native CancelMenu(Handle:menu);
406 * Retrieves a menu's option flags.
408 * @param menu Menu Handle.
409 * @return A bitstring of MENUFLAG bits.
410 * @error Invalid Handle.
412 native GetMenuOptionFlags(Handle:menu);
415 * Sets a menu's option flags.
417 * If a certain bit is not supported, it will be stripped before
420 * @param menu Menu Handle.
421 * @param flags A new bitstring of MENUFLAG bits.
423 * @error Invalid Handle.
425 native SetMenuOptionFlags(Handle:menu, flags);
428 * Returns whether a vote is in progress.
430 * @param menu Deprecated; no longer used.
431 * @return True if a vote is in progress, false otherwise.
433 native bool:IsVoteInProgress(Handle:menu=INVALID_HANDLE);
436 * Cancels the vote in progress.
439 * @error If no vote is in progress.
444 * Broadcasts a menu to a list of clients. The most selected item will be
445 * returned through MenuAction_End. On a tie, a random item will be returned
446 * from a list of the tied items.
448 * Note that MenuAction_VoteEnd and MenuAction_VoteStart are both
449 * default callbacks and do not need to be enabled.
451 * @param menu Menu Handle.
452 * @param clients Array of clients to broadcast to.
453 * @param numClients Number of clients in the array.
454 * @param time Maximum time to leave menu on the screen.
455 * @return True on success, false if this menu already has a vote session
457 * @error Invalid Handle, or a vote is already in progress.
459 native bool:VoteMenu(Handle:menu, clients[], numClients, time);
462 * Sends a vote menu to all clients. See VoteMenu() for more information.
464 * @param menu Menu Handle.
465 * @param time Maximum time to leave menu on the screen.
466 * @return True on success, false if this menu already has a vote session
468 * @error Invalid Handle.
470 stock VoteMenuToAll(Handle:menu, time)
472 new num = GetMaxClients();
476 for (new i=1; i<=num; i++)
478 if (!IsClientInGame(i))
482 players[total++] = i;
485 return VoteMenu(menu, players, total, time);
488 * Callback for when a vote has ended and results are available.
490 * @param menu The menu being voted on.
491 * @param num_votes Number of votes tallied in total.
492 * @param num_clients Number of clients who could vote.
493 * @param client_info Array of clients. Use VOTEINFO_CLIENT_ defines.
494 * @param num_items Number of unique items that were selected.
495 * @param item_info Array of items, sorted by count. Use VOTEINFO_ITEM
499 functag VoteHandler public(Handle:menu,
502 const client_info[][2],
504 const item_info[][2]);
507 * Sets an advanced vote handling callback. If this callback is set,
508 * MenuAction_VoteEnd will not be called.
510 * @param menu Menu Handle.
511 * @param callback Callback function.
513 * @error Invalid Handle or callback.
515 native SetVoteResultCallback(Handle:menu, VoteHandler:callback);
518 * Returns the number of seconds you should "wait" before displaying
519 * a publicly invocable menu. This number is the time remaining until
520 * (last_vote + sm_vote_delay).
522 * @return Number of seconds to wait, or 0 for none.
524 native CheckVoteDelay();
527 * Returns a style's global Handle.
529 * @param style Menu Style.
530 * @return A Handle, or INVALID_HANDLE if not found or unusable.
532 native Handle:GetMenuStyleHandle(MenuStyle:style);
535 * Creates a MenuPanel from a MenuStyle. Panels are used for drawing raw
536 * menus without any extra helper functions. The Handle must be closed
537 * with CloseHandle().
539 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
540 * @return A new MenuPanel Handle.
541 * @error Invalid Handle other than INVALID_HANDLE.
543 native Handle:CreatePanel(Handle:hStyle=INVALID_HANDLE);
546 * Creates a Menu from a MenuStyle. The Handle must be closed with
549 * @parma hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
550 * @param handler Function which will receive menu actions.
551 * @param actions Optionally set which actions to receive. Select,
552 * Cancel, and End will always be received regardless
553 * of whether they are set or not. They are also
554 * the only default actions.
555 * @return A new menu Handle.
556 * @error Invalid Handle other than INVALID_HANDLE.
558 native Handle:CreateMenuEx(Handle:hStyle=INVALID_HANDLE, MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
561 * Returns whether a client is viewing a menu. If the menu source
562 * is MenuSource_Normal, a menu Handle will also be returned.
564 * @param client Client index.
565 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
566 * @return A MenuSource value.
567 * @error Invalid Handle other than INVALID_HANDLE.
569 native MenuSource:GetClientMenu(client, Handle:hStyle=INVALID_HANDLE);
572 * Cancels a menu on a client. This will only affect non-external menus.
574 * @param hstyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
575 * @param client Client index.
576 * @param autoIgnore If true, no menus can be re-drawn on the client during
577 * the cancellation process.
578 * @return True if a menu was cancelled, false otherwise.
580 native bool:CancelClientMenu(client, bool:autoIgnore=false, Handle:hStyle=INVALID_HANDLE);
583 * Returns a style's maximum items per page.
585 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
586 * @return Maximum items per page.
587 * @error Invalid Handle other than INVALID_HANDLE.
589 native GetMaxPageItems(Handle:hStyle=INVALID_HANDLE);
592 * Returns a MenuPanel's parent style.
594 * @param panel A MenuPanel Handle.
595 * @return The MenuStyle Handle that created the panel.
596 * @error Invalid Handle.
598 native Handle:GetPanelStyle(Handle:panel);
601 * Sets the panel's title.
603 * @param panel A MenuPanel Handle.
604 * @param title Text to set as the title.
605 * @param onlyIfEmpty If true, the title will only be set if no title is set.
607 * @error Invalid Handle.
609 native Handle:SetPanelTitle(Handle:panel, const String:text[], bool:onlyIfEmpty=false);
612 * Draws an item on a panel. If the item takes up a slot, the position
615 * @param panel A MenuPanel Handle.
616 * @param text Display text to use. If not a raw line,
617 * the style may automatically add color markup.
618 * No numbering or newlines are needed.
619 * @param style ITEMDRAW style flags.
620 * @return A slot position, or 0 if item was a rawline or could not be drawn.
621 * @error Invalid Handle.
623 native DrawPanelItem(Handle:panel, const String:text[], style=ITEMDRAW_DEFAULT);
626 * Draws a raw line of text on a panel, without any markup other than a newline.
628 * @param panel A MenuPanel Handle, or INVALID_HANDLE if inside a
629 * MenuAction_DisplayItem callback.
630 * @param text Display text to use.
631 * @return True on success, false if raw lines are not supported.
632 * @error Invalid Handle.
634 native DrawPanelText(Handle:panel, const String:text[]);
637 * Returns whether or not the given drawing flags are supported by
640 * @param panel A MenuPanel Handle.
641 * @param style ITEMDRAW style flags.
642 * @return True if item is drawable, false otherwise.
643 * @error Invalid Handle.
645 native CanPanelDrawFlags(Handle:panel, style);
648 * Sets the selectable key map of a panel. This is not supported by
649 * all styles (only by Radio, as of this writing).
651 * @param keys An integer where each bit N allows key
652 * N+1 to be selected. If no keys are selectable,
653 * then key 0 (bit 9) is automatically set.
654 * @return True if supported, false otherwise.
656 native bool:SetPanelKeys(Handle:panel, keys);
659 * Sends a panel to a client. Unlike full menus, the handler
660 * function will only receive the following actions, both of
661 * which will have INVALID_HANDLE for a menu, and the client
664 * MenuAction_Select (param2 will be the key pressed)
665 * MenuAction_Cancel (param2 will be the reason)
667 * Also, if the menu fails to display, no callbacks will be called.
669 * @param panel A MenuPanel Handle.
670 * @param client A client to draw to.
671 * @param handler The MenuHandler function to catch actions with.
672 * @param time Time to hold the menu for.
673 * @return True on success, false on failure.
674 * @error Invalid Handle.
676 native bool:SendPanelToClient(Handle:panel, client, MenuHandler:handler, time);
679 * @brief Returns the amount of text the menu can still hold. If this is
680 * limit is reached or overflowed, the text is silently truncated.
682 * Radio menus: Currently 511 characters (512 bytes).
683 * Valve menus: Currently -1 (no meaning).
685 * @param panel A MenuPanel Handle.
686 * @return Number of characters that the menu can still hold,
687 * or -1 if there is no known limit.
688 * @error Invalid Handle.
690 native GetPanelTextRemaining(Handle:panel);
693 * @brief Returns the current key position.
695 * @param panel A MenuPanel Handle.
696 * @return Current key position starting at 1.
697 * @error Invalid Handle.
699 native GetPanelCurrentKey(Handle:panel);
702 * @brief Sets the next key position. This cannot be used
703 * to traverse backwards.
705 * @param panel A MenuPanel Handle.
706 * @param key Key that is greater or equal to
707 * GetPanelCurrentKey().
708 * @return True on success, false otherwise.
709 * @error Invalid Handle.
711 native bool:SetPanelCurrentKey(Handle:panel, key);
714 * @brief Redraws menu text from inside a MenuAction_DisplayItem callback.
716 * @param text Menu text to draw.
717 * @return Item position; must be returned via the callback.
719 native RedrawMenuItem(const String:text[]);
722 * Retrieves voting information from MenuAction_VoteEnd.
724 * @param param2 Second parameter of MenuAction_VoteEnd.
725 * @param winningVotes Number of votes received by the winning option.
726 * @param totalVotes Number of total votes received.
729 stock GetMenuVoteInfo(param2, &winningVotes, &totalVotes)
731 winningVotes = param2 & 0xFFFF;
732 totalVotes = param2 >> 16;
736 * Quick stock to determine whether voting is allowed. This doesn't let you
737 * fine-tune a reason for not voting, so it's not recommended for lazily
738 * telling clients that voting isn't allowed.
740 * @return True if voting is allowed, false if voting is in progress
741 * or the cooldown is active.
743 stock bool:IsNewVoteAllowed()
745 if (IsVoteInProgress() || CheckVoteDelay() != 0)