From 54febbbc48ef9bc77e581e8d4bf4bb6389f35b57 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 16 Oct 2007 19:28:02 +0000 Subject: [PATCH] cleaned up menu vote code a bit --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401600 --- plugins/basefunvotes/votealltalk.sp | 2 +- plugins/basefunvotes/voteburn.sp | 2 +- plugins/basefunvotes/voteff.sp | 2 +- plugins/basefunvotes/votegravity.sp | 2 +- plugins/basefunvotes/voteslay.sp | 2 +- plugins/basevotes/voteban.sp | 2 +- plugins/basevotes/votekick.sp | 2 +- plugins/basevotes/votemap.sp | 4 +++- plugins/include/menus.inc | 18 ++++++++++++++++++ 9 files changed, 28 insertions(+), 8 deletions(-) diff --git a/plugins/basefunvotes/votealltalk.sp b/plugins/basefunvotes/votealltalk.sp index d673c6de..f4804dbd 100644 --- a/plugins/basefunvotes/votealltalk.sp +++ b/plugins/basefunvotes/votealltalk.sp @@ -53,7 +53,7 @@ public AdminMenu_VoteAllTalk(Handle:topmenu, else if (action == TopMenuAction_DrawOption) { /* disable this option if a vote is already running */ - buffer[0] = IsVoteInProgress() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; + buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; } } diff --git a/plugins/basefunvotes/voteburn.sp b/plugins/basefunvotes/voteburn.sp index 2e69d2bc..cf455a27 100644 --- a/plugins/basefunvotes/voteburn.sp +++ b/plugins/basefunvotes/voteburn.sp @@ -54,7 +54,7 @@ public AdminMenu_VoteBurn(Handle:topmenu, else if (action == TopMenuAction_DrawOption) { /* disable this option if a vote is already running */ - buffer[0] = IsVoteInProgress() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; + buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; } } diff --git a/plugins/basefunvotes/voteff.sp b/plugins/basefunvotes/voteff.sp index f27af390..c7081c09 100644 --- a/plugins/basefunvotes/voteff.sp +++ b/plugins/basefunvotes/voteff.sp @@ -52,7 +52,7 @@ public AdminMenu_VoteFF(Handle:topmenu, else if (action == TopMenuAction_DrawOption) { /* disable this option if a vote is already running */ - buffer[0] = IsVoteInProgress() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; + buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; } } diff --git a/plugins/basefunvotes/votegravity.sp b/plugins/basefunvotes/votegravity.sp index 623850ab..923bc0e2 100644 --- a/plugins/basefunvotes/votegravity.sp +++ b/plugins/basefunvotes/votegravity.sp @@ -51,7 +51,7 @@ public AdminMenu_VoteGravity(Handle:topmenu, else if (action == TopMenuAction_DrawOption) { /* disable this option if a vote is already running */ - buffer[0] = IsVoteInProgress() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; + buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; } } diff --git a/plugins/basefunvotes/voteslay.sp b/plugins/basefunvotes/voteslay.sp index 601c3398..d1ed2e3b 100644 --- a/plugins/basefunvotes/voteslay.sp +++ b/plugins/basefunvotes/voteslay.sp @@ -55,7 +55,7 @@ public AdminMenu_VoteSlay(Handle:topmenu, else if (action == TopMenuAction_DrawOption) { /* disable this option if a vote is already running */ - buffer[0] = IsVoteInProgress() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; + buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; } } diff --git a/plugins/basevotes/voteban.sp b/plugins/basevotes/voteban.sp index 301bbf49..16831856 100644 --- a/plugins/basevotes/voteban.sp +++ b/plugins/basevotes/voteban.sp @@ -53,7 +53,7 @@ public AdminMenu_VoteBan(Handle:topmenu, else if (action == TopMenuAction_DrawOption) { /* disable this option if a vote is already running */ - buffer[0] = IsVoteInProgress() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; + buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; } } diff --git a/plugins/basevotes/votekick.sp b/plugins/basevotes/votekick.sp index b37a8406..c6943069 100644 --- a/plugins/basevotes/votekick.sp +++ b/plugins/basevotes/votekick.sp @@ -52,7 +52,7 @@ public AdminMenu_VoteKick(Handle:topmenu, else if (action == TopMenuAction_DrawOption) { /* disable this option if a vote is already running */ - buffer[0] = IsVoteInProgress() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; + buffer[0] = !IsNewVoteAllowed() ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; } } diff --git a/plugins/basevotes/votemap.sp b/plugins/basevotes/votemap.sp index 2675ff17..5c4c79a1 100644 --- a/plugins/basevotes/votemap.sp +++ b/plugins/basevotes/votemap.sp @@ -50,9 +50,11 @@ public MenuHandler_Confirm(Handle:menu, MenuAction:action, param1, param2) if (action == MenuAction_End) { CloseHandle(menu); + g_VoteMapInUse = false; } else if (action == MenuAction_Cancel) { + g_VoteMapInUse = false; if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE) { DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory); @@ -144,7 +146,7 @@ public AdminMenu_VoteMap(Handle:topmenu, else if (action == TopMenuAction_DrawOption) { /* disable this option if a vote is already running, theres no maps listed or someone else has already acessed this menu */ - buffer[0] = (IsVoteInProgress() || g_mapCount < 1 || g_VoteMapInUse) ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT; + buffer[0] = (!IsNewVoteAllowed() || g_mapCount < 1 || g_VoteMapInUse) ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT; } } diff --git a/plugins/include/menus.inc b/plugins/include/menus.inc index 4399e30a..bc61f58b 100644 --- a/plugins/include/menus.inc +++ b/plugins/include/menus.inc @@ -731,3 +731,21 @@ stock GetMenuVoteInfo(param2, &winningVotes, &totalVotes) winningVotes = param2 & 0xFFFF; totalVotes = param2 >> 16; } + +/** + * Quick stock to determine whether voting is allowed. This doesn't let you + * fine-tune a reason for not voting, so it's not recommended for lazily + * telling clients that voting isn't allowed. + * + * @return True if voting is allowed, false if voting is in progress + * or the cooldown is active. + */ +stock bool:IsNewVoteAllowed() +{ + if (IsVoteInProgress() || CheckVoteDelay() != 0) + { + return false; + } + + return true; +}