3 * ===============================================================
4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ===============================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SOURCEMOD_MENU_SYSTEM_H_
20 #define _INCLUDE_SOURCEMOD_MENU_SYSTEM_H_
22 #include <IShareSys.h>
24 #define SMINTERFACE_MENUMANAGER_NAME "IMenuManager"
25 #define SMINTERFACE_MENUMANAGER_VERSION 1
28 * @file IMenuManager.h
29 * @brief Abstracts on-screen menus for clients.
35 * @brief Used to determine how an item selection is interpreted.
39 ItemSel_None, /**< Invalid selection */
40 ItemSel_Back, /**< Go back one page */
41 ItemSel_Next, /**< Go forward one page */
42 ItemSel_Exit, /**< Menu was exited */
43 ItemSel_Item, /**< Valid item selection */
47 * @brief Used to determine which order to search for items in.
51 ItemOrder_Ascending, /**< Items should be drawn ascendingly */
52 ItemOrder_Descending, /**< Items should be drawn descendingly */
56 * @brief Pairs an item type with an item menu position.
60 ItemSelection type; /**< Item selection type */
61 unsigned int item; /**< Item position, if applicable */
69 * @brief Describes menu display information.
73 unsigned int apiVers; /**< Must be filled with the API version */
74 IBaseMenu *menu; /**< Menu pointer, or NULL if there is only a display */
75 IMenuHandler *mh; /**< Menu callbacks handler */
76 unsigned int firstItem; /**< MENU ONLY: First item displayed on the last page */
77 unsigned int lastItem; /**< MENU ONLY: Last item displayed on the last page */
78 menu_slots_t slots[11]; /**< MENU ONLY: Item selection table (first index is 1) */
81 #define ITEMDRAW_DEFAULT (0) /**< Item should be drawn normally */
82 #define ITEMDRAW_DISABLED (1<<0) /**< Item is drawn but not selectable */
83 #define ITEMDRAW_RAWLINE (1<<1) /**< Item should be a raw line, without a slot */
84 #define ITEMDRAW_NOTEXT (1<<2) /**< No text should be drawn */
85 #define ITEMDRAW_SPACER (1<<3) /**< Item should be drawn as a spacer, if possible */
86 #define ITEMDRAW_IGNORE ((1<<1)|(1<<2)) /**< Item should be completely ignored (rawline + notext) */
87 #define ITEMDRAW_CONTROL (1<<4) /**< Item is control text (back/next/exit) */
90 * @brief Information about item drawing.
99 ItemDrawInfo(const char *DISPLAY, unsigned int STYLE=ITEMDRAW_DEFAULT)
100 : display(DISPLAY), style(STYLE)
103 const char *display; /**< Display text (NULL for none) */
104 unsigned int style; /**< ITEMDRAW style flags */
108 * @brief Reasons for a menu dying.
110 enum MenuCancelReason
112 MenuCancel_Disconnect = -1, /**< Client dropped from the server */
113 MenuCancel_Interrupt = -2, /**< Client was interrupted with another menu */
114 MenuCancel_Exit = -3, /**< Client selected "exit" on a paginated menu */
115 MenuCancel_NoDisplay = -4, /**< Menu could not be displayed to the client */
118 #define MENU_NO_PAGINATION 0 /**< Menu should not be paginated (10 items max) */
119 #define MENU_TIME_FOREVER 0 /**< Menu should be displayed as long as possible */
122 * @brief Extended menu options.
126 MenuOption_IntroMessage, /**< CONST CHAR *: Valve menus only; defaults to:
127 "You have a menu, hit ESC"
129 MenuOption_IntroColor, /**< INT[4]: Valve menus only; specifies the intro message colour
130 using R,G,B,A (defaults to 255,0,0,255)
132 MenuOption_Priority, /**< INT *: Valve menus only; priority (less is higher) */
136 * @brief Describes the menu a player is viewing.
140 MenuSource_None = 0, /**< No menu is being displayed */
141 MenuSource_External = 1, /**< External menu, no pointer */
142 MenuSource_BaseMenu = 2, /**< An IBaseMenu pointer. */
143 MenuSource_Display = 3, /**< IMenuPanel source, no pointer */
149 * @brief Sets how a raw menu should be drawn.
155 * @brief Returns the parent IMenuStyle pointer.
157 * @return IMenuStyle pointer which created
160 virtual IMenuStyle *GetParentStyle() =0;
163 * @brief Resets/clears the cached display text.
165 virtual void Reset() =0;
168 * @brief Sets how the title should be drawn.
170 * @param text Text string to display for the title.
171 * @param onlyIfEmpty Only sets the title if one does not already
174 virtual void DrawTitle(const char *text, bool onlyIfEmpty=false) =0;
177 * @brief Adds an item to the menu and returns the position (1-10).
179 * Note: Item will fail to draw if there are too many items,
180 * or the item is not drawable (for example, invisible).
182 * @return Item draw position, or 0 on failure.
184 virtual unsigned int DrawItem(const ItemDrawInfo &item) =0;
187 * @brief Draws a raw line of text, if supported. The line does not
188 * need to be newline terminated.
190 * @return True on success, false if not supported.
192 virtual bool DrawRawLine(const char *rawline) =0;
195 * @brief Sets an extended menu option.
197 * @param option Option type.
198 * @param valuePtr Pointer of the type expected by the option.
199 * @return True on success, false if option or value is not supported.
201 virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
204 * @brief Returns whether the display is capable of rendering an item
205 * with the given flags.
207 * @param flags ITEMDRAW flags.
208 * @return True if renderable, false otherwise.
210 virtual bool CanDrawItem(unsigned int drawFlags) =0;
213 * @brief Sends the menu display to a client.
215 * @param client Client index to display to.
216 * @param handler Menu handler to use.
217 * @param time Time to hold menu for.
218 * @return True on success, false otherwise.
220 virtual bool SendDisplay(int client, IMenuHandler *handler, unsigned int time) =0;
223 * @brief Destroys the display object.
225 virtual void DeleteThis() =0;
229 * @brief Describes a "MenuStyle" system which manages
230 * menu drawing and construction.
236 * @brief Returns the style API version.
238 * @return API version.
240 virtual unsigned int GetStyleAPIVersion()
242 return SMINTERFACE_MENUMANAGER_VERSION;
246 * @brief Returns the name of the menu style.
248 * @return String containing the style name.
250 virtual const char *GetStyleName() =0;
253 * @brief Creates an IMenuPanel object.
255 * Note: the object should be freed using ::DeleteThis.
257 * @return IMenuPanel object.
259 virtual IMenuPanel *CreatePanel() =0;
262 * @brief Creates an IBaseMenu object of this style.
264 * Note: the object should be freed using IBaseMenu::Destroy.
266 * @return An IBaseMenu pointer.
268 virtual IBaseMenu *CreateMenu() =0;
271 * @brief Returns the maximum number of items per page.
273 * @return Number of items per page.
275 virtual unsigned int GetMaxPageItems() =0;
278 * @brief Returns whether or not a client is viewing a menu.
280 * @param client Client index.
281 * @param object Optional pointer to retrieve menu object,
283 * @return MenuSource value.
285 virtual MenuSource GetClientMenu(int client, void **object) =0;
288 * @brief Cancels a client's menu.
290 * @param client Client index.
291 * @param autoIgnore If true, no menus can be created during
292 * the cancellation process.
293 * @return True if a menu was cancelled, false otherwise.
295 virtual bool CancelClientMenu(int client, bool autoIgnore=false) =0;
299 * @brief High-level interface for building menus.
305 * @brief Appends an item to the end of a menu.
307 * @param info Item information string.
308 * @param draw Default drawing information.
309 * @return True on success, false on item limit reached.
311 virtual bool AppendItem(const char *info, const ItemDrawInfo &draw) =0;
314 * @brief Inserts an item into the menu before a certain position;
315 * the new item will be at the given position and all next items
318 * @param position Position, starting from 0.
319 * @param info Item information string.
320 * @param draw Default item draw info.
321 * @return True on success, false on invalid menu position
323 virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw) =0;
326 * @brief Removes an item from the menu.
328 * @param position Position, starting from 0.
329 * @return True on success, false on invalid menu position.
331 virtual bool RemoveItem(unsigned int position) =0;
334 * @brief Removes all items from the menu.
336 virtual void RemoveAllItems() =0;
339 * @brief Returns an item's info.
341 * @param position Position, starting from 0.
342 * @param draw Optional pointer to store a draw information.
343 * @return Info string pointer, or NULL if position was invalid.
345 virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw) =0;
348 * @brief Returns the number of items.
350 * @return Number of items in the menu.
352 virtual unsigned int GetItemCount() =0;
355 * @brief Sets the menu's pagination,.
357 * @param itemsPerPage Number of items per page, or MENU_NO_PAGINATION.
358 * @return True on success, false if itemsPerPage is too large.
360 virtual bool SetPagination(unsigned int itemsPerPage) =0;
363 * @brief Returns an item's pagination.
365 * @return Pagination setting.
367 virtual unsigned int GetPagination() =0;
370 * @brief Returns the menu style.
372 * @return Menu style.
374 virtual IMenuStyle *GetDrawStyle() =0;
377 * @brief Sets the menu's display title/message.
379 * @param message Message (format options allowed).
381 virtual void SetDefaultTitle(const char *message) =0;
384 * @brief Returns the menu's display/title message.
386 * @return Message string.
388 virtual const char *GetDefaultTitle() =0;
391 * @brief Sets an extended menu option.
393 * @param option Option type.
394 * @param valuePtr Pointer of the type expected by the option.
395 * @return True on success, false if option or value is not supported.
397 virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
400 * @brief Creates a new IMenuPanel object using extended options specific
401 * to the IMenuStyle parent. Titles, items, etc, are not copied.
403 * Note: The object should be freed with IMenuPanel::DeleteThis.
405 * @return IMenuPanel pointer.
407 virtual IMenuPanel *CreatePanel() =0;
410 * @brief Returns whether or not the menu should have an "Exit" button for
413 * @return True to have an exit button, false otherwise.
415 virtual bool GetExitButton() =0;
418 * @brief Sets whether or not the menu should have an "Exit" button for
421 * @param set True to enable, false to disable the exit button.
422 * @return True on success, false if the exit button is
425 virtual bool SetExitButton(bool set) =0;
428 * @brief Sends the menu to a client.
430 * @param client Client index to display to.
431 * @param handler Menu handler to use.
432 * @param time Time to hold menu for.
433 * @return True on success, false otherwise.
435 virtual bool Display(int client, IMenuHandler *handler, unsigned int time) =0;
438 * @brief Destroys the menu and frees all associated resources.1
440 virtual void Destroy() =0;
443 * @brief Cancels the menu on all client's displays. While the menu is
444 * being cancelled, the menu may not be re-displayed to any clients.
446 * @return Number of menus cancelled.
448 virtual void Cancel() =0;
452 * @brief Contains callbacks for menu actions.
458 * @brief Returns the menu api verison.
460 * @return Menu API version.
462 virtual unsigned int GetMenuAPIVersion2()
464 return SMINTERFACE_MENUMANAGER_VERSION;
468 * @brief A display/selection cycle has started.
470 * @param menu Menu pointer.
472 virtual void OnMenuStart(IBaseMenu *menu)
477 * @brief Called before a menu is being displayed. This is where
478 * you can set an alternate title on the menu.
480 * @param menu Menu pointer.
481 * @param client Client index.
482 * @param display IMenuPanel pointer.
484 virtual void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display)
489 * @brief Called when an item is selected.
491 * @param menu Menu pointer.
492 * @param client Client that selected the item.
493 * @param item Item number.
495 virtual void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
500 * @brief An active menu display was dropped from a client.
502 * @param menu Menu pointer.
503 * @param client Client that had the menu.
504 * @param reason Menu cancellation reason.
506 virtual void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
511 * @brief A display/selection cycle has ended.
513 * @param menu Menu pointer.
515 virtual void OnMenuEnd(IBaseMenu *menu)
520 * @brief Called when requesting how to render an item.
522 * @param menu Menu pointer.
523 * @param client Client index receiving the menu.
524 * @param item Item number in the menu.
525 * @param style ITEMSTYLE flags, by reference for modification.
527 virtual void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style)
532 * @brief Called when requesting how to draw an item's text.
534 * @param menu Menu pointer.
535 * @param client Client index receiving the menu.
536 * @param item Item number in the menu.
537 * @param display Pointer to the display text string (changeable).
539 virtual void OnMenuDisplayItem(IBaseMenu *menu, int client, unsigned int item, const char **display)
545 * @brief Handles a vote menu.
547 class IMenuVoteHandler : public IMenuHandler
551 * @brief Called when a vote ends.
553 * @param menu Menu pointer.
554 * @param item Item position that was chosen by a majority.
556 virtual void OnMenuVoteEnd(IBaseMenu *menu, unsigned int item) =0;
560 * @brief Manages menu creation and displaying.
562 class IMenuManager : public SMInterface
565 virtual const char *GetInterfaceName()
567 return SMINTERFACE_MENUMANAGER_NAME;
569 virtual unsigned int GetInterfaceVersion()
571 return SMINTERFACE_MENUMANAGER_VERSION;
575 * @brief Finds a style by name.
577 * @param name Name of the style (case insensitive).
578 * @return IMenuStyle pointer, or NULL if not found.
580 virtual IMenuStyle *FindStyleByName(const char *name) =0;
583 * @brief Broadcasts a menu to a number of clients.
585 * @param menu Menu pointer.
586 * @param handler IMenuHandler pointer.
587 * @param clients Array of client indexes.
588 * @param numClients Number of clients in the array.
589 * @param time Time to hold the menu.
590 * @return Number of clients the menu will be waiting on.
592 virtual unsigned int BroadcastMenu(IBaseMenu *menu,
593 IMenuHandler *handler,
595 unsigned int numClients,
596 unsigned int time) =0;
599 * @brief Broadcasts a menu to a number of clients as a vote menu.
601 * @param menu Menu pointer.
602 * @param handler IMenuHandler pointer.
603 * @param clients Array of client indexes.
604 * @param numClients Number of clients in the array.
605 * @param time Time to hold the menu.
606 * @return Number of clients the menu will be waiting on.
608 virtual unsigned int VoteMenu(IBaseMenu *menu,
609 IMenuVoteHandler *handler,
611 unsigned int numClients,
612 unsigned int time) =0;
615 * @brief Returns the default draw style Core is using.
617 * @return Menu style pointer.
619 virtual IMenuStyle *GetDefaultStyle() =0;
622 * @brief Given a set of menu states, converts it to an IDisplay object.
624 * The state parameter is both INPUT and OUTPUT.
625 * INPUT: menu, mh, firstItem, lastItem
626 * OUTPUT: display, firstItem, lastItem, slots
628 * @param client Client index.
629 * @param states Menu states.
630 * @return IDisplay pointer, or NULL if no items could be
631 * found in the IBaseMenu pointer, or NULL if any
632 * other error occurred. Any valid pointer must
633 * be freed using IMenuPanel::DeleteThis.
635 virtual IMenuPanel *RenderMenu(int client, menu_states_t &states, ItemOrder order) =0;
639 #endif //_INCLUDE_SOURCEMOD_MENU_SYSTEM_H_