3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
8 * or modified under the Terms and Conditions of its License Agreement, which is found
9 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10 * may change at any time. To view the latest information, see:
11 * http://www.sourcemod.net/license.php
16 #if defined _menus_included
19 #define _menus_included
22 * Low-level drawing style of the menu.
26 MenuStyle_Default = 0, /**< The "default" menu style for the mod */
27 MenuStyle_Valve = 1, /**< The Valve provided menu style (Used on HL2DM) */
28 MenuStyle_Radio = 2, /**< The simpler menu style commonly used on CS:S */
32 * Different actions for the menu "pump" callback
36 MenuAction_Start = (1<<0), /**< A menu has been started (nothing passed) */
37 MenuAction_Display = (1<<1), /**< A menu is about to be displayed (param1=client, param2=MenuPanel Handle) */
38 MenuAction_Select = (1<<2), /**< An item was selected (param1=client, param2=item) */
39 MenuAction_Cancel = (1<<3), /**< The menu was cancelled (param1=client, param2=reason) */
40 MenuAction_End = (1<<4), /**< A menu display has fully ended (param1=reason, param2=cancel reason) */
41 MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has succeeded (param1=chosen item)
42 This is not called if SetVoteResultCallback has been used on the menu. */
43 MenuAction_VoteStart = (1<<6), /**< (VOTE ONLY): A vote sequence has started (nothing passed) */
44 MenuAction_VoteCancel = (1<<7), /**< (VOTE ONLY): A vote sequence has been cancelled (nothing passed) */
45 MenuAction_DrawItem = (1<<8), /**< An item is being drawn; return the new style (param1=client, param2=item) */
46 MenuAction_DisplayItem = (1<<9) /**< Item text is being drawn to the display (param1=client, param2=item)
47 To change the text, use RedrawMenuItem().
48 If you do so, return its return value. Otherwise, return 0.
52 /** Default menu actions */
53 #define MENU_ACTIONS_DEFAULT MenuAction_Select|MenuAction_Cancel|MenuAction_End
54 /** All menu actions */
55 #define MENU_ACTIONS_ALL -1
57 #define MENU_NO_PAGINATION 0 /**< Menu should not be paginated (10 items max) */
58 #define MENU_TIME_FOREVER 0 /**< Menu should be displayed as long as possible */
60 #define ITEMDRAW_DEFAULT (0) /**< Item should be drawn normally */
61 #define ITEMDRAW_DISABLED (1<<0) /**< Item is drawn but not selectable */
62 #define ITEMDRAW_RAWLINE (1<<1) /**< Item should be a raw line, without a slot */
63 #define ITEMDRAW_NOTEXT (1<<2) /**< No text should be drawn */
64 #define ITEMDRAW_SPACER (1<<3) /**< Item should be drawn as a spacer, if possible */
65 #define ITEMDRAW_IGNORE ((1<<1)|(1<<2)) /**< Item should be completely ignored (rawline + notext) */
66 #define ITEMDRAW_CONTROL (1<<4) /**< Item is control text (back/next/exit) */
68 #define MENUFLAG_BUTTON_EXIT (1<<0) /**< Menu has an "exit" button */
69 #define MENUFLAG_BUTTON_EXITBACK (1<<1) /**< Menu has an "exit back" button */
70 #define MENUFLAG_NO_SOUND (1<<2) /**< Menu will not have any select sounds */
72 #define VOTEINFO_CLIENT_INDEX 0 /**< Client index */
73 #define VOTEINFO_CLIENT_ITEM 1 /**< Item the client selected, or -1 for none */
74 #define VOTEINFO_ITEM_INDEX 0 /**< Item index */
75 #define VOTEINFO_ITEM_VOTES 1 /**< Number of votes for the item */
78 * Reasons a menu can be cancelled.
82 MenuCancel_Disconnected = -1, /**< Client dropped from the server */
83 MenuCancel_Interrupted = -2, /**< Client was interrupted with another menu */
84 MenuCancel_Exit = -3, /**< Client exited via "exit" */
85 MenuCancel_NoDisplay = -4, /**< Menu could not be displayed to the client */
86 MenuCancel_Timeout = -5, /**< Menu timed out */
87 MenuCancel_ExitBack = -6, /**< Client selected "exit back" on a paginated menu */
91 * Reasons a menu ended.
95 MenuEnd_Selected = 0, /**< Menu item was selected */
96 MenuEnd_VotingDone = -1, /**< Voting finished */
97 MenuEnd_VotingCancelled = -2, /**< Voting was cancelled */
98 MenuEnd_Cancelled = -3, /**< Menu was cancelled (reason in param2) */
99 MenuEnd_Exit = -4, /**< Menu was cleanly exited via "exit" */
100 MenuEnd_ExitBack = -5, /**< Menu was cleanly exited via "back" */
101 MenuEnd_NoVotes = -6, /**< A menu received no votes */
105 * Describes a menu's source
109 MenuSource_None = 0, /**< No menu is being displayed */
110 MenuSource_External = 1, /**< External menu */
111 MenuSource_Normal = 2, /**< A basic menu is being displayed */
112 MenuSource_RawPanel = 3, /**< A display is active, but it is not tied to a menu */
116 * Called when a menu action is completed.
118 * @param menu The menu being acted upon.
119 * @param action The action of the menu.
120 * @param param1 First action parameter (usually the client).
121 * @param param2 Second action parameter (usually the item).
124 functag MenuHandler public(Handle:menu, MenuAction:action, param1, param2);
127 * Creates a new, empty menu using the default style.
129 * @param handler Function which will receive menu actions.
130 * @param actions Optionally set which actions to receive. Select,
131 * Cancel, and End will always be received regardless
132 * of whether they are set or not. They are also
133 * the only default actions.
134 * @return A new menu Handle.
136 native Handle:CreateMenu(MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
139 * Displays a menu to a client.
141 * @param menu Menu Handle.
142 * @param client Client index.
143 * @param time Maximum time to leave menu on the screen.
144 * @return True on success, false on failure.
145 * @error Invalid Handle or client not in game.
147 native bool:DisplayMenu(Handle:menu, client, time);
150 * Appends a new item to the end of a menu.
152 * @param menu Menu Handle.
153 * @param info Item information string.
154 * @param display Default item display string.
155 * @param style Drawing style flags. Anything other than DEFAULT or
156 * DISABLED will be completely ignored when paginating.
157 * @return True on success, false on failure.
158 * @error Invalid Handle or item limit reached.
160 native AddMenuItem(Handle:menu,
162 const String:display[],
163 style=ITEMDRAW_DEFAULT);
166 * Inserts an item into the menu before a certain position; the new item will
167 * be at the given position and all next items pushed forward.
169 * @param menu Menu Handle.
170 * @param position Position, starting from 0.
171 * @param info Item information string.
172 * @param display Default item display string.
173 * @param style Drawing style flags. Anything other than DEFAULT or
174 * DISABLED will be completely ignored when paginating.
175 * @return True on success, false on failure.
176 * @error Invalid Handle or menu position.
178 native bool:InsertMenuItem(Handle:menu,
181 const String:display[],
182 style=ITEMDRAW_DEFAULT);
185 * Removes an item from the menu.
187 * @param menu Menu Handle.
188 * @param position Position, starting from 0.
189 * @return True on success, false on failure.
190 * @error Invalid Handle or menu position.
192 native bool:RemoveMenuItem(Handle:menu, position);
195 * Removes all items from a menu.
197 * @param menu Menu Handle.
199 * @error Invalid Handle or menu position.
201 native RemoveAllMenuItems(Handle:menu);
204 * Retrieves information about a menu item.
206 * @param menu Menu Handle.
207 * @param position Position, starting from 0.
208 * @param infoBuf Info buffer.
209 * @param infoBufLen Maximum length of the info buffer.
210 * @param style By-reference variable to store drawing flags.
211 * @param dispBuf Display buffer.
212 * @param dispBufLen Maximum length of the display buffer.
213 * @return True on success, false if position is invalid.
214 * @error Invalid Handle.
216 native bool:GetMenuItem(Handle:menu, position, String:infoBuf[], infoBufLen, &style=0, String:dispBuf[]="", dispBufLen=0);
219 * Returns the number of items in a menu.
221 * @param menu Menu Handle.
222 * @return Number of items in the menu.
223 * @error Invalid Handle.
225 native GetMenuItemCount(Handle:menu);
228 * Sets whether the menu should be paginated or not.
230 * @param menu Handle to the menu.
231 * @param itemsPerPage Number of items per page, or MENU_NO_PAGINATION.
232 * @return True on success, false if pagination is too high or low.
233 * @error Invalid Handle.
235 native bool:SetMenuPagination(Handle:menu, itemsPerPage);
238 * Returns a menu's pagination setting.
240 * @param menu Handle to the menu.
241 * @return Pagination setting.
242 * @error Invalid Handle.
244 native GetMenuPagination(Handle:menu);
247 * Returns a menu's MenuStyle Handle. The Handle
248 * is global and cannot be freed.
250 * @param menu Handle to the menu.
251 * @return Handle to the menu's draw style.
252 * @error Invalid Handle.
254 native Handle:GetMenuStyle(Handle:menu);
257 * Sets the menu's default title/instruction message.
259 * @param menu Menu Handle.
260 * @param fmt Message string format
261 * @param ... Message string arguments.
263 * @error Invalid Handle.
265 native SetMenuTitle(Handle:menu, const String:fmt[], any:...);
268 * Creates a raw MenuPanel based off the menu's style.
269 * The Handle must be freed with CloseHandle().
271 * @return A new MenuPanel Handle.
272 * @error Invalid Handle.
274 native Handle:CreatePanelFromMenu(Handle:menu);
277 * Returns whether or not the menu has an exit button.
278 * By default, menus have an exit button.
280 * @param menu Menu Handle.
281 * @return True if the menu has an exit button; false otherwise.
282 * @error Invalid Handle.
284 native bool:GetMenuExitButton(Handle:menu);
287 * Sets whether or not the menu has an exit button.
288 * By default, menus have an exit button.
290 * @param menu Menu Handle.
291 * @param button True to enable the button, false to remove it.
292 * @return True if allowed; false on failure.
293 * @error Invalid Handle.
295 native bool:SetMenuExitButton(Handle:menu, bool:button);
298 * Returns whether or not the menu has an "exit back" button.
299 * By default, menus do not have an exit back button.
300 * Exit Back buttons appear as "Back" on page 1 of paginated menus and
301 * have functionality defined by the user in MenuEnd_ExitBack.
303 * @param menu Menu Handle.
304 * @return True if the menu has an exit back button; false otherwise.
305 * @error Invalid Handle.
307 native bool:GetMenuExitBackButton(Handle:menu);
310 * Sets whether or not the menu has an "exit back" button.
311 * By default, menus do not have an exit back button.
312 * Exit Back buttons appear as "Back" on page 1 of paginated menus and
313 * have functionality defined by the user in MenuEnd_ExitBack.
315 * @param menu Menu Handle.
316 * @param button True to enable the button, false to remove it.
317 * @error Invalid Handle.
319 native SetMenuExitBackButton(Handle:menu, bool:button);
323 * Cancels a menu from displaying on all clients. While the
324 * cancellation is in progress, this menu cannot be re-displayed
327 * The menu may still exist on the client's screen after this command.
328 * This simply verifies that the menu is not being used anywhere.
330 * If any vote is in progress on a menu, it will be cancelled.
332 * @param menu Menu Handle.
334 * @error Invalid Handle.
336 native CancelMenu(Handle:menu);
339 * Retrieves a menu's option flags.
341 * @param menu Menu Handle.
342 * @return A bitstring of MENUFLAG bits.
343 * @error Invalid Handle.
345 native GetMenuOptionFlags(Handle:menu);
348 * Sets a menu's option flags.
350 * If a certain bit is not supported, it will be stripped before
353 * @param menu Menu Handle.
354 * @param flags A new bitstring of MENUFLAG bits.
356 * @error Invalid Handle.
358 native SetMenuOptionFlags(Handle:menu, flags);
361 * Returns whether a vote is in progress.
363 * @param menu Deprecated; no longer used.
364 * @return True if a vote is in progress, false otherwise.
366 native bool:IsVoteInProgress(Handle:menu=INVALID_HANDLE);
369 * Cancels the vote in progress.
372 * @error If no vote is in progress.
377 * Broadcasts a menu to a list of clients. The most selected item will be
378 * returned through MenuAction_End. On a tie, a random item will be returned
379 * from a list of the tied items.
381 * Note that MenuAction_VoteEnd and MenuAction_VoteStart are both
382 * default callbacks and do not need to be enabled.
384 * @param menu Menu Handle.
385 * @param clients Array of clients to broadcast to.
386 * @param numClients Number of clients in the array.
387 * @param time Maximum time to leave menu on the screen.
388 * @return True on success, false if this menu already has a vote session
390 * @error Invalid Handle, or a vote is already in progress.
392 native bool:VoteMenu(Handle:menu, clients[], numClients, time);
395 * Sends a vote menu to all clients. See VoteMenu() for more information.
397 * @param menu Menu Handle.
398 * @param time Maximum time to leave menu on the screen.
399 * @return True on success, false if this menu already has a vote session
401 * @error Invalid Handle.
403 stock VoteMenuToAll(Handle:menu, time)
405 new num = GetMaxClients();
409 for (new i=1; i<=num; i++)
411 if (!IsClientInGame(i))
415 players[total++] = i;
418 return VoteMenu(menu, players, total, time);
421 * Callback for when a vote has ended and results are available.
423 * @param menu The menu being voted on.
424 * @param num_votes Number of votes tallied in total.
425 * @param num_clients Number of clients who could vote.
426 * @param client_info Array of clients. Use VOTEINFO_CLIENT_ defines.
427 * @param num_items Number of unique items that were selected.
428 * @param item_info Array of items, sorted by count. Use VOTEINFO_ITEM
432 functag VoteHandler public(Handle:menu,
435 const client_info[][2],
437 const item_info[][2]);
440 * Sets an advanced vote handling callback. If this callback is set,
441 * MenuAction_VoteEnd will not be called.
443 * @param menu Menu Handle.
444 * @param callback Callback function.
446 * @error Invalid Handle or callback.
448 native SetVoteResultCallback(Handle:menu, VoteHandler:callback);
451 * Returns a style's global Handle.
453 * @param style Menu Style.
454 * @return A Handle, or INVALID_HANDLE if not found or unusable.
456 native Handle:GetMenuStyleHandle(MenuStyle:style);
459 * Creates a MenuPanel from a MenuStyle. Panels are used for drawing raw
460 * menus without any extra helper functions. The Handle must be closed
461 * with CloseHandle().
463 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
464 * @return A new MenuPanel Handle.
465 * @error Invalid Handle other than INVALID_HANDLE.
467 native Handle:CreatePanel(Handle:hStyle=INVALID_HANDLE);
470 * Creates a Menu from a MenuStyle. The Handle must be closed with
473 * @parma hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
474 * @param handler Function which will receive menu actions.
475 * @param actions Optionally set which actions to receive. Select,
476 * Cancel, and End will always be received regardless
477 * of whether they are set or not. They are also
478 * the only default actions.
479 * @return A new menu Handle.
480 * @error Invalid Handle other than INVALID_HANDLE.
482 native Handle:CreateMenuEx(Handle:hStyle=INVALID_HANDLE, MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
485 * Returns whether a client is viewing a menu. If the menu source
486 * is MenuSource_Normal, a menu Handle will also be returned.
488 * @param client Client index.
489 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
490 * @return A MenuSource value.
491 * @error Invalid Handle other than INVALID_HANDLE.
493 native MenuSource:GetClientMenu(client, Handle:hStyle=INVALID_HANDLE);
496 * Cancels a menu on a client. This will only affect non-external menus.
498 * @param hstyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
499 * @param client Client index.
500 * @param autoIgnore If true, no menus can be re-drawn on the client during
501 * the cancellation process.
502 * @return True if a menu was cancelled, false otherwise.
504 native bool:CancelClientMenu(client, bool:autoIgnore=false, Handle:hStyle=INVALID_HANDLE);
507 * Returns a style's maximum items per page.
509 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
510 * @return Maximum items per page.
511 * @error Invalid Handle other than INVALID_HANDLE.
513 native GetMaxPageItems(Handle:hStyle=INVALID_HANDLE);
516 * Returns a MenuPanel's parent style.
518 * @param panel A MenuPanel Handle.
519 * @return The MenuStyle Handle that created the panel.
520 * @error Invalid Handle.
522 native Handle:GetPanelStyle(Handle:panel);
525 * Sets the panel's title.
527 * @param panel A MenuPanel Handle.
528 * @param title Text to set as the title.
529 * @param onlyIfEmpty If true, the title will only be set if no title is set.
531 * @error Invalid Handle.
533 native Handle:SetPanelTitle(Handle:panel, const String:text[], bool:onlyIfEmpty=false);
536 * Draws an item on a panel. If the item takes up a slot, the position
539 * @param panel A MenuPanel Handle.
540 * @param text Display text to use. If not a raw line,
541 * the style may automatically add color markup.
542 * No numbering or newlines are needed.
543 * @param style ITEMDRAW style flags.
544 * @return A slot position, or 0 if item was a rawline or could not be drawn.
545 * @error Invalid Handle.
547 native DrawPanelItem(Handle:panel, const String:text[], style=ITEMDRAW_DEFAULT);
550 * Draws a raw line of text on a panel, without any markup other than a newline.
552 * @param panel A MenuPanel Handle, or INVALID_HANDLE if inside a
553 * MenuAction_DisplayItem callback.
554 * @param text Display text to use.
555 * @return True on success, false if raw lines are not supported.
556 * @error Invalid Handle.
558 native DrawPanelText(Handle:panel, const String:text[]);
561 * Returns whether or not the given drawing flags are supported by
564 * @param panel A MenuPanel Handle.
565 * @param style ITEMDRAW style flags.
566 * @return True if item is drawable, false otherwise.
567 * @error Invalid Handle.
569 native CanPanelDrawFlags(Handle:panel, style);
572 * Sets the selectable key map of a panel. This is not supported by
573 * all styles (only by Radio, as of this writing).
575 * @param keys An integer where each bit N allows key
576 * N+1 to be selected. If no keys are selectable,
577 * then key 0 (bit 9) is automatically set.
578 * @return True if supported, false otherwise.
580 native bool:SetPanelKeys(Handle:panel, keys);
583 * Sends a panel to a client. Unlike full menus, the handler
584 * function will only receive the following actions, both of
585 * which will have INVALID_HANDLE for a menu, and the client
588 * MenuAction_Select (param2 will be the key pressed)
589 * MenuAction_Cancel (param2 will be the reason)
591 * Also, if the menu fails to display, no callbacks will be called.
593 * @param panel A MenuPanel Handle.
594 * @param client A client to draw to.
595 * @param handler The MenuHandler function to catch actions with.
596 * @param time Time to hold the menu for.
597 * @return True on success, false on failure.
598 * @error Invalid Handle.
600 native bool:SendPanelToClient(Handle:panel, client, MenuHandler:handler, time);
603 * @brief Returns the current key position.
605 * @param panel A MenuPanel Handle.
606 * @return Current key position starting at 1.
607 * @error Invalid Handle.
609 native GetPanelCurrentKey(Handle:panel);
612 * @brief Sets the next key position. This cannot be used
613 * to traverse backwards.
615 * @param panel A MenuPanel Handle.
616 * @param key Key that is greater or equal to
617 * GetPanelCurrentKey().
618 * @return True on success, false otherwise.
619 * @error Invalid Handle.
621 native bool:SetPanelCurrentKey(Handle:panel, key);
624 * @brief Redraws menu text from inside a MenuAction_DisplayItem callback.
626 * @param text Menu text to draw.
627 * @return Item position; must be returned via the callback.
629 native RedrawMenuItem(const String:text[]);
632 * Retrieves voting information from MenuAction_VoteEnd.
634 * @param param2 Second parameter of MenuAction_VoteEnd.
635 * @param winningVotes Number of votes received by the winning option.
636 * @param totalVotes Number of total votes received.
639 stock GetMenuVoteInfo(param2, &winningVotes, &totalVotes)
641 winningVotes = param2 & 0xFFFF;
642 totalVotes = param2 >> 16;