added amb764, vote delay setting
authorDavid Anderson <dvander@alliedmods.net>
Thu Aug 09 19:05:34 2007 +0000 (2007-08-09)
changeset 1291c6d26de53926
parent 1290 1a3198e040fa
child 1292 753dd36abf17
added amb764, vote delay setting
core/MenuManager.cpp
core/MenuManager.h
core/MenuVoting.cpp
core/MenuVoting.h
core/smn_menus.cpp
plugins/include/menus.inc
public/IMenuManager.h
     1.1 --- a/core/MenuManager.cpp	Thu Aug 09 18:25:00 2007 +0000
     1.2 +++ b/core/MenuManager.cpp	Thu Aug 09 19:05:34 2007 +0000
     1.3 @@ -692,3 +692,8 @@
     1.4  {
     1.5  	s_VoteHandler.CancelVoting();
     1.6  }
     1.7 +
     1.8 +unsigned int MenuManager::GetRemainingVoteDelay()
     1.9 +{
    1.10 +	return s_VoteHandler.GetRemainingVoteDelay();
    1.11 +}
     2.1 --- a/core/MenuManager.h	Thu Aug 09 18:25:00 2007 +0000
     2.2 +++ b/core/MenuManager.h	Thu Aug 09 19:05:34 2007 +0000
     2.3 @@ -89,6 +89,7 @@
     2.4  		unsigned int flags=0);
     2.5  	bool IsVoteInProgress();
     2.6  	void CancelVoting();
     2.7 +	unsigned int GetRemainingVoteDelay();
     2.8  public: //IHandleTypeDispatch
     2.9  	void OnHandleDestroy(HandleType_t type, void *object);
    2.10  public:
     3.1 --- a/core/MenuVoting.cpp	Thu Aug 09 18:25:00 2007 +0000
     3.2 +++ b/core/MenuVoting.cpp	Thu Aug 09 19:05:34 2007 +0000
     3.3 @@ -36,6 +36,49 @@
     3.4  #include "PlayerManager.h"
     3.5  #include "sourcemm_api.h"
     3.6  
     3.7 +float g_next_vote = 0.0f;
     3.8 +
     3.9 +void OnVoteDelayChange(ConVar *cvar, const char *value);
    3.10 +ConVar sm_vote_delay("sm_vote_delay",
    3.11 +					 "30",
    3.12 +					 0,
    3.13 +					 "Sets the recommended time in between public votes",
    3.14 +					 false,
    3.15 +					 0.0,
    3.16 +					 false,
    3.17 +					 0.0,
    3.18 +					 OnVoteDelayChange);
    3.19 +
    3.20 +void OnVoteDelayChange(ConVar *cvar, const char *value)
    3.21 +{
    3.22 +	/* See if the new vote delay isn't something we need to account for */
    3.23 +	if (sm_vote_delay.GetFloat() < 1.0f)
    3.24 +	{
    3.25 +		g_next_vote = 0.0f;
    3.26 +		return;
    3.27 +	}
    3.28 +
    3.29 +	/* If there was never a last vote, ignore this change */
    3.30 +	if (g_next_vote < 0.1f)
    3.31 +	{
    3.32 +		return;
    3.33 +	}
    3.34 +
    3.35 +	/* Subtract the original value, then add the new one. */
    3.36 +	g_next_vote -= (float)atof(value);
    3.37 +	g_next_vote += sm_vote_delay.GetFloat();
    3.38 +}
    3.39 +
    3.40 +unsigned int VoteMenuHandler::GetRemainingVoteDelay()
    3.41 +{
    3.42 +	if (g_next_vote <= gpGlobals->curtime)
    3.43 +	{
    3.44 +		return 0;
    3.45 +	}
    3.46 +
    3.47 +	return (unsigned int)(g_next_vote - gpGlobals->curtime);
    3.48 +}
    3.49 +
    3.50  void VoteMenuHandler::OnSourceModAllInitialized()
    3.51  {
    3.52  	g_Players.AddClientListener(this);
    3.53 @@ -46,6 +89,11 @@
    3.54  	g_Players.RemoveClientListener(this);
    3.55  }
    3.56  
    3.57 +void VoteMenuHandler::OnSourceModLevelChange(const char *mapName)
    3.58 +{
    3.59 +	g_next_vote = 0.0f;
    3.60 +}
    3.61 +
    3.62  unsigned int VoteMenuHandler::GetMenuAPIVersion2()
    3.63  {
    3.64  	return m_pHandler->GetMenuAPIVersion2();
    3.65 @@ -81,6 +129,18 @@
    3.66  		return false;
    3.67  	}
    3.68  
    3.69 +	float fVoteDelay = sm_vote_delay.GetFloat();
    3.70 +	if (fVoteDelay < 1.0)
    3.71 +	{
    3.72 +		g_next_vote = 0.0;
    3.73 +	} else {
    3.74 +		/* This little trick breaks for infinite votes!
    3.75 +		 * However, we just ignore that since those 1) shouldn't exist and 
    3.76 +		 * 2) people must be checking IsVoteInProgress() beforehand anyway.
    3.77 +		 */
    3.78 +		g_next_vote = gpGlobals->curtime + fVoteDelay + (float)max_time;
    3.79 +	}
    3.80 +
    3.81  	for (unsigned int i=0; i<num_clients; i++)
    3.82  	{
    3.83  		menu->Display(clients[i], max_time, this);
    3.84 @@ -177,6 +237,18 @@
    3.85  
    3.86  void VoteMenuHandler::EndVoting()
    3.87  {
    3.88 +	/* Set when the next delay ends.  We ignore cancellation because a menu
    3.89 +	 * was, at one point, displayed, which is all that counts.  However, we
    3.90 +	 * do re-calculate the time just in case the menu had no time limit.
    3.91 +	 */
    3.92 +	float fVoteDelay = sm_vote_delay.GetFloat();
    3.93 +	if (fVoteDelay < 1.0)
    3.94 +	{
    3.95 +		g_next_vote = 0.0;
    3.96 +	} else {
    3.97 +		g_next_vote = gpGlobals->curtime + fVoteDelay;
    3.98 +	}
    3.99 +
   3.100  	if (m_bCancelled)
   3.101  	{
   3.102  		/* If we were cancelled, don't bother tabulating anything.
     4.1 --- a/core/MenuVoting.h	Thu Aug 09 18:25:00 2007 +0000
     4.2 +++ b/core/MenuVoting.h	Thu Aug 09 19:05:34 2007 +0000
     4.3 @@ -49,6 +49,7 @@
     4.4  public: //SMGlobalClass
     4.5  	void OnSourceModAllInitialized();
     4.6  	void OnSourceModShutdown();
     4.7 +	void OnSourceModLevelChange(const char *mapName);
     4.8  public: //IClientListener
     4.9  	void OnClientDisconnected(int client);
    4.10  public: //IMenuHandler
    4.11 @@ -70,6 +71,7 @@
    4.12  	void CancelVoting();
    4.13  	IBaseMenu *GetCurrentMenu();
    4.14  	bool IsCancelling();
    4.15 +	unsigned int GetRemainingVoteDelay();
    4.16  private:
    4.17  	void Reset(IMenuHandler *mh);
    4.18  	void DecrementPlayerCount();
     5.1 --- a/core/smn_menus.cpp	Thu Aug 09 18:25:00 2007 +0000
     5.2 +++ b/core/smn_menus.cpp	Thu Aug 09 19:05:34 2007 +0000
     5.3 @@ -39,6 +39,7 @@
     5.4  #include "HandleSys.h"
     5.5  #include "PluginSys.h"
     5.6  #include "sm_stringutil.h"
     5.7 +#include "sourcemm_api.h"
     5.8  #if defined MENU_DEBUG
     5.9  #include "Logger.h"
    5.10  #endif
    5.11 @@ -1324,6 +1325,11 @@
    5.12  	return 1;
    5.13  }
    5.14  
    5.15 +static cell_t CheckVoteDelay(IPluginContext *pContext, const cell_t *params)
    5.16 +{
    5.17 +	return g_Menus.GetRemainingVoteDelay();
    5.18 +}
    5.19 +
    5.20  REGISTER_NATIVES(menuNatives)
    5.21  {
    5.22  	{"AddMenuItem",				AddMenuItem},
    5.23 @@ -1331,6 +1337,7 @@
    5.24  	{"CancelClientMenu",		CancelClientMenu},
    5.25  	{"CancelMenu",				CancelMenu},
    5.26  	{"CancelVote",				CancelVote},
    5.27 +	{"CheckVoteDelay",			CheckVoteDelay},
    5.28  	{"CreateMenu",				CreateMenu},
    5.29  	{"CreateMenuEx",			CreateMenuEx},
    5.30  	{"CreatePanel",				CreatePanel},
     6.1 --- a/plugins/include/menus.inc	Thu Aug 09 18:25:00 2007 +0000
     6.2 +++ b/plugins/include/menus.inc	Thu Aug 09 19:05:34 2007 +0000
     6.3 @@ -459,6 +459,15 @@
     6.4  native SetVoteResultCallback(Handle:menu, VoteHandler:callback);
     6.5  
     6.6  /**
     6.7 + * Returns the number of seconds you should "wait" before displaying
     6.8 + * a publicly invocable menu.  This number is the time remaining until
     6.9 + * (last_vote + sm_vote_delay).
    6.10 + *
    6.11 + * @return					Number of seconds to wait, or 0 for none.
    6.12 + */
    6.13 +native CheckVoteDelay();
    6.14 +
    6.15 +/**
    6.16   * Returns a style's global Handle.
    6.17   *
    6.18   * @param style			Menu Style.
     7.1 --- a/public/IMenuManager.h	Thu Aug 09 18:25:00 2007 +0000
     7.2 +++ b/public/IMenuManager.h	Thu Aug 09 19:05:34 2007 +0000
     7.3 @@ -807,6 +807,14 @@
     7.4  		 * @brief Cancels the vote in progress.  This calls IBaseMenu::Cancel().
     7.5  		 */
     7.6  		virtual void CancelVoting() =0;
     7.7 +
     7.8 +		/**
     7.9 +		 * @brief Returns the remaining vote delay from the last menu.  This delay is 
    7.10 +		 * a suggestion for all public votes, and is not enforced.
    7.11 +		 *
    7.12 +		 * @return				Number of seconds to wait.
    7.13 +		 */
    7.14 +		virtual unsigned int GetRemainingVoteDelay() =0;
    7.15  	};
    7.16  }
    7.17