summaryrefslogtreecommitdiffstats
path: root/src/UI/Window.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-12-13 18:49:11 +0100
committerHowaner <franzi.moos@googlemail.com>2014-12-13 18:49:11 +0100
commit8591935a4b48c24a16e8c103d474ee6803ce56a0 (patch)
treefe64a235a09dc353aa774854f0ea07bdfc99650f /src/UI/Window.cpp
parentOwn classes for all windows. (diff)
downloadcuberite-8591935a4b48c24a16e8c103d474ee6803ce56a0.tar
cuberite-8591935a4b48c24a16e8c103d474ee6803ce56a0.tar.gz
cuberite-8591935a4b48c24a16e8c103d474ee6803ce56a0.tar.bz2
cuberite-8591935a4b48c24a16e8c103d474ee6803ce56a0.tar.lz
cuberite-8591935a4b48c24a16e8c103d474ee6803ce56a0.tar.xz
cuberite-8591935a4b48c24a16e8c103d474ee6803ce56a0.tar.zst
cuberite-8591935a4b48c24a16e8c103d474ee6803ce56a0.zip
Diffstat (limited to 'src/UI/Window.cpp')
-rw-r--r--src/UI/Window.cpp50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index dc7558d8e..0cb501a65 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -32,7 +32,6 @@ cWindow::cWindow(WindowType a_WindowType, const AString & a_WindowTitle) :
m_WindowType(a_WindowType),
m_WindowTitle(a_WindowTitle),
m_IsDestroyed(false),
- m_ShouldDistributeToHotbarFirst(true),
m_Owner(nullptr)
{
if (a_WindowType == wtInventory)
@@ -392,43 +391,38 @@ bool cWindow::ForEachClient(cItemCallback<cClientHandle> & a_Callback)
-void cWindow::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, cSlotArea * a_ExcludeArea, bool a_ShouldApply)
+void cWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
{
- // Ask each slot area to take as much of the stack as it can.
- // First ask only slots that already have the same kind of item
- // Then ask any remaining slots
- for (int Pass = 0; Pass < 2; ++Pass)
+ cSlotAreas Areas;
+ for (auto Area : m_SlotAreas)
{
- if (m_ShouldDistributeToHotbarFirst)
+ if (Area != a_ClickedArea)
{
- // First distribute into the hotbar:
- if (a_ExcludeArea != m_SlotAreas.back())
- {
- m_SlotAreas.back()->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (Pass == 0));
- if (a_ItemStack.IsEmpty())
- {
- // Distributed it all
- return;
- }
- }
+ Areas.push_back(Area);
}
-
- // The distribute to all other areas:
- cSlotAreas::iterator end = m_ShouldDistributeToHotbarFirst ? (m_SlotAreas.end() - 1) : m_SlotAreas.end();
- for (cSlotAreas::iterator itr = m_SlotAreas.begin(); itr != end; ++itr)
+ }
+
+ DistributeStack(a_ItemStack, a_Player, Areas, a_ShouldApply, false);
+}
+
+
+
+
+
+void cWindow::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, cSlotAreas & a_AreasInOrder, bool a_ShouldApply, bool a_BackFill)
+{
+ for (size_t i = 0; i < 2; i++)
+ {
+ for (cSlotAreas::iterator itr = a_AreasInOrder.begin(); itr != a_AreasInOrder.end(); ++itr)
{
- if (*itr == a_ExcludeArea)
- {
- continue;
- }
- (*itr)->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (Pass == 0));
+ (*itr)->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (i == 0), a_BackFill);
if (a_ItemStack.IsEmpty())
{
// Distributed it all
return;
}
- } // for itr - m_SlotAreas[]
- } // for Pass - repeat twice
+ }
+ }
}