Added amb1167: menu_addtext(menu, const text[], slot=1)
This commit is contained in:
parent
1d7cbd4203
commit
9100ec753c
@ -183,7 +183,7 @@ int Menu::PagekeyToItem(page_t page, item_t key)
|
||||
{
|
||||
for (size_t j=0; j<m_Items[i]->blanks.size(); j++)
|
||||
{
|
||||
if (m_Items[i]->blanks[j] == 1)
|
||||
if (m_Items[i]->blanks[j].EatNumber())
|
||||
{
|
||||
if (!new_key)
|
||||
{
|
||||
@ -231,7 +231,7 @@ int Menu::PagekeyToItem(page_t page, item_t key)
|
||||
|
||||
for (size_t j=0; j<m_Items[i]->blanks.size(); j++)
|
||||
{
|
||||
if (m_Items[i]->blanks[j] == 1)
|
||||
if (m_Items[i]->blanks[j].EatNumber())
|
||||
{
|
||||
new_key--;
|
||||
}
|
||||
@ -265,7 +265,7 @@ int Menu::PagekeyToItem(page_t page, item_t key)
|
||||
{
|
||||
for (size_t j=0; j<m_Items[i]->blanks.size(); j++)
|
||||
{
|
||||
if (m_Items[i]->blanks[j] == 1)
|
||||
if (m_Items[i]->blanks[j].EatNumber())
|
||||
{
|
||||
if (!new_key)
|
||||
{
|
||||
@ -451,10 +451,11 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
|
||||
{
|
||||
for (size_t j=0; j<pItem->blanks.size(); j++)
|
||||
{
|
||||
if (pItem->blanks[j] == 1)
|
||||
if (pItem->blanks[j].EatNumber())
|
||||
{
|
||||
option++;
|
||||
}
|
||||
m_Text.append(pItem->blanks[j].GetDisplay());
|
||||
m_Text.append("\n");
|
||||
slots++;
|
||||
}
|
||||
@ -607,7 +608,6 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params)
|
||||
|
||||
return pMenu->thisId;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL menu_addblank(AMX *amx, cell *params)
|
||||
{
|
||||
GETMENU(params[1]);
|
||||
@ -625,7 +625,51 @@ static cell AMX_NATIVE_CALL menu_addblank(AMX *amx, cell *params)
|
||||
}
|
||||
|
||||
menuitem *item = pMenu->m_Items[pMenu->m_Items.size() - 1];
|
||||
item->blanks.push_back(params[2]);
|
||||
|
||||
BlankItem a;
|
||||
|
||||
a.SetBlank();
|
||||
|
||||
if (params[2] == 1)
|
||||
a.SetEatNumber(true);
|
||||
|
||||
else
|
||||
a.SetEatNumber(false);
|
||||
|
||||
item->blanks.push_back(a);
|
||||
|
||||
return 1;
|
||||
}
|
||||
static cell AMX_NATIVE_CALL menu_addtext(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];
|
||||
|
||||
BlankItem a;
|
||||
|
||||
int len;
|
||||
a.SetText(get_amxstring(amx, params[2], 0, len));
|
||||
|
||||
if (params[3] == 1)
|
||||
a.SetEatNumber(true);
|
||||
|
||||
else
|
||||
a.SetEatNumber(false);
|
||||
|
||||
item->blanks.push_back(a);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1034,6 +1078,7 @@ AMX_NATIVE_INFO g_NewMenuNatives[] =
|
||||
{"menu_create", menu_create},
|
||||
{"menu_additem", menu_additem},
|
||||
{"menu_addblank", menu_addblank},
|
||||
{"menu_addtext", menu_addtext},
|
||||
{"menu_pages", menu_pages},
|
||||
{"menu_items", menu_items},
|
||||
{"menu_display", menu_display},
|
||||
|
@ -54,6 +54,46 @@
|
||||
|
||||
typedef int (*MENUITEM_CALLBACK)(int, int, int);
|
||||
|
||||
class BlankItem
|
||||
{
|
||||
private:
|
||||
char *m_text;
|
||||
bool m_num;
|
||||
public:
|
||||
BlankItem() : m_text(NULL), m_num(false) { }
|
||||
BlankItem(BlankItem &src) { this->copyFrom(src); }
|
||||
~BlankItem() { free(m_text); }
|
||||
|
||||
void copyFrom(BlankItem &src)
|
||||
{
|
||||
m_text = src.m_text;
|
||||
m_num = src.m_num;
|
||||
src.m_text = NULL; // stop the src from freeing the buffer
|
||||
}
|
||||
BlankItem &operator = (const BlankItem &src) { this->copyFrom(const_cast<BlankItem&>(src)); return *this; }
|
||||
|
||||
/* is this text instead of a blank */
|
||||
bool IsText() { return m_text != NULL; }
|
||||
|
||||
/* is this a blank instead of text */
|
||||
bool IsBlank() { return m_text == NULL; }
|
||||
|
||||
/* does this item take up a number */
|
||||
bool EatNumber() { return m_num; }
|
||||
|
||||
/* the text this item is to display */
|
||||
const char *GetDisplay() { return m_text == NULL ? "" : m_text; }
|
||||
|
||||
/* sets this item to use a blank */
|
||||
void SetBlank() { free(m_text); m_text = NULL; }
|
||||
|
||||
/* sets this item to display text */
|
||||
void SetText(const char *text) { free(m_text); m_text = strdup(text); }
|
||||
|
||||
/* sets whether or not this item takes up a line */
|
||||
void SetEatNumber(bool val) { m_num = val; }
|
||||
|
||||
};
|
||||
struct menuitem
|
||||
{
|
||||
String name;
|
||||
@ -65,7 +105,7 @@ struct menuitem
|
||||
MENUITEM_CALLBACK pfn;
|
||||
size_t id;
|
||||
|
||||
CVector<int> blanks;
|
||||
CVector<BlankItem> blanks;
|
||||
};
|
||||
|
||||
typedef unsigned int menu_t;
|
||||
|
@ -227,6 +227,18 @@ native player_menu_info(id, &menu, &newmenu, &menupage=0);
|
||||
*/
|
||||
native menu_addblank(menu, slot=1);
|
||||
|
||||
/**
|
||||
* Adds a text line to a menu. Only available in amxmodx 1.8.1 and above.
|
||||
*
|
||||
* @param menu Menu resource identifier.
|
||||
* @param text Text to add.
|
||||
* @param slot 1 (default) if the line should shift the numbering down.
|
||||
* 0 if the line should be a visual shift only.
|
||||
* @noreturn
|
||||
* @error Invalid menu resource.
|
||||
*/
|
||||
native menu_addtext(menu, const text[], slot=1);
|
||||
|
||||
/**
|
||||
* Sets a menu property.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user