From c2049935a4c9cb837de67a28aef3a04a4687cb33 Mon Sep 17 00:00:00 2001 From: Guillaume Dupuy Date: Sat, 11 Mar 2017 19:25:45 +0100 Subject: [PATCH] Support for an item beeing in multiple groups --HG-- branch : item_group --- .../data/gamedev/interfaces_v3/widgets.xml | 235 ++++++++++++++---- .../src/interface_v3/action_handler_item.cpp | 118 +++++---- code/ryzom/client/src/item_group_manager.cpp | 7 +- code/ryzom/client/src/item_group_manager.h | 4 +- 4 files changed, 262 insertions(+), 102 deletions(-) diff --git a/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml b/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml index 70aea48b1..f94d000d0 100644 --- a/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml +++ b/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml @@ -1819,46 +1819,196 @@ name="uimItemTextEdit" handler="item_text_edition" params="ui:interface:edit_custom" /> + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1870,15 +2020,6 @@ target="ui:interface:item_menu_in_bag:move:pa2:hardtext" /> - - - - - (pMenu->getView("guild")); CViewTextMenu *pMoveToRoom = dynamic_cast(pMenu->getView("room")); CViewTextMenu *pMoveToPa[MAX_INVENTORY_ANIMAL]; - CViewTextMenu *pGroupSubMenu = dynamic_cast(pMenu->getView("item_group")); - CViewTextMenu *pGroupName = dynamic_cast(pMenu->getView("group_name")); - CViewTextMenu *pGroupMoveSubMenu = dynamic_cast(pMenu->getView("group_move")); - CViewTextMenu *pGroupMoveToBag = dynamic_cast(pMenu->getView("group_bag")); - CViewTextMenu *pGroupMoveToGuild = dynamic_cast(pMenu->getView("group_guild")); - CViewTextMenu *pGroupMoveToRoom = dynamic_cast(pMenu->getView("group_room")); - - 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")); CViewTextMenu *pItemTextEdition = dynamic_cast(pMenu->getView("item_text_edition")); - // **** Active Entries // Active Enchant / Reload for a subset of items if(pCrisEnchant) pCrisEnchant->setActive(false); @@ -1790,13 +1779,7 @@ 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(); @@ -1876,11 +1859,9 @@ 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); } @@ -1897,10 +1878,6 @@ 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) pMoveToGuild->setActive(invId==INVENTORIES::bag && invMngr.isInventoryPresent(INVENTORIES::guild)); - if (pGroupMoveToGuild) - pGroupMoveToGuild->setActive(ClientCfg.ItemGroupAllowGuild && invId==INVENTORIES::bag && invMngr.isInventoryPresent(INVENTORIES::guild)); if (pMoveToRoom) pMoveToRoom->setActive(invId==INVENTORIES::bag && invMngr.isInventoryPresent(INVENTORIES::player_room)); - if (pGroupMoveToRoom) - pGroupMoveToRoom->setActive(invId==INVENTORIES::bag && invMngr.isInventoryPresent(INVENTORIES::player_room)); // std case: can drop / destroy if(pDrop) pDrop->setActive(invId!=INVENTORIES::guild); if(pDestroy) pDestroy->setActive(invId!=INVENTORIES::guild); @@ -1930,24 +1899,18 @@ class CHandlerItemMenuCheck : public IActionHandler // hide the move entry completely? bool someMovePossible= false; - bool someGroupMovePossible = false; - if(pMoveSubMenu && pGroupMoveSubMenu) + if(pMoveSubMenu) { if(pMoveToBag) someMovePossible= someMovePossible || pMoveToBag->getActive(); - if(pGroupMoveToBag) someGroupMovePossible= someGroupMovePossible || pGroupMoveToBag->getActive(); for(i=0;igetActive(); - if(pGroupMoveToPa[i]) someGroupMovePossible= someGroupMovePossible || pGroupMoveToPa[i]->getActive(); } if(pMoveToGuild) someMovePossible= someMovePossible || pMoveToGuild->getActive(); if(pMoveToRoom) someMovePossible= someMovePossible || pMoveToRoom->getActive(); - if(pGroupMoveToGuild) someGroupMovePossible= someGroupMovePossible || pGroupMoveToGuild->getActive(); - if(pGroupMoveToRoom) someGroupMovePossible= someGroupMovePossible || (ClientCfg.ItemGroupAllowGuild && pGroupMoveToRoom->getActive()); pMoveSubMenu->setActive(someMovePossible); - pGroupMoveSubMenu->setActive(someGroupMovePossible); } // Equip @@ -2026,12 +1989,10 @@ 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 @@ -2050,17 +2011,57 @@ 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))); } } + //Item GROUP logic + // We go the lazy way here : group move have the same name/active/grayed state as regular move, just copy them. + CViewTextMenu *pGroupSubMenu = dynamic_cast(pMenu->getView("item_group")); + std::vector groupNames = CItemGroupManager::getInstance()->getGroupNames(pCS); + if(pGroupSubMenu) + { + pGroupSubMenu->setActive(!groupNames.empty()); + } + + for(int i=0;i< MAX_DIFFERENT_ITEM_GROUPS; i++) + { + //Disable the submenu if no matching group + + std::string prefix = toString("group%d", i); + CViewTextMenu *pGroupName = dynamic_cast(pMenu->getView(prefix +"_name")); + if(groupNames.size() <= i) + { + pGroupName->setActive(false); + continue; + } + CViewTextMenu *pGroupMoveSubMenu = dynamic_cast(pMenu->getView(prefix + "_move")); + CViewTextMenu *pGroupMoveToBag = dynamic_cast(pMenu->getView(prefix + "_bag")); + CViewTextMenu *pGroupMoveToGuild = dynamic_cast(pMenu->getView(prefix + "_guild")); + CViewTextMenu *pGroupMoveToRoom = dynamic_cast(pMenu->getView(prefix + "_room")); + for(int j=0; j< MAX_INVENTORY_ANIMAL;j++) + { + CViewTextMenu *pGroupMoveToPa = dynamic_cast(pMenu->getView(prefix + toString("_pa%d", j))); + if(pGroupMoveToPa && pMoveToPa[j]) pGroupMoveToPa->setActive(pMoveToPa[j]->getActive()); + if(pGroupMoveToPa && pMoveToPa[j]) pGroupMoveToPa->setGrayed(pMoveToPa[j]->getGrayed()); + if(pGroupMoveToPa && pMoveToPa[j]) pGroupMoveToPa->setName(pMoveToPa[j]->getName()); + } + if(pGroupName) pGroupName->setHardText(groupNames[i]); + if(pMoveSubMenu && pGroupMoveSubMenu) pGroupMoveSubMenu->setActive(pMoveSubMenu->getActive()); + if(pMoveToBag && pGroupMoveToBag) pGroupMoveToBag->setActive(pMoveToBag->getActive()); + if(pMoveToGuild && pGroupMoveToGuild) pGroupMoveToGuild->setActive(pMoveToGuild->getActive()); + if(pMoveToRoom && pGroupMoveToRoom) pGroupMoveToRoom->setActive(pMoveToRoom->getActive()); + if(pMoveSubMenu && pGroupMoveSubMenu) pGroupMoveSubMenu->setGrayed(pMoveSubMenu->getGrayed()); + if(pMoveToBag && pGroupMoveToBag) pGroupMoveToBag->setGrayed(pMoveToBag->getGrayed()); + if(pMoveToGuild && pGroupMoveToGuild) pGroupMoveToGuild->setGrayed(pMoveToGuild->getGrayed()); + if(pMoveToRoom && pGroupMoveToRoom) pGroupMoveToRoom->setGrayed(pMoveToRoom->getGrayed()); + } + + } }; REGISTER_ACTION_HANDLER( CHandlerItemMenuCheck, "item_menu_check" ); @@ -2306,13 +2307,21 @@ class CHandlerItemGroupMove : public IActionHandler nlinfo("Wrong cast"); return; } - std::string groupName = CItemGroupManager::getInstance()->getGroupName(pCS); - if(groupName.empty()) + uint32 groupIndex; + fromString(getParam(sParams, "groupIndex"), groupIndex); + std::string destination = getParam(sParams, "destination"); + std::vector possibleGroups = CItemGroupManager::getInstance()->getGroupNames(pCS); + if(possibleGroups.empty()) { nlinfo("Trying to move a group with a caller not part of any group"); return; } - CItemGroupManager::getInstance()->moveGroup(groupName, INVENTORIES::toInventory(sParams)); + if(possibleGroups.size() <= groupIndex) + { + nlwarning("groupIndex > possiblesGroups, shouldn't happen"); + return; + } + CItemGroupManager::getInstance()->moveGroup(possibleGroups[groupIndex], INVENTORIES::toInventory(destination)); } }; REGISTER_ACTION_HANDLER(CHandlerItemGroupMove, "item_group_move"); @@ -2321,7 +2330,7 @@ REGISTER_ACTION_HANDLER(CHandlerItemGroupMove, "item_group_move"); // *************************************************************************** class CHandlerItemGroupEquip : public IActionHandler { - void execute (CCtrlBase *caller, const std::string &/* sParams */) + void execute (CCtrlBase *caller, const std::string & sParams) { CDBCtrlSheet* pCS = dynamic_cast(caller); if(!pCS) @@ -2329,13 +2338,20 @@ class CHandlerItemGroupEquip : public IActionHandler nlinfo("Wrong cast"); return; } - std::string groupName = CItemGroupManager::getInstance()->getGroupName(pCS); - if(groupName.empty()) + uint32 groupIndex; + fromString(getParam(sParams, "groupIndex"), groupIndex); + std::vector possibleGroups = CItemGroupManager::getInstance()->getGroupNames(pCS); + if(possibleGroups.empty()) { nlinfo("Trying to move a group with a caller not part of any group"); return; } - CItemGroupManager::getInstance()->equipGroup(groupName); + if(possibleGroups.size() <= groupIndex) + { + nlwarning("groupIndex > possiblesGroups, shouldn't happen"); + return; + } + CItemGroupManager::getInstance()->equipGroup(possibleGroups[groupIndex]); } }; 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 2d790c4f4..5509ca1c8 100644 --- a/code/ryzom/client/src/item_group_manager.cpp +++ b/code/ryzom/client/src/item_group_manager.cpp @@ -413,16 +413,17 @@ void CItemGroupManager::listGroup() //Used by AH -std::string CItemGroupManager::getGroupName(CDBCtrlSheet* pCS) +std::vector CItemGroupManager::getGroupNames(CDBCtrlSheet* pCS) { + std::vector out; for(int i=0;i<_Groups.size();i++) { CItemGroup group = _Groups[i]; if(group.contains(pCS)) - return group.name; + out.push_back(group.name); } - return ""; + return out; } //Private methods diff --git a/code/ryzom/client/src/item_group_manager.h b/code/ryzom/client/src/item_group_manager.h index daeefea51..683344719 100644 --- a/code/ryzom/client/src/item_group_manager.h +++ b/code/ryzom/client/src/item_group_manager.h @@ -22,6 +22,8 @@ #include "interface_v3/dbctrl_sheet.h" #include "game_share/inventories.h" +#define MAX_DIFFERENT_ITEM_GROUPS 5 //How many differents item grousp can a single item be part of +// If you change this, remember to modify widgets.xml accordingly struct CInventoryItem { public: CDBCtrlSheet* pCS; @@ -84,7 +86,7 @@ public: bool createGroup(std::string name); bool deleteGroup(std::string name); void listGroup(); - std::string getGroupName(CDBCtrlSheet *pCS); + std::vector getGroupNames(CDBCtrlSheet *pCS); private: CItemGroup* findGroup(std::string name);