From 11eeafc12d5cca3199cab9df2ee73880631a4063 Mon Sep 17 00:00:00 2001 From: Guillaume Dupuy Date: Thu, 16 Mar 2017 00:58:32 +0100 Subject: [PATCH] Support unlimited number of items group (and in a clean way) --HG-- branch : item_group --- .../data/gamedev/interfaces_v3/widgets.xml | 195 +----------------- .../src/interface_v3/action_handler_item.cpp | 120 ++++++----- .../src/interface_v3/interface_manager.cpp | 1 - code/ryzom/client/src/item_group_manager.cpp | 12 ++ code/ryzom/client/src/item_group_manager.h | 2 - 5 files changed, 82 insertions(+), 248 deletions(-) diff --git a/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml b/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml index f94d000d0..193678ec8 100644 --- a/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml +++ b/code/ryzom/client/data/gamedev/interfaces_v3/widgets.xml @@ -1819,196 +1819,13 @@ name="uimItemTextEdit" handler="item_text_edition" params="ui:interface:edit_custom" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + name="uimGroup" /> + + + 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 54bf61f24..634f987cf 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_item.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_item.cpp @@ -2020,48 +2020,68 @@ class CHandlerItemMenuCheck : public IActionHandler } //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) + CGroupMenu *pGroupRootMenu = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:item_menu_in_bag:item_group_menu")); + if(pGroupRootMenu) { - 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) + CGroupSubMenu *pGroupMenu = pGroupRootMenu->getRootMenu(); + std::vector groupNames = CItemGroupManager::getInstance()->getGroupNames(pCS); + CViewText *pGroup = dynamic_cast(pMenu->getView("item_group")); + //First, hide/show the menu if pertinent (we need to hide the action due to it beeing a submenu) + if(pGroup) { - pGroupName->setActive(false); - continue; + if(groupNames.empty()) + { + pGroup->setActive(false); + } + else + { + pGroup->setActive(true); + } } - 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++) + //Reset everything and recreate the submenu for current item + // We do it the lazy way : active/gray options matching regular options (when you do things on a single item) + // Same for translated name of interface + pGroupMenu->reset(); + for(i=0; i(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()); + std::string name = groupNames[i]; + std::string ahParams = "name=" + name; + pGroupMenu->addLine(ucstring(name), "", "", name); + CGroupSubMenu* pNewSubMenu = new CGroupSubMenu(CViewBase::TCtorParam()); + pGroupMenu->setSubMenu(pGroupMenu->getNumLine()-1, pNewSubMenu); + if(pNewSubMenu) + { + if(pEquip) + pNewSubMenu->addLine(pEquip->getHardText(), "item_group_equip", ahParams, name + "_equip"); + if(pMoveToBag && pMoveToBag->getActive()) + { + CViewTextMenu* tmp = pNewSubMenu->addLine(pMoveToBag->getHardText(),"item_group_move", "destination=bag|" + ahParams, name + "_bag"); + if(tmp) tmp->setGrayed(pMoveToBag->getGrayed()); + } + for(int j=0;j< MAX_INVENTORY_ANIMAL; j++) + { + if(pMoveToPa[j] && pMoveToPa[j]->getActive()) + { + //there is an offset of 1 because TInventory names are pet_animal1/2/3/4 + std::string dst = toString("destination=pet_animal%d|", j + 1); + CViewTextMenu* tmp = pNewSubMenu->addLine(ucstring(pMoveToPa[j]->getHardText()),"item_group_move", dst + ahParams, name + toString("_pa%d", j + 1)); + if(tmp) tmp->setGrayed(pMoveToPa[j]->getGrayed()); + } + } + if(pMoveToRoom && pMoveToRoom->getActive()) + { + CViewTextMenu* tmp = pNewSubMenu->addLine(pMoveToRoom->getHardText(), "item_group_move", "destination=player_room|" + ahParams, name + "_room"); + if(tmp) tmp->setGrayed(pMoveToRoom->getGrayed()); + } + if(pMoveToGuild && pMoveToGuild->getActive()) + { + CViewTextMenu* tmp = pNewSubMenu->addLine(pMoveToGuild->getHardText(),"item_group_move", "destination=guild|" + ahParams, name + "_guild"); + if(tmp) tmp->setGrayed(pMoveToRoom->getGrayed()); + } + } } - 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" ); @@ -2307,21 +2327,15 @@ class CHandlerItemGroupMove : public IActionHandler nlinfo("Wrong cast"); return; } - uint32 groupIndex; - fromString(getParam(sParams, "groupIndex"), groupIndex); std::string destination = getParam(sParams, "destination"); - std::vector possibleGroups = CItemGroupManager::getInstance()->getGroupNames(pCS); - if(possibleGroups.empty()) + std::string name = getParam(sParams, "name"); + if(name.empty()) { nlinfo("Trying to move a group with a caller not part of any group"); return; } - if(possibleGroups.size() <= groupIndex) - { - nlwarning("groupIndex > possiblesGroups, shouldn't happen"); - return; - } - CItemGroupManager::getInstance()->moveGroup(possibleGroups[groupIndex], INVENTORIES::toInventory(destination)); + + CItemGroupManager::getInstance()->moveGroup(name, INVENTORIES::toInventory(destination)); } }; REGISTER_ACTION_HANDLER(CHandlerItemGroupMove, "item_group_move"); @@ -2338,20 +2352,14 @@ class CHandlerItemGroupEquip : public IActionHandler nlinfo("Wrong cast"); return; } - uint32 groupIndex; - fromString(getParam(sParams, "groupIndex"), groupIndex); - std::vector possibleGroups = CItemGroupManager::getInstance()->getGroupNames(pCS); - if(possibleGroups.empty()) + std::string name = getParam(sParams, "name"); + if(name.empty()) { nlinfo("Trying to move a group with a caller not part of any group"); return; } - if(possibleGroups.size() <= groupIndex) - { - nlwarning("groupIndex > possiblesGroups, shouldn't happen"); - return; - } - CItemGroupManager::getInstance()->equipGroup(possibleGroups[groupIndex]); + + CItemGroupManager::getInstance()->equipGroup(name); } }; REGISTER_ACTION_HANDLER(CHandlerItemGroupEquip, "item_group_equip"); diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index 413b8bcc5..94ffeb989 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -2997,7 +2997,6 @@ void CInterfaceManager::initEmotes() uint32 nEmoteNb = (*it).EmoteId; string sState = (*it).Anim; string sName = (*it).Path; - // Check that the emote can be added to UI // --------------------------------------- if( (*it).UsableFromClientUI == false ) diff --git a/code/ryzom/client/src/item_group_manager.cpp b/code/ryzom/client/src/item_group_manager.cpp index 5509ca1c8..420f71324 100644 --- a/code/ryzom/client/src/item_group_manager.cpp +++ b/code/ryzom/client/src/item_group_manager.cpp @@ -28,6 +28,7 @@ #include "connection.h" // Used to access PlayerSelectedFileName for xml filename #include "nel/gui/db_manager.h" #include "interface_v3/interface_manager.h" +#include "nel/gui/group_menu.h" CItemGroupManager *CItemGroupManager::_Instance = NULL; CItemGroup::CItemGroup() @@ -164,6 +165,17 @@ CItemGroupManager::CItemGroupManager() void CItemGroupManager::init() { loadGroups(); + //attach item group subgroup to right-click in bag group + CWidgetManager* pWM = CWidgetManager::getInstance(); + CGroupMenu *pRootMenu = dynamic_cast(pWM->getElementFromId("ui:interface:item_menu_in_bag")); + CGroupSubMenu *pMenu = pRootMenu->getRootMenu(); + //get item subgroup + CGroupMenu *pGroupMenu = dynamic_cast(pWM->getElementFromId("ui:interface:item_menu_in_bag:item_group_menu")); + CGroupSubMenu *pGroupSubMenu = pGroupMenu->getRootMenu(); + if(pMenu && pGroupSubMenu) + pMenu->setSubMenu(pMenu->getNumLine() - 1, pGroupSubMenu); + else + nlinfo("Couldn't update yet, maybe wait a little bit ?"); } void CItemGroupManager::uninit() diff --git a/code/ryzom/client/src/item_group_manager.h b/code/ryzom/client/src/item_group_manager.h index 683344719..1655eb477 100644 --- a/code/ryzom/client/src/item_group_manager.h +++ b/code/ryzom/client/src/item_group_manager.h @@ -22,8 +22,6 @@ #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;