From 9fffec8ef15f90dd42f42f0e520f5f756d6e892d Mon Sep 17 00:00:00 2001 From: Guillaume Dupuy Date: Thu, 9 Mar 2017 17:47:25 +0100 Subject: [PATCH] Added interface for item groups --HG-- branch : item_group --- .../data/gamedev/interfaces_v3/widgets.xml | 40 +++++++++ .../src/interface_v3/action_handler_item.cpp | 83 ++++++++++++++++++- code/ryzom/client/src/item_group_manager.cpp | 18 +++- code/ryzom/client/src/item_group_manager.h | 18 +--- 4 files changed, 138 insertions(+), 21 deletions(-) diff --git a/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml b/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml index 24fa399b2..3c25c911a 100644 --- a/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml +++ b/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml @@ -1819,6 +1819,37 @@ name="uimItemTextEdit" handler="item_text_edition" params="ui:interface:edit_custom" /> + + + + + + + + + + + + + + + + + (pMenu->getView("guild")); CViewTextMenu *pMoveToRoom = dynamic_cast(pMenu->getView("room")); CViewTextMenu *pMoveToPa[MAX_INVENTORY_ANIMAL]; + CViewTextMenu *pGroupSubMenu = dynamic_cast(pMenu->getView("item_group")); + CViewTextMenu *pGroupMoveToBag = dynamic_cast(pMenu->getView("group_bag")); + CViewTextMenu *pGroupName = dynamic_cast(pMenu->getView("group_name")); + CViewTextMenu *pGroupMoveToPa[MAX_INVENTORY_ANIMAL]; bool bIsLockedByOwner = pCS->getLockedByOwner(); for(i=0;i(pMenu->getView(toString("pa%d", i))); + pGroupMoveToPa[i]= dynamic_cast(pMenu->getView(toString("group_pa%d", i))); + } CViewTextMenu *pItemInfos = dynamic_cast(pMenu->getView("infos")); CViewTextMenu *pItemTextDisplay = dynamic_cast(pMenu->getView("item_text_display")); @@ -1780,6 +1786,13 @@ class CHandlerItemMenuCheck : public IActionHandler if(pItemTextDisplay) pItemTextDisplay->setActive(false); if(pItemTextEdition) pItemTextEdition->setActive(false); + //Item GROUP logic + if(pGroupSubMenu && pGroupName) + { + std::string groupName = CItemGroupManager::getInstance()->getGroupName(pCS); + pGroupSubMenu->setActive(groupName != ""); + pGroupName->setHardText(groupName); + } if(pLockUnlock) pLockUnlock->setActive(true); const CItemSheet *pIS = pCS->asItemSheet(); @@ -1859,8 +1872,13 @@ class CHandlerItemMenuCheck : public IActionHandler { // cannot move to other animals! :) if(pMoveToBag) pMoveToBag->setActive(false); + if(pGroupMoveToBag) pGroupMoveToBag->setActive(false); for(i=0;isetActive(false); + if(pGroupMoveToPa[i]) pGroupMoveToPa[i]->setActive(false); + } + // additionnaly, cannot drop/destroy/lock an animal item. if(pDrop) pDrop->setActive(false); @@ -1875,6 +1893,10 @@ class CHandlerItemMenuCheck : public IActionHandler pMoveToBag->setActive( invId!=INVENTORIES::bag && invMngr.isInventoryPresent(INVENTORIES::bag) && (invId!=INVENTORIES::guild || invMngr.isInventoryPresent(INVENTORIES::guild)) ); + if(pGroupMoveToBag) + pGroupMoveToBag->setActive( invId!=INVENTORIES::bag && + invMngr.isInventoryPresent(INVENTORIES::bag) && + (invId!=INVENTORIES::guild || invMngr.isInventoryPresent(INVENTORIES::guild)) ); for(i=0;isetActive(invId!=INVENTORIES::guild && (uint)invId!=INVENTORIES::pet_animal+i && invMngr.isInventoryPresent((INVENTORIES::TInventory)(INVENTORIES::pet_animal+i)) ); + if (pGroupMoveToPa[i]) + pGroupMoveToPa[i]->setActive(invId!=INVENTORIES::guild && + (uint)invId!=INVENTORIES::pet_animal+i && + invMngr.isInventoryPresent((INVENTORIES::TInventory)(INVENTORIES::pet_animal+i)) ); } if (pMoveToGuild) @@ -1901,9 +1927,13 @@ class CHandlerItemMenuCheck : public IActionHandler if(pMoveSubMenu) { if(pMoveToBag) someMovePossible= someMovePossible || pMoveToBag->getActive(); + if(pGroupMoveToBag) someMovePossible= someMovePossible || pGroupMoveToBag->getActive(); + for(i=0;igetActive(); + if(pGroupMoveToPa[i]) someMovePossible= someMovePossible || pGroupMoveToPa[i]->getActive(); + } if(pMoveToGuild) someMovePossible= someMovePossible || pMoveToGuild->getActive(); if(pMoveToRoom) someMovePossible= someMovePossible || pMoveToRoom->getActive(); @@ -1986,9 +2016,12 @@ class CHandlerItemMenuCheck : public IActionHandler if(pLockUnlock) pLockUnlock->setGrayed(true); if(pMoveSubMenu) pMoveSubMenu->setGrayed(true); if(pMoveToBag) pMoveToBag->setGrayed(true); + if(pGroupMoveToBag) pGroupMoveToBag->setGrayed(true); + for(i=0;isetGrayed(true); + if(pGroupMoveToPa[i]) pGroupMoveToPa[i]->setGrayed(true); } } // Gray Text entries according to Availables Destinations @@ -2007,10 +2040,14 @@ class CHandlerItemMenuCheck : public IActionHandler // check each inventory dest if available if(pMoveToBag) pMoveToBag->setGrayed(!invMngr.isInventoryAvailable(INVENTORIES::bag)); + if(pGroupMoveToBag) pGroupMoveToBag->setGrayed(!invMngr.isInventoryAvailable(INVENTORIES::bag)); + for(i=0;isetGrayed(!invMngr.isInventoryAvailable( (INVENTORIES::TInventory)(INVENTORIES::pet_animal+i))); + if(pGroupMoveToPa[i]) pGroupMoveToPa[i]->setGrayed(!invMngr.isInventoryAvailable( + (INVENTORIES::TInventory)(INVENTORIES::pet_animal+i))); } } @@ -2247,4 +2284,48 @@ class CHandlerRingXpCatalyserStopUse : public IActionHandler REGISTER_ACTION_HANDLER( CHandlerRingXpCatalyserStopUse, "ring_xp_catalyser_stop_use" ); +// *************************************************************************** +// item groups +class CHandlerItemGroupMove : public IActionHandler +{ + void execute (CCtrlBase *caller, const std::string &sParams) + { + CDBCtrlSheet* pCS = dynamic_cast(caller); + if(!pCS) + { + nlinfo("Wrong cast"); + return; + } + std::string groupName = CItemGroupManager::getInstance()->getGroupName(pCS); + if(groupName.empty()) + { + nlinfo("Trying to move a group with a caller not part of any group"); + return; + } + CItemGroupManager::getInstance()->moveGroup(groupName, INVENTORIES::toInventory(sParams)); + } +}; +REGISTER_ACTION_HANDLER(CHandlerItemGroupMove, "item_group_move"); + +// *************************************************************************** +class CHandlerItemGroupEquip : public IActionHandler +{ + void execute (CCtrlBase *caller, const std::string &/* sParams */) + { + CDBCtrlSheet* pCS = dynamic_cast(caller); + if(!pCS) + { + nlinfo("Wrong cast"); + return; + } + std::string groupName = CItemGroupManager::getInstance()->getGroupName(pCS); + if(groupName.empty()) + { + nlinfo("Trying to move a group with a caller not part of any group"); + return; + } + CItemGroupManager::getInstance()->equipGroup(groupName); + } +}; +REGISTER_ACTION_HANDLER(CHandlerItemGroupEquip, "item_group_equip"); diff --git a/code/ryzom/client/src/item_group_manager.cpp b/code/ryzom/client/src/item_group_manager.cpp index 3d14b6106..6fa7d285d 100644 --- a/code/ryzom/client/src/item_group_manager.cpp +++ b/code/ryzom/client/src/item_group_manager.cpp @@ -251,9 +251,6 @@ bool CItemGroupManager::loadGroups() return true; } - - - //move a group from all available inventory to dst bool CItemGroupManager::moveGroup(std::string name, INVENTORIES::TInventory dst) { @@ -284,7 +281,6 @@ bool CItemGroupManager::moveGroup(std::string name, INVENTORIES::TInventory dst) } - bool CItemGroupManager::equipGroup(std::string name, bool pullBefore) { CItemGroup* group = findGroup(name); @@ -400,6 +396,20 @@ bool CItemGroupManager::deleteGroup(std::string name) return true; } +//Used by AH + +std::string CItemGroupManager::getGroupName(CDBCtrlSheet* pCS) +{ + for(auto &group: _Groups) + { + if(group.contains(pCS)) + return group.name; + + } + return ""; +} + +//Private methods CItemGroup* CItemGroupManager::findGroup(std::string name) { for(auto &group: _Groups) diff --git a/code/ryzom/client/src/item_group_manager.h b/code/ryzom/client/src/item_group_manager.h index 42e3ccd88..27b73757d 100644 --- a/code/ryzom/client/src/item_group_manager.h +++ b/code/ryzom/client/src/item_group_manager.h @@ -22,21 +22,6 @@ #include "interface_v3/dbctrl_sheet.h" #include "game_share/inventories.h" -/* - * - * Il me faut une fonction à la build() pour le chrgt XML, et un save pour le save - * ou stream.h en XML mode, todo - * TODO list : - * * DONE bool usePrice support - * * DONE Sauvegarde / Chargement .xml - * * DONE Singleton manager - * * DONE Commandes de test : loadXML, savexML, equip, move - * * Init au bon moment (où ?) - * * DONE Création de /saveGroup (stuff équipé -> groupe) - * * - * ********* premier commit - * * interface clic droit - * */ struct CInventoryItem { public: CDBCtrlSheet* pCS; @@ -95,9 +80,10 @@ public: //Return NULL if no group was found //Return false if no group was found bool moveGroup(std::string name, INVENTORIES::TInventory dst); - bool equipGroup(std::string name, bool pullBefore=false); + bool equipGroup(std::string name, bool pullBefore=true); bool createGroup(std::string name); bool deleteGroup(std::string name); + std::string getGroupName(CDBCtrlSheet *pCS); private: CItemGroup* findGroup(std::string name);