From 58eedf6226a7bb3486187c150de5d7d712cb814d Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 21 Jun 2007 23:06:37 +0000 Subject: [PATCH] bumped menu api again - added feature to get menu end reason --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401003 --- core/MenuManager.cpp | 6 +++--- core/MenuManager.h | 2 +- core/MenuStyle_Base.cpp | 18 +++++++++++++----- core/MenuStyle_Valve.cpp | 2 +- core/smn_menus.cpp | 6 +++--- plugins/include/menus.inc | 14 +++++++++++++- public/IMenuManager.h | 19 ++++++++++++++++--- 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/core/MenuManager.cpp b/core/MenuManager.cpp index 15163999..288da579 100644 --- a/core/MenuManager.cpp +++ b/core/MenuManager.cpp @@ -104,7 +104,7 @@ void VoteMenuHandler::EndVoting() IBaseMenu *menu = m_pCurMenu; InternalReset(); m_pHandler->OnMenuVoteCancel(menu); - m_pHandler->OnMenuEnd(menu); + m_pHandler->OnMenuEnd(menu, MenuEnd_VotingCancelled); return; } @@ -163,7 +163,7 @@ void VoteMenuHandler::EndVoting() picked_item: m_pHandler->OnMenuVoteEnd(m_pCurMenu, chosen, m_Votes[highest], total); - m_pHandler->OnMenuEnd(m_pCurMenu); + m_pHandler->OnMenuEnd(m_pCurMenu, MenuEnd_VotingDone); InternalReset(); } @@ -172,7 +172,7 @@ void VoteMenuHandler::OnMenuStart(IBaseMenu *menu) m_Clients++; } -void VoteMenuHandler::OnMenuEnd(IBaseMenu *menu) +void VoteMenuHandler::OnMenuEnd(IBaseMenu *menu, MenuEndReason reason) { DecrementPlayerCount(); } diff --git a/core/MenuManager.h b/core/MenuManager.h index 8ce6870d..12a51670 100644 --- a/core/MenuManager.h +++ b/core/MenuManager.h @@ -33,7 +33,7 @@ public: //IMenuHandler void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display); void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item); void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason); - void OnMenuEnd(IBaseMenu *menu); + void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason); void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style); void OnMenuDisplayItem(IBaseMenu *menu, int client, unsigned int item, const char **display); public: //IVoteMenuHandler diff --git a/core/MenuStyle_Base.cpp b/core/MenuStyle_Base.cpp index 96a22560..8ec4c648 100644 --- a/core/MenuStyle_Base.cpp +++ b/core/MenuStyle_Base.cpp @@ -84,7 +84,7 @@ void BaseMenuStyle::_CancelClientMenu(int client, bool bAutoIgnore/* =false */, /* Only fire end if there's a valid menu */ if (menu) { - mh->OnMenuEnd(menu); + mh->OnMenuEnd(menu, MenuEnd_Cancelled); } if (bAutoIgnore) @@ -311,7 +311,15 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press) /* Only fire end for valid menus */ if (menu) { - mh->OnMenuEnd(menu); + MenuEndReason end_reason = + (cancel ? + MenuEnd_Selected + : + (reason == MenuCancel_Exit ? + MenuEnd_Exit + : + MenuEnd_Cancelled)); + mh->OnMenuEnd(menu, end_reason); } } @@ -392,7 +400,7 @@ bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Failed to display to client %d", client); #endif mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay); - mh->OnMenuEnd(menu); + mh->OnMenuEnd(menu, MenuEnd_Cancelled); return false; } @@ -403,7 +411,7 @@ bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, g_Logger.LogMessage("[SM_MENU] DoClientMenu(): Client %d is autoIgnoring", client); #endif mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay); - mh->OnMenuEnd(menu); + mh->OnMenuEnd(menu, MenuEnd_Cancelled); return false; } @@ -439,7 +447,7 @@ bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, player->bAutoIgnore = false; player->bInMenu = false; mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay); - mh->OnMenuEnd(menu); + mh->OnMenuEnd(menu, MenuEnd_Cancelled); return false; } diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index 36f188a0..7aec30af 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -147,7 +147,7 @@ bool ValveMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, { mh->OnMenuStart(menu); mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay); - mh->OnMenuEnd(menu); + mh->OnMenuEnd(menu, MenuEnd_Cancelled); return false; } diff --git a/core/smn_menus.cpp b/core/smn_menus.cpp index aad7164d..decb11e2 100644 --- a/core/smn_menus.cpp +++ b/core/smn_menus.cpp @@ -69,7 +69,7 @@ public: void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display); void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item); void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason); - void OnMenuEnd(IBaseMenu *menu); + void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason); void OnMenuDestroy(IBaseMenu *menu); void OnMenuVoteStart(IBaseMenu *menu); void OnMenuVoteEnd(IBaseMenu *menu, @@ -279,9 +279,9 @@ void CMenuHandler::OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason re DoAction(menu, MenuAction_Cancel, client, (cell_t)reason); } -void CMenuHandler::OnMenuEnd(IBaseMenu *menu) +void CMenuHandler::OnMenuEnd(IBaseMenu *menu, MenuEndReason reason) { - DoAction(menu, MenuAction_End, 0, 0); + DoAction(menu, MenuAction_End, reason, 0); } void CMenuHandler::OnMenuDestroy(IBaseMenu *menu) diff --git a/plugins/include/menus.inc b/plugins/include/menus.inc index f1a85137..e931bb0d 100644 --- a/plugins/include/menus.inc +++ b/plugins/include/menus.inc @@ -37,7 +37,7 @@ enum MenuAction MenuAction_Display = (1<<1), /**< A menu is about to be displayed (param1=client, param2=MenuPanel Handle) */ MenuAction_Select = (1<<2), /**< An item was selected (param1=client, param2=item) */ 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 display has fully ended (param1=reason) */ MenuAction_VoteEnd = (1<<5), /**< (VOTE ONLY): A vote sequence has succeeded (param1=chosen item) */ MenuAction_VoteStart = (1<<6), /**< (VOTE ONLY): A vote sequence has started (nothing passed) */ MenuAction_VoteCancel = (1<<7), /**< (VOTE ONLY): A vote sequence has been cancelled (nothing passed) */ @@ -70,6 +70,18 @@ enum MenuCancel_NoDisplay = -4, /**< Menu could not be displayed to the client */ }; +/** + * Reasons a menu ended. + */ +enum +{ + MenuEnd_Cancelled = -1, /**< Menu was cancelled, reason was passed in MenuAction_Cancel */ + MenuEnd_Exit = -2, /**< Menu was cleanly exited (but cancelled) */ + MenuEnd_Selected = -3, /**< Menu item was selected and thus the menu is finished */ + MenuEnd_VotingDone = -4, /**< Voting finished */ + MenuEnd_VotingCancelled = -5, /**< Voting was cancelled */ +}; + /** * Describes a menu's source */ diff --git a/public/IMenuManager.h b/public/IMenuManager.h index 9d6c453c..02cc851e 100644 --- a/public/IMenuManager.h +++ b/public/IMenuManager.h @@ -23,7 +23,7 @@ #include #define SMINTERFACE_MENUMANAGER_NAME "IMenuManager" -#define SMINTERFACE_MENUMANAGER_VERSION 4 +#define SMINTERFACE_MENUMANAGER_VERSION 5 /** * @file IMenuManager.h @@ -116,6 +116,19 @@ namespace SourceMod MenuCancel_NoDisplay = -4, /**< Menu could not be displayed to the client */ }; + /** + * @brief Reasons a menu ended. + */ + enum MenuEndReason + { + MenuEnd_Cancelled = -1, /**< Menu was cancelled, reason was passed in MenuAction_Cancel */ + MenuEnd_Exit = -2, /**< Menu was cleanly exited (but cancelled) */ + MenuEnd_Selected = -3, /**< Menu item was selected and thus the menu is finished */ + MenuEnd_VotingDone = -4, /**< Voting finished */ + MenuEnd_VotingCancelled = -5, /**< Voting was cancelled */ + }; + + #define MENU_NO_PAGINATION 0 /**< Menu should not be paginated (10 items max) */ #define MENU_TIME_FOREVER 0 /**< Menu should be displayed as long as possible */ @@ -589,7 +602,7 @@ namespace SourceMod * * @param menu Menu pointer. */ - virtual void OnMenuEnd(IBaseMenu *menu) + virtual void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason) { } @@ -722,7 +735,7 @@ namespace SourceMod } virtual bool IsVersionCompatible(unsigned int version) { - if (version < 4 || version > GetInterfaceVersion()) + if (version < 5 || version > GetInterfaceVersion()) { return false; }