Add menu_addblank2 and menu_addtext2 to fix unexpected behavior with the original ones when slot=1 (bug 3096, r=Arkshine)

This commit is contained in:
Nextra 2013-07-02 14:54:07 +02:00
parent 15b0fba122
commit b4f84a5cee
3 changed files with 93 additions and 2 deletions

View File

@ -129,6 +129,7 @@ menuitem *Menu::AddItem(const char *name, const char *cmd, int access)
pItem->access = access;
pItem->id = m_Items.size();
pItem->handler = -1;
pItem->isBlank = false;
pItem->pfn = NULL;
m_Items.push_back(pItem);
@ -420,6 +421,11 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
}
}
if (pItem->isBlank)
{
enabled = false;
}
if (enabled)
{
keys |= (1<<option);
@ -431,7 +437,11 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
option_display = 0;
}
if (enabled)
if (pItem->isBlank)
{
_snprintf(buffer, sizeof(buffer)-1, "%s\n", pItem->name.c_str());
}
else if (enabled)
{
if (m_AutoColors)
{
@ -679,6 +689,43 @@ static cell AMX_NATIVE_CALL menu_addtext(AMX *amx, cell *params)
return 1;
}
static cell AMX_NATIVE_CALL menu_addblank2(AMX *amx, cell *params)
{
GETMENU(params[1]);
if (!pMenu->items_per_page && pMenu->GetItemCount() >= 10)
{
LogError(amx, AMX_ERR_NATIVE, "Non-paginated menus are limited to 10 items.");
return 0;
}
menuitem *pItem = pMenu->AddItem("", "", 0);
pItem->isBlank = true;
return 1;
}
static cell AMX_NATIVE_CALL menu_addtext2(AMX *amx, cell *params)
{
int len;
char *name;
GETMENU(params[1]);
if (!pMenu->items_per_page && pMenu->GetItemCount() >= 10)
{
LogError(amx, AMX_ERR_NATIVE, "Non-paginated menus are limited to 10 items.");
return 0;
}
name = get_amxstring(amx, params[2], 0, len);
validate_menu_text(name);
menuitem *pItem = pMenu->AddItem(name, "", 0);
pItem->isBlank = true;
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)
@ -1097,5 +1144,7 @@ AMX_NATIVE_INFO g_NewMenuNatives[] =
{"menu_setprop", menu_setprop},
{"menu_cancel", menu_cancel},
{"player_menu_info", player_menu_info},
{"menu_addblank2", menu_addblank2},
{"menu_addtext2", menu_addtext2},
{NULL, NULL},
};

View File

@ -101,6 +101,7 @@ struct menuitem
int access;
int handler;
bool isBlank;
MENUITEM_CALLBACK pfn;
size_t id;

View File

@ -219,6 +219,9 @@ native player_menu_info(id, &menu, &newmenu, &menupage=0);
/**
* Adds a blank line to a menu.
*
* When using slot=1 this might break your menu. To achieve this functionality
* menu_addblank2 should be used.
*
* @param menu Menu resource identifier.
* @param slot 1 (default) if the line should shift the numbering down.
* 0 if the line should be a visual shift only.
@ -230,6 +233,9 @@ native menu_addblank(menu, slot=1);
/**
* Adds a text line to a menu. Only available in amxmodx 1.8.1 and above.
*
* When using slot=1 this might break your menu. To achieve this functionality
* menu_addtext2 should be used.
*
* @param menu Menu resource identifier.
* @param text Text to add.
* @param slot 1 (default) if the line should shift the numbering down.
@ -239,6 +245,41 @@ native menu_addblank(menu, slot=1);
*/
native menu_addtext(menu, const text[], slot=1);
/**
* Adds a blank line to a menu, always shifting the numbering down.
*
* This will add a special item to create a blank line. It will affect the menu
* item count and pagination. These items can be modified later but will ignore
* access and item callback results.
*
* Only available in 1.8.3 and above.
*
* @param menu Menu resource identifier.
*
* @return 1 on success, 0 on failure.
* @error Invalid menu resource.
* Too many items on non-paginated menu (max is 10)
*/
native menu_addblank2( menu );
/**
* Adds a text line to a menu, always shifting the numbering down.
*
* This will add a special item to create a blank line. It will affect the menu
* item count and pagination. These items can be modified later but will ignore
* access and item callback results.
*
* Only available in 1.8.3 and above.
*
* @param menu Menu resource identifier.
* @param text Text to add.
*
* @return 1 on success, 0 on failure.
* @error Invalid menu resource.
* Too many items on non-paginated menu (max is 10)
*/
native menu_addtext2( menu, const text[] );
/**
* Sets a menu property.
*