diff options
Diffstat (limited to 'src/UI')
-rw-r--r-- | src/UI/BeaconWindow.h | 2 | ||||
-rw-r--r-- | src/UI/ChestWindow.h | 2 | ||||
-rw-r--r-- | src/UI/InventoryWindow.h | 2 | ||||
-rw-r--r-- | src/UI/SlotArea.cpp | 56 | ||||
-rw-r--r-- | src/UI/SlotArea.h | 78 | ||||
-rw-r--r-- | src/UI/Window.cpp | 42 | ||||
-rw-r--r-- | src/UI/Window.h | 64 |
7 files changed, 123 insertions, 123 deletions
diff --git a/src/UI/BeaconWindow.h b/src/UI/BeaconWindow.h index fa28b41ba..2b35e9d4a 100644 --- a/src/UI/BeaconWindow.h +++ b/src/UI/BeaconWindow.h @@ -25,7 +25,7 @@ public: cBeaconWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconEntity * a_Beacon); cBeaconEntity * GetBeaconEntity(void) const { return m_Beacon; } - + virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override; // cWindow Overrides: diff --git a/src/UI/ChestWindow.h b/src/UI/ChestWindow.h index a3b20cdd9..bf8ef4f2f 100644 --- a/src/UI/ChestWindow.h +++ b/src/UI/ChestWindow.h @@ -32,7 +32,7 @@ public: virtual void OpenedByPlayer(cPlayer & a_Player) override; virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override; - + protected: cWorld * m_World; int m_BlockX, m_BlockY, m_BlockZ; // Position of the chest, for the window-close packet diff --git a/src/UI/InventoryWindow.h b/src/UI/InventoryWindow.h index 10952d37f..c02dcfbbb 100644 --- a/src/UI/InventoryWindow.h +++ b/src/UI/InventoryWindow.h @@ -24,7 +24,7 @@ public: cInventoryWindow(cPlayer & a_Player); virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override; - + protected: cPlayer & m_Player; }; diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index dc89ff8d4..2cef9b06d 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -48,7 +48,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA ItemToFullString(*GetSlot(a_SlotNum, a_Player)).c_str() ); */ - + ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); bool bAsync = false; @@ -57,7 +57,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA LOGWARNING("GetSlot(%d) returned nullptr! Ignoring click", a_SlotNum); return; } - + switch (a_ClickAction) { case caShiftLeftClick: @@ -100,7 +100,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA break; } } - + cItem Slot(*GetSlot(a_SlotNum, a_Player)); if (!Slot.IsSameType(a_ClickedItem)) { @@ -154,7 +154,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA } break; } - + case caLeftClick: { // Left-clicked @@ -193,7 +193,7 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA return; } } // switch (a_ClickAction - + SetSlot(a_SlotNum, a_Player, Slot); if (bAsync) { @@ -216,7 +216,7 @@ void cSlotArea::ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ Slot.Empty(); } SetSlot(a_SlotNum, a_Player, Slot); - + // Some clients try to guess our actions and not always right (armor slots in 1.2.5), so we fix them: m_ParentWindow.BroadcastWholeWindow(); } @@ -240,14 +240,14 @@ void cSlotArea::DblClicked(cPlayer & a_Player, int a_SlotNum) LOGD("%s DblClicked with an empty hand over empty slot, ignoring", a_Player.GetName().c_str()); return; } - + // Add as many items from the surrounding area into hand as possible: // First skip full stacks, then if there's still space, process full stacks as well: if (!m_ParentWindow.CollectItemsToHand(Dragging, *this, a_Player, false)) { m_ParentWindow.CollectItemsToHand(Dragging, *this, a_Player, true); } - + m_ParentWindow.BroadcastWholeWindow(); // We need to broadcast, in case the window was a chest opened by multiple players } @@ -560,7 +560,7 @@ void cSlotAreaCrafting::OnPlayerRemoved(cPlayer & a_Player) { // Toss all items on the crafting grid: TossItems(a_Player, 1, m_NumSlots); - + // Remove the current recipe from the player -> recipe map: for (cRecipeMap::iterator itr = m_Recipes.begin(), end = m_Recipes.end(); itr != end; ++itr) { @@ -640,7 +640,7 @@ void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player) // Get the new recipe and update the result slot: UpdateRecipe(a_Player); - + // We're done. Send all changes to the client and bail out: m_ParentWindow.BroadcastWholeWindow(); } @@ -667,7 +667,7 @@ void cSlotAreaCrafting::ShiftClickedResult(cPlayer & a_Player) // Couldn't distribute all of it. Bail out return; } - + // Distribute the result, this time for real: ResultCopy = Result; m_ParentWindow.DistributeStack(ResultCopy, 0, a_Player, this, true); @@ -681,7 +681,7 @@ void cSlotAreaCrafting::ShiftClickedResult(cPlayer & a_Player) // Broadcast the window, we sometimes move items to different locations than Vanilla, causing needless desyncs: m_ParentWindow.BroadcastWholeWindow(); - + // If the recipe has changed, bail out: if (!Recipe.GetResult().IsEqual(Result)) { @@ -737,7 +737,7 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) return itr->second; } } // for itr - m_Recipes[] - + // Not found. Add a new one: cCraftingGrid Grid(GetPlayerSlots(a_Player) + 1, m_GridSize, m_GridSize); cCraftingRecipe Recipe(Grid); @@ -906,7 +906,7 @@ void cSlotAreaAnvil::ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem OnTakeResult(a_Player); } SetSlot(a_SlotNum, a_Player, Slot); - + // Some clients try to guess our actions and not always right (armor slots in 1.2.5), so we fix them: m_ParentWindow.BroadcastWholeWindow(); } @@ -1055,7 +1055,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) cItem Input(*GetSlot(0, a_Player)); cItem SecondInput(*GetSlot(1, a_Player)); cItem Output(*GetSlot(2, a_Player)); - + if (Input.IsEmpty()) { Output.Empty(); @@ -1071,7 +1071,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) if (!SecondInput.IsEmpty()) { bool IsEnchantBook = (SecondInput.m_ItemType == E_ITEM_ENCHANTED_BOOK); - + RepairCost += SecondInput.m_RepairCost; if (Input.IsDamageable() && cItemHandler::GetItemHandler(Input)->CanRepairWithRawMaterial(SecondInput.m_ItemType)) { @@ -1307,7 +1307,7 @@ void cSlotAreaBeacon::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ { return; } - + Slot = DraggingItem.CopyOne(); DraggingItem.m_ItemCount -= 1; if (DraggingItem.m_ItemCount <= 0) @@ -1459,7 +1459,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio break; } } - + cItem Slot(*GetSlot(a_SlotNum, a_Player)); if (!Slot.IsSameType(a_ClickedItem)) { @@ -2227,12 +2227,12 @@ void cSlotAreaInventoryBase::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAc DropClicked(a_Player, a_SlotNum, (a_ClickAction == caCtrlDropKey)); return; } - + // Creative inventory must treat a_ClickedItem as a DraggedItem instead, replacing the inventory slot with it SetSlot(a_SlotNum, a_Player, a_ClickedItem); return; } - + // Survival inventory and all other windows' inventory has the same handling as normal slot areas super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); return; @@ -2316,7 +2316,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C DropClicked(a_Player, a_SlotNum, (a_ClickAction == caCtrlDropKey)); return; } - + SetSlot(a_SlotNum, a_Player, a_ClickedItem); return; } @@ -2473,18 +2473,18 @@ const cItem * cSlotAreaTemporary::GetSlot(int a_SlotNum, cPlayer & a_Player) con { LOGERROR("cSlotAreaTemporary: player \"%s\" not found for slot %d!", a_Player.GetName().c_str(), a_SlotNum); ASSERT(!"cSlotAreaTemporary: player not found!"); - + // Player not found, this should not happen, ever! Return nullptr, but things may break by this. return nullptr; } - + if (a_SlotNum >= static_cast<int>(itr->second.size())) { LOGERROR("cSlotAreaTemporary: asking for more slots than actually stored!"); ASSERT(!"cSlotAreaTemporary: asking for more slots than actually stored!"); return nullptr; } - + return &(itr->second[static_cast<size_t>(a_SlotNum)]); } @@ -2501,13 +2501,13 @@ void cSlotAreaTemporary::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem LOGWARNING("cSlotAreaTemporary: player not found!"); return; } - + if (a_SlotNum >= static_cast<int>(itr->second.size())) { LOGERROR("cSlotAreaTemporary: asking for more slots than actually stored!"); return; } - + itr->second[static_cast<size_t>(a_SlotNum)] = a_Item; } @@ -2544,7 +2544,7 @@ void cSlotAreaTemporary::TossItems(cPlayer & a_Player, int a_Begin, int a_End) LOGWARNING("Player tossing items (%s) not found in the item map", a_Player.GetName().c_str()); return; } - + cItems Drops; for (int i = a_Begin; i < a_End; i++) { @@ -2555,7 +2555,7 @@ void cSlotAreaTemporary::TossItems(cPlayer & a_Player, int a_Begin, int a_End) } Item.Empty(); } // for i - itr->second[] - + double vX = 0, vY = 0, vZ = 0; EulerToVector(-a_Player.GetYaw(), a_Player.GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 0ff36ce50..b5809b872 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -33,18 +33,18 @@ class cSlotArea public: cSlotArea(int a_NumSlots, cWindow & a_ParentWindow); virtual ~cSlotArea() {} // force a virtual destructor in all subclasses - + int GetNumSlots(void) const { return m_NumSlots; } - + /** Called to retrieve an item in the specified slot for the specified player. Must return a valid cItem. */ virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const = 0; - + /** Called to set an item in the specified slot for the specified player */ virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) = 0; - + /** Called when a player clicks in the window. Parameters taken from the click packet. */ virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem); - + /** Called from Clicked when the action is a shiftclick (left or right) */ virtual void ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem); @@ -62,17 +62,17 @@ public: /** Called when a new player opens the same parent window. The window already tracks the player. CS-locked. */ virtual void OnPlayerAdded(cPlayer & a_Player); - + /** Called when one of the players closes the parent window. The window already doesn't track the player. CS-locked. */ virtual void OnPlayerRemoved(cPlayer & a_Player); - + /** Called to store as much of a_ItemStack in the area as possible. a_ItemStack is modified to reflect the change. The default implementation searches each slot for available space and distributes the stack there. 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) If a_KeepEmptySlots is true, empty slots will be skipped and won't be filled */ virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill); - + /** Called on DblClicking to collect all stackable items into hand. The items are accumulated in a_Dragging and removed from the slots immediately. If a_CollectFullStacks is false, slots with full stacks are skipped while collecting. @@ -93,16 +93,16 @@ class cSlotAreaInventoryBase : public cSlotArea { typedef cSlotArea super; - + public: cSlotAreaInventoryBase(int a_NumSlots, int a_SlotOffset, cWindow & a_ParentWindow); - + // Creative inventory's click handling is somewhat different from survival inventory's, handle that here: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) 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; - + protected: int m_SlotOffset; // Index that this area's slot 0 has in the underlying cInventory } ; @@ -116,7 +116,7 @@ class cSlotAreaInventory : public cSlotAreaInventoryBase { typedef cSlotAreaInventoryBase super; - + public: cSlotAreaInventory(cWindow & a_ParentWindow) : cSlotAreaInventoryBase(cInventory::invInventoryCount, cInventory::invInventoryOffset, a_ParentWindow) @@ -133,7 +133,7 @@ class cSlotAreaHotBar : public cSlotAreaInventoryBase { typedef cSlotAreaInventoryBase super; - + public: cSlotAreaHotBar(cWindow & a_ParentWindow) : cSlotAreaInventoryBase(cInventory::invHotbarCount, cInventory::invHotbarOffset, a_ParentWindow) @@ -174,18 +174,18 @@ class cSlotAreaItemGrid : public cItemGrid::cListener { typedef cSlotArea super; - + public: cSlotAreaItemGrid(cItemGrid & a_ItemGrid, cWindow & a_ParentWindow); - + virtual ~cSlotAreaItemGrid(); - + 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; protected: cItemGrid & m_ItemGrid; - + // cItemGrid::cListener overrides: virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override; } ; @@ -201,24 +201,24 @@ class cSlotAreaTemporary : public cSlotArea { typedef cSlotArea super; - + public: cSlotAreaTemporary(int a_NumSlots, cWindow & a_ParentWindow); - + // cSlotArea overrides: 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; virtual void OnPlayerAdded (cPlayer & a_Player) override; virtual void OnPlayerRemoved(cPlayer & a_Player) override; - + /** Tosses the player's items in slots [a_Begin, a_End) (ie. incl. a_Begin, but excl. a_End) */ void TossItems(cPlayer & a_Player, int a_Begin, int a_End); - + protected: typedef std::map<UInt32, std::vector<cItem> > cItemMap; // Maps EntityID -> items - + cItemMap m_Items; - + /** Returns the pointer to the slot array for the player specified. */ cItem * GetPlayerSlots(cPlayer & a_Player); } ; @@ -231,7 +231,7 @@ class cSlotAreaCrafting : public cSlotAreaTemporary { typedef cSlotAreaTemporary super; - + public: /** a_GridSize is allowed to be only 2 or 3 */ cSlotAreaCrafting(int a_GridSize, cWindow & a_ParentWindow); @@ -241,7 +241,7 @@ public: virtual void DblClicked (cPlayer & a_Player, int a_SlotNum) override; virtual void OnPlayerRemoved(cPlayer & a_Player) override; virtual void SetSlot (int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; - + // Distributing items into this area is completely disabled virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override; @@ -250,14 +250,14 @@ protected: /** Maps player's EntityID -> current recipe. Not a std::map because cCraftingGrid needs proper constructor params. */ typedef std::list<std::pair<UInt32, cCraftingRecipe> > cRecipeMap; - + int m_GridSize; cRecipeMap m_Recipes; - + /** Handles a click in the result slot. Crafts using the current recipe, if possible. */ void ClickedResult(cPlayer & a_Player); - + /** Handles a shift-click in the result slot. Crafts using the current recipe until it changes or no more space for result. */ void ShiftClickedResult(cPlayer & a_Player); @@ -267,7 +267,7 @@ protected: /** Updates the current recipe and result slot based on the ingredients currently in the crafting grid of the specified player. */ void UpdateRecipe(cPlayer & a_Player); - + /** Retrieves the recipe for the specified player from the map, or creates one if not found. */ cCraftingRecipe & GetRecipeForPlayer(cPlayer & a_Player); @@ -321,13 +321,13 @@ class cSlotAreaBeacon : public cItemGrid::cListener { typedef cSlotArea super; - + public: cSlotAreaBeacon(cBeaconEntity * a_Beacon, cWindow & a_ParentWindow); virtual ~cSlotAreaBeacon(); static bool IsPlaceableItem(short a_ItemType); - + 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, bool a_BackFill) override; virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; @@ -380,10 +380,10 @@ class cSlotAreaChest : { public: cSlotAreaChest(cChestEntity * a_Chest, cWindow & a_ParentWindow); - + 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; - + protected: cChestEntity * m_Chest; } ; @@ -397,10 +397,10 @@ class cSlotAreaDoubleChest : { public: cSlotAreaDoubleChest(cChestEntity * a_TopChest, cChestEntity * a_BottomChest, cWindow & a_ParentWindow); - + 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; - + protected: cChestEntity * m_TopChest; cChestEntity * m_BottomChest; @@ -432,17 +432,17 @@ class cSlotAreaFurnace : public cItemGrid::cListener { typedef cSlotArea super; - + public: cSlotAreaFurnace(cFurnaceEntity * a_Furnace, cWindow & a_ParentWindow); - + 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, bool a_BackFill) 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; - + protected: cFurnaceEntity * m_Furnace; diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index e23c3c698..5a2e55feb 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -253,7 +253,7 @@ void cWindow::Clicked( break; } } - + if (a_SlotNum < 0) { // TODO: Other click actions with irrelevant slot number (FS #371) @@ -270,7 +270,7 @@ void cWindow::Clicked( } LocalSlotNum -= itr->GetNumSlots(); } - + LOGWARNING("Slot number higher than available window slots: %d, max %d received from \"%s\"; ignoring.", a_SlotNum, GetNumSlots(), a_Player.GetName().c_str() ); @@ -288,7 +288,7 @@ void cWindow::OpenedByPlayer(cPlayer & a_Player) m_OpenedBy.remove(&a_Player); // Then add player m_OpenedBy.push_back(&a_Player); - + for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) { (*itr)->OnPlayerAdded(a_Player); @@ -326,7 +326,7 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) } // for itr - m_SlotAreas[] m_OpenedBy.remove(&a_Player); - + if ((m_WindowType != wtInventory) && m_OpenedBy.empty()) { Destroy(); @@ -336,7 +336,7 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) { delete this; } - + return true; } @@ -436,7 +436,7 @@ bool cWindow::CollectItemsToHand(cItem & a_Dragging, cSlotArea & a_Area, cPlayer return true; } } - + // a_Dragging still not full, ask slot areas before a_Area in the list: for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) { @@ -480,7 +480,7 @@ void cWindow::SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_Relativ ASSERT(!"cWindow::SendSlot(): unknown a_SlotArea"); return; } - + a_Player.GetClientHandle()->SendInventorySlot( m_WindowID, static_cast<short>(a_RelativeSlotNum + SlotBase), *(a_SlotArea->GetSlot(a_RelativeSlotNum, a_Player)) ); @@ -512,7 +512,7 @@ cSlotArea * cWindow::GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum) ASSERT(!"Invalid SlotNum"); return nullptr; } - + // Iterate through all the SlotAreas, find the correct one int LocalSlotNum = a_GlobalSlotNum; for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) @@ -524,7 +524,7 @@ cSlotArea * cWindow::GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum) } LocalSlotNum -= (*itr)->GetNumSlots(); } // for itr - m_SlotAreas[] - + // We shouldn't be here - the check at the beginnning should prevent this. Log and assert LOGWARNING("%s: GetNumSlots() is out of sync: %d; LocalSlotNum = %d", __FUNCTION__, GetNumSlots(), LocalSlotNum); ASSERT(!"Invalid GetNumSlots"); @@ -543,7 +543,7 @@ const cSlotArea * cWindow::GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum ASSERT(!"Invalid SlotNum"); return nullptr; } - + // Iterate through all the SlotAreas, find the correct one int LocalSlotNum = a_GlobalSlotNum; for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr) @@ -555,7 +555,7 @@ const cSlotArea * cWindow::GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum } LocalSlotNum -= (*itr)->GetNumSlots(); } // for itr - m_SlotAreas[] - + // We shouldn't be here - the check at the beginnning should prevent this. Log and assert LOGWARNING("%s: GetNumSlots() is out of sync: %d; LocalSlotNum = %d", __FUNCTION__, GetNumSlots(), LocalSlotNum); ASSERT(!"Invalid GetNumSlots"); @@ -590,20 +590,20 @@ void cWindow::OnLeftPaintEnd(cPlayer & a_Player) { // Process the entire action stored in the internal structures for inventory painting // distribute as many items as possible - + const cSlotNums & SlotNums = a_Player.GetInventoryPaintSlots(); cItem ToDistribute(a_Player.GetDraggingItem()); int ToEachSlot = static_cast<int>(ToDistribute.m_ItemCount) / static_cast<int>(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()); // To fix #2345 (custom recipes don't work when inventory-painting), we send the result slot explicitly once again @@ -622,16 +622,16 @@ void cWindow::OnRightPaintEnd(cPlayer & a_Player) 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(); } - + SendWholeWindow(*a_Player.GetClientHandle()); // To fix #2345 (custom recipes don't work when inventory-painting), we send the result slot explicitly once again @@ -651,7 +651,7 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int // 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; for (cSlotNums::const_iterator itr = a_SlotNums.begin(), end = a_SlotNums.end(); itr != end; ++itr) @@ -663,7 +663,7 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int LOGWARNING("%s: Bad SlotArea for slot %d", __FUNCTION__, *itr); continue; } - + // Modify the item at the slot cItem AtSlot(*Area->GetSlot(LocalSlotNum, a_Player)); int MaxStack = AtSlot.GetMaxStackSize(); @@ -712,7 +712,7 @@ void cWindow::BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum) ASSERT(!"Invalid slot area"); return; } - + // Broadcast the update packet: cCSLock Lock(m_CS); for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr) diff --git a/src/UI/Window.h b/src/UI/Window.h index 76d22a12c..8a70b5855 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -67,9 +67,9 @@ public: wtDropper = 10, wtAnimalChest = 11, }; - + // tolua_end - + static const int c_NumInventorySlots = 36; cWindow(WindowType a_WindowType, const AString & a_WindowTitle); @@ -81,32 +81,32 @@ public: cWindowOwner * GetOwner(void) { return m_Owner; } void SetOwner( cWindowOwner * a_Owner) { m_Owner = a_Owner; } - + /** Returns the total number of slots */ int GetNumSlots(void) const; - + /** Returns the number of slots, excluding the player's inventory (used for network protocols) */ int GetNumNonInventorySlots(void) const { return GetNumSlots() - c_NumInventorySlots; } - + // tolua_begin - + /** Returns the item at the specified slot for the specified player. Returns nullptr if invalid SlotNum requested */ const cItem * GetSlot(cPlayer & a_Player, int a_SlotNum) const; - + /** Sets the item to the specified slot for the specified player */ void SetSlot(cPlayer & a_Player, int a_SlotNum, const cItem & a_Item); - + /** Returns true if the specified slot is in the Player Main Inventory slotarea */ bool IsSlotInPlayerMainInventory(int a_SlotNum) const; - + /** Returns true if the specified slot is in the Player Hotbar slotarea */ bool IsSlotInPlayerHotbar(int a_SlotNum) const; - + /** Returns true if the specified slot is in the Player Main Inventory or Hotbar slotareas. Note that returns false for Armor. */ bool IsSlotInPlayerInventory(int a_SlotNum) const; - + // tolua_end - + /** Fills a_Slots with the slots read from m_SlotAreas[], for the specified player */ void GetSlots(cPlayer & a_Player, cItems & a_Slots) const; @@ -118,40 +118,40 @@ public: ); virtual void OpenedByPlayer(cPlayer & a_Player); - + /** Called when a player closes this window; notifies all slot areas. Returns true if close accepted */ virtual bool ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse); /** Sends the specified slot's contents to all clients of this window; the slot is specified as local in an area */ void BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum); - + /** Sends the contents of the whole window to the specified client */ void SendWholeWindow(cClientHandle & a_Client); - + /** Sends the contents of the whole window to all clients of this window. */ void BroadcastWholeWindow(void); // tolua_begin - + const AString & GetWindowTitle() const { return m_WindowTitle; } void SetWindowTitle(const AString & a_WindowTitle) { m_WindowTitle = a_WindowTitle; } - + /** Sends the UpdateWindowProperty (0x69) packet to all clients of the window */ virtual void SetProperty(short a_Property, short a_Value); - + /** Sends the UpdateWindowPropert(0x69) packet to the specified player */ virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player); // tolua_end void OwnerDestroyed(void); - + /** Calls the callback safely for each player that has this window open; returns true if all players have been enumerated */ bool ForEachPlayer(cItemCallback<cPlayer> & a_Callback); /** Calls the callback safely for each client that has this window open; returns true if all clients have been enumerated */ bool ForEachClient(cItemCallback<cClientHandle> & a_Callback); - + /** 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) */ @@ -162,58 +162,58 @@ public: if a_ShouldApply is false, only a_ItemStack is modified to reflect the number of fits (for fit-testing purposes) 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. If a_CollectFullStacks is false, slots with full stacks in the area are skipped while collecting. Returns true if full stack has been collected, false if there's space remaining to fill. */ bool CollectItemsToHand(cItem & a_Dragging, cSlotArea & a_Area, cPlayer & a_Player, bool a_CollectFullStacks); - + /** Used by cSlotAreas to send individual slots to clients, a_RelativeSlotNum is the slot number relative to a_SlotArea */ void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum); protected: cSlotAreas m_SlotAreas; - + char m_WindowID; int m_WindowType; AString m_WindowTitle; cCriticalSection m_CS; cPlayerList m_OpenedBy; - + bool m_IsDestroyed; - + cWindowOwner * m_Owner; - + static Byte m_WindowIDCounter; /** Sets the internal flag as "destroyed"; notifies the owner that the window is destroying */ virtual void Destroy(void); - + /** Returns the correct slot area for the specified window-global SlotNum Also returns the area-local SlotNum corresponding to the GlobalSlotNum If the global SlotNum is out of range, returns nullptr */ cSlotArea * GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum); - + /** Returns the correct slot area for the specified window-global SlotNum Also returns the area-local SlotNum corresponding to the GlobalSlotNum If the global SlotNum is out of range, returns nullptr. Const version. */ const cSlotArea * GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum) const; - + /** Prepares the internal structures for inventory painting from the specified player */ void OnPaintBegin(cPlayer & a_Player); - + /** Adds the slot to the internal structures for inventory painting by the specified player */ void OnPaintProgress(cPlayer & a_Player, int a_SlotNum); - + /** Processes the entire action stored in the internal structures for inventory painting; distributes as many items as possible */ void OnLeftPaintEnd(cPlayer & a_Player); /** Processes the entire action stored in the internal structures for inventory painting; distributes one item into each slot */ void OnRightPaintEnd(cPlayer & a_Player); - + /** Distributes a_NumToEachSlot items into the slots specified in a_SlotNums; returns the total number of items distributed */ int DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums); } ; // tolua_export |