core/MenuStyle_Base.cpp
author Scott Ehlert <ds@alliedmods.net>
Fri Jun 22 15:37:12 2007 +0000 (2007-06-22)
changeset 1001 8de56a71f200
parent 997 2fc3152c3118
child 1005 b15b5682d181
permissions -rw-r--r--
Implemented amb423 - Added IsClientObserver() native
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #include <stdarg.h>
    16 #include "sm_stringutil.h"
    17 #include "MenuStyle_Base.h"
    18 #include "PlayerManager.h"
    19 #include "MenuManager.h"
    20 #include "HandleSys.h"
    21 #if defined MENU_DEBUG
    22 #include "Logger.h"
    23 #endif
    24 
    25 BaseMenuStyle::BaseMenuStyle() : m_WatchList(256), m_hHandle(BAD_HANDLE)
    26 {
    27 }
    28 
    29 Handle_t BaseMenuStyle::GetHandle()
    30 {
    31 	/* Don't create the handle until we need it */
    32 	if (m_hHandle == BAD_HANDLE)
    33 	{
    34 		m_hHandle = g_Menus.CreateStyleHandle(this);
    35 	}
    36 
    37 	return m_hHandle;
    38 }
    39 
    40 void BaseMenuStyle::AddClientToWatch(int client)
    41 {
    42 #if defined MENU_DEBUG
    43 	g_Logger.LogMessage("[SM_MENU] AddClientToWatch(%d)", client);
    44 #endif
    45 	m_WatchList.push_back(client);
    46 }
    47 
    48 void BaseMenuStyle::RemoveClientFromWatch(int client)
    49 {
    50 #if defined MENU_DEBUG
    51 	g_Logger.LogMessage("[SM_MENU] RemoveClientFromWatch(%d)", client);
    52 #endif
    53 	m_WatchList.remove(client);
    54 }
    55 
    56 void BaseMenuStyle::_CancelClientMenu(int client, bool bAutoIgnore/* =false */, MenuCancelReason reason/* =MenuCancel_Interrupt */)
    57 {
    58 #if defined MENU_DEBUG
    59 	g_Logger.LogMessage("[SM_MENU] _CancelClientMenu() (client %d) (bAutoIgnore %d) (reason %d)", client, bAutoIgnore, reason);
    60 #endif
    61 	CBaseMenuPlayer *player = GetMenuPlayer(client);
    62 	menu_states_t &states = player->states;
    63 
    64 	bool bOldIgnore = player->bAutoIgnore;
    65 	if (bAutoIgnore)
    66 	{
    67 		player->bAutoIgnore = true;
    68 	}
    69 
    70 	/* Save states */
    71 	IMenuHandler *mh = states.mh;
    72 	IBaseMenu *menu = states.menu;
    73 
    74 	/* Clear menu */
    75 	player->bInMenu = false;
    76 	if (player->menuHoldTime)
    77 	{
    78 		RemoveClientFromWatch(client);
    79 	}
    80 
    81 	/* Fire callbacks */
    82 	mh->OnMenuCancel(menu, client, reason);
    83 	
    84 	/* Only fire end if there's a valid menu */
    85 	if (menu)
    86 	{
    87 		mh->OnMenuEnd(menu, MenuEnd_Cancelled);
    88 	}
    89 
    90 	if (bAutoIgnore)
    91 	{
    92 		player->bAutoIgnore = bOldIgnore;
    93 	}
    94 }
    95 
    96 void BaseMenuStyle::CancelMenu(CBaseMenu *menu)
    97 {
    98 #if defined MENU_DEBUG
    99 	g_Logger.LogMessage("[SM_MENU] CancelMenu() (menu %p)", menu);
   100 #endif
   101 	int maxClients = g_Players.GetMaxClients();
   102 	for (int i=1; i<=maxClients; i++)
   103 	{
   104 		CBaseMenuPlayer *player = GetMenuPlayer(i);
   105 		if (player->bInMenu)
   106 		{
   107 			menu_states_t &states = player->states;
   108 			if (states.menu == menu)
   109 			{
   110 				_CancelClientMenu(i);
   111 			}
   112 		}
   113 	}
   114 }
   115 
   116 bool BaseMenuStyle::CancelClientMenu(int client, bool autoIgnore)
   117 {
   118 #if defined MENU_DEBUG
   119 	g_Logger.LogMessage("[SM_MENU] CancelClientMenu() (client %d) (bAutoIgnore %d)", client, autoIgnore);
   120 #endif
   121 	if (client < 1 || client > g_Players.MaxClients())
   122 	{
   123 		return false;
   124 	}
   125 
   126 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   127 	if (!player->bInMenu)
   128 	{
   129 		return false;
   130 	}
   131 
   132 	_CancelClientMenu(client, autoIgnore);
   133 
   134 	return true;
   135 }
   136 
   137 MenuSource BaseMenuStyle::GetClientMenu(int client, void **object)
   138 {
   139 	if (client < 1 || client > g_Players.GetMaxClients())
   140 	{
   141 		return MenuSource_None;
   142 	}
   143 
   144 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   145 
   146 	if (player->bInMenu)
   147 	{
   148 		IBaseMenu *menu;
   149 		if ((menu=player->states.menu) != NULL)
   150 		{
   151 			if (object)
   152 			{
   153 				*object = menu;
   154 			}
   155 			return MenuSource_BaseMenu;
   156 		}
   157 
   158 		return MenuSource_Display;
   159 	} else if (player->bInExternMenu) {
   160 		if (player->menuHoldTime != 0
   161 			&& (gpGlobals->curtime > player->menuStartTime + player->menuHoldTime))
   162 		{
   163 			player->bInExternMenu = false;
   164 			return MenuSource_None;
   165 		}
   166 		return MenuSource_External;
   167 	}
   168 
   169 	return MenuSource_None;
   170 }
   171 
   172 void BaseMenuStyle::OnClientDisconnected(int client)
   173 {
   174 #if defined MENU_DEBUG
   175 	g_Logger.LogMessage("[SM_MENU] OnClientDisconnected(%d)", client);
   176 #endif
   177 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   178 	if (!player->bInMenu)
   179 	{
   180 		return;
   181 	}
   182 
   183 	_CancelClientMenu(client, true, MenuCancel_Disconnect);
   184 
   185 	player->bInMenu = false;
   186 	player->bInExternMenu = false;
   187 }
   188 
   189 static int do_lookup[256];
   190 void BaseMenuStyle::ProcessWatchList()
   191 {
   192 	if (!m_WatchList.size())
   193 	{
   194 		return;
   195 	}
   196 
   197 	unsigned int total = 0;
   198 	for (FastLink<int>::iterator iter=m_WatchList.begin(); iter!=m_WatchList.end(); ++iter)
   199 	{
   200 		do_lookup[total++] = (*iter);
   201 	}
   202 
   203 #if defined MENU_DEBUG
   204 	if (total)
   205 	{
   206 		g_Logger.LogMessage("[SM_MENU] ProcessWatchList() found %d clients", total);
   207 	}
   208 #endif
   209 
   210 	int client;
   211 	CBaseMenuPlayer *player;
   212 	float curTime = gpGlobals->curtime;
   213 	for (unsigned int i=0; i<total; i++)
   214 	{
   215 		client = do_lookup[i];
   216 		player = GetMenuPlayer(client);
   217 #if defined MENU_DEBUG
   218 		g_Logger.LogMessage("[SM_MENU] ProcessWatchList() (client %d) (bInMenu %d) (menuHoldTime %d) (curTime %f) (menuStartTime %f)",
   219 			client,
   220 			player->bInMenu,
   221 			player->menuHoldTime,
   222 			curTime,
   223 			player->menuStartTime);
   224 #endif
   225 		if (!player->bInMenu || !player->menuHoldTime)
   226 		{
   227 #if defined MENU_DEBUG
   228 			g_Logger.LogMessage("[SM_MENU] ProcessWatchList() removing client %d", client);
   229 #endif
   230 			m_WatchList.remove(client);
   231 			continue;
   232 		}
   233 		if (curTime > player->menuStartTime + player->menuHoldTime)
   234 		{
   235 			_CancelClientMenu(client, false);
   236 		}
   237 	}
   238 }
   239 
   240 void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press)
   241 {
   242 #if defined MENU_DEBUG
   243 	g_Logger.LogMessage("[SM_MENU] ClientPressedKey() (client %d) (key_press %d)", client, key_press);
   244 #endif
   245 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   246 
   247 	/* First question: Are we in a menu? */
   248 	if (!player->bInMenu)
   249 	{
   250 		return;
   251 	}
   252 
   253 	bool cancel = false;
   254 	unsigned int item = 0;
   255 	MenuCancelReason reason = MenuCancel_Exit;
   256 	menu_states_t &states = player->states;
   257 
   258 	assert(states.mh != NULL);
   259 
   260 	if (states.menu == NULL)
   261 	{
   262 		item = key_press;
   263 	} else if (key_press < 1 || key_press > GetMaxPageItems()) {
   264 		cancel = true;
   265 	} else {
   266 		ItemSelection type = states.slots[key_press].type;
   267 
   268 		/* For navigational items, we're going to redisplay */
   269 		if (type == ItemSel_Back)
   270 		{
   271 			if (!RedoClientMenu(client, ItemOrder_Descending))
   272 			{
   273 				cancel = true;
   274 				reason = MenuCancel_NoDisplay;
   275 			} else {
   276 				return;
   277 			}
   278 		} else if (type == ItemSel_Next) {
   279 			if (!RedoClientMenu(client, ItemOrder_Ascending))
   280 			{
   281 				cancel = true;						/* I like Saltines. */
   282 				reason = MenuCancel_NoDisplay;
   283 			} else {
   284 				return;
   285 			}
   286 		} else if (type == ItemSel_Exit || type == ItemSel_None) {
   287 			cancel = true;
   288 		} else {
   289 			item = states.slots[key_press].item;
   290 		}
   291 	}
   292 
   293 	/* Save variables */
   294 	IMenuHandler *mh = states.mh;
   295 	IBaseMenu *menu = states.menu;
   296 
   297 	/* Clear states */
   298 	player->bInMenu = false;
   299 	if (player->menuHoldTime)
   300 	{
   301 		RemoveClientFromWatch(client);
   302 	}
   303 
   304 	if (cancel)
   305 	{
   306 		mh->OnMenuCancel(menu, client, reason);
   307 	} else {
   308 		mh->OnMenuSelect(menu, client, item);
   309 	}
   310 
   311 	/* Only fire end for valid menus */
   312 	if (menu)
   313 	{
   314 		MenuEndReason end_reason = 
   315 			(cancel ? 
   316 				MenuEnd_Selected
   317 				: 
   318 				(reason == MenuCancel_Exit ? 
   319 					MenuEnd_Exit
   320 					: 
   321 					MenuEnd_Cancelled));
   322 		mh->OnMenuEnd(menu, end_reason);
   323 	}
   324 }
   325 
   326 bool BaseMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time)
   327 {
   328 #if defined MENU_DEBUG
   329 	g_Logger.LogMessage("[SM_MENU] DoClientMenu() (client %d) (panel %p) (mh %p) (time %d)",
   330 		client,
   331 		menu,
   332 		mh,
   333 		time);
   334 #endif
   335 	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   336 	if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsInGame())
   337 	{
   338 		return false;
   339 	}
   340 
   341 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   342 	if (player->bAutoIgnore)
   343 	{
   344 		return false;
   345 	}
   346 
   347 	/* For the duration of this, we are going to totally ignore whether
   348 	* the player is already in a menu or not (except to cancel the old one).
   349 	* Instead, we are simply going to ignore any further menu displays, so
   350 	* this display can't be interrupted.
   351 	*/
   352 	player->bAutoIgnore = true;
   353 
   354 	/* Cancel any old menus */
   355 	menu_states_t &states = player->states;
   356 	if (player->bInMenu)
   357 	{
   358 		_CancelClientMenu(client, true);
   359 	}
   360 
   361 	states.firstItem = 0;
   362 	states.lastItem = 0;
   363 	states.menu = NULL;
   364 	states.mh = mh;
   365 	states.apiVers = SMINTERFACE_MENUMANAGER_VERSION;
   366 	player->bInMenu = true;
   367 	player->bInExternMenu = false;
   368 	player->menuStartTime = gpGlobals->curtime;
   369 	player->menuHoldTime = time;
   370 
   371 	if (time)
   372 	{
   373 		AddClientToWatch(client);
   374 	}
   375 
   376 	/* Draw the display */
   377 	SendDisplay(client, menu);
   378 
   379 	/* We can be interrupted again! */
   380 	player->bAutoIgnore = false;
   381 
   382 	return true;
   383 }
   384 
   385 bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time)
   386 {
   387 #if defined MENU_DEBUG
   388 	g_Logger.LogMessage("[SM_MENU] DoClientMenu() (client %d) (menu %p) (mh %p) (time %d)",
   389 		client,
   390 		menu,
   391 		mh,
   392 		time);
   393 #endif
   394 	mh->OnMenuStart(menu);
   395 
   396 	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   397 	if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsInGame())
   398 	{
   399 #if defined MENU_DEBUG
   400 		g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Failed to display to client %d", client);
   401 #endif
   402 		mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay);
   403 		mh->OnMenuEnd(menu, MenuEnd_Cancelled);
   404 		return false;
   405 	}
   406 
   407 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   408 	if (player->bAutoIgnore)
   409 	{
   410 #if defined MENU_DEBUG
   411 		g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Client %d is autoIgnoring", client);
   412 #endif
   413 		mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay);
   414 		mh->OnMenuEnd(menu, MenuEnd_Cancelled);
   415 		return false;
   416 	}
   417 
   418 	/* For the duration of this, we are going to totally ignore whether
   419 	* the player is already in a menu or not (except to cancel the old one).
   420 	* Instead, we are simply going to ignore any further menu displays, so
   421 	* this display can't be interrupted.
   422 	*/
   423 	player->bAutoIgnore = true;
   424 
   425 	/* Cancel any old menus */
   426 	menu_states_t &states = player->states;
   427 	if (player->bInMenu)
   428 	{
   429 #if defined MENU_DEBUG
   430 		g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Cancelling old menu to client %d", client);
   431 #endif
   432 		_CancelClientMenu(client, true);
   433 	}
   434 
   435 	states.firstItem = 0;
   436 	states.lastItem = 0;
   437 	states.menu = menu;
   438 	states.mh = mh;
   439 	states.apiVers = SMINTERFACE_MENUMANAGER_VERSION;
   440 
   441 	IMenuPanel *display = g_Menus.RenderMenu(client, states, ItemOrder_Ascending);
   442 	if (!display)
   443 	{
   444 #if defined MENU_DEBUG
   445 		g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Failed to render to client %d", client);
   446 #endif
   447 		player->bAutoIgnore = false;
   448 		player->bInMenu = false;
   449 		mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay);
   450 		mh->OnMenuEnd(menu, MenuEnd_Cancelled);
   451 		return false;
   452 	}
   453 
   454 	/* Finally, set our states */
   455 	player->bInMenu = true;
   456 	player->bInExternMenu = false;
   457 	player->menuStartTime = gpGlobals->curtime;
   458 	player->menuHoldTime = time;
   459 
   460 	if (time)
   461 	{
   462 		AddClientToWatch(client);
   463 	}
   464 
   465 	/* Draw the display */
   466 	SendDisplay(client, display);
   467 
   468 	/* Free the display pointer */
   469 	display->DeleteThis();
   470 
   471 	/* We can be interrupted again! */
   472 	player->bAutoIgnore = false;
   473 
   474 #if defined MENU_DEBUG
   475 	g_Logger.LogMessage("[SM_MENU] DoClientMenu() finished successfully (client %d)", client);
   476 #endif
   477 
   478 	return true;
   479 }
   480 
   481 bool BaseMenuStyle::RedoClientMenu(int client, ItemOrder order)
   482 {
   483 #if defined MENU_DEBUG
   484 	g_Logger.LogMessage("[SM_MENU] RedoClientMenu() (client %d) (order %d)", client, order);
   485 #endif
   486 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   487 	menu_states_t &states = player->states;
   488 
   489 	player->bAutoIgnore = true;
   490 	IMenuPanel *display = g_Menus.RenderMenu(client, states, order);
   491 	if (!display)
   492 	{
   493 #if defined MENU_DEBUG
   494 		g_Logger.LogMessage("[SM_MENU] RedoClientMenu(): Failed to render menu");
   495 #endif
   496 		if (player->menuHoldTime)
   497 		{
   498 			RemoveClientFromWatch(client);
   499 		}
   500 		player->bAutoIgnore = false;
   501 		return false;
   502 	}
   503 
   504 	SendDisplay(client, display);
   505 
   506 	display->DeleteThis();
   507 
   508 	player->bAutoIgnore = false;
   509 
   510 #if defined MENU_DEBUG
   511 	g_Logger.LogMessage("[SM_MENU] RedoClientMenu(): Succeeded to client %d", client);
   512 #endif
   513 
   514 	return true;
   515 }
   516 
   517 CBaseMenu::CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner) : 
   518 m_pStyle(pStyle), m_Strings(512), m_Pagination(7), m_ExitButton(true), 
   519 m_bShouldDelete(false), m_bCancelling(false), m_pOwner(pOwner ? pOwner : g_pCoreIdent), 
   520 m_bDeleting(false), m_bWillFreeHandle(false), m_hHandle(BAD_HANDLE), m_pHandler(pHandler),
   521 m_pVoteHandler(NULL)
   522 {
   523 }
   524 
   525 CBaseMenu::~CBaseMenu()
   526 {
   527 	g_Menus.ReleaseVoteWrapper(m_pVoteHandler);
   528 }
   529 
   530 Handle_t CBaseMenu::GetHandle()
   531 {
   532 	if (!m_hHandle)
   533 	{
   534 		m_hHandle = g_Menus.CreateMenuHandle(this, m_pOwner);
   535 	}
   536 
   537 	return m_hHandle;
   538 }
   539 
   540 bool CBaseMenu::AppendItem(const char *info, const ItemDrawInfo &draw)
   541 {
   542 	if (m_Pagination == (unsigned)MENU_NO_PAGINATION
   543 		&& m_items.size() >= m_pStyle->GetMaxPageItems())
   544 	{
   545 		return false;
   546 	}
   547 
   548 	CItem item;
   549 
   550 	item.infoString = m_Strings.AddString(info);
   551 	if (draw.display)
   552 	{
   553 		item.displayString = m_Strings.AddString(draw.display);
   554 	}
   555 	item.style = draw.style;
   556 
   557 
   558 	m_items.push_back(item);
   559 
   560 	return true;
   561 }
   562 
   563 bool CBaseMenu::InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw)
   564 {
   565 	if (m_Pagination == (unsigned)MENU_NO_PAGINATION
   566 		&& m_items.size() >= m_pStyle->GetMaxPageItems())
   567 	{
   568 		return false;
   569 	}
   570 
   571 	if (position >= m_items.size())
   572 	{
   573 		return false;
   574 	}
   575 
   576 	CItem item;
   577 	item.infoString = m_Strings.AddString(info);
   578 	if (draw.display)
   579 	{
   580 		item.displayString = m_Strings.AddString(draw.display);
   581 	}
   582 	item.style = draw.style;
   583 
   584 	CVector<CItem>::iterator iter = m_items.iterAt(position);
   585 	m_items.insert(iter, item);
   586 
   587 	return true;
   588 }
   589 
   590 bool CBaseMenu::RemoveItem(unsigned int position)
   591 {
   592 	if (position >= m_items.size())
   593 	{
   594 		return false;
   595 	}
   596 
   597 	m_items.erase(m_items.iterAt(position));
   598 
   599 	if (m_items.size() == 0)
   600 	{
   601 		m_Strings.Reset();
   602 	}
   603 
   604 	return true;
   605 }
   606 
   607 void CBaseMenu::RemoveAllItems()
   608 {
   609 	m_items.clear();
   610 	m_Strings.Reset();
   611 }
   612 
   613 const char *CBaseMenu::GetItemInfo(unsigned int position, ItemDrawInfo *draw/* =NULL */)
   614 {
   615 	if (position >= m_items.size())
   616 	{
   617 		return NULL;
   618 	}
   619 
   620 	if (draw)
   621 	{
   622 		draw->display = m_Strings.GetString(m_items[position].displayString);
   623 		draw->style = m_items[position].style;
   624 	}
   625 
   626 	return m_Strings.GetString(m_items[position].infoString);
   627 }
   628 
   629 unsigned int CBaseMenu::GetItemCount()
   630 {
   631 	return m_items.size();
   632 }
   633 
   634 bool CBaseMenu::SetPagination(unsigned int itemsPerPage)
   635 {
   636 	if (itemsPerPage > 7 || itemsPerPage == 1)
   637 	{
   638 		return false;
   639 	}
   640 
   641 	m_Pagination = itemsPerPage;
   642 
   643 	return true;
   644 }
   645 
   646 unsigned int CBaseMenu::GetPagination()
   647 {
   648 	return m_Pagination;
   649 }
   650 
   651 IMenuStyle *CBaseMenu::GetDrawStyle()
   652 {
   653 	return m_pStyle;
   654 }
   655 
   656 void CBaseMenu::SetDefaultTitle(const char *message)
   657 {
   658 	m_Title.assign(message);
   659 }
   660 
   661 const char *CBaseMenu::GetDefaultTitle()
   662 {
   663 	return m_Title.c_str();
   664 }
   665 
   666 bool CBaseMenu::GetExitButton()
   667 {
   668 	return m_ExitButton;
   669 }
   670 
   671 bool CBaseMenu::SetExitButton(bool set)
   672 {
   673 	m_ExitButton = set;
   674 	return true;
   675 }
   676 
   677 void CBaseMenu::Cancel()
   678 {
   679 	if (m_bCancelling)
   680 	{
   681 		return;
   682 	}
   683 
   684 #if defined MENU_DEBUG
   685 	g_Logger.LogMessage("[SM_MENU] CBaseMenu::Cancel(%p) (m_pVote %p) (inVote %d) (m_bShouldDelete %d)",
   686 		this,
   687 		m_pVoteHandler,
   688 		m_pVoteHandler ? m_pVoteHandler->IsVoteInProgress() : false,
   689 		m_bShouldDelete);
   690 #endif
   691 
   692 	if (m_pVoteHandler && m_pVoteHandler->IsVoteInProgress())
   693 	{
   694 		m_pVoteHandler->CancelVoting();
   695 	}
   696 
   697 	m_bCancelling = true;
   698 	Cancel_Finally();
   699 	m_bCancelling = false;
   700 
   701 	if (m_bShouldDelete)
   702 	{
   703 		InternalDelete();
   704 	}
   705 }
   706 
   707 void CBaseMenu::Destroy(bool releaseHandle)
   708 {
   709 	/* Check if we shouldn't be here */
   710 	if (m_bDeleting)
   711 	{
   712 		return;
   713 	}
   714 
   715 #if defined MENU_DEBUG
   716 	g_Logger.LogMessage("[SM_MENU] CBaseMenu::Destroy(%p) (release %d) (m_bCancelling %d) (m_bShouldDelete %d)",
   717 		this,
   718 		releaseHandle,
   719 		m_bCancelling,
   720 		m_bShouldDelete);
   721 #endif
   722 
   723 	/* Save the destruction hint about our handle */
   724 	m_bWillFreeHandle = releaseHandle;
   725 
   726 	/* Now actually do stuff */
   727 	if (!m_bCancelling || m_bShouldDelete)
   728 	{
   729 		Cancel();
   730 		InternalDelete();
   731 	} else {
   732 		m_bShouldDelete = true;
   733 	}
   734 }
   735 
   736 void CBaseMenu::InternalDelete()
   737 {
   738 	if (m_bWillFreeHandle && m_hHandle != BAD_HANDLE)
   739 	{
   740 		Handle_t hndl = m_hHandle;
   741 		HandleSecurity sec;
   742 
   743 		sec.pOwner = m_pOwner;
   744 		sec.pIdentity = g_pCoreIdent;
   745 
   746 		m_hHandle = BAD_HANDLE;
   747 		m_bDeleting = true;
   748 		g_HandleSys.FreeHandle(hndl, &sec);
   749 	}
   750 
   751 	m_pHandler->OnMenuDestroy(this);
   752 
   753 	delete this;
   754 }
   755 
   756 bool CBaseMenu::BroadcastVote(int clients[], 
   757 							  unsigned int numClients, 
   758 							  unsigned int maxTime,
   759 							  unsigned int flags)
   760 {
   761 #if defined MENU_DEBUG
   762 	g_Logger.LogMessage("[SM_MENU] CBaseMenu::BroadcastVote(%p) (maxTime %d) (numClients %d) (m_pVote %p) (inVote %d)",
   763 		this,
   764 		maxTime,
   765 		numClients,
   766 		m_pVoteHandler,
   767 		m_pVoteHandler ? m_pVoteHandler->IsVoteInProgress() : false);
   768 #endif
   769 	if (!m_pVoteHandler)
   770 	{
   771 		m_pVoteHandler = g_Menus.CreateVoteWrapper(m_pHandler);
   772 	} else if (m_pVoteHandler->IsVoteInProgress()) {
   773 		return false;
   774 	}
   775 
   776 	m_pVoteHandler->InitializeVoting(this);
   777 
   778 	for (unsigned int i=0; i<numClients; i++)
   779 	{
   780 		VoteDisplay(clients[i], maxTime);
   781 	}
   782 
   783 	m_pVoteHandler->StartVoting();
   784 
   785 	return true;
   786 }
   787 
   788 bool CBaseMenu::IsVoteInProgress()
   789 {
   790 	return (m_pVoteHandler && m_pVoteHandler->IsVoteInProgress());
   791 }