rewrote how new menus are detected -- menucmds are no longer used since they're idiotic anyway

This commit is contained in:
David Anderson 2007-04-25 14:44:37 +00:00
parent 3b80342a02
commit d682375d7d
3 changed files with 74 additions and 62 deletions

View File

@ -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);
}

View File

@ -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<cell>(pPlayer->index), static_cast<cell>(menu), static_cast<cell>(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,40 +983,12 @@ 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<cell>(pPlayer->index), static_cast<cell>(menu), static_cast<cell>(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<cell>(pPlayer->index),
static_cast<cell>(pressed_key), 0);
if (ret & 2) result = MRES_SUPERCEDE;
if (ret & 1) RETURN_META(MRES_SUPERCEDE);
}
}
if (g_menucmds.GetWatchIter() != a)
{
a = g_menucmds.GetWatchIter();

View File

@ -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++)