fixed blank items destroying menus

This commit is contained in:
David Anderson 2006-02-08 05:39:03 +00:00
parent 8d0a3ac9ae
commit 1e4c71e8e3
2 changed files with 47 additions and 18 deletions

View File

@ -283,11 +283,6 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
enabled = false;
}
if (pItem->name.size() < 1)
{
option++;
_snprintf(buffer, sizeof(buffer)-1, "\n");
} else {
if (enabled)
{
keys |= (1<<option);
@ -304,9 +299,19 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
option++;
}
}
}
m_Text.append(buffer);
//attach blanks
if (pItem->blanks.size())
{
for (size_t j=0; j<pItem->blanks.size(); j++)
{
if (pItem->blanks[j] == 1)
option++;
m_Text.append("\n");
}
}
}
for (int i=0; i<3; i++)
@ -395,6 +400,28 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params)
return (int)g_NewMenus.size() - 1;
}
static cell AMX_NATIVE_CALL menu_addblank(AMX *amx, cell *params)
{
GETMENU(params[1]);
if (params[2] && (!pMenu->items_per_page && pMenu->GetItemCount() >= 10))
{
LogError(amx, AMX_ERR_NATIVE, "Non-paginated menus are limited to 10 items.");
return 0;
}
if (!pMenu->m_Items.size())
{
LogError(amx, AMX_ERR_NATIVE, "Blanks can only be added after items.");
return 0;
}
menuitem *item = pMenu->m_Items[pMenu->m_Items.size() - 1];
item->blanks.push_back(params[2]);
return 1;
}
//Adds an item to the menu (returns current item count - 1)
//native menu_additem(menu, const name[], const command[]="", access=0);
static cell AMX_NATIVE_CALL menu_additem(AMX *amx, cell *params)
@ -704,6 +731,7 @@ AMX_NATIVE_INFO g_NewMenuNatives[] =
{
{"menu_create", menu_create},
{"menu_additem", menu_additem},
{"menu_addblank", menu_addblank},
{"menu_pages", menu_pages},
{"menu_items", menu_items},
{"menu_display", menu_display},

View File

@ -61,6 +61,8 @@ struct menuitem
MENUITEM_CALLBACK pfn;
size_t id;
CVector<int> blanks;
};
typedef unsigned int menu_t;
@ -83,9 +85,8 @@ public:
int PagekeyToItem(page_t page, item_t key);
int GetMenuMenuid();
private:
CVector<menuitem * > m_Items;
public:
CVector<menuitem * > m_Items;
String m_Title;
String m_Text;