core/MenuStyle_Base.cpp
author David Anderson <dvander@alliedmods.net>
Sun Jun 17 18:48:46 2007 +0000 (2007-06-17)
changeset 972 63d848bccec5
parent 970 b47becc0083d
child 997 2fc3152c3118
permissions -rw-r--r--
fixed bug amb401
     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);
    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 		mh->OnMenuEnd(menu);
   315 	}
   316 }
   317 
   318 bool BaseMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time)
   319 {
   320 #if defined MENU_DEBUG
   321 	g_Logger.LogMessage("[SM_MENU] DoClientMenu() (client %d) (panel %p) (mh %p) (time %d)",
   322 		client,
   323 		menu,
   324 		mh,
   325 		time);
   326 #endif
   327 	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   328 	if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsInGame())
   329 	{
   330 		return false;
   331 	}
   332 
   333 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   334 	if (player->bAutoIgnore)
   335 	{
   336 		return false;
   337 	}
   338 
   339 	/* For the duration of this, we are going to totally ignore whether
   340 	* the player is already in a menu or not (except to cancel the old one).
   341 	* Instead, we are simply going to ignore any further menu displays, so
   342 	* this display can't be interrupted.
   343 	*/
   344 	player->bAutoIgnore = true;
   345 
   346 	/* Cancel any old menus */
   347 	menu_states_t &states = player->states;
   348 	if (player->bInMenu)
   349 	{
   350 		_CancelClientMenu(client, true);
   351 	}
   352 
   353 	states.firstItem = 0;
   354 	states.lastItem = 0;
   355 	states.menu = NULL;
   356 	states.mh = mh;
   357 	states.apiVers = SMINTERFACE_MENUMANAGER_VERSION;
   358 	player->bInMenu = true;
   359 	player->bInExternMenu = false;
   360 	player->menuStartTime = gpGlobals->curtime;
   361 	player->menuHoldTime = time;
   362 
   363 	if (time)
   364 	{
   365 		AddClientToWatch(client);
   366 	}
   367 
   368 	/* Draw the display */
   369 	SendDisplay(client, menu);
   370 
   371 	/* We can be interrupted again! */
   372 	player->bAutoIgnore = false;
   373 
   374 	return true;
   375 }
   376 
   377 bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time)
   378 {
   379 #if defined MENU_DEBUG
   380 	g_Logger.LogMessage("[SM_MENU] DoClientMenu() (client %d) (menu %p) (mh %p) (time %d)",
   381 		client,
   382 		menu,
   383 		mh,
   384 		time);
   385 #endif
   386 	mh->OnMenuStart(menu);
   387 
   388 	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
   389 	if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsInGame())
   390 	{
   391 #if defined MENU_DEBUG
   392 		g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Failed to display to client %d", client);
   393 #endif
   394 		mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay);
   395 		mh->OnMenuEnd(menu);
   396 		return false;
   397 	}
   398 
   399 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   400 	if (player->bAutoIgnore)
   401 	{
   402 #if defined MENU_DEBUG
   403 		g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Client %d is autoIgnoring", client);
   404 #endif
   405 		mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay);
   406 		mh->OnMenuEnd(menu);
   407 		return false;
   408 	}
   409 
   410 	/* For the duration of this, we are going to totally ignore whether
   411 	* the player is already in a menu or not (except to cancel the old one).
   412 	* Instead, we are simply going to ignore any further menu displays, so
   413 	* this display can't be interrupted.
   414 	*/
   415 	player->bAutoIgnore = true;
   416 
   417 	/* Cancel any old menus */
   418 	menu_states_t &states = player->states;
   419 	if (player->bInMenu)
   420 	{
   421 #if defined MENU_DEBUG
   422 		g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Cancelling old menu to client %d", client);
   423 #endif
   424 		_CancelClientMenu(client, true);
   425 	}
   426 
   427 	states.firstItem = 0;
   428 	states.lastItem = 0;
   429 	states.menu = menu;
   430 	states.mh = mh;
   431 	states.apiVers = SMINTERFACE_MENUMANAGER_VERSION;
   432 
   433 	IMenuPanel *display = g_Menus.RenderMenu(client, states, ItemOrder_Ascending);
   434 	if (!display)
   435 	{
   436 #if defined MENU_DEBUG
   437 		g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Failed to render to client %d", client);
   438 #endif
   439 		player->bAutoIgnore = false;
   440 		player->bInMenu = false;
   441 		mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay);
   442 		mh->OnMenuEnd(menu);
   443 		return false;
   444 	}
   445 
   446 	/* Finally, set our states */
   447 	player->bInMenu = true;
   448 	player->bInExternMenu = false;
   449 	player->menuStartTime = gpGlobals->curtime;
   450 	player->menuHoldTime = time;
   451 
   452 	if (time)
   453 	{
   454 		AddClientToWatch(client);
   455 	}
   456 
   457 	/* Draw the display */
   458 	SendDisplay(client, display);
   459 
   460 	/* Free the display pointer */
   461 	display->DeleteThis();
   462 
   463 	/* We can be interrupted again! */
   464 	player->bAutoIgnore = false;
   465 
   466 #if defined MENU_DEBUG
   467 	g_Logger.LogMessage("[SM_MENU] DoClientMenu() finished successfully (client %d)", client);
   468 #endif
   469 
   470 	return true;
   471 }
   472 
   473 bool BaseMenuStyle::RedoClientMenu(int client, ItemOrder order)
   474 {
   475 #if defined MENU_DEBUG
   476 	g_Logger.LogMessage("[SM_MENU] RedoClientMenu() (client %d) (order %d)", client, order);
   477 #endif
   478 	CBaseMenuPlayer *player = GetMenuPlayer(client);
   479 	menu_states_t &states = player->states;
   480 
   481 	player->bAutoIgnore = true;
   482 	IMenuPanel *display = g_Menus.RenderMenu(client, states, order);
   483 	if (!display)
   484 	{
   485 #if defined MENU_DEBUG
   486 		g_Logger.LogMessage("[SM_MENU] RedoClientMenu(): Failed to render menu");
   487 #endif
   488 		if (player->menuHoldTime)
   489 		{
   490 			RemoveClientFromWatch(client);
   491 		}
   492 		player->bAutoIgnore = false;
   493 		return false;
   494 	}
   495 
   496 	SendDisplay(client, display);
   497 
   498 	display->DeleteThis();
   499 
   500 	player->bAutoIgnore = false;
   501 
   502 #if defined MENU_DEBUG
   503 	g_Logger.LogMessage("[SM_MENU] RedoClientMenu(): Succeeded to client %d", client);
   504 #endif
   505 
   506 	return true;
   507 }
   508 
   509 CBaseMenu::CBaseMenu(IMenuHandler *pHandler, IMenuStyle *pStyle, IdentityToken_t *pOwner) : 
   510 m_pStyle(pStyle), m_Strings(512), m_Pagination(7), m_ExitButton(true), 
   511 m_bShouldDelete(false), m_bCancelling(false), m_pOwner(pOwner ? pOwner : g_pCoreIdent), 
   512 m_bDeleting(false), m_bWillFreeHandle(false), m_hHandle(BAD_HANDLE), m_pHandler(pHandler),
   513 m_pVoteHandler(NULL)
   514 {
   515 }
   516 
   517 CBaseMenu::~CBaseMenu()
   518 {
   519 	g_Menus.ReleaseVoteWrapper(m_pVoteHandler);
   520 }
   521 
   522 Handle_t CBaseMenu::GetHandle()
   523 {
   524 	if (!m_hHandle)
   525 	{
   526 		m_hHandle = g_Menus.CreateMenuHandle(this, m_pOwner);
   527 	}
   528 
   529 	return m_hHandle;
   530 }
   531 
   532 bool CBaseMenu::AppendItem(const char *info, const ItemDrawInfo &draw)
   533 {
   534 	if (m_Pagination == (unsigned)MENU_NO_PAGINATION
   535 		&& m_items.size() >= m_pStyle->GetMaxPageItems())
   536 	{
   537 		return false;
   538 	}
   539 
   540 	CItem item;
   541 
   542 	item.infoString = m_Strings.AddString(info);
   543 	if (draw.display)
   544 	{
   545 		item.displayString = m_Strings.AddString(draw.display);
   546 	}
   547 	item.style = draw.style;
   548 
   549 
   550 	m_items.push_back(item);
   551 
   552 	return true;
   553 }
   554 
   555 bool CBaseMenu::InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw)
   556 {
   557 	if (m_Pagination == (unsigned)MENU_NO_PAGINATION
   558 		&& m_items.size() >= m_pStyle->GetMaxPageItems())
   559 	{
   560 		return false;
   561 	}
   562 
   563 	if (position >= m_items.size())
   564 	{
   565 		return false;
   566 	}
   567 
   568 	CItem item;
   569 	item.infoString = m_Strings.AddString(info);
   570 	if (draw.display)
   571 	{
   572 		item.displayString = m_Strings.AddString(draw.display);
   573 	}
   574 	item.style = draw.style;
   575 
   576 	CVector<CItem>::iterator iter = m_items.iterAt(position);
   577 	m_items.insert(iter, item);
   578 
   579 	return true;
   580 }
   581 
   582 bool CBaseMenu::RemoveItem(unsigned int position)
   583 {
   584 	if (position >= m_items.size())
   585 	{
   586 		return false;
   587 	}
   588 
   589 	m_items.erase(m_items.iterAt(position));
   590 
   591 	if (m_items.size() == 0)
   592 	{
   593 		m_Strings.Reset();
   594 	}
   595 
   596 	return true;
   597 }
   598 
   599 void CBaseMenu::RemoveAllItems()
   600 {
   601 	m_items.clear();
   602 	m_Strings.Reset();
   603 }
   604 
   605 const char *CBaseMenu::GetItemInfo(unsigned int position, ItemDrawInfo *draw/* =NULL */)
   606 {
   607 	if (position >= m_items.size())
   608 	{
   609 		return NULL;
   610 	}
   611 
   612 	if (draw)
   613 	{
   614 		draw->display = m_Strings.GetString(m_items[position].displayString);
   615 		draw->style = m_items[position].style;
   616 	}
   617 
   618 	return m_Strings.GetString(m_items[position].infoString);
   619 }
   620 
   621 unsigned int CBaseMenu::GetItemCount()
   622 {
   623 	return m_items.size();
   624 }
   625 
   626 bool CBaseMenu::SetPagination(unsigned int itemsPerPage)
   627 {
   628 	if (itemsPerPage > 7 || itemsPerPage == 1)
   629 	{
   630 		return false;
   631 	}
   632 
   633 	m_Pagination = itemsPerPage;
   634 
   635 	return true;
   636 }
   637 
   638 unsigned int CBaseMenu::GetPagination()
   639 {
   640 	return m_Pagination;
   641 }
   642 
   643 IMenuStyle *CBaseMenu::GetDrawStyle()
   644 {
   645 	return m_pStyle;
   646 }
   647 
   648 void CBaseMenu::SetDefaultTitle(const char *message)
   649 {
   650 	m_Title.assign(message);
   651 }
   652 
   653 const char *CBaseMenu::GetDefaultTitle()
   654 {
   655 	return m_Title.c_str();
   656 }
   657 
   658 bool CBaseMenu::GetExitButton()
   659 {
   660 	return m_ExitButton;
   661 }
   662 
   663 bool CBaseMenu::SetExitButton(bool set)
   664 {
   665 	m_ExitButton = set;
   666 	return true;
   667 }
   668 
   669 void CBaseMenu::Cancel()
   670 {
   671 	if (m_bCancelling)
   672 	{
   673 		return;
   674 	}
   675 
   676 #if defined MENU_DEBUG
   677 	g_Logger.LogMessage("[SM_MENU] CBaseMenu::Cancel(%p) (m_pVote %p) (inVote %d) (m_bShouldDelete %d)",
   678 		this,
   679 		m_pVoteHandler,
   680 		m_pVoteHandler ? m_pVoteHandler->IsVoteInProgress() : false,
   681 		m_bShouldDelete);
   682 #endif
   683 
   684 	if (m_pVoteHandler && m_pVoteHandler->IsVoteInProgress())
   685 	{
   686 		m_pVoteHandler->CancelVoting();
   687 	}
   688 
   689 	m_bCancelling = true;
   690 	Cancel_Finally();
   691 	m_bCancelling = false;
   692 
   693 	if (m_bShouldDelete)
   694 	{
   695 		InternalDelete();
   696 	}
   697 }
   698 
   699 void CBaseMenu::Destroy(bool releaseHandle)
   700 {
   701 	/* Check if we shouldn't be here */
   702 	if (m_bDeleting)
   703 	{
   704 		return;
   705 	}
   706 
   707 #if defined MENU_DEBUG
   708 	g_Logger.LogMessage("[SM_MENU] CBaseMenu::Destroy(%p) (release %d) (m_bCancelling %d) (m_bShouldDelete %d)",
   709 		this,
   710 		releaseHandle,
   711 		m_bCancelling,
   712 		m_bShouldDelete);
   713 #endif
   714 
   715 	/* Save the destruction hint about our handle */
   716 	m_bWillFreeHandle = releaseHandle;
   717 
   718 	/* Now actually do stuff */
   719 	if (!m_bCancelling || m_bShouldDelete)
   720 	{
   721 		Cancel();
   722 		InternalDelete();
   723 	} else {
   724 		m_bShouldDelete = true;
   725 	}
   726 }
   727 
   728 void CBaseMenu::InternalDelete()
   729 {
   730 	if (m_bWillFreeHandle && m_hHandle != BAD_HANDLE)
   731 	{
   732 		Handle_t hndl = m_hHandle;
   733 		HandleSecurity sec;
   734 
   735 		sec.pOwner = m_pOwner;
   736 		sec.pIdentity = g_pCoreIdent;
   737 
   738 		m_hHandle = BAD_HANDLE;
   739 		m_bDeleting = true;
   740 		g_HandleSys.FreeHandle(hndl, &sec);
   741 	}
   742 
   743 	m_pHandler->OnMenuDestroy(this);
   744 
   745 	delete this;
   746 }
   747 
   748 bool CBaseMenu::BroadcastVote(int clients[], 
   749 							  unsigned int numClients, 
   750 							  unsigned int maxTime,
   751 							  unsigned int flags)
   752 {
   753 #if defined MENU_DEBUG
   754 	g_Logger.LogMessage("[SM_MENU] CBaseMenu::BroadcastVote(%p) (maxTime %d) (numClients %d) (m_pVote %p) (inVote %d)",
   755 		this,
   756 		maxTime,
   757 		numClients,
   758 		m_pVoteHandler,
   759 		m_pVoteHandler ? m_pVoteHandler->IsVoteInProgress() : false);
   760 #endif
   761 	if (!m_pVoteHandler)
   762 	{
   763 		m_pVoteHandler = g_Menus.CreateVoteWrapper(m_pHandler);
   764 	} else if (m_pVoteHandler->IsVoteInProgress()) {
   765 		return false;
   766 	}
   767 
   768 	m_pVoteHandler->InitializeVoting(this);
   769 
   770 	for (unsigned int i=0; i<numClients; i++)
   771 	{
   772 		VoteDisplay(clients[i], maxTime);
   773 	}
   774 
   775 	m_pVoteHandler->StartVoting();
   776 
   777 	return true;
   778 }
   779 
   780 bool CBaseMenu::IsVoteInProgress()
   781 {
   782 	return (m_pVoteHandler && m_pVoteHandler->IsVoteInProgress());
   783 }