commit
3a6b3a16b8
@ -102,13 +102,17 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT
|
||||
{
|
||||
cItem ToAdd(a_Item);
|
||||
int res = 0;
|
||||
|
||||
// When the item is a armor, try to set it directly to the armor slot.
|
||||
if (ItemCategory::IsArmor(a_Item.m_ItemType))
|
||||
{
|
||||
res = m_ArmorSlots.AddItem(ToAdd, a_AllowNewStacks);
|
||||
ToAdd.m_ItemCount -= res;
|
||||
if (ToAdd.m_ItemCount == 0)
|
||||
for (size_t i = 0; i < (size_t)m_ArmorSlots.GetNumSlots(); i++)
|
||||
{
|
||||
return res;
|
||||
if (m_ArmorSlots.GetSlot(i).IsEmpty() && cSlotAreaArmor::CanPlaceArmorInSlot(i, a_Item))
|
||||
{
|
||||
m_ArmorSlots.SetSlot(i, a_Item);
|
||||
return a_Item.m_ItemCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ int cItemGrid::AddItemToSlot(const cItem & a_ItemStack, int a_Slot, int a_Num, i
|
||||
int cItemGrid::AddItem(cItem & a_ItemStack, bool a_AllowNewStacks, int a_PrioritarySlot)
|
||||
{
|
||||
int NumLeft = a_ItemStack.m_ItemCount;
|
||||
int MaxStack = ItemHandler(a_ItemStack.m_ItemType)->GetMaxStackSize();
|
||||
int MaxStack = a_ItemStack.GetMaxStackSize();
|
||||
|
||||
// Try prioritarySlot first:
|
||||
if (
|
||||
@ -284,7 +284,7 @@ int cItemGrid::AddItem(cItem & a_ItemStack, bool a_AllowNewStacks, int a_Priorit
|
||||
}
|
||||
|
||||
// Scan existing stacks:
|
||||
for (int i = m_NumSlots - 1; i >= 0; i--)
|
||||
for (int i = 0; i < m_NumSlots; i++)
|
||||
{
|
||||
if (m_Slots[i].IsEqual(a_ItemStack))
|
||||
{
|
||||
@ -302,7 +302,7 @@ int cItemGrid::AddItem(cItem & a_ItemStack, bool a_AllowNewStacks, int a_Priorit
|
||||
return (a_ItemStack.m_ItemCount - NumLeft);
|
||||
}
|
||||
|
||||
for (int i = m_NumSlots - 1; i >= 0; i--)
|
||||
for (int i = 0; i < m_NumSlots; i++)
|
||||
{
|
||||
if (m_Slots[i].IsEmpty())
|
||||
{
|
||||
|
@ -1866,6 +1866,19 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
|
||||
{
|
||||
ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots()));
|
||||
|
||||
// When the player is in creative mode, the client sends the new item as a_ClickedItem, not the current item in the slot.
|
||||
if (a_Player.IsGameModeCreative() && (m_ParentWindow.GetWindowType() == cWindow::wtInventory))
|
||||
{
|
||||
if ((a_ClickAction == caDropKey) || (a_ClickAction == caCtrlDropKey))
|
||||
{
|
||||
DropClicked(a_Player, a_SlotNum, (a_ClickAction == caCtrlDropKey));
|
||||
return;
|
||||
}
|
||||
|
||||
SetSlot(a_SlotNum, a_Player, a_ClickedItem);
|
||||
return;
|
||||
}
|
||||
|
||||
bool bAsync = false;
|
||||
if (GetSlot(a_SlotNum, a_Player) == NULL)
|
||||
{
|
||||
@ -1913,7 +1926,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
|
||||
return;
|
||||
}
|
||||
|
||||
if (DraggingItem.IsEmpty() || CanPlaceInSlot(a_SlotNum, DraggingItem))
|
||||
if (DraggingItem.IsEmpty() || CanPlaceArmorInSlot(a_SlotNum, DraggingItem))
|
||||
{
|
||||
// Swap contents
|
||||
cItem tmp(DraggingItem);
|
||||
@ -1932,7 +1945,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
|
||||
|
||||
|
||||
|
||||
bool cSlotAreaArmor::CanPlaceInSlot(int a_SlotNum, const cItem & a_Item)
|
||||
bool cSlotAreaArmor::CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item)
|
||||
{
|
||||
switch (a_SlotNum)
|
||||
{
|
||||
|
@ -161,7 +161,7 @@ public:
|
||||
/** Called when a player clicks in the window. Parameters taken from the click packet. */
|
||||
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
|
||||
|
||||
bool CanPlaceInSlot(int a_SlotNum, const cItem & a_Item);
|
||||
static bool CanPlaceArmorInSlot(int a_SlotNum, const cItem & a_Item);
|
||||
} ;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user