From fb7f2993bf3b62c00d4502b846018b035ffbdb7a Mon Sep 17 00:00:00 2001 From: Julian Laubstein Date: Mon, 19 May 2014 14:34:34 +0200 Subject: Fixed some warnings in Server.cpp, and in UI/ --- src/UI/SlotArea.cpp | 3 ++- src/UI/Window.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 8833a767a..be3ce1f8d 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -600,7 +600,8 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) : cSlotAreaTemporary(3, a_ParentWindow), - m_MaximumCost(0) + m_MaximumCost(0), + m_StackSizeToBeUsedInRepair(0) { } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 46885390b..24b718156 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -856,7 +856,8 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : cWindow(wtEnchantment, "Enchant"), m_BlockX(a_BlockX), m_BlockY(a_BlockY), - m_BlockZ(a_BlockZ) + m_BlockZ(a_BlockZ), + m_SlotArea() { m_SlotAreas.push_back(new cSlotAreaEnchanting(*this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); -- cgit v1.2.3 From 7e2effb2d8297ddb99d86844e1b06b37c6e30d63 Mon Sep 17 00:00:00 2001 From: Julian Laubstein Date: Mon, 19 May 2014 15:46:36 +0200 Subject: Changed the m_slotarea position --- src/UI/Window.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/UI') diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 24b718156..98a9a0cec 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -854,10 +854,10 @@ void cAnvilWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ) cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : cWindow(wtEnchantment, "Enchant"), + m_SlotArea(), m_BlockX(a_BlockX), m_BlockY(a_BlockY), - m_BlockZ(a_BlockZ), - m_SlotArea() + m_BlockZ(a_BlockZ) { m_SlotAreas.push_back(new cSlotAreaEnchanting(*this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); -- cgit v1.2.3 From 843288493e1dcf9e22ac644d652ea3b13c7858ab Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 30 May 2014 23:41:17 +0200 Subject: Fix the furnace result slot. --- src/UI/SlotArea.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 2 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 507b45833..6853ff90c 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1381,14 +1381,99 @@ cSlotAreaFurnace::~cSlotAreaFurnace() void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); - if (m_Furnace == NULL) { LOGERROR("cSlotAreaFurnace::Clicked(): m_Furnace == NULL"); ASSERT(!"cSlotAreaFurnace::Clicked(): m_Furnace == NULL"); return; } + + if (a_SlotNum == 2) + { + bool bAsync = false; + if (GetSlot(a_SlotNum, a_Player) == NULL) + { + LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + return; + } + + if (a_ClickAction == caDblClick) + { + return; + } + + if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) + { + ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + } + + cItem Slot(*GetSlot(a_SlotNum, a_Player)); + if (!Slot.IsSameType(a_ClickedItem)) + { + LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots); + LOGWARNING("My item: %s", ItemToFullString(Slot).c_str()); + LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str()); + bAsync = true; + } + cItem & DraggingItem = a_Player.GetDraggingItem(); + + if (!DraggingItem.IsEmpty()) + { + if (!DraggingItem.IsEqual(Slot)) + { + return; + } + if ((DraggingItem.m_ItemCount + Slot.m_ItemCount) > Slot.GetMaxStackSize()) + { + return; + } + + DraggingItem.m_ItemCount += Slot.m_ItemCount; + Slot.Empty(); + } + else + { + switch (a_ClickAction) + { + case caDblClick: + { + DblClicked(a_Player, a_SlotNum); + return; + } + case caLeftClick: + { + DraggingItem = cItem(Slot); + Slot.Empty(); + break; + } + case caRightClick: + { + DraggingItem = Slot.CopyOne(); + DraggingItem.m_ItemCount = (char)(((float)Slot.m_ItemCount) / 2.f + 0.5f); + Slot.m_ItemCount -= DraggingItem.m_ItemCount; + + if (Slot.IsEmpty()) + { + Slot.Empty(); + } + break; + } + default: + { + ASSERT(!"Unhandled click type!"); + } + } + } + + SetSlot(a_SlotNum, a_Player, Slot); + if (bAsync) + { + m_ParentWindow.BroadcastWholeWindow(); + } + return; + } + + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); } @@ -1397,6 +1482,7 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a const cItem * cSlotAreaFurnace::GetSlot(int a_SlotNum, cPlayer & a_Player) const { + UNUSED(a_Player); // a_SlotNum ranges from 0 to 2, query the items from the underlying furnace: return &(m_Furnace->GetSlot(a_SlotNum)); } @@ -1407,6 +1493,7 @@ const cItem * cSlotAreaFurnace::GetSlot(int a_SlotNum, cPlayer & a_Player) const void cSlotAreaFurnace::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) { + UNUSED(a_Player); m_Furnace->SetSlot(a_SlotNum, a_Item); } @@ -1416,6 +1503,7 @@ void cSlotAreaFurnace::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & void cSlotAreaFurnace::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) { + UNUSED(a_SlotNum); // Something has changed in the window, broadcast the entire window to all clients ASSERT(a_ItemGrid == &(m_Furnace->GetContents())); -- cgit v1.2.3 From 01fc93857cb18d918ab98109dabd9665038871af Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 31 May 2014 00:22:24 +0200 Subject: Change "Slot.IsEmpty()" to "Slot.m_ItemCount <= 0" --- src/UI/SlotArea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 6853ff90c..3acc49cde 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1452,7 +1452,7 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a DraggingItem.m_ItemCount = (char)(((float)Slot.m_ItemCount) / 2.f + 0.5f); Slot.m_ItemCount -= DraggingItem.m_ItemCount; - if (Slot.IsEmpty()) + if (Slot.m_ItemCount <= 0) { Slot.Empty(); } -- cgit v1.2.3 From d422aa4081cd5c64ab0df4017630674a245c701d Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 31 May 2014 00:25:20 +0200 Subject: Fix DBL bug. --- src/UI/SlotArea.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 3acc49cde..7c79e290a 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1397,11 +1397,6 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a return; } - if (a_ClickAction == caDblClick) - { - return; - } - if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) { ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); @@ -1419,6 +1414,10 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a if (!DraggingItem.IsEmpty()) { + if (a_ClickAction == caDblClick) + { + return; + } if (!DraggingItem.IsEqual(Slot)) { return; -- cgit v1.2.3 From 2030800ad78678b783224010e22382d413863975 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 31 May 2014 00:27:24 +0200 Subject: Set DraggingItem to Slot directly. --- src/UI/SlotArea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 7c79e290a..b3e126247 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1441,7 +1441,7 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a } case caLeftClick: { - DraggingItem = cItem(Slot); + DraggingItem = Slot; Slot.Empty(); break; } -- cgit v1.2.3 From 5368e664864094c51a919dc8846f2b41039417e6 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 1 Jun 2014 00:29:17 +0200 Subject: Missing return; --- src/UI/SlotArea.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index b3e126247..bc8dd9cd6 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1400,6 +1400,7 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) { ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + return; } cItem Slot(*GetSlot(a_SlotNum, a_Player)); -- cgit v1.2.3 From a18b6c231102c78604b9ada7e6ce8a4eb074591e Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 1 Jun 2014 00:43:09 +0200 Subject: Add HandleSmeltItem() call for achievements. --- src/UI/SlotArea.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index bc8dd9cd6..ac85322b3 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1397,12 +1397,6 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a return; } - if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) - { - ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); - return; - } - cItem Slot(*GetSlot(a_SlotNum, a_Player)); if (!Slot.IsSameType(a_ClickedItem)) { @@ -1411,8 +1405,15 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str()); bAsync = true; } - cItem & DraggingItem = a_Player.GetDraggingItem(); + if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) + { + HandleSmeltItem(Slot, a_Player); + ShiftClicked(a_Player, a_SlotNum, Slot); + return; + } + + cItem & DraggingItem = a_Player.GetDraggingItem(); if (!DraggingItem.IsEmpty()) { if (a_ClickAction == caDblClick) @@ -1429,6 +1430,7 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a } DraggingItem.m_ItemCount += Slot.m_ItemCount; + HandleSmeltItem(Slot, a_Player); Slot.Empty(); } else @@ -1443,6 +1445,7 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a case caLeftClick: { DraggingItem = Slot; + HandleSmeltItem(Slot, a_Player); Slot.Empty(); break; } @@ -1456,6 +1459,7 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a { Slot.Empty(); } + HandleSmeltItem(DraggingItem, a_Player); break; } default: -- cgit v1.2.3 From 12f3c0fcdf6e45cbeed630730edb1223a2ecc4d8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 1 Jun 2014 00:50:35 +0200 Subject: Players can't set items in the result slot, when they shift a item. --- src/UI/SlotArea.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/UI/SlotArea.h | 1 + 2 files changed, 39 insertions(+) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index ac85322b3..59a6384b1 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1484,6 +1484,44 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a +void cSlotAreaFurnace::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) +{ + for (int i = 0; i < 2; i++) + { + const cItem * Slot = GetSlot(i, a_Player); + if (!Slot->IsEqual(a_ItemStack) && (!Slot->IsEmpty() || a_KeepEmptySlots)) + { + // Different items + continue; + } + int NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; + if (NumFit <= 0) + { + // Full stack already + continue; + } + if (NumFit > a_ItemStack.m_ItemCount) + { + NumFit = a_ItemStack.m_ItemCount; + } + if (a_ShouldApply) + { + cItem NewSlot(a_ItemStack); + NewSlot.m_ItemCount = Slot->m_ItemCount + NumFit; + SetSlot(i, a_Player, NewSlot); + } + a_ItemStack.m_ItemCount -= NumFit; + if (a_ItemStack.IsEmpty()) + { + return; + } + } // for i - Slots +} + + + + + const cItem * cSlotAreaFurnace::GetSlot(int a_SlotNum, cPlayer & a_Player) const { UNUSED(a_Player); diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index e297bcff7..b4b693cf6 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -392,6 +392,7 @@ public: virtual ~cSlotAreaFurnace(); virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override; virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; -- cgit v1.2.3 From 98c575ebc276b9825c3da186b8b560811e855da6 Mon Sep 17 00:00:00 2001 From: worktycho Date: Wed, 4 Jun 2014 11:12:06 +0100 Subject: Make sure m_StackSizeToBeUsedInRepair Always has a valid value --- src/UI/SlotArea.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 59a6384b1..682f20c00 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -625,7 +625,8 @@ void cSlotAreaCrafting::HandleCraftItem(const cItem & a_Result, cPlayer & a_Play cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) : cSlotAreaTemporary(3, a_ParentWindow), - m_MaximumCost(0) + m_MaximumCost(0), + m_StackSizeToBeUsedInRepair(0); { } @@ -796,6 +797,7 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player) { cItem NewSecondItem(*Item); NewSecondItem.m_ItemCount -= m_StackSizeToBeUsedInRepair; + m_StackSizeToBeUsedInRepair = 0; SetSlot(1, a_Player, NewSecondItem); } else -- cgit v1.2.3 From c94d0c814442785b2be7654c3a8c0d9c1fc5f765 Mon Sep 17 00:00:00 2001 From: worktycho Date: Wed, 4 Jun 2014 11:39:21 +0100 Subject: derp --- src/UI/SlotArea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 682f20c00..728692f2a 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -626,7 +626,7 @@ void cSlotAreaCrafting::HandleCraftItem(const cItem & a_Result, cPlayer & a_Play cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) : cSlotAreaTemporary(3, a_ParentWindow), m_MaximumCost(0), - m_StackSizeToBeUsedInRepair(0); + m_StackSizeToBeUsedInRepair(0) { } -- cgit v1.2.3