From d682375d7d6b188a063a6987fc9bd421ca64a79b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 25 Apr 2007 14:44:37 +0000 Subject: [PATCH] rewrote how new menus are detected -- menucmds are no longer used since they're idiotic anyway --- amxmodx/CMenu.cpp | 19 +++++++++++-- amxmodx/meta_api.cpp | 66 ++++++++++++++++++++++---------------------- amxmodx/newmenus.cpp | 51 ++++++++++++++++------------------ 3 files changed, 74 insertions(+), 62 deletions(-) diff --git a/amxmodx/CMenu.cpp b/amxmodx/CMenu.cpp index 7fb8b130..b2a3bafc 100755 --- a/amxmodx/CMenu.cpp +++ b/amxmodx/CMenu.cpp @@ -150,8 +150,23 @@ int MenuMngr::registerMenuId(const char* n, AMX* a) void MenuMngr::registerMenuCmd(CPluginMngr::CPlugin *a, int mi, int k, int f, int n) { - MenuCommand** temp = &headcmd; - while (*temp) temp = &(*temp)->next; + MenuCommand **temp = &headcmd; + MenuCommand *ptr; + while (*temp) + { + ptr = *temp; + if (n > -1 + && ptr->plugin == a + && ptr->menuid == mi + && ptr->keys == k) + { + if (strcmp(g_forwards.getFuncName(ptr->function), g_forwards.getFuncName(f)) == 0) + { + return; + } + } + temp = &(*temp)->next; + } *temp = new MenuCommand(a, mi, k, f, n); } diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 69fdaeed..9e47b515 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -948,6 +948,34 @@ void C_ClientCommand(edict_t *pEntity) int menuid = pPlayer->menu; pPlayer->menu = 0; + /* First, do new menus */ + if (pPlayer->newmenu != -1) + { + int menu = pPlayer->newmenu; + pPlayer->newmenu = -1; + + if (menu >= 0 && menu < (int)g_NewMenus.size() && g_NewMenus[menu]) + { + Menu *pMenu = g_NewMenus[menu]; + int item = pMenu->PagekeyToItem(pPlayer->page, pressed_key+1); + if (item == MENU_BACK) + { + pMenu->Display(pPlayer->index, pPlayer->page - 1); + } else if (item == MENU_MORE) { + pMenu->Display(pPlayer->index, pPlayer->page + 1); + } else { + ret = executeForwards(pMenu->func, static_cast(pPlayer->index), static_cast(menu), static_cast(item)); + if (ret & 2) + { + result = MRES_SUPERCEDE; + } else if (ret & 1) { + RETURN_META(MRES_SUPERCEDE); + } + } + } + } + + /* Now, do old menus */ MenuMngr::iterator a = g_menucmds.begin(); while (a) @@ -955,39 +983,11 @@ void C_ClientCommand(edict_t *pEntity) g_menucmds.SetWatchIter(a); if ((*a).matchCommand(menuid, bit_key) && (*a).getPlugin()->isExecutable((*a).getFunction())) { - if (pPlayer->newmenu != -1 && pPlayer->newmenu == (*a).newmenu) - { - int menu = pPlayer->newmenu; - pPlayer->newmenu = -1; - - if (menu >= 0 && menu < (int)g_NewMenus.size()) - { - Menu *pMenu = g_NewMenus[menu]; - int item = pMenu->PagekeyToItem(pPlayer->page, pressed_key+1); - - if (item == MENU_BACK) - { - pMenu->Display(pPlayer->index, pPlayer->page - 1); - } else if (item == MENU_MORE) { - pMenu->Display(pPlayer->index, pPlayer->page + 1); - } else { - ret = executeForwards((*a).getFunction(), static_cast(pPlayer->index), static_cast(menu), static_cast(item)); - - if (ret & 2) - result = MRES_SUPERCEDE; - else if (ret & 1) - RETURN_META(MRES_SUPERCEDE); - } - } - if (pPlayer->newmenu != -1) - break; - } else { - ret = executeForwards((*a).getFunction(), static_cast(pPlayer->index), - static_cast(pressed_key), 0); - - if (ret & 2) result = MRES_SUPERCEDE; - if (ret & 1) RETURN_META(MRES_SUPERCEDE); - } + ret = executeForwards((*a).getFunction(), static_cast(pPlayer->index), + static_cast(pressed_key), 0); + + if (ret & 2) result = MRES_SUPERCEDE; + if (ret & 1) RETURN_META(MRES_SUPERCEDE); } if (g_menucmds.GetWatchIter() != a) { diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index a3f5960d..9fd18f45 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -48,6 +48,28 @@ void ClearMenus() } } +void RemoveMenuIdIfOkay(Menu *pMenu, int menuid) +{ + /* :TODO: Move this to some sort of referencing counting thingy */ + bool removeMenuId = true; + for (size_t i = 0; i < g_NewMenus.size(); i++) + { + if (!g_NewMenus[i] || g_NewMenus[i]->isDestroying) + { + continue; + } + if (g_NewMenus[i]->menuId == menuid) + { + removeMenuId = false; + break; + } + } + if (removeMenuId) + { + g_menucmds.removeMenuId(menuid); + } +} + void validate_menu_text(char *str) { if (!g_coloredmenus) @@ -600,8 +622,6 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params) pMenu->thisId = pos; } - g_menucmds.registerMenuCmd(g_plugins.findPluginFast(amx), id, 1023, func, pMenu->thisId); - return pMenu->thisId; } @@ -883,14 +903,9 @@ static cell AMX_NATIVE_CALL menu_setprop(AMX *amx, cell *params) { char *str = get_amxstring(amx, params[3], 0, len); int old = pMenu->menuId; - g_menucmds.removeMenuId(old); + RemoveMenuIdIfOkay(pMenu, old); pMenu->m_Title.assign(str); pMenu->menuId = g_menucmds.registerMenuId(str, amx); - g_menucmds.registerMenuCmd( - g_plugins.findPluginFast(amx), - pMenu->menuId, - 1023, - pMenu->func); CPlayer *pl; /** * NOTE - this is actually bogus @@ -990,25 +1005,7 @@ static cell AMX_NATIVE_CALL menu_destroy(AMX *amx, cell *params) pMenu->isDestroying = true; - /* :TODO: Move this to some sort of referencing counting thingy */ - bool removeMenuId = true; - for (size_t i = 0; i < g_NewMenus.size(); i++) - { - if (!g_NewMenus[i] || g_NewMenus[i]->isDestroying) - { - continue; - } - if (g_NewMenus[i]->menuId == pMenu->menuId) - { - removeMenuId = false; - break; - } - } - if (removeMenuId) - { - g_menucmds.removeMenuId(pMenu->menuId); - } - g_menucmds.removeMenuCmds(pMenu->thisId); + RemoveMenuIdIfOkay(pMenu, pMenu->menuId); CPlayer *player; for (int i=1; i<=gpGlobals->maxClients; i++)