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