From 4930ec109da6a0cb7107ce06cc210a13307baebc Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 3 Nov 2011 18:24:02 +0000 Subject: [PATCH] added a new lua method from Muwuum --- source/glest_game/game/script_manager.cpp | 99 +++++++++++++++++++++++ source/glest_game/game/script_manager.h | 2 + 2 files changed, 101 insertions(+) diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index 08761b67..33cb5d78 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -90,6 +90,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){ luaScript.registerFunction(addConsoleText, "addConsoleText"); luaScript.registerFunction(DisplayFormattedText, "DisplayFormattedText"); luaScript.registerFunction(DisplayFormattedText, "displayFormattedText"); + luaScript.registerFunction(DisplayFormattedLangText, "DisplayFormattedLangText"); + luaScript.registerFunction(DisplayFormattedLangText, "displayFormattedLangText"); luaScript.registerFunction(clearDisplayText, "clearDisplayText"); luaScript.registerFunction(setCameraPosition, "setCameraPosition"); luaScript.registerFunction(createUnit, "createUnit"); @@ -434,7 +436,24 @@ void ScriptManager::DisplayFormattedText(const char *fmt, ...) { va_end(argList); } +void ScriptManager::DisplayFormattedLangText(const char *fmt, ...) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + ScriptManager_STREFLOP_Wrapper streflopWrapper; + + + va_list argList; + va_start(argList, fmt); + + const int max_debug_buffer_size = 8096; + char szBuf[max_debug_buffer_size]=""; + vsnprintf(szBuf,max_debug_buffer_size-1,fmt, argList); + + //displayText= wrapString(Lang::getInstance().getScenarioString(text), displayTextWrapCount); + displayText=szBuf; + + va_end(argList); +} void ScriptManager::setCameraPosition(const Vec2i &pos){ if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1375,7 +1394,87 @@ int ScriptManager::DisplayFormattedText(LuaHandle* luaHandle) { return 0; */ } +int ScriptManager::DisplayFormattedLangText(LuaHandle* luaHandle) { + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //const char *ret; + //lua_lock(luaHandle); + //luaC_checkGC(luaHandle); + + const int max_args_allowed = 8; + int args = lua_gettop(luaHandle); + if(lua_checkstack(luaHandle, args+1)) { + LuaArguments luaArguments(luaHandle); + string fmt = luaArguments.getString(-args); + //va_list argList; + //va_start(argList, fmt.c_str() ); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"DisplayFormattedText args = %d!\n",args); + + if(args == 1) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str()); + } + else if(args == 2) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1)); + } + else if(args == 3) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2)); + } + else if(args == 4) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3)); + } + else if(args == 5) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4)); + } + else if(args == 6) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5)); + } + else if(args == 7) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5), + luaArguments.getGenericData(-args+6)); + } + else if(args == max_args_allowed) { + thisScriptManager->DisplayFormattedLangText(Lang::getInstance().getScenarioString(fmt).c_str(), + luaArguments.getGenericData(-args+1), + luaArguments.getGenericData(-args+2), + luaArguments.getGenericData(-args+3), + luaArguments.getGenericData(-args+4), + luaArguments.getGenericData(-args+5), + luaArguments.getGenericData(-args+6), + luaArguments.getGenericData(-args+7)); + } + else { + char szBuf[1024]=""; + sprintf(szBuf,"Invalid parameter count in method [%s] args = %d [argument count must be between 1 and %d]",__FUNCTION__,args,max_args_allowed); + throw runtime_error(szBuf); + } + + //va_end(argList); + } + //lua_unlock(luaHandle); + return 1; + +} int ScriptManager::getGameWon(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); luaArguments.returnInt(thisScriptManager->getGameWon()); diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index 9960fb72..7dc4bf6d 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -181,6 +181,7 @@ private: void setDisplayText(const string &text); void addConsoleText(const string &text); void DisplayFormattedText(const char *fmt,...); + void DisplayFormattedLangText(const char *fmt,...); void setCameraPosition(const Vec2i &pos); void createUnit(const string &unitName, int factionIndex, Vec2i pos); @@ -249,6 +250,7 @@ private: static int setDisplayText(LuaHandle* luaHandle); static int addConsoleText(LuaHandle* luaHandle); static int DisplayFormattedText(LuaHandle* luaHandle); + static int DisplayFormattedLangText(LuaHandle* luaHandle); static int clearDisplayText(LuaHandle* luaHandle); static int setCameraPosition(LuaHandle* luaHandle); static int createUnit(LuaHandle* luaHandle);