From 82c578f32dcfd9797d22280b0018466a01d24d4b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 23 May 2007 02:26:43 +0000 Subject: [PATCH] added request amb320 --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40846 --- core/MenuStyle_Radio.cpp | 17 +++++++++++++++++ core/MenuStyle_Radio.h | 2 ++ core/MenuStyle_Valve.cpp | 17 +++++++++++++++++ core/MenuStyle_Valve.h | 2 ++ core/smn_menus.cpp | 30 ++++++++++++++++++++++++++++++ plugins/include/menus.inc | 21 +++++++++++++++++++++ public/IMenuManager.h | 17 +++++++++++++++++ 7 files changed, 106 insertions(+) diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index fc558799..cb588fb1 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -198,6 +198,23 @@ void CRadioDisplay::Reset() keys = 0; } +unsigned int CRadioDisplay::GetCurrentKey() +{ + return m_NextPos; +} + +bool CRadioDisplay::SetCurrentKey(unsigned int key) +{ + if (key < m_NextPos || m_NextPos > 10) + { + return false; + } + + m_NextPos = key; + + return true; +} + bool CRadioDisplay::SendDisplay(int client, IMenuHandler *handler, unsigned int time) { return g_RadioMenuStyle.DoClientMenu(client, this, handler, time); diff --git a/core/MenuStyle_Radio.h b/core/MenuStyle_Radio.h index 3bf0b7a6..1c86778f 100644 --- a/core/MenuStyle_Radio.h +++ b/core/MenuStyle_Radio.h @@ -79,6 +79,8 @@ public: //IMenuPanel void DeleteThis(); void SendRawDisplay(int client, unsigned int time); bool SetSelectableKeys(unsigned int keymap); + unsigned int GetCurrentKey(); + bool SetCurrentKey(unsigned int key); private: String m_BufferText; String m_Title; diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index aff9f228..5c3f2383 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -194,6 +194,23 @@ void CValveMenuDisplay::Reset() m_TitleDrawn = false; } +unsigned int CValveMenuDisplay::GetCurrentKey() +{ + return m_NextPos; +} + +bool CValveMenuDisplay::SetCurrentKey(unsigned int key) +{ + if (key < m_NextPos || key > 9) + { + return false; + } + + m_NextPos = key; + + return true; +} + bool CValveMenuDisplay::SetExtOption(MenuOption option, const void *valuePtr) { if (option == MenuOption_IntroMessage) diff --git a/core/MenuStyle_Valve.h b/core/MenuStyle_Valve.h index 95e4af89..97edcfbf 100644 --- a/core/MenuStyle_Valve.h +++ b/core/MenuStyle_Valve.h @@ -83,6 +83,8 @@ public: void SendRawDisplay(int client, int priority, unsigned int time); void DeleteThis(); bool SetSelectableKeys(unsigned int keymap); + unsigned int GetCurrentKey(); + bool SetCurrentKey(unsigned int key); private: KeyValues *m_pKv; unsigned int m_NextPos; diff --git a/core/smn_menus.cpp b/core/smn_menus.cpp index 09ac5b6e..ad873dbf 100644 --- a/core/smn_menus.cpp +++ b/core/smn_menus.cpp @@ -869,6 +869,34 @@ static cell_t SetPanelKeys(IPluginContext *pContext, const cell_t *params) return panel->SetSelectableKeys(params[2]); } +static cell_t GetPanelCurrentKey(IPluginContext *pContext, const cell_t *params) +{ + Handle_t hndl = (Handle_t)params[1]; + HandleError err; + IMenuPanel *panel; + + if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None) + { + return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); + } + + return panel->GetCurrentKey(); +} + +static cell_t SetPanelCurrentKey(IPluginContext *pContext, const cell_t *params) +{ + Handle_t hndl = (Handle_t)params[1]; + HandleError err; + IMenuPanel *panel; + + if ((err=ReadPanelHandle(hndl, &panel)) != HandleError_None) + { + return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); + } + + return panel->SetCurrentKey(params[2]) ? 1 : 0; +} + REGISTER_NATIVES(menuNatives) { {"AddMenuItem", AddMenuItem}, @@ -890,6 +918,7 @@ REGISTER_NATIVES(menuNatives) {"GetMenuPagination", GetMenuPagination}, {"GetMenuStyle", GetMenuStyle}, {"GetMenuStyleHandle", GetMenuStyleHandle}, + {"GetPanelCurrentKey", GetPanelCurrentKey}, {"GetPanelStyle", GetPanelStyle}, {"InsertMenuItem", InsertMenuItem}, {"RemoveAllMenuItems", RemoveAllMenuItems}, @@ -898,6 +927,7 @@ REGISTER_NATIVES(menuNatives) {"SetMenuExitButton", SetMenuExitButton}, {"SetMenuPagination", SetMenuPagination}, {"SetMenuTitle", SetMenuTitle}, + {"SetPanelCurrentKey", SetPanelCurrentKey}, {"SetPanelTitle", SetPanelTitle}, {"SetPanelKeys", SetPanelKeys}, {NULL, NULL}, diff --git a/plugins/include/menus.inc b/plugins/include/menus.inc index 019f17fd..45703428 100644 --- a/plugins/include/menus.inc +++ b/plugins/include/menus.inc @@ -509,3 +509,24 @@ native bool:SetPanelKeys(Handle:panel, keys); * @error Invalid Handle. */ native bool:SendPanelToClient(Handle:panel, client, MenuHandler:handler, time); + +/** + * @brief Returns the current key position. + * + * @param panel A MenuPanel Handle. + * @return Current key position starting at 1. + * @error Invalid Handle. + */ +native GetPanelCurrentKey(Handle:panel); + +/** + * @brief Sets the next key position. This cannot be used + * to traverse backwards. + * + * @param panel A MenuPanel Handle. + * @param key Key that is greater or equal to + * GetPanelCurrentKey(). + * @return True on success, false otherwise. + * @error Invalid Handle. + */ +native bool:SetPanelCurrentKey(Handle:panel, key); diff --git a/public/IMenuManager.h b/public/IMenuManager.h index 5c08727b..343d59e2 100644 --- a/public/IMenuManager.h +++ b/public/IMenuManager.h @@ -236,6 +236,23 @@ namespace SourceMod * @return True on success, false if not supported. */ virtual bool SetSelectableKeys(unsigned int keymap) =0; + + /** + * @brief Returns the current key position. + * + * @return Current key position starting at 1. + */ + virtual unsigned int GetCurrentKey() =0; + + /** + * @brief Sets the next key position. This cannot be used + * to traverse backwards. + * + * @param key Key that is greater or equal to + * GetCurrentKey(). + * @return True on success, false otherwise. + */ + virtual bool SetCurrentKey(unsigned int key) =0; }; /**