Skip to content

Commit 597a34c

Browse files
revolucasXottab-DUTY
authored andcommitted
~ further improved the new non-slot equip mechanic. slot_persistent = 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)
1 parent f64b76a commit 597a34c

File tree

4 files changed

+73
-29
lines changed

4 files changed

+73
-29
lines changed

src/xrGame/ui/UIActorMenu.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,23 +475,24 @@ void CUIActorMenu::highlight_item_slot(CUICellItem* cell_item)
475475
CEatableItem* eatable = smart_cast<CEatableItem*>(item);
476476
CArtefact* artefact = smart_cast<CArtefact*>(item);
477477

478-
if (weapon)
478+
u16 slot_id = item->BaseSlot();
479+
if (weapon && (slot_id == INV_SLOT_2 || slot_id == INV_SLOT_3))
479480
{
480481
m_InvSlot2Highlight->Show(true);
481482
m_InvSlot3Highlight->Show(true);
482483
return;
483484
}
484-
if (helmet)
485+
if (helmet && slot_id == HELMET_SLOT)
485486
{
486487
m_HelmetSlotHighlight->Show(true);
487488
return;
488489
}
489-
if (outfit)
490+
if (outfit && slot_id == OUTFIT_SLOT)
490491
{
491492
m_OutfitSlotHighlight->Show(true);
492493
return;
493494
}
494-
if (detector)
495+
if (detector && slot_id == DETECTOR_SLOT)
495496
{
496497
m_DetectorSlotHighlight->Show(true);
497498
return;

src/xrGame/ui/UIActorMenuInventory.cpp

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void CUIActorMenu::DetachAddon(LPCSTR addon_name, PIItem itm)
376376

377377
void CUIActorMenu::InitCellForSlot(u16 slot_idx)
378378
{
379-
VERIFY(KNIFE_SLOT <= slot_idx && slot_idx <= LAST_SLOT);
379+
//VERIFY(KNIFE_SLOT <= slot_idx && slot_idx <= LAST_SLOT);
380380
PIItem item = m_pActorInvOwner->inventory().ItemFromSlot(slot_idx);
381381
if (!item)
382382
{
@@ -414,6 +414,15 @@ void CUIActorMenu::InitInventoryContents(CUIDragDropListEx* pBagList)
414414
InitCellForSlot(GRENADE_SLOT);
415415
InitCellForSlot(HELMET_SLOT);
416416

417+
//Alundaio
418+
if (!m_pActorInvOwner->inventory().SlotIsPersistent(KNIFE_SLOT))
419+
InitCellForSlot(KNIFE_SLOT);
420+
if (!m_pActorInvOwner->inventory().SlotIsPersistent(BINOCULAR_SLOT))
421+
InitCellForSlot(BINOCULAR_SLOT);
422+
if (!m_pActorInvOwner->inventory().SlotIsPersistent(ARTEFACT_SLOT))
423+
InitCellForSlot(ARTEFACT_SLOT);
424+
//-Alundaio
425+
417426
curr_list = m_pInventoryBeltList;
418427
TIItemContainer::iterator itb = m_pActorInvOwner->inventory().m_belt.begin();
419428
TIItemContainer::iterator ite = m_pActorInvOwner->inventory().m_belt.end();
@@ -494,11 +503,12 @@ bool CUIActorMenu::ToSlot(CUICellItem* itm, bool force_place, u16 slot_id)
494503
{
495504
CUIDragDropListEx* new_owner = GetSlotList(slot_id);
496505

497-
if (slot_id == GRENADE_SLOT || !new_owner)
506+
//Alundaio
507+
/*if (slot_id == GRENADE_SLOT || !new_owner)
498508
{
499509
return true; // fake, sorry (((
500510
}
501-
else if (slot_id == OUTFIT_SLOT)
511+
else*/ if (slot_id == OUTFIT_SLOT)
502512
{
503513
CCustomOutfit* pOutfit = smart_cast<CCustomOutfit*>(iitem);
504514
if (pOutfit && !pOutfit->bIsHelmetAvaliable)
@@ -546,15 +556,24 @@ bool CUIActorMenu::ToSlot(CUICellItem* itm, bool force_place, u16 slot_id)
546556

547557
PIItem _iitem = m_pActorInvOwner->inventory().ItemFromSlot(slot_id);
548558
CUIDragDropListEx* slot_list = GetSlotList(slot_id);
549-
VERIFY(slot_list->ItemsCount() == 1);
559+
if (!slot_list)
560+
return false;
550561

551-
CUICellItem* slot_cell = slot_list->GetItemIdx(0);
552-
VERIFY(slot_cell && ((PIItem)slot_cell->m_pData) == _iitem);
562+
CUIDragDropListEx* invlist = GetListByType(iActorBag);
563+
if (invlist != slot_list)
564+
{
565+
if (!slot_list->ItemsCount() == 1)
566+
return false;
553567

554-
bool result = ToBag(slot_cell, false);
555-
VERIFY(result);
568+
CUICellItem* slot_cell = slot_list->GetItemIdx(0);
569+
if (!(slot_cell && static_cast<PIItem>(slot_cell->m_pData) == _iitem))
570+
return false;
556571

557-
result = ToSlot(itm, false, slot_id);
572+
if (ToBag(slot_cell, false) == false)
573+
return false;
574+
}
575+
576+
bool result = ToSlot(itm, false, slot_id);
558577
if (b_own_item && result && slot_id == DETECTOR_SLOT)
559578
{
560579
CCustomDetector* det = smart_cast<CCustomDetector*>(iitem);
@@ -685,6 +704,10 @@ CUIDragDropListEx* CUIActorMenu::GetSlotList(u16 slot_idx)
685704

686705
case DETECTOR_SLOT: return m_pInventoryDetectorList; break;
687706

707+
case ARTEFACT_SLOT:
708+
case BINOCULAR_SLOT:
709+
case KNIFE_SLOT:
710+
688711
case GRENADE_SLOT: // fake
689712
if (m_currMenuMode == mmTrade)
690713
{
@@ -849,7 +872,8 @@ void CUIActorMenu::PropertiesBoxForSlots(PIItem item, bool& b_show)
849872
bool bAlreadyDressed = false;
850873
u16 cur_slot = item->BaseSlot();
851874

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

1417-
if (parent->ChildsCount() > 0)
1441+
while (parent->ChildsCount())
14181442
{
1419-
while (parent->ChildsCount())
1420-
{
1421-
CUICellItem* child = parent->PopChild(nullptr);
1422-
invlist->SetItem(child);
1423-
}
1443+
CUICellItem* child = parent->PopChild(nullptr);
1444+
invlist->SetItem(child);
14241445
}
1425-
invlist->SetItem(parent);
1446+
1447+
invlist->SetItem(parent, GetUICursor().GetCursorPosition());
14261448
}
14271449
}
14281450
}

src/xrGame/ui/UIActorMenuTrade.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,11 @@ void CUIActorMenu::DonateCurrentItem(CUICellItem* cell_item)
547547
if (!item)
548548
return;
549549

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

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

554-
m_pTradePartnerList->SetItem(cell_item);
554+
m_pTradePartnerList->SetItem(itm);
555555

556556
SetCurrentItem(nullptr);
557557
UpdateItemsPlace();

src/xrGame/ui/UIDragDropListEx.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include "Common/object_broker.h"
55
#include "UICellItem.h"
66
#include "UICursor.h"
7+
//Alundaio
8+
#include "Inventory.h"
9+
//-Alundaio
710

811
CUIDragItem* CUIDragDropListEx::m_drag_item = NULL;
912

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

481484
CUICellItem* i = FindSimilar(itm);
485+
if (i == nullptr)
486+
return false;
487+
482488
R_ASSERT(i != itm);
483489
R_ASSERT(0 == itm->ChildsCount());
484490
if (i)
@@ -492,14 +498,23 @@ bool CUICellContainer::AddSimilar(CUICellItem* itm)
492498

493499
CUICellItem* CUICellContainer::FindSimilar(CUICellItem* itm)
494500
{
501+
// XXX: try to replace with range-based for
495502
for (auto it = m_ChildWndList.begin(); m_ChildWndList.end() != it; ++it)
496503
{
497504
#ifdef DEBUG
498505
CUICellItem* i = smart_cast<CUICellItem*>(*it);
499506
#else
500507
CUICellItem* i = (CUICellItem*)(*it);
501508
#endif
502-
R_ASSERT(i != itm);
509+
//Alundaio: Don't stack equipped items
510+
PIItem iitem = static_cast<PIItem>(i->m_pData);
511+
if (iitem && iitem->m_pInventory && iitem->m_pInventory->ItemFromSlot(iitem->BaseSlot()) == iitem)
512+
continue;
513+
514+
if (i == itm)
515+
continue;
516+
517+
//R_ASSERT(i != itm);
503518
if (i->EqualTo(itm))
504519
return i;
505520
}
@@ -845,16 +860,22 @@ void CUICellContainer::Draw()
845860
if (!ui_cell.Empty())
846861
{
847862
if (ui_cell.m_item->m_cur_mark)
848-
{
849863
select_mode = 2;
850-
}
851864
else if (ui_cell.m_item->m_selected)
852-
{
853865
select_mode = 1;
854-
}
855866
else if (ui_cell.m_item->m_select_armament)
856-
{
857867
select_mode = 3;
868+
else
869+
{
870+
//Alundaio: Highlight equipped items
871+
PIItem iitem = static_cast<PIItem>(ui_cell.m_item->m_pData);
872+
if (iitem)
873+
{
874+
u16 slot = iitem->BaseSlot();
875+
if (iitem->m_pInventory && iitem->m_pInventory->ItemFromSlot(slot) == iitem)
876+
select_mode = 3;
877+
}
878+
//-Alundaio
858879
}
859880
}
860881

0 commit comments

Comments
 (0)