From f61d10c75e7b3a6c20844c412975457a9c309d85 Mon Sep 17 00:00:00 2001 From: Nuno Date: Wed, 10 Feb 2021 09:11:03 +0100 Subject: [PATCH] Added executeRyzomScript, executeTutorial and processTutorialEvent lua callbacks --- code/nel/src/gui/group_html.cpp | 26 ++++++++++++++++--- .../src/interface_v3/group_quick_help.cpp | 2 ++ .../client/src/interface_v3/lua_ihm_ryzom.cpp | 17 ++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 50b381a3c..9531ff216 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -5503,7 +5503,7 @@ namespace NLGUI string suri = elm.getAttribute("href"); if(suri.find("ah:") == 0) { - if (_TrustedDomain) + if (_TrustedDomain || suri.find("ah:script:") == 0) _Link.back() = suri; } else @@ -6360,11 +6360,13 @@ namespace NLGUI void CGroupHTML::htmlOBJECTend(const CHtmlElement &elm) { - if (!_TrustedDomain) - return; + if (_ObjectType=="application/ryzom-data") { + if (!_TrustedDomain) + return; + if (!_ObjectData.empty()) { if (addBnpDownload(_ObjectData, _ObjectAction, _ObjectScript, _ObjectMD5Sum)) @@ -6374,6 +6376,24 @@ namespace NLGUI _ObjectScript.clear(); } } + else if (_ObjectType=="application/ryzom-tutorial") + { + strFindReplace(_ObjectScript, "[[", "\\[\\["); + strFindReplace(_ObjectScript, "]]", "\\]\\]"); + strFindReplace(_ObjectScript, "\\[\\[", "]]..'[['..[["); + strFindReplace(_ObjectScript, "\\]\\]", "]]..']]'..[["); + CLuaManager::getInstance().executeLuaScript("\ngame:executeTutorial([["+_ObjectScript+"]])\n", true); + _ObjectScript.clear(); + } + else if (_ObjectType=="application/ryzom-script") + { + strFindReplace(_ObjectScript, "[[", "\\[\\["); + strFindReplace(_ObjectScript, "]]", "\\]\\]"); + strFindReplace(_ObjectScript, "\\[\\[", "]]..'[['..[["); + strFindReplace(_ObjectScript, "\\]\\]", "]]..']]'..[["); + CLuaManager::getInstance().executeLuaScript("\ngame:executeRyzomScript([["+_ObjectScript+"]])\n", true); + _ObjectScript.clear(); + } _Object = false; } diff --git a/code/ryzom/client/src/interface_v3/group_quick_help.cpp b/code/ryzom/client/src/interface_v3/group_quick_help.cpp index 0b789fccf..e89967193 100644 --- a/code/ryzom/client/src/interface_v3/group_quick_help.cpp +++ b/code/ryzom/client/src/interface_v3/group_quick_help.cpp @@ -74,6 +74,8 @@ bool CGroupQuickHelp::submitEvent (const char *event) // Update the text updateParagraph (); + + CLuaManager::getInstance().executeLuaScript(toString("\ngame:processTutorialEvent(\"%s\")\n", event), true); } } return false; 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 35d4042ee..87d2a52b4 100644 --- a/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp +++ b/code/ryzom/client/src/interface_v3/lua_ihm_ryzom.cpp @@ -184,6 +184,23 @@ private: REGISTER_ACTION_HANDLER(CHandlerLUA, "lua"); std::deque > CHandlerLUA::_UICallerStack; +// *************************************************************************** +class CHandlerSCRIPT : public IActionHandler +{ +public: + void execute(CCtrlBase *pCaller, const std::string &sParams) + { + string script = sParams; + strFindReplace(script, "[[", "\\[\\["); + strFindReplace(script, "]]", "\\]\\]"); + strFindReplace(script, "\\[\\[", "]]..'[['..[["); + strFindReplace(script, "\\]\\]", "]]..']]'..[["); + strFindReplace(script, "|", "\n"); + CLuaManager::getInstance().executeLuaScript("\ngame:executeRyzomScript([["+script+"]])\n", true); + } +}; +REGISTER_ACTION_HANDLER(CHandlerSCRIPT, "script"); + // *************************************************************************** // Allow also to call script from expression static DECLARE_INTERFACE_USER_FCT(lua)