From 2c92ec7909dfb6c68f38a664fbb05451e20cd312 Mon Sep 17 00:00:00 2001 From: Inky Date: Tue, 30 Apr 2019 16:59:15 +0300 Subject: [PATCH 1/3] Added: item sheets scroll properties execute lua code, open webig and set menu label --HG-- branch : develop --- code/ryzom/client/src/client_sheets/item_sheet.cpp | 11 ++++++++++- code/ryzom/client/src/client_sheets/item_sheet.h | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/code/ryzom/client/src/client_sheets/item_sheet.cpp b/code/ryzom/client/src/client_sheets/item_sheet.cpp index e13d8e267..daac055fe 100644 --- a/code/ryzom/client/src/client_sheets/item_sheet.cpp +++ b/code/ryzom/client/src/client_sheets/item_sheet.cpp @@ -367,6 +367,11 @@ void CItemSheet::build(const NLGEORGES::UFormElm &item) if (!val.empty()) CraftPlan = CSheetId(val); + // commands and menu label + TRANSLATE_VAL( Scroll.LuaCommand, "basics.Scroll.LuaCommand" ); + TRANSLATE_VAL( Scroll.WebCommand, "basics.Scroll.WebCommand" ); + TRANSLATE_VAL( Scroll.Label, "basics.Scroll.Label" ); + // Special according to Family; switch(Family) { @@ -658,6 +663,9 @@ void CItemSheet::serial(NLMISC::IStream &f) // **** Serial Help Infos f.serialEnum(ItemOrigin); + // item commands + f.serial(Scroll); + // Different Serial according to family switch(Family) { @@ -697,8 +705,9 @@ void CItemSheet::serial(NLMISC::IStream &f) case ITEMFAMILY::TELEPORT: f.serial(Teleport); break; + // keep for readability case ITEMFAMILY::SCROLL: - f.serial(Scroll); + //f.serial(Scroll); break; case ITEMFAMILY::CONSUMABLE: f.serial(Consumable); diff --git a/code/ryzom/client/src/client_sheets/item_sheet.h b/code/ryzom/client/src/client_sheets/item_sheet.h index c363c9756..bd79b1569 100644 --- a/code/ryzom/client/src/client_sheets/item_sheet.h +++ b/code/ryzom/client/src/client_sheets/item_sheet.h @@ -255,10 +255,16 @@ public: struct CScroll { std::string Texture; + std::string LuaCommand; + std::string WebCommand; + std::string Label; void serial(NLMISC::IStream &f) { f.serial(Texture); + f.serial(LuaCommand); + f.serial(WebCommand); + f.serial(Label); } }; From 17945d24b03b7c0d135085888f39dacb5233a1bd Mon Sep 17 00:00:00 2001 From: Inky Date: Tue, 30 Apr 2019 01:33:39 +0300 Subject: [PATCH 2/3] Added: CGroup menu set action handler --HG-- branch : develop --- code/nel/include/nel/gui/group_menu.h | 5 ++++ code/nel/src/gui/group_menu.cpp | 36 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/code/nel/include/nel/gui/group_menu.h b/code/nel/include/nel/gui/group_menu.h index cfe91f7f9..ecdd8aff0 100644 --- a/code/nel/include/nel/gui/group_menu.h +++ b/code/nel/include/nel/gui/group_menu.h @@ -137,6 +137,9 @@ namespace NLGUI const std::string getActionHandler(uint lineIndex) const; const std::string getActionHandlerParam(uint lineIndex) const; + void setActionHandler(uint lineIndex, const std::string &ah = ""); + void setActionHandlerParam(uint lineIndex, const std::string ¶ms = ""); + void openSubMenu (sint32 nb); void hideSubMenus (); @@ -330,6 +333,8 @@ namespace NLGUI const std::string getActionHandler(uint lineIndex) const; const std::string getActionHandlerParam(uint lineIndex) const; + void setActionHandler(uint lineIndex, const std::string &ah = ""); + void setActionHandlerParam(uint lineIndex, const std::string ¶ms = ""); void addLine (const ucstring &name, const std::string &ah = "", const std::string ¶ms = "", const std::string &id = std::string(), diff --git a/code/nel/src/gui/group_menu.cpp b/code/nel/src/gui/group_menu.cpp index d8b3452ed..15a655d76 100644 --- a/code/nel/src/gui/group_menu.cpp +++ b/code/nel/src/gui/group_menu.cpp @@ -1663,6 +1663,28 @@ namespace NLGUI return _Lines[lineIndex].AHParams; } + // ------------------------------------------------------------------------------------------------ + void CGroupSubMenu::setActionHandler(uint lineIndex, const std::string &ah) + { + if (lineIndex > _Lines.size()) + { + nlwarning("Bad index"); + return; + } + _Lines[lineIndex].AHName = ah; + } + + // ------------------------------------------------------------------------------------------------ + void CGroupSubMenu::setActionHandlerParam(uint lineIndex, const std::string ¶ms) + { + if (lineIndex > _Lines.size()) + { + nlwarning("Bad index"); + return; + } + _Lines[lineIndex].AHParams = params; + } + // ------------------------------------------------------------------------------------------------ void CGroupSubMenu::setSelectable(uint lineIndex, bool selectable) { @@ -2596,6 +2618,20 @@ namespace NLGUI return _RootMenu ? _RootMenu->getActionHandlerParam(lineIndex) : ""; } + // ------------------------------------------------------------------------------------------------ + void CGroupMenu::setActionHandler(uint lineIndex, const std::string &ah) + { + if (_RootMenu) + _RootMenu->setActionHandler(lineIndex, ah); + } + + // ------------------------------------------------------------------------------------------------ + void CGroupMenu::setActionHandlerParam(uint lineIndex, const std::string ¶ms) + { + if (_RootMenu) + _RootMenu->setActionHandlerParam(lineIndex, params); + } + // ------------------------------------------------------------------------------------------------ void CGroupMenu::setUserGroupRight(uint line, CInterfaceGroup *gr, bool ownerShip /*=true*/) { From 59da139eb740a25a7f7a24d0c2c1b6d28b73fe4b Mon Sep 17 00:00:00 2001 From: Inky Date: Tue, 30 Apr 2019 02:52:54 +0300 Subject: [PATCH 3/3] Changed: introduce new proprieties menu and action handler --HG-- branch : develop --- .../src/interface_v3/action_handler_item.cpp | 109 +++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/code/ryzom/client/src/interface_v3/action_handler_item.cpp b/code/ryzom/client/src/interface_v3/action_handler_item.cpp index d15ae130c..99c1147d3 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_item.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_item.cpp @@ -430,7 +430,7 @@ static TStackMode CurrentStackMode; static void validateStackItem(CDBCtrlSheet *src, CDBCtrlSheet *dest, sint32 quantity, TStackMode stackMode); - +static void checkItemCommand(const CItemSheet *itemSheet); //===================================================================================================================== /** Send a swap item msg to the server @@ -1672,6 +1672,10 @@ class CHandlerItemCristalReload : public IActionHandler CDBCtrlSheet *pCS = dynamic_cast(CWidgetManager::getInstance()->getCtrlLaunchingModal()); if (pCS == NULL) return; + const CItemSheet *pIS = pCS->asItemSheet(); + if (pIS && pIS->Scroll.Label.empty()) + checkItemCommand(pIS); + sendToServerEnchantMessage((uint8)pCS->getInventoryIndex(), (uint16)pCS->getIndexInDB()); } }; @@ -1749,6 +1753,7 @@ class CHandlerItemMenuCheck : public IActionHandler CViewTextMenu *pCrisReload = dynamic_cast(pMenu->getView("cris_reload")); CViewTextMenu *pTeleportUse = dynamic_cast(pMenu->getView("teleport_use")); CViewTextMenu *pItemConsume = dynamic_cast(pMenu->getView("item_consume")); + CViewTextMenu *pItemExecute = dynamic_cast(pMenu->getView("item_execute")); CViewTextMenu *pXpCatalyserUse = dynamic_cast(pMenu->getView("xp_catalyser_use")); CViewTextMenu *pDrop = dynamic_cast(pMenu->getView("drop")); CViewTextMenu *pDestroy = dynamic_cast(pMenu->getView("destroy")); @@ -1776,6 +1781,7 @@ class CHandlerItemMenuCheck : public IActionHandler if(pCrisReload) pCrisReload->setActive(false); if(pTeleportUse) pTeleportUse->setActive(false); if(pItemConsume) pItemConsume->setActive(false); + if(pItemExecute) pItemExecute->setActive(false); if(pXpCatalyserUse) pXpCatalyserUse->setActive(false); if(pItemTextDisplay) pItemTextDisplay->setActive(false); if(pItemTextEdition) pItemTextEdition->setActive(false); @@ -1850,6 +1856,61 @@ class CHandlerItemMenuCheck : public IActionHandler { pItemInfos->setActive(true); } + // item has a label? + if (!pIS->Scroll.Label.empty()) + { + CGroupMenu *menu = dynamic_cast( + CWidgetManager::getInstance()->getElementFromId("ui:interface:item_menu_in_bag") + ); + // add the label to default menu + if (!pIS->Scroll.LuaCommand.empty() || !pIS->Scroll.WebCommand.empty()) + menu->setActionHandler(4, menu->getActionHandler(4)); + else + { + // replace default menu and redirect action handler + if (pCrisEnchant && pCrisEnchant->getActive()) + { + pCrisEnchant->setActive(false); + menu->setActionHandler(4, menu->getActionHandler(0)); + } + if (pCrisReload && pCrisReload->getActive()) + { + pCrisReload->setActive(false); + menu->setActionHandler(4, menu->getActionHandler(1)); + } + if (pTeleportUse && pTeleportUse->getActive()) + { + pTeleportUse->setActive(false); + menu->setActionHandler(4, menu->getActionHandler(2)); + } + if (pItemConsume && pItemConsume->getActive()) + { + pItemConsume->setActive(false); + menu->setActionHandler(4, menu->getActionHandler(3)); + } + if (pXpCatalyserUse && pXpCatalyserUse->getActive()) + { + pXpCatalyserUse->setActive(false); + menu->setActionHandler(4, menu->getActionHandler(5)); + } + if (pItemTextDisplay && pItemTextDisplay->getActive()) + { + pItemTextDisplay->setActive(false); + menu->setActionHandler(4, menu->getActionHandler(6)); + menu->setActionHandlerParam(4, menu->getActionHandlerParam(6)); + } + } + if (!bIsLockedByOwner) + { + if (pCS->getInventoryIndex() == INVENTORIES::bag) + pItemExecute->setActive(true); + // enchant and reload can be used from anywhere + if (pIS->Family == ITEMFAMILY::CRYSTALLIZED_SPELL || pIS->Family == ITEMFAMILY::ITEM_SAP_RECHARGE) + pItemExecute->setActive(true); + + pItemExecute->setText(CI18N::get(pIS->Scroll.Label)); + } + } } CInventoryManager &invMngr= getInventory(); @@ -1980,6 +2041,7 @@ class CHandlerItemMenuCheck : public IActionHandler if(pCrisReload) pCrisReload->setGrayed(true); if(pTeleportUse) pTeleportUse->setGrayed(true); if(pItemConsume) pItemConsume->setGrayed(true); + if(pItemExecute) pItemExecute->setGrayed(true); if(pXpCatalyserUse) pXpCatalyserUse->setGrayed(true); if(pDrop) pDrop->setGrayed(true); if(pDestroy) pDestroy->setGrayed(true); @@ -1999,6 +2061,7 @@ class CHandlerItemMenuCheck : public IActionHandler if(pCrisReload) pCrisReload->setGrayed(false); if(pTeleportUse) pTeleportUse->setGrayed(false); if(pItemConsume) pItemConsume->setGrayed(false); + if(pItemExecute) pItemExecute->setGrayed(false); if(pXpCatalyserUse) pXpCatalyserUse->setGrayed(false); if(pDrop) pDrop->setGrayed(false); if(pDestroy) pDestroy->setGrayed(false); @@ -2179,6 +2242,24 @@ static void sendMsgStopUseXpCat( bool isRingCatalyser ) } } +// *************************************************************************** +static void checkItemCommand(const CItemSheet *itemSheet) +{ + if (itemSheet) + { + if (!itemSheet->Scroll.LuaCommand.empty()) + CLuaManager::getInstance().executeLuaScript(itemSheet->Scroll.LuaCommand); + // webig + if (!itemSheet->Scroll.WebCommand.empty()) + { + CGroupHTML *pGH = dynamic_cast( + CWidgetManager::getInstance()->getElementFromId("ui:interface:web_transactions:content:html") + ); + if (pGH) pGH->browse(itemSheet->Scroll.WebCommand.c_str()); + } + } + return; +} // *************************************************************************** class CHandlerTeleportUse : public IActionHandler @@ -2207,6 +2288,8 @@ class CHandlerTeleportUse : public IActionHandler LoadingBackground = TeleportKaravanBackground; break; } + if (pIS->Scroll.Label.empty()) + checkItemCommand(pIS); } } }; @@ -2221,12 +2304,28 @@ class CHandlerItemConsume : public IActionHandler CDBCtrlSheet *pCS = dynamic_cast(CWidgetManager::getInstance()->getCtrlLaunchingModal()); if (pCS == NULL) return; + const CItemSheet *pIS = pCS->asItemSheet(); + if (pIS && pIS->Scroll.Label.empty()) + checkItemCommand(pIS); + // use the item sendMsgUseItem(uint16(pCS->getIndexInDB())); } }; REGISTER_ACTION_HANDLER( CHandlerItemConsume, "item_consume" ); +// *************************************************************************** +class CHandlerItemExecute : public IActionHandler +{ + void execute (CCtrlBase * /* pCaller */, const std::string &/* sParams */) + { + CDBCtrlSheet *pCS = dynamic_cast(CWidgetManager::getInstance()->getCtrlLaunchingModal()); + if (pCS) + checkItemCommand(pCS->asItemSheet()); + return; + } +}; +REGISTER_ACTION_HANDLER( CHandlerItemExecute, "item_execute" ); // *************************************************************************** class CHandlerValidateItemTextEdition : public IActionHandler @@ -2250,6 +2349,10 @@ class CHandlerItemTextDisplay : public IActionHandler if (pCSItem == NULL || windowName.empty()) return; + const CItemSheet *pIS = pCSItem->asItemSheet(); + if (pIS && pIS->Scroll.Label.empty()) + checkItemCommand(pIS); + CInterfaceItemEdition::getInstance()->setCurrWindow(pCSItem, windowName, false); } }; @@ -2291,6 +2394,10 @@ class CHandlerXpCatalyserUse : public IActionHandler CDBCtrlSheet *pCS = dynamic_cast(CWidgetManager::getInstance()->getCtrlLaunchingModal()); if (pCS == NULL) return; + const CItemSheet *pIS = pCS->asItemSheet(); + if (pIS && pIS->Scroll.Label.empty()) + checkItemCommand(pIS); + // use the item sendMsgUseItem(uint16(pCS->getIndexInDB())); }