Skip to content

Commit

Permalink
~ further improved the new non-slot equip mechanic. slot_persistent =…
Browse files Browse the repository at this point in the history
… false must be set to enable this feature for a slot. Some minor bugs exist when stacking and a bug where you are unable to equip an item unless you unequip the existing item first. (Still work in progress)
  • Loading branch information
revolucas authored and Xottab-DUTY committed Dec 16, 2017
1 parent f64b76a commit 597a34c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 29 deletions.
9 changes: 5 additions & 4 deletions src/xrGame/ui/UIActorMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,23 +475,24 @@ void CUIActorMenu::highlight_item_slot(CUICellItem* cell_item)
CEatableItem* eatable = smart_cast<CEatableItem*>(item);
CArtefact* artefact = smart_cast<CArtefact*>(item);

if (weapon)
u16 slot_id = item->BaseSlot();
if (weapon && (slot_id == INV_SLOT_2 || slot_id == INV_SLOT_3))
{
m_InvSlot2Highlight->Show(true);
m_InvSlot3Highlight->Show(true);
return;
}
if (helmet)
if (helmet && slot_id == HELMET_SLOT)
{
m_HelmetSlotHighlight->Show(true);
return;
}
if (outfit)
if (outfit && slot_id == OUTFIT_SLOT)
{
m_OutfitSlotHighlight->Show(true);
return;
}
if (detector)
if (detector && slot_id == DETECTOR_SLOT)
{
m_DetectorSlotHighlight->Show(true);
return;
Expand Down
56 changes: 39 additions & 17 deletions src/xrGame/ui/UIActorMenuInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void CUIActorMenu::DetachAddon(LPCSTR addon_name, PIItem itm)

void CUIActorMenu::InitCellForSlot(u16 slot_idx)
{
VERIFY(KNIFE_SLOT <= slot_idx && slot_idx <= LAST_SLOT);
//VERIFY(KNIFE_SLOT <= slot_idx && slot_idx <= LAST_SLOT);
PIItem item = m_pActorInvOwner->inventory().ItemFromSlot(slot_idx);
if (!item)
{
Expand Down Expand Up @@ -414,6 +414,15 @@ void CUIActorMenu::InitInventoryContents(CUIDragDropListEx* pBagList)
InitCellForSlot(GRENADE_SLOT);
InitCellForSlot(HELMET_SLOT);

//Alundaio
if (!m_pActorInvOwner->inventory().SlotIsPersistent(KNIFE_SLOT))
InitCellForSlot(KNIFE_SLOT);
if (!m_pActorInvOwner->inventory().SlotIsPersistent(BINOCULAR_SLOT))
InitCellForSlot(BINOCULAR_SLOT);
if (!m_pActorInvOwner->inventory().SlotIsPersistent(ARTEFACT_SLOT))
InitCellForSlot(ARTEFACT_SLOT);
//-Alundaio

curr_list = m_pInventoryBeltList;
TIItemContainer::iterator itb = m_pActorInvOwner->inventory().m_belt.begin();
TIItemContainer::iterator ite = m_pActorInvOwner->inventory().m_belt.end();
Expand Down Expand Up @@ -494,11 +503,12 @@ bool CUIActorMenu::ToSlot(CUICellItem* itm, bool force_place, u16 slot_id)
{
CUIDragDropListEx* new_owner = GetSlotList(slot_id);

if (slot_id == GRENADE_SLOT || !new_owner)
//Alundaio
/*if (slot_id == GRENADE_SLOT || !new_owner)
{
return true; // fake, sorry (((
}
else if (slot_id == OUTFIT_SLOT)
else*/ if (slot_id == OUTFIT_SLOT)
{
CCustomOutfit* pOutfit = smart_cast<CCustomOutfit*>(iitem);
if (pOutfit && !pOutfit->bIsHelmetAvaliable)
Expand Down Expand Up @@ -546,15 +556,24 @@ bool CUIActorMenu::ToSlot(CUICellItem* itm, bool force_place, u16 slot_id)

PIItem _iitem = m_pActorInvOwner->inventory().ItemFromSlot(slot_id);
CUIDragDropListEx* slot_list = GetSlotList(slot_id);
VERIFY(slot_list->ItemsCount() == 1);
if (!slot_list)
return false;

CUICellItem* slot_cell = slot_list->GetItemIdx(0);
VERIFY(slot_cell && ((PIItem)slot_cell->m_pData) == _iitem);
CUIDragDropListEx* invlist = GetListByType(iActorBag);
if (invlist != slot_list)
{
if (!slot_list->ItemsCount() == 1)
return false;

bool result = ToBag(slot_cell, false);
VERIFY(result);
CUICellItem* slot_cell = slot_list->GetItemIdx(0);
if (!(slot_cell && static_cast<PIItem>(slot_cell->m_pData) == _iitem))
return false;

result = ToSlot(itm, false, slot_id);
if (ToBag(slot_cell, false) == false)
return false;
}

bool result = ToSlot(itm, false, slot_id);
if (b_own_item && result && slot_id == DETECTOR_SLOT)
{
CCustomDetector* det = smart_cast<CCustomDetector*>(iitem);
Expand Down Expand Up @@ -685,6 +704,10 @@ CUIDragDropListEx* CUIActorMenu::GetSlotList(u16 slot_idx)

case DETECTOR_SLOT: return m_pInventoryDetectorList; break;

case ARTEFACT_SLOT:
case BINOCULAR_SLOT:
case KNIFE_SLOT:

case GRENADE_SLOT: // fake
if (m_currMenuMode == mmTrade)
{
Expand Down Expand Up @@ -849,7 +872,8 @@ void CUIActorMenu::PropertiesBoxForSlots(PIItem item, bool& b_show)
bool bAlreadyDressed = false;
u16 cur_slot = item->BaseSlot();

if (!pOutfit && !pHelmet && cur_slot != NO_ACTIVE_SLOT && !inv.SlotIsPersistent(cur_slot) /*&& inv.CanPutInSlot(item, cur_slot)*/)
if (!pOutfit && !pHelmet && cur_slot != NO_ACTIVE_SLOT && !inv.SlotIsPersistent(cur_slot) && m_pActorInvOwner->
inventory().ItemFromSlot(cur_slot) != item /*&& inv.CanPutInSlot(item, cur_slot)*/)
{
m_UIPropertiesBox->AddItem("st_move_to_slot", NULL, INVENTORY_TO_SLOT_ACTION);
b_show = true;
Expand Down Expand Up @@ -1414,15 +1438,13 @@ void CUIActorMenu::RefreshCurrentItemCell()
{
CUICellItem* parent = invlist->RemoveItem(ci, true);

if (parent->ChildsCount() > 0)
while (parent->ChildsCount())
{
while (parent->ChildsCount())
{
CUICellItem* child = parent->PopChild(nullptr);
invlist->SetItem(child);
}
CUICellItem* child = parent->PopChild(nullptr);
invlist->SetItem(child);
}
invlist->SetItem(parent);

invlist->SetItem(parent, GetUICursor().GetCursorPosition());
}
}
}
4 changes: 2 additions & 2 deletions src/xrGame/ui/UIActorMenuTrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,11 @@ void CUIActorMenu::DonateCurrentItem(CUICellItem* cell_item)
if (!item)
return;

invlist->RemoveItem(cell_item, false);
CUICellItem* itm = invlist->RemoveItem(cell_item, false);

m_partner_trade->TransferItem(item, true, true);

m_pTradePartnerList->SetItem(cell_item);
m_pTradePartnerList->SetItem(itm);

SetCurrentItem(nullptr);
UpdateItemsPlace();
Expand Down
33 changes: 27 additions & 6 deletions src/xrGame/ui/UIDragDropListEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "Common/object_broker.h"
#include "UICellItem.h"
#include "UICursor.h"
//Alundaio
#include "Inventory.h"
//-Alundaio

CUIDragItem* CUIDragDropListEx::m_drag_item = NULL;

Expand Down Expand Up @@ -479,6 +482,9 @@ bool CUICellContainer::AddSimilar(CUICellItem* itm)
return false;

CUICellItem* i = FindSimilar(itm);
if (i == nullptr)
return false;

R_ASSERT(i != itm);
R_ASSERT(0 == itm->ChildsCount());
if (i)
Expand All @@ -492,14 +498,23 @@ bool CUICellContainer::AddSimilar(CUICellItem* itm)

CUICellItem* CUICellContainer::FindSimilar(CUICellItem* itm)
{
// XXX: try to replace with range-based for
for (auto it = m_ChildWndList.begin(); m_ChildWndList.end() != it; ++it)
{
#ifdef DEBUG
CUICellItem* i = smart_cast<CUICellItem*>(*it);
#else
CUICellItem* i = (CUICellItem*)(*it);
#endif
R_ASSERT(i != itm);
//Alundaio: Don't stack equipped items
PIItem iitem = static_cast<PIItem>(i->m_pData);
if (iitem && iitem->m_pInventory && iitem->m_pInventory->ItemFromSlot(iitem->BaseSlot()) == iitem)
continue;

if (i == itm)
continue;

//R_ASSERT(i != itm);
if (i->EqualTo(itm))
return i;
}
Expand Down Expand Up @@ -845,16 +860,22 @@ void CUICellContainer::Draw()
if (!ui_cell.Empty())
{
if (ui_cell.m_item->m_cur_mark)
{
select_mode = 2;
}
else if (ui_cell.m_item->m_selected)
{
select_mode = 1;
}
else if (ui_cell.m_item->m_select_armament)
{
select_mode = 3;
else
{
//Alundaio: Highlight equipped items
PIItem iitem = static_cast<PIItem>(ui_cell.m_item->m_pData);
if (iitem)
{
u16 slot = iitem->BaseSlot();
if (iitem->m_pInventory && iitem->m_pInventory->ItemFromSlot(slot) == iitem)
select_mode = 3;
}
//-Alundaio
}
}

Expand Down

0 comments on commit 597a34c

Please sign in to comment.