From 570c73576c363892303b796ca6a358a8b193e5b9 Mon Sep 17 00:00:00 2001 From: Inky Date: Sun, 26 May 2019 01:09:10 +0300 Subject: [PATCH 1/3] Changed: add channel rgba colors and index order --HG-- branch : lua --- .../client/src/interface_v3/lua_ihm_ryzom.cpp | 76 +++++++++++-------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp index 875edde9c..293b0e15a 100644 --- a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp +++ b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp @@ -3996,7 +3996,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; @@ -4007,37 +4007,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()); } @@ -4049,7 +4055,6 @@ int CLuaIHMRyzom::readUserChannels(CLuaState &ls) return 1; } -// *************************************************************************** int CLuaIHMRyzom::saveUserChannels(CLuaState &ls) { const char *funcName = "saveUserChannels"; @@ -4067,7 +4072,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; @@ -4080,27 +4085,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()); - std::string name = it.nextKey().toString(); - std::string pass = it.nextValue().toString(); + ENUM_LUA_TABLE(it.nextValue(), itt) + { + if (!itt.nextKey().isString()) + continue; + if (!itt.nextValue().isString()) + continue; - 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()); + key = itt.nextKey().toString(); + value = itt.nextValue().toString(); + + 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) { From 9dec7f9dbe813e40df9eaaf516aa9d0bbea1a73f Mon Sep 17 00:00:00 2001 From: Inky Date: Fri, 21 Jun 2019 21:15:34 +0300 Subject: [PATCH 2/3] Changed: get the lua script executed at checkCoords time --HG-- branch : lua --- code/nel/include/nel/gui/interface_group.h | 2 ++ code/nel/include/nel/gui/lua_ihm.h | 1 + code/nel/src/gui/lua_ihm.cpp | 30 ++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index 01f2b9701..e782af01e 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -313,6 +313,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 diff --git a/code/nel/include/nel/gui/lua_ihm.h b/code/nel/include/nel/gui/lua_ihm.h index e45e1125f..a7c5f9e2b 100644 --- a/code/nel/include/nel/gui/lua_ihm.h +++ b/code/nel/include/nel/gui/lua_ihm.h @@ -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); diff --git a/code/nel/src/gui/lua_ihm.cpp b/code/nel/src/gui/lua_ihm.cpp index 4a51d221f..6da211b52 100644 --- a/code/nel/src/gui/lua_ihm.cpp +++ b/code/nel/src/gui/lua_ihm.cpp @@ -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(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); From a1492e70e0369a6fa84c0df5a42a3c96b1085899 Mon Sep 17 00:00:00 2001 From: Inky Date: Sat, 22 Jun 2019 23:38:03 +0300 Subject: [PATCH 3/3] Changed: bind to interact with vertical/horizontal scroll elements --HG-- branch : lua --- .../client/src/interface_v3/lua_ihm_ryzom.cpp | 47 ++++++++++++++++++- .../client/src/interface_v3/lua_ihm_ryzom.h | 3 ++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp index 293b0e15a..0fab25843 100644 --- a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp +++ b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp @@ -495,6 +495,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(); @@ -4248,4 +4249,48 @@ int CLuaIHMRyzom::displayChatMessage(CLuaState &ls) ci.DynamicChat[id].displayMessage(ucstring(msg), prop.getRGBA()); } return 1; -} \ No newline at end of file +} + +// *************************************************************************** +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(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; +} diff --git a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.h b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.h index d60279aec..b071d5228 100644 --- a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.h +++ b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.h @@ -271,6 +271,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: