From efbf57ac90da7f409edff98afb7c4e4c21ef17d5 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 26 Sep 2007 01:04:22 +0000 Subject: [PATCH] added API for menus to re-display from a previous page --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401480 --- core/MenuManager.cpp | 4 +++- core/MenuStyle_Base.cpp | 14 ++++++++++++-- core/MenuStyle_Base.h | 6 +++++- core/MenuStyle_Radio.cpp | 14 +++++++++++++- core/MenuStyle_Radio.h | 4 ++++ core/MenuStyle_Valve.cpp | 14 +++++++++++--- core/MenuStyle_Valve.h | 6 +++++- core/MenuVoting.cpp | 8 ++++++++ core/MenuVoting.h | 1 + public/IMenuManager.h | 36 +++++++++++++++++++++++++++++++++++- 10 files changed, 97 insertions(+), 10 deletions(-) diff --git a/core/MenuManager.cpp b/core/MenuManager.cpp index 2febf988..aade116b 100644 --- a/core/MenuManager.cpp +++ b/core/MenuManager.cpp @@ -366,7 +366,9 @@ IMenuPanel *MenuManager::RenderMenu(int client, menu_states_t &md, ItemOrder ord } } } - } else if (order == ItemOrder_Ascending) { + } + else if (order == ItemOrder_Ascending) + { lastItem = drawItems[0].position; if (lastItem == 0) { diff --git a/core/MenuStyle_Base.cpp b/core/MenuStyle_Base.cpp index 59d58126..ec9e58c7 100644 --- a/core/MenuStyle_Base.cpp +++ b/core/MenuStyle_Base.cpp @@ -288,6 +288,8 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press) IMenuHandler *mh = states.mh; IBaseMenu *menu = states.menu; + unsigned int item_on_page = states.firstItem; + assert(mh != NULL); if (menu == NULL) @@ -380,6 +382,10 @@ void BaseMenuStyle::ClientPressedKey(int client, unsigned int key_press) mh->OnMenuCancel(menu, client, reason); } else { mh->OnMenuSelect(menu, client, item); + if (mh->GetMenuAPIVersion2() >= 13) + { + mh->OnMenuSelect2(menu, client, item, item_on_page); + } } /* Only fire end for valid menus */ @@ -448,7 +454,11 @@ bool BaseMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, return true; } -bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time) +bool BaseMenuStyle::DoClientMenu(int client, + CBaseMenu *menu, + unsigned int first_item, + IMenuHandler *mh, + unsigned int time) { #if defined MENU_DEBUG g_Logger.LogMessage("[SM_MENU] DoClientMenu() (client %d) (menu %p) (mh %p) (time %d)", @@ -498,7 +508,7 @@ bool BaseMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, _CancelClientMenu(client, MenuCancel_Interrupted, true); } - states.firstItem = 0; + states.firstItem = first_item; states.lastItem = 0; states.menu = menu; states.mh = mh; diff --git a/core/MenuStyle_Base.h b/core/MenuStyle_Base.h index f31b095d..8d3df647 100644 --- a/core/MenuStyle_Base.h +++ b/core/MenuStyle_Base.h @@ -91,7 +91,11 @@ public: //what derived must implement virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0; virtual void SendDisplay(int client, IMenuPanel *display) =0; public: //what derived may implement - virtual bool DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time); + virtual bool DoClientMenu(int client, + CBaseMenu *menu, + unsigned int first_item, + IMenuHandler *mh, + unsigned int time); virtual bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time); virtual void AddClientToWatch(int client); virtual void RemoveClientFromWatch(int client); diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index 4d376af0..26503340 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -398,6 +398,14 @@ IMenuPanel *CRadioMenu::CreatePanel() } bool CRadioMenu::Display(int client, unsigned int time, IMenuHandler *alt_handler) +{ + return DisplayAtItem(client, time, 0, alt_handler); +} + +bool CRadioMenu::DisplayAtItem(int client, + unsigned int time, + unsigned int start_item, + IMenuHandler *alt_handler) { #if defined MENU_DEBUG g_Logger.LogMessage("[SM_MENU] CRadioMenu::Display(%p) (client %d) (time %d)", @@ -410,7 +418,11 @@ bool CRadioMenu::Display(int client, unsigned int time, IMenuHandler *alt_handle return false; } - return g_RadioMenuStyle.DoClientMenu(client, this, alt_handler ? alt_handler : m_pHandler, time); + return g_RadioMenuStyle.DoClientMenu(client, + this, + start_item, + alt_handler ? alt_handler : m_pHandler, + time); } void CRadioMenu::Cancel_Finally() diff --git a/core/MenuStyle_Radio.h b/core/MenuStyle_Radio.h index a7a4eecf..248b8162 100644 --- a/core/MenuStyle_Radio.h +++ b/core/MenuStyle_Radio.h @@ -115,6 +115,10 @@ public: bool SetExtOption(MenuOption option, const void *valuePtr); IMenuPanel *CreatePanel(); bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL); + bool DisplayAtItem(int client, + unsigned int time, + unsigned int start_item, + IMenuHandler *alt_handler/* =NULL */); void Cancel_Finally(); }; diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index b43ec972..08bd4b16 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -156,7 +156,7 @@ bool ValveMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh return BaseMenuStyle::DoClientMenu(client, menu, mh, time); } -bool ValveMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time) +bool ValveMenuStyle::DoClientMenu(int client, CBaseMenu *menu, unsigned int first_item, IMenuHandler *mh, unsigned int time) { if (!g_pVSPHandle) { @@ -166,7 +166,7 @@ bool ValveMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, return false; } - return BaseMenuStyle::DoClientMenu(client, menu, mh, time); + return BaseMenuStyle::DoClientMenu(client, menu, first_item, mh, time); } CValveMenuDisplay::CValveMenuDisplay() @@ -387,13 +387,21 @@ bool CValveMenu::SetExtOption(MenuOption option, const void *valuePtr) } bool CValveMenu::Display(int client, unsigned int time, IMenuHandler *alt_handler) +{ + return DisplayAtItem(client, time, 0, alt_handler); +} + +bool CValveMenu::DisplayAtItem(int client, + unsigned int time, + unsigned int start_item, + IMenuHandler *alt_handler/* =NULL */) { if (m_bCancelling) { return false; } - return g_ValveMenuStyle.DoClientMenu(client, this, alt_handler ? alt_handler : m_pHandler, time); + return g_ValveMenuStyle.DoClientMenu(client, this, start_item, alt_handler ? alt_handler : m_pHandler, time); } IMenuPanel *CValveMenu::CreatePanel() diff --git a/core/MenuStyle_Valve.h b/core/MenuStyle_Valve.h index 9ead52d3..56797d18 100644 --- a/core/MenuStyle_Valve.h +++ b/core/MenuStyle_Valve.h @@ -63,7 +63,7 @@ public: public: //BaseMenuStyle CBaseMenuPlayer *GetMenuPlayer(int client); void SendDisplay(int client, IMenuPanel *display); - bool DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time); + bool DoClientMenu(int client, CBaseMenu *menu, unsigned int first_item, IMenuHandler *mh, unsigned int time); bool DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time); public: //SMGlobalClass void OnSourceModAllInitialized(); @@ -121,6 +121,10 @@ public: //IBaseMenu bool SetExitButton(bool set); bool SetPagination(unsigned int itemsPerPage); bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL); + bool DisplayAtItem(int client, + unsigned int time, + unsigned int start_item, + IMenuHandler *alt_handler/* =NULL */); void SetMenuOptionFlags(unsigned int flags); public: //CBaseMenu void Cancel_Finally(); diff --git a/core/MenuVoting.cpp b/core/MenuVoting.cpp index 4374de0b..998051f7 100644 --- a/core/MenuVoting.cpp +++ b/core/MenuVoting.cpp @@ -365,6 +365,14 @@ void VoteMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int ite m_pHandler->OnMenuSelect(menu, client, item); } +void VoteMenuHandler::OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page) +{ + if (m_pHandler->GetMenuAPIVersion2() >= 13) + { + m_pHandler->OnMenuSelect2(menu, client, item, item_on_page); + } +} + void VoteMenuHandler::InternalReset() { m_Clients = 0; diff --git a/core/MenuVoting.h b/core/MenuVoting.h index c3fe4d45..22e42a09 100644 --- a/core/MenuVoting.h +++ b/core/MenuVoting.h @@ -56,6 +56,7 @@ public: //IMenuHandler void OnMenuStart(IBaseMenu *menu); void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display); void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item); + void OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page); void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason); void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason); void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style); diff --git a/public/IMenuManager.h b/public/IMenuManager.h index ddde206b..11e17fb8 100644 --- a/public/IMenuManager.h +++ b/public/IMenuManager.h @@ -36,7 +36,7 @@ #include #define SMINTERFACE_MENUMANAGER_NAME "IMenuManager" -#define SMINTERFACE_MENUMANAGER_VERSION 12 +#define SMINTERFACE_MENUMANAGER_VERSION 13 /** * @file IMenuManager.h @@ -572,6 +572,22 @@ namespace SourceMod * @return IMenuHandler of the menu. */ virtual IMenuHandler *GetHandler() =0; + + /** + * @brief Sends the menu to a client, starting from the given item number. + * + * Note: this API call was added in v13. + * + * @param client Client index to display to. + * @param time Time to hold menu for. + * @param start_item Starting item to draw. + * @param alt_handler Alternate IMenuHandler. + * @return True on success, false otherwise. + */ + virtual bool DisplayAtItem(int client, + unsigned int time, + unsigned int start_item, + IMenuHandler *alt_handler=NULL) =0; }; /** @@ -731,6 +747,24 @@ namespace SourceMod { return false; } + + /** + * @brief Called when an item is selected. + * + * Note: This callback was added in v13. It is called after OnMenuSelect(). + * + * @param menu Menu pointer. + * @param client Client that selected the item. + * @param item Item number. + * @param item_on_page The first item on the page the player was last + * viewing. + */ + virtual void OnMenuSelect2(IBaseMenu *menu, + int client, + unsigned int item, + unsigned int item_on_page) + { + } }; /**