Fixed revote bug and inflexibilities in RedrawClientVoteMenu (bug 3834, r=fyren).

This commit is contained in:
David Anderson 2009-05-30 19:59:55 -04:00
parent c2c4ed1fe5
commit d4798ccaa5
7 changed files with 66 additions and 14 deletions

View File

@ -798,5 +798,11 @@ bool MenuManager::IsClientInVotePool(int client)
bool MenuManager::RedrawClientVoteMenu(int client) bool MenuManager::RedrawClientVoteMenu(int client)
{ {
return s_VoteHandler.RedrawToClient(client); return RedrawClientVoteMenu2(client, true);
} }
bool MenuManager::RedrawClientVoteMenu2(int client, bool revote)
{
return s_VoteHandler.RedrawToClient(client, revote);
}

View File

@ -91,6 +91,7 @@ public:
unsigned int GetRemainingVoteDelay(); unsigned int GetRemainingVoteDelay();
bool IsClientInVotePool(int client); bool IsClientInVotePool(int client);
bool RedrawClientVoteMenu(int client); bool RedrawClientVoteMenu(int client);
bool RedrawClientVoteMenu2(int client, bool revote);
public: //IHandleTypeDispatch public: //IHandleTypeDispatch
void OnHandleDestroy(HandleType_t type, void *object); void OnHandleDestroy(HandleType_t type, void *object);
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize); bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);

View File

@ -1,8 +1,8 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 sw=4 :
* ============================================================================= * =============================================================================
* SourceMod * SourceMod
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
@ -205,7 +205,7 @@ bool VoteMenuHandler::GetClientVoteChoice(int client, unsigned int *pItem)
return true; return true;
} }
bool VoteMenuHandler::RedrawToClient(int client) bool VoteMenuHandler::RedrawToClient(int client, bool revotes)
{ {
unsigned int time_limit; unsigned int time_limit;
@ -214,6 +214,18 @@ bool VoteMenuHandler::RedrawToClient(int client)
return false; return false;
} }
if (m_ClientVotes[client] >= 0)
{
if ((m_VoteFlags & VOTEFLAG_NO_REVOTES) == VOTEFLAG_NO_REVOTES || !revotes)
{
return false;
}
assert((unsigned)m_ClientVotes[client] < m_Items);
assert(m_Votes[m_ClientVotes[client]] > 0);
m_Votes[m_ClientVotes[client]]--;
m_ClientVotes[client] = -1;
}
if (m_nMenuTime == MENU_TIME_FOREVER) if (m_nMenuTime == MENU_TIME_FOREVER)
{ {
time_limit = m_nMenuTime; time_limit = m_nMenuTime;
@ -489,3 +501,4 @@ bool VoteMenuHandler::IsCancelling()
{ {
return m_bCancelled; return m_bCancelled;
} }

View File

@ -74,7 +74,7 @@ public:
unsigned int GetRemainingVoteDelay(); unsigned int GetRemainingVoteDelay();
bool IsClientInVotePool(int client); bool IsClientInVotePool(int client);
bool GetClientVoteChoice(int client, unsigned int *pItem); bool GetClientVoteChoice(int client, unsigned int *pItem);
bool RedrawToClient(int client); bool RedrawToClient(int client, bool revote);
private: private:
void Reset(IMenuHandler *mh); void Reset(IMenuHandler *mh);
void DecrementPlayerCount(); void DecrementPlayerCount();
@ -102,3 +102,4 @@ private:
}; };
#endif //_INCLUDE_SOURCEMOD_MENUVOTING_H_ #endif //_INCLUDE_SOURCEMOD_MENUVOTING_H_

View File

@ -676,7 +676,13 @@ static cell_t VoteMenu(IPluginContext *pContext, const cell_t *params)
cell_t *addr; cell_t *addr;
pContext->LocalToPhysAddr(params[2], &addr); pContext->LocalToPhysAddr(params[2], &addr);
if (!g_Menus.StartVote(menu, params[3], addr, params[4])) cell_t flags = 0;
if (params[0] >= 5)
{
flags = params[5];
}
if (!g_Menus.StartVote(menu, params[3], addr, params[4], flags))
{ {
return 0; return 0;
} }
@ -1445,7 +1451,13 @@ static cell_t RedrawClientVoteMenu(IPluginContext *pContext, const cell_t *param
return pContext->ThrowNativeError("Client is not in the voting pool"); return pContext->ThrowNativeError("Client is not in the voting pool");
} }
return g_Menus.RedrawClientVoteMenu(client) ? 1 : 0; bool revote = true;
if (params[0] >= 2 && !params[2])
{
revote = false;
}
return g_Menus.RedrawClientVoteMenu2(client, revote) ? 1 : 0;
} }
class EmptyMenuHandler : public IMenuHandler class EmptyMenuHandler : public IMenuHandler
@ -1567,3 +1579,4 @@ REGISTER_NATIVES(menuNatives)
{"VoteMenu", VoteMenu}, {"VoteMenu", VoteMenu},
{NULL, NULL}, {NULL, NULL},
}; };

View File

