core/MenuManager.cpp
changeset 1952 b7aa2b626807
child 2042 4a2faafca477
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/MenuManager.cpp	Sun Mar 30 07:00:22 2008 +0000
     1.3 @@ -0,0 +1,779 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod
     1.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     1.9 + * =============================================================================
    1.10 + *
    1.11 + * This program is free software; you can redistribute it and/or modify it under
    1.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 + * Free Software Foundation.
    1.14 + * 
    1.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 + * details.
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License along with
    1.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 + *
    1.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 + * or <http://www.sourcemod.net/license.php>.
    1.31 + *
    1.32 + * Version: $Id$
    1.33 + */
    1.34 +
    1.35 +#include <time.h>
    1.36 +#include <stdarg.h>
    1.37 +#include <stdlib.h>
    1.38 +#include "MenuManager.h"
    1.39 +#include "MenuVoting.h"
    1.40 +#include "sm_stringutil.h"
    1.41 +#include "sourcemm_api.h"
    1.42 +#include "PlayerManager.h"
    1.43 +#include "MenuStyle_Valve.h"
    1.44 +#include "ShareSys.h"
    1.45 +#include "HandleSys.h"
    1.46 +#include "sourcemm_api.h"
    1.47 +
    1.48 +MenuManager g_Menus;
    1.49 +VoteMenuHandler s_VoteHandler;
    1.50 +
    1.51 +ConVar sm_menu_sounds("sm_menu_sounds", "1", 0, "Sets whether SourceMod menus play trigger sounds");
    1.52 +
    1.53 +MenuManager::MenuManager()
    1.54 +{
    1.55 +	m_Styles.push_back(&g_ValveMenuStyle);
    1.56 +	SetDefaultStyle(&g_ValveMenuStyle);
    1.57 +}
    1.58 +
    1.59 +void MenuManager::OnSourceModAllInitialized()
    1.60 +{
    1.61 +	g_ShareSys.AddInterface(NULL, this);
    1.62 +
    1.63 +	HandleAccess access;
    1.64 +	g_HandleSys.InitAccessDefaults(NULL, &access);
    1.65 +
    1.66 +	/* Deny cloning to menus */
    1.67 +	access.access[HandleAccess_Clone] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
    1.68 +	m_MenuType = g_HandleSys.CreateType("IBaseMenu", this, 0, NULL, &access, g_pCoreIdent, NULL);
    1.69 +
    1.70 +	/* Also deny deletion to styles */
    1.71 +	access.access[HandleAccess_Delete] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
    1.72 +	m_StyleType = g_HandleSys.CreateType("IMenuStyle", this, 0, NULL, &access, g_pCoreIdent, NULL);
    1.73 +}
    1.74 +
    1.75 +void MenuManager::OnSourceModAllShutdown()
    1.76 +{
    1.77 +	g_HandleSys.RemoveType(m_MenuType, g_pCoreIdent);
    1.78 +	g_HandleSys.RemoveType(m_StyleType, g_pCoreIdent);
    1.79 +}
    1.80 +
    1.81 +void MenuManager::OnHandleDestroy(HandleType_t type, void *object)
    1.82 +{
    1.83 +	if (type == m_MenuType)
    1.84 +	{
    1.85 +		IBaseMenu *menu = (IBaseMenu *)object;
    1.86 +		menu->Destroy(false);
    1.87 +	}
    1.88 +	else if (type == m_StyleType)
    1.89 +	{
    1.90 +		/* Do nothing */
    1.91 +	}
    1.92 +}
    1.93 +
    1.94 +bool MenuManager::GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize)
    1.95 +{
    1.96 +	if (type == m_MenuType)
    1.97 +	{
    1.98 +		*pSize = ((IBaseMenu *)object)->GetApproxMemUsage();
    1.99 +		return true;
   1.100 +	}
   1.101 +	else
   1.102 +	{
   1.103 +		*pSize = ((IMenuStyle *)object)->GetApproxMemUsage();
   1.104 +		return true;
   1.105 +	}
   1.106 +
   1.107 +	return false;
   1.108 +}
   1.109 +
   1.110 +Handle_t MenuManager::CreateMenuHandle(IBaseMenu *menu, IdentityToken_t *pOwner)
   1.111 +{
   1.112 +	if (m_MenuType == NO_HANDLE_TYPE)
   1.113 +	{
   1.114 +		return BAD_HANDLE;
   1.115 +	}
   1.116 +
   1.117 +	return g_HandleSys.CreateHandle(m_MenuType, menu, pOwner, g_pCoreIdent, NULL);
   1.118 +}
   1.119 +
   1.120 +Handle_t MenuManager::CreateStyleHandle(IMenuStyle *style)
   1.121 +{
   1.122 +	if (m_StyleType == NO_HANDLE_TYPE)
   1.123 +	{
   1.124 +		return BAD_HANDLE;
   1.125 +	}
   1.126 +
   1.127 +	return g_HandleSys.CreateHandle(m_StyleType, style, g_pCoreIdent, g_pCoreIdent, NULL);
   1.128 +}
   1.129 +
   1.130 +HandleError MenuManager::ReadMenuHandle(Handle_t handle, IBaseMenu **menu)
   1.131 +{
   1.132 +	HandleSecurity sec;
   1.133 +
   1.134 +	sec.pIdentity = g_pCoreIdent;
   1.135 +	sec.pOwner = NULL;
   1.136 +
   1.137 +	return g_HandleSys.ReadHandle(handle, m_MenuType, &sec, (void **)menu);
   1.138 +}
   1.139 +
   1.140 +HandleError MenuManager::ReadStyleHandle(Handle_t handle, IMenuStyle **style)
   1.141 +{
   1.142 +	HandleSecurity sec;
   1.143 +
   1.144 +	sec.pIdentity = g_pCoreIdent;
   1.145 +	sec.pOwner = g_pCoreIdent;
   1.146 +
   1.147 +	return g_HandleSys.ReadHandle(handle, m_StyleType, &sec, (void **)style);
   1.148 +}
   1.149 +
   1.150 +bool MenuManager::SetDefaultStyle(IMenuStyle *style)
   1.151 +{
   1.152 +	if (!style)
   1.153 +	{
   1.154 +		return false;
   1.155 +	}
   1.156 +
   1.157 +	m_pDefaultStyle = style;
   1.158 +
   1.159 +	return true;
   1.160 +}
   1.161 +
   1.162 +IMenuStyle *MenuManager::GetStyle(unsigned int index)
   1.163 +{
   1.164 +	if (index >= GetStyleCount())
   1.165 +	{
   1.166 +		return NULL;
   1.167 +	}
   1.168 +
   1.169 +	return m_Styles[index];
   1.170 +}
   1.171 +
   1.172 +void MenuManager::AddStyle(IMenuStyle *style)
   1.173 +{
   1.174 +	m_Styles.push_back(style);
   1.175 +}
   1.176 +
   1.177 +unsigned int MenuManager::GetStyleCount()
   1.178 +{
   1.179 +	return (unsigned int)m_Styles.size();
   1.180 +}
   1.181 +
   1.182 +IMenuStyle *MenuManager::FindStyleByName(const char *name)
   1.183 +{
   1.184 +	unsigned int count = GetStyleCount();
   1.185 +	for (unsigned int i=0; i<count; i++)
   1.186 +	{
   1.187 +		IMenuStyle *ptr = GetStyle(i);
   1.188 +		if (strcasecmp(ptr->GetStyleName(), name) == 0)
   1.189 +		{
   1.190 +			return ptr;
   1.191 +		}
   1.192 +	}
   1.193 +
   1.194 +	return NULL;
   1.195 +}
   1.196 +
   1.197 +inline bool IsSlotItem(IMenuPanel *display,
   1.198 +					   unsigned int style)
   1.199 +{
   1.200 +	if (!display->CanDrawItem(style))
   1.201 +	{
   1.202 +	return false;
   1.203 +	}
   1.204 +	if ((style & ITEMDRAW_IGNORE) == ITEMDRAW_IGNORE)
   1.205 +	{
   1.206 +		return false;
   1.207 +	}
   1.208 +	if (style & ITEMDRAW_RAWLINE)
   1.209 +	{
   1.210 +		return false;
   1.211 +	}
   1.212 +
   1.213 +	return true;
   1.214 +}
   1.215 +
   1.216 +IMenuPanel *MenuManager::RenderMenu(int client, menu_states_t &md, ItemOrder order)
   1.217 +{
   1.218 +	IBaseMenu *menu = md.menu;
   1.219 +
   1.220 +	if (!menu)
   1.221 +	{
   1.222 +		return NULL;
   1.223 +	}
   1.224 +
   1.225 +	struct
   1.226 +	{
   1.227 +		unsigned int position;
   1.228 +		ItemDrawInfo draw;
   1.229 +	} drawItems[10];
   1.230 +
   1.231 +	/* Figure out how many items to draw */
   1.232 +	IMenuStyle *style = menu->GetDrawStyle();
   1.233 +	unsigned int pgn = menu->GetPagination();
   1.234 +	unsigned int maxItems = style->GetMaxPageItems();
   1.235 +	bool exitButton = (menu->GetMenuOptionFlags() & MENUFLAG_BUTTON_EXIT) == MENUFLAG_BUTTON_EXIT;
   1.236 +
   1.237 +	if (pgn != MENU_NO_PAGINATION)
   1.238 +	{
   1.239 +		maxItems = pgn;
   1.240 +	}
   1.241 +	else if (exitButton)
   1.242 +	{
   1.243 +		maxItems--;
   1.244 +	}
   1.245 +
   1.246 +	/* This is very not allowed! */
   1.247 +	if (maxItems < 2)
   1.248 +	{
   1.249 +		return NULL;
   1.250 +	}
   1.251 +
   1.252 +	unsigned int totalItems = menu->GetItemCount();
   1.253 +	unsigned int startItem = 0;
   1.254 +
   1.255 +	/* For pagination, find the starting point. */
   1.256 +	if (pgn != MENU_NO_PAGINATION)
   1.257 +	{
   1.258 +		if (order == ItemOrder_Ascending)
   1.259 +		{
   1.260 +			startItem = md.lastItem;
   1.261 +			/* This shouldn't happen with well-coded menus.
   1.262 +			 * If the item is out of bounds, switch the order to
   1.263 +			 * Items_Descending and make us start from the top.
   1.264 +			 */
   1.265 +			if (startItem >= totalItems)
   1.266 +			{
   1.267 +				startItem = totalItems - 1;
   1.268 +				order = ItemOrder_Descending;
   1.269 +			}
   1.270 +		}
   1.271 +		else if (order == ItemOrder_Descending)
   1.272 +		{
   1.273 +			startItem = md.firstItem;
   1.274 +			/* This shouldn't happen with well-coded menus.
   1.275 +			 * If searching backwards doesn't give us enough room,
   1.276 +			 * start from the beginning and change to ascending.
   1.277 +			 */
   1.278 +			if (startItem <= maxItems)
   1.279 +			{
   1.280 +				startItem = 0;
   1.281 +				order = ItemOrder_Ascending;
   1.282 +			}
   1.283 +		}
   1.284 +	}
   1.285 +
   1.286 +	/* Get our Display pointer and initialize some crap */
   1.287 +	IMenuPanel *panel = menu->CreatePanel();
   1.288 +	IMenuHandler *mh = md.mh;
   1.289 +	bool foundExtra = false;
   1.290 +	unsigned int extraItem = 0;
   1.291 +
   1.292 +	if (panel == NULL)
   1.293 +	{
   1.294 +		return NULL;
   1.295 +	}
   1.296 +
   1.297 +	/**
   1.298 +	 * We keep searching until:
   1.299 +	 * 1) There are no more items
   1.300 +	 * 2) We reach one OVER the maximum number of slot items
   1.301 +	 * 3) We have reached maxItems and pagination is MENU_NO_PAGINATION
   1.302 +	 */
   1.303 +	unsigned int i = startItem;
   1.304 +	unsigned int foundItems = 0;
   1.305 +	while (totalItems)
   1.306 +	{
   1.307 +		ItemDrawInfo &dr = drawItems[foundItems].draw;
   1.308 +		/* Is the item valid? */
   1.309 +		if (menu->GetItemInfo(i, &dr) != NULL)
   1.310 +		{
   1.311 +			/* Ask the user to change the style, if necessary */
   1.312 +			mh->OnMenuDrawItem(menu, client, i, dr.style);
   1.313 +			/* Check if it's renderable */
   1.314 +			if (IsSlotItem(panel, dr.style))
   1.315 +			{
   1.316 +				/* If we've already found the max number of items,
   1.317 +				 * This means we should just cancel out and log our
   1.318 +				 * "last item."
   1.319 +				 */
   1.320 +				if (foundItems >= maxItems)
   1.321 +				{
   1.322 +					foundExtra = true;
   1.323 +					extraItem = i;
   1.324 +					break;
   1.325 +				}
   1.326 +				drawItems[foundItems++].position = i;
   1.327 +			}
   1.328 +		}
   1.329 +		/* If there's no pagination, stop once the menu is full. */
   1.330 +		if (pgn == MENU_NO_PAGINATION)
   1.331 +		{
   1.332 +			/* If we've filled up, then stop */
   1.333 +			if (foundItems >= maxItems)
   1.334 +			{
   1.335 +				break;
   1.336 +			}
   1.337 +		}
   1.338 +		/* If we're descending and this is the first item, stop */
   1.339 +		if (order == ItemOrder_Descending)
   1.340 +		{
   1.341 +			if (i == 0)
   1.342 +			{
   1.343 +				break;
   1.344 +			}
   1.345 +			i--;
   1.346 +		} 
   1.347 +		/* If we're ascending and this is the last item, stop */
   1.348 +		else if (order == ItemOrder_Ascending)
   1.349 +		{
   1.350 +			if (i >= totalItems - 1)
   1.351 +			{
   1.352 +				break;
   1.353 +			}
   1.354 +			i++;
   1.355 +		}
   1.356 +	}
   1.357 +
   1.358 +	/* There were no items to draw! */
   1.359 +	if (!foundItems)
   1.360 +	{
   1.361 +		panel->DeleteThis();
   1.362 +		return NULL;
   1.363 +	}
   1.364 +
   1.365 +	bool displayPrev = false;
   1.366 +	bool displayNext = false;
   1.367 +
   1.368 +	/* This is an annoying process.
   1.369 +	 * Skip it for non-paginated menus, which get special treatment.
   1.370 +	 */
   1.371 +	if (pgn != MENU_NO_PAGINATION)
   1.372 +	{
   1.373 +		if (foundExtra)
   1.374 +		{
   1.375 +			if (order == ItemOrder_Descending)
   1.376 +			{
   1.377 +				displayPrev = true;
   1.378 +				md.firstItem = extraItem;
   1.379 +			}
   1.380 +			else if (order == ItemOrder_Ascending)
   1.381 +			{
   1.382 +				displayNext = true;
   1.383 +				md.lastItem = extraItem;
   1.384 +			}
   1.385 +		}
   1.386 +
   1.387 +		unsigned int lastItem = 0;
   1.388 +		ItemDrawInfo dr;
   1.389 +		/* Find the last feasible item to search from. */
   1.390 +		if (order == ItemOrder_Descending)
   1.391 +		{
   1.392 +			lastItem = drawItems[0].position;
   1.393 +			if (lastItem >= totalItems - 1)
   1.394 +			{
   1.395 +				goto skip_search;
   1.396 +			}
   1.397 +			while (++lastItem < totalItems)
   1.398 +			{
   1.399 +				if (menu->GetItemInfo(lastItem, &dr) != NULL)
   1.400 +				{
   1.401 +					mh->OnMenuDrawItem(menu, client, lastItem, dr.style);
   1.402 +					if (IsSlotItem(panel, dr.style))
   1.403 +					{
   1.404 +						displayNext = true;
   1.405 +						md.lastItem = lastItem;
   1.406 +						break;
   1.407 +					}
   1.408 +				}
   1.409 +			}
   1.410 +		}
   1.411 +		else if (order == ItemOrder_Ascending)
   1.412 +		{
   1.413 +			lastItem = drawItems[0].position;
   1.414 +			if (lastItem == 0)
   1.415 +			{
   1.416 +				goto skip_search;
   1.417 +			}
   1.418 +			lastItem--;
   1.419 +			while (lastItem != 0)
   1.420 +			{
   1.421 +				if (menu->GetItemInfo(lastItem, &dr) != NULL)
   1.422 +				{
   1.423 +					mh->OnMenuDrawItem(menu, client, lastItem, dr.style);
   1.424 +					if (IsSlotItem(panel, dr.style))
   1.425 +					{
   1.426 +						displayPrev = true;
   1.427 +						md.firstItem = lastItem;
   1.428 +						break;
   1.429 +					}
   1.430 +				}
   1.431 +				lastItem--;
   1.432 +			}
   1.433 +		}
   1.434 +	}
   1.435 +
   1.436 +skip_search:
   1.437 +
   1.438 +	/* Draw the item according to the order */
   1.439 +	menu_slots_t *slots = md.slots;
   1.440 +	unsigned int position = 0;			/* Keep track of the last position */
   1.441 +	if (order == ItemOrder_Ascending)
   1.442 +	{
   1.443 +		md.item_on_page = drawItems[0].position;
   1.444 +		for (unsigned int i = 0; i < foundItems; i++)
   1.445 +		{
   1.446 +			ItemDrawInfo &dr = drawItems[i].draw;
   1.447 +			if ((position = mh->OnMenuDisplayItem(menu, client, panel, drawItems[i].position, dr)) == 0)
   1.448 +			{
   1.449 +				position = panel->DrawItem(dr);
   1.450 +			}
   1.451 +			if (position != 0)
   1.452 +			{
   1.453 +				slots[position].item = drawItems[i].position;
   1.454 +				if ((dr.style & ITEMDRAW_DISABLED) == ITEMDRAW_DISABLED)
   1.455 +				{
   1.456 +					slots[position].type = ItemSel_None;
   1.457 +				}
   1.458 +				else
   1.459 +				{
   1.460 +					slots[position].type = ItemSel_Item;
   1.461 +				}
   1.462 +			}
   1.463 +		}
   1.464 +	}
   1.465 +	else if (order == ItemOrder_Descending)
   1.466 +	{
   1.467 +		unsigned int i = foundItems;
   1.468 +		/* NOTE: There will always be at least one item because
   1.469 +		 * of the check earlier.
   1.470 +		 */
   1.471 +		md.item_on_page = drawItems[foundItems - 1].position;
   1.472 +		while (i--)
   1.473 +		{
   1.474 +			ItemDrawInfo &dr = drawItems[i].draw;
   1.475 +			if ((position = mh->OnMenuDisplayItem(menu, client, panel, drawItems[i].position, dr)) == 0)
   1.476 +			{
   1.477 +				position = panel->DrawItem(dr);
   1.478 +			}
   1.479 +			if (position != 0)
   1.480 +			{
   1.481 +				slots[position].item = drawItems[i].position;
   1.482 +				if ((dr.style & ITEMDRAW_DISABLED) == ITEMDRAW_DISABLED)
   1.483 +				{
   1.484 +					slots[position].type = ItemSel_None;
   1.485 +				}
   1.486 +				else
   1.487 +				{
   1.488 +					slots[position].type = ItemSel_Item;
   1.489 +				}
   1.490 +			}
   1.491 +		}
   1.492 +	}
   1.493 +
   1.494 +	/* Now, we need to check if we need to add anything extra */
   1.495 +	if (pgn != MENU_NO_PAGINATION || exitButton)
   1.496 +	{
   1.497 +		bool canDrawDisabled = panel->CanDrawItem(ITEMDRAW_DISABLED|ITEMDRAW_CONTROL);
   1.498 +		bool exitBackButton = false;
   1.499 +		char text[50];
   1.500 +
   1.501 +		if (pgn != MENU_NO_PAGINATION
   1.502 +			&& (menu->GetMenuOptionFlags() & MENUFLAG_BUTTON_EXITBACK) == MENUFLAG_BUTTON_EXITBACK)
   1.503 +		{
   1.504 +			exitBackButton = true;
   1.505 +		}
   1.506 +
   1.507 +		/* Calculate how many items we are allowed for control stuff */
   1.508 +		unsigned int padding = style->GetMaxPageItems() - maxItems;
   1.509 +		
   1.510 +		/* Add the number of available slots */
   1.511 +		padding += (maxItems - foundItems);
   1.512 +
   1.513 +		/* Someday, if we are able to re-enable this, we will be very lucky men. */
   1.514 +#if 0
   1.515 +		if (!style->FeatureExists(MenuStyleFeature_ImplicitExit))
   1.516 +		{
   1.517 +#endif
   1.518 +		/* Even if we don't draw an exit button, we invalidate the slot. */
   1.519 +		padding--;
   1.520 +#if 0
   1.521 +		} else {
   1.522 +			/* Otherwise, we don't draw anything and leave the slot available */
   1.523 +			exitButton = false;
   1.524 +		}
   1.525 +#endif
   1.526 +
   1.527 +		if (pgn != MENU_NO_PAGINATION)
   1.528 +		{
   1.529 +			/* Subtract two slots for the displayNext/displayPrev padding */
   1.530 +			padding -= 2;
   1.531 +		}
   1.532 +
   1.533 +		/* If we have an "Exit Back" button and the space to draw it, do so. */
   1.534 +		if (exitBackButton)
   1.535 +		{
   1.536 +			if (!displayPrev)
   1.537 +			{
   1.538 +				displayPrev = true;
   1.539 +			}
   1.540 +			else
   1.541 +			{
   1.542 +				exitBackButton = false;
   1.543 +			}
   1.544 +		}
   1.545 +
   1.546 +		/**
   1.547 +		 * We allow next/prev to be undrawn if neither exists.
   1.548 +		 * Thus, we only need padding if one of them will be drawn,
   1.549 +		 * or the exit button will be drawn.
   1.550 +		 */
   1.551 +		ItemDrawInfo padItem(NULL, ITEMDRAW_SPACER);
   1.552 +		if (exitButton || (displayNext || displayPrev))
   1.553 +		{
   1.554 +			/* If there are no control options,
   1.555 +			 * Instead just pad with invisible slots.
   1.556 +			 */
   1.557 +			if (!displayPrev && !displayPrev)
   1.558 +			{
   1.559 +				padItem.style = ITEMDRAW_NOTEXT;
   1.560 +			}
   1.561 +			/* Add spacers so we can pad to the end */
   1.562 +			for (unsigned int i=0; i<padding; i++)
   1.563 +			{
   1.564 +				position = panel->DrawItem(padItem);
   1.565 +				slots[position].type = ItemSel_None;
   1.566 +			}
   1.567 +		}
   1.568 +
   1.569 +		/* Put a fake spacer before control stuff, if possible */
   1.570 +		if ((displayPrev || displayNext) || exitButton)
   1.571 +		{
   1.572 +			ItemDrawInfo draw("", ITEMDRAW_RAWLINE|ITEMDRAW_SPACER);
   1.573 +			panel->DrawItem(draw);
   1.574 +		}
   1.575 +
   1.576 +		ItemDrawInfo dr(text, 0);
   1.577 +
   1.578 +		/**
   1.579 +		 * If we have one or the other, we need to have spacers for both.
   1.580 +		 */
   1.581 +		if (pgn != MENU_NO_PAGINATION)
   1.582 +		{
   1.583 +			if (displayPrev || displayNext)
   1.584 +			{
   1.585 +				/* PREVIOUS */
   1.586 +				ItemDrawInfo padCtrlItem(NULL, ITEMDRAW_SPACER|ITEMDRAW_CONTROL);
   1.587 +				if (displayPrev || canDrawDisabled)
   1.588 +				{
   1.589 +					if (exitBackButton)
   1.590 +					{
   1.591 +						CorePlayerTranslate(client, text, sizeof(text), "Back", NULL);
   1.592 +						dr.style = ITEMDRAW_CONTROL;
   1.593 +						position = panel->DrawItem(dr);
   1.594 +						slots[position].type = ItemSel_ExitBack;
   1.595 +					}
   1.596 +					else
   1.597 +					{
   1.598 +						CorePlayerTranslate(client, text, sizeof(text), "Previous", NULL);
   1.599 +						dr.style = (displayPrev ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
   1.600 +						position = panel->DrawItem(dr);
   1.601 +						slots[position].type = ItemSel_Back;
   1.602 +					}
   1.603 +				}
   1.604 +				else if (displayNext || exitButton)
   1.605 +				{
   1.606 +					/* If we can't display this, and there is an exit button,
   1.607 +					 * we need to pad!
   1.608 +					 */
   1.609 +					position = panel->DrawItem(padCtrlItem);
   1.610 +					slots[position].type = ItemSel_None;
   1.611 +				}
   1.612 +
   1.613 +				/* NEXT */
   1.614 +				if (displayNext || canDrawDisabled)
   1.615 +				{
   1.616 +					CorePlayerTranslate(client, text, sizeof(text), "Next", NULL);
   1.617 +					dr.style = (displayNext ? 0 : ITEMDRAW_DISABLED)|ITEMDRAW_CONTROL;
   1.618 +					position = panel->DrawItem(dr);
   1.619 +					slots[position].type = ItemSel_Next;
   1.620 +				}
   1.621 +				else if (exitButton)
   1.622 +				{
   1.623 +					/* If we can't display this,
   1.624 +					 * but there is an "exit" button, we need to pad!
   1.625 +					 */
   1.626 +					position = panel->DrawItem(padCtrlItem);
   1.627 +					slots[position].type = ItemSel_None;
   1.628 +				}
   1.629 +			}
   1.630 +			else
   1.631 +			{
   1.632 +				/* Otherwise, bump to two slots! */
   1.633 +				ItemDrawInfo numBump(NULL, ITEMDRAW_NOTEXT);
   1.634 +				position = panel->DrawItem(numBump);
   1.635 +				slots[position].type = ItemSel_None;
   1.636 +				position = panel->DrawItem(numBump);
   1.637 +				slots[position].type = ItemSel_None;
   1.638 +			}
   1.639 +		}
   1.640 +
   1.641 +		/* EXIT */
   1.642 +		if (exitButton)
   1.643 +		{
   1.644 +			CorePlayerTranslate(client, text, sizeof(text), "Exit", NULL);
   1.645 +			dr.style = ITEMDRAW_CONTROL;
   1.646 +			position = panel->DrawItem(dr);
   1.647 +			slots[position].type = ItemSel_Exit;
   1.648 +		}
   1.649 +	}
   1.650 +
   1.651 +	/* Lastly, fill in any slots we could have missed */
   1.652 +	for (unsigned int i = position + 1; i < 10; i++)
   1.653 +	{
   1.654 +		slots[i].type = ItemSel_None;
   1.655 +	}
   1.656 +
   1.657 +	/* Do title stuff */
   1.658 +	mh->OnMenuDisplay(menu, client, panel);
   1.659 +	panel->DrawTitle(menu->GetDefaultTitle(), true);
   1.660 +
   1.661 +	return panel;
   1.662 +}
   1.663 +
   1.664 +IMenuStyle *MenuManager::GetDefaultStyle()
   1.665 +{
   1.666 +	return m_pDefaultStyle;
   1.667 +}
   1.668 +
   1.669 +bool MenuManager::MenuSoundsEnabled()
   1.670 +{
   1.671 +	return (sm_menu_sounds.GetInt() != 0);
   1.672 +}
   1.673 +
   1.674 +ConfigResult MenuManager::OnSourceModConfigChanged(const char *key,
   1.675 +												   const char *value,
   1.676 +												   ConfigSource source,
   1.677 +												   char *error,
   1.678 +												   size_t maxlength)
   1.679 +{
   1.680 +	if (strcmp(key, "MenuItemSound") == 0)
   1.681 +	{
   1.682 +		m_SelectSound.assign(value);
   1.683 +		return ConfigResult_Accept;
   1.684 +	} else if (strcmp(key, "MenuExitBackSound") == 0) {
   1.685 +		m_ExitBackSound.assign(value);
   1.686 +		return ConfigResult_Accept;
   1.687 +	} else if (strcmp(key, "MenuExitSound") == 0) {
   1.688 +		m_ExitSound.assign(value);
   1.689 +		return ConfigResult_Accept;
   1.690 +	}
   1.691 +
   1.692 +	return ConfigResult_Ignore;
   1.693 +}
   1.694 +
   1.695 +const char *MenuManager::GetMenuSound(ItemSelection sel)
   1.696 +{
   1.697 +	const char *sound = NULL;
   1.698 +
   1.699 +	switch (sel)
   1.700 +	{
   1.701 +	case ItemSel_Back:
   1.702 +	case ItemSel_Next:
   1.703 +	case ItemSel_Item:
   1.704 +		{
   1.705 +			if (m_SelectSound.size() > 0)
   1.706 +			{
   1.707 +				sound = m_SelectSound.c_str();
   1.708 +			}
   1.709 +			break;
   1.710 +		}
   1.711 +	case ItemSel_ExitBack:
   1.712 +		{
   1.713 +			if (m_ExitBackSound.size() > 0)
   1.714 +			{
   1.715 +				sound = m_ExitBackSound.c_str();
   1.716 +			}
   1.717 +			break;
   1.718 +		}
   1.719 +	case ItemSel_Exit:
   1.720 +		{
   1.721 +			if (m_ExitSound.size() > 0)
   1.722 +			{
   1.723 +				sound = m_ExitSound.c_str();
   1.724 +			}
   1.725 +			break;
   1.726 +		}
   1.727 +	default:
   1.728 +		{
   1.729 +			break;
   1.730 +		}
   1.731 +	}
   1.732 +
   1.733 +	return sound;
   1.734 +}
   1.735 +
   1.736 +void MenuManager::OnSourceModLevelChange(const char *mapName)
   1.737 +{
   1.738 +	if (m_SelectSound.size() > 0)
   1.739 +	{
   1.740 +		enginesound->PrecacheSound(m_SelectSound.c_str(), true);
   1.741 +	}
   1.742 +	if (m_ExitBackSound.size() > 0)
   1.743 +	{
   1.744 +		enginesound->PrecacheSound(m_ExitBackSound.c_str(), true);
   1.745 +	}
   1.746 +	if (m_ExitSound.size() > 0)
   1.747 +	{
   1.748 +		enginesound->PrecacheSound(m_ExitSound.c_str(), true);
   1.749 +	}
   1.750 +}
   1.751 +
   1.752 +void MenuManager::CancelMenu(IBaseMenu *menu)
   1.753 +{
   1.754 +	if (s_VoteHandler.GetCurrentMenu() == menu
   1.755 +		&& !s_VoteHandler.IsCancelling())
   1.756 +	{
   1.757 +		s_VoteHandler.CancelVoting();
   1.758 +		return;
   1.759 +	}
   1.760 +
   1.761 +	menu->Cancel();
   1.762 +}
   1.763 +
   1.764 +bool MenuManager::StartVote(IBaseMenu *menu, unsigned int num_clients, int clients[], unsigned int max_time, unsigned int flags)
   1.765 +{
   1.766 +	return s_VoteHandler.StartVote(menu, num_clients, clients, max_time, flags);
   1.767 +}
   1.768 +
   1.769 +bool MenuManager::IsVoteInProgress()
   1.770 +{
   1.771 +	return s_VoteHandler.IsVoteInProgress();
   1.772 +}
   1.773 +
   1.774 +void MenuManager::CancelVoting()
   1.775 +{
   1.776 +	s_VoteHandler.CancelVoting();
   1.777 +}
   1.778 +
   1.779 +unsigned int MenuManager::GetRemainingVoteDelay()
   1.780 +{
   1.781 +	return s_VoteHandler.GetRemainingVoteDelay();
   1.782 +}