Merge with lua

--HG--
branch : atys
hg/atys
Inky 5 years ago
commit cc3a609b01

@ -321,6 +321,8 @@ namespace NLGUI
void deleteLUAEnvTable(bool recurse = false);
// Set the LUA script to execute at checkCoords time (empty to reset)
void setLuaScriptOnDraw(const std::string &script);
// Get the LUA script executed at checkCoords time
inline CStringShared getLuaScriptOnDraw() { return _LUAOnDraw; }
//
void executeLuaScriptOnDraw();
// Set the LUA script to execute when a list of DB change (of forms: "@DB1,@DB2" ....). The dbList is the key

@ -161,6 +161,7 @@ namespace NLGUI
static int luaMethodCall(lua_State *ls);
static int setOnDraw(CLuaState &ls); // params: CInterfaceGroup*, "script". return: none
static int getOnDraw(CLuaState &ls); // params: CInterfaceGroup*. return: "script" (nil if 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);

@ -794,6 +794,35 @@ namespace NLGUI
return 0;
}
// ***************************************************************************
int CLuaIHM::getOnDraw(CLuaState &ls)
{
//H_AUTO(Lua_CLuaIHM_getOnDraw
CLuaStackChecker lsc(&ls, 1);
// params: CInterfaceElement*.
// return: "script" (nil if empty)
CLuaIHM::checkArgCount(ls, "getOnDraw", 1);
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), "getOnDraw() requires a UI object in param 1");
// retrieve arguments
CInterfaceElement *pIE = CLuaIHM::getUIOnStack(ls, 1);
if (pIE)
{
// must be a group
CInterfaceGroup *group = dynamic_cast<CInterfaceGroup*>(pIE);
if (group)
{
if (!group->getLuaScriptOnDraw().empty()) {
ls.push(group->getLuaScriptOnDraw());
return 1;
}
}
}
ls.pushNil();
return 1;
}
// ***************************************************************************
int CLuaIHM::addOnDbChange(CLuaState &ls)
{
@ -1589,6 +1618,7 @@ namespace NLGUI
// *** Register Functions
ls.registerFunc("setOnDraw", setOnDraw);
ls.registerFunc("getOnDraw", getOnDraw);
ls.registerFunc("setCaptureKeyboard", setCaptureKeyboard);
ls.registerFunc("resetCaptureKeyboard", resetCaptureKeyboard);
ls.registerFunc("setTopWindow", setTopWindow);

@ -497,6 +497,7 @@ void CLuaIHMRyzom::RegisterRyzomFunctions(NLGUI::CLuaState &ls)
ls.registerFunc("saveUserChannels", saveUserChannels);
ls.registerFunc("readUserChannels", readUserChannels);
ls.registerFunc("getMaxDynChan", getMaxDynChan);
ls.registerFunc("scrollElement", scrollElement);
lua_State *L = ls.getStatePointer();
@ -3292,6 +3293,7 @@ void CLuaIHMRyzom::browseNpcWebPage(const std::string &htmlId, const std::string
groupHtml->setTimeout((float)std::max(0.0, timeout));
// Browse the url
groupHtml->clean();
groupHtml->browse(url.c_str());
// Set top of the page
CCtrlScroll *pScroll = groupHtml->getScrollBar();
@ -4013,7 +4015,7 @@ int CLuaIHMRyzom::setArkPowoOptions(CLuaState &ls)
// ***************************************************************************
int CLuaIHMRyzom::readUserChannels(CLuaState &ls)
{
std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
try
{
CIFile fd;
@ -4024,37 +4026,43 @@ int CLuaIHMRyzom::readUserChannels(CLuaState &ls)
xmlKeepBlanksDefault(0);
xmlNodePtr root = stream.getRootNode();
if (!root)
return 0;
if (!root) return 0;
CXMLAutoPtr prop;
// table
ls.newTable();
CLuaObject output(ls);
uint nb = 0;
std::vector< string > tags;
// allowed tags
tags.push_back("id");
tags.push_back("name");
tags.push_back("rgba");
tags.push_back("passwd");
xmlNodePtr node = root->children;
uint nb = 0;
while (node)
{
prop = xmlGetProp(node, (xmlChar*)"name");
if (!prop)
return 0;
std::string name = (const char*)prop;
ls.newTable();
CLuaObject nodeTable(ls);
prop = xmlGetProp(node, (xmlChar*)"passwd");
if (!prop)
return 0;
std::string pass = (const char*)prop;
for (uint i = 0; i < tags.size(); i++)
{
prop = xmlGetProp(node, (xmlChar*)tags[i].c_str());
if (!prop) return 0;
output.setValue(name.c_str(), pass.c_str());
nodeTable.setValue(tags[i].c_str(), (const char *)prop);
}
output.setValue(toString("%i", nb).c_str(), nodeTable);
node = node->next;
nb++;
}
output.push();
// no exception
fd.close();
// release lua table
output.push();
}
nlinfo("parse %s", filename.c_str());
}
@ -4084,7 +4092,7 @@ int CLuaIHMRyzom::saveUserChannels(CLuaState &ls)
CLuaObject params;
params.pop(ls);
std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
const std::string filename = CInterfaceManager::getInstance()->getSaveFileName("channels", "xml");
try
{
COFile fd;
@ -4097,27 +4105,38 @@ int CLuaIHMRyzom::saveUserChannels(CLuaState &ls)
xmlNodePtr node = xmlNewDocNode(doc, NULL, (const xmlChar*)"interface_config", NULL);
xmlDocSetRootElement(doc, node);
std::string key, value;
ENUM_LUA_TABLE(params, it)
{
if (!it.nextKey().isString())
continue;
if (!it.nextValue().isString())
continue;
if (it.nextKey().type() == LUA_TSTRING)
{
xmlNodePtr newNode = xmlNewChild(node, NULL, (const xmlChar*)"channels", NULL);
if (it.nextValue().type() == LUA_TTABLE)
{
xmlSetProp(newNode, (const xmlChar*)"id", (const xmlChar*)it.nextKey().toString().c_str());
ENUM_LUA_TABLE(it.nextValue(), itt)
{
if (!itt.nextKey().isString())
continue;
if (!itt.nextValue().isString())
continue;
std::string name = it.nextKey().toString();
std::string pass = it.nextValue().toString();
key = itt.nextKey().toString();
value = itt.nextValue().toString();
xmlNodePtr newNode = xmlNewChild(node, NULL, (const xmlChar*)"channels", NULL);
xmlSetProp(newNode, (const xmlChar*)"name", (const xmlChar*)name.c_str());
xmlSetProp(newNode, (const xmlChar*)"passwd", (const xmlChar*)pass.c_str());
xmlSetProp(newNode, (const xmlChar*)key.c_str(), (const xmlChar*)value.c_str());
}
}
}
}
stream.flush();
// no exception
fd.close();
}
nlinfo("save %s", filename.c_str());
if (verbose)
CInterfaceManager::getInstance()->displaySystemInfo("Saving " + filename);
CInterfaceManager::getInstance()->displaySystemInfo("Save " + filename);
}
catch (const Exception &e)
{
@ -4250,3 +4269,47 @@ int CLuaIHMRyzom::displayChatMessage(CLuaState &ls)
}
return 1;
}
// ***************************************************************************
int CLuaIHMRyzom::scrollElement(CLuaState &ls)
{
const char *funcName = "scrollElement";
// scrollElement(object, vertical, direction, offset_multiplier)
CLuaIHM::checkArgMin(ls, funcName, 3);
CLuaIHM::check(ls, ls.getTop() > 2, funcName);
CLuaIHM::check(ls, CLuaIHM::isUIOnStack(ls, 1), toString("%s requires a UI object in param 1", funcName));
CLuaIHM::check(ls, ls.type(2)==LUA_TBOOLEAN, toString("%s requires a boolean in param 2", funcName));
CLuaIHM::check(ls, ls.isInteger(3), toString("%s requires a number in param 3", funcName));
if (ls.getTop() > 3)
CLuaIHM::check(ls, ls.isInteger(4), toString("%s requires a number in param 4", funcName));
CInterfaceElement *pIE = CLuaIHM::getUIOnStack(ls, 1);
if (pIE)
{
// must be a scroll element
CCtrlScroll *pCS = dynamic_cast<CCtrlScroll*>(pIE);
if (pCS)
{
sint32 direction = 0;
sint32 multiplier = 16;
direction = (ls.toInteger(3) > 0) ? 1 : -1;
if (ls.getTop() > 3)
multiplier = (ls.toInteger(4) > 0) ? ls.toInteger(4) : 1;
const bool vertical = ls.toBoolean(2);
if (vertical)
pCS->moveTrackY(-(direction * multiplier));
else
pCS->moveTrackX(-(direction * multiplier));
return 0;
}
}
ls.pushNil();
return 1;
}

@ -273,6 +273,9 @@ private:
static bool isPlayerInPVPMode();
static bool isTargetInPVPMode();
// vertical and horizontal scrolling
// do not require element to be focused
static int scrollElement(CLuaState &ls); // return none (nil if error)
public:

Loading…
Cancel
Save