@ -94,6 +94,8 @@ enum MenuAction
#define VOTEINFO_ITEM_INDEX 0 /**< Item index */ #define VOTEINFO_ITEM_INDEX 0 /**< Item index */
#define VOTEINFO_ITEM_VOTES 1 /**< Number of votes for the item */ #define VOTEINFO_ITEM_VOTES 1 /**< Number of votes for the item */
#define VOTEFLAG_NO_REVOTES (1<<0) /**< Players cannot change their votes */
/** /**
* Reasons a menu can be cancelled (MenuAction_Cancel). * Reasons a menu can be cancelled (MenuAction_Cancel).
*/ */
@ -469,22 +471,24 @@ native CancelVote();
* @param clients Array of clients to broadcast to. * @param clients Array of clients to broadcast to.
* @param numClients Number of clients in the array. * @param numClients Number of clients in the array.
* @param time Maximum time to leave menu on the screen. * @param time Maximum time to leave menu on the screen.
* @param flags Optional voting flags.
* @return True on success, false if this menu already has a vote session * @return True on success, false if this menu already has a vote session
* in progress. * in progress.
* @error Invalid Handle, or a vote is already in progress. * @error Invalid Handle, or a vote is already in progress.
*/ */
native bool:VoteMenu(Handle:menu, clients[], numClients, time); native bool:VoteMenu(Handle:menu, clients[], numClients, time, flags=0);
/** /**
* Sends a vote menu to all clients. See VoteMenu() for more information. * Sends a vote menu to all clients. See VoteMenu() for more information.
* *
* @param menu Menu Handle. * @param menu Menu Handle.
* @param time Maximum time to leave menu on the screen. * @param time Maximum time to leave menu on the screen.
* @param flags Optional voting flags.
* @return True on success, false if this menu already has a vote session * @return True on success, false if this menu already has a vote session
* in progress. * in progress.
* @error Invalid Handle. * @error Invalid Handle.
*/ */
stock VoteMenuToAll(Handle:menu, time) stock VoteMenuToAll(Handle:menu, time, flags=0)
{ {
new num = GetMaxClients(); new num = GetMaxClients();
new total; new total;
@ -499,7 +503,7 @@ stock VoteMenuToAll(Handle:menu, time)
players[total++] = i; players[total++] = i;
} }
return VoteMenu(menu, players, total, time); return VoteMenu(menu, players, total, time, flags);
} }
/** /**
* Callback for when a vote has ended and results are available. * Callback for when a vote has ended and results are available.
@ -543,7 +547,7 @@ native CheckVoteDelay();
/** /**
* Returns whether a client is in the pool of clients allowed * Returns whether a client is in the pool of clients allowed
* to participate in the current vote. This is determined by * to participate in the current vote. This is determined by
* the client list passed to StartVote(). * the client list passed to VoteMenu().
* *
* @param client Client index. * @param client Client index.
* @return True if client is allowed to vote, false otherwise. * @return True if client is allowed to vote, false otherwise.
@ -555,12 +559,13 @@ native bool:IsClientInVotePool(client);
* Redraws the current vote menu to a client in the voting pool. * Redraws the current vote menu to a client in the voting pool.
* *
* @param client Client index. * @param client Client index.
* @param revotes True to allow revotes, false otherwise.
* @return True on success, false if the client is in the vote pool * @return True on success, false if the client is in the vote pool
* but cannot vote again. * but cannot vote again.
* @error No vote in progress, client is not in the voting pool, * @error No vote in progress, client is not in the voting pool,
* or client index is invalid. * or client index is invalid.
*/ */
native bool:RedrawClientVoteMenu(client); native bool:RedrawClientVoteMenu(client, bool:revotes=true);
/** /**
* Returns a style's global Handle. * Returns a style's global Handle.
@ -807,3 +812,4 @@ stock bool:IsNewVoteAllowed()
return true; return true;
} }

View File

@ -36,7 +36,7 @@
#include <IHandleSys.h> #include <IHandleSys.h>
#define SMINTERFACE_MENUMANAGER_NAME "IMenuManager" #define SMINTERFACE_MENUMANAGER_NAME "IMenuManager"
#define SMINTERFACE_MENUMANAGER_VERSION 15 #define SMINTERFACE_MENUMANAGER_VERSION 16
/** /**
* @file IMenuManager.h * @file IMenuManager.h
@ -179,6 +179,8 @@ namespace SourceMod
#define MENUFLAG_BUTTON_EXITBACK (1<<1) /**< Menu has an "exit back" button */ #define MENUFLAG_BUTTON_EXITBACK (1<<1) /**< Menu has an "exit back" button */
#define MENUFLAG_NO_SOUND (1<<2) /**< Menu will not have any select sounds */ #define MENUFLAG_NO_SOUND (1<<2) /**< Menu will not have any select sounds */
#define VOTEFLAG_NO_REVOTES (1<<0) /**< Players cannot change their votes */
/** /**
* @brief Extended menu options. * @brief Extended menu options.
*/ */
@ -869,7 +871,7 @@ namespace SourceMod
* @param num_clients Number of clients to display to. * @param num_clients Number of clients to display to.
* @param clients Client index array. * @param clients Client index array.
* @param max_time Maximum time to hold menu for. * @param max_time Maximum time to hold menu for.
* @param flags Vote flags (currently unused). * @param flags Vote flags.
* @return True on success, false if a vote is in progress. * @return True on success, false if a vote is in progress.
*/ */
virtual bool StartVote(IBaseMenu *menu, virtual bool StartVote(IBaseMenu *menu,
@ -914,7 +916,17 @@ namespace SourceMod
* @return True on success, false if client is not allowed to vote. * @return True on success, false if client is not allowed to vote.
*/ */
virtual bool RedrawClientVoteMenu(int client) =0; virtual bool RedrawClientVoteMenu(int client) =0;
/**
* @brief Redraws the current vote menu to a client in the voting pool.
*
* @param client Client index.
* @param revotes True to allow revotes, false otherwise.
* @return True on success, false if client is not allowed to vote.
*/
virtual bool RedrawClientVoteMenu2(int client, bool revotes) =0;
}; };
} }
#endif //_INCLUDE_SOURCEMOD_MENU_SYSTEM_H_ #endif //_INCLUDE_SOURCEMOD_MENU_SYSTEM_H_