From bd7b703f3acb51c3adc6348179c6ce8878a50e58 Mon Sep 17 00:00:00 2001 From: "ulukyn@gmail.com" Date: Sat, 10 Dec 2016 21:58:15 +0100 Subject: [PATCH] Added: Add lua function to have an icon at left of menu option --HG-- branch : compatibility-develop --- code/nel/include/nel/gui/group_menu.h | 3 ++ code/nel/src/gui/group_menu.cpp | 45 +++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/code/nel/include/nel/gui/group_menu.h b/code/nel/include/nel/gui/group_menu.h index e55bed751..d4f940088 100644 --- a/code/nel/include/nel/gui/group_menu.h +++ b/code/nel/include/nel/gui/group_menu.h @@ -191,6 +191,7 @@ namespace NLGUI int luaGetLineFromId(CLuaState &ls); int luaIsSeparator(CLuaState &ls); int luaAddLine(CLuaState &ls); + int luaAddIconLine(CLuaState &ls); int luaAddLineAtIndex(CLuaState &ls); int luaAddSeparator(CLuaState &ls); int luaAddSeparatorAtIndex(CLuaState &ls); @@ -210,6 +211,7 @@ namespace NLGUI REFLECT_LUA_METHOD("addSubMenu", luaAddSubMenu); REFLECT_LUA_METHOD("isSeparator", luaIsSeparator); REFLECT_LUA_METHOD("addLine", luaAddLine); // name, ah, ah_params, id + REFLECT_LUA_METHOD("addIconLine", luaAddIconLine); // name, ah, ah_params, id, texture REFLECT_LUA_METHOD("addLineAtIndex", luaAddLineAtIndex); // index, name, ah, ah_params, id REFLECT_LUA_METHOD("addSeparator", luaAddSeparator); REFLECT_LUA_METHOD("addSeparatorAtIndex", luaAddSeparatorAtIndex); @@ -278,6 +280,7 @@ namespace NLGUI */ CGroupSubMenu *cloneMenu(CGroupSubMenu *appendToMenu, CGroupMenu *newFather, CInterfaceGroup *initGroup = NULL) const; void initOptions(CInterfaceGroup *parent); + CViewBitmap *createIcon(CInterfaceElement *parentPos, const std::string &texture); CViewBitmap *createCheckBox(bool checked); CViewBitmap *createRightArrow(CInterfaceElement *parentPos, bool center); }; diff --git a/code/nel/src/gui/group_menu.cpp b/code/nel/src/gui/group_menu.cpp index 7ab5db84c..48a9ee8b5 100644 --- a/code/nel/src/gui/group_menu.cpp +++ b/code/nel/src/gui/group_menu.cpp @@ -381,6 +381,22 @@ namespace NLGUI return true; } + // ------------------------------------------------------------------------------------------------ + CViewBitmap *CGroupSubMenu::createIcon(CInterfaceElement *parentPos, const string &texture) + { + // Add an icon to the line + CViewBitmap *pVB = new CViewBitmap(CViewBase::TCtorParam()); + pVB->setSerializable( false ); + pVB->setParent (this); + pVB->setParentPos (parentPos); + pVB->setParentPosRef (Hotspot_ML); + pVB->setPosRef (Hotspot_MR); + pVB->setTexture(texture); + pVB->setModulateGlobalColor(false); + pVB->setX (-2); + addView (pVB); + return pVB; + } // ------------------------------------------------------------------------------------------------ CViewBitmap *CGroupSubMenu::createCheckBox(bool checked) @@ -1226,13 +1242,22 @@ namespace NLGUI pV->setCheckBox(checkBox); } + CViewBitmap *icon = NULL; + if (!texture.empty()) + { + if (_GroupList->getNumChildren() == 1) + pV->setX(20); + icon = createIcon(pV, texture); + } + + tmp.ViewText = pV; tmp.Separator = NULL; tmp.AHName = ah; tmp.AHParams = params; tmp.Cond = cond; tmp.CheckBox = checkBox; - tmp.RightArrow = NULL; + tmp.RightArrow = icon; if (id.empty()) tmp.Id = NLMISC::toString (_Lines.size()); else @@ -1772,7 +1797,23 @@ namespace NLGUI addLine(arg1, ls.toString(2), ls.toString(3), ls.toString(4)); return 0; } - + + // ------------------------------------------------------------------------------------------------ + int CGroupSubMenu::luaAddIconLine(CLuaState &ls) + { + const char *funcName = "addIconLine"; + CLuaIHM::checkArgCount(ls, funcName, 5); + CLuaIHM::checkArgTypeUCString(ls, funcName, 1); + CLuaIHM::checkArgType(ls, funcName, 2, LUA_TSTRING); + CLuaIHM::checkArgType(ls, funcName, 3, LUA_TSTRING); + CLuaIHM::checkArgType(ls, funcName, 4, LUA_TSTRING); + CLuaIHM::checkArgType(ls, funcName, 5, LUA_TSTRING); + ucstring arg1; + nlverify(CLuaIHM::getUCStringOnStack(ls, 1, arg1)); + addLine(arg1, ls.toString(2), ls.toString(3), ls.toString(4), string(), ls.toString(5)); + return 0; + } + // ------------------------------------------------------------------------------------------------ int CGroupSubMenu::luaAddLineAtIndex(CLuaState &ls) {