From af6975ae110b606b93d7dedf1680c2bfe5753ce8 Mon Sep 17 00:00:00 2001 From: ulukyn Date: Sun, 4 Mar 2018 11:40:29 +0100 Subject: [PATCH] Added: onclick_r and onover Lua reflect properties. Setup id to buttonGroup to access it --HG-- branch : patches-from-atys --- code/nel/include/nel/gui/ctrl_base_button.h | 12 ++++++++++- code/nel/src/gui/ctrl_base_button.cpp | 22 +++++++++++++++++++++ code/nel/src/gui/group_html.cpp | 5 +++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_base_button.h b/code/nel/include/nel/gui/ctrl_base_button.h index d4699305f..9859f5b6e 100644 --- a/code/nel/include/nel/gui/ctrl_base_button.h +++ b/code/nel/include/nel/gui/ctrl_base_button.h @@ -124,9 +124,11 @@ namespace NLGUI // Event part void setActionOnLeftClick (const std::string &actionHandlerName) { _AHOnLeftClickString = actionHandlerName; _AHOnLeftClick = CAHManager::getInstance()->getAH(actionHandlerName, _AHLeftClickParams); } void setActionOnLeftClickParams(const std::string ¶ms) { _AHOnLeftClickStringParams = params; } + void setActionOnOver (const std::string &actionHandlerName) { _AHOnOver = CAHManager::getInstance()->getAH(actionHandlerName, _AHOverParams); } void setActionOnRightClick (const std::string &actionHandlerName) { _AHOnRightClick = CAHManager::getInstance()->getAH(actionHandlerName, _AHRightClickParams); } void setActionOnClockTick (const std::string &ahName) { _AHOnClockTick = CAHManager::getInstance()->getAH(ahName, _AHClockTickParams); } void setParamsOnLeftClick (const std::string ¶msHandlerName) { _AHLeftClickParams = paramsHandlerName; } + void setParamsOnOver (const std::string ¶msHandlerName) { _AHOverParams = paramsHandlerName; } void setParamsOnRightClick (const std::string ¶msHandlerName) { _AHRightClickParams = paramsHandlerName; } void setParamsOnClockTick (const std::string &ahParamsName) { _AHClockTickParams = ahParamsName; } @@ -141,14 +143,16 @@ namespace NLGUI IActionHandler *getActionOnLeftClick () const { return _AHOnLeftClick; } IActionHandler *getActionOnRightClick () const { return _AHOnRightClick; } IActionHandler *getActionOnClockTick () const { return _AHOnClockTick; } - std::string _getParamsOnOver() const{ return _AHOverParams.toString(); } + std::string _getParamsOnOver() const{ return _AHOverParams.toString(); } std::string _getParamsOnLeftClick () const { return _AHLeftClickParams.toString(); } + std::string _getParamsOnRightClick () const { return _AHRightClickParams.toString(); } const std::string &getParamsOnLeftClick () const { return _AHLeftClickParams; } const std::string &getParamsOnRightClick () const { return _AHRightClickParams; } const std::string &getParamsOnClockTick () const { return _AHClockTickParams; } // run action on left click void runLeftClickAction(); + void runRightClickAction(); // Context menu accessor/ One for each button void setListMenuLeft (const std::string &cm) { _ListMenuLeft = cm; } @@ -161,6 +165,7 @@ namespace NLGUI int luaRunLeftClickAction(CLuaState &ls); + int luaRunRightClickAction(CLuaState &ls); REFLECT_EXPORT_START(CCtrlBaseButton, CCtrlBase) REFLECT_BOOL("pushed", getPushed, setPushed); REFLECT_STRING("col_normal", getColorAsString, setColorAsString); @@ -174,6 +179,11 @@ namespace NLGUI REFLECT_STRING("onclick_l", _getActionOnLeftClick, setActionOnLeftClick); REFLECT_STRING("params_l", _getParamsOnLeftClick, setParamsOnLeftClick); REFLECT_LUA_METHOD("runLeftClickAction", luaRunLeftClickAction); + REFLECT_STRING("onclick_r", _getActionOnRightClick, setActionOnRightClick); + REFLECT_STRING("params_r", _getParamsOnRightClick, setParamsOnRightClick); + REFLECT_LUA_METHOD("runRightClickAction", luaRunRightClickAction); + REFLECT_STRING("onover", _getActionOnOver, setActionOnOver); + REFLECT_STRING("params_over", _getParamsOnOver, setParamsOnOver); REFLECT_EXPORT_END protected: diff --git a/code/nel/src/gui/ctrl_base_button.cpp b/code/nel/src/gui/ctrl_base_button.cpp index d60824295..91fe0b744 100644 --- a/code/nel/src/gui/ctrl_base_button.cpp +++ b/code/nel/src/gui/ctrl_base_button.cpp @@ -996,5 +996,27 @@ namespace NLGUI return 0; } + // *************************************************************************** + void CCtrlBaseButton::runRightClickAction() + { + if(_AHOnRightClick != NULL) + { + + CAHManager::getInstance()->submitEvent( "button_click:" + getId() ); + CAHManager::getInstance()->runActionHandler (_AHOnRightClick, this, _AHRightClickParams); + } + } + + // *************************************************************************** + int CCtrlBaseButton::luaRunRightClickAction(CLuaState &ls) + { + const char *funcName = "onRightClick"; + CLuaIHM::checkArgCount(ls, funcName, 0); + + runRightClickAction(); + + return 0; + } + } diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index a2906f017..50106e5c0 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -2759,7 +2759,8 @@ namespace NLGUI CInterfaceGroup *buttonGroup = CWidgetManager::getInstance()->getParser()->createGroupInstance(buttonTemplate, _Paragraph->getId(), tmplParams); if (buttonGroup) { - + if (!_AnchorName.empty()) + buttonGroup->setId(_AnchorName.back()); // Add the ctrl button CCtrlTextButton *ctrlButton = dynamic_cast(buttonGroup->getCtrl("button")); if (!ctrlButton) ctrlButton = dynamic_cast(buttonGroup->getCtrl("b")); @@ -4512,7 +4513,7 @@ namespace NLGUI // *************************************************************************** int CGroupHTML::luaSetBackground(CLuaState &ls) { - const char *funcName = "renderHtml"; + const char *funcName = "setBackground"; CLuaIHM::checkArgCount(ls, funcName, 3); CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING); CLuaIHM::checkArgType(ls, funcName, 2, LUA_TBOOLEAN);