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*/) { diff --git a/code/ryzom/client/src/client_sheets/item_sheet.cpp b/code/ryzom/client/src/client_sheets/item_sheet.cpp index 7ac2376c4..b55382660 100644 --- a/code/ryzom/client/src/client_sheets/item_sheet.cpp +++ b/code/ryzom/client/src/client_sheets/item_sheet.cpp @@ -427,6 +427,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) { @@ -726,6 +731,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) { @@ -765,8 +773,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 6bea55fbc..752a40843 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); } }; 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 2b89061c4..5f2b99c72 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_item.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_item.cpp @@ -442,7 +442,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 @@ -1684,6 +1684,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()); } }; @@ -1761,6 +1765,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")); @@ -1788,6 +1793,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); @@ -1862,6 +1868,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(); @@ -1992,6 +2053,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); @@ -2011,6 +2073,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); @@ -2191,6 +2254,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 @@ -2219,6 +2300,8 @@ class CHandlerTeleportUse : public IActionHandler LoadingBackground = TeleportKaravanBackground; break; } + if (pIS->Scroll.Label.empty()) + checkItemCommand(pIS); } } }; @@ -2233,12 +2316,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 @@ -2262,6 +2361,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); } }; @@ -2303,6 +2406,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())); }