Added interface for item groups

--HG--
branch : item_group
This commit is contained in:
Guillaume Dupuy 2017-03-09 17:47:25 +01:00
parent fdbc261a7e
commit 9fffec8ef1
4 changed files with 138 additions and 21 deletions

View file

@ -1819,6 +1819,37 @@
name="uimItemTextEdit"
handler="item_text_edition"
params="ui:interface:edit_custom" />
<action id="item_group"
name="uiGroup">
<action id="group_name" />
<action id="group_equip"
name="uimEquip"
handler="item_group_equip"/>
<action id="group_move"
name="uimMoveTo">
<action id="group_bag"
name="uimMtBag"
handler="item_group_move"
params="bag" />
<action id="group_pa0"
name="uimMtPaMount0"
handler="item_group_move"
params="pet_animal1" /> <!-- Offset because they are named petanimal1/2/3/4 in Inventories::TEnumType -->
<action id="group_pa1"
name="uimMtPaMount1"
handler="item_group_move"
params="pet_animal2" />
<action id="group_pa2"
name="uimMtPaMount2"
handler="item_group_move"
params="pet_animal3" />
<action id="group_pa3"
name="uimMtPaMount3"
handler="item_group_move"
params="pet_animal4" />
</action> <!-- move !-->
</action> <!-- item_group !-->
</group>
<!-- MAX_INVENTORY_ANIMAL -->
<link expr="switch(@%pa_beast0:TYPE, 'uimMtPaMount0', 'uimMtPaMount0', 'uimMtPaPacker0', 'uimMtPaDemon0')"
@ -1829,6 +1860,15 @@
target="ui:interface:item_menu_in_bag:move:pa2:hardtext" />
<link expr="switch(@%pa_beast3:TYPE, 'uimMtPaMount3', 'uimMtPaMount3', 'uimMtPaPacker3', 'uimMtPaDemon3')"
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 -->
<group type="menu"
id="item_menu_in_self"

View file

@ -43,7 +43,7 @@
#include "nel/gui/ctrl_base_button.h"
#include "../connection.h"
#include "nel/gui/view_bitmap.h"
#include "../item_group_manager.h"
extern CSheetManager SheetMngr;
extern NLMISC::CLog g_log;
@ -1758,12 +1758,18 @@ class CHandlerItemMenuCheck : public IActionHandler
CViewTextMenu *pMoveToGuild = dynamic_cast<CViewTextMenu*>(pMenu->getView("guild"));
CViewTextMenu *pMoveToRoom = dynamic_cast<CViewTextMenu*>(pMenu->getView("room"));
CViewTextMenu *pMoveToPa[MAX_INVENTORY_ANIMAL];
CViewTextMenu *pGroupSubMenu = dynamic_cast<CViewTextMenu*>(pMenu->getView("item_group"));
CViewTextMenu *pGroupMoveToBag = dynamic_cast<CViewTextMenu*>(pMenu->getView("group_bag"));
CViewTextMenu *pGroupName = dynamic_cast<CViewTextMenu*>(pMenu->getView("group_name"));
CViewTextMenu *pGroupMoveToPa[MAX_INVENTORY_ANIMAL];
bool bIsLockedByOwner = pCS->getLockedByOwner();
for(i=0;i<MAX_INVENTORY_ANIMAL;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 *pItemTextDisplay = dynamic_cast<CViewTextMenu*>(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;i<MAX_INVENTORY_ANIMAL;i++)
{
if(pMoveToPa[i]) pMoveToPa[i]->setActive(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;i<MAX_INVENTORY_ANIMAL;i++)
{
@ -1882,6 +1904,10 @@ class CHandlerItemMenuCheck : public IActionHandler
pMoveToPa[i]->setActive(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;i<MAX_INVENTORY_ANIMAL;i++)
{
if(pMoveToPa[i]) someMovePossible= someMovePossible || pMoveToPa[i]->getActive();
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;i<MAX_INVENTORY_ANIMAL;i++)
{
if(pMoveToPa[i]) pMoveToPa[i]->setGrayed(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;i<MAX_INVENTORY_ANIMAL;i++)
{
if(pMoveToPa[i]) pMoveToPa[i]->setGrayed(!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<CDBCtrlSheet*>(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<CDBCtrlSheet*>(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");

View file

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

View file

@ -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 ( ?)
* * 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);