From 8277e1ec4e3e761527bc850ac371f3b899d023bf Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 17 Dec 2014 19:14:01 +0100 Subject: C++11 and function rename. --- src/Bindings/LuaWindow.cpp | 18 ++++++++++++++++++ src/Bindings/LuaWindow.h | 1 + src/FurnaceRecipe.cpp | 3 +-- src/UI/AnvilWindow.h | 2 +- src/UI/BeaconWindow.h | 4 ++-- src/UI/ChestWindow.h | 4 ++-- src/UI/CraftingWindow.h | 6 +++--- src/UI/DropSpenserWindow.h | 4 ++-- src/UI/EnchantingWindow.h | 4 ++-- src/UI/EnderChestWindow.h | 4 ++-- src/UI/FurnaceWindow.h | 6 +++--- src/UI/HopperWindow.h | 4 ++-- src/UI/InventoryWindow.h | 8 ++++---- src/UI/MinecartWithChestWindow.h | 20 ++++++++++++++++++++ src/UI/Window.cpp | 24 +++--------------------- src/UI/Window.h | 9 +++++---- 16 files changed, 71 insertions(+), 50 deletions(-) diff --git a/src/Bindings/LuaWindow.cpp b/src/Bindings/LuaWindow.cpp index 35730878d..d4014059b 100644 --- a/src/Bindings/LuaWindow.cpp +++ b/src/Bindings/LuaWindow.cpp @@ -167,6 +167,24 @@ void cLuaWindow::Destroy(void) +void cLuaWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer& a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) +{ + cSlotAreas Areas; + for (auto Area : m_SlotAreas) + { + if (Area != a_ClickedArea) + { + Areas.push_back(Area); + } + } + + super::DistributeStackToAreas(a_ItemStack, a_Player, Areas, a_ShouldApply, false); +} + + + + + void cLuaWindow::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) { if (a_ItemGrid != &m_Contents) diff --git a/src/Bindings/LuaWindow.h b/src/Bindings/LuaWindow.h index dab99a2e2..76530d99d 100644 --- a/src/Bindings/LuaWindow.h +++ b/src/Bindings/LuaWindow.h @@ -84,6 +84,7 @@ protected: // cWindow overrides: virtual bool ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) override; virtual void Destroy(void) override; + virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override; // cItemGrid::cListener overrides: virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override; diff --git a/src/FurnaceRecipe.cpp b/src/FurnaceRecipe.cpp index fe46ed770..ea952a852 100644 --- a/src/FurnaceRecipe.cpp +++ b/src/FurnaceRecipe.cpp @@ -293,9 +293,8 @@ const cFurnaceRecipe::cRecipe * cFurnaceRecipe::GetRecipeFrom(const cItem & a_In bool cFurnaceRecipe::IsFuel(const cItem & a_Item) const { - for (FuelList::const_iterator itr = m_pState->Fuel.begin(); itr != m_pState->Fuel.end(); ++itr) + for (auto & Fuel : m_pState->Fuel) { - const cFuel & Fuel = *itr; if ((Fuel.In->m_ItemType == a_Item.m_ItemType) && (Fuel.In->m_ItemCount <= a_Item.m_ItemCount)) { return true; diff --git a/src/UI/AnvilWindow.h b/src/UI/AnvilWindow.h index fd5c77871..e1a91bfc6 100644 --- a/src/UI/AnvilWindow.h +++ b/src/UI/AnvilWindow.h @@ -70,7 +70,7 @@ public: // Inventory or Hotbar AreasInOrder.push_back(m_SlotAreas[0]); /* Anvil */ } - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } protected: diff --git a/src/UI/BeaconWindow.h b/src/UI/BeaconWindow.h index a2ec50f02..c4d337afd 100644 --- a/src/UI/BeaconWindow.h +++ b/src/UI/BeaconWindow.h @@ -44,7 +44,7 @@ public: // Beacon Area AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); } else { @@ -63,7 +63,7 @@ public: // Hotbar Area AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ } - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } diff --git a/src/UI/ChestWindow.h b/src/UI/ChestWindow.h index 852ec28ef..a34edff70 100644 --- a/src/UI/ChestWindow.h +++ b/src/UI/ChestWindow.h @@ -117,13 +117,13 @@ public: // Chest Area AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); } else { // Hotbar or Inventory AreasInOrder.push_back(m_SlotAreas[0]); /* Chest */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } diff --git a/src/UI/CraftingWindow.h b/src/UI/CraftingWindow.h index f5a0328f2..e6292175e 100644 --- a/src/UI/CraftingWindow.h +++ b/src/UI/CraftingWindow.h @@ -48,19 +48,19 @@ public: AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ } - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, (a_Slot == 0)); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, (a_Slot == 0)); } else if (a_ClickedArea == m_SlotAreas[1]) { // Inventory Area AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } else { // Hotbar AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } }; diff --git a/src/UI/DropSpenserWindow.h b/src/UI/DropSpenserWindow.h index ef8e2d0cd..8f5d5236c 100644 --- a/src/UI/DropSpenserWindow.h +++ b/src/UI/DropSpenserWindow.h @@ -40,13 +40,13 @@ public: // DropSpenser Area AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); } else { // Inventory or Hotbar AreasInOrder.push_back(m_SlotAreas[0]); /* DropSpenser */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } }; diff --git a/src/UI/EnchantingWindow.h b/src/UI/EnchantingWindow.h index a6386ffe2..620d8fcef 100644 --- a/src/UI/EnchantingWindow.h +++ b/src/UI/EnchantingWindow.h @@ -79,13 +79,13 @@ public: // Enchanting Area AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); } else { // Inventory or Hotbar AreasInOrder.push_back(m_SlotAreas[0]); /* Enchanting */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } diff --git a/src/UI/EnderChestWindow.h b/src/UI/EnderChestWindow.h index 4c7dd2495..d63689f54 100644 --- a/src/UI/EnderChestWindow.h +++ b/src/UI/EnderChestWindow.h @@ -58,13 +58,13 @@ public: // Chest Area AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); } else { // Hotbar or Inventory AreasInOrder.push_back(m_SlotAreas[0]); /* Chest */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } diff --git a/src/UI/FurnaceWindow.h b/src/UI/FurnaceWindow.h index fb0a50656..532f99928 100644 --- a/src/UI/FurnaceWindow.h +++ b/src/UI/FurnaceWindow.h @@ -43,14 +43,14 @@ public: // Result Slot AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); } else { // Furnace Input/Fuel Slot AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } else @@ -71,7 +71,7 @@ public: // Hotbar Area AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ } - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } }; diff --git a/src/UI/HopperWindow.h b/src/UI/HopperWindow.h index 4aa03c605..08e2a2644 100644 --- a/src/UI/HopperWindow.h +++ b/src/UI/HopperWindow.h @@ -40,13 +40,13 @@ public: // Hopper Area AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); } else { // Inventory or Hotbar AreasInOrder.push_back(m_SlotAreas[0]); /* Hopper */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } }; diff --git a/src/UI/InventoryWindow.h b/src/UI/InventoryWindow.h index a6ea7c793..31b85b1bc 100644 --- a/src/UI/InventoryWindow.h +++ b/src/UI/InventoryWindow.h @@ -50,28 +50,28 @@ public: AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */ AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */ } - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, (a_Slot == 0)); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, (a_Slot == 0)); } else if (a_ClickedArea == m_SlotAreas[1]) { // Armor Area AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */ AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } else if (a_ClickedArea == m_SlotAreas[2]) { // Inventory Area AreasInOrder.push_back(m_SlotAreas[1]); /* Armor */ AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } else { // Hotbar AreasInOrder.push_back(m_SlotAreas[1]); /* Armor */ AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */ - super::DistributeStack(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); } } diff --git a/src/UI/MinecartWithChestWindow.h b/src/UI/MinecartWithChestWindow.h index 57e9beedf..a2b5283a6 100644 --- a/src/UI/MinecartWithChestWindow.h +++ b/src/UI/MinecartWithChestWindow.h @@ -33,6 +33,26 @@ public: a_ChestCart->GetWorld()->BroadcastSoundEffect("random.chestopen", a_ChestCart->GetPosX(), a_ChestCart->GetPosY(), a_ChestCart->GetPosZ(), 1, 1); } + virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea* a_ClickedArea, bool a_ShouldApply) override + { + cSlotAreas AreasInOrder; + + if (a_ClickedArea == m_SlotAreas[0]) + { + // Chest Area + AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */ + AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */ + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true); + } + else + { + // Hotbar or Inventory + AreasInOrder.push_back(m_SlotAreas[0]); /* Chest */ + super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false); + } + } + + ~cMinecartWithChestWindow() { m_ChestCart->GetWorld()->BroadcastSoundEffect("random.chestclosed", m_ChestCart->GetPosX(), m_ChestCart->GetPosY(), m_ChestCart->GetPosZ(), 1, 1); diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 0cb501a65..8bb7607ff 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -391,31 +391,13 @@ bool cWindow::ForEachClient(cItemCallback & a_Callback) -void cWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) -{ - cSlotAreas Areas; - for (auto Area : m_SlotAreas) - { - if (Area != a_ClickedArea) - { - Areas.push_back(Area); - } - } - - 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) +void cWindow::DistributeStackToAreas(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) + for (auto SlotArea : a_AreasInOrder) { - (*itr)->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (i == 0), a_BackFill); + SlotArea->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (i == 0), a_BackFill); if (a_ItemStack.IsEmpty()) { // Distributed it all diff --git a/src/UI/Window.h b/src/UI/Window.h index 9d9a5d7e8..811cac812 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -153,11 +153,12 @@ public: /** Called on shift-clicking to distribute the stack into other areas; Modifies a_ItemStack as it is distributed! if a_ShouldApply is true, the changes are written into the slots; - if a_ShouldApply is false, only a_ItemStack is modified to reflect the number of fits (for fit-testing purposes) - */ - virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply); + if a_ShouldApply is false, only a_ItemStack is modified to reflect the number of fits (for fit-testing purposes) */ + virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) = 0; - void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, cSlotAreas & a_AreasInOrder, bool a_ShouldApply, bool a_BackFill); + /** Called from DistributeStack() to distribute the stack into a_AreasInOrder; Modifies a_ItemStack as it is distributed! + If a_BackFill is true, the areas will be filled from the back (right side). (Example: Empty Hotbar -> Item get in slot 8, not slot 0) */ + void DistributeStackToAreas(cItem & a_ItemStack, cPlayer & a_Player, cSlotAreas & a_AreasInOrder, bool a_ShouldApply, bool a_BackFill); /** Called on DblClicking to collect all stackable items from all areas into hand, starting with the specified area. The items are accumulated in a_Dragging and removed from the SlotAreas immediately. -- cgit v1.2.3