Skip to content

Commit 9c43597

Browse files
revolucasXottab-DUTY
authored andcommitted
+ added code to donate item through context menu during trade (Work in progress)
= fixed duplicating items caused by CEatableItem::Useful() and the removal of the remaining uses check + added code to swap equipment slots, including knife and binoc through context menu (Work In Progress)
1 parent 7840b0f commit 9c43597

File tree

8 files changed

+106
-15
lines changed

8 files changed

+106
-15
lines changed

src/xrGame/UIGameCustom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ CScriptGameObject* CUIGameCustom::CurrentItemAtCell()
196196
if (!IItm)
197197
return nullptr;
198198

199-
CGameObject* GO = IItm->cast_game_object();
199+
CGameObject* GO = smart_cast<CGameObject*>(IItm);
200200

201201
if (GO)
202202
return GO->lua_game_object();

src/xrGame/eatable_item.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ bool CEatableItem::Useful() const
8686
return false;
8787

8888
//проверить не все ли еще съедено
89-
/*Alundaio: Commented out to prevent crash when placing items with 0 remaining uses inside inventory boxes
90-
if (m_iRemainingUses == 0)
89+
if (m_iRemainingUses == 0 && CanDelete())
9190
return false;
92-
*/
9391

9492
return true;
9593
}

src/xrGame/trade.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ class CTrade
5353
bool IsInTradeState() { return TradeState; }
5454
void OnPerformTrade(u32 money_get, u32 money_put);
5555

56-
void TransferItem(CInventoryItem* pItem, bool bBuying);
56+
void TransferItem(CInventoryItem* pItem, bool bBuying, bool bFree = false);
5757

5858
CInventoryOwner* GetPartner();
5959
CTrade* GetPartnerTrade();
6060
CInventory* GetPartnerInventory();
6161

62-
u32 GetItemPrice(CInventoryItem* pItem, bool b_buying);
62+
u32 GetItemPrice(CInventoryItem* pItem, bool b_buying, bool bFree = false);
6363

6464
void UpdateTrade();
6565

src/xrGame/trade2.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ bool CTrade::CanTrade()
6363
return true;
6464
}
6565

