- added amb1050 - topmenu info strings (similar to menus)
- added removal detection to topmenus --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401640
This commit is contained in:
@@ -124,6 +124,18 @@ unsigned int TopMenu::AddToMenu(const char *name,
|
||||
const char *cmdname,
|
||||
FlagBits flags,
|
||||
unsigned int parent)
|
||||
{
|
||||
return AddToMenu2(name, type, callbacks, owner, cmdname, flags, parent, NULL);
|
||||
}
|
||||
|
||||
unsigned int TopMenu::AddToMenu2(const char *name,
|
||||
TopMenuObjectType type,
|
||||
ITopMenuObjectCallbacks *callbacks,
|
||||
IdentityToken_t *owner,
|
||||
const char *cmdname,
|
||||
FlagBits flags,
|
||||
unsigned int parent,
|
||||
const char *info_string)
|
||||
{
|
||||
/* Sanity checks */
|
||||
if (type == TopMenuObject_Category && parent != 0)
|
||||
@@ -202,6 +214,7 @@ unsigned int TopMenu::AddToMenu(const char *name,
|
||||
obj->parent = parent_obj;
|
||||
strncopy(obj->name, name, sizeof(obj->name));
|
||||
strncopy(obj->cmdname, cmdname ? cmdname : "", sizeof(obj->cmdname));
|
||||
strncopy(obj->info, info_string ? info_string : "", sizeof(obj->info));
|
||||
|
||||
if (obj->type == TopMenuObject_Category)
|
||||
{
|
||||
@@ -239,6 +252,20 @@ unsigned int TopMenu::AddToMenu(const char *name,
|
||||
return obj->object_id;
|
||||
}
|
||||
|
||||
const char *TopMenu::GetObjectInfoString(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->info;
|
||||
}
|
||||
|
||||
void TopMenu::RemoveFromMenu(unsigned int object_id)
|
||||
{
|
||||
if (object_id == 0
|
||||
@@ -320,11 +347,11 @@ void TopMenu::RemoveFromMenu(unsigned int object_id)
|
||||
}
|
||||
}
|
||||
|
||||
/* Finally, mark the object as free. */
|
||||
obj->is_free = true;
|
||||
|
||||
/* The callbacks pointer is still valid, so fire away! */
|
||||
obj->callbacks->OnTopMenuObjectRemoved(this, object_id);
|
||||
|
||||
/* Finally, mark the object as free. */
|
||||
obj->is_free = true;
|
||||
}
|
||||
|
||||
bool TopMenu::DisplayMenu(int client, unsigned int hold_time, TopMenuPosition position)
|
||||
|
||||
@@ -68,6 +68,7 @@ struct topmenu_object_t
|
||||
topmenu_object_t *parent; /** Parent, if any */
|
||||
TopMenuObjectType type; /** Object Type */
|
||||
bool is_free; /** Free or not? */
|
||||
char info[255]; /** Info string */
|
||||
};
|
||||
|
||||
struct topmenu_category_t
|
||||
@@ -115,12 +116,21 @@ public: //ITopMenu
|
||||
const char *cmdname,
|
||||
FlagBits flags,
|
||||
unsigned int parent);
|
||||
unsigned int AddToMenu2(const char *name,
|
||||
TopMenuObjectType type,
|
||||
ITopMenuObjectCallbacks *callbacks,
|
||||
IdentityToken_t *owner,
|
||||
const char *cmdname,
|
||||
FlagBits flags,
|
||||
unsigned int parent,
|
||||
const char *info_string);
|
||||
virtual void RemoveFromMenu(unsigned int object_id);
|
||||
virtual bool DisplayMenu(int client,
|
||||
unsigned int hold_time,
|
||||
TopMenuPosition position);
|
||||
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);
|
||||
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);
|
||||
@@ -166,4 +176,6 @@ private:
|
||||
bool m_bCatsNeedResort; /* True if categories need a resort */
|
||||
};
|
||||
|
||||
unsigned int strncopy(char *dest, const char *src, size_t count);
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_TOP_MENU_H_
|
||||
|
||||
@@ -67,6 +67,7 @@ enum TopMenuAction
|
||||
TopMenuAction_DisplayTitle = 1,
|
||||
TopMenuAction_SelectOption = 2,
|
||||
TopMenuAction_DrawOption = 3,
|
||||
TopMenuAction_RemoveObject = 4,
|
||||
};
|
||||
|
||||
class TopMenuCallbacks : public ITopMenuObjectCallbacks
|
||||
@@ -138,6 +139,14 @@ public:
|
||||
|
||||
void OnTopMenuObjectRemoved(ITopMenu *menu, unsigned int object_id)
|
||||
{
|
||||
m_pFunction->PushCell(m_hMenuHandle);
|
||||
m_pFunction->PushCell(TopMenuAction_RemoveObject);
|
||||
m_pFunction->PushCell(object_id);
|
||||
m_pFunction->PushCell(0);
|
||||
m_pFunction->PushString("");
|
||||
m_pFunction->PushCell(0);
|
||||
m_pFunction->Execute(NULL);
|
||||
|
||||
delete this;
|
||||
}
|
||||
|
||||
@@ -221,20 +230,26 @@ static cell_t AddToTopMenu(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
TopMenuCallbacks *cb = new TopMenuCallbacks(func);
|
||||
|
||||
char *name, *cmdname;
|
||||
char *name, *cmdname, *info_string;
|
||||
pContext->LocalToString(params[2], &name);
|
||||
pContext->LocalToString(params[6], &cmdname);
|
||||
|
||||
if (params[0] >= 8)
|
||||
{
|
||||
pContext->LocalToString(params[8], &info_string);
|
||||
}
|
||||
|
||||
TopMenuObjectType obj_type = (TopMenuObjectType)params[3];
|
||||
|
||||
unsigned int object_id;
|
||||
if ((object_id = pMenu->AddToMenu(name,
|
||||
if ((object_id = pMenu->AddToMenu2(name,
|
||||
obj_type,
|
||||
cb,
|
||||
pContext->GetIdentity(),
|
||||
cmdname,
|
||||
params[7],
|
||||
params[5])) == 0)
|
||||
params[5],
|
||||
info_string)) == 0)
|
||||
{
|
||||
delete cb;
|
||||
return 0;
|
||||
@@ -306,13 +321,38 @@ static cell_t DisplayTopMenu(IPluginContext *pContext, const cell_t *params)
|
||||
return pMenu->DisplayMenu(client, 0, (TopMenuPosition)params[3]);
|
||||
}
|
||||
|
||||
static cell_t GetTopMenuInfoString(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->GetObjectInfoString(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},
|
||||
{"CreateTopMenu", CreateTopMenu},
|
||||
{"DisplayTopMenu", DisplayTopMenu},
|
||||
{"LoadTopMenuConfig", LoadTopMenuConfig},
|
||||
{"RemoveFromTopMenu", RemoveFromTopMenu},
|
||||
{"FindTopMenuCategory", FindTopMenuCategory},
|
||||
{"AddToTopMenu", AddToTopMenu},
|
||||
{"CreateTopMenu", CreateTopMenu},
|
||||
{"DisplayTopMenu", DisplayTopMenu},
|
||||
{"LoadTopMenuConfig", LoadTopMenuConfig},
|
||||
{"RemoveFromTopMenu", RemoveFromTopMenu},
|
||||
{"FindTopMenuCategory", FindTopMenuCategory},
|
||||
{"GetTopMenuInfoString", GetTopMenuInfoString},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user