Support for an item beeing in multiple groups

--HG--
branch : item_group
This commit is contained in:
Guillaume Dupuy 2017-03-11 19:25:45 +01:00
parent 5dcc7932ff
commit c2049935a4
4 changed files with 262 additions and 102 deletions

View file

@ -1819,46 +1819,196 @@
name="uimItemTextEdit" name="uimItemTextEdit"
handler="item_text_edition" handler="item_text_edition"
params="ui:interface:edit_custom" /> 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" <action id="item_group"
name="uiGroup"> name="uiGroup">
<action id="group_name" /> <action id="group0_name"
<action id="group_equip" name="you should not see this ingame">
name="uimEquip" <action id="group0_equip"
handler="item_group_equip"/> name="uimEquip"
<action id="group_move" handler="item_group_equip"
name="uimMoveTo"> params="groupIndex=0" />
<action id="group_bag" <action id="group0_move"
name="uimMtBag" name="uimMoveTo">
handler="item_group_move" <action id="group0_bag"
params="bag" /> name="uimMtBag"
<action id="group_pa0" handler="item_group_move"
name="uimMtPaMount0" params="groupIndex=0|destination=bag" />
handler="item_group_move" <action id="group0_pa0"
params="pet_animal1" /> <!-- Offset because they are named petanimal1/2/3/4 in Inventories::TEnumType --> name="uimMtPaMount0"
<action id="group_pa1" handler="item_group_move"
name="uimMtPaMount1" params="groupIndex=0|destination=pet_animal1" /><!-- Offset because they are named petanimal1/2/3/4 in Inventories::TEnumType -->
handler="item_group_move" <action id="group0_pa1"
params="pet_animal2" /> name="uimMtPaMount1"
<action id="group_pa2" handler="item_group_move"
name="uimMtPaMount2" params="groupIndex=0|destination=pet_animal2" />
handler="item_group_move" <action id="group0_pa2"
params="pet_animal3" /> name="uimMtPaMount2"
<action id="group_pa3" handler="item_group_move"
name="uimMtPaMount3" params="groupIndex=0|destination=pet_animal3" />
handler="item_group_move" <action id="group0_pa3"
params="pet_animal4" /> name="uimMtPaMount3"
<action id="group_room" handler="item_group_move"
name="uimMtRoom" params="groupIndex=0|destination=pet_animal4" />
handler="item_group_move" <action id="group0_room"
params="player_room" /> name="uimMtRoom"
<action id="group_guild" handler="item_group_move"
name="uimMtGuild" params="groupIndex=0|destination=player_room" />
handler="item_group_move" <action id="group0_guild"
params="guild" /> name="uimMtGuild"
handler="item_group_move"
</action> params="groupIndex=0|destination=guild" /> </action> <!-- MOVE -->
<!-- move !--> </action> <!--group0 -->
</action> <!-- item_group !--> <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 -->
</group> </group>
<!-- MAX_INVENTORY_ANIMAL --> <!-- MAX_INVENTORY_ANIMAL -->
@ -1870,15 +2020,6 @@
target="ui:interface:item_menu_in_bag:move:pa2:hardtext" /> target="ui:interface:item_menu_in_bag:move:pa2:hardtext" />
<link expr="switch(@%pa_beast3:TYPE, 'uimMtPaMount3', 'uimMtPaMount3', 'uimMtPaPacker3', 'uimMtPaDemon3')" <link expr="switch(@%pa_beast3:TYPE, 'uimMtPaMount3', 'uimMtPaMount3', 'uimMtPaPacker3', 'uimMtPaDemon3')"
target="ui:interface:item_menu_in_bag:move:pa3:hardtext" /> target="ui:interface:item_menu_in_bag:move:pa3:hardtext" />
<!-- Item group submenu -->
<link expr="switch(@%pa_beast0:TYPE, 'uimMtPaMount0', 'uimMtPaMount0', 'uimMtPaPacker0', 'uimMtPaDemon0')"
target="ui:interface:item_menu_in_bag:item_group:group_move:group_pa0:hardtext" />
<link expr="switch(@%pa_beast1:TYPE, 'uimMtPaMount1', 'uimMtPaMount1', 'uimMtPaPacker1', 'uimMtPaDemon1')"
target="ui:interface:item_menu_in_bag:item_group:group_move:group_pa1:hardtext" />
<link expr="switch(@%pa_beast2:TYPE, 'uimMtPaMount2', 'uimMtPaMount2', 'uimMtPaPacker2', 'uimMtPaDemon2')"
target="ui:interface:item_menu_in_bag:item_group:group_move:group_pa2:hardtext" />
<link expr="switch(@%pa_beast3:TYPE, 'uimMtPaMount3', 'uimMtPaMount3', 'uimMtPaPacker3', 'uimMtPaDemon3')"
target="ui:interface:item_menu_in_bag:item_group:group_move:group_pa3:hardtext" />
<!-- item menu when we are in self --> <!-- item menu when we are in self -->
<group type="menu" <group type="menu"
id="item_menu_in_self" id="item_menu_in_self"

View file

@ -1758,28 +1758,17 @@ class CHandlerItemMenuCheck : public IActionHandler
CViewTextMenu *pMoveToGuild = dynamic_cast<CViewTextMenu*>(pMenu->getView("guild")); CViewTextMenu *pMoveToGuild = dynamic_cast<CViewTextMenu*>(pMenu->getView("guild"));
CViewTextMenu *pMoveToRoom = dynamic_cast<CViewTextMenu*>(pMenu->getView("room")); CViewTextMenu *pMoveToRoom = dynamic_cast<CViewTextMenu*>(pMenu->getView("room"));
CViewTextMenu *pMoveToPa[MAX_INVENTORY_ANIMAL]; CViewTextMenu *pMoveToPa[MAX_INVENTORY_ANIMAL];
CViewTextMenu *pGroupSubMenu = dynamic_cast<CViewTextMenu*>(pMenu->getView("item_group"));
CViewTextMenu *pGroupName = dynamic_cast<CViewTextMenu*>(pMenu->getView("group_name"));
CViewTextMenu *pGroupMoveSubMenu = dynamic_cast<CViewTextMenu*>(pMenu->getView("group_move"));
CViewTextMenu *pGroupMoveToBag = dynamic_cast<CViewTextMenu*>(pMenu->getView("group_bag"));
CViewTextMenu *pGroupMoveToGuild = dynamic_cast<CViewTextMenu*>(pMenu->getView("group_guild"));
CViewTextMenu *pGroupMoveToRoom = dynamic_cast<CViewTextMenu*>(pMenu->getView("group_room"));
CViewTextMenu *pGroupMoveToPa[MAX_INVENTORY_ANIMAL];
bool bIsLockedByOwner = pCS->getLockedByOwner(); bool bIsLockedByOwner = pCS->getLockedByOwner();
for(i=0;i<MAX_INVENTORY_ANIMAL;i++) for(i=0;i<MAX_INVENTORY_ANIMAL;i++)
{ {
pMoveToPa[i]= dynamic_cast<CViewTextMenu*>(pMenu->getView(toString("pa%d", i))); pMoveToPa[i]= dynamic_cast<CViewTextMenu*>(pMenu->getView(toString("pa%d", i)));
pGroupMoveToPa[i]= dynamic_cast<CViewTextMenu*>(pMenu->getView(toString("group_pa%d", i)));
} }
CViewTextMenu *pItemInfos = dynamic_cast<CViewTextMenu*>(pMenu->getView("infos")); CViewTextMenu *pItemInfos = dynamic_cast<CViewTextMenu*>(pMenu->getView("infos"));
CViewTextMenu *pItemTextDisplay = dynamic_cast<CViewTextMenu*>(pMenu->getView("item_text_display")); CViewTextMenu *pItemTextDisplay = dynamic_cast<CViewTextMenu*>(pMenu->getView("item_text_display"));
CViewTextMenu *pItemTextEdition = dynamic_cast<CViewTextMenu*>(pMenu->getView("item_text_edition")); CViewTextMenu *pItemTextEdition = dynamic_cast<CViewTextMenu*>(pMenu->getView("item_text_edition"));
// **** Active Entries // **** Active Entries
// Active Enchant / Reload for a subset of items // Active Enchant / Reload for a subset of items
if(pCrisEnchant) pCrisEnchant->setActive(false); if(pCrisEnchant) pCrisEnchant->setActive(false);
@ -1790,13 +1779,7 @@ class CHandlerItemMenuCheck : public IActionHandler
if(pItemTextDisplay) pItemTextDisplay->setActive(false); if(pItemTextDisplay) pItemTextDisplay->setActive(false);
if(pItemTextEdition) pItemTextEdition->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); if(pLockUnlock) pLockUnlock->setActive(true);
const CItemSheet *pIS = pCS->asItemSheet(); const CItemSheet *pIS = pCS->asItemSheet();
@ -1876,11 +1859,9 @@ class CHandlerItemMenuCheck : public IActionHandler
{ {
// cannot move to other animals! :) // cannot move to other animals! :)
if(pMoveToBag) pMoveToBag->setActive(false); if(pMoveToBag) pMoveToBag->setActive(false);
if(pGroupMoveToBag) pGroupMoveToBag->setActive(false);
for(i=0;i<MAX_INVENTORY_ANIMAL;i++) for(i=0;i<MAX_INVENTORY_ANIMAL;i++)
{ {
if(pMoveToPa[i]) pMoveToPa[i]->setActive(false); if(pMoveToPa[i]) pMoveToPa[i]->setActive(false);
if(pGroupMoveToPa[i]) pGroupMoveToPa[i]->setActive(false);
} }
@ -1897,10 +1878,6 @@ class CHandlerItemMenuCheck : public IActionHandler
pMoveToBag->setActive( invId!=INVENTORIES::bag && pMoveToBag->setActive( invId!=INVENTORIES::bag &&
invMngr.isInventoryPresent(INVENTORIES::bag) && invMngr.isInventoryPresent(INVENTORIES::bag) &&
(invId!=INVENTORIES::guild || invMngr.isInventoryPresent(INVENTORIES::guild)) ); (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;i<MAX_INVENTORY_ANIMAL;i++) for(i=0;i<MAX_INVENTORY_ANIMAL;i++)
{ {
@ -1908,20 +1885,12 @@ class CHandlerItemMenuCheck : public IActionHandler
pMoveToPa[i]->setActive(invId!=INVENTORIES::guild && pMoveToPa[i]->setActive(invId!=INVENTORIES::guild &&
(uint)invId!=INVENTORIES::pet_animal+i && (uint)invId!=INVENTORIES::pet_animal+i &&
invMngr.isInventoryPresent((INVENTORIES::TInventory)(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) if (pMoveToGuild)
pMoveToGuild->setActive(invId==INVENTORIES::bag && invMngr.isInventoryPresent(INVENTORIES::guild)); pMoveToGuild->setActive(invId==INVENTORIES::bag && invMngr.isInventoryPresent(INVENTORIES::guild));
if (pGroupMoveToGuild)
pGroupMoveToGuild->setActive(ClientCfg.ItemGroupAllowGuild && invId==INVENTORIES::bag && invMngr.isInventoryPresent(INVENTORIES::guild));
if (pMoveToRoom) if (pMoveToRoom)
pMoveToRoom->setActive(invId==INVENTORIES::bag && invMngr.isInventoryPresent(INVENTORIES::player_room)); 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 // std case: can drop / destroy
if(pDrop) pDrop->setActive(invId!=INVENTORIES::guild); if(pDrop) pDrop->setActive(invId!=INVENTORIES::guild);
if(pDestroy) pDestroy->setActive(invId!=INVENTORIES::guild); if(pDestroy) pDestroy->setActive(invId!=INVENTORIES::guild);
@ -1930,24 +1899,18 @@ class CHandlerItemMenuCheck : public IActionHandler
// hide the move entry completely? // hide the move entry completely?
bool someMovePossible= false; bool someMovePossible= false;
bool someGroupMovePossible = false; if(pMoveSubMenu)
if(pMoveSubMenu && pGroupMoveSubMenu)
{ {
if(pMoveToBag) someMovePossible= someMovePossible || pMoveToBag->getActive(); if(pMoveToBag) someMovePossible= someMovePossible || pMoveToBag->getActive();
if(pGroupMoveToBag) someGroupMovePossible= someGroupMovePossible || pGroupMoveToBag->getActive();
for(i=0;i<MAX_INVENTORY_ANIMAL;i++) for(i=0;i<MAX_INVENTORY_ANIMAL;i++)
{ {
if(pMoveToPa[i]) someMovePossible= someMovePossible || pMoveToPa[i]->getActive(); if(pMoveToPa[i]) someMovePossible= someMovePossible || pMoveToPa[i]->getActive();
if(pGroupMoveToPa[i]) someGroupMovePossible= someGroupMovePossible || pGroupMoveToPa[i]->getActive();
} }
if(pMoveToGuild) someMovePossible= someMovePossible || pMoveToGuild->getActive(); if(pMoveToGuild) someMovePossible= someMovePossible || pMoveToGuild->getActive();
if(pMoveToRoom) someMovePossible= someMovePossible || pMoveToRoom->getActive(); if(pMoveToRoom) someMovePossible= someMovePossible || pMoveToRoom->getActive();
if(pGroupMoveToGuild) someGroupMovePossible= someGroupMovePossible || pGroupMoveToGuild->getActive();
if(pGroupMoveToRoom) someGroupMovePossible= someGroupMovePossible || (ClientCfg.ItemGroupAllowGuild && pGroupMoveToRoom->getActive());
pMoveSubMenu->setActive(someMovePossible); pMoveSubMenu->setActive(someMovePossible);
pGroupMoveSubMenu->setActive(someGroupMovePossible);
} }
// Equip // Equip
@ -2026,12 +1989,10 @@ class CHandlerItemMenuCheck : public IActionHandler
if(pLockUnlock) pLockUnlock->setGrayed(true); if(pLockUnlock) pLockUnlock->setGrayed(true);
if(pMoveSubMenu) pMoveSubMenu->setGrayed(true); if(pMoveSubMenu) pMoveSubMenu->setGrayed(true);
if(pMoveToBag) pMoveToBag->setGrayed(true); if(pMoveToBag) pMoveToBag->setGrayed(true);
if(pGroupMoveToBag) pGroupMoveToBag->setGrayed(true);
for(i=0;i<MAX_INVENTORY_ANIMAL;i++) for(i=0;i<MAX_INVENTORY_ANIMAL;i++)
{ {
if(pMoveToPa[i]) pMoveToPa[i]->setGrayed(true); if(pMoveToPa[i]) pMoveToPa[i]->setGrayed(true);
if(pGroupMoveToPa[i]) pGroupMoveToPa[i]->setGrayed(true);
} }
} }
// Gray Text entries according to Availables Destinations // Gray Text entries according to Availables Destinations
@ -2050,17 +2011,57 @@ class CHandlerItemMenuCheck : public IActionHandler
// check each inventory dest if available // check each inventory dest if available
if(pMoveToBag) pMoveToBag->setGrayed(!invMngr.isInventoryAvailable(INVENTORIES::bag)); if(pMoveToBag) pMoveToBag->setGrayed(!invMngr.isInventoryAvailable(INVENTORIES::bag));
if(pGroupMoveToBag) pGroupMoveToBag->setGrayed(!invMngr.isInventoryAvailable(INVENTORIES::bag));
for(i=0;i<MAX_INVENTORY_ANIMAL;i++) for(i=0;i<MAX_INVENTORY_ANIMAL;i++)
{ {
if(pMoveToPa[i]) pMoveToPa[i]->setGrayed(!invMngr.isInventoryAvailable( if(pMoveToPa[i]) pMoveToPa[i]->setGrayed(!invMngr.isInventoryAvailable(
(INVENTORIES::TInventory)(INVENTORIES::pet_animal+i))); (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<CViewTextMenu*>(pMenu->getView("item_group"));
std::vector<std::string> 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<CViewTextMenu*>(pMenu->getView(prefix +"_name"));
if(groupNames.size() <= i)
{
pGroupName->setActive(false);
continue;
}
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(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" ); REGISTER_ACTION_HANDLER( CHandlerItemMenuCheck, "item_menu_check" );
@ -2306,13 +2307,21 @@ class CHandlerItemGroupMove : public IActionHandler
nlinfo("Wrong cast"); nlinfo("Wrong cast");
return; return;
} }
std::string groupName = CItemGroupManager::getInstance()->getGroupName(pCS); uint32 groupIndex;
if(groupName.empty()) fromString(getParam(sParams, "groupIndex"), groupIndex);
std::string destination = getParam(sParams, "destination");
std::vector<std::string> possibleGroups = CItemGroupManager::getInstance()->getGroupNames(pCS);
if(possibleGroups.empty())
{ {
nlinfo("Trying to move a group with a caller not part of any group"); nlinfo("Trying to move a group with a caller not part of any group");
return; 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"); REGISTER_ACTION_HANDLER(CHandlerItemGroupMove, "item_group_move");
@ -2321,7 +2330,7 @@ REGISTER_ACTION_HANDLER(CHandlerItemGroupMove, "item_group_move");
// *************************************************************************** // ***************************************************************************
class CHandlerItemGroupEquip : public IActionHandler class CHandlerItemGroupEquip : public IActionHandler
{ {
void execute (CCtrlBase *caller, const std::string &/* sParams */) void execute (CCtrlBase *caller, const std::string & sParams)
{ {
CDBCtrlSheet* pCS = dynamic_cast<CDBCtrlSheet*>(caller); CDBCtrlSheet* pCS = dynamic_cast<CDBCtrlSheet*>(caller);
if(!pCS) if(!pCS)
@ -2329,13 +2338,20 @@ class CHandlerItemGroupEquip : public IActionHandler
nlinfo("Wrong cast"); nlinfo("Wrong cast");
return; return;
} }
std::string groupName = CItemGroupManager::getInstance()->getGroupName(pCS); uint32 groupIndex;
if(groupName.empty()) fromString(getParam(sParams, "groupIndex"), groupIndex);
std::vector<std::string> possibleGroups = CItemGroupManager::getInstance()->getGroupNames(pCS);
if(possibleGroups.empty())
{ {
nlinfo("Trying to move a group with a caller not part of any group"); nlinfo("Trying to move a group with a caller not part of any group");
return; 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"); REGISTER_ACTION_HANDLER(CHandlerItemGroupEquip, "item_group_equip");

View file

@ -413,16 +413,17 @@ void CItemGroupManager::listGroup()
//Used by AH //Used by AH
std::string CItemGroupManager::getGroupName(CDBCtrlSheet* pCS) std::vector<std::string> CItemGroupManager::getGroupNames(CDBCtrlSheet* pCS)
{ {
std::vector<std::string> out;
for(int i=0;i<_Groups.size();i++) for(int i=0;i<_Groups.size();i++)
{ {
CItemGroup group = _Groups[i]; CItemGroup group = _Groups[i];
if(group.contains(pCS)) if(group.contains(pCS))
return group.name; out.push_back(group.name);
} }
return ""; return out;
} }
//Private methods //Private methods

View file

@ -22,6 +22,8 @@
#include "interface_v3/dbctrl_sheet.h" #include "interface_v3/dbctrl_sheet.h"
#include "game_share/inventories.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 { struct CInventoryItem {
public: public:
CDBCtrlSheet* pCS; CDBCtrlSheet* pCS;
@ -84,7 +86,7 @@ public:
bool createGroup(std::string name); bool createGroup(std::string name);
bool deleteGroup(std::string name); bool deleteGroup(std::string name);
void listGroup(); void listGroup();
std::string getGroupName(CDBCtrlSheet *pCS); std::vector<std::string> getGroupNames(CDBCtrlSheet *pCS);
private: private:
CItemGroup* findGroup(std::string name); CItemGroup* findGroup(std::string name);