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