summaryrefslogtreecommitdiffstats
path: root/src/UI/ChestWindow.h
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2015-03-10 19:40:53 +0100
committerHowaner <franzi.moos@googlemail.com>2015-03-10 19:40:53 +0100
commit685f6e37138dc63391bfa587f6631fa303dcbe6b (patch)
tree3e0e7313c88c27d5f4a8d48f8959f3cc04b94486 /src/UI/ChestWindow.h
parentMerge branch 'master' into Inventory (diff)
downloadcuberite-685f6e37138dc63391bfa587f6631fa303dcbe6b.tar
cuberite-685f6e37138dc63391bfa587f6631fa303dcbe6b.tar.gz
cuberite-685f6e37138dc63391bfa587f6631fa303dcbe6b.tar.bz2
cuberite-685f6e37138dc63391bfa587f6631fa303dcbe6b.tar.lz
cuberite-685f6e37138dc63391bfa587f6631fa303dcbe6b.tar.xz
cuberite-685f6e37138dc63391bfa587f6631fa303dcbe6b.tar.zst
cuberite-685f6e37138dc63391bfa587f6631fa303dcbe6b.zip
Diffstat (limited to 'src/UI/ChestWindow.h')
-rw-r--r--src/UI/ChestWindow.h116
1 files changed, 11 insertions, 105 deletions
diff --git a/src/UI/ChestWindow.h b/src/UI/ChestWindow.h
index a34edff70..a3b20cdd9 100644
--- a/src/UI/ChestWindow.h
+++ b/src/UI/ChestWindow.h
@@ -10,8 +10,6 @@
#pragma once
#include "Window.h"
-#include "../BlockEntities/ChestEntity.h"
-#include "../Entities/Player.h"
@@ -23,109 +21,17 @@ class cChestWindow :
typedef cWindow super;
public:
- cChestWindow(cChestEntity * a_Chest) :
- cWindow(wtChest, (a_Chest->GetBlockType() == E_BLOCK_CHEST) ? "Chest" : "Trapped Chest"),
- m_World(a_Chest->GetWorld()),
- m_BlockX(a_Chest->GetPosX()),
- m_BlockY(a_Chest->GetPosY()),
- m_BlockZ(a_Chest->GetPosZ()),
- m_PrimaryChest(a_Chest),
- m_SecondaryChest(nullptr)
- {
- m_SlotAreas.push_back(new cSlotAreaChest(a_Chest, *this));
- m_SlotAreas.push_back(new cSlotAreaInventory(*this));
- m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
-
- // Play the opening sound:
- m_World->BroadcastSoundEffect("random.chestopen", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 1, 1);
-
- // Send out the chest-open packet:
- m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 1, a_Chest->GetBlockType());
- }
-
- cChestWindow(cChestEntity * a_PrimaryChest, cChestEntity * a_SecondaryChest) :
- cWindow(wtChest, (a_PrimaryChest->GetBlockType() == E_BLOCK_CHEST) ? "Double Chest" : "Double Trapped Chest"),
- m_World(a_PrimaryChest->GetWorld()),
- m_BlockX(a_PrimaryChest->GetPosX()),
- m_BlockY(a_PrimaryChest->GetPosY()),
- m_BlockZ(a_PrimaryChest->GetPosZ()),
- m_PrimaryChest(a_PrimaryChest),
- m_SecondaryChest(a_SecondaryChest)
- {
- m_SlotAreas.push_back(new cSlotAreaDoubleChest(a_PrimaryChest, a_SecondaryChest, *this));
- m_SlotAreas.push_back(new cSlotAreaInventory(*this));
- m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
-
- // Play the opening sound:
- m_World->BroadcastSoundEffect("random.chestopen", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 1, 1);
-
- // Send out the chest-open packet:
- m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 1, a_PrimaryChest->GetBlockType());
- }
-
- ~cChestWindow()
- {
- // Send out the chest-close packet:
- m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 0, m_PrimaryChest->GetBlockType());
-
- m_World->BroadcastSoundEffect("random.chestclosed", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 1, 1);
- }
-
- virtual bool ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) override
- {
- int ChunkX, ChunkZ;
-
- m_PrimaryChest->SetNumberOfPlayers(m_PrimaryChest->GetNumberOfPlayers() - 1);
- cChunkDef::BlockToChunk(m_PrimaryChest->GetPosX(), m_PrimaryChest->GetPosZ(), ChunkX, ChunkZ);
- m_PrimaryChest->GetWorld()->MarkRedstoneDirty(ChunkX, ChunkZ);
-
- if (m_SecondaryChest != nullptr)
- {
- m_SecondaryChest->SetNumberOfPlayers(m_SecondaryChest->GetNumberOfPlayers() - 1);
- cChunkDef::BlockToChunk(m_SecondaryChest->GetPosX(), m_SecondaryChest->GetPosZ(), ChunkX, ChunkZ);
- m_SecondaryChest->GetWorld()->MarkRedstoneDirty(ChunkX, ChunkZ);
- }
-
- cWindow::ClosedByPlayer(a_Player, a_CanRefuse);
- return true;
- }
-
- virtual void OpenedByPlayer(cPlayer & a_Player) override
- {
- int ChunkX, ChunkZ;
-
- m_PrimaryChest->SetNumberOfPlayers(m_PrimaryChest->GetNumberOfPlayers() + 1);
- cChunkDef::BlockToChunk(m_PrimaryChest->GetPosX(), m_PrimaryChest->GetPosZ(), ChunkX, ChunkZ);
- m_PrimaryChest->GetWorld()->MarkRedstoneDirty(ChunkX, ChunkZ);
-
- if (m_SecondaryChest != nullptr)
- {
- m_SecondaryChest->SetNumberOfPlayers(m_SecondaryChest->GetNumberOfPlayers() + 1);
- cChunkDef::BlockToChunk(m_SecondaryChest->GetPosX(), m_SecondaryChest->GetPosZ(), ChunkX, ChunkZ);
- m_SecondaryChest->GetWorld()->MarkRedstoneDirty(ChunkX, ChunkZ);
- }
-
- cWindow::OpenedByPlayer(a_Player);
- }
-
- 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);
- }
- }
+ cChestWindow(cChestEntity * a_Chest);
+
+ cChestWindow(cChestEntity * a_PrimaryChest, cChestEntity * a_SecondaryChest);
+
+ ~cChestWindow();
+
+ virtual bool ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) override;
+
+ 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;