public/IMenuManager.h
author Matt Woodrow <pred@alliedmods.net>
Sun Jul 06 03:30:06 2008 +0000 (2008-07-06)
changeset 2165 ca3757e676f6
parent 2056 f1fcde46ac7c
child 2289 44045ead61cd
permissions -rw-r--r--
Fixed requiring dependencies at the wrong time.
     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		15
    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 
   182 	/**
   183 	 * @brief Extended menu options.
   184 	 */
   185 	enum MenuOption
   186 	{
   187 		MenuOption_IntroMessage,				/**< CONST CHAR *: Valve menus only; defaults to:
   188 													 "You have a menu, hit ESC"
   189 													 */
   190 		MenuOption_IntroColor,					/**< INT[4]: Valve menus only; specifies the intro message colour
   191 													 using R,G,B,A (defaults to 255,0,0,255)
   192 													 */
   193 		MenuOption_Priority,					/**< INT *: Valve menus only; priority (less is higher) */
   194 	};
   195 
   196 	/**
   197 	 * @brief Describes the menu a player is viewing.
   198 	 */
   199 	enum MenuSource
   200 	{
   201 		MenuSource_None = 0,					/**< No menu is being displayed */
   202 		MenuSource_External = 1,				/**< External menu, no pointer */
   203 		MenuSource_BaseMenu = 2,				/**< An IBaseMenu pointer. */
   204 		MenuSource_Display = 3,					/**< IMenuPanel source, no pointer */
   205 	};
   206 
   207 	class IMenuStyle;
   208 
   209 	/**
   210 	 * @brief Sets how a raw menu should be drawn.
   211 	 */
   212 	class IMenuPanel
   213 	{
   214 	public:
   215 		/**
   216 		 * @brief Returns the parent IMenuStyle pointer.
   217 		 *
   218 		 * @return				IMenuStyle pointer which created
   219 		 *						this object.
   220 		 */
   221 		virtual IMenuStyle *GetParentStyle() =0;
   222 
   223 		/**
   224 		 * @brief Resets/clears the cached display text.
   225 		 */
   226 		virtual void Reset() =0;
   227 
   228 		/**
   229 		 * @brief Sets how the title should be drawn.
   230 		 *
   231 		 * @param text			Text string to display for the title.
   232 		 * @param onlyIfEmpty	Only sets the title if one does not already 
   233 		 *						exist.
   234 		 */
   235 		virtual void DrawTitle(const char *text, bool onlyIfEmpty=false) =0;
   236 
   237 		/**
   238 		 * @brief Adds an item to the menu and returns the position (1-10).
   239 		 *
   240 		 * Note: Item will fail to draw if there are too many items,
   241 		 * or the item is not drawable (for example, invisible).	
   242 		 * 
   243 		 * @return				Item draw position, or 0 on failure.
   244 		 */
   245 		virtual unsigned int DrawItem(const ItemDrawInfo &item) =0;
   246 
   247 		/**
   248 		 * @brief Draws a raw line of text, if supported.  The line does not 
   249 		 * need to be newline terminated.
   250 		 *
   251 		 * @return				True on success, false if not supported.
   252 		 */
   253 		virtual bool DrawRawLine(const char *rawline) =0;
   254 
   255 		/**
   256 		 * @brief Sets an extended menu option.
   257 		 *
   258 		 * @param option		Option type.
   259 		 * @param valuePtr		Pointer of the type expected by the option.
   260 		 * @return				True on success, false if option or value is not supported.
   261 		 */
   262 		virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
   263 
   264 		/**
   265 		 * @brief Returns whether the display is capable of rendering an item
   266 		 * with the given flags.
   267 		 *
   268 		 * @param drawFlags		ITEMDRAW flags.
   269 		 * @return				True if renderable, false otherwise.
   270 		 */
   271 		virtual bool CanDrawItem(unsigned int drawFlags) =0;
   272 
   273 		/**
   274 		 * @brief Sends the menu display to a client.
   275 		 *
   276 		 * @param client		Client index to display to.
   277 		 * @param handler		Menu handler to use.
   278 		 * @param time			Time to hold menu for.
   279 		 * @return				True on success, false otherwise.
   280 		 */
   281 		virtual bool SendDisplay(int client, IMenuHandler *handler, unsigned int time) =0;
   282 
   283 		/**
   284 		 * @brief Destroys the display object.
   285 		 */
   286 		virtual void DeleteThis() =0;
   287 
   288 		/**
   289 		 * @brief Sets the selectable key map.  Returns false if the function 
   290 		 * is not supported.
   291 		 * 
   292 		 * @param keymap		A bit string where each bit N-1 specifies 
   293 		 *						that key N is selectable (key 0 is bit 9).  
   294 		 *						If the selectable key map is 0, it will be
   295 		 *						automatically set to allow 0.
   296 		 * @return				True on success, false if not supported.
   297 		 */
   298 		virtual bool SetSelectableKeys(unsigned int keymap) =0;
   299 
   300 		/**
   301 		 * @brief Returns the current key position.
   302 		 *
   303 		 * @return				Current key position starting at 1.
   304 		 */
   305 		virtual unsigned int GetCurrentKey() =0;
   306 
   307 		/**
   308 		 * @brief Sets the next key position.  This cannot be used
   309 		 * to traverse backwards.
   310 		 *
   311 		 * @param key			Key that is greater or equal to
   312 		 *						GetCurrentKey().
   313 		 * @return				True on success, false otherwise.
   314 		 */
   315 		virtual bool SetCurrentKey(unsigned int key) =0;
   316 
   317 		/**
   318 		 * @brief Returns the number of characters that can be added to the 
   319 		 * menu.  The internal buffer is truncated if overflowed; this is for 
   320 		 * manual truncation/wrapping purposes.
   321 		 *
   322 		 * @return				Number of bytes available.  If the result is 
   323 		 *						-1, then the panel has no text limit.
   324 		 */
   325 		virtual int GetAmountRemaining() =0;
   326 
   327 		/**
   328 		 * @brief For the Handle system, returns approximate memory usage.
   329 		 *
   330 		 * @return				Approximate number of bytes being used.
   331 		 */
   332 		virtual unsigned int GetApproxMemUsage() =0;
   333 	};
   334 
   335 	/**
   336 	 * @brief Describes a "MenuStyle" system which manages
   337 	 * menu drawing and construction.
   338 	 */
   339 	class IMenuStyle
   340 	{
   341 	public:
   342 		/**
   343 		 * @brief Returns the style API version.
   344 		 *
   345 		 * @return				API version.
   346 		 */
   347 		virtual unsigned int GetStyleAPIVersion()
   348 		{
   349 			return SMINTERFACE_MENUMANAGER_VERSION;
   350 		}
   351 
   352 		/**
   353 		 * @brief Returns the name of the menu style.
   354 		 *
   355 		 * @return				String containing the style name.
   356 		 */
   357 		virtual const char *GetStyleName() =0;
   358 
   359 		/**
   360 		 * @brief Creates an IMenuPanel object.
   361 		 *
   362 		 * Note: the object should be freed using ::DeleteThis.
   363 		 *
   364 		 * @return				IMenuPanel object.
   365 		 */
   366 		virtual IMenuPanel *CreatePanel() =0;
   367 
   368 		/**
   369 		 * @brief Creates an IBaseMenu object of this style.
   370 		 *
   371 		 * Note: the object should be freed using IBaseMenu::Destroy.
   372 		 *
   373 		 * @param handler		IMenuHandler pointer.
   374 		 * @param pOwner		Optional IdentityToken_t owner for handle 
   375 		 *						creation.
   376 		 * @return				An IBaseMenu pointer.
   377 		 */
   378 		virtual IBaseMenu *CreateMenu(IMenuHandler *handler, IdentityToken_t *pOwner=NULL) =0;
   379 
   380 		/**
   381 		 * @brief Returns the maximum number of items per page.
   382 		 *
   383 		 * Menu implementations must return >= 2.  Styles with only 1 or 0 
   384 		 * items per page are not valid.
   385 		 *
   386 		 * @return				Number of items per page.
   387 		 */
   388 		virtual unsigned int GetMaxPageItems() =0;
   389 
   390 		/**
   391 		 * @brief Returns whether or not a client is viewing a menu.
   392 		 *
   393 		 * @param client		Client index.
   394 		 * @param object		Optional pointer to retrieve menu object,
   395 		 *						if any.
   396 		 * @return				MenuSource value.
   397 		 */
   398 		virtual MenuSource GetClientMenu(int client, void **object) =0;
   399 
   400 		/**
   401 		 * @brief Cancels a client's menu.
   402 		 *
   403 		 * @param client		Client index.
   404 		 * @param autoIgnore	If true, no menus can be created during 
   405 		 *						the cancellation process.
   406 		 * @return				True if a menu was cancelled, false otherwise.
   407 		 */
   408 		virtual bool CancelClientMenu(int client, bool autoIgnore=false) =0;
   409 
   410 		/**
   411 		 * @brief Returns a Handle the IMenuStyle object.
   412 		 *
   413 		 * @return				Handle_t pointing to this object.
   414 		 */
   415 		virtual Handle_t GetHandle() =0;
   416 
   417 		/**
   418 		 * @brief For the Handle system, returns approximate memory usage.
   419 		 *
   420 		 * @return				Approximate number of bytes being used.
   421 		 */
   422 		virtual unsigned int GetApproxMemUsage() =0;
   423 	};
   424 
   425 	/**
   426 	 * @brief High-level interface for building menus.
   427 	 */
   428 	class IBaseMenu
   429 	{
   430 	public:
   431 		/**
   432 		 * @brief Appends an item to the end of a menu.
   433 		 *
   434 		 * @param info			Item information string.
   435 		 * @param draw			Default drawing information.
   436 		 * @return				True on success, false on item limit reached.
   437 		 */
   438 		virtual bool AppendItem(const char *info, const ItemDrawInfo &draw) =0;
   439 
   440 		/**
   441 		 * @brief Inserts an item into the menu before a certain position; 
   442 		 * the new item will be at the given position and all next items 
   443 		 * pushed forward.
   444 		 *
   445 		 * @param position		Position, starting from 0.
   446 		 * @param info			Item information string.
   447 		 * @param draw			Default item draw info.
   448 		 * @return				True on success, false on invalid menu position
   449 		 */
   450 		virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw) =0;
   451 
   452 		/**
   453 		 * @brief Removes an item from the menu.
   454 		 *
   455 		 * @param position		Position, starting from 0.
   456 		 * @return				True on success, false on invalid menu position.
   457 		 */
   458 		virtual bool RemoveItem(unsigned int position) =0;
   459 
   460 		/**
   461 		 * @brief Removes all items from the menu.
   462 		 */
   463 		virtual void RemoveAllItems() =0;
   464 
   465 		/**
   466 		 * @brief Returns an item's info.
   467 		 *
   468 		 * @param position		Position, starting from 0.
   469 		 * @param draw			Optional pointer to store a draw information.
   470 		 * @return				Info string pointer, or NULL if position was invalid.
   471 		 */
   472 		virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw) =0;
   473 
   474 		/**
   475 		 * @brief Returns the number of items.
   476 		 *
   477 		 * @return				Number of items in the menu.
   478 		 */
   479 		virtual unsigned int GetItemCount() =0;
   480 
   481 		/** 
   482 		 * @brief Sets the menu's pagination,.
   483 		 *
   484 		 * If pagination is set to MENU_NO_PAGINATION, and the previous 
   485 		 * pagination was not MENU_NO_PAGINATION, then the MENUFLAG_BUTTON_EXIT 
   486 		 * is unset.  It can be re-applied if desired.
   487 		 *
   488 		 * @param itemsPerPage	Number of items per page, or MENU_NO_PAGINATION.
   489 		 * @return				True on success, false if itemsPerPage is too 
   490 		 *						large.
   491 		 */
   492 		virtual bool SetPagination(unsigned int itemsPerPage) =0;
   493 
   494 		/**
   495 		 * @brief Returns an item's pagination.
   496 		 *
   497 		 * @return				Pagination setting.
   498 		 */
   499 		virtual unsigned int GetPagination() =0;
   500 
   501 		/**
   502 		 * @brief Returns the menu style.
   503 		 * 
   504 		 * @return				Menu style.
   505 		 */
   506 		virtual IMenuStyle *GetDrawStyle() =0;
   507 
   508 		/**
   509 		 * @brief Sets the menu's display title/message.
   510 		 *
   511 		 * @param message		Message (format options allowed).
   512 		 */
   513 		virtual void SetDefaultTitle(const char *message) =0;
   514 
   515 		/**
   516 		 * @brief Returns the menu's display/title message.
   517 		 *
   518 		 * @return				Message string.
   519 		 */
   520 		virtual const char *GetDefaultTitle() =0;
   521 
   522 		/**
   523 		 * @brief Sets an extended menu option.
   524 		 *
   525 		 * @param option		Option type.
   526 		 * @param valuePtr		Pointer of the type expected by the option.
   527 		 * @return				True on success, false if option or value is not supported.
   528 		 */
   529 		virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
   530 
   531 		/**
   532 		 * @brief Creates a new IMenuPanel object using extended options specific
   533 		 * to the IMenuStyle parent.  Titles, items, etc, are not copied.
   534 		 *
   535 		 * Note: The object should be freed with IMenuPanel::DeleteThis.
   536 		 *
   537 		 * @return				IMenuPanel pointer.
   538 		 */
   539 		virtual IMenuPanel *CreatePanel() =0;
   540 
   541 		/**
   542 		 * @brief Sends the menu to a client.
   543 		 *
   544 		 * @param client		Client index to display to.
   545 		 * @param time			Time to hold menu for.
   546 		 * @param alt_handler	Alternate IMenuHandler.
   547 		 * @return				True on success, false otherwise.
   548 		 */
   549 		virtual bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL) =0;
   550 
   551 		/**
   552 		 * @brief Destroys the menu and frees all associated resources.
   553 		 *
   554 		 * @param releaseHandle	If true, the Handle will be released
   555 		 *						in the destructor.  This should be set
   556 		 *						to true except for IHandleTypeDispatch
   557 		 *						destructors.
   558 		 */
   559 		virtual void Destroy(bool releaseHandle=true) =0;
   560 
   561 		/**
   562 		 * @brief Cancels the menu on all client's displays.  While the menu is
   563 		 * being cancelled, the menu may not be re-displayed to any clients.
   564 		 * If a vote menu is currently active, it will be cancelled as well.
   565 		 *
   566 		 * @return				Number of menus cancelled.
   567 		 */
   568 		virtual void Cancel() =0;
   569 
   570 		/**
   571 		 * @brief Returns the menu's Handle.  The Handle is automatically
   572 		 * removed when the menu is destroyed.
   573 		 *
   574 		 * @return				Handle_t handle value.
   575 		 */
   576 		virtual Handle_t GetHandle() =0;
   577 		
   578 		/**
   579 		 * @brief Returns menu option flags.
   580 		 *
   581 		 * @return				Menu option flags.
   582 		 */
   583 		virtual unsigned int GetMenuOptionFlags() =0;
   584 
   585 		/**
   586 		 * @brief Sets menu option flags.
   587 		 *
   588 		 * @param flags			Menu option flags.
   589 		 */
   590 		virtual void SetMenuOptionFlags(unsigned int flags) =0;
   591 
   592 		/**
   593 		 * @brief Returns the menu's handler.
   594 		 *
   595 		 * @return				IMenuHandler of the menu.
   596 		 */
   597 		virtual IMenuHandler *GetHandler() =0;
   598 
   599 		/**
   600 		 * @brief Sends the menu to a client, starting from the given item number. 
   601 		 *
   602 		 * Note: this API call was added in v13.
   603 		 *
   604 		 * @param client		Client index to display to.
   605 		 * @param time			Time to hold menu for.
   606 		 * @param start_item	Starting item to draw.
   607 		 * @param alt_handler	Alternate IMenuHandler.
   608 		 * @return				True on success, false otherwise.
   609 		 */
   610 		virtual bool DisplayAtItem(int client,
   611 			unsigned int time,
   612 			unsigned int start_item,
   613 			IMenuHandler *alt_handler=NULL) =0;
   614 
   615 		/**
   616 		 * @brief For the Handle system, returns approximate memory usage.
   617 		 *
   618 		 * @return				Approximate number of bytes being used.
   619 		 */
   620 		virtual unsigned int GetApproxMemUsage() =0;
   621 	};
   622 
   623 	/** 
   624 	 * @brief Contains callbacks for menu actions.
   625 	 */
   626 	class IMenuHandler
   627 	{
   628 	public:
   629 		/**
   630 		 * @brief Returns the menu api verison.
   631 		 *
   632 		 * @return				Menu API version.
   633 		 */
   634 		virtual unsigned int GetMenuAPIVersion2()
   635 		{
   636 			return SMINTERFACE_MENUMANAGER_VERSION;
   637 		}
   638 
   639 		/** 
   640 		 * @brief A display/selection cycle has started.
   641 		 *
   642 		 * @param menu			Menu pointer.
   643 		 */
   644 		virtual void OnMenuStart(IBaseMenu *menu)
   645 		{
   646 		}
   647 
   648 		/**
   649 		 * @brief Called before a menu is being displayed.  This is where
   650 		 * you can set an alternate title on the menu.
   651 		 *
   652 		 * @param menu			Menu pointer.
   653 		 * @param client		Client index.
   654 		 * @param display		IMenuPanel pointer.
   655 		 */
   656 		virtual void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display)
   657 		{
   658 		}
   659 
   660 		/**
   661 		 * @brief Called when an item is selected.
   662 		 *
   663 		 * @param menu			Menu pointer.
   664 		 * @param client		Client that selected the item.
   665 		 * @param item			Item number.
   666 		 */
   667 		virtual void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
   668 		{
   669 		}
   670 
   671 		/**
   672 		 * @brief An active menu display was dropped from a client.
   673 		 *
   674 		 * @param menu			Menu pointer.
   675 		 * @param client		Client that had the menu.
   676 		 * @param reason		Menu cancellation reason.
   677 		 */
   678 		virtual void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
   679 		{
   680 		}
   681 
   682 		/**
   683 		 * @brief A display/selection cycle has ended.
   684 		 *
   685 		 * @param menu			Menu pointer.
   686 		 * @param reason		MenuEndReason reason.
   687 		 */
   688 		virtual void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason)
   689 		{
   690 		}
   691 
   692 		/**
   693 		 * @brief Called when the menu object is destroyed.
   694 		 *
   695 		 * @param menu			Menu pointer.
   696 		 */
   697 		virtual void OnMenuDestroy(IBaseMenu *menu)
   698 		{
   699 		}
   700 
   701 		/**
   702 		 * @brief Called when requesting how to render an item.
   703 		 *
   704 		 * @param menu			Menu pointer.
   705 		 * @param client		Client index receiving the menu.
   706 		 * @param item			Item number in the menu.
   707 		 * @param style			ITEMSTYLE flags, by reference for modification.
   708 		 */
   709 		virtual void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style)
   710 		{
   711 		}
   712 
   713 		/**
   714 		 * @brief Called when drawing item text.
   715 		 *
   716 		 * @param menu			Menu pointer.
   717 		 * @param client		Client index receiving the menu.
   718 		 * @param panel			Panel being used to draw the menu.
   719 		 * @param item			Item number in the menu.
   720 		 * @param dr			Item draw information.
   721 		 * @return				0 to let the render algorithm decide how to draw, otherwise,
   722 		 *						the return value from panel->DrawItem should be returned.
   723 		 */
   724 		virtual unsigned int OnMenuDisplayItem(IBaseMenu *menu, 
   725 											   int client, 
   726 											   IMenuPanel *panel,
   727 											   unsigned int item, 
   728 											   const ItemDrawInfo &dr)
   729 		{
   730 			return 0;
   731 		}
   732 
   733 		/**
   734 		 * @brief Called when a vote has been started and displayed to 
   735 		 * clients.  This is called after OnMenuStart() and OnMenuDisplay(),
   736 		 * but before OnMenuSelect().
   737 		 *
   738 		 * @param menu			Menu pointer.
   739 		 */
   740 		virtual void OnMenuVoteStart(IBaseMenu *menu)
   741 		{
   742 		}
   743 
   744 		/**
   745 		 * @brief Called when a vote ends.  This is automatically called by the 
   746 		 * wrapper, and never needs to called from a style implementation.  
   747 		 *
   748 		 * This function does not replace OnMenuEnd(), nor does it have the 
   749 		 * same meaning as OnMenuEnd(), meaning you should not destroy a menu
   750 		 * while it is in this function.
   751 		 *
   752 		 * @param menu			Menu pointer.
   753 		 * @param results		Menu vote results.
   754 		 */
   755 		virtual void OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *results)
   756 		{
   757 		}
   758 
   759 		/**
   760 		 * @brief Called when a vote is cancelled.  If this is called, then 
   761 		 * OnMenuVoteResults() will not be called.  In both cases, OnMenuEnd will 
   762 		 * always be called.
   763 		 *
   764 		 * @param menu			Menu pointer.
   765 		 * @param reason		VoteCancelReason reason.
   766 		 */
   767 		virtual void OnMenuVoteCancel(IBaseMenu *menu, VoteCancelReason reason)
   768 		{
   769 		}
   770 
   771 		/**
   772 		 * @brief Call to set private handler stuff.
   773 		 *
   774 		 * @param option		Option name.
   775 		 * @param data			Private data.
   776 		 * @return				True if set, false if invalid or unrecognized.
   777 		 */
   778 		virtual bool OnSetHandlerOption(const char *option, const void *data)
   779 		{
   780 			return false;
   781 		}
   782 
   783 		/**
   784 		 * @brief Called when an item is selected.
   785 		 *
   786 		 * Note: This callback was added in v13.  It is called after OnMenuSelect().
   787 		 *
   788 		 * @param menu			Menu pointer.
   789 		 * @param client		Client that selected the item.
   790 		 * @param item			Item number.
   791 		 * @param item_on_page	The first item on the page the player was last 
   792 		 *						viewing.
   793 		 */
   794 		virtual void OnMenuSelect2(IBaseMenu *menu,
   795 			int client,
   796 			unsigned int item,
   797 			unsigned int item_on_page)
   798 		{
   799 		}
   800 	};
   801 
   802 	/**
   803 	 * @brief Manages menu creation and displaying.
   804 	 */
   805 	class IMenuManager : public SMInterface
   806 	{
   807 	public:
   808 		virtual const char *GetInterfaceName()
   809 		{
   810 			return SMINTERFACE_MENUMANAGER_NAME;
   811 		}
   812 		virtual unsigned int GetInterfaceVersion()
   813 		{
   814 			return SMINTERFACE_MENUMANAGER_VERSION;
   815 		}
   816 		virtual bool IsVersionCompatible(unsigned int version)
   817 		{
   818 			if (version < 11 || version > GetInterfaceVersion())
   819 			{
   820 				return false;
   821 			}
   822 			return true;
   823 		}
   824 	public:
   825 		/**
   826 		 * @brief Finds a style by name.
   827 		 *
   828 		 * @param name			Name of the style (case insensitive).
   829 		 * @return				IMenuStyle pointer, or NULL if not found.
   830 		 */
   831 		virtual IMenuStyle *FindStyleByName(const char *name) =0;
   832 
   833 		/**
   834 		 * @brief Returns the default draw style Core is using.
   835 		 *
   836 		 * @return				Menu style pointer.
   837 		 */
   838 		virtual IMenuStyle *GetDefaultStyle() =0;
   839 
   840 		/**
   841 		 * @brief Given a set of menu states, converts it to an IMenuPanel object.
   842 		 *
   843 		 * The state parameter is both INPUT and OUTPUT.
   844 		 * INPUT: menu, mh, firstItem, lastItem
   845 		 * OUTPUT: display, firstItem, lastItem, slots
   846 		 *
   847 		 * @param client		Client index.
   848 		 * @param states		Menu states.
   849 		 * @param order			Order to search for items.
   850 		 * @return				IMenuPanel pointer, or NULL if no items could be 
   851 		 *						found in the IBaseMenu pointer, or NULL if any
   852 		 *						other error occurred.  Any valid pointer must
   853 		 *						be freed using IMenuPanel::DeleteThis.
   854 		 */
   855 		virtual IMenuPanel *RenderMenu(int client, menu_states_t &states, ItemOrder order) =0;
   856 
   857 		/**
   858 		 * @brief Cancels a menu.  Calls IBaseMenu::Cancel() after doing some preparatory 
   859 		 * work.  This should always be used instead of directly calling Cancel().
   860 		 *
   861 		 * @param menu			IBaseMenu pointer.
   862 		 */
   863 		virtual void CancelMenu(IBaseMenu *menu) =0;
   864 
   865 		/**
   866 		 * @brief Displays a menu as a vote.
   867 		 *
   868 		 * @param menu			IBaseMenu pointer.
   869 		 * @param num_clients	Number of clients to display to.
   870 		 * @param clients		Client index array.
   871 		 * @param max_time		Maximum time to hold menu for.
   872 		 * @param flags			Vote flags (currently unused).
   873 		 * @return				True on success, false if a vote is in progress.
   874 		 */
   875 		virtual bool StartVote(IBaseMenu *menu,
   876 								unsigned int num_clients,
   877 								int clients[],
   878 								unsigned int max_time,
   879 								unsigned int flags=0) =0;
   880 
   881 		/**
   882 		 * @brief Returns whether or not a vote is in progress.
   883 		 *
   884 		 * @return				True if a vote is in progress, false otherwise.
   885 		 */
   886 		virtual bool IsVoteInProgress() =0;
   887 
   888 		/**
   889 		 * @brief Cancels the vote in progress.  This calls IBaseMenu::Cancel().
   890 		 */
   891 		virtual void CancelVoting() =0;
   892 
   893 		/**
   894 		 * @brief Returns the remaining vote delay from the last menu.  This delay is 
   895 		 * a suggestion for all public votes, and is not enforced.
   896 		 *
   897 		 * @return				Number of seconds to wait.
   898 		 */
   899 		virtual unsigned int GetRemainingVoteDelay() =0;
   900 
   901 		/**
   902 		 * @brief Returns whether a client is in the "allowed to vote" pool determined 
   903 		 * by the initial call to StartVote().
   904 		 *
   905 		 * @param client		Client index.
   906 		 * @return				True if client is allowed to vote, false on failure.
   907 		 */
   908 		virtual bool IsClientInVotePool(int client) =0;
   909 
   910 		/**
   911 		 * @brief Redraws the current vote menu to a client in the voting pool.
   912 		 *
   913 		 * @param client		Client index.
   914 		 * @return				True on success, false if client is not allowed to vote.
   915 		 */
   916 		virtual bool RedrawClientVoteMenu(int client) =0;
   917 	};
   918 }
   919 
   920 #endif //_INCLUDE_SOURCEMOD_MENU_SYSTEM_H_