submitting patch from amb1181 - retrieving topmenu object name

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401705
This commit is contained in:
David Anderson 2007-11-20 02:22:26 +00:00
parent 3d4d583182
commit d04d0e4089
4 changed files with 1971 additions and 1918 deletions

View File

@ -266,6 +266,20 @@ const char *TopMenu::GetObjectInfoString(unsigned int object_id)
return obj->info;
}
const char *TopMenu::GetObjectName(unsigned int object_id)
{
if (object_id == 0
|| object_id > m_Objects.size()
|| m_Objects[object_id - 1]->is_free)
{
return NULL;
}
topmenu_object_t *obj = m_Objects[object_id - 1];
return obj->name;
}
void TopMenu::RemoveFromMenu(unsigned int object_id)
{
if (object_id == 0

View File

@ -131,6 +131,7 @@ public: //ITopMenu
virtual bool LoadConfiguration(const char *file, char *error, size_t maxlength);
virtual unsigned int FindCategory(const char *name);
const char *GetObjectInfoString(unsigned int object_id);
const char *GetObjectName(unsigned int object_id);
public: //IMenuHandler
virtual void OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page);
virtual void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style);

View File

@ -345,6 +345,30 @@ static cell_t GetTopMenuInfoString(IPluginContext *pContext, const cell_t *param
return strncopy(buffer, str, params[4]);
}
static cell_t GetTopMenuName(IPluginContext *pContext, const cell_t *params)
{
HandleError err;
ITopMenu *pMenu;
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
if ((err = handlesys->ReadHandle(params[1], hTopMenuType, &sec, (void **)&pMenu))
!= HandleError_None)
{
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
}
const char *str;
if ((str = pMenu->GetObjectName(params[2])) == NULL)
{
return pContext->ThrowNativeError("Invalid menu object %d", params[2]);
}
char *buffer;
pContext->LocalToString(params[3], &buffer);
return strncopy(buffer, str, params[4]);
}
sp_nativeinfo_t g_TopMenuNatives[] =
{
{"AddToTopMenu", AddToTopMenu},
@ -354,5 +378,6 @@ sp_nativeinfo_t g_TopMenuNatives[] =
{"RemoveFromTopMenu", RemoveFromTopMenu},
{"FindTopMenuCategory", FindTopMenuCategory},
{"GetTopMenuInfoString", GetTopMenuInfoString},
{"GetTopMenuName", GetTopMenuName},
{NULL, NULL},
};

View File

@ -210,6 +210,19 @@ native TopMenuObject:AddToTopMenu(Handle:topmenu,
*/
native GetTopMenuInfoString(Handle:topmenu, TopMenuObject:parent, String:buffer[], maxlength);
/**
* Retrieves the name string of a top menu item.
*
* @param topmenu TopMenu Handle.
* @param object TopMenuObject ID.
* @param buffer Buffer to store info string.
* @param maxlength Maximum size of info string.
* @return Number of bytes written, not including the
* null terminator.
* @error Invalid TopMenu Handle or TopMenuObject ID.
*/
native GetTopMenuName(Handle:topmenu, TopMenuObject:parent, String:buffer[], maxlength);
/**
* Removes an object from a TopMenu.
*