added helper function for panel text

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401367
This commit is contained in:
David Anderson 2007-08-19 18:34:36 +00:00
parent 2a3de44ddb
commit 25f045bdea
7 changed files with 58 additions and 1 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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},

View File

@ -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.
*

View File

@ -36,7 +36,7 @@
#include <IHandleSys.h>
#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;
};
/**