@ -74,6 +74,7 @@ CInventoryManager *CInventoryManager::_Instance = NULL;
NLMISC_REGISTER_OBJECT ( CViewBase , CDBGroupListSheetBag , std : : string , " list_sheet_bag " ) ;
NLMISC_REGISTER_OBJECT ( CViewBase , CDBGroupIconListBag , std : : string , " list_icon_bag " ) ;
NLMISC_REGISTER_OBJECT ( CViewBase , CDBGroupListSheetFilterCLMSlot , std : : string , " list_sheet_filter_clm_slot " ) ;
NLMISC_REGISTER_OBJECT ( CViewBase , CDBGroupListSheetFilterHotbarSlot , std : : string , " list_sheet_filter_hotbar_slot " ) ;
NLMISC_REGISTER_OBJECT ( CViewBase , CDBGroupListSheetFilterExchangeable , std : : string , " list_sheet_filter_exchangeable " ) ;
// ***************************************************************************
@ -314,6 +315,8 @@ CInventoryManager::CInventoryManager()
{
Hands [ i ] = ServerHands [ i ] = 0 ;
UIHands [ i ] = NULL ;
UIHands2 [ i ] = NULL ;
UIHands3 [ i ] = NULL ;
}
for ( i = 0 ; i < MAX_EQUIPINV_ENTRIES ; + + i )
@ -323,6 +326,14 @@ CInventoryManager::CInventoryManager()
UIEquip2 [ i ] = NULL ;
}
for ( i = 0 ; i < MAX_HOTBARINV_ENTRIES ; + + i )
{
Hotbar [ i ] = ServerHotbar [ i ] = 0 ;
UIHotbar [ i ] = NULL ;
UIHotbar2 [ i ] = NULL ;
UIHotbar3 [ i ] = NULL ;
}
for ( i = 0 ; i < MAX_BAGINV_ENTRIES ; i + + )
{
BagItemEquipped [ i ] = false ;
@ -390,6 +401,16 @@ CItemImage *CInventoryManager::getEquipItem(uint index)
return NULL ;
}
// *************************************************************************************************
CItemImage * CInventoryManager : : getHotbarItem ( uint index )
{
nlassert ( index < MAX_HOTBARINV_ENTRIES ) ;
if ( Hotbar [ index ] ! = 0 )
return & Bag [ Hotbar [ index ] ] ;
else
return NULL ;
}
// *************************************************************************************************
CDBCtrlSheet * CInventoryManager : : getHandSheet ( uint index )
{
@ -402,6 +423,11 @@ CDBCtrlSheet *CInventoryManager::getEquipSheet(uint index)
return UIEquip [ index ] ;
}
// *************************************************************************************************
CDBCtrlSheet * CInventoryManager : : getHotbarSheet ( uint index )
{
return UIHotbar [ index ] ;
}
// *************************************************************************************************
CItemImage & CInventoryManager : : getServerBagItem ( uint index )
@ -480,6 +506,7 @@ void CInventoryManager::init()
Money = NLGUI : : CDBManager : : getInstance ( ) - > getDbProp ( LOCAL_INVENTORY " :MONEY " ) ;
initIndirection ( LOCAL_INVENTORY " :HAND: " , Hands , MAX_HANDINV_ENTRIES , true ) ;
initIndirection ( LOCAL_INVENTORY " :EQUIP: " , Equip , MAX_EQUIPINV_ENTRIES , true ) ;
initIndirection ( LOCAL_INVENTORY " :HOTBAR: " , Hotbar , MAX_HOTBARINV_ENTRIES , true ) ;
// Init observers for auto equipment
{
for ( uint i = 0 ; i < MAX_BAGINV_ENTRIES ; + + i )
@ -527,6 +554,15 @@ void CInventoryManager::init()
UIEquip [ SLOT_EQUIPMENT : : LEGS ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_ARMOR_LEGS ) ) ;
UIEquip [ SLOT_EQUIPMENT : : HANDS ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_ARMOR_HANDS ) ) ;
UIHotbar [ 0 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR_1 ) ) ;
UIHotbar [ 1 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR_2 ) ) ;
UIHotbar [ 2 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR_3 ) ) ;
UIHotbar [ 3 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR_4 ) ) ;
UIHotbar [ 4 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR_5 ) ) ;
UIHands2 [ 0 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HAND2_RIGHT ) ) ;
UIHands2 [ 1 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HAND2_LEFT ) ) ;
UIEquip2 [ SLOT_EQUIPMENT : : HEADDRESS ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_JEWL2_HEADDRESS ) ) ;
UIEquip2 [ SLOT_EQUIPMENT : : EARL ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_JEWL2_EARING_LEFT ) ) ;
UIEquip2 [ SLOT_EQUIPMENT : : EARR ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_JEWL2_EARING_RIGHT ) ) ;
@ -545,6 +581,20 @@ void CInventoryManager::init()
UIEquip2 [ SLOT_EQUIPMENT : : LEGS ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_ARMR2_LEGS ) ) ;
UIEquip2 [ SLOT_EQUIPMENT : : HANDS ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_ARMR2_HANDS ) ) ;
UIHotbar2 [ 0 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR2_1 ) ) ;
UIHotbar2 [ 1 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR2_2 ) ) ;
UIHotbar2 [ 2 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR2_3 ) ) ;
UIHotbar2 [ 3 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR2_4 ) ) ;
UIHotbar2 [ 4 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR2_5 ) ) ;
UIHands3 [ 0 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HAND3_RIGHT ) ) ;
UIHands3 [ 1 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HAND3_LEFT ) ) ;
UIHotbar3 [ 0 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR3_1 ) ) ;
UIHotbar3 [ 1 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR3_2 ) ) ;
UIHotbar3 [ 2 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR3_3 ) ) ;
UIHotbar3 [ 3 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR3_4 ) ) ;
UIHotbar3 [ 4 ] = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( CTRL_HOTBAR3_5 ) ) ;
// Init ItemInfoObservers
{
@ -658,6 +708,14 @@ std::string CInventoryManager::getDBIndexPath(CDBCtrlSheet *pCS)
{
return string ( LOCAL_INVENTORY ) + " :HAND: " + toString ( i ) ;
}
if ( UIHands2 [ i ] = = pCS )
{
return string ( LOCAL_INVENTORY ) + " :HAND: " + toString ( i ) ;
}
if ( UIHands3 [ i ] = = pCS )
{
return string ( LOCAL_INVENTORY ) + " :HAND: " + toString ( i ) ;
}
}
for ( i = 0 ; i < MAX_EQUIPINV_ENTRIES ; + + i )
@ -671,6 +729,23 @@ std::string CInventoryManager::getDBIndexPath(CDBCtrlSheet *pCS)
return string ( LOCAL_INVENTORY ) + " :EQUIP: " + toString ( i ) ;
}
}
for ( i = 0 ; i < MAX_HOTBARINV_ENTRIES ; + + i )
{
if ( UIHotbar [ i ] = = pCS )
{
return string ( LOCAL_INVENTORY ) + " :HOTBAR: " + toString ( i ) ;
}
if ( UIHotbar2 [ i ] = = pCS )
{
return string ( LOCAL_INVENTORY ) + " :HOTBAR: " + toString ( i ) ;
}
if ( UIHotbar3 [ i ] = = pCS )
{
return string ( LOCAL_INVENTORY ) + " :HOTBAR: " + toString ( i ) ;
}
}
return " " ;
}
@ -758,6 +833,20 @@ bool CInventoryManager::isForageToolItem(uint32 sheetID)
return result ;
}
// ***************************************************************************
bool CInventoryManager : : isUsableItem ( uint32 sheetID )
{
bool result = false ;
CEntitySheet * sheet = SheetMngr . get ( CSheetId ( sheetID ) ) ;
if ( sheet & & sheet - > type ( ) = = CEntitySheet : : ITEM )
{
CItemSheet * item = ( CItemSheet * ) sheet ;
if ( ITEMFAMILY : : isUsable ( item - > Family ) )
result = true ;
}
return result ;
}
// ***************************************************************************
uint32 CInventoryManager : : getHandItemSheet ( bool rightHand ) const
{
@ -957,6 +1046,11 @@ void CInventoryManager::equip(const std::string &bagPath, const std::string &inv
inventory = INVENTORIES : : equipment ;
fromString ( invPath . substr ( 22 , invPath . size ( ) ) , invSlot ) ;
}
else if ( strnicmp ( invPath . c_str ( ) , " LOCAL:INVENTORY:HOTBAR " , 22 ) = = 0 )
{
inventory = INVENTORIES : : hotbar ;
fromString ( invPath . substr ( 23 , invPath . size ( ) ) , invSlot ) ;
}
// Hands management : check if we have to unequip left hand because of incompatibility with right hand item
sint16 oldRightIndexInBag = NLGUI : : CDBManager : : getInstance ( ) - > getDbProp ( invPath + " :INDEX_IN_BAG " ) - > getValue16 ( ) ;
@ -1090,6 +1184,11 @@ void CInventoryManager::unequip(const std::string &invPath)
inventory = INVENTORIES : : equipment ;
fromString ( invPath . substr ( 22 , invPath . size ( ) ) , invSlot ) ;
}
else if ( strnicmp ( invPath . c_str ( ) , " LOCAL:INVENTORY:HOTBAR " , 22 ) = = 0 )
{
inventory = INVENTORIES : : hotbar ;
fromString ( invPath . substr ( 23 , invPath . size ( ) ) , invSlot ) ;
}
// Hands management : check if we have to unequip left hand because of incompatibility with right hand item
if ( inventory = = INVENTORIES : : handling & & invSlot = = 0 )
@ -1176,7 +1275,7 @@ void CInventoryManager::CDBEquipObs::update(ICDBNode* node)
{
CInterfaceManager * pIM = CInterfaceManager : : getInstance ( ) ;
string sTmp = node - > getFullName ( ) ;
string sIE , sIE2 ; // Interface Element
string sIE , sIE2 , sIE3 ; // Interface Element
CCDBNodeLeaf * pNL = dynamic_cast < CCDBNodeLeaf * > ( node ) ;
if ( pNL = = NULL ) return ;
if ( strnicmp ( sTmp . c_str ( ) , " LOCAL:INVENTORY:HAND " , 20 ) = = 0 )
@ -1186,10 +1285,16 @@ void CInventoryManager::CDBEquipObs::update(ICDBNode* node)
sTmp = sTmp . substr ( 0 , sTmp . rfind ( ' : ' ) ) ;
sint index ;
fromString ( sTmp , index ) ;
if ( index = = 0 )
if ( index = = 0 ) {
sIE = CTRL_HAND_RIGHT ;
else
sIE2 = CTRL_HAND2_RIGHT ;
sIE3 = CTRL_HAND3_RIGHT ;
}
else {
sIE = CTRL_HAND_LEFT ;
sIE2 = CTRL_HAND2_LEFT ;
sIE3 = CTRL_HAND3_LEFT ;
}
// update Hands.
getInventory ( ) . Hands [ index ] = pNL - > getValue16 ( ) ;
}
@ -1245,11 +1350,49 @@ void CInventoryManager::CDBEquipObs::update(ICDBNode* node)
// update Equips.
getInventory ( ) . Equip [ index ] = pNL - > getValue16 ( ) ;
}
else if ( strnicmp ( sTmp . c_str ( ) , " LOCAL:INVENTORY:HOTBAR " , 22 ) = = 0 )
{
// Coming from hand
sTmp = sTmp . substr ( 23 , sTmp . size ( ) ) ;
sTmp = sTmp . substr ( 0 , sTmp . rfind ( ' : ' ) ) ;
sint index ;
fromString ( sTmp , index ) ;
switch ( index ) {
case 0 :
sIE = CTRL_HOTBAR_1 ;
sIE2 = CTRL_HOTBAR2_1 ;
sIE3 = CTRL_HOTBAR3_1 ;
break ;
case 1 :
sIE = CTRL_HOTBAR_2 ;
sIE2 = CTRL_HOTBAR2_2 ;
sIE3 = CTRL_HOTBAR3_2 ;
break ;
case 2 :
sIE = CTRL_HOTBAR_3 ;
sIE2 = CTRL_HOTBAR2_3 ;
sIE3 = CTRL_HOTBAR3_3 ;
break ;
case 3 :
sIE = CTRL_HOTBAR_4 ;
sIE2 = CTRL_HOTBAR2_4 ;
sIE3 = CTRL_HOTBAR3_4 ;
break ;
case 4 :
sIE = CTRL_HOTBAR_5 ;
sIE2 = CTRL_HOTBAR2_5 ;
sIE3 = CTRL_HOTBAR3_5 ;
break ;
}
// update Hotbar.
getInventory ( ) . Hotbar [ index ] = pNL - > getValue16 ( ) ;
}
else return ;
// Set database for wearing the right item
CDBCtrlSheet * pCS = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( sIE ) ) ;
CDBCtrlSheet * pCS2 = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( sIE2 ) ) ;
CDBCtrlSheet * pCS3 = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getElementFromId ( sIE3 ) ) ;
// Remove Last reference and update database
sint16 oldVal = pNL - > getOldValue16 ( ) ;
@ -1268,12 +1411,14 @@ void CInventoryManager::CDBEquipObs::update(ICDBNode* node)
{
if ( pCS ! = NULL ) pCS - > setSheet ( " " ) ;
if ( pCS2 ! = NULL ) pCS2 - > setSheet ( " " ) ;
if ( pCS3 ! = NULL ) pCS3 - > setSheet ( " " ) ;
}
}
else
{
if ( pCS ! = NULL ) pCS - > setSheet ( LOCAL_INVENTORY " :BAG: " + toString ( newVal - 1 ) ) ;
if ( pCS2 ! = NULL ) pCS2 - > setSheet ( LOCAL_INVENTORY " :BAG: " + toString ( newVal - 1 ) ) ;
if ( pCS3 ! = NULL ) pCS3 - > setSheet ( LOCAL_INVENTORY " :BAG: " + toString ( newVal - 1 ) ) ;
}
// Hands management
@ -1405,6 +1550,7 @@ void CInventoryManager::CDBEquipObs::update(ICDBNode* node)
{
if ( pCS ! = NULL ) pCS - > setSheet ( " " ) ;
if ( pCS2 ! = NULL ) pCS2 - > setSheet ( " " ) ;
if ( pCS3 ! = NULL ) pCS3 - > setSheet ( " " ) ;
}
}
}
@ -2608,6 +2754,42 @@ bool CDBGroupListSheetFilterCLMSlot::CSheetChildFilter::isSheetValid(CDBGroupLis
return false ;
}
// ***************************************************************************
// CDBGroupListSheetFilterHotbarSlot
// ***************************************************************************
// ***************************************************************************
bool CDBGroupListSheetFilterHotbarSlot : : CSheetChildFilter : : isSheetValid ( CDBGroupListSheet * pFather )
{
if ( CSheetChild : : isSheetValid ( pFather ) )
{
CInterfaceManager * pIM = CInterfaceManager : : getInstance ( ) ;
CDBCtrlSheet * clmCtrl = dynamic_cast < CDBCtrlSheet * > ( CWidgetManager : : getInstance ( ) - > getCtrlLaunchingModal ( ) ) ;
if ( ! clmCtrl | | ! Ctrl ) return false ;
if ( clmCtrl - > getInventoryIndex ( ) = = INVENTORIES : : exchange & &
Ctrl - > getInventoryIndex ( ) = = INVENTORIES : : exchange )
{
return false ;
}
if ( ( clmCtrl - > getType ( ) = = CCtrlSheetInfo : : SheetType_Item ) & &
( Ctrl - > getType ( ) = = CCtrlSheetInfo : : SheetType_Item ) )
{
// Ok if we can put in the slot Ctrl in clmCtrl
if ( clmCtrl - > canDropItem ( Ctrl ) )
{
string sTmp = Ctrl - > getSheet ( ) ;
// Look if the source is locked
sTmp = sTmp . substr ( sTmp . rfind ( ' : ' ) + 1 , sTmp . size ( ) ) ;
sint32 nTmp ;
fromString ( sTmp , nTmp ) ;
if ( ! getInventory ( ) . isBagItemWeared ( nTmp ) & & getInventory ( ) . isUsableItem ( Ctrl - > getSheetId ( ) ) & & Ctrl - > getLockedByOwner ( ) = = 0 )
return true ;
}
}
}
return false ;
}
// ***************************************************************************
// CDBGroupListSheetFilterExchangeable
// ***************************************************************************
@ -2960,7 +3142,7 @@ class CHandlerInvDropTo : public IActionHandler
{
CInterfaceGroup * pIG = CWidgetManager : : getInstance ( ) - > getModalWindow ( ) ;
if ( pIG = = NULL ) return ;
if ( pIG - > getId ( ) ! = " ui:interface:bag_choose " ) return ;
if ( pIG - > getId ( ) ! = " ui:interface:bag_choose " & & pIG - > getId ( ) ! = " ui:interface:hotbar_choose " ) return ;
getInventory ( ) . beginDrag ( NULL , CInventoryManager : : TextList ) ;
// Special case for choose in bag dialog
@ -3121,7 +3303,6 @@ class CHandlerInvCannotDrop : public IActionHandler
// Is the dragged sheet comes from a slot
if ( ! getInventory ( ) . isDraggingFromTextList ( ) )
{
// Unequip
CDBCtrlSheet * pCSDst = dynamic_cast < CDBCtrlSheet * > ( pCaller ) ;
string invPath = getInventory ( ) . getDBIndexPath ( pCSDst ) ;
getInventory ( ) . unequip ( invPath ) ;
@ -3131,6 +3312,75 @@ class CHandlerInvCannotDrop : public IActionHandler
} ;
REGISTER_ACTION_HANDLER ( CHandlerInvCannotDrop , " inv_cannot_drop " ) ;
// **********************************************************************************************************
class CCanDropToHotbar : public IActionHandler
{
virtual void execute ( CCtrlBase * pCaller , const string & Params )
{
CInterfaceManager * pIM = CInterfaceManager : : getInstance ( ) ;
string src = getParam ( Params , " src " ) ;
CInterfaceElement * pElt = CWidgetManager : : getInstance ( ) - > getElementFromId ( src ) ;
CDBCtrlSheet * pCSSrc = dynamic_cast < CDBCtrlSheet * > ( pElt ) ;
CDBCtrlSheet * pCSDst = dynamic_cast < CDBCtrlSheet * > ( pCaller ) ;
if ( ! pCSSrc | | ! pCSDst ) return ;
// Exchange can only be done from bag to exchange inventories
uint32 srcInventory = pCSSrc - > getSecondIndexInDB ( ) ;
if (
srcInventory = = INVENTORIES : : bag
& & getInventory ( ) . isInventoryAvailable ( ( INVENTORIES : : TInventory ) pCSSrc - > getSecondIndexInDB ( ) )
& & getInventory ( ) . isUsableItem ( pCSSrc - > getSheetId ( ) )
)
{
pCSDst - > setCanDrop ( true ) ;
}
}
} ;
REGISTER_ACTION_HANDLER ( CCanDropToHotbar , " can_drop_to_hotbar " ) ;
// **********************************************************************************************************
class CHotbarLeftClickOnSlotHandler : public IActionHandler
{
virtual void execute ( CCtrlBase * pCaller , const string & /* Params */ )
{
CDBCtrlSheet * sheet = dynamic_cast < CDBCtrlSheet * > ( pCaller ) ;
if ( ! sheet ) return ;
if ( sheet - > getSheetId ( ) = = 0 )
{
// is there's no item that is not worn, can't choose any item)
bool isThereObjectNotWorn = false ;
for ( uint k = 0 ; k < MAX_BAGINV_ENTRIES ; + + k )
{
uint32 sheetid = getInventory ( ) . getBagItem ( k ) . getSheetID ( ) ;
if ( sheetid ! = 0 )
{
if ( ! getInventory ( ) . isBagItemWeared ( k ) )
{
CEntitySheet * pES = SheetMngr . get ( CSheetId ( sheetid ) ) ;
if ( pES & & pES - > type ( ) = = CEntitySheet : : ITEM )
{
CItemSheet * pIS = ( CItemSheet * ) pES ;
if ( getInventory ( ) . isUsableItem ( sheetid ) )
{
isThereObjectNotWorn = true ;
break ;
}
}
}
}
}
if ( ! isThereObjectNotWorn )
{
// every object are worn, so there's no use to display an empty list -> no-op
return ;
}
}
CInterfaceManager * im = CInterfaceManager : : getInstance ( ) ;
CWidgetManager : : getInstance ( ) - > pushModalWindow ( pCaller , " ui:interface:hotbar_choose " ) ;
}
} ;
REGISTER_ACTION_HANDLER ( CHotbarLeftClickOnSlotHandler , " hotbar_left_click_on_slot " ) ;
// ***************************************************************************
class CHandlerInvAutoEquip : public IActionHandler