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