From 9c32e31edf7c283d939910f23b9f59edba0d2db6 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 18 Jul 2014 01:02:25 +0200 Subject: Items should first added to the first slot, not the latest. --- src/ItemGrid.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ItemGrid.cpp b/src/ItemGrid.cpp index cd36b1f2a..395547545 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()) { -- cgit v1.2.3 From 2e9aed793a5d4cde9fc93913ca0769fb1a913346 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 18 Jul 2014 01:16:49 +0200 Subject: Fixed the armor slot in creative mode. Also removed that armor get directly to the armor slot. It is extremely buggy and unnecessary. --- src/Inventory.cpp | 9 --------- src/UI/SlotArea.cpp | 13 +++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Inventory.cpp b/src/Inventory.cpp index 38d3c886d..18154bafd 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -102,15 +102,6 @@ int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryT { cItem ToAdd(a_Item); int res = 0; - if (ItemCategory::IsArmor(a_Item.m_ItemType)) - { - res = m_ArmorSlots.AddItem(ToAdd, a_AllowNewStacks); - ToAdd.m_ItemCount -= res; - if (ToAdd.m_ItemCount == 0) - { - return res; - } - } res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1); ToAdd.m_ItemCount = a_Item.m_ItemCount - res; diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 21b6ed0c8..f331c2fc2 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())); + 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; + } + + // Creative inventory must treat a_ClickedItem as a DraggedItem instead, replacing the inventory slot with it + SetSlot(a_SlotNum, a_Player, a_ClickedItem); + return; + } + bool bAsync = false; if (GetSlot(a_SlotNum, a_Player) == NULL) { -- cgit v1.2.3 From e32b0ce4fa1e81c48a5036bc4c43112fda7ffada Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 18 Jul 2014 16:38:59 +0200 Subject: Moved comment. --- src/UI/SlotArea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index f331c2fc2..6f4f65ca3 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1866,6 +1866,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C { ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); + // Creative inventory must treat a_ClickedItem as a DraggedItem instead, replacing the inventory slot with it if (a_Player.IsGameModeCreative() && (m_ParentWindow.GetWindowType() == cWindow::wtInventory)) { if ((a_ClickAction == caDropKey) || (a_ClickAction == caCtrlDropKey)) @@ -1874,7 +1875,6 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C return; } - // Creative inventory must treat a_ClickedItem as a DraggedItem instead, replacing the inventory slot with it SetSlot(a_SlotNum, a_Player, a_ClickedItem); return; } -- cgit v1.2.3 From 897d68dc35620f0e6c33fe4a6083a76ab43a9a57 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 20 Jul 2014 01:22:58 +0200 Subject: Add armor items directly to the armor slots. --- src/Inventory.cpp | 13 +++++++++++++ src/UI/SlotArea.cpp | 4 ++-- src/UI/SlotArea.h | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Inventory.cpp b/src/Inventory.cpp index 18154bafd..fff6e4a4e 100644 --- a/src/Inventory.cpp +++ b/src/Inventory.cpp @@ -103,6 +103,19 @@ 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)) + { + for (size_t i = 0; i < (size_t)m_ArmorSlots.GetNumSlots(); i++) + { + if (m_ArmorSlots.GetSlot(i).IsEmpty() && cSlotAreaArmor::CanPlaceArmorInSlot(i, a_Item)) + { + m_ArmorSlots.SetSlot(i, a_Item); + return a_Item.m_ItemCount; + } + } + } + res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1); ToAdd.m_ItemCount = a_Item.m_ItemCount - res; if (ToAdd.m_ItemCount == 0) diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 6f4f65ca3..e9b1ef8e0 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1926,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); @@ -1945,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); } ; -- cgit v1.2.3 From 6e2025d12544e33c379f0d03ab875faad08c7330 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 26 Jul 2014 13:29:25 +0200 Subject: Change comment. --- src/UI/SlotArea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index e9b1ef8e0..b5f84c24c 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1866,7 +1866,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C { ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); - // Creative inventory must treat a_ClickedItem as a DraggedItem instead, replacing the inventory slot with it + // 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)) -- cgit v1.2.3