- various improvements to the plugin-level topmenu api

- categories are no longer displayed if they have no items

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401502
This commit is contained in:
David Anderson
2007-09-26 21:44:12 +00:00
parent 035d646dfd
commit 61ac102fe2
4 changed files with 123 additions and 22 deletions
+24
View File
@@ -225,6 +225,14 @@ unsigned int TopMenu::AddToMenu(const char *name,
parent_cat->obj_list.push_back(obj);
parent_cat->reorder = true;
parent_cat->serial++;
/* If the category just went from 0 to 1 items, mark it as
* changed, so clients get the category drawn.
*/
if (parent_cat->obj_list.size() == 1)
{
m_SerialNo++;
}
}
m_ObjLookup.insert(name, obj);
@@ -295,6 +303,14 @@ void TopMenu::RemoveFromMenu(unsigned int object_id)
if (parent_cat->obj_list[i] == obj)
{
parent_cat->obj_list.erase(parent_cat->obj_list.iterAt(i));
/* If this category now has no items, mark root as changed
* so clients won't get the category drawn anymore.
*/
if (parent_cat->obj_list.size() == 0)
{
m_SerialNo++;
}
break;
}
}
@@ -552,6 +568,10 @@ void TopMenu::UpdateClientRoot(int client, IGamePlayer *pGamePlayer)
/* Add the sorted items */
for (size_t i = 0; i < m_SortedCats.size(); i++)
{
if (m_Categories[m_SortedCats[i]]->obj_list.size() == 0)
{
continue;
}
root_menu->AppendItem(m_Categories[m_SortedCats[i]]->obj->name, ItemDrawInfo(""));
}
@@ -579,6 +599,10 @@ void TopMenu::UpdateClientRoot(int client, IGamePlayer *pGamePlayer)
/* Add the new sorted categories */
for (size_t i = 0; i < m_SortedCats.size(); i++)
{
if (m_Categories[item_list[i].obj_index]->obj_list.size() == 0)
{
continue;
}
root_menu->AppendItem(m_Categories[item_list[i].obj_index]->obj->name, ItemDrawInfo(""));
}
+3 -3
View File
@@ -62,7 +62,7 @@
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)\sample.ext.dll"
OutputFile="$(OutDir)\topmenus.ext.dll"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
@@ -118,7 +118,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..;..\sdk;..\..\..\public;..\..\..\public\sourcepawn"
AdditionalIncludeDirectories="..;..\sdk;..\..\..\public;..\..\..\public\sourcepawn;..\..\..\public\extensions"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SDK_EXPORTS;_CRT_SECURE_NO_DEPRECATE;SOURCEMOD_BUILD"
RuntimeLibrary="0"
RuntimeTypeInfo="false"
@@ -138,7 +138,7 @@
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)\sample.ext.dll"
OutputFile="$(OutDir)\topmenus.ext.dll"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="2"
+39 -6
View File
@@ -84,8 +84,9 @@ public:
cell_t result = ITEMDRAW_DEFAULT;
m_pFunction->PushCell(m_hMenuHandle);
m_pFunction->PushCell(client);
m_pFunction->PushCell(TopMenuAction_DrawOption);
m_pFunction->PushCell(object_id);
m_pFunction->PushCell(client);
m_pFunction->PushStringEx(buffer, maxlength, 0, SM_PARAM_COPYBACK);
m_pFunction->PushCell(maxlength);
m_pFunction->Execute(&result);
@@ -100,8 +101,9 @@ public:
size_t maxlength)
{
m_pFunction->PushCell(m_hMenuHandle);
m_pFunction->PushCell(client);
m_pFunction->PushCell(TopMenuAction_DrawTitle);
m_pFunction->PushCell(object_id);
m_pFunction->PushCell(client);
m_pFunction->PushStringEx(buffer, maxlength, 0, SM_PARAM_COPYBACK);
m_pFunction->PushCell(maxlength);
m_pFunction->Execute(NULL);
@@ -112,8 +114,9 @@ public:
unsigned int object_id)
{
m_pFunction->PushCell(m_hMenuHandle);
m_pFunction->PushCell(client);
m_pFunction->PushCell(TopMenuAction_SelectOption);
m_pFunction->PushCell(object_id);
m_pFunction->PushCell(client);
m_pFunction->PushString("");
m_pFunction->PushCell(0);
m_pFunction->Execute(NULL);
@@ -157,6 +160,8 @@ static cell_t CreateTopMenu(IPluginContext *pContext, const cell_t *params)
return BAD_HANDLE;
}
cb->m_hMenuHandle = hndl;
return hndl;
}
@@ -204,7 +209,7 @@ static cell_t AddToTopMenu(IPluginContext *pContext, const cell_t *params)
char *name, *cmdname;
pContext->LocalToString(params[2], &name);
pContext->LocalToString(params[5], &cmdname);
pContext->LocalToString(params[6], &cmdname);
TopMenuObjectType obj_type = (TopMenuObjectType)params[3];
@@ -213,8 +218,9 @@ static cell_t AddToTopMenu(IPluginContext *pContext, const cell_t *params)
obj_type,
cb,
pContext->GetIdentity(),
cmdname,params[6],
params[7])) == 0)
cmdname,
params[7],
params[5])) == 0)
{
delete cb;
return 0;
@@ -258,10 +264,37 @@ static cell_t FindTopMenuCategory(IPluginContext *pContext, const cell_t *params
return pMenu->FindCategory(name);
}
static cell_t DisplayTopMenu(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);
}
int client = params[2];
IGamePlayer *player = playerhelpers->GetGamePlayer(client);
if (!player)
{
return pContext->ThrowNativeError("Invalid client index %d", client);
}
else if (!player->IsInGame())
{
return pContext->ThrowNativeError("Client %d is not in game", client);
}
return pMenu->DisplayMenu(client, 0, (TopMenuPosition)params[3]);
}
sp_nativeinfo_t g_TopMenuNatives[] =
{
{"AddToTopMenu", AddToTopMenu},
{"CreateTopMenu", CreateTopMenu},
{"DisplayTopMenu", DisplayTopMenu},
{"LoadTopMenuConfig", LoadTopMenuConfig},
{"RemoveFromTopMenu", RemoveFromTopMenu},
{"FindTopMenuCategory", FindTopMenuCategory},