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