added a new lua method from Muwuum
This commit is contained in:
parent
5b0c3accfc
commit
4930ec109d
|
@ -90,6 +90,8 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){
|
||||||
luaScript.registerFunction(addConsoleText, "addConsoleText");
|
luaScript.registerFunction(addConsoleText, "addConsoleText");
|
||||||
luaScript.registerFunction(DisplayFormattedText, "DisplayFormattedText");
|
luaScript.registerFunction(DisplayFormattedText, "DisplayFormattedText");
|
||||||
luaScript.registerFunction(DisplayFormattedText, "displayFormattedText");
|
luaScript.registerFunction(DisplayFormattedText, "displayFormattedText");
|
||||||
|
luaScript.registerFunction(DisplayFormattedLangText, "DisplayFormattedLangText");
|
||||||
|
luaScript.registerFunction(DisplayFormattedLangText, "displayFormattedLangText");
|
||||||
luaScript.registerFunction(clearDisplayText, "clearDisplayText");
|
luaScript.registerFunction(clearDisplayText, "clearDisplayText");
|
||||||
luaScript.registerFunction(setCameraPosition, "setCameraPosition");
|
luaScript.registerFunction(setCameraPosition, "setCameraPosition");
|
||||||
luaScript.registerFunction(createUnit, "createUnit");
|
luaScript.registerFunction(createUnit, "createUnit");
|
||||||
|
@ -434,7 +436,24 @@ void ScriptManager::DisplayFormattedText(const char *fmt, ...) {
|
||||||
|
|
||||||
va_end(argList);
|
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){
|
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__);
|
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;
|
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){
|
int ScriptManager::getGameWon(LuaHandle* luaHandle){
|
||||||
LuaArguments luaArguments(luaHandle);
|
LuaArguments luaArguments(luaHandle);
|
||||||
luaArguments.returnInt(thisScriptManager->getGameWon());
|
luaArguments.returnInt(thisScriptManager->getGameWon());
|
||||||
|
|
|
@ -181,6 +181,7 @@ private:
|
||||||
void setDisplayText(const string &text);
|
void setDisplayText(const string &text);
|
||||||
void addConsoleText(const string &text);
|
void addConsoleText(const string &text);
|
||||||
void DisplayFormattedText(const char *fmt,...);
|
void DisplayFormattedText(const char *fmt,...);
|
||||||
|
void DisplayFormattedLangText(const char *fmt,...);
|
||||||
void setCameraPosition(const Vec2i &pos);
|
void setCameraPosition(const Vec2i &pos);
|
||||||
void createUnit(const string &unitName, int factionIndex, Vec2i pos);
|
void createUnit(const string &unitName, int factionIndex, Vec2i pos);
|
||||||
|
|
||||||
|
@ -249,6 +250,7 @@ private:
|
||||||
static int setDisplayText(LuaHandle* luaHandle);
|
static int setDisplayText(LuaHandle* luaHandle);
|
||||||
static int addConsoleText(LuaHandle* luaHandle);
|
static int addConsoleText(LuaHandle* luaHandle);
|
||||||
static int DisplayFormattedText(LuaHandle* luaHandle);
|
static int DisplayFormattedText(LuaHandle* luaHandle);
|
||||||
|
static int DisplayFormattedLangText(LuaHandle* luaHandle);
|
||||||
static int clearDisplayText(LuaHandle* luaHandle);
|
static int clearDisplayText(LuaHandle* luaHandle);
|
||||||
static int setCameraPosition(LuaHandle* luaHandle);
|
static int setCameraPosition(LuaHandle* luaHandle);
|
||||||
static int createUnit(LuaHandle* luaHandle);
|
static int createUnit(LuaHandle* luaHandle);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user