public/IMenuManager.h
author Erik Minekus <erik@minekus.com>
Thu Aug 01 09:26:34 2013 -0400 (2013-08-01)
changeset 3967 ceafb87d38a7
parent 2928 1f7626e1a49d
permissions -rw-r--r--
Numerous code documentation fixups (bug 5720, r=psychonic).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_MENU_SYSTEM_H_
    33 #define _INCLUDE_SOURCEMOD_MENU_SYSTEM_H_
    34 
    35 #include <IShareSys.h>
    36 #include <IHandleSys.h>
    37 
    38 #define SMINTERFACE_MENUMANAGER_NAME		"IMenuManager"
    39 #define SMINTERFACE_MENUMANAGER_VERSION		16
    40 
    41 /**
    42  * @file IMenuManager.h
    43  * @brief Abstracts on-screen menus for clients.
    44  */
    45 
    46 namespace SourceMod
    47 {
    48 	/**
    49 	 * @brief Used to determine how an item selection is interpreted.
    50 	 */
    51 	enum ItemSelection
    52 	{
    53 		ItemSel_None,					/**< Invalid selection */
    54 		ItemSel_Back,					/**< Go back one page (really "Previous") */
    55 		ItemSel_Next,					/**< Go forward one page */
    56 		ItemSel_Exit,					/**< Menu was exited */
    57 		ItemSel_Item,					/**< Valid item selection */
    58 		ItemSel_ExitBack,				/**< Sends MenuEnd_ExitBack */
    59 	};
    60 
    61 	/**
    62 	 * @brief Used to determine which order to search for items in.
    63 	 */
    64 	enum ItemOrder
    65 	{
    66 		ItemOrder_Ascending,			/**< Items should be drawn ascendingly */
    67 		ItemOrder_Descending,			/**< Items should be drawn descendingly */
    68 	};
    69 
    70 	/**
    71 	 * @brief Pairs an item type with an item menu position.
    72 	 */
    73 	struct menu_slots_t
    74 	{
    75 		ItemSelection type;				/**< Item selection type */
    76 		unsigned int item;				/**< Item position, if applicable */
    77 	};
    78 
    79 	class IBaseMenu;
    80 	class IMenuPanel;
    81 	class IMenuHandler;
    82 
    83 	/**
    84 	 * @brief Describes menu display information.
    85 	 */
    86 	struct menu_states_t
    87 	{
    88 		unsigned int apiVers;			/**< Must be filled with the API version */
    89 		IBaseMenu *menu;				/**< Menu pointer, or NULL if there is only a display */
    90 		IMenuHandler *mh;				/**< Menu callbacks handler */
    91 		unsigned int firstItem;			/**< MENU ONLY: First item displayed on the last page */
    92 		unsigned int lastItem;			/**< MENU ONLY: Last item displayed on the last page */
    93 		unsigned int item_on_page;		/**< MENU ONLY: First item on page */
    94 		menu_slots_t slots[11];			/**< MENU ONLY: Item selection table (first index is 1) */
    95 	};
    96 
    97 	#define ITEMDRAW_DEFAULT		(0)		/**< Item should be drawn normally */
    98 	#define ITEMDRAW_DISABLED		(1<<0)	/**< Item is drawn but not selectable */
    99 	#define ITEMDRAW_RAWLINE		(1<<1)	/**< Item should be a raw line, without a slot */
   100 	#define ITEMDRAW_NOTEXT			(1<<2)	/**< No text should be drawn */
   101 	#define ITEMDRAW_SPACER			(1<<3)	/**< Item should be drawn as a spacer, if possible */
   102 	#define ITEMDRAW_IGNORE	((1<<1)|(1<<2))	/**< Item should be completely ignored (rawline + notext) */
   103 	#define ITEMDRAW_CONTROL		(1<<4)	/**< Item is control text (back/next/exit) */
   104 
   105 	/**
   106 	 * @brief Information about item drawing.
   107 	 */
   108 	struct ItemDrawInfo
   109 	{
   110 		ItemDrawInfo(const char *DISPLAY=NULL, unsigned int STYLE=ITEMDRAW_DEFAULT, 
   111 					 unsigned int FLAGS=0, const char *HELPTEXT=NULL) 
   112 			: display(DISPLAY), style(STYLE)
   113 		{
   114 		}
   115 		const char *display;			/**< Display text (NULL for none) */
   116 		unsigned int style;				/**< ITEMDRAW style flags */
   117 	};
   118 
   119 	/**
   120 	 * @brief Contains information about a vote result.
   121 	 */
   122 	struct menu_vote_result_t
   123 	{
   124 		unsigned int num_clients;		/**< Number of clients the menu was displayed to */
   125 		unsigned int num_votes;			/**< Number of votes received */
   126 		struct menu_client_vote_t
   127 		{
   128 			int client;					/**< Client index */
   129 			int item;					/**< Item # (or -1 for none) */
   130 		} *client_list;					/**< Array of size num_clients */
   131 		unsigned int num_items;			/**< Number of items voted for */
   132 		struct menu_item_vote_t
   133 		{
   134 			unsigned int item;			/**< Item index */
   135 			unsigned int count;			/**< Number of votes */
   136 		} *item_list;					/**< Array of size num_items, sorted by count, 
   137 											 descending */
   138 	};
   139 
   140 	/**
   141 	 * @brief Reasons for a menu dying.
   142 	 */
   143 	enum MenuCancelReason
   144 	{
   145 		MenuCancel_Disconnected = -1,	/**< Client dropped from the server */
   146 		MenuCancel_Interrupted = -2,	/**< Client was interrupted with another menu */
   147 		MenuCancel_Exit = -3,			/**< Client selected "exit" on a paginated menu */
   148 		MenuCancel_NoDisplay = -4,		/**< Menu could not be displayed to the client */
   149 		MenuCancel_Timeout = -5,		/**< Menu timed out */
   150 		MenuCancel_ExitBack = -6,		/**< Client selected "exit back" on a paginated menu */
   151 	};
   152 
   153 	/**
   154 	 * @brief Reasons a menu ended.
   155 	 */
   156 	enum MenuEndReason
   157 	{
   158 		MenuEnd_Selected = 0,				/**< Menu item was selected */
   159 		MenuEnd_VotingDone = -1,			/**< Voting finished */
   160 		MenuEnd_VotingCancelled = -2,		/**< Voting was cancelled */
   161 		MenuEnd_Cancelled = -3,				/**< Menu was uncleanly cancelled */
   162 		MenuEnd_Exit = -4,					/**< Menu was cleanly exited via "exit" */
   163 		MenuEnd_ExitBack = -5,				/**< Menu was cleanly exited via "back" */
   164 	};
   165 
   166 	/**
   167 	 * @brief Reasons a vote can be cancelled.
   168 	 */
   169 	enum VoteCancelReason
   170 	{
   171 		VoteCancel_Generic = -1,		/**< Vote was generically cancelled. */
   172 		VoteCancel_NoVotes = -2,		/**< Vote did not receive any votes. */
   173 	};
   174 
   175 	#define MENU_NO_PAGINATION			0		/**< Menu should not be paginated (10 items max) */
   176 	#define MENU_TIME_FOREVER			0		/**< Menu should be displayed as long as possible */
   177 
   178 	#define MENUFLAG_BUTTON_EXIT		(1<<0)	/**< Menu has an "exit" button */
   179 	#define MENUFLAG_BUTTON_EXITBACK	(1<<1)	/**< Menu has an "exit back" button */
   180 	#define MENUFLAG_NO_SOUND			(1<<2)	/**< Menu will not have any select sounds */
   181 	#define MENUFLAG_BUTTON_NOVOTE		(1<<3)	/**< Menu has a "No Vote" button at slot 1 */
   182 
   183 	#define VOTEFLAG_NO_REVOTES			(1<<0)	/**< Players cannot change their votes */
   184 
   185 	/**
   186 	 * @brief Extended menu options.
   187 	 */
   188 	enum MenuOption
   189 	{
   190 		MenuOption_IntroMessage,				/**< CONST CHAR *: Valve menus only; defaults to:
   191 													 "You have a menu, hit ESC"
   192 													 */
   193 		MenuOption_IntroColor,					/**< INT[4]: Valve menus only; specifies the intro message colour
   194 													 using R,G,B,A (defaults to 255,0,0,255)
   195 													 */
   196 		MenuOption_Priority,					/**< INT *: Valve menus only; priority (less is higher) */
   197 	};
   198 
   199 	/**
   200 	 * @brief Describes the menu a player is viewing.
   201 	 */
   202 	enum MenuSource
   203 	{
   204 		MenuSource_None = 0,					/**< No menu is being displayed */
   205 		MenuSource_External = 1,				/**< External menu, no pointer */
   206 		MenuSource_BaseMenu = 2,				/**< An IBaseMenu pointer. */
   207 		MenuSource_Display = 3,					/**< IMenuPanel source, no pointer */
   208 	};
   209 
   210 	class IMenuStyle;
   211 
   212 	/**
   213 	 * @brief Sets how a raw menu should be drawn.
   214 	 */
   215 	class IMenuPanel
   216 	{
   217 	public:
   218 		/**
   219 		 * @brief Returns the parent IMenuStyle pointer.
   220 		 *
   221 		 * @return				IMenuStyle pointer which created
   222 		 *						this object.
   223 		 */
   224 		virtual IMenuStyle *GetParentStyle() =0;
   225 
   226 		/**
   227 		 * @brief Resets/clears the cached display text.
   228 		 */
   229 		virtual void Reset() =0;
   230 
   231 		/**
   232 		 * @brief Sets how the title should be drawn.
   233 		 *
   234 		 * @param text			Text string to display for the title.
   235 		 * @param onlyIfEmpty	Only sets the title if one does not already 
   236 		 *						exist.
   237 		 */
   238 		virtual void DrawTitle(const char *text, bool onlyIfEmpty=false) =0;
   239 
   240 		/**
   241 		 * @brief Adds an item to the menu and returns the position (1-10).
   242 		 *
   243 		 * Note: Item will fail to draw if there are too many items,
   244 		 * or the item is not drawable (for example, invisible).	
   245 		 * 
   246 		 * @return				Item draw position, or 0 on failure.
   247 		 */
   248 		virtual unsigned int DrawItem(const ItemDrawInfo &item) =0;
   249 
   250 		/**
   251 		 * @brief Draws a raw line of text, if supported.  The line does not 
   252 		 * need to be newline terminated.
   253 		 *
   254 		 * @return				True on success, false if not supported.
   255 		 */
   256 		virtual bool DrawRawLine(const char *rawline) =0;
   257 
   258 		/**
   259 		 * @brief Sets an extended menu option.
   260 		 *
   261 		 * @param option		Option type.
   262 		 * @param valuePtr		Pointer of the type expected by the option.
   263 		 * @return				True on success, false if option or value is not supported.
   264 		 */
   265 		virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
   266 
   267 		/**
   268 		 * @brief Returns whether the display is capable of rendering an item
   269 		 * with the given flags.
   270 		 *
   271 		 * @param drawFlags		ITEMDRAW flags.
   272 		 * @return				True if renderable, false otherwise.
   273 		 */
   274 		virtual bool CanDrawItem(unsigned int drawFlags) =0;
   275 
   276 		/**
   277 		 * @brief Sends the menu display to a client.
   278 		 *
   279 		 * @param client		Client index to display to.
   280 		 * @param handler		Menu handler to use.
   281 		 * @param time			Time to hold menu for.
   282 		 * @return				True on success, false otherwise.
   283 		 */
   284 		virtual bool SendDisplay(int client, IMenuHandler *handler, unsigned int time) =0;
   285 
   286 		/**
   287 		 * @brief Destroys the display object.
   288 		 */
   289 		virtual void DeleteThis() =0;
   290 
   291 		/**
   292 		 * @brief Sets the selectable key map.  Returns false if the function 
   293 		 * is not supported.
   294 		 * 
   295 		 * @param keymap		A bit string where each bit N-1 specifies 
   296 		 *						that key N is selectable (key 0 is bit 9).  
   297 		 *						If the selectable key map is 0, it will be
   298 		 *						automatically set to allow 0.
   299 		 * @return				True on success, false if not supported.
   300 		 */
   301 		virtual bool SetSelectableKeys(unsigned int keymap) =0;
   302 
   303 		/**
   304 		 * @brief Returns the current key position.
   305 		 *
   306 		 * @return				Current key position starting at 1.
   307 		 */
   308 		virtual unsigned int GetCurrentKey() =0;
   309 
   310 		/**
   311 		 * @brief Sets the next key position.  This cannot be used
   312 		 * to traverse backwards.
   313 		 *
   314 		 * @param key			Key that is greater or equal to
   315 		 *						GetCurrentKey().
   316 		 * @return				True on success, false otherwise.
   317 		 */
   318 		virtual bool SetCurrentKey(unsigned int key) =0;
   319 
   320 		/**
   321 		 * @brief Returns the number of characters that can be added to the 
   322 		 * menu.  The internal buffer is truncated if overflowed; this is for 
   323 		 * manual truncation/wrapping purposes.
   324 		 *
   325 		 * @return				Number of bytes available.  If the result is 
   326 		 *						-1, then the panel has no text limit.
   327 		 */
   328 		virtual int GetAmountRemaining() =0;
   329 
   330 		/**
   331 		 * @brief For the Handle system, returns approximate memory usage.
   332 		 *
   333 		 * @return				Approximate number of bytes being used.
   334 		 */
   335 		virtual unsigned int GetApproxMemUsage() =0;
   336 	};
   337 
   338 	/**
   339 	 * @brief Describes a "MenuStyle" system which manages
   340 	 * menu drawing and construction.
   341 	 */
   342 	class IMenuStyle
   343 	{
   344 	public:
   345 		/**
   346 		 * @brief Returns the style API version.
   347 		 *
   348 		 * @return				API version.
   349 		 */
   350 		virtual unsigned int GetStyleAPIVersion()
   351 		{
   352 			return SMINTERFACE_MENUMANAGER_VERSION;
   353 		}
   354 
   355 		/**
   356 		 * @brief Returns the name of the menu style.
   357 		 *
   358 		 * @return				String containing the style name.
   359 		 */
   360 		virtual const char *GetStyleName() =0;
   361 
   362 		/**
   363 		 * @brief Creates an IMenuPanel object.
   364 		 *
   365 		 * Note: the object should be freed using ::DeleteThis.
   366 		 *
   367 		 * @return				IMenuPanel object.
   368 		 */
   369 		virtual IMenuPanel *CreatePanel() =0;
   370 
   371 		/**
   372 		 * @brief Creates an IBaseMenu object of this style.
   373 		 *
   374 		 * Note: the object should be freed using IBaseMenu::Destroy.
   375 		 *
   376 		 * @param handler		IMenuHandler pointer.
   377 		 * @param pOwner		Optional IdentityToken_t owner for handle 
   378 		 *						creation.
   379 		 * @return				An IBaseMenu pointer.
   380 		 */
   381 		virtual IBaseMenu *CreateMenu(IMenuHandler *handler, IdentityToken_t *pOwner=NULL) =0;
   382 
   383 		/**
   384 		 * @brief Returns the maximum number of items per page.
   385 		 *
   386 		 * Menu implementations must return >= 2.  Styles with only 1 or 0 
   387 		 * items per page are not valid.
   388 		 *
   389 		 * @return				Number of items per page.
   390 		 */
   391 		virtual unsigned int GetMaxPageItems() =0;
   392 
   393 		/**
   394 		 * @brief Returns whether or not a client is viewing a menu.
   395 		 *
   396 		 * @param client		Client index.
   397 		 * @param object		Optional pointer to retrieve menu object,
   398 		 *						if any.
   399 		 * @return				MenuSource value.
   400 		 */
   401 		virtual MenuSource GetClientMenu(int client, void **object) =0;
   402 
   403 		/**
   404 		 * @brief Cancels a client's menu.
   405 		 *
   406 		 * @param client		Client index.
   407 		 * @param autoIgnore	If true, no menus can be created during 
   408 		 *						the cancellation process.
   409 		 * @return				True if a menu was cancelled, false otherwise.
   410 		 */
   411 		virtual bool CancelClientMenu(int client, bool autoIgnore=false) =0;
   412 
   413 		/**
   414 		 * @brief Returns a Handle the IMenuStyle object.
   415 		 *
   416 		 * @return				Handle_t pointing to this object.
   417 		 */
   418 		virtual Handle_t GetHandle() =0;
   419 
   420 		/**
   421 		 * @brief For the Handle system, returns approximate memory usage.
   422 		 *
   423 		 * @return				Approximate number of bytes being used.
   424 		 */
   425 		virtual unsigned int GetApproxMemUsage() =0;
   426 	};
   427 
   428 	/**
   429 	 * @brief High-level interface for building menus.
   430 	 */
   431 	class IBaseMenu
   432 	{
   433 	public:
   434 		/**
   435 		 * @brief Appends an item to the end of a menu.
   436 		 *
   437 		 * @param info			Item information string.
   438 		 * @param draw			Default drawing information.
   439 		 * @return				True on success, false on item limit reached.
   440 		 */
   441 		virtual bool AppendItem(const char *info, const ItemDrawInfo &draw) =0;
   442 
   443 		/**
   444 		 * @brief Inserts an item into the menu before a certain position; 
   445 		 * the new item will be at the given position and all next items 
   446 		 * pushed forward.
   447 		 *
   448 		 * @param position		Position, starting from 0.
   449 		 * @param info			Item information string.
   450 		 * @param draw			Default item draw info.
   451 		 * @return				True on success, false on invalid menu position
   452 		 */
   453 		virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw) =0;
   454 
   455 		/**
   456 		 * @brief Removes an item from the menu.
   457 		 *
   458 		 * @param position		Position, starting from 0.
   459 		 * @return				True on success, false on invalid menu position.
   460 		 */
   461 		virtual bool RemoveItem(unsigned int position) =0;
   462 
   463 		/**
   464 		 * @brief Removes all items from the menu.
   465 		 */
   466 		virtual void RemoveAllItems() =0;
   467 
   468 		/**
   469 		 * @brief Returns an item's info.
   470 		 *
   471 		 * @param position		Position, starting from 0.
   472 		 * @param draw			Optional pointer to store a draw information.
   473 		 * @return				Info string pointer, or NULL if position was invalid.
   474 		 */
   475 		virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw) =0;
   476 
   477 		/**
   478 		 * @brief Returns the number of items.
   479 		 *
   480 		 * @return				Number of items in the menu.
   481 		 */
   482 		virtual unsigned int GetItemCount() =0;
   483 
   484 		/** 
   485 		 * @brief Sets the menu's pagination,.
   486 		 *
   487 		 * If pagination is set to MENU_NO_PAGINATION, and the previous 
   488 		 * pagination was not MENU_NO_PAGINATION, then the MENUFLAG_BUTTON_EXIT 
   489 		 * is unset.  It can be re-applied if desired.
   490 		 *
   491 		 * @param itemsPerPage	Number of items per page, or MENU_NO_PAGINATION.
   492 		 * @return				True on success, false if itemsPerPage is too 
   493 		 *						large.
   494 		 */
   495 		virtual bool SetPagination(unsigned int itemsPerPage) =0;
   496 
   497 		/**
   498 		 * @brief Returns an item's pagination.
   499 		 *
   500 		 * @return				Pagination setting.
   501 		 */
   502 		virtual unsigned int GetPagination() =0;
   503 
   504 		/**
   505 		 * @brief Returns the menu style.
   506 		 * 
   507 		 * @return				Menu style.
   508 		 */
   509 		virtual IMenuStyle *GetDrawStyle() =0;
   510 
   511 		/**
   512 		 * @brief Sets the menu's display title/message.
   513 		 *
   514 		 * @param message		Message (format options allowed).
   515 		 */
   516 		virtual void SetDefaultTitle(const char *message) =0;
   517 
   518 		/**
   519 		 * @brief Returns the menu's display/title message.
   520 		 *
   521 		 * @return				Message string.
   522 		 */
   523 		virtual const char *GetDefaultTitle() =0;
   524 
   525 		/**
   526 		 * @brief Sets an extended menu option.
   527 		 *
   528 		 * @param option		Option type.
   529 		 * @param valuePtr		Pointer of the type expected by the option.
   530 		 * @return				True on success, false if option or value is not supported.
   531 		 */
   532 		virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
   533 
   534 		/**
   535 		 * @brief Creates a new IMenuPanel object using extended options specific
   536 		 * to the IMenuStyle parent.  Titles, items, etc, are not copied.
   537 		 *
   538 		 * Note: The object should be freed with IMenuPanel::DeleteThis.
   539 		 *
   540 		 * @return				IMenuPanel pointer.
   541 		 */
   542 		virtual IMenuPanel *CreatePanel() =0;
   543 
   544 		/**
   545 		 * @brief Sends the menu to a client.
   546 		 *
   547 		 * @param client		Client index to display to.
   548 		 * @param time			Time to hold menu for.
   549 		 * @param alt_handler	Alternate IMenuHandler.
   550 		 * @return				True on success, false otherwise.
   551 		 */
   552 		virtual bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL) =0;
   553 
   554 		/**
   555 		 * @brief Destroys the menu and frees all associated resources.
   556 		 *
   557 		 * @param releaseHandle	If true, the Handle will be released
   558 		 *						in the destructor.  This should be set
   559 		 *						to true except for IHandleTypeDispatch
   560 		 *						destructors.
   561 		 */
   562 		virtual void Destroy(bool releaseHandle=true) =0;
   563 
   564 		/**
   565 		 * @brief Cancels the menu on all client's displays.  While the menu is
   566 		 * being cancelled, the menu may not be re-displayed to any clients.
   567 		 * If a vote menu is currently active, it will be cancelled as well.
   568 		 *
   569 		 * @return				Number of menus cancelled.
   570 		 */
   571 		virtual void Cancel() =0;
   572 
   573 		/**
   574 		 * @brief Returns the menu's Handle.  The Handle is automatically
   575 		 * removed when the menu is destroyed.
   576 		 *
   577 		 * @return				Handle_t handle value.
   578 		 */
   579 		virtual Handle_t GetHandle() =0;
   580 		
   581 		/**
   582 		 * @brief Returns menu option flags.
   583 		 *
   584 		 * @return				Menu option flags.
   585 		 */
   586 		virtual unsigned int GetMenuOptionFlags() =0;
   587 
   588 		/**
   589 		 * @brief Sets menu option flags.
   590 		 *
   591 		 * @param flags			Menu option flags.
   592 		 */
   593 		virtual void SetMenuOptionFlags(unsigned int flags) =0;
   594 
   595 		/**
   596 		 * @brief Returns the menu's handler.
   597 		 *
   598 		 * @return				IMenuHandler of the menu.
   599 		 */
   600 		virtual IMenuHandler *GetHandler() =0;
   601 
   602 		/**
   603 		 * @brief Sends the menu to a client, starting from the given item number. 
   604 		 *
   605 		 * Note: this API call was added in v13.
   606 		 *
   607 		 * @param client		Client index to display to.
   608 		 * @param time			Time to hold menu for.
   609 		 * @param start_item	Starting item to draw.
   610 		 * @param alt_handler	Alternate IMenuHandler.
   611 		 * @return				True on success, false otherwise.
   612 		 */
   613 		virtual bool DisplayAtItem(int client,
   614 			unsigned int time,
   615 			unsigned int start_item,
   616 			IMenuHandler *alt_handler=NULL) =0;
   617 
   618 		/**
   619 		 * @brief For the Handle system, returns approximate memory usage.
   620 		 *
   621 		 * @return				Approximate number of bytes being used.
   622 		 */
   623 		virtual unsigned int GetApproxMemUsage() =0;
   624 	};
   625 
   626 	/** 
   627 	 * @brief Contains callbacks for menu actions.
   628 	 */
   629 	class IMenuHandler
   630 	{
   631 	public:
   632 		/**
   633 		 * @brief Returns the menu api verison.
   634 		 *
   635 		 * @return				Menu API version.
   636 		 */
   637 		virtual unsigned int GetMenuAPIVersion2()
   638 		{
   639 			return SMINTERFACE_MENUMANAGER_VERSION;
   640 		}
   641 
   642 		/** 
   643 		 * @brief A display/selection cycle has started.
   644 		 *
   645 		 * @param menu			Menu pointer.
   646 		 */
   647 		virtual void OnMenuStart(IBaseMenu *menu)
   648 		{
   649 		}
   650 
   651 		/**
   652 		 * @brief Called before a menu is being displayed.  This is where
   653 		 * you can set an alternate title on the menu.
   654 		 *
   655 		 * @param menu			Menu pointer.
   656 		 * @param client		Client index.
   657 		 * @param display		IMenuPanel pointer.
   658 		 */
   659 		virtual void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display)
   660 		{
   661 		}
   662 
   663 		/**
   664 		 * @brief Called when an item is selected.
   665 		 *
   666 		 * @param menu			Menu pointer.
   667 		 * @param client		Client that selected the item.
   668 		 * @param item			Item number.
   669 		 */
   670 		virtual void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
   671 		{
   672 		}
   673 
   674 		/**
   675 		 * @brief An active menu display was dropped from a client.
   676 		 *
   677 		 * @param menu			Menu pointer.
   678 		 * @param client		Client that had the menu.
   679 		 * @param reason		Menu cancellation reason.
   680 		 */
   681 		virtual void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
   682 		{
   683 		}
   684 
   685 		/**
   686 		 * @brief A display/selection cycle has ended.
   687 		 *
   688 		 * @param menu			Menu pointer.
   689 		 * @param reason		MenuEndReason reason.
   690 		 */
   691 		virtual void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason)
   692 		{
   693 		}
   694 
   695 		/**
   696 		 * @brief Called when the menu object is destroyed.
   697 		 *
   698 		 * @param menu			Menu pointer.
   699 		 */
   700 		virtual void OnMenuDestroy(IBaseMenu *menu)
   701 		{
   702 		}
   703 
   704 		/**
   705 		 * @brief Called when requesting how to render an item.
   706 		 *
   707 		 * @param menu			Menu pointer.
   708 		 * @param client		Client index receiving the menu.
   709 		 * @param item			Item number in the menu.
   710 		 * @param style			ITEMSTYLE flags, by reference for modification.
   711 		 */
   712 		virtual void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style)
   713 		{
   714 		}
   715 
   716 		/**
   717 		 * @brief Called when drawing item text.
   718 		 *
   719 		 * @param menu			Menu pointer.
   720 		 * @param client		Client index receiving the menu.
   721 		 * @param panel			Panel being used to draw the menu.
   722 		 * @param item			Item number in the menu.
   723 		 * @param dr			Item draw information.
   724 		 * @return				0 to let the render algorithm decide how to draw, otherwise,
   725 		 *						the return value from panel->DrawItem should be returned.
   726 		 */
   727 		virtual unsigned int OnMenuDisplayItem(IBaseMenu *menu, 
   728 											   int client, 
   729 											   IMenuPanel *panel,
   730 											   unsigned int item, 
   731 											   const ItemDrawInfo &dr)
   732 		{
   733 			return 0;
   734 		}
   735 
   736 		/**
   737 		 * @brief Called when a vote has been started and displayed to 
   738 		 * clients.  This is called after OnMenuStart() and OnMenuDisplay(),
   739 		 * but before OnMenuSelect().
   740 		 *
   741 		 * @param menu			Menu pointer.
   742 		 */
   743 		virtual void OnMenuVoteStart(IBaseMenu *menu)
   744 		{
   745 		}
   746 
   747 		/**
   748 		 * @brief Called when a vote ends.  This is automatically called by the 
   749 		 * wrapper, and never needs to called from a style implementation.  
   750 		 *
   751 		 * This function does not replace OnMenuEnd(), nor does it have the 
   752 		 * same meaning as OnMenuEnd(), meaning you should not destroy a menu
   753 		 * while it is in this function.
   754 		 *
   755 		 * @param menu			Menu pointer.
   756 		 * @param results		Menu vote results.
   757 		 */
   758 		virtual void OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *results)
   759 		{
   760 		}
   761 
   762 		/**
   763 		 * @brief Called when a vote is cancelled.  If this is called, then 
   764 		 * OnMenuVoteResults() will not be called.  In both cases, OnMenuEnd will 
   765 		 * always be called.
   766 		 *
   767 		 * @param menu			Menu pointer.
   768 		 * @param reason		VoteCancelReason reason.
   769 		 */
   770 		virtual void OnMenuVoteCancel(IBaseMenu *menu, VoteCancelReason reason)
   771 		{
   772 		}
   773 
   774 		/**
   775 		 * @brief Call to set private handler stuff.
   776 		 *
   777 		 * @param option		Option name.
   778 		 * @param data			Private data.
   779 		 * @return				True if set, false if invalid or unrecognized.
   780 		 */
   781 		virtual bool OnSetHandlerOption(const char *option, const void *data)
   782 		{
   783 			return false;
   784 		}
   785 
   786 		/**
   787 		 * @brief Called when an item is selected.
   788 		 *
   789 		 * Note: This callback was added in v13.  It is called after OnMenuSelect().
   790 		 *
   791 		 * @param menu			Menu pointer.
   792 		 * @param client		Client that selected the item.
   793 		 * @param item			Item number.
   794 		 * @param item_on_page	The first item on the page the player was last 
   795 		 *						viewing.
   796 		 */
   797 		virtual void OnMenuSelect2(IBaseMenu *menu,
   798 			int client,
   799 			unsigned int item,
   800 			unsigned int item_on_page)
   801 		{
   802 		}
   803 	};
   804 
   805 	/**
   806 	 * @brief Manages menu creation and displaying.
   807 	 */
   808 	class IMenuManager : public SMInterface
   809 	{
   810 	public:
   811 		virtual const char *GetInterfaceName()
   812 		{
   813 			return SMINTERFACE_MENUMANAGER_NAME;
   814 		}
   815 		virtual unsigned int GetInterfaceVersion()
   816 		{
   817 			return SMINTERFACE_MENUMANAGER_VERSION;
   818 		}
   819 		virtual bool IsVersionCompatible(unsigned int version)
   820 		{
   821 			if (version < 11 || version > GetInterfaceVersion())
   822 			{
   823 				return false;
   824 			}
   825 			return true;
   826 		}
   827 	public:
   828 		/**
   829 		 * @brief Finds a style by name.
   830 		 *
   831 		 * @param name			Name of the style (case insensitive).
   832 		 * @return				IMenuStyle pointer, or NULL if not found.
   833 		 */
   834 		virtual IMenuStyle *FindStyleByName(const char *name) =0;
   835 
   836 		/**
   837 		 * @brief Returns the default draw style Core is using.
   838 		 *
   839 		 * @return				Menu style pointer.
   840 		 */
   841 		virtual IMenuStyle *GetDefaultStyle() =0;
   842 
   843 		/**
   844 		 * @brief Given a set of menu states, converts it to an IMenuPanel object.
   845 		 *
   846 		 * The state parameter is both INPUT and OUTPUT.
   847 		 * INPUT: menu, mh, firstItem, lastItem
   848 		 * OUTPUT: display, firstItem, lastItem, slots
   849 		 *
   850 		 * @param client		Client index.
   851 		 * @param states		Menu states.
   852 		 * @param order			Order to search for items.
   853 		 * @return				IMenuPanel pointer, or NULL if no items could be 
   854 		 *						found in the IBaseMenu pointer, or NULL if any
   855 		 *						other error occurred.  Any valid pointer must
   856 		 *						be freed using IMenuPanel::DeleteThis.
   857 		 */
   858 		virtual IMenuPanel *RenderMenu(int client, menu_states_t &states, ItemOrder order) =0;
   859 
   860 		/**
   861 		 * @brief Cancels a menu.  Calls IBaseMenu::Cancel() after doing some preparatory 
   862 		 * work.  This should always be used instead of directly calling Cancel().
   863 		 *
   864 		 * @param menu			IBaseMenu pointer.
   865 		 */
   866 		virtual void CancelMenu(IBaseMenu *menu) =0;
   867 
   868 		/**
   869 		 * @brief Displays a menu as a vote.
   870 		 *
   871 		 * @param menu			IBaseMenu pointer.
   872 		 * @param num_clients	Number of clients to display to.
   873 		 * @param clients		Client index array.
   874 		 * @param max_time		Maximum time to hold menu for.
   875 		 * @param flags			Vote flags.
   876 		 * @return				True on success, false if a vote is in progress.
   877 		 */
   878 		virtual bool StartVote(IBaseMenu *menu,
   879 								unsigned int num_clients,
   880 								int clients[],
   881 								unsigned int max_time,
   882 								unsigned int flags=0) =0;
   883 
   884 		/**
   885 		 * @brief Returns whether or not a vote is in progress.
   886 		 *
   887 		 * @return				True if a vote is in progress, false otherwise.
   888 		 */
   889 		virtual bool IsVoteInProgress() =0;
   890 
   891 		/**
   892 		 * @brief Cancels the vote in progress.  This calls IBaseMenu::Cancel().
   893 		 */
   894 		virtual void CancelVoting() =0;
   895 
   896 		/**
   897 		 * @brief Returns the remaining vote delay from the last menu.  This delay is 
   898 		 * a suggestion for all public votes, and is not enforced.
   899 		 *
   900 		 * @return				Number of seconds to wait.
   901 		 */
   902 		virtual unsigned int GetRemainingVoteDelay() =0;
   903 
   904 		/**
   905 		 * @brief Returns whether a client is in the "allowed to vote" pool determined 
   906 		 * by the initial call to StartVote().
   907 		 *
   908 		 * @param client		Client index.
   909 		 * @return				True if client is allowed to vote, false on failure.
   910 		 */
   911 		virtual bool IsClientInVotePool(int client) =0;
   912 
   913 		/**
   914 		 * @brief Redraws the current vote menu to a client in the voting pool.
   915 		 *
   916 		 * @param client		Client index.
   917 		 * @return				True on success, false if client is not allowed to vote.
   918 		 */
   919 		virtual bool RedrawClientVoteMenu(int client) =0;
   920 
   921 		/**
   922 		 * @brief Redraws the current vote menu to a client in the voting pool.
   923 		 *
   924 		 * @param client		Client index.
   925 		 * @param revotes		True to allow revotes, false otherwise.
   926 		 * @return				True on success, false if client is not allowed to vote.
   927 		 */
   928 		virtual bool RedrawClientVoteMenu2(int client, bool revotes) =0;
   929 	};
   930 }
   931 
   932 #endif //_INCLUDE_SOURCEMOD_MENU_SYSTEM_H_
   933