exposed new voting features to plugins (MenuAction_VoteCancel, IsVoteInProgress)
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's display/selection cycle is complete (nothing passed) */
41 MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has succeeded (param1=chosen item) */
42 MenuAction_VoteStart = (1<<6), /**< (VOTE ONLY): A vote sequence has started (nothing passed) */
43 MenuAction_VoteCancel = (1<<7), /**< (VOTE ONLY): A vote sequence has been cancelled (nothing passed) */
46 /** Default menu actions */
47 #define MENU_ACTIONS_DEFAULT MenuAction_Select|MenuAction_Cancel|MenuAction_End
48 /** All menu actions */
49 #define MENU_ACTIONS_ALL -1
51 #define MENU_NO_PAGINATION 0 /**< Menu should not be paginated (10 items max) */
52 #define MENU_TIME_FOREVER 0 /**< Menu should be displayed as long as possible */
54 #define ITEMDRAW_DEFAULT (0) /**< Item should be drawn normally */
55 #define ITEMDRAW_DISABLED (1<<0) /**< Item is drawn but not selectable */
56 #define ITEMDRAW_RAWLINE (1<<1) /**< Item should be a raw line, without a slot */
57 #define ITEMDRAW_NOTEXT (1<<2) /**< No text should be drawn */
58 #define ITEMDRAW_SPACER (1<<3) /**< Item should be drawn as a spacer, if possible */
59 #define ITEMDRAW_IGNORE ((1<<1)|(1<<2)) /**< Item should be completely ignored (rawline + notext) */
60 #define ITEMDRAW_CONTROL (1<<4) /**< Item is control text (back/next/exit) */
63 * Reasons a menu can be cancelled.
67 MenuCancel_Disconnect = -1, /**< Client dropped from the server */
68 MenuCancel_Interrupt = -2, /**< Client was interrupted with another menu */
69 MenuCancel_Exit = -3, /**< Client selected "exit" on a paginated menu */
70 MenuCancel_NoDisplay = -4, /**< Menu could not be displayed to the client */
74 * Describes a menu's source
78 MenuSource_None = 0, /**< No menu is being displayed */
79 MenuSource_External = 1, /**< External menu */
80 MenuSource_Normal = 2, /**< A basic menu is being displayed */
81 MenuSource_RawPanel = 3, /**< A display is active, but it is not tied to a menu */
85 * Called when a menu action is completed.
87 * @param menu The menu being acted upon.
88 * @param action The action of the menu.
89 * @param param1 First action parameter (usually the client).
90 * @param param2 Second action parameter (usually the item).
93 functag MenuHandler public(Handle:menu, MenuAction:action, param1, param2);
96 * Creates a new, empty menu using the default style.
98 * @param handler Function which will receive menu actions.
99 * @param actions Optionally set which actions to receive. Select,
100 * Cancel, and End will always be received regardless
101 * of whether they are set or not. They are also
102 * the only default actions.
103 * @return A new menu Handle.
105 native Handle:CreateMenu(MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
108 * Displays a menu to a client.
110 * @param menu Menu Handle.
111 * @param client Client index.
112 * @param time Maximum time to leave menu on the screen.
113 * @return True on success, false on failure.
114 * @error Invalid Handle or client not in game.
116 native bool:DisplayMenu(Handle:menu, client, time);
119 * Appends a new item to the end of a menu.
121 * @param menu Menu Handle.
122 * @param info Item information string.
123 * @param display Default item display string.
124 * @param style Drawing style flags.
125 * @return True on success, false on failure.
126 * @error Invalid Handle or item limit reached.
128 native AddMenuItem(Handle:menu,
130 const String:display[],
131 style=ITEMDRAW_DEFAULT);
134 * Inserts an item into the menu before a certain position; the new item will
135 * be at the given position and all next items pushed forward.
137 * @param menu Menu Handle.
138 * @param position Position, starting from 0.
139 * @param info Item information string.
140 * @param display Default item display string.
141 * @param style Drawing style flags.
142 * @return True on success, false on failure.
143 * @error Invalid Handle or menu position.
145 native bool:InsertMenuItem(Handle:menu,
148 const String:display[],
149 style=ITEMDRAW_DEFAULT);
152 * Removes an item from the menu.
154 * @param menu Menu Handle.
155 * @param position Position, starting from 0.
156 * @return True on success, false on failure.
157 * @error Invalid Handle or menu position.
159 native bool:RemoveMenuItem(Handle:menu, position);
162 * Removes all items from a menu.
164 * @param menu Menu Handle.
166 * @error Invalid Handle or menu position.
168 native RemoveAllMenuItems(Handle:menu);
171 * Retrieves information about a menu item.
173 * @param menu Menu Handle.
174 * @param position Position, starting from 0.
175 * @param infoBuf Info buffer.
176 * @param infoBufLen Maximum length of the info buffer.
177 * @param style By-reference variable to store drawing flags.
178 * @param dispBuf Display buffer.
179 * @param dispBufLen Maximum length of the display buffer.
180 * @return True on success, false if position is invalid.
181 * @error Invalid Handle.
183 native bool:GetMenuItem(Handle:menu, position, String:infoBuf[], infoBufLen, &style=0, String:dispBuf[]="", dispBufLen=0);
186 * Returns the number of items in a menu.
188 * @param menu Menu Handle.
189 * @return Number of items in the menu.
190 * @error Invalid Handle.
192 native GetMenuItemCount(Handle:menu);
195 * Sets whether the menu should be paginated or not.
197 * @param menu Handle to the menu.
198 * @param itemsPerPage Number of items per page, or MENU_NO_PAGINATION.
199 * @return True on success, false if pagination is too high or low.
200 * @error Invalid Handle.
202 native bool:SetMenuPagination(Handle:menu, itemsPerPage);
205 * Returns a menu's pagination setting.
207 * @param menu Handle to the menu.
208 * @return Pagination setting.
209 * @error Invalid Handle.
211 native GetMenuPagination(Handle:menu);
214 * Returns a menu's MenuStyle Handle. The Handle
215 * is global and cannot be freed.
217 * @param menu Handle to the menu.
218 * @return Handle to the menu's draw style.
219 * @error Invalid Handle.
221 native Handle:GetMenuStyle(Handle:menu);
224 * Sets the menu's default title/instruction message.
226 * @param menu Menu Handle.
227 * @param fmt Message string format
228 * @param ... Message string arguments.
230 * @error Invalid Handle.
232 native SetMenuTitle(Handle:menu, const String:fmt[], any:...);
235 * Creates a raw MenuPanel based off the menu's style.
236 * The Handle must be freed with CloseHandle().
238 * @return A new MenuPanel Handle.
239 * @error Invalid Handle.
241 native Handle:CreatePanelFromMenu(Handle:menu);
244 * Returns whether or not the menu has an exit button.
245 * By default, menus have an exit button.
247 * @param menu Menu Handle.
248 * @return True if the menu has an exit button; false otherwise.
249 * @error Invalid Handle.
251 native bool:GetMenuExitButton(Handle:menu);
254 * Sets whether or not the menu has an exit button.
255 * By default, menus have an exit button.
257 * @param menu Menu Handle.
258 * @param button True to enable the button, false to remove it.
259 * @return True if allowed; false on failure.
260 * @error Invalid Handle.
262 native bool:SetMenuExitButton(Handle:menu, bool:button);
265 * Cancels a menu from displaying on all clients. While the
266 * cancellation is in progress, this menu cannot be re-displayed
269 * The menu may still exist on the client's screen after this command.
270 * This simply verifies that the menu is not being used anywhere.
272 * If any vote is in progress on a menu, it will be cancelled.
274 * @param menu Menu Handle.
276 * @error Invalid Handle.
278 native CancelMenu(Handle:menu);
281 * Returns whether a vote is in progress on the given menu.
283 * @param menu Menu Handle.
284 * @return True if a vote is in progress, false otherwise.
286 native bool:IsVoteInProgress(Handle:menu);
289 * Broadcasts a menu to a list of clients. The most selected item will be
290 * returned through MenuAction_End. On a tie, a random item will be returned
291 * from a list of the tied items.
293 * Note that MenuAction_VoteEnd and MenuAction_VoteStart are both
294 * default callbacks and do not need to be enabled.
296 * @param menu Menu Handle.
297 * @param clients Array of clients to broadcast to.
298 * @param numClients Number of clients in the array.
299 * @param time Maximum time to leave menu on the screen.
300 * @return True on success, false if this menu already has a vote session
302 * @error Invalid Handle.
304 native bool:VoteMenu(Handle:menu, clients[], numClients, time);
307 * Sends a vote menu to all clients. See VoteMenu() for more information.
309 * @param menu Menu Handle.
310 * @param time Maximum time to leave menu on the screen.
311 * @return True on success, false if this menu already has a vote session
313 * @error Invalid Handle.
315 stock VoteMenuToAll(Handle:menu, time)
317 new num = GetMaxClients();
321 for (new i=1; i<=num; i++)
323 if (!IsClientConnected(i))
327 players[total++] = i;
330 return VoteMenu(menu, players, total, time);
334 * Returns a style's global Handle.
336 * @param style Menu Style.
337 * @return A Handle, or INVALID_HANDLE if not found or unusable.
339 native Handle:GetMenuStyleHandle(MenuStyle:style);
342 * Creates a MenuPanel from a MenuStyle. Panels are used for drawing raw
343 * menus without any extra helper functions. The Handle must be closed
344 * with CloseHandle().
346 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
347 * @return A new MenuPanel Handle.
348 * @error Invalid Handle other than INVALID_HANDLE.
350 native Handle:CreatePanel(Handle:hStyle=INVALID_HANDLE);
353 * Creates a Menu from a MenuStyle. The Handle must be closed with
356 * @parma hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
357 * @param handler Function which will receive menu actions.
358 * @param actions Optionally set which actions to receive. Select,
359 * Cancel, and End will always be received regardless
360 * of whether they are set or not. They are also
361 * the only default actions.
362 * @return A new menu Handle.
363 * @error Invalid Handle other than INVALID_HANDLE.
365 native Handle:CreateMenuEx(Handle:hStyle=INVALID_HANDLE, MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
368 * Returns whether a client is viewing a menu. If the menu source
369 * is MenuSource_Normal, a menu Handle will also be returned.
371 * @param client Client index.
372 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
373 * @return A MenuSource value.
374 * @error Invalid Handle other than INVALID_HANDLE.
376 native MenuSource:GetClientMenu(client, Handle:hStyle=INVALID_HANDLE);
379 * Cancels a menu on a client. This will only affect non-external menus.
381 * @param hstyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
382 * @param client Client index.
383 * @param autoIgnore If true, no menus can be re-drawn on the client during
384 * the cancellation process.
385 * @return True if a menu was cancelled, false otherwise.
387 native bool:CancelClientMenu(client, bool:autoIgnore=false, Handle:hStyle=INVALID_HANDLE);
390 * Returns a style's maximum items per page.
392 * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
393 * @return Maximum items per page.
394 * @error Invalid Handle other than INVALID_HANDLE.
396 native GetMaxPageItems(Handle:hStyle=INVALID_HANDLE);
399 * Returns a MenuPanel's parent style.
401 * @param panel A MenuPanel Handle.
402 * @return The MenuStyle Handle that created the panel.
403 * @error Invalid Handle.
405 native Handle:GetPanelStyle(Handle:panel);
408 * Sets the panel's title.
410 * @param panel A MenuPanel Handle.
411 * @param title Text to set as the title.
412 * @param onlyIfEmpty If true, the title will only be set if no title is set.
414 * @error Invalid Handle.
416 native Handle:SetPanelTitle(Handle:panel, const String:text[], bool:onlyIfEmpty=false);
419 * Draws an item on a panel. If the item takes up a slot, the position
422 * @param panel A MenuPanel Handle.
423 * @param text Display text to use. If not a raw line,
424 * the style may automatically add color markup.
425 * No numbering or newlines are needed.
426 * @param style ITEMDRAW style flags.
427 * @return A slot position, or 0 if item was a rawline or could not be drawn.
428 * @error Invalid Handle.
430 native DrawPanelItem(Handle:panel, const String:text[], style=ITEMDRAW_DEFAULT);
433 * Draws a raw line of text on a panel, without any markup other than a newline.
435 * @param panel A MenuPanel Handle.
436 * @param text Display text to use.
437 * @return True on success, false if raw lines are not supported.
438 * @error Invalid Handle.
440 native DrawPanelText(Handle:panel, const String:text[]);
443 * Returns whether or not the given drawing flags are supported by
446 * @param panel A MenuPanel Handle.
447 * @param style ITEMDRAW style flags.
448 * @return True if item is drawable, false otherwise.
449 * @error Invalid Handle.
451 native CanPanelDrawFlags(Handle:panel, style);
454 * Sets the selectable key map of a panel. This is not supported by
455 * all styles (only by Radio, as of this writing).
457 * @param keys An integer where each bit N allows key
458 * N+1 to be selected. If no keys are selectable,
459 * then key 0 (bit 9) is automatically set.
460 * @return True if supported, false otherwise.
462 native bool:SetPanelKeys(Handle:panel, keys);
465 * Sends a panel to a client. Unlike full menus, the handler
466 * function will only receive the following actions, both of
467 * which will have INVALID_HANDLE for a menu, and the client
470 * MenuAction_Select (param2 will be the key pressed)
471 * MenuAction_Cancel (param2 will be the reason)
473 * Also, if the menu fails to display, no callbacks will be called.
475 * @param panel A MenuPanel Handle.
476 * @param client A client to draw to.
477 * @param handler The MenuHandler function to catch actions with.
478 * @param time Time to hold the menu for.
479 * @return True on success, false on failure.
480 * @error Invalid Handle.
482 native bool:SendPanelToClient(Handle:panel, client, MenuHandler:handler, time);
485 * @brief Returns the current key position.
487 * @param panel A MenuPanel Handle.
488 * @return Current key position starting at 1.
489 * @error Invalid Handle.
491 native GetPanelCurrentKey(Handle:panel);
494 * @brief Sets the next key position. This cannot be used
495 * to traverse backwards.
497 * @param panel A MenuPanel Handle.
498 * @param key Key that is greater or equal to
499 * GetPanelCurrentKey().
500 * @return True on success, false otherwise.
501 * @error Invalid Handle.
503 native bool:SetPanelCurrentKey(Handle:panel, key);