mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-25 16:46:17 +00:00
CHANGED: #1471 Moved back some more static methods from CLuaIHMRyzom to CLuaIHM, as CLuaIHM can now handle these too.
This commit is contained in:
parent
929b1c3aff
commit
79c83c421a
4 changed files with 663 additions and 656 deletions
|
@ -159,6 +159,31 @@ namespace NLGUI
|
|||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int luaMethodCall(lua_State *ls);
|
||||
|
||||
static int setOnDraw(CLuaState &ls); // params: CInterfaceGroup*, "script". return: none
|
||||
static int addOnDbChange(CLuaState &ls); // params: CInterfaceGroup*, "dblist", "script". return: none
|
||||
static int removeOnDbChange(CLuaState &ls);// params: CInterfaceGroup*. return: none
|
||||
static int setCaptureKeyboard(CLuaState &ls);
|
||||
static int resetCaptureKeyboard(CLuaState &ls);
|
||||
static int getUIId(CLuaState &ls); // params: CInterfaceElement*. return: ui id (empty if error)
|
||||
static int runAH(CLuaState &ls); // params: CInterfaceElement *, "ah", "params". return: none
|
||||
static int getWindowSize(CLuaState &ls);
|
||||
static int setTopWindow(CLuaState &ls); // set the top window
|
||||
static int getTextureSize(CLuaState &ls);
|
||||
static int disableModalWindow(CLuaState &ls);
|
||||
static int deleteUI(CLuaState &ls); // params: CInterfaceElement*.... return: none
|
||||
static int deleteReflectable(CLuaState &ls); // params: CInterfaceElement*.... return: none
|
||||
static int getCurrentWindowUnder(CLuaState &ls); // params: none. return: CInterfaceElement* (nil if none)
|
||||
static bool fileExists(const std::string &fileName);
|
||||
static int runExprAndPushResult(CLuaState &ls, const std::string &expr); // Used by runExpr and runFct
|
||||
static int runExpr(CLuaState &ls); // params: "expr". return: any of: nil,bool,string,number, RGBA, UCString
|
||||
static int runFct(CLuaState &ls); // params: "expr", param1, param2.... return: any of: nil,bool,string,number, RGBA, UCString
|
||||
static int runCommand(CLuaState &ls); // params: "command name", param1, param2 ... return true or false
|
||||
static int isUCString(CLuaState &ls);
|
||||
static int concatUCString(CLuaState &ls); // workaround for + operator that don't work in luabind for ucstrings ...
|
||||
static int concatString(CLuaState &ls); // speedup concatenation of several strings
|
||||
static int tableToString(CLuaState &ls); // concat element of a table to build a string
|
||||
static int getPathContent(CLuaState &ls);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -71,10 +71,15 @@
|
|||
#include "nel/misc/time_nl.h"
|
||||
#include "nel/misc/path.h"
|
||||
#include "nel/misc/sstring.h"
|
||||
#include "nel/misc/command.h"
|
||||
#include "nel/gui/lua_object.h"
|
||||
#include "nel/misc/polygon.h"
|
||||
#include "nel/gui/lua_manager.h"
|
||||
|
||||
#include "nel/gui/widget_manager.h"
|
||||
#include "nel/gui/action_handler.h"
|
||||
#include "nel/gui/view_renderer.h"
|
||||
#include "nel/gui/interface_expr.h"
|
||||
#include "nel/misc/debug.h"
|
||||
|
||||
// ***************************************************************************
|
||||
/*
|
||||
|
@ -757,6 +762,614 @@ namespace NLGUI
|
|||
return numResults;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::setOnDraw(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_setOnDraw)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceGroup*, "script".
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "setOnDraw", 2);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "setOnDraw() requires a UI object in param 1");
|
||||
CLuaIHM::check(ls, ls.isString(2), "setOnDraw() requires a string in param 2");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
std::string script;
|
||||
ls.toString(2, script);
|
||||
|
||||
// must be a group
|
||||
CInterfaceGroup *group= dynamic_cast<CInterfaceGroup*>(pIE);
|
||||
if(!group)
|
||||
throw ELuaIHMException("setOnDraw(): '%s' is not a group", pIE->getId().c_str());
|
||||
// Set the script to be executed at each draw
|
||||
group->setLuaScriptOnDraw(script);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::addOnDbChange(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_addOnDbChange)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceGroup*, "dblist", "script".
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "addOnDbChange", 3);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "addOnDbChange() requires a UI object in param 1");
|
||||
CLuaIHM::check(ls, ls.isString(2), "addOnDbChange() requires a string in param 2");
|
||||
CLuaIHM::check(ls, ls.isString(3), "addOnDbChange() requires a string in param 3");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
std::string dbList, script;
|
||||
ls.toString(2, dbList);
|
||||
ls.toString(3, script);
|
||||
|
||||
// must be a group
|
||||
CInterfaceGroup *group= dynamic_cast<CInterfaceGroup*>(pIE);
|
||||
if(!group)
|
||||
throw ELuaIHMException("addOnDbChange(): '%s' is not a group", pIE->getId().c_str());
|
||||
// Set the script to be executed when the given DB change
|
||||
group->addLuaScriptOnDBChange(dbList, script);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::removeOnDbChange(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_removeOnDbChange)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceGroup*, "dbList"
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "removeOnDbChange", 2);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "removeOnDbChange() requires a UI object in param 1");
|
||||
CLuaIHM::check(ls, ls.isString(2), "removeOnDbChange() requires a string in param 2");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
std::string dbList;
|
||||
ls.toString(2, dbList);
|
||||
|
||||
// must be a group
|
||||
CInterfaceGroup *group= dynamic_cast<CInterfaceGroup*>(pIE);
|
||||
if(!group)
|
||||
throw ELuaIHMException("removeOnDbChange(): '%s' is not a group", pIE->getId().c_str());
|
||||
// Remove the script to be executed when the given DB change
|
||||
group->removeLuaScriptOnDBChange(dbList);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::setCaptureKeyboard(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_setCaptureKeyboard)
|
||||
const char *funcName = "setCaptureKeyboard";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgTypeUIElement(ls, funcName, 1);
|
||||
CCtrlBase *ctrl = dynamic_cast<CCtrlBase *>( CLuaIHM::getUIOnStack(ls, 1));
|
||||
if (!ctrl)
|
||||
{
|
||||
CLuaIHM::fails(ls, "%s waits a ui control as arg 1", funcName);
|
||||
}
|
||||
CWidgetManager::getInstance()->setCaptureKeyboard(ctrl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::resetCaptureKeyboard(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_resetCaptureKeyboard)
|
||||
const char *funcName = "resetCaptureKeyboard";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 0);
|
||||
CWidgetManager::getInstance()->resetCaptureKeyboard();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::getUIId(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getUIId)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
|
||||
// params: CInterfaceElement*
|
||||
// return: "ui:interface:...". (empty if error)
|
||||
CLuaIHM::checkArgCount(ls, "getUIId", 1);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "getUIId() requires a UI object in param 1");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
|
||||
// convert to id
|
||||
if(pIE)
|
||||
ls.push(pIE->getId());
|
||||
else
|
||||
ls.push("");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::runAH(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runAH)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceElement *, "ah", "params".
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "runAH", 3);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1) || ls.isNil(1), "runAH() requires a UI object in param 1 (or Nil)");
|
||||
CLuaIHM::check(ls, ls.isString(2), "runAH() requires a string in param 2");
|
||||
CLuaIHM::check(ls, ls.isString(3), "runAH() requires a string in param 3");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
std::string ah, params;
|
||||
ls.toString(2, ah);
|
||||
ls.toString(3, params);
|
||||
|
||||
// run AH
|
||||
// The element must be ctrl (or NULL)
|
||||
CCtrlBase *ctrl= NULL;
|
||||
if(pIE)
|
||||
{
|
||||
ctrl= dynamic_cast<CCtrlBase*>(pIE);
|
||||
if(!ctrl)
|
||||
throw ELuaIHMException("runAH(): '%s' is not a ctrl", pIE->getId().c_str());
|
||||
}
|
||||
CAHManager::getInstance()->runActionHandler(ah, ctrl, params);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::getWindowSize(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getWindowSize)
|
||||
CLuaIHM::checkArgCount(ls, "getWindowSize", 0);
|
||||
uint32 w, h;
|
||||
CViewRenderer::getInstance()->getScreenSize(w, h);
|
||||
ls.push((double) w);
|
||||
ls.push((double) h);
|
||||
return 2;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::setTopWindow(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_setTopWindow)
|
||||
const char *funcName = "setTopWindow";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CInterfaceGroup *wnd = dynamic_cast<CInterfaceGroup *>( CLuaIHM::getUIOnStack(ls, 1));
|
||||
if (!wnd)
|
||||
{
|
||||
CLuaIHM::fails(ls, "%s : interface group expected as arg 1", funcName);
|
||||
}
|
||||
CWidgetManager::getInstance()->setTopWindow(wnd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaIHM::getTextureSize(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getTextureSize)
|
||||
const char *funcName = "getTextureSize";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
|
||||
std::string textureName = ls.toString(1);
|
||||
|
||||
CBitmap bitmap;
|
||||
CIFile fs(CPath::lookup(textureName).c_str());
|
||||
bitmap.load(fs);
|
||||
|
||||
ls.push((double) bitmap.getWidth());
|
||||
ls.push((double) bitmap.getHeight());
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::disableModalWindow(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_disableModalWindow)
|
||||
CLuaIHM::checkArgCount(ls, "disableModalWindow", 0);
|
||||
CWidgetManager::getInstance()->disableModalWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::deleteUI(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_deleteUI)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceElement *
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "deleteUI", 1);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "deleteUI() requires a UI object in param 1");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
if(!pIE)
|
||||
return 0;
|
||||
|
||||
// has a parent?
|
||||
CInterfaceGroup *parent= pIE->getParent();
|
||||
if(parent)
|
||||
{
|
||||
// correctly remove from parent
|
||||
parent->delElement(pIE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// just delete
|
||||
delete pIE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::deleteReflectable(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_deleteReflectable)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceElement *
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "deleteReflectable", 1);
|
||||
CLuaIHM::check(ls, CLuaIHM::isReflectableOnStack(ls, 1), "deleteReflectable() requires a reflectable C++ object in param 1");
|
||||
|
||||
// retrieve args
|
||||
CReflectableRefPtrTarget *pRPT= CLuaIHM::getReflectableOnStack(ls, 1);
|
||||
if(!pRPT)
|
||||
return 0;
|
||||
|
||||
|
||||
CInterfaceElement *pIE = dynamic_cast<CInterfaceElement *>(pRPT);
|
||||
|
||||
if (pIE)
|
||||
{
|
||||
// has a parent?
|
||||
CInterfaceGroup *parent= pIE->getParent();
|
||||
if(parent)
|
||||
{
|
||||
// correctly remove from parent
|
||||
parent->delElement(pIE);
|
||||
}
|
||||
}
|
||||
|
||||
// just delete
|
||||
delete pIE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CLuaIHM::getCurrentWindowUnder(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getCurrentWindowUnder)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
CInterfaceElement *pIE= CWidgetManager::getInstance()->getCurrentWindowUnder();
|
||||
if(!pIE)
|
||||
{
|
||||
ls.pushNil();
|
||||
nlerror("getCurrentWindowUnder(): No UICaller found. return Nil");
|
||||
}
|
||||
else
|
||||
{
|
||||
CLuaIHM::pushUIOnStack(ls, pIE);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
bool CLuaIHM::fileExists(const std::string &fileName)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_fileExists)
|
||||
return CPath::exists(fileName);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::runExprAndPushResult(CLuaState &ls, const std::string &expr)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runExprAndPushResult)
|
||||
// Execute expression
|
||||
CInterfaceExprValue value;
|
||||
if (CInterfaceExpr::eval(expr, value, NULL))
|
||||
{
|
||||
switch(value.getType())
|
||||
{
|
||||
case CInterfaceExprValue::Boolean:
|
||||
ls.push(value.getBool());
|
||||
break;
|
||||
case CInterfaceExprValue::Integer:
|
||||
ls.push((double)value.getInteger());
|
||||
break;
|
||||
case CInterfaceExprValue::Double:
|
||||
ls.push(value.getDouble());
|
||||
break;
|
||||
case CInterfaceExprValue::String:
|
||||
{
|
||||
ucstring ucstr= value.getUCString();
|
||||
// Yoyo: dynamically decide whether must return a string or a ucstring
|
||||
bool mustUseUCString= false;
|
||||
for (uint i = 0; i < ucstr.size (); i++)
|
||||
{
|
||||
if (ucstr[i] > 255)
|
||||
{
|
||||
mustUseUCString= true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// push a ucstring?
|
||||
if(mustUseUCString)
|
||||
{
|
||||
#if LUABIND_VERSION > 600
|
||||
luabind::detail::push(ls.getStatePointer(), ucstr);
|
||||
#else
|
||||
luabind::object obj(ls.getStatePointer(), ucstr);
|
||||
obj.pushvalue();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
ls.push(ucstr.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CInterfaceExprValue::RGBA:
|
||||
{
|
||||
CRGBA color = value.getRGBA();
|
||||
#if LUABIND_VERSION > 600
|
||||
luabind::detail::push(ls.getStatePointer(), color);
|
||||
#else
|
||||
luabind::object obj(ls.getStatePointer(), color);
|
||||
obj.pushvalue();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CInterfaceExprValue::UserType: // Yoyo: don't care UserType...
|
||||
default:
|
||||
ls.pushNil();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
ls.pushNil();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::runExpr(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runExpr)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
|
||||
// params: "expr".
|
||||
// return: any of: nil, bool, string, number, RGBA, UCString
|
||||
CLuaIHM::checkArgCount(ls, "runExpr", 1);
|
||||
CLuaIHM::check(ls, ls.isString(1), "runExpr() requires a string in param 1");
|
||||
|
||||
// retrieve args
|
||||
std::string expr;
|
||||
ls.toString(1, expr);
|
||||
|
||||
// run expression and push result
|
||||
return runExprAndPushResult(ls, expr);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::runFct(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runFct)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
|
||||
// params: "expr", param1, param2...
|
||||
// return: any of: nil, bool, string, number, RGBA, UCString
|
||||
CLuaIHM::checkArgMin(ls, "runFct", 1);
|
||||
CLuaIHM::check(ls, ls.isString(1), "runExpr() requires a string in param 1");
|
||||
|
||||
// retrieve fct
|
||||
std::string expr;
|
||||
ls.toString(1, expr);
|
||||
expr+= "(";
|
||||
|
||||
// retrieve params
|
||||
uint top= ls.getTop();
|
||||
for(uint i=2;i<=top;i++)
|
||||
{
|
||||
if(i>2)
|
||||
expr+= ", ";
|
||||
|
||||
// If it is a number
|
||||
if(ls.type(i)==LUA_TNUMBER)
|
||||
{
|
||||
std::string paramValue;
|
||||
ls.toString(i, paramValue); // nb: transformed to a string in the stack
|
||||
expr+= paramValue;
|
||||
}
|
||||
// else suppose a string
|
||||
else
|
||||
{
|
||||
// must enclose with "'"
|
||||
std::string paramValue;
|
||||
ls.toString(i, paramValue);
|
||||
expr+= std::string("'") + paramValue + std::string("'") ;
|
||||
}
|
||||
}
|
||||
|
||||
// end fct call
|
||||
expr+= ")";
|
||||
|
||||
|
||||
// run expression and push result
|
||||
return runExprAndPushResult(ls, expr);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::runCommand(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runCommand)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
if (ls.empty())
|
||||
{
|
||||
nlwarning("'runCommand' : Command name expected");
|
||||
ls.push(false);
|
||||
return 1;
|
||||
}
|
||||
const char *commandName = ls.toString(1);
|
||||
if (!commandName)
|
||||
{
|
||||
nlwarning("'runCommand' : Bad command name");
|
||||
ls.push(false);
|
||||
return 1;
|
||||
}
|
||||
if (!NLMISC::ICommand::LocalCommands || !NLMISC::ICommand::LocalCommands->count(ls.toString(1)))
|
||||
{
|
||||
nlwarning("'runCommand' : Command %s not found", ls.toString(1));
|
||||
ls.push(false);
|
||||
return 1;
|
||||
}
|
||||
std::string rawCommandString = ls.toString(1);
|
||||
NLMISC::ICommand *command = (*NLMISC::ICommand::LocalCommands)[ls.toString(1)];
|
||||
nlassert(command);
|
||||
std::vector<std::string> args(ls.getTop() - 1);
|
||||
for(uint k = 2; k <= (uint) ls.getTop(); ++k)
|
||||
{
|
||||
if (ls.toString(k))
|
||||
{
|
||||
args[k - 2] = ls.toString(k);
|
||||
rawCommandString += " " + std::string(ls.toString(k));
|
||||
}
|
||||
}
|
||||
|
||||
ls.push(command->execute(rawCommandString, args, NLMISC::ErrorLog(), false, true));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::isUCString(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_isUCString)
|
||||
const char *funcName = "isUCString";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
ls.push(CLuaIHM::isUCStringOnStack(ls, 1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::concatUCString(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_concatUCString)
|
||||
const char *funcName = "concatUCString";
|
||||
ucstring result;
|
||||
for (uint k = 1; k <= (uint) ls.getTop(); ++k)
|
||||
{
|
||||
//nlwarning("arg %d = %s", k, ls.getTypename(ls.type(k)));
|
||||
ucstring part;
|
||||
if (ls.isString(k))
|
||||
{
|
||||
part.fromUtf8(ls.toString(k));
|
||||
}
|
||||
else
|
||||
{
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, k);
|
||||
nlverify(CLuaIHM::getUCStringOnStack(ls, k, part));
|
||||
}
|
||||
result += part;
|
||||
}
|
||||
CLuaIHM::push(ls, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::concatString(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_concatUCString)
|
||||
const char *funcName = "concatString";
|
||||
std::string result;
|
||||
uint stackSize = ls.getTop();
|
||||
for (uint k = 1; k <= stackSize; ++k)
|
||||
{
|
||||
CLuaIHM::checkArgType(ls, funcName, k, LUA_TSTRING);
|
||||
result += ls.toString(k);
|
||||
}
|
||||
ls.push(result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHM::tableToString(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "tableToString";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TTABLE);
|
||||
uint length = 0;
|
||||
// compute size
|
||||
ls.pushNil();
|
||||
while (ls.next(-2))
|
||||
{
|
||||
ls.toString(-1);
|
||||
length += (uint)ls.strlen(-1);
|
||||
ls.pop(2);
|
||||
}
|
||||
std::string result;
|
||||
result.resize(length);
|
||||
char *dest = &result[0];
|
||||
// concatenate
|
||||
ls.pushNil();
|
||||
while (ls.next(-2))
|
||||
{
|
||||
uint length = (uint)ls.strlen(-1);
|
||||
if (length)
|
||||
{
|
||||
memcpy(dest, ls.toString(-1), length);
|
||||
}
|
||||
dest += length;
|
||||
ls.pop(2);
|
||||
}
|
||||
ls.push(result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int CLuaIHM::getPathContent(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getPathContent)
|
||||
const char *funcName = "getPathContent";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
|
||||
std::vector<std::string> files;
|
||||
NLMISC::CPath::getPathContent(ls.toString(1), false, false, true, files);
|
||||
ls.newTable();
|
||||
for(uint k = 0; k < files.size(); ++k)
|
||||
{
|
||||
ls.push((double) k);
|
||||
ls.push(files[k]);
|
||||
ls.setTable(-3);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
void CLuaIHM::luaValueFromReflectedProperty(CLuaState &ls, CReflectable &reflectedObject, const CReflectedProperty &property)
|
||||
{
|
||||
|
@ -972,6 +1585,28 @@ namespace NLGUI
|
|||
|
||||
|
||||
// *** Register Functions
|
||||
ls.registerFunc("setOnDraw", setOnDraw);
|
||||
ls.registerFunc("setCaptureKeyboard", setCaptureKeyboard);
|
||||
ls.registerFunc("resetCaptureKeyboard", resetCaptureKeyboard);
|
||||
ls.registerFunc("setTopWindow", setTopWindow);
|
||||
ls.registerFunc("addOnDbChange", addOnDbChange);
|
||||
ls.registerFunc("removeOnDbChange", removeOnDbChange);
|
||||
ls.registerFunc("getUIId", getUIId);
|
||||
ls.registerFunc("runAH", runAH);
|
||||
ls.registerFunc("deleteUI", deleteUI);
|
||||
ls.registerFunc("deleteReflectable", deleteReflectable);
|
||||
ls.registerFunc("getWindowSize", getWindowSize);
|
||||
ls.registerFunc("getTextureSize", getTextureSize);
|
||||
ls.registerFunc("disableModalWindow", disableModalWindow);
|
||||
ls.registerFunc("isUCString", isUCString);
|
||||
ls.registerFunc("concatUCString", concatUCString);
|
||||
ls.registerFunc("concatString", concatString);
|
||||
ls.registerFunc("tableToString", tableToString);
|
||||
ls.registerFunc("getCurrentWindowUnder", getCurrentWindowUnder);
|
||||
ls.registerFunc("runExpr", runExpr);
|
||||
ls.registerFunc("runFct", runFct);
|
||||
ls.registerFunc("runCommand", runCommand);
|
||||
ls.registerFunc("getPathContent", getPathContent);
|
||||
|
||||
// Through LUABind API
|
||||
lua_State *L= ls.getStatePointer();
|
||||
|
@ -990,7 +1625,8 @@ namespace NLGUI
|
|||
#endif
|
||||
|
||||
luabind::def("fileLookup", CMiscFunctions::fileLookup),
|
||||
luabind::def("shellExecute", CMiscFunctions::shellExecute)
|
||||
luabind::def("shellExecute", CMiscFunctions::shellExecute),
|
||||
LUABIND_FUNC(fileExists)
|
||||
];
|
||||
|
||||
// inside i18n table
|
||||
|
|
|
@ -362,55 +362,33 @@ void CLuaIHMRyzom::RegisterRyzomFunctions( NLGUI::CLuaState &ls )
|
|||
globals.setNil("__cfmt"); // remove temp metatable
|
||||
|
||||
ls.registerFunc( "getUI", getUI );
|
||||
ls.registerFunc("setOnDraw", setOnDraw);
|
||||
ls.registerFunc("setCaptureKeyboard", setCaptureKeyboard);
|
||||
ls.registerFunc("resetCaptureKeyboard", resetCaptureKeyboard);
|
||||
ls.registerFunc("validMessageBox", validMessageBox);
|
||||
ls.registerFunc("setTopWindow", setTopWindow);
|
||||
ls.registerFunc("concatUCString", concatUCString);
|
||||
ls.registerFunc("concatString", concatString);
|
||||
ls.registerFunc("tableToString", tableToString);
|
||||
ls.registerFunc("addOnDbChange", addOnDbChange);
|
||||
ls.registerFunc("removeOnDbChange", removeOnDbChange);
|
||||
ls.registerFunc("getUICaller", getUICaller);
|
||||
ls.registerFunc("getCurrentWindowUnder", getCurrentWindowUnder);
|
||||
ls.registerFunc("getUI", getUI);
|
||||
ls.registerFunc("getIndexInDB", getIndexInDB);
|
||||
ls.registerFunc("getUIId", getUIId);
|
||||
ls.registerFunc("createGroupInstance", createGroupInstance);
|
||||
ls.registerFunc("createRootGroupInstance", createRootGroupInstance);
|
||||
ls.registerFunc("createUIElement", createUIElement);
|
||||
ls.registerFunc("launchContextMenuInGame", launchContextMenuInGame);
|
||||
ls.registerFunc("parseInterfaceFromString", parseInterfaceFromString);
|
||||
ls.registerFunc("updateAllLocalisedElements", updateAllLocalisedElements);
|
||||
ls.registerFunc("runAH", runAH);
|
||||
ls.registerFunc("runExpr", runExpr);
|
||||
ls.registerFunc("runFct", runFct);
|
||||
ls.registerFunc("runCommand", runCommand);
|
||||
ls.registerFunc("formatUI", formatUI);
|
||||
ls.registerFunc("formatDB", formatDB);
|
||||
ls.registerFunc("deleteUI", deleteUI);
|
||||
ls.registerFunc("deleteReflectable", deleteReflectable);
|
||||
ls.registerFunc("dumpUI", dumpUI);
|
||||
ls.registerFunc("setKeyboardContext", setKeyboardContext);
|
||||
ls.registerFunc("breakPoint", breakPoint);
|
||||
ls.registerFunc("getWindowSize", getWindowSize);
|
||||
ls.registerFunc("setTextFormatTaged", setTextFormatTaged);
|
||||
ls.registerFunc("initEmotesMenu", initEmotesMenu);
|
||||
ls.registerFunc("isUCString", isUCString);
|
||||
ls.registerFunc("hideAllWindows", hideAllWindows);
|
||||
ls.registerFunc("hideAllNonSavableWindows", hideAllNonSavableWindows);
|
||||
ls.registerFunc("getDesktopIndex", getDesktopIndex);
|
||||
ls.registerFunc("setLuaBreakPoint", setLuaBreakPoint);
|
||||
ls.registerFunc("getMainPageURL", getMainPageURL);
|
||||
ls.registerFunc("getCharSlot", getCharSlot);
|
||||
ls.registerFunc("getPathContent", getPathContent);
|
||||
ls.registerFunc("getServerSeason", getServerSeason);
|
||||
ls.registerFunc("computeCurrSeason", computeCurrSeason);
|
||||
ls.registerFunc("getAutoSeason", getAutoSeason);
|
||||
ls.registerFunc("getTextureSize", getTextureSize);
|
||||
ls.registerFunc("enableModalWindow", enableModalWindow);
|
||||
ls.registerFunc("disableModalWindow", disableModalWindow);
|
||||
ls.registerFunc("getPlayerPos", getPlayerPos);
|
||||
ls.registerFunc("getPlayerFront", getPlayerFront);
|
||||
ls.registerFunc("getPlayerDirection", getPlayerDirection);
|
||||
|
@ -497,7 +475,6 @@ void CLuaIHMRyzom::RegisterRyzomFunctions( NLGUI::CLuaState &ls )
|
|||
LUABIND_FUNC(getFirstTribeFameIndex),
|
||||
LUABIND_FUNC(getNbTribeFameIndex),
|
||||
LUABIND_FUNC(getClientCfg),
|
||||
LUABIND_FUNC(fileExists),
|
||||
LUABIND_FUNC(sendMsgToServer),
|
||||
LUABIND_FUNC(sendMsgToServerPvpTag),
|
||||
LUABIND_FUNC(isGuildQuitAvailable),
|
||||
|
@ -611,260 +588,6 @@ int CLuaIHMRyzom::getUI(CLuaState &ls)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::setCaptureKeyboard(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_setCaptureKeyboard)
|
||||
const char *funcName = "setCaptureKeyboard";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgTypeUIElement(ls, funcName, 1);
|
||||
CCtrlBase *ctrl = dynamic_cast<CCtrlBase *>( CLuaIHM::getUIOnStack(ls, 1));
|
||||
if (!ctrl)
|
||||
{
|
||||
CLuaIHM::fails(ls, "%s waits a ui control as arg 1", funcName);
|
||||
}
|
||||
CInterfaceManager *im = CInterfaceManager::getInstance();
|
||||
CWidgetManager::getInstance()->setCaptureKeyboard(ctrl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::resetCaptureKeyboard(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_resetCaptureKeyboard)
|
||||
const char *funcName = "resetCaptureKeyboard";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 0);
|
||||
CInterfaceManager *im = CInterfaceManager::getInstance();
|
||||
CWidgetManager::getInstance()->resetCaptureKeyboard();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::setOnDraw(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_setOnDraw)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceGroup*, "script".
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "setOnDraw", 2);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "setOnDraw() requires a UI object in param 1");
|
||||
CLuaIHM::check(ls, ls.isString(2), "setOnDraw() requires a string in param 2");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
std::string script;
|
||||
ls.toString(2, script);
|
||||
|
||||
// must be a group
|
||||
CInterfaceGroup *group= dynamic_cast<CInterfaceGroup*>(pIE);
|
||||
if(!group)
|
||||
throw ELuaIHMException("setOnDraw(): '%s' is not a group", pIE->getId().c_str());
|
||||
// Set the script to be executed at each draw
|
||||
group->setLuaScriptOnDraw(script);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::addOnDbChange(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_addOnDbChange)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceGroup*, "dblist", "script".
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "addOnDbChange", 3);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "addOnDbChange() requires a UI object in param 1");
|
||||
CLuaIHM::check(ls, ls.isString(2), "addOnDbChange() requires a string in param 2");
|
||||
CLuaIHM::check(ls, ls.isString(3), "addOnDbChange() requires a string in param 3");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
std::string dbList, script;
|
||||
ls.toString(2, dbList);
|
||||
ls.toString(3, script);
|
||||
|
||||
// must be a group
|
||||
CInterfaceGroup *group= dynamic_cast<CInterfaceGroup*>(pIE);
|
||||
if(!group)
|
||||
throw ELuaIHMException("addOnDbChange(): '%s' is not a group", pIE->getId().c_str());
|
||||
// Set the script to be executed when the given DB change
|
||||
group->addLuaScriptOnDBChange(dbList, script);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::removeOnDbChange(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_removeOnDbChange)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceGroup*, "dbList"
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "removeOnDbChange", 2);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "removeOnDbChange() requires a UI object in param 1");
|
||||
CLuaIHM::check(ls, ls.isString(2), "removeOnDbChange() requires a string in param 2");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
std::string dbList;
|
||||
ls.toString(2, dbList);
|
||||
|
||||
// must be a group
|
||||
CInterfaceGroup *group= dynamic_cast<CInterfaceGroup*>(pIE);
|
||||
if(!group)
|
||||
throw ELuaIHMException("removeOnDbChange(): '%s' is not a group", pIE->getId().c_str());
|
||||
// Remove the script to be executed when the given DB change
|
||||
group->removeLuaScriptOnDBChange(dbList);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::runAH(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runAH)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceElement *, "ah", "params".
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "runAH", 3);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1) || ls.isNil(1), "runAH() requires a UI object in param 1 (or Nil)");
|
||||
CLuaIHM::check(ls, ls.isString(2), "runAH() requires a string in param 2");
|
||||
CLuaIHM::check(ls, ls.isString(3), "runAH() requires a string in param 3");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
std::string ah, params;
|
||||
ls.toString(2, ah);
|
||||
ls.toString(3, params);
|
||||
|
||||
// run AH
|
||||
CInterfaceManager *pIM= CInterfaceManager::getInstance();
|
||||
// The element must be ctrl (or NULL)
|
||||
CCtrlBase *ctrl= NULL;
|
||||
if(pIE)
|
||||
{
|
||||
ctrl= dynamic_cast<CCtrlBase*>(pIE);
|
||||
if(!ctrl)
|
||||
throw ELuaIHMException("runAH(): '%s' is not a ctrl", pIE->getId().c_str());
|
||||
}
|
||||
CAHManager::getInstance()->runActionHandler(ah, ctrl, params);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::runExpr(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runExpr)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
|
||||
// params: "expr".
|
||||
// return: any of: nil, bool, string, number, RGBA, UCString
|
||||
CLuaIHM::checkArgCount(ls, "runExpr", 1);
|
||||
CLuaIHM::check(ls, ls.isString(1), "runExpr() requires a string in param 1");
|
||||
|
||||
// retrieve args
|
||||
std::string expr;
|
||||
ls.toString(1, expr);
|
||||
|
||||
// run expression and push result
|
||||
return runExprAndPushResult(ls, expr);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::runFct(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runFct)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
|
||||
// params: "expr", param1, param2...
|
||||
// return: any of: nil, bool, string, number, RGBA, UCString
|
||||
CLuaIHM::checkArgMin(ls, "runFct", 1);
|
||||
CLuaIHM::check(ls, ls.isString(1), "runExpr() requires a string in param 1");
|
||||
|
||||
// retrieve fct
|
||||
std::string expr;
|
||||
ls.toString(1, expr);
|
||||
expr+= "(";
|
||||
|
||||
// retrieve params
|
||||
uint top= ls.getTop();
|
||||
for(uint i=2;i<=top;i++)
|
||||
{
|
||||
if(i>2)
|
||||
expr+= ", ";
|
||||
|
||||
// If it is a number
|
||||
if(ls.type(i)==LUA_TNUMBER)
|
||||
{
|
||||
std::string paramValue;
|
||||
ls.toString(i, paramValue); // nb: transformed to a string in the stack
|
||||
expr+= paramValue;
|
||||
}
|
||||
// else suppose a string
|
||||
else
|
||||
{
|
||||
// must enclose with "'"
|
||||
std::string paramValue;
|
||||
ls.toString(i, paramValue);
|
||||
expr+= std::string("'") + paramValue + std::string("'") ;
|
||||
}
|
||||
}
|
||||
|
||||
// end fct call
|
||||
expr+= ")";
|
||||
|
||||
|
||||
// run expression and push result
|
||||
return runExprAndPushResult(ls, expr);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::runCommand(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runCommand)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
if (ls.empty())
|
||||
{
|
||||
nlwarning("'runCommand' : Command name expected");
|
||||
ls.push(false);
|
||||
return 1;
|
||||
}
|
||||
const char *commandName = ls.toString(1);
|
||||
if (!commandName)
|
||||
{
|
||||
nlwarning("'runCommand' : Bad command name");
|
||||
ls.push(false);
|
||||
return 1;
|
||||
}
|
||||
if (!NLMISC::ICommand::LocalCommands || !NLMISC::ICommand::LocalCommands->count(ls.toString(1)))
|
||||
{
|
||||
nlwarning("'runCommand' : Command %s not found", ls.toString(1));
|
||||
ls.push(false);
|
||||
return 1;
|
||||
}
|
||||
std::string rawCommandString = ls.toString(1);
|
||||
NLMISC::ICommand *command = (*NLMISC::ICommand::LocalCommands)[ls.toString(1)];
|
||||
nlassert(command);
|
||||
std::vector<std::string> args(ls.getTop() - 1);
|
||||
for(uint k = 2; k <= (uint) ls.getTop(); ++k)
|
||||
{
|
||||
if (ls.toString(k))
|
||||
{
|
||||
args[k - 2] = ls.toString(k);
|
||||
rawCommandString += " " + std::string(ls.toString(k));
|
||||
}
|
||||
}
|
||||
|
||||
ls.push(command->execute(rawCommandString, args, g_log, false, true));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::formatUI(CLuaState &ls)
|
||||
|
@ -939,74 +662,6 @@ int CLuaIHMRyzom::formatDB(CLuaState &ls)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::deleteUI(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_deleteUI)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceElement *
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "deleteUI", 1);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "deleteUI() requires a UI object in param 1");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
if(!pIE)
|
||||
return 0;
|
||||
|
||||
// has a parent?
|
||||
CInterfaceGroup *parent= pIE->getParent();
|
||||
if(parent)
|
||||
{
|
||||
// correctly remove from parent
|
||||
parent->delElement(pIE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// just delete
|
||||
delete pIE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::deleteReflectable(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_deleteReflectable)
|
||||
CLuaStackChecker lsc(&ls, 0);
|
||||
|
||||
// params: CInterfaceElement *
|
||||
// return: none
|
||||
CLuaIHM::checkArgCount(ls, "deleteReflectable", 1);
|
||||
CLuaIHM::check(ls, CLuaIHM::isReflectableOnStack(ls, 1), "deleteReflectable() requires a reflectable C++ object in param 1");
|
||||
|
||||
// retrieve args
|
||||
CReflectableRefPtrTarget *pRPT= CLuaIHM::getReflectableOnStack(ls, 1);
|
||||
if(!pRPT)
|
||||
return 0;
|
||||
|
||||
|
||||
CInterfaceElement *pIE = dynamic_cast<CInterfaceElement *>(pRPT);
|
||||
|
||||
if (pIE)
|
||||
{
|
||||
// has a parent?
|
||||
CInterfaceGroup *parent= pIE->getParent();
|
||||
if(parent)
|
||||
{
|
||||
// correctly remove from parent
|
||||
parent->delElement(pIE);
|
||||
}
|
||||
}
|
||||
|
||||
// just delete
|
||||
delete pIE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::dumpUI(CLuaState &ls)
|
||||
{
|
||||
|
@ -1066,97 +721,6 @@ int CLuaIHMRyzom::validMessageBox(CLuaState &ls)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::setTopWindow(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_setTopWindow)
|
||||
const char *funcName = "setTopWindow";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CInterfaceGroup *wnd = dynamic_cast<CInterfaceGroup *>( CLuaIHM::getUIOnStack(ls, 1));
|
||||
if (!wnd)
|
||||
{
|
||||
CLuaIHM::fails(ls, "%s : interface group expected as arg 1", funcName);
|
||||
}
|
||||
CInterfaceManager *im = CInterfaceManager::getInstance();
|
||||
CWidgetManager::getInstance()->setTopWindow(wnd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::concatUCString(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_concatUCString)
|
||||
const char *funcName = "concatUCString";
|
||||
ucstring result;
|
||||
for (uint k = 1; k <= (uint) ls.getTop(); ++k)
|
||||
{
|
||||
//nlwarning("arg %d = %s", k, ls.getTypename(ls.type(k)));
|
||||
ucstring part;
|
||||
if (ls.isString(k))
|
||||
{
|
||||
part.fromUtf8(ls.toString(k));
|
||||
}
|
||||
else
|
||||
{
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, k);
|
||||
nlverify(CLuaIHM::getUCStringOnStack(ls, k, part));
|
||||
}
|
||||
result += part;
|
||||
}
|
||||
CLuaIHM::push(ls, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::concatString(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_concatUCString)
|
||||
const char *funcName = "concatString";
|
||||
std::string result;
|
||||
uint stackSize = ls.getTop();
|
||||
for (uint k = 1; k <= stackSize; ++k)
|
||||
{
|
||||
CLuaIHM::checkArgType(ls, funcName, k, LUA_TSTRING);
|
||||
result += ls.toString(k);
|
||||
}
|
||||
ls.push(result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::tableToString(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "tableToString";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TTABLE);
|
||||
uint length = 0;
|
||||
// compute size
|
||||
ls.pushNil();
|
||||
while (ls.next(-2))
|
||||
{
|
||||
ls.toString(-1);
|
||||
length += (uint)ls.strlen(-1);
|
||||
ls.pop(2);
|
||||
}
|
||||
std::string result;
|
||||
result.resize(length);
|
||||
char *dest = &result[0];
|
||||
// concatenate
|
||||
ls.pushNil();
|
||||
while (ls.next(-2))
|
||||
{
|
||||
uint length = (uint)ls.strlen(-1);
|
||||
if (length)
|
||||
{
|
||||
memcpy(dest, ls.toString(-1), length);
|
||||
}
|
||||
dest += length;
|
||||
ls.pop(2);
|
||||
}
|
||||
ls.push(result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::breakPoint(CLuaState &ls)
|
||||
{
|
||||
|
@ -1174,21 +738,6 @@ int CLuaIHMRyzom::breakPoint(CLuaState &ls)
|
|||
}
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::getWindowSize(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getWindowSize)
|
||||
CLuaIHM::checkArgCount(ls, "getWindowSize", 0);
|
||||
CInterfaceManager *pIM= CInterfaceManager::getInstance();
|
||||
uint32 w, h;
|
||||
CViewRenderer::getInstance()->getScreenSize(w, h);
|
||||
ls.push((double) w);
|
||||
ls.push((double) h);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::setTextFormatTaged(CLuaState &ls)
|
||||
{
|
||||
|
@ -1412,16 +961,6 @@ int CLuaIHMRyzom::initEmotesMenu(CLuaState &ls)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::isUCString(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_isUCString)
|
||||
const char *funcName = "isUCString";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
ls.push(CLuaIHM::isUCStringOnStack(ls, 1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::hideAllWindows(CLuaState &/* ls */)
|
||||
{
|
||||
|
@ -1486,25 +1025,6 @@ int CLuaIHMRyzom::getCharSlot(CLuaState &ls)
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int CLuaIHMRyzom::getPathContent(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getPathContent)
|
||||
const char *funcName = "getPathContent";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
|
||||
std::vector<std::string> files;
|
||||
NLMISC::CPath::getPathContent(ls.toString(1), false, false, true, files);
|
||||
ls.newTable();
|
||||
for(uint k = 0; k < files.size(); ++k)
|
||||
{
|
||||
ls.push((double) k);
|
||||
ls.push(files[k]);
|
||||
ls.setTable(-3);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CLuaIHMRyzom::getServerSeason(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getServerSeason)
|
||||
|
@ -1533,27 +1053,6 @@ int CLuaIHMRyzom::getAutoSeason(CLuaState &ls)
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int CLuaIHMRyzom::getTextureSize(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getTextureSize)
|
||||
const char *funcName = "getTextureSize";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING);
|
||||
std::string textureName = ls.toString(1);
|
||||
|
||||
CBitmap bitmap;
|
||||
CIFile fs(CPath::lookup(textureName).c_str());
|
||||
bitmap.load(fs);
|
||||
|
||||
ls.push((double) bitmap.getWidth());
|
||||
ls.push((double) bitmap.getHeight());
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
int CLuaIHMRyzom::enableModalWindow(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_enableModalWindow)
|
||||
|
@ -1592,16 +1091,6 @@ int CLuaIHMRyzom::enableModalWindow(CLuaState &ls)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::disableModalWindow(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_disableModalWindow)
|
||||
CLuaIHM::checkArgCount(ls, "disableModalWindow", 0);
|
||||
CInterfaceManager *pIM= CInterfaceManager::getInstance();
|
||||
CWidgetManager::getInstance()->disableModalWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::getPlayerPos(CLuaState &ls)
|
||||
{
|
||||
|
@ -1988,47 +1477,6 @@ int CLuaIHMRyzom::getUICaller(CLuaState &ls)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int CLuaIHMRyzom::getCurrentWindowUnder(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getCurrentWindowUnder)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
CInterfaceManager *im = CInterfaceManager::getInstance();
|
||||
CInterfaceElement *pIE= CWidgetManager::getInstance()->getCurrentWindowUnder();
|
||||
if(!pIE)
|
||||
{
|
||||
ls.pushNil();
|
||||
debugInfo(toString("getCurrentWindowUnder(): No UICaller found. return Nil"));
|
||||
}
|
||||
else
|
||||
{
|
||||
CLuaIHM::pushUIOnStack(ls, pIE);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::getUIId(CLuaState &ls)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_getUIId)
|
||||
CLuaStackChecker lsc(&ls, 1);
|
||||
|
||||
// params: CInterfaceElement*
|
||||
// return: "ui:interface:...". (empty if error)
|
||||
CLuaIHM::checkArgCount(ls, "getUIId", 1);
|
||||
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "getUIId() requires a UI object in param 1");
|
||||
|
||||
// retrieve args
|
||||
CInterfaceElement *pIE= CLuaIHM::getUIOnStack(ls, 1);
|
||||
|
||||
// convert to id
|
||||
if(pIE)
|
||||
ls.push(pIE->getId());
|
||||
else
|
||||
ls.push("");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::getIndexInDB(CLuaState &ls)
|
||||
{
|
||||
|
@ -3009,13 +2457,6 @@ string CLuaIHMRyzom::getClientCfg(const string &varName)
|
|||
return ClientCfg.readString(varName);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
bool CLuaIHMRyzom::fileExists(const string &fileName)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_fileExists)
|
||||
return CPath::exists(fileName);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CLuaIHMRyzom::sendMsgToServer(const std::string &sMsg)
|
||||
{
|
||||
|
@ -3438,74 +2879,4 @@ std::string CLuaIHMRyzom::createGotoFileButtonTag(const char *fileName, uint lin
|
|||
return "";
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CLuaIHMRyzom::runExprAndPushResult(CLuaState &ls, const std::string &expr)
|
||||
{
|
||||
//H_AUTO(Lua_CLuaIHM_runExprAndPushResult)
|
||||
// Execute expression
|
||||
CInterfaceExprValue value;
|
||||
if (CInterfaceExpr::eval(expr, value, NULL))
|
||||
{
|
||||
switch(value.getType())
|
||||
{
|
||||
case CInterfaceExprValue::Boolean:
|
||||
ls.push(value.getBool());
|
||||
break;
|
||||
case CInterfaceExprValue::Integer:
|
||||
ls.push((double)value.getInteger());
|
||||
break;
|
||||
case CInterfaceExprValue::Double:
|
||||
ls.push(value.getDouble());
|
||||
break;
|
||||
case CInterfaceExprValue::String:
|
||||
{
|
||||
ucstring ucstr= value.getUCString();
|
||||
// Yoyo: dynamically decide whether must return a string or a ucstring
|
||||
bool mustUseUCString= false;
|
||||
for (uint i = 0; i < ucstr.size (); i++)
|
||||
{
|
||||
if (ucstr[i] > 255)
|
||||
{
|
||||
mustUseUCString= true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// push a ucstring?
|
||||
if(mustUseUCString)
|
||||
{
|
||||
#if LUABIND_VERSION > 600
|
||||
luabind::detail::push(ls.getStatePointer(), ucstr);
|
||||
#else
|
||||
luabind::object obj(ls.getStatePointer(), ucstr);
|
||||
obj.pushvalue();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
ls.push(ucstr.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CInterfaceExprValue::RGBA:
|
||||
{
|
||||
CRGBA color = value.getRGBA();
|
||||
#if LUABIND_VERSION > 600
|
||||
luabind::detail::push(ls.getStatePointer(), color);
|
||||
#else
|
||||
luabind::object obj(ls.getStatePointer(), color);
|
||||
obj.pushvalue();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CInterfaceExprValue::UserType: // Yoyo: don't care UserType...
|
||||
default:
|
||||
ls.pushNil();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
ls.pushNil();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -23,13 +23,7 @@ private:
|
|||
|
||||
static int getUI(CLuaState &ls); // params: "ui:interface:...". return: CInterfaceElement* (nil if error), an additionnal boolean parameter
|
||||
// LUA exported Functions with standard lua (because use ui object, use variable param number, or return dynamic-typed object)
|
||||
static int setCaptureKeyboard(CLuaState &ls);
|
||||
static int resetCaptureKeyboard(CLuaState &ls);
|
||||
static int setOnDraw(CLuaState &ls); // params: CInterfaceGroup*, "script". return: none
|
||||
static int addOnDbChange(CLuaState &ls); // params: CInterfaceGroup*, "dblist", "script". return: none
|
||||
static int removeOnDbChange(CLuaState &ls);// params: CInterfaceGroup*. return: none
|
||||
static int getUICaller(CLuaState &ls); // params: none. return: CInterfaceElement* (nil if error)
|
||||
static int getCurrentWindowUnder(CLuaState &ls); // params: none. return: CInterfaceElement* (nil if none)
|
||||
// can specify verbose display when the element is note found (default is true)
|
||||
static int createGroupInstance(CLuaState &ls); // params : param 1 = template name,
|
||||
// param 2 = id of parent where the instance will be inserted
|
||||
|
@ -49,27 +43,16 @@ private:
|
|||
// param 3 = table with all strings and urls
|
||||
// {"main text"="http:///", "text option 1"="http:///", "text option 2"="http:///") etc...
|
||||
static int getIndexInDB(CLuaState &ls); // params: CDBCtrlSheet*.... return: index, or 0 if error
|
||||
static int getUIId(CLuaState &ls); // params: CInterfaceElement*. return: ui id (empty if error)
|
||||
static int runAH(CLuaState &ls); // params: CInterfaceElement *, "ah", "params". return: none
|
||||
static int runExpr(CLuaState &ls); // params: "expr". return: any of: nil,bool,string,number, RGBA, UCString
|
||||
static int runFct(CLuaState &ls); // params: "expr", param1, param2.... return: any of: nil,bool,string,number, RGBA, UCString
|
||||
static int runCommand(CLuaState &ls); // params: "command name", param1, param2 ... return true or false
|
||||
static int formatUI(CLuaState &ls); // params: "expr", param1, param2.... return: string with # and % parsed
|
||||
static int formatDB(CLuaState &ls); // params: param1, param2.... return: string with @ and , added
|
||||
static int launchContextMenuInGame(CLuaState &ls); // params : menu name
|
||||
static int parseInterfaceFromString(CLuaState &ls); // params : intreface script
|
||||
static int updateAllLocalisedElements(CLuaState &ls);
|
||||
static int breakPoint(CLuaState &ls);
|
||||
static int getWindowSize(CLuaState &ls);
|
||||
static int i18n(CLuaState &ls); // retrieve an unicode string from CI18N
|
||||
static int setTextFormatTaged(CLuaState &ls); // set a text that may contains Tag Format infos
|
||||
static int validMessageBox(CLuaState &ls); // ok/cancel type message box (can't get it to work through luabind)
|
||||
static int concatUCString(CLuaState &ls); // workaround for + operator that don't work in luabind for ucstrings ...
|
||||
static int concatString(CLuaState &ls); // speedup concatenation of several strings
|
||||
static int tableToString(CLuaState &ls); // concat element of a table to build a string
|
||||
static int setTopWindow(CLuaState &ls); // set the top window
|
||||
static int initEmotesMenu(CLuaState &ls);
|
||||
static int isUCString(CLuaState &ls);
|
||||
static int hideAllWindows(CLuaState &ls);
|
||||
static int hideAllNonSavableWindows(CLuaState &ls);
|
||||
static int getDesktopIndex(CLuaState &ls);
|
||||
|
@ -81,7 +64,6 @@ private:
|
|||
static int getWeatherValue(CLuaState &ls); // get current real weather value (blend between server driven value & predicted value). Manual weather value is ignored
|
||||
static int disableContextHelpForControl(CLuaState &ls); // params: CCtrlBase*. return: none
|
||||
static int disableContextHelp(CLuaState &ls);
|
||||
static int getPathContent(CLuaState &ls);
|
||||
static int getServerSeason(CLuaState &ls); // get the last season sent by the server
|
||||
// 0->auto, computed locally from the current day (or not received from server yet)
|
||||
// 1->server force spring
|
||||
|
@ -92,9 +74,7 @@ private:
|
|||
static int getAutoSeason(CLuaState &ls); // compute automatic season that would be at this time (1->spring, etc .)
|
||||
|
||||
|
||||
static int getTextureSize(CLuaState &ls);
|
||||
static int enableModalWindow(CLuaState &ls);
|
||||
static int disableModalWindow(CLuaState &ls);
|
||||
static int getPlayerPos(CLuaState &ls);
|
||||
static int getPlayerFront(CLuaState &ls);
|
||||
static int getPlayerDirection(CLuaState &ls);
|
||||
|
@ -120,8 +100,6 @@ private:
|
|||
static int getSlotDataSetId(CLuaState &ls);
|
||||
|
||||
// LUA functions exported for Dev only (debug)
|
||||
static int deleteUI(CLuaState &ls); // params: CInterfaceElement*.... return: none
|
||||
static int deleteReflectable(CLuaState &ls); // params: CInterfaceElement*.... return: none
|
||||
static int dumpUI(CLuaState &ls); // params: CInterfaceElement*.... return: none
|
||||
static int setKeyboardContext(CLuaState &ls);
|
||||
|
||||
|
@ -206,7 +184,6 @@ private:
|
|||
static sint32 getFirstTribeFameIndex(); // fame index of the 1st tribe
|
||||
static sint32 getNbTribeFameIndex(); // number of tribe fame index (which are contiguous)
|
||||
static std::string getClientCfg(const std::string &varName);
|
||||
static bool fileExists(const std::string &fileName);
|
||||
static void sendMsgToServer(const std::string &msgName);
|
||||
static void sendMsgToServerPvpTag(bool pvpTag);
|
||||
static bool isGuildQuitAvailable();
|
||||
|
@ -260,8 +237,6 @@ public:
|
|||
// Requires that 'ClientCfg.LuaDebugInfoGotoButtonEnabled' is set to 1, else
|
||||
// a, empty tag is returned
|
||||
static std::string createGotoFileButtonTag(const char *fileName, uint line);
|
||||
|
||||
static int runExprAndPushResult(CLuaState &ls, const std::string &expr); // Used by runExpr and runFct
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue