Support unlimited number of items group (and in a clean way)

--HG--
branch : item_group
This commit is contained in:
Guillaume Dupuy 2017-03-16 00:58:32 +01:00
parent c2049935a4
commit 11eeafc12d
5 changed files with 82 additions and 248 deletions

View file

@ -1819,196 +1819,13 @@
name="uimItemTextEdit"
handler="item_text_edition"
params="ui:interface:edit_custom" />
<!-- TODO glorf : ugly because i haven't found a way to do template with actions inside ... -->
<action id="item_group"
name="uiGroup">
<action id="group0_name"
name="you should not see this ingame">
<action id="group0_equip"
name="uimEquip"
handler="item_group_equip"
params="groupIndex=0" />
<action id="group0_move"
name="uimMoveTo">
<action id="group0_bag"
name="uimMtBag"
handler="item_group_move"
params="groupIndex=0|destination=bag" />
<action id="group0_pa0"
name="uimMtPaMount0"
handler="item_group_move"
params="groupIndex=0|destination=pet_animal1" /><!-- Offset because they are named petanimal1/2/3/4 in Inventories::TEnumType -->
<action id="group0_pa1"
name="uimMtPaMount1"
handler="item_group_move"
params="groupIndex=0|destination=pet_animal2" />
<action id="group0_pa2"
name="uimMtPaMount2"
handler="item_group_move"
params="groupIndex=0|destination=pet_animal3" />
<action id="group0_pa3"
name="uimMtPaMount3"
handler="item_group_move"
params="groupIndex=0|destination=pet_animal4" />
<action id="group0_room"
name="uimMtRoom"
handler="item_group_move"
params="groupIndex=0|destination=player_room" />
<action id="group0_guild"
name="uimMtGuild"
handler="item_group_move"
params="groupIndex=0|destination=guild" /> </action> <!-- MOVE -->
</action> <!--group0 -->
<action id="group1_name"
name="you should not see this ingame">
<action id="group1_equip"
name="uimEquip"
handler="item_group_equip"
params="groupIndex=1" />
<action id="group1_move"
name="uimMoveTo">
<action id="group1_bag"
name="uimMtBag"
handler="item_group_move"
params="groupIndex=1|destination=bag" />
<action id="group1_pa0"
name="uimMtPaMount0"
handler="item_group_move"
params="groupIndex=1|destination=pet_animal1" /><!-- Offset because they are named petanimal1/2/3/4 in Inventories::TEnumType -->
<action id="group1_pa1"
name="uimMtPaMount1"
handler="item_group_move"
params="groupIndex=1|destination=pet_animal2" />
<action id="group1_pa2"
name="uimMtPaMount2"
handler="item_group_move"
params="groupIndex=1|destination=pet_animal3" />
<action id="group1_pa3"
name="uimMtPaMount3"
handler="item_group_move"
params="groupIndex=1|destination=pet_animal4" />
<action id="group1_room"
name="uimMtRoom"
handler="item_group_move"
params="groupIndex=1|destination=player_room" />
<action id="group1_guild"
name="uimMtGuild"
handler="item_group_move"
params="groupIndex=1|destination=guild" /> </action> <!-- MOVE -->
</action> <!-- group1 -->
<action id="group2_name"
name="you should not see this ingame">
<action id="group2_equip"
name="uimEquip"
handler="item_group_equip"
params="groupIndex=2" />
<action id="group2_move"
name="uimMoveTo">
<action id="group2_bag"
name="uimMtBag"
handler="item_group_move"
params="groupIndex=2|destination=bag" />
<action id="group2_pa0"
name="uimMtPaMount0"
handler="item_group_move"
params="groupIndex=2|destination=pet_animal1" /><!-- Offset because they are named petanimal1/2/3/4 in Inventories::TEnumType -->
<action id="group2_pa1"
name="uimMtPaMount1"
handler="item_group_move"
params="groupIndex=2|destination=pet_animal2" />
<action id="group2_pa2"
name="uimMtPaMount2"
handler="item_group_move"
params="groupIndex=2|destination=pet_animal3" />
<action id="group2_pa3"
name="uimMtPaMount3"
handler="item_group_move"
params="groupIndex=2|destination=pet_animal4" />
<action id="group2_room"
name="uimMtRoom"
handler="item_group_move"
params="groupIndex=2|destination=player_room" />
<action id="group2_guild"
name="uimMtGuild"
handler="item_group_move"
params="groupIndex=2|destination=guild" /> </action> <!-- MOVE -->
</action> <!-- group2 -->
<action id="group3_name"
name="you should not see this ingame">
<action id="group3_equip"
name="uimEquip"
handler="item_group_equip"
params="groupIndex=3" />
<action id="group3_move"
name="uimMoveTo">
<action id="group3_bag"
name="uimMtBag"
handler="item_group_move"
params="groupIndex=3|destination=bag" />
<action id="group3_pa0"
name="uimMtPaMount0"
handler="item_group_move"
params="groupIndex=3|destination=pet_animal1" /><!-- Offset because they are named petanimal1/2/3/4 in Inventories::TEnumType -->
<action id="group3_pa1"
name="uimMtPaMount1"
handler="item_group_move"
params="groupIndex=3|destination=pet_animal2" />
<action id="group3_pa2"
name="uimMtPaMount2"
handler="item_group_move"
params="groupIndex=3|destination=pet_animal3" />
<action id="group3_pa3"
name="uimMtPaMount3"
handler="item_group_move"
params="groupIndex=3|destination=pet_animal4" />
<action id="group3_room"
name="uimMtRoom"
handler="item_group_move"
params="groupIndex=3|destination=player_room" />
<action id="group3_guild"
name="uimMtGuild"
handler="item_group_move"
params="groupIndex=3|destination=guild" /> </action> <!-- MOVE -->
</action> <!-- group3 -->
<action id="group4_name"
name="you should not see this ingame">
<action id="group4_equip"
name="uimEquip"
handler="item_group_equip"
params="groupIndex=4" />
<action id="group4_move"
name="uimMoveTo">
<action id="group4_bag"
name="uimMtBag"
handler="item_group_move"
params="groupIndex=4|destination=bag" />
<!-- name is correctly set in code based on corresponding regular move -->
<action id="group4_pa0"
name="uimMtPaMount0"
handler="item_group_move"
params="groupIndex=4|destination=pet_animal1" /><!-- Offset because they are named petanimal1/2/3/4 in Inventories::TEnumType -->
<action id="group4_pa1"
name="uimMtPaMount1"
handler="item_group_move"
params="groupIndex=4|destination=pet_animal2" />
<action id="group4_pa2"
name="uimMtPaMount2"
handler="item_group_move"
params="groupIndex=4|destination=pet_animal3" />
<action id="group4_pa3"
name="uimMtPaMount3"
handler="item_group_move"
params="groupIndex=4|destination=pet_animal4" />
<action id="group4_room"
name="uimMtRoom"
handler="item_group_move"
params="groupIndex=4|destination=player_room" />
<action id="group4_guild"
name="uimMtGuild"
handler="item_group_move"
params="groupIndex=4|destination=guild" /> </action> <!-- MOVE -->
</action> <!-- group4 -->
</action> <!-- item_group -->
name="uimGroup" />
<!-- Will be activated and populated in code -->
<group type="menu"
id="item_group_menu"
extends="base_menu">
</group>
</group>
<!-- MAX_INVENTORY_ANIMAL -->

View file

@ -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<CViewTextMenu*>(pMenu->getView("item_group"));
CGroupMenu *pGroupRootMenu = dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:item_menu_in_bag:item_group_menu"));
if(pGroupRootMenu)
{
CGroupSubMenu *pGroupMenu = pGroupRootMenu->getRootMenu();
std::vector<std::string> groupNames = CItemGroupManager::getInstance()->getGroupNames(pCS);
if(pGroupSubMenu)
CViewText *pGroup = dynamic_cast<CViewText*>(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)
{
pGroupSubMenu->setActive(!groupNames.empty());
if(groupNames.empty())
{
pGroup->setActive(false);
}
for(int i=0;i< MAX_DIFFERENT_ITEM_GROUPS; i++)
else
{
//Disable the submenu if no matching group
std::string prefix = toString("group%d", i);
CViewTextMenu *pGroupName = dynamic_cast<CViewTextMenu*>(pMenu->getView(prefix +"_name"));
if(groupNames.size() <= i)
{
pGroupName->setActive(false);
continue;
pGroup->setActive(true);
}
}
//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<groupNames.size(); i++)
{
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());
}
CViewTextMenu *pGroupMoveSubMenu = dynamic_cast<CViewTextMenu*>(pMenu->getView(prefix + "_move"));
CViewTextMenu *pGroupMoveToBag = dynamic_cast<CViewTextMenu*>(pMenu->getView(prefix + "_bag"));
CViewTextMenu *pGroupMoveToGuild = dynamic_cast<CViewTextMenu*>(pMenu->getView(prefix + "_guild"));
CViewTextMenu *pGroupMoveToRoom = dynamic_cast<CViewTextMenu*>(pMenu->getView(prefix + "_room"));
for(int j=0;j< MAX_INVENTORY_ANIMAL; j++)
{
CViewTextMenu *pGroupMoveToPa = dynamic_cast<CViewTextMenu*>(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(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<std::string> 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<std::string> 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");

View file

@ -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 )

View file

@ -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<CGroupMenu*>(pWM->getElementFromId("ui:interface:item_menu_in_bag"));
CGroupSubMenu *pMenu = pRootMenu->getRootMenu();
//get item subgroup
CGroupMenu *pGroupMenu = dynamic_cast<CGroupMenu*>(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()

View file

@ -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;