added amb764, vote delay setting
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401297
This commit is contained in:
parent
3cd3a0a8d6
commit
e6fa620ae2
@ -692,3 +692,8 @@ void MenuManager::CancelVoting()
|
||||
{
|
||||
s_VoteHandler.CancelVoting();
|
||||
}
|
||||
|
||||
unsigned int MenuManager::GetRemainingVoteDelay()
|
||||
{
|
||||
return s_VoteHandler.GetRemainingVoteDelay();
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ public:
|
||||
unsigned int flags=0);
|
||||
bool IsVoteInProgress();
|
||||
void CancelVoting();
|
||||
unsigned int GetRemainingVoteDelay();
|
||||
public: //IHandleTypeDispatch
|
||||
void OnHandleDestroy(HandleType_t type, void *object);
|
||||
public:
|
||||
|
@ -36,6 +36,49 @@
|
||||
#include "PlayerManager.h"
|
||||
#include "sourcemm_api.h"
|
||||
|
||||
float g_next_vote = 0.0f;
|
||||
|
||||
void OnVoteDelayChange(ConVar *cvar, const char *value);
|
||||
ConVar sm_vote_delay("sm_vote_delay",
|
||||
"30",
|
||||
0,
|
||||
"Sets the recommended time in between public votes",
|
||||
false,
|
||||
0.0,
|
||||
false,
|
||||
0.0,
|
||||
OnVoteDelayChange);
|
||||
|
||||
void OnVoteDelayChange(ConVar *cvar, const char *value)
|
||||
{
|
||||
/* See if the new vote delay isn't something we need to account for */
|
||||
if (sm_vote_delay.GetFloat() < 1.0f)
|
||||
{
|
||||
g_next_vote = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
/* If there was never a last vote, ignore this change */
|
||||
if (g_next_vote < 0.1f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Subtract the original value, then add the new one. */
|
||||
g_next_vote -= (float)atof(value);
|
||||
g_next_vote += sm_vote_delay.GetFloat();
|
||||
}
|
||||
|
||||
unsigned int VoteMenuHandler::GetRemainingVoteDelay()
|
||||
{
|
||||
if (g_next_vote <= gpGlobals->curtime)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (unsigned int)(g_next_vote - gpGlobals->curtime);
|
||||
}
|
||||
|
||||
void VoteMenuHandler::OnSourceModAllInitialized()
|
||||
{
|
||||
g_Players.AddClientListener(this);
|
||||
@ -46,6 +89,11 @@ void VoteMenuHandler::OnSourceModShutdown()
|
||||
g_Players.RemoveClientListener(this);
|
||||
}
|
||||
|
||||
void VoteMenuHandler::OnSourceModLevelChange(const char *mapName)
|
||||
{
|
||||
g_next_vote = 0.0f;
|
||||
}
|
||||
|
||||
unsigned int VoteMenuHandler::GetMenuAPIVersion2()
|
||||
{
|
||||
return m_pHandler->GetMenuAPIVersion2();
|
||||
@ -81,6 +129,18 @@ bool VoteMenuHandler::StartVote(IBaseMenu *menu, unsigned int num_clients, int c
|
||||
return false;
|
||||
}
|
||||
|
||||
float fVoteDelay = sm_vote_delay.GetFloat();
|
||||
if (fVoteDelay < 1.0)
|
||||
{
|
||||
g_next_vote = 0.0;
|
||||
} else {
|
||||
/* This little trick breaks for infinite votes!
|
||||
* However, we just ignore that since those 1) shouldn't exist and
|
||||
* 2) people must be checking IsVoteInProgress() beforehand anyway.
|
||||
*/
|
||||
g_next_vote = gpGlobals->curtime + fVoteDelay + (float)max_time;
|
||||
}
|
||||
|
||||
for (unsigned int i=0; i<num_clients; i++)
|
||||
{
|
||||
menu->Display(clients[i], max_time, this);
|
||||
@ -177,6 +237,18 @@ int SortVoteItems(const void *item1, const void *item2)
|
||||
|
||||
void VoteMenuHandler::EndVoting()
|
||||
{
|
||||
/* Set when the next delay ends. We ignore cancellation because a menu
|
||||
* was, at one point, displayed, which is all that counts. However, we
|
||||
* do re-calculate the time just in case the menu had no time limit.
|
||||
*/
|
||||
float fVoteDelay = sm_vote_delay.GetFloat();
|
||||
if (fVoteDelay < 1.0)
|
||||
{
|
||||
g_next_vote = 0.0;
|
||||
} else {
|
||||
g_next_vote = gpGlobals->curtime + fVoteDelay;
|
||||
}
|
||||
|
||||
if (m_bCancelled)
|
||||
{
|
||||
/* If we were cancelled, don't bother tabulating anything.
|
||||
|
@ -49,6 +49,7 @@ class VoteMenuHandler :
|
||||
public: //SMGlobalClass
|
||||
void OnSourceModAllInitialized();
|
||||
void OnSourceModShutdown();
|
||||
void OnSourceModLevelChange(const char *mapName);
|
||||
public: //IClientListener
|
||||
void OnClientDisconnected(int client);
|
||||
public: //IMenuHandler
|
||||
@ -70,6 +71,7 @@ public:
|
||||
void CancelVoting();
|
||||
IBaseMenu *GetCurrentMenu();
|
||||
bool IsCancelling();
|
||||
unsigned int GetRemainingVoteDelay();
|
||||
private:
|
||||
void Reset(IMenuHandler *mh);
|
||||
void DecrementPlayerCount();
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "HandleSys.h"
|
||||
#include "PluginSys.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include "sourcemm_api.h"
|
||||
#if defined MENU_DEBUG
|
||||
#include "Logger.h"
|
||||
#endif
|
||||
@ -1324,6 +1325,11 @@ static cell_t SetVoteResultCallback(IPluginContext *pContext, const cell_t *para
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t CheckVoteDelay(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
return g_Menus.GetRemainingVoteDelay();
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(menuNatives)
|
||||
{
|
||||
{"AddMenuItem", AddMenuItem},
|
||||
@ -1331,6 +1337,7 @@ REGISTER_NATIVES(menuNatives)
|
||||
{"CancelClientMenu", CancelClientMenu},
|
||||
{"CancelMenu", CancelMenu},
|
||||
{"CancelVote", CancelVote},
|
||||
{"CheckVoteDelay", CheckVoteDelay},
|
||||
{"CreateMenu", CreateMenu},
|
||||
{"CreateMenuEx", CreateMenuEx},
|
||||
{"CreatePanel", CreatePanel},
|
||||
|
@ -458,6 +458,15 @@ functag VoteHandler public(Handle:menu,
|
||||
*/
|
||||
native SetVoteResultCallback(Handle:menu, VoteHandler:callback);
|
||||
|
||||
/**
|
||||
* Returns the number of seconds you should "wait" before displaying
|
||||
* a publicly invocable menu. This number is the time remaining until
|
||||
* (last_vote + sm_vote_delay).
|
||||
*
|
||||
* @return Number of seconds to wait, or 0 for none.
|
||||
*/
|
||||
native CheckVoteDelay();
|
||||
|
||||
/**
|
||||
* Returns a style's global Handle.
|
||||
*
|
||||
|
@ -807,6 +807,14 @@ namespace SourceMod
|
||||
* @brief Cancels the vote in progress. This calls IBaseMenu::Cancel().
|
||||
*/
|
||||
virtual void CancelVoting() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the remaining vote delay from the last menu. This delay is
|
||||
* a suggestion for all public votes, and is not enforced.
|
||||
*
|
||||
* @return Number of seconds to wait.
|
||||
*/
|
||||
virtual unsigned int GetRemainingVoteDelay() =0;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user