Newmenus: Add get_menu_by_id and use it everywhere
This commit is contained in:
parent
c91d67912b
commit
a6ffae72f5
@ -65,11 +65,8 @@ void CPlayer::Disconnect()
|
||||
authorized = false;
|
||||
teamIdsInitialized = false;
|
||||
|
||||
if (newmenu >= 0 && newmenu < (int)g_NewMenus.size() && g_NewMenus[newmenu])
|
||||
{
|
||||
Menu *pMenu = g_NewMenus[newmenu];
|
||||
if (Menu *pMenu = get_menu_by_id(newmenu))
|
||||
pMenu->Close(index);
|
||||
}
|
||||
|
||||
List<ClientCvarQuery_Info *>::iterator iter, end=queries.end();
|
||||
for (iter=queries.begin(); iter!=end; iter++)
|
||||
|
@ -1294,12 +1294,8 @@ static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */
|
||||
pPlayer->menu = 0;
|
||||
|
||||
// Fire newmenu callback so closing it can be handled by the plugin
|
||||
int menu = pPlayer->newmenu;
|
||||
if (menu >= 0 && menu < (int)g_NewMenus.size() && g_NewMenus[menu])
|
||||
{
|
||||
Menu *pMenu = g_NewMenus[menu];
|
||||
if (Menu *pMenu = get_menu_by_id(pPlayer->newmenu))
|
||||
pMenu->Close(pPlayer->index);
|
||||
}
|
||||
|
||||
UTIL_FakeClientCommand(pPlayer->pEdict, "menuselect", "10", 0);
|
||||
|
||||
@ -1333,12 +1329,8 @@ static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */
|
||||
pPlayer->menu = 0;
|
||||
|
||||
// Fire newmenu callback so closing it can be handled by the plugin
|
||||
int menu = pPlayer->newmenu;
|
||||
if (menu >= 0 && menu < (int)g_NewMenus.size() && g_NewMenus[menu])
|
||||
{
|
||||
Menu *pMenu = g_NewMenus[menu];
|
||||
if (Menu *pMenu = get_menu_by_id(pPlayer->newmenu))
|
||||
pMenu->Close(pPlayer->index);
|
||||
}
|
||||
|
||||
UTIL_FakeClientCommand(pPlayer->pEdict, "menuselect", "10", 0);
|
||||
|
||||
@ -2962,12 +2954,8 @@ static cell AMX_NATIVE_CALL get_user_menu(AMX *amx, cell *params) /* 3 param */
|
||||
{
|
||||
if (gpGlobals->time > pPlayer->menuexpire)
|
||||
{
|
||||
int menu = pPlayer->newmenu;
|
||||
if (menu >= 0 && menu < (int)g_NewMenus.size() && g_NewMenus[menu])
|
||||
{
|
||||
Menu *pMenu = g_NewMenus[menu];
|
||||
if (Menu *pMenu = get_menu_by_id(pPlayer->newmenu))
|
||||
pMenu->Close(pPlayer->index);
|
||||
}
|
||||
else
|
||||
pPlayer->menu = 0;
|
||||
|
||||
|
@ -963,10 +963,8 @@ void C_ClientCommand(edict_t *pEntity)
|
||||
{
|
||||
if (gpGlobals->time > pPlayer->menuexpire)
|
||||
{
|
||||
int menu = pPlayer->newmenu;
|
||||
if (menu >= 0 && menu < (int)g_NewMenus.size() && g_NewMenus[menu])
|
||||
if (Menu *pMenu = get_menu_by_id(pPlayer->newmenu))
|
||||
{
|
||||
Menu *pMenu = g_NewMenus[menu];
|
||||
pMenu->Close(pPlayer->index);
|
||||
|
||||
RETURN_META(MRES_SUPERCEDE);
|
||||
@ -989,10 +987,8 @@ void C_ClientCommand(edict_t *pEntity)
|
||||
{
|
||||
int menu = pPlayer->newmenu;
|
||||
pPlayer->newmenu = -1;
|
||||
|
||||
if (menu >= 0 && menu < (int)g_NewMenus.size() && g_NewMenus[menu])
|
||||
if (Menu *pMenu = get_menu_by_id(menu))
|
||||
{
|
||||
Menu *pMenu = g_NewMenus[menu];
|
||||
int item = pMenu->PagekeyToItem(pPlayer->page, pressed_key+1);
|
||||
if (item == MENU_BACK)
|
||||
{
|
||||
|
@ -81,6 +81,14 @@ void validate_menu_text(char *str)
|
||||
}
|
||||
}
|
||||
|
||||
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"),
|
||||
m_NeverExit(false), m_AutoColors(g_coloredmenus), thisId(0), func(fid),
|
||||
isDestroying(false), items_per_page(7)
|
||||
@ -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;
|
||||
|
||||
Menu *pMenu = g_NewMenus[menu];
|
||||
if (Menu *pMenu = get_menu_by_id(player->newmenu)) {
|
||||
pMenu->Close(player->index);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params)
|
||||
|
@ -151,6 +151,7 @@ public:
|
||||
};
|
||||
|
||||
void ClearMenus();
|
||||
Menu *get_menu_by_id(int id);
|
||||
|
||||
extern CVector<Menu *> g_NewMenus;
|
||||
extern AMX_NATIVE_INFO g_NewMenuNatives[];
|
||||
|
Loading…
Reference in New Issue
Block a user