66-
void CTrade::TransferItem(CInventoryItem* pItem, bool bBuying)
66+
void CTrade::TransferItem(CInventoryItem* pItem, bool bBuying, bool bFree)
6767
{
6868
// сумма сделки учитывая ценовой коэффициент
6969
// актер цену не говорит никогда, все делают за него
70-
u32 dwTransferMoney = GetItemPrice(pItem, bBuying);
70+
u32 dwTransferMoney = GetItemPrice(pItem, bBuying, bFree);
7171

7272
if (bBuying)
7373
{
@@ -136,8 +136,11 @@ CInventory& CTrade::GetTradeInv(SInventoryOwner owner)
136136
CTrade* CTrade::GetPartnerTrade() { return pPartner.inv_owner->GetTrade(); }
137137
CInventory* CTrade::GetPartnerInventory() { return &GetTradeInv(pPartner); }
138138
CInventoryOwner* CTrade::GetPartner() { return pPartner.inv_owner; }
139-
u32 CTrade::GetItemPrice(PIItem pItem, bool b_buying)
139+
u32 CTrade::GetItemPrice(PIItem pItem, bool b_buying, bool bFree)
140140
{
141+
if (bFree)
142+
return 0;
143+
141144
CArtefact* pArtefact = smart_cast<CArtefact*>(pItem);
142145

143146
// computing base_cost

src/xrGame/ui/UIActorMenu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class CUIActorMenu : public CUIDialogWnd, public CUIWndCallback
204204
void PropertiesBoxForPlaying(PIItem item, bool& b_show);
205205
void PropertiesBoxForDrop(CUICellItem* cell_item, PIItem item, bool& b_show);
206206
void PropertiesBoxForRepair(PIItem item, bool& b_show);
207+
void PropertiesBoxForDonate(PIItem item, bool& b_show); //Alundaio
207208

208209
private:
209210
void clear_highlight_lists();
@@ -361,4 +362,5 @@ class CUIActorMenu : public CUIDialogWnd, public CUIWndCallback
361362
IC UIHint* get_hint_wnd() { return m_hint_wnd; }
362363

363364
void RefreshCurrentItemCell();
365+
void DonateCurrentItem(CUICellItem* cell_item); //Alundaio: Donate item via context menu while in trade menu
364366
}; // class CUIActorMenu

src/xrGame/ui/UIActorMenuInventory.cpp

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ bool CUIActorMenu::ToSlot(CUICellItem* itm, bool force_place, u16 slot_id)
498498
{
499499
return true; // fake, sorry (((
500500
}
501-
502-
if (slot_id == OUTFIT_SLOT)
501+
else if (slot_id == OUTFIT_SLOT)
503502
{
504503
CCustomOutfit* pOutfit = smart_cast<CCustomOutfit*>(iitem);
505504
if (pOutfit && !pOutfit->bIsHelmetAvaliable)
@@ -785,7 +784,7 @@ void CUIActorMenu::TryHidePropertiesBox()
785784
void CUIActorMenu::ActivatePropertiesBox()
786785
{
787786
TryHidePropertiesBox();
788-
if (!(m_currMenuMode == mmInventory || m_currMenuMode == mmDeadBodySearch || m_currMenuMode == mmUpgrade))
787+
if (!(m_currMenuMode == mmInventory || m_currMenuMode == mmDeadBodySearch || m_currMenuMode == mmUpgrade || m_currMenuMode == mmTrade))
789788
{
790789
return;
791790
}
@@ -818,7 +817,14 @@ void CUIActorMenu::ActivatePropertiesBox()
818817
{
819818
PropertiesBoxForRepair(item, b_show);
820819
}
821-
820+
//Alundaio: Ability to donate item to npc during trade
821+
else if (m_currMenuMode == mmTrade)
822+
{
823+
CUIDragDropListEx* invlist = GetListByType(iActorBag);
824+
if (invlist->IsOwner(cell_item))
825+
PropertiesBoxForDonate(item, b_show);
826+
}
827+
//-Alundaio
822828
if (b_show)
823829
{
824830
m_UIPropertiesBox->AutoUpdateSize();
@@ -843,8 +849,7 @@ void CUIActorMenu::PropertiesBoxForSlots(PIItem item, bool& b_show)
843849
bool bAlreadyDressed = false;
844850
u16 cur_slot = item->BaseSlot();
845851

846-
if (!pOutfit && !pHelmet && cur_slot != NO_ACTIVE_SLOT && !inv.SlotIsPersistent(cur_slot) &&
847-
inv.CanPutInSlot(item, cur_slot))
852+
if (!pOutfit && !pHelmet && cur_slot != NO_ACTIVE_SLOT && !inv.SlotIsPersistent(cur_slot) /*&& inv.CanPutInSlot(item, cur_slot)*/)
848853
{
849854
m_UIPropertiesBox->AddItem("st_move_to_slot", NULL, INVENTORY_TO_SLOT_ACTION);
850855
b_show = true;
@@ -1092,6 +1097,22 @@ void CUIActorMenu::PropertiesBoxForUsing(PIItem item, bool& b_show)
10921097
m_UIPropertiesBox->AddItem(act_str, nullptr, INVENTORY_EAT3_ACTION);
10931098
b_show = true;
10941099
}
1100+
1101+
//3rd Custom Use action
1102+
act_str = READ_IF_EXISTS(pSettings, r_string, section_name, "use3_text", 0);
1103+
if (act_str)
1104+
{
1105+
m_UIPropertiesBox->AddItem(act_str, nullptr, INVENTORY_EAT4_ACTION);
1106+
b_show = true;
1107+
}
1108+
1109+
//4th Custom Use action
1110+
act_str = READ_IF_EXISTS(pSettings, r_string, section_name, "use4_text", 0);
1111+
if (act_str)
1112+
{
1113+
m_UIPropertiesBox->AddItem(act_str, nullptr, INVENTORY_EAT5_ACTION);
1114+
b_show = true;
1115+
}
10951116
}
10961117

10971118
void CUIActorMenu::PropertiesBoxForPlaying(PIItem item, bool& b_show)
@@ -1132,6 +1153,14 @@ void CUIActorMenu::PropertiesBoxForRepair(PIItem item, bool& b_show)
11321153
}
11331154
}
11341155

1156+
//Alundaio: Ability to donate item during trade
1157+
void CUIActorMenu::PropertiesBoxForDonate(PIItem item, bool& b_show)
1158+
{
1159+
m_UIPropertiesBox->AddItem("st_donate", nullptr, INVENTORY_DONATE_ACTION);
1160+
b_show = true;
1161+
}
1162+
//-Alundaio
1163+
11351164
void CUIActorMenu::ProcessPropertiesBoxClicked(CUIWindow* w, void* d)
11361165
{
11371166
PIItem item = CurrentIItem();
@@ -1147,6 +1176,7 @@ void CUIActorMenu::ProcessPropertiesBoxClicked(CUIWindow* w, void* d)
11471176
case INVENTORY_TO_SLOT_ACTION: ToSlot(cell_item, true, item->BaseSlot()); break;
11481177
case INVENTORY_TO_BELT_ACTION: ToBelt(cell_item, false); break;
11491178
case INVENTORY_TO_BAG_ACTION: ToBag(cell_item, false); break;
1179+
case INVENTORY_DONATE_ACTION: DonateCurrentItem(cell_item); break;
11501180
case INVENTORY_EAT_ACTION: TryUseItem(cell_item); break;
11511181
case INVENTORY_EAT2_ACTION:
11521182
{
@@ -1178,6 +1208,36 @@ void CUIActorMenu::ProcessPropertiesBoxClicked(CUIWindow* w, void* d)
11781208
}
11791209
break;
11801210
}
1211+
case INVENTORY_EAT4_ACTION:
1212+
{
1213+
CGameObject* GO = smart_cast<CGameObject*>(item);
1214+
const pcstr functor_name = READ_IF_EXISTS(pSettings, r_string, GO->cNameSect(), "use3_functor", 0);
1215+
if (functor_name)
1216+
{
1217+
luabind::functor<bool> funct3;
1218+
if (ai().script_engine().functor(functor_name, funct3))
1219+
{
1220+
if (funct3(GO->lua_game_object()))
1221+
TryUseItem(cell_item);
1222+
}
1223+
}
1224+
break;
1225+
}
1226+
case INVENTORY_EAT5_ACTION:
1227+
{
1228+
CGameObject* GO = smart_cast<CGameObject*>(item);
1229+
const pcstr functor_name = READ_IF_EXISTS(pSettings, r_string, GO->cNameSect(), "use4_functor", 0);
1230+
if (functor_name)
1231+
{
1232+
luabind::functor<bool> funct4;
1233+
if (ai().script_engine().functor(functor_name, funct4))
1234+
{
1235+
if (funct4(GO->lua_game_object()))
1236+
TryUseItem(cell_item);
1237+
}
1238+
}
1239+
break;
1240+
}
11811241
case INVENTORY_DROP_ACTION:
11821242
{
11831243
void* d = m_UIPropertiesBox->GetClickedItem()->GetData();

src/xrGame/ui/UIActorMenuTrade.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,28 @@ void CUIActorMenu::TransferItems(
532532
pTrade->pThis.inv_owner->set_money(pTrade->pThis.inv_owner->get_money(), true);
533533
pTrade->pPartner.inv_owner->set_money(pTrade->pPartner.inv_owner->get_money(), true);
534534
}
535+
536+
//Alundaio: Donate current item while in trade menu
537+
void CUIActorMenu::DonateCurrentItem(CUICellItem* cell_item)
538+
{
539+
if (!m_partner_trade || !m_pTradePartnerList)
540+
return;
541+
542+
CUIDragDropListEx* invlist = GetListByType(iActorBag);
543+
if (!invlist->IsOwner(cell_item))
544+
return;
545+
546+
PIItem item = static_cast<PIItem>(cell_item->m_pData);
547+
if (!item)
548+
return;
549+
550+
invlist->RemoveItem(cell_item, false);
551+
552+
m_partner_trade->TransferItem(item, true, true);
553+
554+
m_pTradePartnerList->SetItem(cell_item);
555+
556+
SetCurrentItem(nullptr);
557+
UpdateItemsPlace();
558+
}
559+
//-Alundaio

src/xrGame/ui/UIMessages.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ enum EUIMessages
9595
//Alundaio
9696
INVENTORY_EAT2_ACTION,
9797
INVENTORY_EAT3_ACTION,
98+
INVENTORY_EAT4_ACTION,
99+
INVENTORY_EAT5_ACTION,
100+
INVENTORY_DONATE_ACTION,
98101
//-Alundaio
99102
INVENTORY_PLAY_ACTION,
100103
INVENTORY_TO_BELT_ACTION,

0 commit comments

Comments
 (0)