From 9dec7f9dbe813e40df9eaaf516aa9d0bbea1a73f Mon Sep 17 00:00:00 2001 From: Inky Date: Fri, 21 Jun 2019 21:15:34 +0300 Subject: [PATCH] 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);