diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/Inventory.cpp | 12 | ||||
-rw-r--r-- | src/ItemGrid.cpp | 6 | ||||
-rw-r--r-- | src/UI/SlotArea.cpp | 17 | ||||
-rw-r--r-- | src/UI/SlotArea.h | 2 |
5 files changed, 28 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore index 400bf2c91..51987336c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ cloc.xsl *.suo /EveryNight.cmd /UploadLuaAPI.cmd +AllFiles.lst # IDE Stuff ## Sublime Text diff --git a/src/Inventory.cpp b/src/Inventory.cpp index 0f9716d89..3c2844612 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -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; + } } } diff --git a/src/ItemGrid.cpp b/src/ItemGrid.cpp index 38829cbf8..2344dc0a5 100644 --- a/src/ItemGrid.cpp +++ b/src/ItemGrid.cpp @@ -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()) { diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 21b6ed0c8..b5f84c24c 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -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) { diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 7f37159b7..fa842bb81 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -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); } ; |