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) */
89 * @brief Information about item drawing.
98 ItemDrawInfo(const char *DISPLAY, unsigned int STYLE=ITEMDRAW_DEFAULT)
99 : display(DISPLAY), style(STYLE)
102 const char *display; /**< Display text (NULL for none) */
103 unsigned int style; /**< ITEMDRAW style flags */
107 * @brief Reasons for a menu dying.
109 enum MenuCancelReason
111 MenuCancel_Disconnect = -1, /** Client dropped from the server */
112 MenuCancel_Interrupt = -2, /** Client was interrupted with another menu */
113 MenuCancel_Exit = -3, /** Client selected "exit" on a paginated menu */
114 MenuCancel_NoDisplay = -4, /** Menu could not be displayed to the client */
117 #define MENU_NO_PAGINATION 0 /**< Menu should not be paginated (10 items max) */
118 #define MENU_TIME_FOREVER 0 /**< Menu should be displayed as long as possible */
121 * @brief Extended menu options.
125 MenuOption_IntroMessage, /**< CONST CHAR *: Valve menus only; defaults to:
126 "You have a menu, hit ESC"
128 MenuOption_IntroColor, /**< INT[4]: Valve menus only; specifies the intro message colour
129 using R,G,B,A (defaults to 255,0,0,255)
131 MenuOption_Priority, /**< INT *: Valve menus only; priority (less is higher) */
135 * @brief Describes the menu a player is viewing.
139 MenuSource_None = 0, /**< No menu is being displayed */
140 MenuSource_External = 1, /**< External menu, no pointer */
141 MenuSource_BaseMenu = 2, /**< An IBaseMenu pointer. */
142 MenuSource_Display = 3, /**< IMenuDisplay source, no pointer */
148 * @brief Sets how a raw menu should be drawn.
154 * @brief Returns the parent IMenuStyle pointer.
156 * @return IMenuStyle pointer which created
159 virtual IMenuStyle *GetParentStyle() =0;
162 * @brief Resets/clears the cached display text.
164 virtual void Reset() =0;
167 * @brief Sets how the title should be drawn.
169 * @param text Text string to display for the title.
170 * @param onlyIfEmpty Only sets the title if one does not already
173 virtual void DrawTitle(const char *text, bool onlyIfEmpty=false) =0;
176 * @brief Adds an item to the menu and returns the position (1-10).
178 * Note: Item will fail to draw if there are too many items,
179 * or the item is not drawable (for example, invisible).
181 * @return Item draw position, or 0 on failure.
183 virtual unsigned int DrawItem(const ItemDrawInfo &item) =0;
186 * @brief Draws a raw line of text, if supported. The line does not
187 * need to be newline terminated.
189 * @return True on success, false if not supported.
191 virtual bool DrawRawLine(const char *rawline) =0;
194 * @brief Sets an extended menu option.
196 * @param option Option type.
197 * @param valuePtr Pointer of the type expected by the option.
198 * @return True on success, false if option or value is not supported.
200 virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
203 * @brief Returns whether the display is capable of rendering an item
204 * with the given flags.
206 * @param flags ITEMDRAW flags.
207 * @return True if renderable, false otherwise.
209 virtual bool CanDrawItem(unsigned int drawFlags) =0;
212 * @brief Sends the menu display to a client.
214 * @param client Client index to display to.
215 * @param handler Menu handler to use.
216 * @param time Time to hold menu for.
217 * @return True on success, false otherwise.
219 virtual bool SendDisplay(int client, IMenuHandler *handler, unsigned int time) =0;
222 * @brief Destroys the display object.
224 virtual void DeleteThis() =0;
228 * @brief Describes a "MenuStyle" system which manages
229 * menu drawing and construction.
235 * @brief Returns the style API version.
237 * @return API version.
239 virtual unsigned int GetStyleAPIVersion()
241 return SMINTERFACE_MENUMANAGER_VERSION;
245 * @brief Returns the name of the menu style.
247 * @return String containing the style name.
249 virtual const char *GetStyleName() =0;
252 * @brief Creates an IMenuDisplay object.
254 * Note: the object should be freed using ::DeleteThis.
256 * @return IMenuDisplay object.
258 virtual IMenuDisplay *CreateDisplay() =0;
261 * @brief Creates an IBaseMenu object of this style.
263 * Note: the object should be freed using IBaseMenu::Destroy.
265 * @return An IBaseMenu pointer.
267 virtual IBaseMenu *CreateMenu() =0;
270 * @brief Returns the maximum number of items per page.
272 * @return Number of items per page.
274 virtual unsigned int GetMaxPageItems() =0;
277 * @brief Returns whether or not a client is viewing a menu.
279 * @param client Client index.
280 * @param object Optional pointer to retrieve menu object,
282 * @return MenuSource value.
284 virtual MenuSource GetClientMenu(int client, void **object) =0;
287 * @brief Cancels a client's menu.
289 * @param client Client index.
290 * @param autoIgnore If true, no menus can be created during
291 * the cancellation process.
292 * @return True if a menu was cancelled, false otherwise.
294 virtual bool CancelClientMenu(int client, bool autoIgnore=false) =0;
298 * @brief High-level interface for building menus.
304 * @brief Appends an item to the end of a menu.
306 * @param info Item information string.
307 * @param draw Default drawing information.
308 * @return True on success, false on item limit reached.
310 virtual bool AppendItem(const char *info, const ItemDrawInfo &draw) =0;
313 * @brief Inserts an item into the menu before a certain position;
314 * the new item will be at the given position and all next items
317 * @param position Position, starting from 0.
318 * @param info Item information string.
319 * @param draw Default item draw info.
320 * @return True on success, false on invalid menu position
322 virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw) =0;
325 * @brief Removes an item from the menu.
327 * @param position Position, starting from 0.
328 * @return True on success, false on invalid menu position.
330 virtual bool RemoveItem(unsigned int position) =0;
333 * @brief Removes all items from the menu.
335 virtual void RemoveAllItems() =0;
338 * @brief Returns an item's info.
340 * @param position Position, starting from 0.
341 * @param draw Optional pointer to store a draw information.
342 * @return Info string pointer, or NULL if position was invalid.
344 virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw) =0;
347 * @brief Returns the number of items.
349 * @return Number of items in the menu.
351 virtual unsigned int GetItemCount() =0;
354 * @brief Sets the menu's pagination,.
356 * @param itemsPerPage Number of items per page, or MENU_NO_PAGINATION.
357 * @return True on success, false if itemsPerPage is too large.
359 virtual bool SetPagination(unsigned int itemsPerPage) =0;
362 * @brief Returns an item's pagination.
364 * @return Pagination setting.
366 virtual unsigned int GetPagination() =0;
369 * @brief Returns the menu style.
371 * @return Menu style.
373 virtual IMenuStyle *GetDrawStyle() =0;
376 * @brief Sets the menu's display title/message.
378 * @param message Message (format options allowed).
380 virtual void SetDefaultTitle(const char *message) =0;
383 * @brief Returns the menu's display/title message.
385 * @return Message string.
387 virtual const char *GetDefaultTitle() =0;
390 * @brief Sets an extended menu option.
392 * @param option Option type.
393 * @param valuePtr Pointer of the type expected by the option.
394 * @return True on success, false if option or value is not supported.
396 virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
399 * @brief Creates a new IMenuDisplay object using extended options specific
400 * to the IMenuStyle parent. Titles, items, etc, are not copied.
402 * Note: The object should be freed with IMenuDisplay::DeleteThis.
404 * @return IMenuDisplay pointer.
406 virtual IMenuDisplay *CreateDisplay() =0;
409 * @brief Returns whether or not the menu should have an "Exit" button for
412 * @return True to have an exit button, false otherwise.
414 virtual bool GetExitButton() =0;
417 * @brief Sets whether or not the menu should have an "Exit" button for
420 * @param set True to enable, false to disable the exit button.
421 * @return True on success, false if the exit button is
424 virtual bool SetExitButton(bool set) =0;
427 * @brief Sends the menu to a client.
429 * @param client Client index to display to.
430 * @param handler Menu handler to use.
431 * @param time Time to hold menu for.
432 * @return True on success, false otherwise.
434 virtual bool Display(int client, IMenuHandler *handler, unsigned int time) =0;
437 * @brief Destroys the menu and frees all associated resources.1
439 virtual void Destroy() =0;
442 * @brief Cancels the menu on all client's displays. While the menu is
443 * being cancelled, the menu may not be re-displayed to any clients.
445 * @return Number of menus cancelled.
447 virtual void Cancel() =0;
451 * @brief Contains callbacks for menu actions.
457 * @brief Returns the menu api verison.
459 * @return Menu API version.
461 virtual unsigned int GetMenuAPIVersion2()
463 return SMINTERFACE_MENUMANAGER_VERSION;
467 * @brief A display/selection cycle has started.
469 * @param menu Menu pointer.
471 virtual void OnMenuStart(IBaseMenu *menu)
476 * @brief Called before a menu is being displayed. This is where
477 * you can set an alternate title on the menu.
479 * @param menu Menu pointer.
480 * @param client Client index.
481 * @param display IMenuDisplay pointer.
483 virtual void OnMenuDisplay(IBaseMenu *menu, int client, IMenuDisplay *display)
488 * @brief Called when an item is selected.
490 * @param menu Menu pointer.
491 * @param client Client that selected the item.
492 * @param item Item number.
494 virtual void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
499 * @brief An active menu display was dropped from a client.
501 * @param menu Menu pointer.
502 * @param client Client that had the menu.
503 * @param reason Menu cancellation reason.
505 virtual void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
510 * @brief A display/selection cycle has ended.
512 * @param menu Menu pointer.
514 virtual void OnMenuEnd(IBaseMenu *menu)
519 * @brief Called when requesting how to render an item.
521 * @param menu Menu pointer.
522 * @param client Client index receiving the menu.
523 * @param item Item number in the menu.
524 * @param style ITEMSTYLE flags, by reference for modification.
526 virtual void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style)
531 * @brief Called when requesting how to draw an item's text.
533 * @param menu Menu pointer.
534 * @param client Client index receiving the menu.
535 * @param item Item number in the menu.
536 * @param display Pointer to the display text string (changeable).
538 virtual void OnMenuDisplayItem(IBaseMenu *menu, int client, unsigned int item, const char **display)
544 * @brief Handles a vote menu.
546 class IMenuVoteHandler : public IMenuHandler
550 * @brief Called when a vote ends.
552 * @param menu Menu pointer.
553 * @param item Item position that was chosen by a majority.
555 virtual void OnMenuVoteEnd(IBaseMenu *menu, unsigned int item) =0;
559 * @brief Manages menu creation and displaying.
561 class IMenuManager : public SMInterface
564 virtual const char *GetInterfaceName()
566 return SMINTERFACE_MENUMANAGER_NAME;
568 virtual unsigned int GetInterfaceVersion()
570 return SMINTERFACE_MENUMANAGER_VERSION;
574 * @brief Finds a style by name.
576 * @param name Name of the style (case insensitive).
577 * @return IMenuStyle pointer, or NULL if not found.
579 virtual IMenuStyle *FindStyleByName(const char *name) =0;
582 * @brief Broadcasts a menu to a number of clients.
584 * @param menu Menu pointer.
585 * @param handler IMenuHandler pointer.
586 * @param clients Array of client indexes.
587 * @param numClients Number of clients in the array.
588 * @param time Time to hold the menu.
589 * @return Number of clients the menu will be waiting on.
591 virtual unsigned int BroadcastMenu(IBaseMenu *menu,
592 IMenuHandler *handler,
594 unsigned int numClients,
595 unsigned int time) =0;
598 * @brief Broadcasts a menu to a number of clients as a vote menu.
600 * @param menu Menu pointer.
601 * @param handler IMenuHandler pointer.
602 * @param clients Array of client indexes.
603 * @param numClients Number of clients in the array.
604 * @param time Time to hold the menu.
605 * @return Number of clients the menu will be waiting on.
607 virtual unsigned int VoteMenu(IBaseMenu *menu,
608 IMenuVoteHandler *handler,
610 unsigned int numClients,
611 unsigned int time) =0;
614 * @brief Returns the default draw style Core is using.
616 * @return Menu style pointer.
618 virtual IMenuStyle *GetDefaultStyle() =0;
621 * @brief Sets the default draw style Core uses.
623 * @param style Menu style.
624 * @return True on success, false on failure.
626 virtual bool SetDefaultStyle(IMenuStyle *style) =0;
629 * @brief Given a set of menu states, converts it to an IDisplay object.
631 * The state parameter is both INPUT and OUTPUT.
632 * INPUT: menu, mh, firstItem, lastItem
633 * OUTPUT: display, firstItem, lastItem, slots
635 * @param client Client index.
636 * @param states Menu states.
637 * @return IDisplay pointer, or NULL if no items could be
638 * found in the IBaseMenu pointer, or NULL if any
639 * other error occurred. Any valid pointer must
640 * be freed using IMenuDisplay::DeleteThis.
642 virtual IMenuDisplay *RenderMenu(int client, menu_states_t &states, ItemOrder order) =0;
646 #endif //_INCLUDE_SOURCEMOD_MENU_SYSTEM_H_