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