diff --git a/core/MenuManager.cpp b/core/MenuManager.cpp index 5a66b8d0..051b7b7f 100644 --- a/core/MenuManager.cpp +++ b/core/MenuManager.cpp @@ -798,5 +798,11 @@ bool MenuManager::IsClientInVotePool(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); +} + diff --git a/core/MenuManager.h b/core/MenuManager.h index 3993eacf..7c43507f 100644 --- a/core/MenuManager.h +++ b/core/MenuManager.h @@ -91,6 +91,7 @@ public: unsigned int GetRemainingVoteDelay(); bool IsClientInVotePool(int client); bool RedrawClientVoteMenu(int client); + bool RedrawClientVoteMenu2(int client, bool revote); public: //IHandleTypeDispatch void OnHandleDestroy(HandleType_t type, void *object); bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize); diff --git a/core/MenuVoting.cpp b/core/MenuVoting.cpp index bc46bef4..53434070 100644 --- a/core/MenuVoting.cpp +++ b/core/MenuVoting.cpp @@ -1,8 +1,8 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 : * ============================================================================= * 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 @@ -205,7 +205,7 @@ bool VoteMenuHandler::GetClientVoteChoice(int client, unsigned int *pItem) return true; } -bool VoteMenuHandler::RedrawToClient(int client) +bool VoteMenuHandler::RedrawToClient(int client, bool revotes) { unsigned int time_limit; @@ -214,6 +214,18 @@ bool VoteMenuHandler::RedrawToClient(int client) 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) { time_limit = m_nMenuTime; @@ -489,3 +501,4 @@ bool VoteMenuHandler::IsCancelling() { return m_bCancelled; } + diff --git a/core/MenuVoting.h b/core/MenuVoting.h index 1627fd41..cef98280 100644 --- a/core/MenuVoting.h +++ b/core/MenuVoting.h @@ -74,7 +74,7 @@ public: unsigned int GetRemainingVoteDelay(); bool IsClientInVotePool(int client); bool GetClientVoteChoice(int client, unsigned int *pItem); - bool RedrawToClient(int client); + bool RedrawToClient(int client, bool revote); private: void Reset(IMenuHandler *mh); void DecrementPlayerCount(); @@ -102,3 +102,4 @@ private: }; #endif //_INCLUDE_SOURCEMOD_MENUVOTING_H_ + diff --git a/core/smn_menus.cpp b/core/smn_menus.cpp index 1e5d636a..ffb1a4a8 100644 --- a/core/smn_menus.cpp +++ b/core/smn_menus.cpp @@ -676,7 +676,13 @@ static cell_t VoteMenu(IPluginContext *pContext, const cell_t *params) cell_t *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; } @@ -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 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 @@ -1567,3 +1579,4 @@ REGISTER_NATIVES(menuNatives) {"VoteMenu", VoteMenu}, {NULL, NULL}, }; + diff --git a/plugins/include/menus.inc b/plugins/include/menus.inc index 587df79e..1d7d37d2 100644 --- a/plugins/include/menus.inc +++ b/plugins/include/menus.inc @@ -94,6 +94,8 @@ enum MenuAction #define VOTEINFO_ITEM_INDEX 0 /**< Item index */ #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). */ @@ -469,22 +471,24 @@ native CancelVote(); * @param clients Array of clients to broadcast to. * @param numClients Number of clients in the array. * @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 * 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. * * @param menu Menu Handle. * @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 * in progress. * @error Invalid Handle. */ -stock VoteMenuToAll(Handle:menu, time) +stock VoteMenuToAll(Handle:menu, time, flags=0) { new num = GetMaxClients(); new total; @@ -499,7 +503,7 @@ stock VoteMenuToAll(Handle:menu, time) 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. @@ -543,7 +547,7 @@ native CheckVoteDelay(); /** * Returns whether a client is in the pool of clients allowed * 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. * @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. * * @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 * but cannot vote again. * @error No vote in progress, client is not in the voting pool, * or client index is invalid. */ -native bool:RedrawClientVoteMenu(client); +native bool:RedrawClientVoteMenu(client, bool:revotes=true); /** * Returns a style's global Handle. @@ -807,3 +812,4 @@ stock bool:IsNewVoteAllowed() return true; } + diff --git a/public/IMenuManager.h b/public/IMenuManager.h index b85ca7d4..4717404d 100644 --- a/public/IMenuManager.h +++ b/public/IMenuManager.h @@ -36,7 +36,7 @@ #include #define SMINTERFACE_MENUMANAGER_NAME "IMenuManager" -#define SMINTERFACE_MENUMANAGER_VERSION 15 +#define SMINTERFACE_MENUMANAGER_VERSION 16 /** * @file IMenuManager.h @@ -179,6 +179,8 @@ namespace SourceMod #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 VOTEFLAG_NO_REVOTES (1<<0) /**< Players cannot change their votes */ + /** * @brief Extended menu options. */ @@ -869,7 +871,7 @@ namespace SourceMod * @param num_clients Number of clients to display to. * @param clients Client index array. * @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. */ virtual bool StartVote(IBaseMenu *menu, @@ -914,7 +916,17 @@ namespace SourceMod * @return True on success, false if client is not allowed to vote. */ 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_ +