public/IMenuManager.h
author David Anderson <dvander@alliedmods.net>
Fri Nov 16 01:27:38 2007 +0000 (2007-11-16)
changeset 1679 5374868c0f6a
parent 1678 aad21f87ee38
child 1766 d30c252089be
permissions -rw-r--r--
another minor doxytypo
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 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		13
    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 	/**
   329 	 * @brief Describes a "MenuStyle" system which manages
   330 	 * menu drawing and construction.
   331 	 */
   332 	class IMenuStyle
   333 	{
   334 	public:
   335 		/**
   336 		 * @brief Returns the style API version.
   337 		 *
   338 		 * @return				API version.
   339 		 */
   340 		virtual unsigned int GetStyleAPIVersion()
   341 		{
   342 			return SMINTERFACE_MENUMANAGER_VERSION;
   343 		}
   344 
   345 		/**
   346 		 * @brief Returns the name of the menu style.
   347 		 *
   348 		 * @return				String containing the style name.
   349 		 */
   350 		virtual const char *GetStyleName() =0;
   351 
   352 		/**
   353 		 * @brief Creates an IMenuPanel object.
   354 		 *
   355 		 * Note: the object should be freed using ::DeleteThis.
   356 		 *
   357 		 * @return				IMenuPanel object.
   358 		 */
   359 		virtual IMenuPanel *CreatePanel() =0;
   360 
   361 		/**
   362 		 * @brief Creates an IBaseMenu object of this style.
   363 		 *
   364 		 * Note: the object should be freed using IBaseMenu::Destroy.
   365 		 *
   366 		 * @param handler		IMenuHandler pointer.
   367 		 * @param pOwner		Optional IdentityToken_t owner for handle 
   368 		 *						creation.
   369 		 * @return				An IBaseMenu pointer.
   370 		 */
   371 		virtual IBaseMenu *CreateMenu(IMenuHandler *handler, IdentityToken_t *pOwner=NULL) =0;
   372 
   373 		/**
   374 		 * @brief Returns the maximum number of items per page.
   375 		 *
   376 		 * Menu implementations must return >= 2.  Styles with only 1 or 0 
   377 		 * items per page are not valid.
   378 		 *
   379 		 * @return				Number of items per page.
   380 		 */
   381 		virtual unsigned int GetMaxPageItems() =0;
   382 
   383 		/**
   384 		 * @brief Returns whether or not a client is viewing a menu.
   385 		 *
   386 		 * @param client		Client index.
   387 		 * @param object		Optional pointer to retrieve menu object,
   388 		 *						if any.
   389 		 * @return				MenuSource value.
   390 		 */
   391 		virtual MenuSource GetClientMenu(int client, void **object) =0;
   392 
   393 		/**
   394 		 * @brief Cancels a client's menu.
   395 		 *
   396 		 * @param client		Client index.
   397 		 * @param autoIgnore	If true, no menus can be created during 
   398 		 *						the cancellation process.
   399 		 * @return				True if a menu was cancelled, false otherwise.
   400 		 */
   401 		virtual bool CancelClientMenu(int client, bool autoIgnore=false) =0;
   402 
   403 		/**
   404 		 * @brief Returns a Handle the IMenuStyle object.
   405 		 *
   406 		 * @return				Handle_t pointing to this object.
   407 		 */
   408 		virtual Handle_t GetHandle() =0;
   409 	};
   410 
   411 	/**
   412 	 * @brief High-level interface for building menus.
   413 	 */
   414 	class IBaseMenu
   415 	{
   416 	public:
   417 		/**
   418 		 * @brief Appends an item to the end of a menu.
   419 		 *
   420 		 * @param info			Item information string.
   421 		 * @param draw			Default drawing information.
   422 		 * @return				True on success, false on item limit reached.
   423 		 */
   424 		virtual bool AppendItem(const char *info, const ItemDrawInfo &draw) =0;
   425 
   426 		/**
   427 		 * @brief Inserts an item into the menu before a certain position; 
   428 		 * the new item will be at the given position and all next items 
   429 		 * pushed forward.
   430 		 *
   431 		 * @param position		Position, starting from 0.
   432 		 * @param info			Item information string.
   433 		 * @param draw			Default item draw info.
   434 		 * @return				True on success, false on invalid menu position
   435 		 */
   436 		virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw) =0;
   437 
   438 		/**
   439 		 * @brief Removes an item from the menu.
   440 		 *
   441 		 * @param position		Position, starting from 0.
   442 		 * @return				True on success, false on invalid menu position.
   443 		 */
   444 		virtual bool RemoveItem(unsigned int position) =0;
   445 
   446 		/**
   447 		 * @brief Removes all items from the menu.
   448 		 */
   449 		virtual void RemoveAllItems() =0;
   450 
   451 		/**
   452 		 * @brief Returns an item's info.
   453 		 *
   454 		 * @param position		Position, starting from 0.
   455 		 * @param draw			Optional pointer to store a draw information.
   456 		 * @return				Info string pointer, or NULL if position was invalid.
   457 		 */
   458 		virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw) =0;
   459 
   460 		/**
   461 		 * @brief Returns the number of items.
   462 		 *
   463 		 * @return				Number of items in the menu.
   464 		 */
   465 		virtual unsigned int GetItemCount() =0;
   466 
   467 		/** 
   468 		 * @brief Sets the menu's pagination,.
   469 		 *
   470 		 * If pagination is set to MENU_NO_PAGINATION, and the previous 
   471 		 * pagination was not MENU_NO_PAGINATION, then the MENUFLAG_BUTTON_EXIT 
   472 		 * is unset.  It can be re-applied if desired.
   473 		 *
   474 		 * @param itemsPerPage	Number of items per page, or MENU_NO_PAGINATION.
   475 		 * @return				True on success, false if itemsPerPage is too 
   476 		 *						large.
   477 		 */
   478 		virtual bool SetPagination(unsigned int itemsPerPage) =0;
   479 
   480 		/**
   481 		 * @brief Returns an item's pagination.
   482 		 *
   483 		 * @return				Pagination setting.
   484 		 */
   485 		virtual unsigned int GetPagination() =0;
   486 
   487 		/**
   488 		 * @brief Returns the menu style.
   489 		 * 
   490 		 * @return				Menu style.
   491 		 */
   492 		virtual IMenuStyle *GetDrawStyle() =0;
   493 
   494 		/**
   495 		 * @brief Sets the menu's display title/message.
   496 		 *
   497 		 * @param message		Message (format options allowed).
   498 		 */
   499 		virtual void SetDefaultTitle(const char *message) =0;
   500 
   501 		/**
   502 		 * @brief Returns the menu's display/title message.
   503 		 *
   504 		 * @return				Message string.
   505 		 */
   506 		virtual const char *GetDefaultTitle() =0;
   507 
   508 		/**
   509 		 * @brief Sets an extended menu option.
   510 		 *
   511 		 * @param option		Option type.
   512 		 * @param valuePtr		Pointer of the type expected by the option.
   513 		 * @return				True on success, false if option or value is not supported.
   514 		 */
   515 		virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
   516 
   517 		/**
   518 		 * @brief Creates a new IMenuPanel object using extended options specific
   519 		 * to the IMenuStyle parent.  Titles, items, etc, are not copied.
   520 		 *
   521 		 * Note: The object should be freed with IMenuPanel::DeleteThis.
   522 		 *
   523 		 * @return				IMenuPanel pointer.
   524 		 */
   525 		virtual IMenuPanel *CreatePanel() =0;
   526 
   527 		/**
   528 		 * @brief Sends the menu to a client.
   529 		 *
   530 		 * @param client		Client index to display to.
   531 		 * @param time			Time to hold menu for.
   532 		 * @param alt_handler	Alternate IMenuHandler.
   533 		 * @return				True on success, false otherwise.
   534 		 */
   535 		virtual bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL) =0;
   536 
   537 		/**
   538 		 * @brief Destroys the menu and frees all associated resources.
   539 		 *
   540 		 * @param releaseHandle	If true, the Handle will be released
   541 		 *						in the destructor.  This should be set
   542 		 *						to true except for IHandleTypeDispatch
   543 		 *						destructors.
   544 		 */
   545 		virtual void Destroy(bool releaseHandle=true) =0;
   546 
   547 		/**
   548 		 * @brief Cancels the menu on all client's displays.  While the menu is
   549 		 * being cancelled, the menu may not be re-displayed to any clients.
   550 		 * If a vote menu is currently active, it will be cancelled as well.
   551 		 *
   552 		 * @return				Number of menus cancelled.
   553 		 */
   554 		virtual void Cancel() =0;
   555 
   556 		/**
   557 		 * @brief Returns the menu's Handle.  The Handle is automatically
   558 		 * removed when the menu is destroyed.
   559 		 *
   560 		 * @return				Handle_t handle value.
   561 		 */
   562 		virtual Handle_t GetHandle() =0;
   563 		
   564 		/**
   565 		 * @brief Returns menu option flags.
   566 		 *
   567 		 * @return				Menu option flags.
   568 		 */
   569 		virtual unsigned int GetMenuOptionFlags() =0;
   570 
   571 		/**
   572 		 * @brief Sets menu option flags.
   573 		 *
   574 		 * @param flags			Menu option flags.
   575 		 */
   576 		virtual void SetMenuOptionFlags(unsigned int flags) =0;
   577 
   578 		/**
   579 		 * @brief Returns the menu's handler.
   580 		 *
   581 		 * @return				IMenuHandler of the menu.
   582 		 */
   583 		virtual IMenuHandler *GetHandler() =0;
   584 
   585 		/**
   586 		 * @brief Sends the menu to a client, starting from the given item number. 
   587 		 *
   588 		 * Note: this API call was added in v13.
   589 		 *
   590 		 * @param client		Client index to display to.
   591 		 * @param time			Time to hold menu for.
   592 		 * @param start_item	Starting item to draw.
   593 		 * @param alt_handler	Alternate IMenuHandler.
   594 		 * @return				True on success, false otherwise.
   595 		 */
   596 		virtual bool DisplayAtItem(int client,
   597 			unsigned int time,
   598 			unsigned int start_item,
   599 			IMenuHandler *alt_handler=NULL) =0;
   600 	};
   601 
   602 	/** 
   603 	 * @brief Contains callbacks for menu actions.
   604 	 */
   605 	class IMenuHandler
   606 	{
   607 	public:
   608 		/**
   609 		 * @brief Returns the menu api verison.
   610 		 *
   611 		 * @return				Menu API version.
   612 		 */
   613 		virtual unsigned int GetMenuAPIVersion2()
   614 		{
   615 			return SMINTERFACE_MENUMANAGER_VERSION;
   616 		}
   617 
   618 		/** 
   619 		 * @brief A display/selection cycle has started.
   620 		 *
   621 		 * @param menu			Menu pointer.
   622 		 */
   623 		virtual void OnMenuStart(IBaseMenu *menu)
   624 		{
   625 		}
   626 
   627 		/**
   628 		 * @brief Called before a menu is being displayed.  This is where
   629 		 * you can set an alternate title on the menu.
   630 		 *
   631 		 * @param menu			Menu pointer.
   632 		 * @param client		Client index.
   633 		 * @param display		IMenuPanel pointer.
   634 		 */
   635 		virtual void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display)
   636 		{
   637 		}
   638 
   639 		/**
   640 		 * @brief Called when an item is selected.
   641 		 *
   642 		 * @param menu			Menu pointer.
   643 		 * @param client		Client that selected the item.
   644 		 * @param item			Item number.
   645 		 */
   646 		virtual void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
   647 		{
   648 		}
   649 
   650 		/**
   651 		 * @brief An active menu display was dropped from a client.
   652 		 *
   653 		 * @param menu			Menu pointer.
   654 		 * @param client		Client that had the menu.
   655 		 * @param reason		Menu cancellation reason.
   656 		 */
   657 		virtual void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
   658 		{
   659 		}
   660 
   661 		/**
   662 		 * @brief A display/selection cycle has ended.
   663 		 *
   664 		 * @param menu			Menu pointer.
   665 		 * @param reason		MenuEndReason reason.
   666 		 */
   667 		virtual void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason)
   668 		{
   669 		}
   670 
   671 		/**
   672 		 * @brief Called when the menu object is destroyed.
   673 		 *
   674 		 * @param menu			Menu pointer.
   675 		 */
   676 		virtual void OnMenuDestroy(IBaseMenu *menu)
   677 		{
   678 		}
   679 
   680 		/**
   681 		 * @brief Called when requesting how to render an item.
   682 		 *
   683 		 * @param menu			Menu pointer.
   684 		 * @param client		Client index receiving the menu.
   685 		 * @param item			Item number in the menu.
   686 		 * @param style			ITEMSTYLE flags, by reference for modification.
   687 		 */
   688 		virtual void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style)
   689 		{
   690 		}
   691 
   692 		/**
   693 		 * @brief Called when drawing item text.
   694 		 *
   695 		 * @param menu			Menu pointer.
   696 		 * @param client		Client index receiving the menu.
   697 		 * @param panel			Panel being used to draw the menu.
   698 		 * @param item			Item number in the menu.
   699 		 * @param dr			Item draw information.
   700 		 * @return				0 to let the render algorithm decide how to draw, otherwise,
   701 		 *						the return value from panel->DrawItem should be returned.
   702 		 */
   703 		virtual unsigned int OnMenuDisplayItem(IBaseMenu *menu, 
   704 											   int client, 
   705 											   IMenuPanel *panel,
   706 											   unsigned int item, 
   707 											   const ItemDrawInfo &dr)
   708 		{
   709 			return 0;
   710 		}
   711 
   712 		/**
   713 		 * @brief Called when a vote has been started and displayed to 
   714 		 * clients.  This is called after OnMenuStart() and OnMenuDisplay(),
   715 		 * but before OnMenuSelect().
   716 		 *
   717 		 * @param menu			Menu pointer.
   718 		 */
   719 		virtual void OnMenuVoteStart(IBaseMenu *menu)
   720 		{
   721 		}
   722 
   723 		/**
   724 		 * @brief Called when a vote ends.  This is automatically called by the 
   725 		 * wrapper, and never needs to called from a style implementation.  
   726 		 *
   727 		 * This function does not replace OnMenuEnd(), nor does it have the 
   728 		 * same meaning as OnMenuEnd(), meaning you should not destroy a menu
   729 		 * while it is in this function.
   730 		 *
   731 		 * @param menu			Menu pointer.
   732 		 * @param results		Menu vote results.
   733 		 */
   734 		virtual void OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *results)
   735 		{
   736 		}
   737 
   738 		/**
   739 		 * @brief Called when a vote is cancelled.  If this is called, then 
   740 		 * OnMenuVoteResults() will not be called.  In both cases, OnMenuEnd will 
   741 		 * always be called.
   742 		 *
   743 		 * @param menu			Menu pointer.
   744 		 * @param reason		VoteCancelReason reason.
   745 		 */
   746 		virtual void OnMenuVoteCancel(IBaseMenu *menu, VoteCancelReason reason)
   747 		{
   748 		}
   749 
   750 		/**
   751 		 * @brief Call to set private handler stuff.
   752 		 *
   753 		 * @param option		Option name.
   754 		 * @param data			Private data.
   755 		 * @return				True if set, false if invalid or unrecognized.
   756 		 */
   757 		virtual bool OnSetHandlerOption(const char *option, const void *data)
   758 		{
   759 			return false;
   760 		}
   761 
   762 		/**
   763 		 * @brief Called when an item is selected.
   764 		 *
   765 		 * Note: This callback was added in v13.  It is called after OnMenuSelect().
   766 		 *
   767 		 * @param menu			Menu pointer.
   768 		 * @param client		Client that selected the item.
   769 		 * @param item			Item number.
   770 		 * @param item_on_page	The first item on the page the player was last 
   771 		 *						viewing.
   772 		 */
   773 		virtual void OnMenuSelect2(IBaseMenu *menu,
   774 			int client,
   775 			unsigned int item,
   776 			unsigned int item_on_page)
   777 		{
   778 		}
   779 	};
   780 
   781 	/**
   782 	 * @brief Manages menu creation and displaying.
   783 	 */
   784 	class IMenuManager : public SMInterface
   785 	{
   786 	public:
   787 		virtual const char *GetInterfaceName()
   788 		{
   789 			return SMINTERFACE_MENUMANAGER_NAME;
   790 		}
   791 		virtual unsigned int GetInterfaceVersion()
   792 		{
   793 			return SMINTERFACE_MENUMANAGER_VERSION;
   794 		}
   795 		virtual bool IsVersionCompatible(unsigned int version)
   796 		{
   797 			if (version < 11 || version > GetInterfaceVersion())
   798 			{
   799 				return false;
   800 			}
   801 			return true;
   802 		}
   803 	public:
   804 		/**
   805 		 * @brief Finds a style by name.
   806 		 *
   807 		 * @param name			Name of the style (case insensitive).
   808 		 * @return				IMenuStyle pointer, or NULL if not found.
   809 		 */
   810 		virtual IMenuStyle *FindStyleByName(const char *name) =0;
   811 
   812 		/**
   813 		 * @brief Returns the default draw style Core is using.
   814 		 *
   815 		 * @return				Menu style pointer.
   816 		 */
   817 		virtual IMenuStyle *GetDefaultStyle() =0;
   818 
   819 		/**
   820 		 * @brief Given a set of menu states, converts it to an IMenuPanel object.
   821 		 *
   822 		 * The state parameter is both INPUT and OUTPUT.
   823 		 * INPUT: menu, mh, firstItem, lastItem
   824 		 * OUTPUT: display, firstItem, lastItem, slots
   825 		 *
   826 		 * @param client		Client index.
   827 		 * @param states		Menu states.
   828 		 * @param order			Order to search for items.
   829 		 * @return				IMenuPanel pointer, or NULL if no items could be 
   830 		 *						found in the IBaseMenu pointer, or NULL if any
   831 		 *						other error occurred.  Any valid pointer must
   832 		 *						be freed using IMenuPanel::DeleteThis.
   833 		 */
   834 		virtual IMenuPanel *RenderMenu(int client, menu_states_t &states, ItemOrder order) =0;
   835 
   836 		/**
   837 		 * @brief Cancels a menu.  Calls IBaseMenu::Cancel() after doing some preparatory 
   838 		 * work.  This should always be used instead of directly calling Cancel().
   839 		 *
   840 		 * @param menu			IBaseMenu pointer.
   841 		 */
   842 		virtual void CancelMenu(IBaseMenu *menu) =0;
   843 
   844 		/**
   845 		 * @brief Displays a menu as a vote.
   846 		 *
   847 		 * @param menu			IBaseMenu pointer.
   848 		 * @param num_clients	Number of clients to display to.
   849 		 * @param clients		Client index array.
   850 		 * @param max_time		Maximum time to hold menu for.
   851 		 * @param flags			Vote flags (currently unused).
   852 		 * @return				True on success, false if a vote is in progress.
   853 		 */
   854 		virtual bool StartVote(IBaseMenu *menu,
   855 								unsigned int num_clients,
   856 								int clients[],
   857 								unsigned int max_time,
   858 								unsigned int flags=0) =0;
   859 
   860 		/**
   861 		 * @brief Returns whether or not a vote is in progress.
   862 		 *
   863 		 * @return				True if a vote is in progress, false otherwise.
   864 		 */
   865 		virtual bool IsVoteInProgress() =0;
   866 
   867 		/**
   868 		 * @brief Cancels the vote in progress.  This calls IBaseMenu::Cancel().
   869 		 */
   870 		virtual void CancelVoting() =0;
   871 
   872 		/**
   873 		 * @brief Returns the remaining vote delay from the last menu.  This delay is 
   874 		 * a suggestion for all public votes, and is not enforced.
   875 		 *
   876 		 * @return				Number of seconds to wait.
   877 		 */
   878 		virtual unsigned int GetRemainingVoteDelay() =0;
   879 	};
   880 }
   881 
   882 #endif //_INCLUDE_SOURCEMOD_MENU_SYSTEM_H_