From daceab19cd984d30dae75c3cef9d1cb05d055ef1 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 21 May 2007 01:11:37 +0000 Subject: [PATCH] added key selection setting fixed amb309 --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40825 --- core/MenuStyle_Radio.cpp | 9 ++++++++- core/MenuStyle_Radio.h | 1 + core/MenuStyle_Valve.cpp | 5 +++++ core/MenuStyle_Valve.h | 1 + core/smn_menus.cpp | 15 +++++++++++++++ plugins/include/menus.inc | 11 +++++++++++ public/IMenuManager.h | 12 ++++++++++++ 7 files changed, 53 insertions(+), 1 deletion(-) diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index 2f78409b..989e350c 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -286,6 +286,8 @@ void CRadioDisplay::SendRawDisplay(int client, unsigned int time) cell_t players[1] = {client}; + int _sel_keys = (keys == 0) ? (1<<9) : keys; + char *ptr = buffer; char save = 0; while (true) @@ -296,7 +298,7 @@ void CRadioDisplay::SendRawDisplay(int client, unsigned int time) ptr[240] = '\0'; } bf_write *buffer = g_UserMsgs.StartMessage(g_ShowMenuId, players, 1, 0); - buffer->WriteWord(keys); + buffer->WriteWord(_sel_keys); buffer->WriteChar(time ? time : -1); buffer->WriteByte( (len > 240) ? 1 : 0 ); buffer->WriteString(ptr); @@ -317,6 +319,11 @@ void CRadioDisplay::DeleteThis() delete this; } +bool CRadioDisplay::SetSelectableKeys(unsigned int keymap) +{ + keys = (signed)keymap; +} + CRadioMenu::CRadioMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner) : CBaseMenu(pHandler, &g_RadioMenuStyle, pOwner) { diff --git a/core/MenuStyle_Radio.h b/core/MenuStyle_Radio.h index eac5cb4d..3bf0b7a6 100644 --- a/core/MenuStyle_Radio.h +++ b/core/MenuStyle_Radio.h @@ -78,6 +78,7 @@ public: //IMenuPanel bool SendDisplay(int client, IMenuHandler *handler, unsigned int time); void DeleteThis(); void SendRawDisplay(int client, unsigned int time); + bool SetSelectableKeys(unsigned int keymap); private: String m_BufferText; String m_Title; diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index de9f2dd9..819b7e1e 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -305,6 +305,11 @@ bool CValveMenuDisplay::SendDisplay(int client, IMenuHandler *handler, unsigned return g_ValveMenuStyle.DoClientMenu(client, this, handler, time); } +bool CValveMenuDisplay::SetSelectableKeys(unsigned int keymap) +{ + return false; +} + CValveMenu::CValveMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner) : CBaseMenu(pHandler, &g_ValveMenuStyle, pOwner), m_IntroColor(255, 0, 0, 255) diff --git a/core/MenuStyle_Valve.h b/core/MenuStyle_Valve.h index a4c48df7..95e4af89 100644 --- a/core/MenuStyle_Valve.h +++ b/core/MenuStyle_Valve.h @@ -82,6 +82,7 @@ public: bool CanDrawItem(unsigned int drawFlags); void SendRawDisplay(int client, int priority, unsigned int time); void DeleteThis(); + bool SetSelectableKeys(unsigned int keymap); private: KeyValues *m_pKv; unsigned int m_NextPos; diff --git a/core/smn_menus.cpp b/core/smn_menus.cpp index 5f174d56..09ac5b6e 100644 --- a/core/smn_menus.cpp +++ b/core/smn_menus.cpp @@ -855,6 +855,20 @@ static cell_t SendPanelToClient(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t SetPanelKeys(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->SetSelectableKeys(params[2]); +} + REGISTER_NATIVES(menuNatives) { {"AddMenuItem", AddMenuItem}, @@ -885,5 +899,6 @@ REGISTER_NATIVES(menuNatives) {"SetMenuPagination", SetMenuPagination}, {"SetMenuTitle", SetMenuTitle}, {"SetPanelTitle", SetPanelTitle}, + {"SetPanelKeys", SetPanelKeys}, {NULL, NULL}, }; diff --git a/plugins/include/menus.inc b/plugins/include/menus.inc index c18b1623..019f17fd 100644 --- a/plugins/include/menus.inc +++ b/plugins/include/menus.inc @@ -479,6 +479,17 @@ native DrawPanelText(Handle:panel, const String:text[]); */ native CanPanelDrawFlags(Handle:panel, style); +/** + * Sets the selectable key map of a panel. This is not supported by + * all styles (only by Radio, as of this writing). + * + * @param keys An integer where each bit N allows key + * N+1 to be selected. If no keys are selectable, + * then key 0 (bit 9) is automatically set. + * @return True if supported, false otherwise. + */ +native bool:SetPanelKeys(Handle:panel, keys); + /** * Sends a panel to a client. Unlike full menus, the handler * function will only receive the following actions, both of diff --git a/public/IMenuManager.h b/public/IMenuManager.h index 77a05389..5c08727b 100644 --- a/public/IMenuManager.h +++ b/public/IMenuManager.h @@ -224,6 +224,18 @@ namespace SourceMod * @brief Destroys the display object. */ virtual void DeleteThis() =0; + + /** + * @brief Sets the selectable key map. Returns false if the function + * is not supported. + * + * @param keys A bit string where each bit N-1 specifies + * that key N is selectable (key 0 is bit 9). + * If the selectable key map is 0, it will be + * automatically set to allow 0. + * @return True on success, false if not supported. + */ + virtual bool SetSelectableKeys(unsigned int keymap) =0; }; /**