From 32a42886dd597f8062db7ef28834659cc388ab79 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 29 Jul 2005 19:13:55 +0000 Subject: [PATCH] Finished new menu system (for now) Fixed bug where client_print did not add newlines properly --- amxmodx/CMisc.h | 2 ++ amxmodx/amxmodx.cpp | 8 ++++-- amxmodx/meta_api.cpp | 68 +++++++++++++++++++------------------------- amxmodx/newmenus.cpp | 6 ++-- amxmodx/newmenus.h | 1 + 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/amxmodx/CMisc.h b/amxmodx/CMisc.h index 45e88b4d..9699a13e 100755 --- a/amxmodx/CMisc.h +++ b/amxmodx/CMisc.h @@ -99,6 +99,8 @@ public: int death_victim; bool death_tk; String death_weapon; + int newmenu; + int page; Vector lastTrace; Vector thisTrace; diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 0a0059f3..481ef1fe 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -223,7 +223,7 @@ static cell AMX_NATIVE_CALL client_print(AMX *amx, cell *params) /* 3 param */ msg[len++] = '\n'; msg[len] = 0; if (pPlayer->ingame) - UTIL_ClientPrint(pPlayer->pEdict, params[2], format_amxstring(amx, params, 3, len)); + UTIL_ClientPrint(pPlayer->pEdict, params[2], msg); //format_amxstring(amx, params, 3, len)); } return len; } @@ -756,6 +756,8 @@ static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */ if (pPlayer->ingame){ pPlayer->keys = keys; pPlayer->menu = menuid; + pPlayer->newmenu = -1; + pPlayer->page = 0; UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen ); } } @@ -770,6 +772,8 @@ static cell AMX_NATIVE_CALL show_menu(AMX *amx, cell *params) /* 3 param */ if (pPlayer->ingame){ pPlayer->keys = keys; pPlayer->menu = menuid; + pPlayer->newmenu = -1; + pPlayer->page = 0; UTIL_ShowMenu(pPlayer->pEdict, keys, time, sMenu, ilen ); } } @@ -794,7 +798,7 @@ static cell AMX_NATIVE_CALL register_menucmd(AMX *amx, cell *params) /* 3 param int ilen, idx; char* sptemp = get_amxstring(amx,params[3],0,ilen); - idx = registerSPForwardByName(amx, sptemp, FP_CELL, FP_CELL, FP_DONE); + idx = registerSPForwardByName(amx, sptemp, FP_CELL, FP_CELL, FP_CELL, FP_DONE); if (idx == -1) { LogError(amx, AMX_ERR_NOTFOUND, "Function \"%s\" was not found", sptemp); diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 0331e590..eb185646 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -175,19 +175,8 @@ int C_InconsistentFile( const edict_t *player, const char *filename, char *disco { CPlayer *pPlayer = GET_PLAYER_POINTER((edict_t *)player); -#ifdef ENABLEEXEPTIONS - try - { -#endif if (executeForwards(FF_InconsistentFile, pPlayer->index, filename, disconnect_message) == 1) RETURN_META_VALUE(MRES_SUPERCEDE, FALSE); -#ifdef ENABLEEXEPTIONS - } - catch( ... ) - { - AMXXLOG_Log( "[AMXX] Fatal error at inconsistent file forward execution"); - } -#endif RETURN_META_VALUE(MRES_SUPERCEDE, TRUE ); } @@ -638,27 +627,12 @@ void C_ClientCommand( edict_t *pEntity ) { } } -#ifdef ENABLEEXEPTIONS - try - { -#endif - if (executeForwards(FF_ClientCommand, pPlayer->index) > 0) - RETURN_META(MRES_SUPERCEDE); + if (executeForwards(FF_ClientCommand, pPlayer->index) > 0) + RETURN_META(MRES_SUPERCEDE); -#ifdef ENABLEEXEPTIONS - } - catch( ... ) - { - AMXXLOG_Log( "[AMXX] Fatal error at commmand forward execution"); - } -#endif /* check for command and if needed also for first argument and call proper function */ -#ifdef ENABLEEXEPTIONS - try{ -#endif - CmdMngr::iterator aa = g_commands.clcmdprefixbegin( cmd ); if ( !aa ) aa = g_commands.clcmdbegin(); @@ -675,12 +649,6 @@ void C_ClientCommand( edict_t *pEntity ) { ++aa; } -#ifdef ENABLEEXEPTIONS - }catch( ... ) - { - AMXXLOG_Log( "[AMXX] fatal error at client commmand execution"); - } -#endif /* check menu commands */ if (!strcmp(cmd,"menuselect")) @@ -694,15 +662,39 @@ void C_ClientCommand( edict_t *pEntity ) { int menuid = pPlayer->menu; pPlayer->menu = 0; - MenuMngr::iterator a = g_menucmds.begin(); + MenuMngr::iterator a = g_menucmds.begin(); while( a ) { if ( (*a).matchCommand( menuid , bit_key ) && (*a).getPlugin()->isExecutable( (*a).getFunction() ) ) { - ret = executeForwards((*a).getFunction(), pPlayer->index, pressed_key); - if ( ret & 2 ) result = MRES_SUPERCEDE; - if ( ret & 1 ) RETURN_META(MRES_SUPERCEDE); + if (pPlayer->newmenu != -1) + { + 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); + ret = executeForwards( (*a).getFunction(), pPlayer->index, menu, item ); + if ( ret & 2 ) result = MRES_SUPERCEDE; + else if ( ret & 1 ) RETURN_META(MRES_SUPERCEDE); + else { + if (item == MENU_BACK) + { + pMenu->Display(pPlayer->index, pPlayer->page-1); + } else if (item == MENU_MORE) { + pMenu->Display(pPlayer->index, pPlayer->page+1); + } else if (item == MENU_EXIT) { + //nothing + } + } + } + } else { + ret = executeForwards((*a).getFunction(), pPlayer->index, pressed_key, 0); + if ( ret & 2 ) result = MRES_SUPERCEDE; + if ( ret & 1 ) RETURN_META(MRES_SUPERCEDE); + } } ++a; diff --git a/amxmodx/newmenus.cpp b/amxmodx/newmenus.cpp index 1f167a70..6871b41a 100755 --- a/amxmodx/newmenus.cpp +++ b/amxmodx/newmenus.cpp @@ -127,6 +127,8 @@ bool Menu::Display(int player, page_t page) pPlayer->keys = keys; pPlayer->menu = menuId; + pPlayer->newmenu = thisId; + pPlayer->page = (int)page; UTIL_ShowMenu(pPlayer->pEdict, keys, -1, buffer, len); @@ -238,7 +240,7 @@ static cell AMX_NATIVE_CALL menu_create(AMX *amx, cell *params) char *title = get_amxstring(amx, params[1], 0, len); char *handler = get_amxstring(amx, params[2], 1, len); - int func = registerSPForwardByName(amx, handler, FP_CELL, FP_CELL, FP_DONE); + int func = registerSPForwardByName(amx, handler, FP_CELL, FP_CELL, FP_CELL, FP_DONE); if (func == -1) { LogError(amx, AMX_ERR_NOTFOUND, "Invalid function \"%s\"", handler); @@ -372,4 +374,4 @@ AMX_NATIVE_INFO g_NewMenuNatives[] = {"menu_item_getinfo", menu_item_getinfo}, {"menu_makecallback", menu_makecallback}, {NULL, NULL}, -}; \ No newline at end of file +}; diff --git a/amxmodx/newmenus.h b/amxmodx/newmenus.h index 5c29bb95..f6a3750e 100755 --- a/amxmodx/newmenus.h +++ b/amxmodx/newmenus.h @@ -62,6 +62,7 @@ const char *GetItemCmd(menu_t menu, item_t item);*/ void ClearMenus(); +extern CVector g_NewMenus; extern AMX_NATIVE_INFO g_NewMenuNatives[]; #endif //_INCLUDE_NEWMENUS_H