1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/include/menus.inc Mon May 14 04:46:06 2007 +0000
1.3 @@ -0,0 +1,500 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * ===============================================================
1.7 + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
1.8 + * ===============================================================
1.9 + *
1.10 + * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
1.11 + * or modified under the Terms and Conditions of its License Agreement, which is found
1.12 + * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
1.13 + * may change at any time. To view the latest information, see:
1.14 + * http://www.sourcemod.net/license.php
1.15 + *
1.16 + * Version: $Id$
1.17 + */
1.18 +
1.19 +#if defined _menus_included
1.20 + #endinput
1.21 +#endif
1.22 +#define _menus_included
1.23 +
1.24 +/**
1.25 + * Low-level drawing style of the menu.
1.26 + */
1.27 +enum MenuStyle
1.28 +{
1.29 + MenuStyle_Default = 0, /**< The "default" menu style for the mod */
1.30 + MenuStyle_Valve = 1, /**< The Valve provided menu style (Used on HL2DM) */
1.31 + MenuStyle_Radio = 2, /**< The simpler menu style commonly used on CS:S */
1.32 +};
1.33 +
1.34 +/**
1.35 + * Different actions for the menu "pump" callback
1.36 + */
1.37 +enum MenuAction
1.38 +{
1.39 + MenuAction_Start = (1<<0), /**< A menu has been started (nothing passed) */
1.40 + MenuAction_Display = (1<<1), /**< A menu is about to be displayed (param1=client, param2=MenuPanel Handle) */
1.41 + MenuAction_Select = (1<<2), /**< An item was selected (param1=client, param2=item) */
1.42 + MenuAction_Cancel = (1<<3), /**< The menu was cancelled (param1=client, param2=item) */
1.43 + MenuAction_End = (1<<4), /**< A menu's display/selection cycle is complete (nothing passed). */
1.44 + MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has ended (param1=chosen item) */
1.45 +};
1.46 +
1.47 +/** Default menu actions */
1.48 +#define MENU_ACTIONS_DEFAULT MenuAction_Select|MenuAction_Cancel|MenuAction_End
1.49 +/** All menu actions */
1.50 +#define MENU_ACTIONS_ALL -1
1.51 +
1.52 +#define MENU_NO_PAGINATION 0 /**< Menu should not be paginated (10 items max) */
1.53 +#define MENU_TIME_FOREVER 0 /**< Menu should be displayed as long as possible */
1.54 +
1.55 +#define ITEMDRAW_DEFAULT (0) /**< Item should be drawn normally */
1.56 +#define ITEMDRAW_DISABLED (1<<0) /**< Item is drawn but not selectable */
1.57 +#define ITEMDRAW_RAWLINE (1<<1) /**< Item should be a raw line, without a slot */
1.58 +#define ITEMDRAW_NOTEXT (1<<2) /**< No text should be drawn */
1.59 +#define ITEMDRAW_SPACER (1<<3) /**< Item should be drawn as a spacer, if possible */
1.60 +#define ITEMDRAW_IGNORE ((1<<1)|(1<<2)) /**< Item should be completely ignored (rawline + notext) */
1.61 +#define ITEMDRAW_CONTROL (1<<4) /**< Item is control text (back/next/exit) */
1.62 +
1.63 +/**
1.64 + * Reasons a menu can be cancelled.
1.65 + */
1.66 +enum
1.67 +{
1.68 + MenuCancel_Disconnect = -1, /**< Client dropped from the server */
1.69 + MenuCancel_Interrupt = -2, /**< Client was interrupted with another menu */
1.70 + MenuCancel_Exit = -3, /**< Client selected "exit" on a paginated menu */
1.71 + MenuCancel_NoDisplay = -4, /**< Menu could not be displayed to the client */
1.72 +};
1.73 +
1.74 +/**
1.75 + * Describes a menu's source
1.76 + */
1.77 +enum MenuSource
1.78 +{
1.79 + MenuSource_None = 0, /**< No menu is being displayed */
1.80 + MenuSource_External = 1, /**< External menu */
1.81 + MenuSource_Normal = 2, /**< A basic menu is being displayed */
1.82 + MenuSource_RawPanel = 3, /**< A display is active, but it is not tied to a menu */
1.83 +};
1.84 +
1.85 +/**
1.86 + * Called when a menu action is completed.
1.87 + *
1.88 + * @param menu The menu being acted upon.
1.89 + * @param action The action of the menu.
1.90 + * @param param1 First action parameter (usually the client).
1.91 + * @param param2 Second action parameter (usually the item).
1.92 + * @noreturn
1.93 + */
1.94 +functag MenuHandler public(Handle:menu, MenuAction:action, param1, param2);
1.95 +
1.96 +/**
1.97 + * Creates a new, empty menu using the default style.
1.98 + *
1.99 + * @param handler Function which will receive menu actions.
1.100 + * @param actions Optionally set which actions to receive. Select,
1.101 + * Cancel, and End will always be received regardless
1.102 + * of whether they are set or not. They are also
1.103 + * the only default actions.
1.104 + * @return A new menu Handle.
1.105 + */
1.106 +native Handle:CreateMenu(MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
1.107 +
1.108 +/**
1.109 + * Displays a menu to a client.
1.110 + *
1.111 + * @param menu Menu Handle.
1.112 + * @param client Client index.
1.113 + * @param time Maximum time to leave menu on the screen.
1.114 + * @return True on success, false on failure.
1.115 + * @error Invalid Handle or client not in game.
1.116 + */
1.117 +native bool:DisplayMenu(Handle:menu, client, time);
1.118 +
1.119 +/**
1.120 + * Appends a new item to the end of a menu.
1.121 + *
1.122 + * @param menu Menu Handle.
1.123 + * @param info Item information string.
1.124 + * @param display Default item display string.
1.125 + * @param style Drawing style flags.
1.126 + * @return True on success, false on failure.
1.127 + * @error Invalid Handle or item limit reached.
1.128 + */
1.129 +native AddMenuItem(Handle:menu,
1.130 + const String:info[],
1.131 + const String:display[],
1.132 + style=ITEMDRAW_DEFAULT);
1.133 +
1.134 +/**
1.135 + * Inserts an item into the menu before a certain position; the new item will
1.136 + * be at the given position and all next items pushed forward.
1.137 + *
1.138 + * @param menu Menu Handle.
1.139 + * @param position Position, starting from 0.
1.140 + * @param info Item information string.
1.141 + * @param display Default item display string.
1.142 + * @param style Drawing style flags.
1.143 + * @return True on success, false on failure.
1.144 + * @error Invalid Handle or menu position.
1.145 + */
1.146 +native bool:InsertMenuItem(Handle:menu,
1.147 + position,
1.148 + const String:info[],
1.149 + const String:display[],
1.150 + style=ITEMDRAW_DEFAULT);
1.151 +
1.152 +/**
1.153 + * Removes an item from the menu.
1.154 + *
1.155 + * @param menu Menu Handle.
1.156 + * @param position Position, starting from 0.
1.157 + * @return True on success, false on failure.
1.158 + * @error Invalid Handle or menu position.
1.159 + */
1.160 +native bool:RemoveMenuItem(Handle:menu, position);
1.161 +
1.162 +/**
1.163 + * Removes all items from a menu.
1.164 + *
1.165 + * @param menu Menu Handle.
1.166 + * @noreturn
1.167 + * @error Invalid Handle or menu position.
1.168 + */
1.169 +native RemoveAllMenuItems(Handle:menu);
1.170 +
1.171 +/**
1.172 + * Retrieves information about a menu item.
1.173 + *
1.174 + * @param menu Menu Handle.
1.175 + * @param position Position, starting from 0.
1.176 + * @param infoBuf Info buffer.
1.177 + * @param infoBufLen Maximum length of the info buffer.
1.178 + * @param style By-reference variable to store drawing flags.
1.179 + * @param dispBuf Display buffer.
1.180 + * @param dispBufLen Maximum length of the display buffer.
1.181 + * @return True on success, false if position is invalid.
1.182 + * @error Invalid Handle.
1.183 + */
1.184 +native bool:GetMenuItem(Handle:menu, position, String:infoBuf[], infoBufLen, &style=0, String:dispBuf[]="", dispBufLen=0);
1.185 +
1.186 +/**
1.187 + * Returns the number of items in a menu.
1.188 + *
1.189 + * @param menu Menu Handle.
1.190 + * @return Number of items in the menu.
1.191 + * @error Invalid Handle.
1.192 + */
1.193 +native GetMenuItemCount(Handle:menu);
1.194 +
1.195 +/**
1.196 + * Sets whether the menu should be paginated or not.
1.197 + *
1.198 + * @param menu Handle to the menu.
1.199 + * @param itemsPerPage Number of items per page, or MENU_NO_PAGINATION.
1.200 + * @return True on success, false if pagination is too high or low.
1.201 + * @error Invalid Handle.
1.202 + */
1.203 +native bool:SetMenuPagination(Handle:menu, itemsPerPage);
1.204 +
1.205 +/**
1.206 + * Returns a menu's pagination setting.
1.207 + *
1.208 + * @param menu Handle to the menu.
1.209 + * @return Pagination setting.
1.210 + * @error Invalid Handle.
1.211 + */
1.212 +native GetMenuPagination(Handle:menu);
1.213 +
1.214 +/**
1.215 + * Returns a menu's MenuStyle Handle. The Handle
1.216 + * is global and cannot be freed.
1.217 + *
1.218 + * @param menu Handle to the menu.
1.219 + * @return Handle to the menu's draw style.
1.220 + * @error Invalid Handle.
1.221 + */
1.222 +native Handle:GetMenuStyle(Handle:menu);
1.223 +
1.224 +/**
1.225 + * Sets the menu's default title/instruction message.
1.226 + *
1.227 + * @param menu Menu Handle.
1.228 + * @param fmt Message string format
1.229 + * @param ... Message string arguments.
1.230 + * @noreturn
1.231 + * @error Invalid Handle.
1.232 + */
1.233 +native SetMenuTitle(Handle:menu, const String:fmt[], any:...);
1.234 +
1.235 +/**
1.236 + * Creates a raw MenuPanel based off the menu's style.
1.237 + * The Handle must be freed with CloseHandle().
1.238 + *
1.239 + * @return A new MenuPanel Handle.
1.240 + * @error Invalid Handle.
1.241 + */
1.242 +native Handle:CreatePanelFromMenu(Handle:menu);
1.243 +
1.244 +/**
1.245 + * Returns whether or not the menu has an exit button.
1.246 + * By default, menus have an exit button.
1.247 + *
1.248 + * @param menu Menu Handle.
1.249 + * @return True if the menu has an exit button; false otherwise.
1.250 + * @error Invalid Handle.
1.251 + */
1.252 +native bool:GetMenuExitButton(Handle:menu);
1.253 +
1.254 +/**
1.255 + * Sets whether or not the menu has an exit button.
1.256 + * By default, menus have an exit button.
1.257 + *
1.258 + * @param menu Menu Handle.
1.259 + * @param button True to enable the button, false to remove it.
1.260 + * @return True if allowed; false on failure.
1.261 + * @error Invalid Handle.
1.262 + */
1.263 +native bool:SetMenuExitButton(Handle:menu, bool:button);
1.264 +
1.265 +/**
1.266 + * Cancels a menu from displaying on all clients. While the
1.267 + * cancellation is in progress, this menu cannot be re-displayed
1.268 + * to any clients.
1.269 + *
1.270 + * The menu may still exist on the client's screen after this command.
1.271 + * This simply verifies that the menu is not being used anywhere.
1.272 + *
1.273 + * @param menu Menu Handle.
1.274 + * @noreturn
1.275 + * @error Invalid Handle.
1.276 + */
1.277 +native CancelMenu(Handle:menu);
1.278 +
1.279 +#if 0
1.280 +/**
1.281 + * Broadcasts a menu to a list of clients.
1.282 + *
1.283 + * @param menu Menu Handle.
1.284 + * @param handler MenuHandler callback to receive actions.
1.285 + * @param players Array of players to broadcast to.
1.286 + * @param numPlayers Number of players in the array.
1.287 + * @param time Maximum time to leave menu on the screen.
1.288 + * @return Number of clients that broadcast will wait upon.
1.289 + * @error Invalid Handle.
1.290 + */
1.291 +native BroadcastMenu(Handle:menu, MenuHandler:handler, players[], numPlayers, time);
1.292 +
1.293 +/**
1.294 + * Broadcasts a menu to a list of clients. The most selected
1.295 + * item will be returned through MenuAction_End. On a tie, a random
1.296 + * item will be returned.
1.297 + *
1.298 + * @param menu Menu Handle.
1.299 + * @param handler MenuHandler callback to receive actions.
1.300 + * @param players Array of players to broadcast to.
1.301 + * @param numPlayers Number of players in the array.
1.302 + * @param time Maximum time to leave menu on the screen.
1.303 + * @return Number of clients that vote will wait upon.
1.304 + * @error Invalid Handle.
1.305 + */
1.306 +native VoteMenu(Handle:menu, MenuHandler:handler, players[], numPlayers, time);
1.307 +
1.308 +/**
1.309 + * Broadcasts a menu to all clients.
1.310 + *
1.311 + * @param menu Menu Handle.
1.312 + * @param handler MenuHandler callback to receive actions.
1.313 + * @param time Maximum time to leave menu on the screen.
1.314 + * @return Number of clients that broadcast will wait upon.
1.315 + * @error Invalid Handle.
1.316 + */
1.317 +stock BroadcastMenuToAll(Handle:menu, MenuHandler:handler, time)
1.318 +{
1.319 + new num = GetMaxClients();
1.320 + new total;
1.321 + decl players[num];
1.322 +
1.323 + for (new i=1; i<=num; i++)
1.324 + {
1.325 + if (!IsClientConnected(i))
1.326 + {
1.327 + continue;
1.328 + }
1.329 + players[total++] = i;
1.330 + }
1.331 +
1.332 + return BroadcastMenu(menu, handler, players, total, time);
1.333 +}
1.334 +
1.335 +/**
1.336 + * Broadcasts a menu to all clients. The most selected item will
1.337 + * be returned through MenuAction_End. On a tie, a random item
1.338 + * will be returned.
1.339 + *
1.340 + * @param menu Menu Handle.
1.341 + * @param handler MenuHandler callback to receive actions.
1.342 + * @param time Maximum time to leave menu on the screen.
1.343 + * @return Number of clients that the vote will wait upon.
1.344 + * @error Invalid Handle.
1.345 + */
1.346 +native VoteMenuToAll(Handle:menu, MenuHandler:handler, time)
1.347 +{
1.348 + new num = GetMaxClients();
1.349 + new total;
1.350 + decl players[num];
1.351 +
1.352 + for (new i=1; i<=num; i++)
1.353 + {
1.354 + if (!IsClientConnected(i))
1.355 + {
1.356 + continue;
1.357 + }
1.358 + players[total++] = i;
1.359 + }
1.360 +
1.361 + return VoteMenu(menu, handler, players, total, time);
1.362 +}
1.363 +#endif
1.364 +
1.365 +/**
1.366 + * Returns a style's global Handle.
1.367 + *
1.368 + * @param style Menu Style.
1.369 + * @return A Handle, or INVALID_HANDLE if not found or unusable.
1.370 + */
1.371 +native Handle:GetMenuStyleHandle(MenuStyle:style);
1.372 +
1.373 +/**
1.374 + * Creates a MenuPanel from a MenuStyle. Panels are used for drawing raw
1.375 + * menus without any extra helper functions. The Handle must be closed
1.376 + * with CloseHandle().
1.377 + *
1.378 + * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
1.379 + * @return A new MenuPanel Handle.
1.380 + * @error Invalid Handle other than INVALID_HANDLE.
1.381 + */
1.382 +native Handle:CreatePanel(Handle:hStyle=INVALID_HANDLE);
1.383 +
1.384 +/**
1.385 + * Creates a Menu from a MenuStyle. The Handle must be closed with
1.386 + * CloseHandle().
1.387 + *
1.388 + * @parma hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
1.389 + * @param handler Function which will receive menu actions.
1.390 + * @param actions Optionally set which actions to receive. Select,
1.391 + * Cancel, and End will always be received regardless
1.392 + * of whether they are set or not. They are also
1.393 + * the only default actions.
1.394 + * @return A new menu Handle.
1.395 + * @error Invalid Handle other than INVALID_HANDLE.
1.396 + */
1.397 +native Handle:CreateMenuEx(Handle:hStyle=INVALID_HANDLE, MenuHandler:handler, MenuAction:actions=MENU_ACTIONS_DEFAULT);
1.398 +
1.399 +/**
1.400 + * Returns whether a client is viewing a menu. If the menu source
1.401 + * is MenuSource_Normal, a menu Handle will also be returned.
1.402 + *
1.403 + * @param client Client index.
1.404 + * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
1.405 + * @return A MenuSource value.
1.406 + * @error Invalid Handle other than INVALID_HANDLE.
1.407 + */
1.408 +native MenuSource:GetClientMenu(client, Handle:hStyle=INVALID_HANDLE);
1.409 +
1.410 +/**
1.411 + * Cancels a menu on a client. This will only affect non-external menus.
1.412 + *
1.413 + * @param hstyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
1.414 + * @param client Client index.
1.415 + * @param autoIgnore If true, no menus can be re-drawn on the client during
1.416 + * the cancellation process.
1.417 + * @return True if a menu was cancelled, false otherwise.
1.418 + */
1.419 +native bool:CancelClientMenu(client, bool:autoIgnore=false, Handle:hStyle=INVALID_HANDLE);
1.420 +
1.421 +/**
1.422 + * Returns a style's maximum items per page.
1.423 + *
1.424 + * @param hStyle MenuStyle Handle, or INVALID_HANDLE to use the default style.
1.425 + * @return Maximum items per page.
1.426 + * @error Invalid Handle other than INVALID_HANDLE.
1.427 + */
1.428 +native GetMaxPageItems(Handle:hStyle=INVALID_HANDLE);
1.429 +
1.430 +/**
1.431 + * Returns a MenuPanel's parent style.
1.432 + *
1.433 + * @param panel A MenuPanel Handle.
1.434 + * @return The MenuStyle Handle that created the panel.
1.435 + * @error Invalid Handle.
1.436 + */
1.437 +native Handle:GetPanelStyle(Handle:panel);
1.438 +
1.439 +/**
1.440 + * Sets the panel's title.
1.441 + *
1.442 + * @param panel A MenuPanel Handle.
1.443 + * @param title Text to set as the title.
1.444 + * @param onlyIfEmpty If true, the title will only be set if no title is set.
1.445 + * @noreturn
1.446 + * @error Invalid Handle.
1.447 + */
1.448 +native Handle:SetPanelTitle(Handle:panel, const String:text[], bool:onlyIfEmpty=false);
1.449 +
1.450 +/**
1.451 + * Draws an item on a panel. If the item takes up a slot, the position
1.452 + * is returned.
1.453 + *
1.454 + * @param panel A MenuPanel Handle.
1.455 + * @param text Display text to use. If not a raw line,
1.456 + * the style may automatically add color markup.
1.457 + * No numbering or newlines are needed.
1.458 + * @param style ITEMDRAW style flags.
1.459 + * @return A slot position, or 0 if item was a rawline or could not be drawn.
1.460 + * @error Invalid Handle.
1.461 + */
1.462 +native DrawPanelItem(Handle:panel, const String:text[], style=ITEMDRAW_DEFAULT);
1.463 +
1.464 +/**
1.465 + * Draws a raw line of text on a panel, without any markup other than a newline.
1.466 + *
1.467 + * @param panel A MenuPanel Handle.
1.468 + * @param text Display text to use.
1.469 + * @return True on success, false if raw lines are not supported.
1.470 + * @error Invalid Handle.
1.471 + */
1.472 +native DrawPanelText(Handle:panel, const String:text[]);
1.473 +
1.474 +/**
1.475 + * Returns whether or not the given drawing flags are supported by
1.476 + * the menu style.
1.477 + *
1.478 + * @param panel A MenuPanel Handle.
1.479 + * @param style ITEMDRAW style flags.
1.480 + * @return True if item is drawable, false otherwise.
1.481 + * @error Invalid Handle.
1.482 + */
1.483 +native CanPanelDrawFlags(Handle:panel, style);
1.484 +
1.485 +/**
1.486 + * Sends a panel to a client. Unlike full menus, the handler
1.487 + * function will only receive the following actions, both of
1.488 + * which will have INVALID_HANDLE for a menu, and the client
1.489 + * as param1.
1.490 + *
1.491 + * MenuAction_Select (param2 will be the key pressed)
1.492 + * MenuAction_Cancel (param2 will be the reason)
1.493 + *
1.494 + * Also, if the menu fails to display, no callbacks will be called.
1.495 + *
1.496 + * @param panel A MenuPanel Handle.
1.497 + * @param client A client to draw to.
1.498 + * @param handler The MenuHandler function to catch actions with.
1.499 + * @param time Time to hold the menu for.
1.500 + * @return True on success, false on failure.
1.501 + * @error Invalid Handle.
1.502 + */
1.503 +native bool:SendPanelToClient(Handle:panel, client, MenuHandler:handler, time);