From a1492e70e0369a6fa84c0df5a42a3c96b1085899 Mon Sep 17 00:00:00 2001 From: Inky Date: Sat, 22 Jun 2019 23:38:03 +0300 Subject: [PATCH] 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: