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>
23 #include <IHandleSys.h>
25 #define SMINTERFACE_MENUMANAGER_NAME "IMenuManager"
26 #define SMINTERFACE_MENUMANAGER_VERSION 2
29 * @file IMenuManager.h
30 * @brief Abstracts on-screen menus for clients.
36 * @brief Used to determine how an item selection is interpreted.
40 ItemSel_None, /**< Invalid selection */
41 ItemSel_Back, /**< Go back one page */
42 ItemSel_Next, /**< Go forward one page */
43 ItemSel_Exit, /**< Menu was exited */
44 ItemSel_Item, /**< Valid item selection */
48 * @brief Used to determine which order to search for items in.
52 ItemOrder_Ascending, /**< Items should be drawn ascendingly */
53 ItemOrder_Descending, /**< Items should be drawn descendingly */
57 * @brief Pairs an item type with an item menu position.
61 ItemSelection type; /**< Item selection type */
62 unsigned int item; /**< Item position, if applicable */
70 * @brief Describes menu display information.
74 unsigned int apiVers; /**< Must be filled with the API version */
75 IBaseMenu *menu; /**< Menu pointer, or NULL if there is only a display */
76 IMenuHandler *mh; /**< Menu callbacks handler */
77 unsigned int firstItem; /**< MENU ONLY: First item displayed on the last page */
78 unsigned int lastItem; /**< MENU ONLY: Last item displayed on the last page */
79 menu_slots_t slots[11]; /**< MENU ONLY: Item selection table (first index is 1) */
82 #define ITEMDRAW_DEFAULT (0) /**< Item should be drawn normally */
83 #define ITEMDRAW_DISABLED (1<<0) /**< Item is drawn but not selectable */
84 #define ITEMDRAW_RAWLINE (1<<1) /**< Item should be a raw line, without a slot */
85 #define ITEMDRAW_NOTEXT (1<<2) /**< No text should be drawn */
86 #define ITEMDRAW_SPACER (1<<3) /**< Item should be drawn as a spacer, if possible */
87 #define ITEMDRAW_IGNORE ((1<<1)|(1<<2)) /**< Item should be completely ignored (rawline + notext) */
88 #define ITEMDRAW_CONTROL (1<<4) /**< Item is control text (back/next/exit) */
91 * @brief Information about item drawing.
100 ItemDrawInfo(const char *DISPLAY, unsigned int STYLE=ITEMDRAW_DEFAULT)
101 : display(DISPLAY), style(STYLE)
104 const char *display; /**< Display text (NULL for none) */
105 unsigned int style; /**< ITEMDRAW style flags */
109 * @brief Reasons for a menu dying.
111 enum MenuCancelReason
113 MenuCancel_Disconnect = -1, /**< Client dropped from the server */
114 MenuCancel_Interrupt = -2, /**< Client was interrupted with another menu */
115 MenuCancel_Exit = -3, /**< Client selected "exit" on a paginated menu */
116 MenuCancel_NoDisplay = -4, /**< Menu could not be displayed to the client */
119 #define MENU_NO_PAGINATION 0 /**< Menu should not be paginated (10 items max) */
120 #define MENU_TIME_FOREVER 0 /**< Menu should be displayed as long as possible */
123 * @brief Extended menu options.
127 MenuOption_IntroMessage, /**< CONST CHAR *: Valve menus only; defaults to:
128 "You have a menu, hit ESC"
130 MenuOption_IntroColor, /**< INT[4]: Valve menus only; specifies the intro message colour
131 using R,G,B,A (defaults to 255,0,0,255)
133 MenuOption_Priority, /**< INT *: Valve menus only; priority (less is higher) */
137 * @brief Describes the menu a player is viewing.
141 MenuSource_None = 0, /**< No menu is being displayed */
142 MenuSource_External = 1, /**< External menu, no pointer */
143 MenuSource_BaseMenu = 2, /**< An IBaseMenu pointer. */
144 MenuSource_Display = 3, /**< IMenuPanel source, no pointer */
150 * @brief Sets how a raw menu should be drawn.
156 * @brief Returns the parent IMenuStyle pointer.
158 * @return IMenuStyle pointer which created
161 virtual IMenuStyle *GetParentStyle() =0;
164 * @brief Resets/clears the cached display text.
166 virtual void Reset() =0;
169 * @brief Sets how the title should be drawn.
171 * @param text Text string to display for the title.
172 * @param onlyIfEmpty Only sets the title if one does not already
175 virtual void DrawTitle(const char *text, bool onlyIfEmpty=false) =0;
178 * @brief Adds an item to the menu and returns the position (1-10).
180 * Note: Item will fail to draw if there are too many items,
181 * or the item is not drawable (for example, invisible).
183 * @return Item draw position, or 0 on failure.
185 virtual unsigned int DrawItem(const ItemDrawInfo &item) =0;
188 * @brief Draws a raw line of text, if supported. The line does not
189 * need to be newline terminated.
191 * @return True on success, false if not supported.
193 virtual bool DrawRawLine(const char *rawline) =0;
196 * @brief Sets an extended menu option.
198 * @param option Option type.
199 * @param valuePtr Pointer of the type expected by the option.
200 * @return True on success, false if option or value is not supported.
202 virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
205 * @brief Returns whether the display is capable of rendering an item
206 * with the given flags.
208 * @param flags ITEMDRAW flags.
209 * @return True if renderable, false otherwise.
211 virtual bool CanDrawItem(unsigned int drawFlags) =0;
214 * @brief Sends the menu display to a client.
216 * @param client Client index to display to.
217 * @param handler Menu handler to use.
218 * @param time Time to hold menu for.
219 * @return True on success, false otherwise.
221 virtual bool SendDisplay(int client, IMenuHandler *handler, unsigned int time) =0;
224 * @brief Destroys the display object.
226 virtual void DeleteThis() =0;
229 * @brief Sets the selectable key map. Returns false if the function
232 * @param keys A bit string where each bit N-1 specifies
233 * that key N is selectable (key 0 is bit 9).
234 * If the selectable key map is 0, it will be
235 * automatically set to allow 0.
236 * @return True on success, false if not supported.
238 virtual bool SetSelectableKeys(unsigned int keymap) =0;
241 * @brief Returns the current key position.
243 * @return Current key position starting at 1.
245 virtual unsigned int GetCurrentKey() =0;
248 * @brief Sets the next key position. This cannot be used
249 * to traverse backwards.
251 * @param key Key that is greater or equal to
253 * @return True on success, false otherwise.
255 virtual bool SetCurrentKey(unsigned int key) =0;
259 * @brief Describes a "MenuStyle" system which manages
260 * menu drawing and construction.
266 * @brief Returns the style API version.
268 * @return API version.
270 virtual unsigned int GetStyleAPIVersion()
272 return SMINTERFACE_MENUMANAGER_VERSION;
276 * @brief Returns the name of the menu style.
278 * @return String containing the style name.
280 virtual const char *GetStyleName() =0;
283 * @brief Creates an IMenuPanel object.
285 * Note: the object should be freed using ::DeleteThis.
287 * @return IMenuPanel object.
289 virtual IMenuPanel *CreatePanel() =0;
292 * @brief Creates an IBaseMenu object of this style.
294 * Note: the object should be freed using IBaseMenu::Destroy.
296 * @param handler IMenuHandler pointer.
297 * @param pOwner Optional IdentityToken_t owner for handle
299 * @return An IBaseMenu pointer.
301 virtual IBaseMenu *CreateMenu(IMenuHandler *handler, IdentityToken_t *pOwner=NULL) =0;
304 * @brief Returns the maximum number of items per page.
306 * @return Number of items per page.
308 virtual unsigned int GetMaxPageItems() =0;
311 * @brief Returns whether or not a client is viewing a menu.
313 * @param client Client index.
314 * @param object Optional pointer to retrieve menu object,
316 * @return MenuSource value.
318 virtual MenuSource GetClientMenu(int client, void **object) =0;
321 * @brief Cancels a client's menu.
323 * @param client Client index.
324 * @param autoIgnore If true, no menus can be created during
325 * the cancellation process.
326 * @return True if a menu was cancelled, false otherwise.
328 virtual bool CancelClientMenu(int client, bool autoIgnore=false) =0;
331 * @brief Returns a Handle the IMenuStyle object.
333 * @return Handle_t pointing to this object.
335 virtual Handle_t GetHandle() =0;
339 * @brief High-level interface for building menus.
345 * @brief Appends an item to the end of a menu.
347 * @param info Item information string.
348 * @param draw Default drawing information.
349 * @return True on success, false on item limit reached.
351 virtual bool AppendItem(const char *info, const ItemDrawInfo &draw) =0;
354 * @brief Inserts an item into the menu before a certain position;
355 * the new item will be at the given position and all next items
358 * @param position Position, starting from 0.
359 * @param info Item information string.
360 * @param draw Default item draw info.
361 * @return True on success, false on invalid menu position
363 virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw) =0;
366 * @brief Removes an item from the menu.
368 * @param position Position, starting from 0.
369 * @return True on success, false on invalid menu position.
371 virtual bool RemoveItem(unsigned int position) =0;
374 * @brief Removes all items from the menu.
376 virtual void RemoveAllItems() =0;
379 * @brief Returns an item's info.
381 * @param position Position, starting from 0.
382 * @param draw Optional pointer to store a draw information.
383 * @return Info string pointer, or NULL if position was invalid.
385 virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw) =0;
388 * @brief Returns the number of items.
390 * @return Number of items in the menu.
392 virtual unsigned int GetItemCount() =0;
395 * @brief Sets the menu's pagination,.
397 * @param itemsPerPage Number of items per page, or MENU_NO_PAGINATION.
398 * @return True on success, false if itemsPerPage is too large.
400 virtual bool SetPagination(unsigned int itemsPerPage) =0;
403 * @brief Returns an item's pagination.
405 * @return Pagination setting.
407 virtual unsigned int GetPagination() =0;
410 * @brief Returns the menu style.
412 * @return Menu style.
414 virtual IMenuStyle *GetDrawStyle() =0;
417 * @brief Sets the menu's display title/message.
419 * @param message Message (format options allowed).
421 virtual void SetDefaultTitle(const char *message) =0;
424 * @brief Returns the menu's display/title message.
426 * @return Message string.
428 virtual const char *GetDefaultTitle() =0;
431 * @brief Sets an extended menu option.
433 * @param option Option type.
434 * @param valuePtr Pointer of the type expected by the option.
435 * @return True on success, false if option or value is not supported.
437 virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
440 * @brief Creates a new IMenuPanel object using extended options specific
441 * to the IMenuStyle parent. Titles, items, etc, are not copied.
443 * Note: The object should be freed with IMenuPanel::DeleteThis.
445 * @return IMenuPanel pointer.
447 virtual IMenuPanel *CreatePanel() =0;
450 * @brief Returns whether or not the menu should have an "Exit" button for
453 * @return True to have an exit button, false otherwise.
455 virtual bool GetExitButton() =0;
458 * @brief Sets whether or not the menu should have an "Exit" button for
461 * @param set True to enable, false to disable the exit button.
462 * @return True on success, false if the exit button is
465 virtual bool SetExitButton(bool set) =0;
468 * @brief Sends the menu to a client.
470 * @param client Client index to display to.
471 * @param time Time to hold menu for.
472 * @return True on success, false otherwise.
474 virtual bool Display(int client, unsigned int time) =0;
477 * @brief Destroys the menu and frees all associated resources.
479 * @param releaseHandle If true, the Handle will be released
480 * in the destructor. This should be set
481 * to true except for IHandleTypeDispatch
484 virtual void Destroy(bool releaseHandle=true) =0;
487 * @brief Cancels the menu on all client's displays. While the menu is
488 * being cancelled, the menu may not be re-displayed to any clients.
490 * @return Number of menus cancelled.
492 virtual void Cancel() =0;
495 * @brief Returns the menu's Handle. The Handle is automatically
496 * removed when the menu is destroyed.
498 * @return Handle_t handle value.
500 virtual Handle_t GetHandle() =0;
503 * @brief Sends a menu to multiple clients as a vote menu. All callbacks
504 * will be sent as normal, except two extras, OnMenuVoteStart and
505 * OnMenuVoteEnd, will be called.
507 * @param clients Array of client indexes.
508 * @param numClients Number of client indexes in the array.
509 * @param maxTime Maximum amount of time to hold the vote.
510 * @param flags Optional voting flags (currently unused).
511 * @return True on success, false if a vote is already in
512 * progress (the menu must be cancelled first).
514 virtual bool BroadcastVote(int clients[],
515 unsigned int numClients,
516 unsigned int maxTime,
517 unsigned int flags=0) =0;
521 * @brief Contains callbacks for menu actions.
527 * @brief Returns the menu api verison.
529 * @return Menu API version.
531 virtual unsigned int GetMenuAPIVersion2()
533 return SMINTERFACE_MENUMANAGER_VERSION;
537 * @brief A display/selection cycle has started.
539 * @param menu Menu pointer.
541 virtual void OnMenuStart(IBaseMenu *menu)
546 * @brief Called before a menu is being displayed. This is where
547 * you can set an alternate title on the menu.
549 * @param menu Menu pointer.
550 * @param client Client index.
551 * @param display IMenuPanel pointer.
553 virtual void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display)
558 * @brief Called when an item is selected.
560 * @param menu Menu pointer.
561 * @param client Client that selected the item.
562 * @param item Item number.
564 virtual void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
569 * @brief An active menu display was dropped from a client.
571 * @param menu Menu pointer.
572 * @param client Client that had the menu.
573 * @param reason Menu cancellation reason.
575 virtual void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
580 * @brief A display/selection cycle has ended.
582 * @param menu Menu pointer.
584 virtual void OnMenuEnd(IBaseMenu *menu)
589 * @brief Called when the menu object is destroyed.
591 * @param menu Menu pointer.
593 virtual void OnMenuDestroy(IBaseMenu *menu)
598 * @brief Called when requesting how to render an item.
600 * @param menu Menu pointer.
601 * @param client Client index receiving the menu.
602 * @param item Item number in the menu.
603 * @param style ITEMSTYLE flags, by reference for modification.
605 virtual void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style)
610 * @brief Called when requesting how to draw an item's text.
612 * @param menu Menu pointer.
613 * @param client Client index receiving the menu.
614 * @param item Item number in the menu.
615 * @param display Pointer to the display text string (changeable).
617 virtual void OnMenuDisplayItem(IBaseMenu *menu, int client, unsigned int item, const char **display)
622 * @brief Called when a vote has been started and displayed to
623 * clients. This is called after OnMenuStart() and OnMenuDisplay(),
624 * but before OnMenuSelect().
626 * @param menu Menu pointer.
628 virtual void OnMenuVoteStart(IBaseMenu *menu)
633 * @brief Called when a vote ends. This is automatically called by the
634 * wrapper, and never needs to called from a style implementation.
636 * @param menu Menu pointer.
637 * @param item Item position that was chosen by a majority.
639 virtual void OnMenuVoteEnd(IBaseMenu *menu, unsigned int item)
645 * @brief Contains functions for managing a vote handler.
647 class IVoteMenuHandler : public IMenuHandler
651 * @brief Returns whether or not a vote is in progress.
653 * @return True if a vote is in progress, false otherwise.
655 virtual bool IsVoteInProgress() =0;
658 * @brief Use this to mark the vote as in progress (start).
660 * @param menu Menu pointer.
662 virtual void InitializeVoting(IBaseMenu *menu) =0;
665 * @brief Use this to notify that all clients' displays have been
666 * processed (i.e., there are no more clients to display to).
668 virtual void StartVoting() =0;
672 * @brief Manages menu creation and displaying.
674 class IMenuManager : public SMInterface
677 virtual const char *GetInterfaceName()
679 return SMINTERFACE_MENUMANAGER_NAME;
681 virtual unsigned int GetInterfaceVersion()
683 return SMINTERFACE_MENUMANAGER_VERSION;
687 * @brief Finds a style by name.
689 * @param name Name of the style (case insensitive).
690 * @return IMenuStyle pointer, or NULL if not found.
692 virtual IMenuStyle *FindStyleByName(const char *name) =0;
695 * @brief Returns the default draw style Core is using.
697 * @return Menu style pointer.
699 virtual IMenuStyle *GetDefaultStyle() =0;
702 * @brief Given a set of menu states, converts it to an IDisplay object.
704 * The state parameter is both INPUT and OUTPUT.
705 * INPUT: menu, mh, firstItem, lastItem
706 * OUTPUT: display, firstItem, lastItem, slots
708 * @param client Client index.
709 * @param states Menu states.
710 * @return IDisplay pointer, or NULL if no items could be
711 * found in the IBaseMenu pointer, or NULL if any
712 * other error occurred. Any valid pointer must
713 * be freed using IMenuPanel::DeleteThis.
715 virtual IMenuPanel *RenderMenu(int client, menu_states_t &states, ItemOrder order) =0;
718 * @brief Creates a standard voting wrapper. The wrapper is not
719 * re-entrant; a second menu cannot be displayed on the same handler
722 * @param mh Menu handler to wrap around.
723 * @return An IMenuHandler pointer that is a wrapper
724 * around IMenuHandler callbacks to invoke
725 * voting related callbacks.
727 virtual IVoteMenuHandler *CreateVoteWrapper(IMenuHandler *mh) =0;
730 * @brief Frees a standard voting wrapper.
732 * @param mh Menu handler pointer created by
733 * CreateVoteWrapper(). NULL values will be
736 virtual void ReleaseVoteWrapper(IVoteMenuHandler *mh) =0;
740 #endif //_INCLUDE_SOURCEMOD_MENU_SYSTEM_H_