added vote functionality
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40884
This commit is contained in:
parent
aea69f5fe8
commit
2ee18824e9
@ -757,16 +757,6 @@
|
|||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
|
||||||
Name="Resources"
|
|
||||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
|
||||||
UniqueIdentifier="{2A750240-7C10-455f-A900-B9A9D362356C}"
|
|
||||||
>
|
|
||||||
<File
|
|
||||||
RelativePath="..\version.rc"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
<Filter
|
||||||
Name="HL2SDK"
|
Name="HL2SDK"
|
||||||
UniqueIdentifier="{80B56842-7A9F-4d5d-8149-767C285D0EB4}"
|
UniqueIdentifier="{80B56842-7A9F-4d5d-8149-767C285D0EB4}"
|
||||||
@ -877,6 +867,16 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Resources"
|
||||||
|
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||||
|
UniqueIdentifier="{2A750240-7C10-455f-A900-B9A9D362356C}"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\version.rc"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Files>
|
</Files>
|
||||||
<Globals>
|
<Globals>
|
||||||
</Globals>
|
</Globals>
|
||||||
|
@ -38,6 +38,7 @@ enum MenuAction
|
|||||||
MenuAction_Cancel = (1<<3), /**< The menu was cancelled (param1=client, param2=item) */
|
MenuAction_Cancel = (1<<3), /**< The menu was cancelled (param1=client, param2=item) */
|
||||||
MenuAction_End = (1<<4), /**< A menu's display/selection cycle is complete (nothing passed). */
|
MenuAction_End = (1<<4), /**< A menu's display/selection cycle is complete (nothing passed). */
|
||||||
MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has ended (param1=chosen item) */
|
MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has ended (param1=chosen item) */
|
||||||
|
MenuAction_VoteStart = (1<<6), /**< (VOTE ONLY): A vote sequence has started */
|
||||||
};
|
};
|
||||||
|
|
||||||
class CPanelHandler : public IMenuHandler
|
class CPanelHandler : public IMenuHandler
|
||||||
@ -66,10 +67,14 @@ public:
|
|||||||
void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason);
|
void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason);
|
||||||
void OnMenuEnd(IBaseMenu *menu);
|
void OnMenuEnd(IBaseMenu *menu);
|
||||||
void OnMenuDestroy(IBaseMenu *menu);
|
void OnMenuDestroy(IBaseMenu *menu);
|
||||||
|
void OnMenuVoteStart(IBaseMenu *menu);
|
||||||
|
void OnMenuVoteEnd(IBaseMenu *menu, unsigned int item);
|
||||||
#if 0
|
#if 0
|
||||||
void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style);
|
void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style);
|
||||||
void OnMenuDisplayItem(IBaseMenu *menu, int client, unsigned int item, const char **display);
|
void OnMenuDisplayItem(IBaseMenu *menu, int client, unsigned int item, const char **display);
|
||||||
#endif
|
#endif
|
||||||
|
private:
|
||||||
|
void DoAction(IBaseMenu *menu, MenuAction action, cell_t param1, cell_t param2);
|
||||||
private:
|
private:
|
||||||
IPluginFunction *m_pBasic;
|
IPluginFunction *m_pBasic;
|
||||||
int m_Flags;
|
int m_Flags;
|
||||||
@ -232,11 +237,7 @@ void CMenuHandler::OnMenuStart(IBaseMenu *menu)
|
|||||||
{
|
{
|
||||||
if ((m_Flags & (int)MenuAction_Start) == (int)MenuAction_Start)
|
if ((m_Flags & (int)MenuAction_Start) == (int)MenuAction_Start)
|
||||||
{
|
{
|
||||||
m_pBasic->PushCell(menu->GetHandle());
|
DoAction(menu, MenuAction_Start, 0, 0);
|
||||||
m_pBasic->PushCell(MenuAction_Start);
|
|
||||||
m_pBasic->PushCell(0);
|
|
||||||
m_pBasic->PushCell(0);
|
|
||||||
m_pBasic->Execute(NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,11 +255,7 @@ void CMenuHandler::OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *panel)
|
|||||||
|
|
||||||
Handle_t hndl = g_HandleSys.CreateHandleEx(g_MenuHelpers.GetPanelType(), panel, &sec, &access, NULL);
|
Handle_t hndl = g_HandleSys.CreateHandleEx(g_MenuHelpers.GetPanelType(), panel, &sec, &access, NULL);
|
||||||
|
|
||||||
m_pBasic->PushCell(menu->GetHandle());
|
DoAction(menu, MenuAction_Display, client, hndl);
|
||||||
m_pBasic->PushCell(MenuAction_Display);
|
|
||||||
m_pBasic->PushCell(client);
|
|
||||||
m_pBasic->PushCell(hndl);
|
|
||||||
m_pBasic->Execute(NULL);
|
|
||||||
|
|
||||||
g_HandleSys.FreeHandle(hndl, &sec);
|
g_HandleSys.FreeHandle(hndl, &sec);
|
||||||
}
|
}
|
||||||
@ -266,29 +263,17 @@ void CMenuHandler::OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *panel)
|
|||||||
|
|
||||||
void CMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
|
void CMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
|
||||||
{
|
{
|
||||||
m_pBasic->PushCell(menu->GetHandle());
|
DoAction(menu, MenuAction_Select, client, item);
|
||||||
m_pBasic->PushCell(MenuAction_Select);
|
|
||||||
m_pBasic->PushCell(client);
|
|
||||||
m_pBasic->PushCell(item);
|
|
||||||
m_pBasic->Execute(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMenuHandler::OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
|
void CMenuHandler::OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
|
||||||
{
|
{
|
||||||
m_pBasic->PushCell(menu->GetHandle());
|
DoAction(menu, MenuAction_Cancel, client, (cell_t)reason);
|
||||||
m_pBasic->PushCell(MenuAction_Cancel);
|
|
||||||
m_pBasic->PushCell(client);
|
|
||||||
m_pBasic->PushCell(reason);
|
|
||||||
m_pBasic->Execute(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMenuHandler::OnMenuEnd(IBaseMenu *menu)
|
void CMenuHandler::OnMenuEnd(IBaseMenu *menu)
|
||||||
{
|
{
|
||||||
m_pBasic->PushCell(menu->GetHandle());
|
DoAction(menu, MenuAction_End, 0, 0);
|
||||||
m_pBasic->PushCell(MenuAction_End);
|
|
||||||
m_pBasic->PushCell(0);
|
|
||||||
m_pBasic->PushCell(0);
|
|
||||||
m_pBasic->Execute(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMenuHandler::OnMenuDestroy(IBaseMenu *menu)
|
void CMenuHandler::OnMenuDestroy(IBaseMenu *menu)
|
||||||
@ -296,6 +281,25 @@ void CMenuHandler::OnMenuDestroy(IBaseMenu *menu)
|
|||||||
g_MenuHelpers.FreeMenuHandler(this);
|
g_MenuHelpers.FreeMenuHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMenuHandler::OnMenuVoteStart(IBaseMenu *menu)
|
||||||
|
{
|
||||||
|
DoAction(menu, MenuAction_VoteStart, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMenuHandler::OnMenuVoteEnd(IBaseMenu *menu, unsigned int item)
|
||||||
|
{
|
||||||
|
DoAction(menu, MenuAction_VoteEnd, item, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMenuHandler::DoAction(IBaseMenu *menu, MenuAction action, cell_t param1, cell_t param2)
|
||||||
|
{
|
||||||
|
m_pBasic->PushCell(menu->GetHandle());
|
||||||
|
m_pBasic->PushCell((cell_t)action);
|
||||||
|
m_pBasic->PushCell(param1);
|
||||||
|
m_pBasic->PushCell(param2);
|
||||||
|
m_pBasic->Execute(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INLINE FUNCTIONS FOR NATIVES
|
* INLINE FUNCTIONS FOR NATIVES
|
||||||
*/
|
*/
|
||||||
@ -375,6 +379,23 @@ static cell_t DisplayMenu(IPluginContext *pContext, const cell_t *params)
|
|||||||
return menu->Display(params[2], params[3]) ? 1 : 0;
|
return menu->Display(params[2], params[3]) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell_t VoteMenu(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
Handle_t hndl = (Handle_t)params[1];
|
||||||
|
HandleError err;
|
||||||
|
IBaseMenu *menu;
|
||||||
|
|
||||||
|
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
cell_t *addr;
|
||||||
|
pContext->LocalToPhysAddr(params[2], &addr);
|
||||||
|
|
||||||
|
return menu->BroadcastVote(addr, params[3], params[4]);
|
||||||
|
}
|
||||||
|
|
||||||
static cell_t AddMenuItem(IPluginContext *pContext, const cell_t *params)
|
static cell_t AddMenuItem(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
Handle_t hndl = (Handle_t)params[1];
|
Handle_t hndl = (Handle_t)params[1];
|
||||||
@ -930,5 +951,6 @@ REGISTER_NATIVES(menuNatives)
|
|||||||
{"SetPanelCurrentKey", SetPanelCurrentKey},
|
{"SetPanelCurrentKey", SetPanelCurrentKey},
|
||||||
{"SetPanelTitle", SetPanelTitle},
|
{"SetPanelTitle", SetPanelTitle},
|
||||||
{"SetPanelKeys", SetPanelKeys},
|
{"SetPanelKeys", SetPanelKeys},
|
||||||
|
{"VoteMenu", VoteMenu},
|
||||||
{NULL, NULL},
|
{NULL, NULL},
|
||||||
};
|
};
|
||||||
|
@ -39,6 +39,7 @@ enum MenuAction
|
|||||||
MenuAction_Cancel = (1<<3), /**< The menu was cancelled (param1=client, param2=reason) */
|
MenuAction_Cancel = (1<<3), /**< The menu was cancelled (param1=client, param2=reason) */
|
||||||
MenuAction_End = (1<<4), /**< A menu's display/selection cycle is complete (nothing passed). */
|
MenuAction_End = (1<<4), /**< A menu's display/selection cycle is complete (nothing passed). */
|
||||||
MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has ended (param1=chosen item) */
|
MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has ended (param1=chosen item) */
|
||||||
|
MenuAction_VoteStart = (1<<6), /**< (VOTE ONLY): A vote sequence has started */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Default menu actions */
|
/** Default menu actions */
|
||||||
@ -273,45 +274,34 @@ native bool:SetMenuExitButton(Handle:menu, bool:button);
|
|||||||
*/
|
*/
|
||||||
native CancelMenu(Handle:menu);
|
native CancelMenu(Handle:menu);
|
||||||
|
|
||||||
#if 0
|
|
||||||
/**
|
/**
|
||||||
* Broadcasts a menu to a list of clients.
|
* Broadcasts a menu to a list of clients. The most selected item will be
|
||||||
|
* returned through MenuAction_End. On a tie, a random item will be returned
|
||||||
|
* from a list of the tied items.
|
||||||
|
*
|
||||||
|
* Note that MenuAction_VoteEnd and MenuAction_VoteStart are both
|
||||||
|
* default callbacks and do not need to be enabled.
|
||||||
*
|
*
|
||||||
* @param menu Menu Handle.
|
* @param menu Menu Handle.
|
||||||
* @param handler MenuHandler callback to receive actions.
|
* @param clients Array of clients to broadcast to.
|
||||||
* @param players Array of players to broadcast to.
|
* @param numClients Number of clients in the array.
|
||||||
* @param numPlayers Number of players in the array.
|
|
||||||
* @param time Maximum time to leave menu on the screen.
|
* @param time Maximum time to leave menu on the screen.
|
||||||
* @return Number of clients that broadcast will wait upon.
|
* @return True on success, false if this menu already has a vote session
|
||||||
|
* in progress.
|
||||||
* @error Invalid Handle.
|
* @error Invalid Handle.
|
||||||
*/
|
*/
|
||||||
native BroadcastMenu(Handle:menu, MenuHandler:handler, players[], numPlayers, time);
|
native bool:VoteMenu(Handle:menu, clients[], numClients, time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcasts a menu to a list of clients. The most selected
|
* Sends a vote menu to all clients. See VoteMenu() for more information.
|
||||||
* item will be returned through MenuAction_End. On a tie, a random
|
|
||||||
* item will be returned.
|
|
||||||
*
|
*
|
||||||
* @param menu Menu Handle.
|
* @param menu Menu Handle.
|
||||||
* @param handler MenuHandler callback to receive actions.
|
|
||||||
* @param players Array of players to broadcast to.
|
|
||||||
* @param numPlayers Number of players in the array.
|
|
||||||
* @param time Maximum time to leave menu on the screen.
|
* @param time Maximum time to leave menu on the screen.
|
||||||
* @return Number of clients that vote will wait upon.
|
* @return True on success, false if this menu already has a vote session
|
||||||
|
* in progress.
|
||||||
* @error Invalid Handle.
|
* @error Invalid Handle.
|
||||||
*/
|
*/
|
||||||
native VoteMenu(Handle:menu, MenuHandler:handler, players[], numPlayers, time);
|
stock VoteMenuToAll(Handle:menu, time)
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcasts a menu to all clients.
|
|
||||||
*
|
|
||||||
* @param menu Menu Handle.
|
|
||||||
* @param handler MenuHandler callback to receive actions.
|
|
||||||
* @param time Maximum time to leave menu on the screen.
|
|
||||||
* @return Number of clients that broadcast will wait upon.
|
|
||||||
* @error Invalid Handle.
|
|
||||||
*/
|
|
||||||
stock BroadcastMenuToAll(Handle:menu, MenuHandler:handler, time)
|
|
||||||
{
|
{
|
||||||
new num = GetMaxClients();
|
new num = GetMaxClients();
|
||||||
new total;
|
new total;
|
||||||
@ -326,39 +316,9 @@ stock BroadcastMenuToAll(Handle:menu, MenuHandler:handler, time)
|
|||||||
players[total++] = i;
|
players[total++] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BroadcastMenu(menu, handler, players, total, time);
|
return VoteMenu(menu, players, total, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcasts a menu to all clients. The most selected item will
|
|
||||||
* be returned through MenuAction_End. On a tie, a random item
|
|
||||||
* will be returned.
|
|
||||||
*
|
|
||||||
* @param menu Menu Handle.
|
|
||||||
* @param handler MenuHandler callback to receive actions.
|
|
||||||
* @param time Maximum time to leave menu on the screen.
|
|
||||||
* @return Number of clients that the vote will wait upon.
|
|
||||||
* @error Invalid Handle.
|
|
||||||
*/
|
|
||||||
stock VoteMenuToAll(Handle:menu, MenuHandler:handler, time)
|
|
||||||
{
|
|
||||||
new num = GetMaxClients();
|
|
||||||
new total;
|
|
||||||
decl players[num];
|
|
||||||
|
|
||||||
for (new i=1; i<=num; i++)
|
|
||||||
{
|
|
||||||
if (!IsClientConnected(i))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
players[total++] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return VoteMenu(menu, handler, players, total, time);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a style's global Handle.
|
* Returns a style's global Handle.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user