Newmenus: Add get_menu_by_id and use it everywhere
This commit is contained in:
@@ -79,6 +79,14 @@ void validate_menu_text(char *str)
|
||||
*(str-offs) = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Menu *get_menu_by_id(int id)
|
||||
{
|
||||
if (id < 0 || size_t(id) >= g_NewMenus.size() || !g_NewMenus[id])
|
||||
return NULL;
|
||||
|
||||
return g_NewMenus[id];
|
||||
}
|
||||
|
||||
Menu::Menu(const char *title, AMX *amx, int fid) : m_Title(title), m_ItemColor("\\r"),
|
||||
@@ -606,10 +614,10 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
|
||||
return m_Text.c_str();
|
||||
}
|
||||
|
||||
#define GETMENU(p) if (p >= (int)g_NewMenus.size() || p < 0 || !g_NewMenus[p] || g_NewMenus[p]->isDestroying) { \
|
||||
#define GETMENU(p) Menu *pMenu = get_menu_by_id(p); \
|
||||
if (pMenu == NULL || pMenu->isDestroying) { \
|
||||
LogError(amx, AMX_ERR_NATIVE, "Invalid menu id %d(%d)", p, g_NewMenus.size()); \
|
||||
return 0; } \
|
||||
Menu *pMenu = g_NewMenus[p];
|
||||
return 0; }
|
||||
|
||||
//Makes a new menu handle (-1 for failure)
|
||||
//native csdm_makemenu(title[]);
|
||||
@@ -1040,10 +1048,10 @@ static cell AMX_NATIVE_CALL menu_setprop(AMX *amx, cell *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define GETMENU_R(p) if (p >= (int)g_NewMenus.size() || p < 0 || !g_NewMenus[p]) { \
|
||||
#define GETMENU_R(p) Menu *pMenu = get_menu_by_id(p); \
|
||||
if (pMenu == NULL) { \
|
||||
LogError(amx, AMX_ERR_NATIVE, "Invalid menu id %d(%d)", p, g_NewMenus.size()); \
|
||||
return 0; } \
|
||||
Menu *pMenu = g_NewMenus[p];
|
||||
return 0; }
|
||||
|
||||
static cell AMX_NATIVE_CALL menu_cancel(AMX *amx, cell *params)
|
||||
{
|
||||
@@ -1062,14 +1070,12 @@ static cell AMX_NATIVE_CALL menu_cancel(AMX *amx, cell *params)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int menu = player->newmenu;
|
||||
if (menu < 0 || menu >= (int)g_NewMenus.size() || !g_NewMenus[menu])
|
||||
return 0;
|
||||
if (Menu *pMenu = get_menu_by_id(player->newmenu)) {
|
||||
pMenu->Close(player->index);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Menu *pMenu = g_NewMenus[menu];
|
||||
pMenu->Close(player->index);
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params)
|
||||
|
Reference in New Issue
Block a user