From 2d8d7795de974d9bf7c963f99e4dad3a204eadc1 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 30 May 2013 10:10:58 +0000 Subject: Implemented right-click inventory painting git-svn-id: http://mc-server.googlecode.com/svn/trunk@1530 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/UI/Window.cpp | 78 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 26 deletions(-) (limited to 'source/UI/Window.cpp') diff --git a/source/UI/Window.cpp b/source/UI/Window.cpp index 57a565a05..2b279a22c 100644 --- a/source/UI/Window.cpp +++ b/source/UI/Window.cpp @@ -482,17 +482,60 @@ void cWindow::OnLeftPaintEnd(cPlayer & a_Player) const cSlotNums & SlotNums = a_Player.GetInventoryPaintSlots(); cItem ToDistribute(a_Player.GetDraggingItem()); + int ToEachSlot = (int)ToDistribute.m_ItemCount / SlotNums.size(); + + int NumDistributed = DistributeItemToSlots(a_Player, ToDistribute, ToEachSlot, SlotNums); + + // Remove the items distributed from the dragging item: + a_Player.GetDraggingItem().m_ItemCount -= NumDistributed; + if (a_Player.GetDraggingItem().m_ItemCount == 0) + { + a_Player.GetDraggingItem().Empty(); + } + + SendWholeWindow(*a_Player.GetClientHandle()); +} + + + + + +void cWindow::OnRightPaintEnd(cPlayer & a_Player) +{ + // Process the entire action stored in the internal structures for inventory painting + // distribute one item into each slot + + const cSlotNums & SlotNums = a_Player.GetInventoryPaintSlots(); + cItem ToDistribute(a_Player.GetDraggingItem()); + + int NumDistributed = DistributeItemToSlots(a_Player, ToDistribute, 1, SlotNums); + + // Remove the items distributed from the dragging item: + a_Player.GetDraggingItem().m_ItemCount -= NumDistributed; + if (a_Player.GetDraggingItem().m_ItemCount == 0) + { + a_Player.GetDraggingItem().Empty(); + } - if ((size_t)(ToDistribute.m_ItemCount) < SlotNums.size()) + SendWholeWindow(*a_Player.GetClientHandle()); +} + + + + + +int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums) +{ + if ((size_t)(a_Item.m_ItemCount) < a_SlotNums.size()) { - LOGWARNING("%s: Distributing less items (%d) than slots (%u)", __FUNCTION__, (int)ToDistribute.m_ItemCount, SlotNums.size()); + LOGWARNING("%s: Distributing less items (%d) than slots (%u)", __FUNCTION__, (int)a_Item.m_ItemCount, a_SlotNums.size()); // This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now + return 0; } // Distribute to individual slots, keep track of how many items were actually distributed (full stacks etc.) int NumDistributed = 0; - int ToEachSlot = (int)ToDistribute.m_ItemCount / SlotNums.size(); - for (cSlotNums::const_iterator itr = SlotNums.begin(), end = SlotNums.end(); itr != end; ++itr) + for (cSlotNums::const_iterator itr = a_SlotNums.begin(), end = a_SlotNums.end(); itr != end; ++itr) { int LocalSlotNum = 0; cSlotArea * Area = GetSlotArea(*itr, LocalSlotNum); @@ -508,38 +551,21 @@ void cWindow::OnLeftPaintEnd(cPlayer & a_Player) if (AtSlot.IsEmpty()) { // Empty, just move all of it there: - cItem ToStore(ToDistribute); - ToStore.m_ItemCount = std::min(ToEachSlot, (int)MaxStack); + cItem ToStore(a_Item); + ToStore.m_ItemCount = std::min(a_NumToEachSlot, (int)MaxStack); Area->SetSlot(LocalSlotNum, a_Player, ToStore); NumDistributed += ToStore.m_ItemCount; } else { - int CanStore = std::min(ToEachSlot, (int)MaxStack - AtSlot.m_ItemCount); + // Occupied, add and cap at MaxStack: + int CanStore = std::min(a_NumToEachSlot, (int)MaxStack - AtSlot.m_ItemCount); AtSlot.m_ItemCount += CanStore; Area->SetSlot(LocalSlotNum, a_Player, AtSlot); NumDistributed += CanStore; } } // for itr - SlotNums[] - - // Remove the items distributed from the dragging item: - a_Player.GetDraggingItem().m_ItemCount -= NumDistributed; - if (a_Player.GetDraggingItem().m_ItemCount == 0) - { - a_Player.GetDraggingItem().Empty(); - } - - SendWholeWindow(*a_Player.GetClientHandle()); -} - - - - - -void cWindow::OnRightPaintEnd(cPlayer & a_Player) -{ - // Process the entire action stored in the internal structures for inventory painting - // distribute one item into each slot + return NumDistributed; } -- cgit v1.2.3