core/MenuManager.cpp
author David Anderson <dvander@alliedmods.net>
Mon Sep 29 20:02:19 2008 -0700 (2008-09-29)
changeset 2335 cf312a67fb8f
parent 2289 44045ead61cd
child 2737 eb7713d87fa1
permissions -rw-r--r--
Fixed OnConfigsExecuted() not working on listen servers (bug 3287, r=me).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #include <time.h>
    33 #include <stdarg.h>
    34 #include <stdlib.h>
    35 #include "MenuManager.h"
    36 #include "MenuVoting.h"
    37 #include "sm_stringutil.h"
    38 #include "sourcemm_api.h"
    39 #include "PlayerManager.h"
    40 #include "MenuStyle_Valve.h"
    41 #include "ShareSys.h"
    42 #include "HandleSys.h"
    43 #include "sourcemm_api.h"
    44 #include "Translator.h"
    45 
    46 MenuManager g_Menus;
    47 VoteMenuHandler s_VoteHandler;
    48 
    49 ConVar sm_menu_sounds("sm_menu_sounds", "1", 0, "Sets whether SourceMod menus play trigger sounds");
    50 
    51 MenuManager::MenuManager()
    52 {
    53 	m_Styles.push_back(&g_ValveMenuStyle);
    54 	SetDefaultStyle(&g_ValveMenuStyle);
    55 }
    56 
    57 void MenuManager::OnSourceModAllInitialized()
    58 {
    59 	g_ShareSys.AddInterface(NULL, this);
    60 
    61 	HandleAccess access;
    62 	g_HandleSys.InitAccessDefaults(NULL, &access);
    63 
    64 	/* Deny cloning to menus */
    65 	access.access[HandleAccess_Clone] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
    66 	m_MenuType = g_HandleSys.CreateType("IBaseMenu", this, 0, NULL, &access, g_pCoreIdent, NULL);
    67 
    68 	/* Also deny deletion to styles */
    69 	access.access[HandleAccess_Delete] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
    70 	m_StyleType = g_HandleSys.CreateType("IMenuStyle", this, 0, NULL, &access, g_pCoreIdent, NULL);
    71 }
    72 
    73 void MenuManager::OnSourceModAllShutdown()
    74 {
    75 	g_HandleSys.RemoveType(m_MenuType, g_pCoreIdent);
    76 	g_HandleSys.RemoveType(m_StyleType, g_pCoreIdent);
    77 }
    78 
    79 void MenuManager::OnHandleDestroy(HandleType_t type, void *object)
    80 {
    81 	if (type == m_MenuType)
    82 	{
    83 		IBaseMenu *menu = (IBaseMenu *)object;
    84 		menu->Destroy(false);
    85 	}
    86 	else if (type == m_StyleType)
    87 	{
    88 		/* Do nothing */
    89 	}
    90 }
    91 
    92 bool MenuManager::GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize)
    93 {
    94 	if (type == m_MenuType)
    95 	{
    96 		*pSize = ((IBaseMenu *)object)->GetApproxMemUsage();
    97 		return true;
    98 	}
    99 	else
   100 	{
   101 		*pSize = ((IMenuStyle *)object)->GetApproxMemUsage();
   102 		return true;
   103 	}
   104 
   105 	return false;
   106 }
   107 
   108 Handle_t MenuManager::CreateMenuHandle(IBaseMenu *menu, IdentityToken_t *pOwner)
   109 {
   110 	if (m_MenuType == NO_HANDLE_TYPE)
   111 	{
   112 		return BAD_HANDLE;
   113 	}
   114 
   115 	return g_HandleSys.CreateHandle(m_MenuType, menu, pOwner, g_pCoreIdent, NULL);
   116 }
   117 
   118 Handle_t MenuManager::CreateStyleHandle(IMenuStyle *style)
   119 {
   120 	if (m_StyleType == NO_HANDLE_TYPE)
   121 	{
   122 		return BAD_HANDLE;
   123 	}
   124 
   125 	return g_HandleSys.CreateHandle(m_StyleType, style, g_pCoreIdent, g_pCoreIdent, NULL);
   126 }
   127 
   128 HandleError MenuManager::ReadMenuHandle(Handle_t handle, IBaseMenu **menu)
   129 {
   130 	HandleSecurity sec;
   131 
   132 	sec.pIdentity = g_pCoreIdent;
   133 	sec.pOwner = NULL;
   134 
   135 	return g_HandleSys.ReadHandle(handle, m_MenuType, &sec, (void **)menu);
   136 }
   137 
   138 HandleError MenuManager::ReadStyleHandle(Handle_t handle, IMenuStyle **style)
   139 {
   140 	HandleSecurity sec;
   141 
   142 	sec.pIdentity = g_pCoreIdent;
   143 	sec.pOwner = g_pCoreIdent;
   144 
   145 	return g_HandleSys.ReadHandle(handle, m_StyleType, &sec, (void **)style);
   146 }
   147 
   148 bool MenuManager::SetDefaultStyle(IMenuStyle *style)
   149 {
   150 	if (!style)
   151 	{
   152 		return false;
   153 	}
   154 
   155 	m_pDefaultStyle = style;
   156 
   157 	return true;
   158 }
   159 
   160 IMenuStyle *MenuManager::GetStyle(unsigned int index)
   161 {
   162 	if (index >= GetStyleCount())
   163 	{
   164 		return NULL;
   165 	}
   166 
   167 	return m_Styles[index];
   168 }
   169 
   170 void MenuManager::AddStyle(IMenuStyle *style)
   171 {
   172 	m_Styles.push_back(style);
   173 }
   174 
   175 unsigned int MenuManager::GetStyleCount()
   176 {
   177 	return (unsigned int)m_Styles.size();
   178 }
   179 
   180 IMenuStyle *MenuManager::FindStyleByName(const char *name)
   181 {
   182 	unsigned int count = GetStyleCount();
   183 	for (unsigned int i=0; i<count; i++)
   184 	{
   185 		IMenuStyle *ptr = GetStyle(i);
   186 		if (strcasecmp(ptr->GetStyleName(), name) == 0)
   187 		{
   188 			return ptr;
   189 		}
   190 	}
   191 
   192 	return NULL;
   193 }
   194 
   195 inline bool IsSlotItem(IMenuPanel *display,
   196 					   unsigned int style)
   197 {
   198 	if (!display->CanDrawItem(style))
   199 	{
   200 	return false;
   201 	}
   202 	if ((style & ITEMDRAW_IGNORE) == ITEMDRAW_IGNORE)
   203 	{
   204 		return false;
   205 	}
   206 	if (style & ITEMDRAW_RAWLINE)
   207 	{
   208 		return false;
   209 	}
   210 
   211 	return true;
   212 }
   213 
   214 IMenuPanel *MenuManager::RenderMenu(int client, menu_states_t &md, ItemOrder order)
   215 {
   216 	IBaseMenu *menu = md.menu;
   217 
   218 	if (!menu)
   219 	{
   220 		return NULL;
   221 	}
   222 
   223 	struct
   224 	{
   225 		unsigned int position;
   226 		ItemDrawInfo draw;
   227 	} drawItems[10];
   228 
   229 	/* Figure out how many items to draw */
   230 	IMenuStyle *style = menu->GetDrawStyle();
   231 	unsigned int pgn = menu->GetPagination();
   232 	unsigned int maxItems = style->GetMaxPageItems();
   233 	bool exitButton = (menu->GetMenuOptionFlags() & MENUFLAG_BUTTON_EXIT) == MENUFLAG_BUTTON_EXIT;
   234 
   235 	if (pgn != MENU_NO_PAGINATION)
   236 	{
   237 		maxItems = pgn;
   238 	}
   239 	else if (exitButton)
   240 	{
   241 		maxItems--;
   242 	}
   243 
   244 	/* This is very not allowed! */
   245 	if (maxItems < 2)
   246 	{
   247 		return NULL;
   248 	}
   249 
   250 	unsigned int totalItems = menu->GetItemCount();
   251 	unsigned int startItem = 0;
   252 
   253 	/* For pagination, find the starting point. */
   254 	if (pgn != MENU_NO_PAGINATION)
   255 	{
   256 		if (order == ItemOrder_Ascending)
   257 		{
   258 			startItem = md.lastItem;
   259 			/* This shouldn't happen with well-coded menus.
   260 			 * If the item is out of bounds, switch the order to
   261 			 * Items_Descending and make us start from the top.
   262 			 */
   263 			if (startItem >= totalItems)
   264 			{
   265 				startItem = totalItems - 1;
   266 				order = ItemOrder_Descending;
   267 			}
   268 		}
   269 		else if (order == ItemOrder_Descending)
   270 		{
   271 			startItem = md.firstItem;
   272 			/* This shouldn't happen with well-coded menus.
   273 			 * If searching backwards doesn't give us enough room,
   274 			 * start from the beginning and change to ascending.
   275 			 */
   276 			if (startItem <= maxItems)
   277 			{
   278 				startItem = 0;
   279 				order = ItemOrder_Ascending;
   280 			}
   281 		}
   282 	}
   283 
   284 	/* Get our Display pointer and initialize some crap */
   285 	IMenuPanel *panel = menu->CreatePanel();
   286 	IMenuHandler *mh = md.mh;
   287 	bool foundExtra = false;
   288 	unsigned int extraItem = 0;
   289 
   290 	if (panel == NULL)
   291 	{
   292 		return NULL;
   293 	}
   294 
   295 	/**
   296 	 * We keep searching until:
   297 	 * 1) There are no more items
   298 	 * 2) We reach one OVER the maximum number of slot items
   299 	 * 3) We have reached maxItems and pagination is MENU_NO_PAGINATION
   300 	 */
   301 	unsigned int i = startItem;
   302 	unsigned int foundItems = 0;
   303 	while (totalItems)
   304 	{
   305 		ItemDrawInfo &dr = drawItems[foundItems].draw;
   306 		/* Is the item valid? */
   307 		if (menu->GetItemInfo(i, &dr) != NULL)
   308 		{
   309 			/* Ask the user to change the style, if necessary */
   310 			mh->OnMenuDrawItem(menu, client, i, dr.style);
   311 			/* Check if it's renderable */
   312 			if (IsSlotItem(panel, dr.style))
   313 			{
   314 				/* If we've already found the max number of items,
   315 				 * This means we should just cancel out and log our
   316 				 * "last item."
   317 				 */
   318 				if (foundItems >= maxItems)
   319 				{
   320 					foundExtra = true;
   321 					extraItem = i;
   322 					break;
   323 				}
   324 				drawItems[foundItems++].position = i;
   325 			}
   326 		}
   327 		/* If there's no pagination, stop once the menu is full. */
   328 		if (pgn == MENU_NO_PAGINATION)
   329 		{
   330 			/* If we've filled up, then stop */
   331 			if (foundItems >= maxItems)
   332 			{
   333 				break;
   334 			}
   335 		}
   336 		/* If we're descending and this is the first item, stop */
   337 		if (order == ItemOrder_Descending)
   338 		{
   339 			if (i == 0)
   340 			{
   341 				break;
   342 			}
   343 			i--;
   344 		} 
   345 		/* If we're ascending and this is the last item, stop */
   346 		else if (order == ItemOrder_Ascending)
   347 		{
   348 			if (i >= totalItems - 1)
   349 			{
   350 				break;
   351 			}
   352 			i++;
   353 		}
   354 	}
   355 
   356 	/* There were no items to draw! */
   357 	if (!foundItems)
   358 	{
   359 		panel->DeleteThis();
   360 		return NULL;
   361 	}
   362 
   363 	bool displayPrev = false;
   364 	bool displayNext = false;
   365 
   366 	/* This is an annoying process.
   367 	 * Skip it for non-paginated menus, which get special treatment.
   368 	 */
   369 	if (pgn != MENU_NO_PAGINATION)
   370 	{
   371 		if (foundExtra)
   372 		{
   373 			if (order == ItemOrder_Descending)
   374 			{
   375 				displayPrev = true;
   376 				md.firstItem = extraItem;
   377 			}
   378 			else if (order == ItemOrder_Ascending)
   379 			{
   380 				displayNext = true;
   381 				md.lastItem = extraItem;
   382 			}
   383 		}
   384 
   385 		unsigned int lastItem = 0;
   386 		ItemDrawInfo dr;
   387 		/* Find the last feasible item to search from. */
   388 		if (order == ItemOrder_Descending)
   389 		{
   390 			lastItem = drawItems[0].position;
   391 			if (lastItem >= totalItems - 1)
   392 			{
   393 				goto skip_search;
   394 			}
   395 			while (++lastItem < totalItems)
   396 			{
   397 				if (menu->GetItemInfo(lastItem, &dr) != NULL)
   398 				{
   399 					mh->OnMenuDrawItem(menu, client, lastItem, dr.style);
   400 					if (IsSlotItem(panel, dr.style))
   401 					{
   402 						displayNext = true;
   403 						md.lastItem = lastItem;
   404 						break;
   405 					}
   406 				}
   407 			}
   408 		}
   409 		else if (order == ItemOrder_Ascending)
   410 		{
   411 			lastItem = drawItems[0].position;
   412 			if (lastItem == 0)
   413 			{
   414 				goto skip_search;
   415 			}
   416 			lastItem--;
   417 			while (lastItem != 0)
   418 			{
   419 				if (menu->GetItemInfo(lastItem, &dr) != NULL)
   420 				{
   421 					mh->OnMenuDrawItem(menu, client, lastItem, dr.style);
   422 					if (IsSlotItem(panel, dr.style))
   423 					{
   424 						displayPrev = true;
   425 						md.firstItem = lastItem;
   426 						break;
   427 					}
   428 				}
   429 				lastItem--;
   430 			}
   431 		}
   432 	}
   433 
   434 skip_search:
   435 
   436 	/* Draw the item according to the order */
   437 	menu_slots_t *slots = md.slots;
   438 	unsigned int position = 0;			/* Keep track of the last position */
   439 	if (order == ItemOrder_Ascending)
   440 	{
   441 		md.item_on_page = drawItems[0].position;
   442 		for (unsigned int i = 0; i < foundItems; i++)
   443 		{
   444 			ItemDrawInfo &dr = drawItems[i].draw;
   445 			if ((position = mh->OnMenuDisplayItem(menu, client, panel, drawItems[i].position, dr)) == 0)
   446 			{
   447 				position = panel->DrawItem(dr);
   448 			}
   449 			if (position != 0)
   450 			{
   451 				slots[position].item = drawItems[i].position;
   452 				if ((dr.style & ITEMDRAW_DISABLED) == ITEMDRAW_DISABLED)
   453 				{
   454 					slots[position].type = ItemSel_None;
   455 				}
   456 				else
   457 				{
   458 					slots[position].type = ItemSel_Item;
   459 				}
   460 			}
   461 		}
   462 	}
   463 	else if (order == ItemOrder_Descending)
   464 	{
   465 		unsigned int i = foundItems;
   466 		/* NOTE: There will always be at least one item because
   467 		 * of the check earlier.
   468 		 */
   469 		md.item_on_page = drawItems[foundItems - 1].position;
   470 		while (i--)
   471 		{
   472 			ItemDrawInfo &dr = drawItems[i].draw;
   473 			if ((position = mh->OnMenuDisplayItem(menu, client, panel, drawItems[i].position, dr)) == 0)
   474 			{
   475 				position = panel->DrawItem(dr);
   476 			}
   477 			if (position != 0)
   478 			{
   479 				slots[position].item = drawItems[i].position;
   480 				if ((dr.style & ITEMDRAW_DISABLED) == ITEMDRAW_DISABLED)
   481 				{
   482 					slots[position].type = ItemSel_None;
   483 				}
   484 				else
   485 				{
   486 					slots[position].type = ItemSel_Item;
   487 				}
   488 			}
   489 		}
   490 	}
   491 
   492 	/* Now, we need to check if we need to add anything extra */
   493 	if (pgn != MENU_NO_PAGINATION || exitButton)
   494 	{
   495 		bool canDrawDisabled = panel->CanDrawItem(ITEMDRAW_DISABLED|ITEMDRAW_CONTROL);
   496 		bool exitBackButton = false;
   497 		char text[50];
   498 
   499 		if (pgn != MENU_NO_PAGINATION
   500 			&& (menu->GetMenuOptionFlags() & MENUFLAG_BUTTON_EXITBACK) == MENUFLAG_BUTTON_EXITBACK)
   501 		{
   502 			exitBackButton = true;
   503 		}
   504 
   505 		/* Calculate how many items we are allowed for control stuff */
   506 		unsigned int padding = style->GetMaxPageItems() - maxItems;
   507 		
   508 		/* Add the number of available slots */
   509 		padding += (maxItems - foundItems);
   510 
   511 		/* Someday, if we are able to re-enable this, we will be very lucky men. */
   512 #if 0
   513 		if (!style->FeatureExists(MenuStyleFeature_ImplicitExit))
   514 		{
   515 #endif
   516 		/* Even if we don't draw an exit button, we invalidate the slot. */
   517 		padding--;
   518 #if 0
   519 		} else {
   520 			/* Otherwise, we don't draw anything and leave the slot available */
   521 			exitButton = false;
   522 		}
   523 #endif
   524 
   525 		if (pgn != MENU_NO_PAGINATION)
   526 		{
   527 			/* Subtract two slots for the displayNext/displayPrev padding */
   528 			padding -= 2;
   529 		}
   530 
   531 		/* If we have an "Exit Back" button and the space to draw it, do so. */
   532 		if (exitBackButton)
   533 		{
   534 			if (!displayPrev)
   535 			{
   536 				displayPrev = true;
   537 			}
   538 			else
   539 			{
   540 				exitBackButton = false;
   541 			}
   542 		}
   543 
   544 		/**
   545 		 * We allow next/prev to be undrawn if neither exists.
   546 		 * Thus, we only need padding if one of them will be drawn,
   547 		 * or the exit button will be drawn.
   548 		 */
   549 		ItemDrawInfo padItem(NULL, ITEMDRAW_SPACER);
   550 		if (exitButton || (displayNext || displayPrev))
   551 		{
   552 			/* If there are no control options,
   553 			 * Instead just pad with invisible slots.
   554 			 */
   555 			if (!displayPrev && !displayPrev)
   556 			{
   557 				padItem.style = ITEMDRAW_NOTEXT;
   558 			}
   559 			/* Add spacers so we can pad to the end */
   560 			for (unsigned int i=0; i<padding; i++)
   561 			{
   562 				position = panel->DrawItem(padItem);
   563 				slots[position].type = ItemSel_None;
   564 			}
   565 		}
   566 
   567 		/* Put a fake spacer before control stuff, if possible */
   568 		if ((displayPrev || displayNext) || exitButton)
   569 		{
   570 			ItemDrawInfo draw("", ITEMDRAW_RAWLINE|ITEMDRAW_SPACER);
   571 			panel->DrawItem(draw);
   572 		}
   573 
   574 		ItemDrawInfo dr(text, 0);
   575 
   576 		/**
   577 		 * If we have one or the other, we need to have spacers for both.
   578 		 */
   579 		if (pgn != MENU_NO_PAGINATION)
   580 		{
   581 			if (displayPrev || displayNext)
   582 			{
   583 				/* PREVIOUS */
   584 				ItemDrawInfo padCtrlItem(NULL, ITEMDRAW_SPACER|ITEMDRAW_CONTROL);
   585 				if (displayPrev || canDrawDisabled)
   586 				{
   587 					if (exitBackButton)
   588 					{
   589 						if (!CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Back", &client))
   590 						{
   591 							UTIL_Format(text, sizeof(text), "Back");
   592 						}
   593 						dr.style = ITEMDRAW_CONTROL;
   594 						position = panel->DrawItem(dr);
   595 						slots[position].type = ItemSel_ExitBack;
   596 					}
   597 					else
   598 					{
   599 						if (!CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Previous", &client))
   600 						{
   601 							UTIL_Format(text, sizeof(text), "Previous");
   602 						}
   603 						dr.style = (displayPrev ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
   604 						position = panel->DrawItem(dr);
   605 						slots[position].type = ItemSel_Back;
   606 					}
   607 				}
   608 				else if (displayNext || exitButton)
   609 				{
   610 					/* If we can't display this, and there is an exit button,
   611 					 * we need to pad!
   612 					 */
   613 					position = panel->DrawItem(padCtrlItem);
   614 					slots[position].type = ItemSel_None;
   615 				}
   616 
   617 				/* NEXT */
   618 				if (displayNext || canDrawDisabled)
   619 				{
   620 					if (!CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Next", &client))
   621 					{
   622 						UTIL_Format(text, sizeof(text), "Next");
   623 					}
   624 					dr.style = (displayNext ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
   625 					position = panel->DrawItem(dr);
   626 					slots[position].type = ItemSel_Next;
   627 				}
   628 				else if (exitButton)
   629 				{
   630 					/* If we can't display this,
   631 					 * but there is an "exit" button, we need to pad!
   632 					 */
   633 					position = panel->DrawItem(padCtrlItem);
   634 					slots[position].type = ItemSel_None;
   635 				}
   636 			}
   637 			else
   638 			{
   639 				/* Otherwise, bump to two slots! */
   640 				ItemDrawInfo numBump(NULL, ITEMDRAW_NOTEXT);
   641 				position = panel->DrawItem(numBump);
   642 				slots[position].type = ItemSel_None;
   643 				position = panel->DrawItem(numBump);
   644 				slots[position].type = ItemSel_None;
   645 			}
   646 		}
   647 
   648 		/* EXIT */
   649 		if (exitButton)
   650 		{
   651 			if (!CoreTranslate(text, sizeof(text), "%T", 2, NULL, "Exit", &client))
   652 			{
   653 				UTIL_Format(text, sizeof(text), "Exit");
   654 			}
   655 			dr.style = ITEMDRAW_CONTROL;
   656 			position = panel->DrawItem(dr);
   657 			slots[position].type = ItemSel_Exit;
   658 		}
   659 	}
   660 
   661 	/* Lastly, fill in any slots we could have missed */
   662 	for (unsigned int i = position + 1; i < 10; i++)
   663 	{
   664 		slots[i].type = ItemSel_None;
   665 	}
   666 
   667 	/* Do title stuff */
   668 	mh->OnMenuDisplay(menu, client, panel);
   669 	panel->DrawTitle(menu->GetDefaultTitle(), true);
   670 
   671 	return panel;
   672 }
   673 
   674 IMenuStyle *MenuManager::GetDefaultStyle()
   675 {
   676 	return m_pDefaultStyle;
   677 }
   678 
   679 bool MenuManager::MenuSoundsEnabled()
   680 {
   681 	return (sm_menu_sounds.GetInt() != 0);
   682 }
   683 
   684 ConfigResult MenuManager::OnSourceModConfigChanged(const char *key,
   685 												   const char *value,
   686 												   ConfigSource source,
   687 												   char *error,
   688 												   size_t maxlength)
   689 {
   690 	if (strcmp(key, "MenuItemSound") == 0)
   691 	{
   692 		m_SelectSound.assign(value);
   693 		return ConfigResult_Accept;
   694 	} else if (strcmp(key, "MenuExitBackSound") == 0) {
   695 		m_ExitBackSound.assign(value);
   696 		return ConfigResult_Accept;
   697 	} else if (strcmp(key, "MenuExitSound") == 0) {
   698 		m_ExitSound.assign(value);
   699 		return ConfigResult_Accept;
   700 	}
   701 
   702 	return ConfigResult_Ignore;
   703 }
   704 
   705 const char *MenuManager::GetMenuSound(ItemSelection sel)
   706 {
   707 	const char *sound = NULL;
   708 
   709 	switch (sel)
   710 	{
   711 	case ItemSel_Back:
   712 	case ItemSel_Next:
   713 	case ItemSel_Item:
   714 		{
   715 			if (m_SelectSound.size() > 0)
   716 			{
   717 				sound = m_SelectSound.c_str();
   718 			}
   719 			break;
   720 		}
   721 	case ItemSel_ExitBack:
   722 		{
   723 			if (m_ExitBackSound.size() > 0)
   724 			{
   725 				sound = m_ExitBackSound.c_str();
   726 			}
   727 			break;
   728 		}
   729 	case ItemSel_Exit:
   730 		{
   731 			if (m_ExitSound.size() > 0)
   732 			{
   733 				sound = m_ExitSound.c_str();
   734 			}
   735 			break;
   736 		}
   737 	default:
   738 		{
   739 			break;
   740 		}
   741 	}
   742 
   743 	return sound;
   744 }
   745 
   746 void MenuManager::OnSourceModLevelChange(const char *mapName)
   747 {
   748 	if (m_SelectSound.size() > 0)
   749 	{
   750 		enginesound->PrecacheSound(m_SelectSound.c_str(), true);
   751 	}
   752 	if (m_ExitBackSound.size() > 0)
   753 	{
   754 		enginesound->PrecacheSound(m_ExitBackSound.c_str(), true);
   755 	}
   756 	if (m_ExitSound.size() > 0)
   757 	{
   758 		enginesound->PrecacheSound(m_ExitSound.c_str(), true);
   759 	}
   760 }
   761 
   762 void MenuManager::CancelMenu(IBaseMenu *menu)
   763 {
   764 	if (s_VoteHandler.GetCurrentMenu() == menu
   765 		&& !s_VoteHandler.IsCancelling())
   766 	{
   767 		s_VoteHandler.CancelVoting();
   768 		return;
   769 	}
   770 
   771 	menu->Cancel();
   772 }
   773 
   774 bool MenuManager::StartVote(IBaseMenu *menu, unsigned int num_clients, int clients[], unsigned int max_time, unsigned int flags)
   775 {
   776 	return s_VoteHandler.StartVote(menu, num_clients, clients, max_time, flags);
   777 }
   778 
   779 bool MenuManager::IsVoteInProgress()
   780 {
   781 	return s_VoteHandler.IsVoteInProgress();
   782 }
   783 
   784 void MenuManager::CancelVoting()
   785 {
   786 	s_VoteHandler.CancelVoting();
   787 }
   788 
   789 unsigned int MenuManager::GetRemainingVoteDelay()
   790 {
   791 	return s_VoteHandler.GetRemainingVoteDelay();
   792 }
   793 
   794 bool MenuManager::IsClientInVotePool(int client)
   795 {
   796 	return s_VoteHandler.IsClientInVotePool(client);
   797 }
   798 
   799 bool MenuManager::RedrawClientVoteMenu(int client)
   800 {
   801 	return s_VoteHandler.RedrawToClient(client);
   802 }