From 25f045bdea2fff161654fbbe242b43ec53026378 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 19 Aug 2007 18:34:36 +0000 Subject: [PATCH] added helper function for panel text --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401367 --- core/MenuStyle_Radio.cpp | 10 ++++++++++ core/MenuStyle_Radio.h | 1 + core/MenuStyle_Valve.cpp | 6 ++++++ core/MenuStyle_Valve.h | 1 + core/smn_menus.cpp | 15 +++++++++++++++ plugins/include/menus.inc | 14 ++++++++++++++ public/IMenuManager.h | 12 +++++++++++- 7 files changed, 58 insertions(+), 1 deletion(-) diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index abf1eda8..4d376af0 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -361,6 +361,16 @@ void CRadioDisplay::SendRawDisplay(int client, unsigned int time) } } +int CRadioDisplay::GetAmountRemaining() +{ + size_t amt = m_Title.size() + 1 + m_BufferText.size(); + if (amt >= 511) + { + return 0; + } + return (int)(511 - amt); +} + void CRadioDisplay::DeleteThis() { delete this; diff --git a/core/MenuStyle_Radio.h b/core/MenuStyle_Radio.h index ae8d7fd3..a7a4eecf 100644 --- a/core/MenuStyle_Radio.h +++ b/core/MenuStyle_Radio.h @@ -99,6 +99,7 @@ public: //IMenuPanel bool SetSelectableKeys(unsigned int keymap); unsigned int GetCurrentKey(); bool SetCurrentKey(unsigned int key); + int GetAmountRemaining(); private: String m_BufferText; String m_Title; diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index 0ff81f0d..b43ec972 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -342,6 +342,12 @@ bool CValveMenuDisplay::SetSelectableKeys(unsigned int keymap) return false; } +int CValveMenuDisplay::GetAmountRemaining() +{ + /* :TODO: this is a lie, but nothing really seems meaningful... */ + return -1; +} + 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 b4865700..9ead52d3 100644 --- a/core/MenuStyle_Valve.h +++ b/core/MenuStyle_Valve.h @@ -102,6 +102,7 @@ public: bool SetSelectableKeys(unsigned int keymap); unsigned int GetCurrentKey(); bool SetCurrentKey(unsigned int key); + int GetAmountRemaining(); private: KeyValues *m_pKv; unsigned int m_NextPos; diff --git a/core/smn_menus.cpp b/core/smn_menus.cpp index b53ba938..59d2590b 100644 --- a/core/smn_menus.cpp +++ b/core/smn_menus.cpp @@ -1217,6 +1217,20 @@ static cell_t GetPanelCurrentKey(IPluginContext *pContext, const cell_t *params) return panel->GetCurrentKey(); } +static cell_t GetPanelTextRemaining(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->GetAmountRemaining(); +} + static cell_t SetPanelCurrentKey(IPluginContext *pContext, const cell_t *params) { Handle_t hndl = (Handle_t)params[1]; @@ -1355,6 +1369,7 @@ REGISTER_NATIVES(menuNatives) {"GetMenuStyle", GetMenuStyle}, {"GetMenuStyleHandle", GetMenuStyleHandle}, {"GetMenuTitle", GetMenuTitle}, + {"GetPanelTextRemaining", GetPanelTextRemaining}, {"GetPanelCurrentKey", GetPanelCurrentKey}, {"GetPanelStyle", GetPanelStyle}, {"InsertMenuItem", InsertMenuItem}, diff --git a/plugins/include/menus.inc b/plugins/include/menus.inc index 312f1ef6..38fb173d 100644 --- a/plugins/include/menus.inc +++ b/plugins/include/menus.inc @@ -644,6 +644,20 @@ native bool:SetPanelKeys(Handle:panel, keys); */ native bool:SendPanelToClient(Handle:panel, client, MenuHandler:handler, time); +/** + * @brief Returns the amount of text the menu can still hold. If this is + * limit is reached or overflowed, the text is silently truncated. + * + * Radio menus: Currently 511 characters (512 bytes). + * Valve menus: Currently -1 (no meaning). + * + * @param panel A MenuPanel Handle. + * @return Number of characters that the menu can still hold, + * or -1 if there is no known limit. + * @error Invalid Handle. + */ +native GetPanelTextRemaining(Handle:panel); + /** * @brief Returns the current key position. * diff --git a/public/IMenuManager.h b/public/IMenuManager.h index a973287d..ddde206b 100644 --- a/public/IMenuManager.h +++ b/public/IMenuManager.h @@ -36,7 +36,7 @@ #include #define SMINTERFACE_MENUMANAGER_NAME "IMenuManager" -#define SMINTERFACE_MENUMANAGER_VERSION 11 +#define SMINTERFACE_MENUMANAGER_VERSION 12 /** * @file IMenuManager.h @@ -312,6 +312,16 @@ namespace SourceMod * @return True on success, false otherwise. */ virtual bool SetCurrentKey(unsigned int key) =0; + + /** + * @brief Returns the number of characters that can be added to the + * menu. The internal buffer is truncated if overflowed; this is for + * manual truncation/wrapping purposes. + * + * @return Number of bytes available. If the result is + * -1, then the panel has no text limit. + */ + virtual int GetAmountRemaining() =0; }; /**