- vote menus now get cancelled properly (and get a new callback with it)
- added api for seeing if a menu is in a VoteDisplay - fixed another item count bug - removed some cruft from the vote handler header --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40890
This commit is contained in:
parent
749f2a2ce7
commit
6f4784e3d1
@ -95,6 +95,19 @@ void VoteMenuHandler::DecrementPlayerCount()
|
||||
|
||||
void VoteMenuHandler::EndVoting()
|
||||
{
|
||||
if (m_bCancelled)
|
||||
{
|
||||
/* If we were cancelled, don't bother tabulating anything.
|
||||
* Reset just in case someone tries to redraw, which means
|
||||
* we need to save our states.
|
||||
*/
|
||||
IBaseMenu *menu = m_pCurMenu;
|
||||
InternalReset();
|
||||
m_pHandler->OnMenuVoteCancel(menu);
|
||||
m_pHandler->OnMenuEnd(menu);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int chosen = 0;
|
||||
unsigned int highest = 0;
|
||||
unsigned int dup_count = 0;
|
||||
@ -104,7 +117,7 @@ void VoteMenuHandler::EndVoting()
|
||||
{
|
||||
/* Pick a random item and then jump far, far away. */
|
||||
srand((unsigned int)(time(NULL)));
|
||||
chosen = (unsigned int)rand() % static_cast<unsigned int>(m_Votes.size());
|
||||
chosen = (unsigned int)rand() % m_Items;
|
||||
goto picked_item;
|
||||
}
|
||||
|
||||
@ -207,6 +220,12 @@ void VoteMenuHandler::InternalReset()
|
||||
m_bStarted = false;
|
||||
m_pCurMenu = NULL;
|
||||
m_NumVotes = 0;
|
||||
m_bCancelled = false;
|
||||
}
|
||||
|
||||
void VoteMenuHandler::CancelVoting()
|
||||
{
|
||||
m_bCancelled = true;
|
||||
}
|
||||
|
||||
/*******************************
|
||||
|
@ -40,6 +40,7 @@ public: //IVoteMenuHandler
|
||||
bool IsVoteInProgress();
|
||||
void InitializeVoting(IBaseMenu *menu);
|
||||
void StartVoting();
|
||||
void CancelVoting();
|
||||
public:
|
||||
void Reset(IMenuHandler *mh);
|
||||
private:
|
||||
@ -51,9 +52,9 @@ private:
|
||||
unsigned int m_Clients;
|
||||
unsigned int m_Items;
|
||||
CVector<unsigned int> m_Votes;
|
||||
CVector<unsigned int> m_Dups;
|
||||
IBaseMenu *m_pCurMenu;
|
||||
bool m_bStarted;
|
||||
bool m_bCancelled;
|
||||
unsigned int m_NumVotes;
|
||||
};
|
||||
|
||||
|
@ -673,3 +673,7 @@ bool CBaseMenu::BroadcastVote(int clients[],
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBaseMenu::IsVoteInProgress()
|
||||
{
|
||||
return (m_pVoteHandler && m_pVoteHandler->IsVoteInProgress());
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ public:
|
||||
unsigned int numClients,
|
||||
unsigned int maxTime,
|
||||
unsigned int flags=0);
|
||||
bool IsVoteInProgress();
|
||||
public:
|
||||
virtual void VoteDisplay(int client, unsigned int maxTime) =0;
|
||||
private:
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <IHandleSys.h>
|
||||
|
||||
#define SMINTERFACE_MENUMANAGER_NAME "IMenuManager"
|
||||
#define SMINTERFACE_MENUMANAGER_VERSION 2
|
||||
#define SMINTERFACE_MENUMANAGER_VERSION 3
|
||||
|
||||
/**
|
||||
* @file IMenuManager.h
|
||||
@ -486,6 +486,7 @@ namespace SourceMod
|
||||
/**
|
||||
* @brief Cancels the menu on all client's displays. While the menu is
|
||||
* being cancelled, the menu may not be re-displayed to any clients.
|
||||
* If a vote menu is currently active, it will be cancelled as well.
|
||||
*
|
||||
* @return Number of menus cancelled.
|
||||
*/
|
||||
@ -515,6 +516,13 @@ namespace SourceMod
|
||||
unsigned int numClients,
|
||||
unsigned int maxTime,
|
||||
unsigned int flags=0) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns whether a vote menu is active.
|
||||
*
|
||||
* @return True if a vote menu is active, false otherwise.
|
||||
*/
|
||||
virtual bool IsVoteInProgress() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -631,7 +639,11 @@ namespace SourceMod
|
||||
|
||||
/**
|
||||
* @brief Called when a vote ends. This is automatically called by the
|
||||
* wrapper, and never needs to called from a style implementation.
|
||||
* wrapper, and never needs to called from a style implementation.
|
||||
*
|
||||
* This function does not replace OnMenuEnd(), nor does it have the
|
||||
* same meaning as OnMenuEnd(), meaning you should not destroy a menu
|
||||
* while it is in this function.
|
||||
*
|
||||
* @param menu Menu pointer.
|
||||
* @param item Item position that was chosen by a majority.
|
||||
@ -639,6 +651,17 @@ namespace SourceMod
|
||||
virtual void OnMenuVoteEnd(IBaseMenu *menu, unsigned int item)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when a vote is cancelled. If this is called, then
|
||||
* OnMenuVoteEnd() will not be called. In both cases, OnMenuEnd will
|
||||
* always be called.
|
||||
*
|
||||
* @param menu Menu pointer.
|
||||
*/
|
||||
virtual void OnMenuVoteCancel(IBaseMenu *menu)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -666,6 +689,16 @@ namespace SourceMod
|
||||
* processed (i.e., there are no more clients to display to).
|
||||
*/
|
||||
virtual void StartVoting() =0;
|
||||
|
||||
/**
|
||||
* @brief Notifies the vote handler that the voting should be
|
||||
* cancelled.
|
||||
*
|
||||
* Cancellation is not immediate and will only occur once every menu
|
||||
* has been cancelled from clients. Thus this should only be called
|
||||
* from the beginning of IBaseMenu::Cancel.
|
||||
*/
|
||||
virtual void CancelVoting() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user