From fdf83870925d30560ec7f853fdc19ec6c9e29155 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 20 Sep 2012 20:10:46 +0000 Subject: UI: Added shift-click support to most slot areas, except crafting. Also fixed survival inventory's crafting grid not working. git-svn-id: http://mc-server.googlecode.com/svn/trunk@868 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/UI/cWindow.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'source/UI/cWindow.cpp') diff --git a/source/UI/cWindow.cpp b/source/UI/cWindow.cpp index 475670425..71d2a1200 100644 --- a/source/UI/cWindow.cpp +++ b/source/UI/cWindow.cpp @@ -256,7 +256,45 @@ bool cWindow::ForEachClient(cItemCallback & a_Callback) -void cWindow::Destroy() +void cWindow::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, cSlotArea * a_ExcludeArea, 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) + { + // 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; + } + } + // The distribute to all other areas: + for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end() - 1; itr != end; ++itr) + { + if (*itr == a_ExcludeArea) + { + continue; + } + (*itr)->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (Pass == 0)); + if (a_ItemStack.IsEmpty()) + { + // Distributed it all + return; + } + } // for itr - m_SlotAreas[] + } // for Pass - repeat twice +} + + + + + +void cWindow::Destroy(void) { LOGD("Destroying window %p (type %d)", this, m_WindowType); if (m_Owner != NULL) @@ -316,6 +354,7 @@ cInventoryWindow::cInventoryWindow(cPlayer & a_Player) : m_SlotAreas.push_back(new cSlotAreaCrafting(2, *this)); // The creative inventory doesn't display it, but it's still counted into slot numbers m_SlotAreas.push_back(new cSlotAreaArmor(*this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); } @@ -330,6 +369,7 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : { m_SlotAreas.push_back(new cSlotAreaCrafting(3, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); } @@ -351,6 +391,7 @@ cChestWindow::cChestWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cChestEntit // TODO: Double chests m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); // Send out the chest-open packet: m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 1, E_BLOCK_CHEST); @@ -378,6 +419,7 @@ cFurnaceWindow::cFurnaceWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnac { m_SlotAreas.push_back(new cSlotAreaFurnace(a_Furnace, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); } -- cgit v1.2.3