Moved window code into cpp files
This commit is contained in:
parent
a96c21fc0d
commit
685f6e3713
@ -290,7 +290,7 @@ void cBeaconEntity::UsedBy(cPlayer * a_Player)
|
||||
OpenWindow(new cBeaconWindow(m_PosX, m_PosY, m_PosZ, this));
|
||||
Window = GetWindow();
|
||||
}
|
||||
|
||||
|
||||
if (Window != nullptr)
|
||||
{
|
||||
// if (a_Player->GetWindow() != Window)
|
||||
|
@ -9,7 +9,7 @@ include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/libevent/include
|
||||
|
||||
set(FOLDERS
|
||||
OSSupport HTTPServer Items Blocks Protocol Generating PolarSSL++ Bindings
|
||||
WorldStorage Mobs Entities Simulator UI BlockEntities Generating/Prefabs
|
||||
WorldStorage Mobs Entities Simulator BlockEntities UI Generating/Prefabs
|
||||
Noise
|
||||
)
|
||||
|
||||
@ -318,7 +318,7 @@ if (NOT MSVC)
|
||||
target_link_libraries(${EXECUTABLE}
|
||||
OSSupport HTTPServer Bindings Items Blocks Noise
|
||||
Protocol Generating Generating_Prefabs WorldStorage
|
||||
Mobs Entities Simulator UI BlockEntities PolarSSL++
|
||||
Mobs Entities Simulator BlockEntities UI PolarSSL++
|
||||
)
|
||||
endif ()
|
||||
if (WIN32)
|
||||
|
83
src/UI/AnvilWindow.cpp
Normal file
83
src/UI/AnvilWindow.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
|
||||
// AnvilWindow.cpp
|
||||
|
||||
// Representing the UI window for the anvil block
|
||||
|
||||
#include "Globals.h"
|
||||
#include "AnvilWindow.h"
|
||||
#include "SlotArea.h"
|
||||
|
||||
|
||||
|
||||
|
||||
cAnvilWindow::cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
||||
cWindow(wtAnvil, "Repair"),
|
||||
m_RepairedItemName(""),
|
||||
m_BlockX(a_BlockX),
|
||||
m_BlockY(a_BlockY),
|
||||
m_BlockZ(a_BlockZ)
|
||||
{
|
||||
m_AnvilSlotArea = new cSlotAreaAnvil(*this);
|
||||
m_SlotAreas.push_back(m_AnvilSlotArea);
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AString cAnvilWindow::GetRepairedItemName(void) const
|
||||
{
|
||||
return m_RepairedItemName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cAnvilWindow::SetRepairedItemName(const AString & a_Name, cPlayer * a_Player)
|
||||
{
|
||||
m_RepairedItemName = a_Name;
|
||||
if (a_Player != nullptr)
|
||||
{
|
||||
m_AnvilSlotArea->UpdateResult(*a_Player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cAnvilWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
|
||||
{
|
||||
a_PosX = m_BlockX;
|
||||
a_PosY = m_BlockY;
|
||||
a_PosZ = m_BlockZ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cAnvilWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
cSlotAreas AreasInOrder;
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[0])
|
||||
{
|
||||
// Anvil Slot
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inventory or Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Anvil */
|
||||
}
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -21,57 +21,18 @@ class cAnvilWindow :
|
||||
typedef cWindow super;
|
||||
|
||||
public:
|
||||
cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
||||
cWindow(wtAnvil, "Repair"),
|
||||
m_RepairedItemName(""),
|
||||
m_BlockX(a_BlockX),
|
||||
m_BlockY(a_BlockY),
|
||||
m_BlockZ(a_BlockZ)
|
||||
{
|
||||
m_AnvilSlotArea = new cSlotAreaAnvil(*this);
|
||||
m_SlotAreas.push_back(m_AnvilSlotArea);
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
|
||||
/** Gets the repaired item name. */
|
||||
AString GetRepairedItemName(void) const { return m_RepairedItemName; }
|
||||
AString GetRepairedItemName(void) const;
|
||||
|
||||
/** Set the repaired item name. */
|
||||
void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player)
|
||||
{
|
||||
m_RepairedItemName = a_Name;
|
||||
if (a_Player != nullptr)
|
||||
{
|
||||
m_AnvilSlotArea->UpdateResult(*a_Player);
|
||||
}
|
||||
}
|
||||
void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player);
|
||||
|
||||
/** Gets the Position from the Anvil */
|
||||
void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
|
||||
{
|
||||
a_PosX = m_BlockX;
|
||||
a_PosY = m_BlockY;
|
||||
a_PosZ = m_BlockZ;
|
||||
}
|
||||
void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ);
|
||||
|
||||
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])
|
||||
{
|
||||
// Anvil Slot
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inventory or Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Anvil */
|
||||
}
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
|
||||
protected:
|
||||
cSlotAreaAnvil * m_AnvilSlotArea;
|
||||
|
76
src/UI/BeaconWindow.cpp
Normal file
76
src/UI/BeaconWindow.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
|
||||
// BeaconWindow.cpp
|
||||
|
||||
// Representing the UI window for the beacon block
|
||||
|
||||
#include "Globals.h"
|
||||
#include "BeaconWindow.h"
|
||||
#include "SlotArea.h"
|
||||
#include "../BlockEntities/BeaconEntity.h"
|
||||
#include "../Entities/Player.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cBeaconWindow::cBeaconWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconEntity * a_Beacon) :
|
||||
cWindow(wtBeacon, "Beacon"),
|
||||
m_Beacon(a_Beacon)
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaBeacon(m_Beacon, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cBeaconWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
cSlotAreas AreasInOrder;
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[0])
|
||||
{
|
||||
// Beacon 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
|
||||
{
|
||||
if (cSlotAreaBeacon::IsPlaceableItem(a_ItemStack.m_ItemType) && (a_ItemStack.m_ItemCount == 1))
|
||||
{
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Beacon */
|
||||
}
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[1])
|
||||
{
|
||||
// Inventory Area
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hotbar Area
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
}
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cBeaconWindow::OpenedByPlayer(cPlayer & a_Player)
|
||||
{
|
||||
super::OpenedByPlayer(a_Player);
|
||||
|
||||
a_Player.GetClientHandle()->SendWindowProperty(*this, 0, m_Beacon->GetBeaconLevel());
|
||||
a_Player.GetClientHandle()->SendWindowProperty(*this, 1, m_Beacon->GetPrimaryEffect());
|
||||
a_Player.GetClientHandle()->SendWindowProperty(*this, 2, m_Beacon->GetSecondaryEffect());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -22,61 +22,14 @@ class cBeaconWindow :
|
||||
typedef cWindow super;
|
||||
|
||||
public:
|
||||
cBeaconWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconEntity * a_Beacon) :
|
||||
cWindow(wtBeacon, "Beacon"),
|
||||
m_Beacon(a_Beacon)
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaBeacon(m_Beacon, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
cSlotAreas AreasInOrder;
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[0])
|
||||
{
|
||||
// Beacon 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
|
||||
{
|
||||
if (cSlotAreaBeacon::IsPlaceableItem(a_ItemStack.m_ItemType) && (a_ItemStack.m_ItemCount == 1))
|
||||
{
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Beacon */
|
||||
}
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[1])
|
||||
{
|
||||
// Inventory Area
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hotbar Area
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
}
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
|
||||
// cWindow Overrides:
|
||||
virtual void OpenedByPlayer(cPlayer & a_Player) override
|
||||
{
|
||||
super::OpenedByPlayer(a_Player);
|
||||
|
||||
a_Player.GetClientHandle()->SendWindowProperty(*this, 0, m_Beacon->GetBeaconLevel());
|
||||
a_Player.GetClientHandle()->SendWindowProperty(*this, 1, m_Beacon->GetPrimaryEffect());
|
||||
a_Player.GetClientHandle()->SendWindowProperty(*this, 2, m_Beacon->GetSecondaryEffect());
|
||||
}
|
||||
virtual void OpenedByPlayer(cPlayer & a_Player) override;
|
||||
|
||||
protected:
|
||||
cBeaconEntity * m_Beacon;
|
||||
|
@ -6,7 +6,17 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
|
||||
|
||||
SET (SRCS
|
||||
SlotArea.cpp
|
||||
Window.cpp)
|
||||
Window.cpp
|
||||
AnvilWindow.cpp
|
||||
BeaconWindow.cpp
|
||||
ChestWindow.cpp
|
||||
CraftingWindow.cpp
|
||||
DropSpenserWindow.cpp
|
||||
EnchantingWindow.cpp
|
||||
EnderChestWindow.cpp
|
||||
FurnaceWindow.cpp
|
||||
HopperWindow.cpp
|
||||
InventoryWindow.cpp)
|
||||
|
||||
SET (HDRS
|
||||
SlotArea.h
|
||||
|
141
src/UI/ChestWindow.cpp
Normal file
141
src/UI/ChestWindow.cpp
Normal file
@ -0,0 +1,141 @@
|
||||
|
||||
// ChestWindow.cpp
|
||||
|
||||
// Representing the UI window for the chest block
|
||||
|
||||
#include "Globals.h"
|
||||
#include "ChestWindow.h"
|
||||
#include "../BlockEntities/ChestEntity.h"
|
||||
#include "../Entities/Player.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cChestWindow::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::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::~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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cChestWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChestWindow::OpenedByPlayer(cPlayer & a_Player)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChestWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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));
|
||||
cChestWindow(cChestEntity * a_Chest);
|
||||
|
||||
// Play the opening sound:
|
||||
m_World->BroadcastSoundEffect("random.chestopen", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 1, 1);
|
||||
cChestWindow(cChestEntity * a_PrimaryChest, cChestEntity * a_SecondaryChest);
|
||||
|
||||
// Send out the chest-open packet:
|
||||
m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 1, a_Chest->GetBlockType());
|
||||
}
|
||||
~cChestWindow();
|
||||
|
||||
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));
|
||||
virtual bool ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) override;
|
||||
|
||||
// Play the opening sound:
|
||||
m_World->BroadcastSoundEffect("random.chestopen", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 1, 1);
|
||||
virtual void OpenedByPlayer(cPlayer & a_Player) override;
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
|
||||
protected:
|
||||
cWorld * m_World;
|
||||
|
61
src/UI/CraftingWindow.cpp
Normal file
61
src/UI/CraftingWindow.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
// CraftingWindow.cpp
|
||||
|
||||
// Representing the UI window for the crafting block
|
||||
|
||||
#include "Globals.h"
|
||||
#include "CraftingWindow.h"
|
||||
#include "SlotArea.h"
|
||||
|
||||
|
||||
|
||||
|
||||
cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
||||
cWindow(wtWorkbench, "Crafting Table")
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaCrafting(3, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cCraftingWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
cSlotAreas AreasInOrder;
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[0])
|
||||
{
|
||||
// Crafting Area
|
||||
if (a_Slot == 0)
|
||||
{
|
||||
// Result Slot
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
}
|
||||
else
|
||||
{
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
}
|
||||
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::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -21,48 +21,9 @@ class cCraftingWindow :
|
||||
typedef cWindow super;
|
||||
|
||||
public:
|
||||
cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
||||
cWindow(wtWorkbench, "Crafting Table")
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaCrafting(3, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
|
||||
|
||||
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])
|
||||
{
|
||||
// Crafting Area
|
||||
if (a_Slot == 0)
|
||||
{
|
||||
// Result Slot
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
}
|
||||
else
|
||||
{
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
}
|
||||
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::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
};
|
||||
|
||||
|
||||
|
46
src/UI/DropSpenserWindow.cpp
Normal file
46
src/UI/DropSpenserWindow.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
// DropSpenserWindow.cpp
|
||||
|
||||
// Representing the UI window for the dropper/dispenser block
|
||||
|
||||
#include "Globals.h"
|
||||
#include "DropSpenserWindow.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cDropSpenserWindow::cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserEntity * a_DropSpenser) :
|
||||
cWindow(wtDropSpenser, (a_DropSpenser->GetBlockType() == E_BLOCK_DISPENSER) ? "Dispenser" : "Dropper")
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaItemGrid(a_DropSpenser->GetContents(), *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cDropSpenserWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
cSlotAreas AreasInOrder;
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[0])
|
||||
{
|
||||
// DropSpenser 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
|
||||
{
|
||||
// Inventory or Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* DropSpenser */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -22,33 +22,9 @@ class cDropSpenserWindow :
|
||||
typedef cWindow super;
|
||||
|
||||
public:
|
||||
cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserEntity * a_DropSpenser) :
|
||||
cWindow(wtDropSpenser, (a_DropSpenser->GetBlockType() == E_BLOCK_DISPENSER) ? "Dispenser" : "Dropper")
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaItemGrid(a_DropSpenser->GetContents(), *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserEntity * a_DropSpenser);
|
||||
|
||||
|
||||
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])
|
||||
{
|
||||
// DropSpenser 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
|
||||
{
|
||||
// Inventory or Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* DropSpenser */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
};
|
||||
|
||||
|
||||
|
100
src/UI/EnchantingWindow.cpp
Normal file
100
src/UI/EnchantingWindow.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
|
||||
// EnchantingWindow.cpp
|
||||
|
||||
// Representing the UI window for the enchanting block
|
||||
|
||||
#include "Globals.h"
|
||||
#include "EnchantingWindow.h"
|
||||
#include "SlotArea.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
||||
cWindow(wtEnchantment, "Enchant"),
|
||||
m_SlotArea(),
|
||||
m_BlockX(a_BlockX),
|
||||
m_BlockY(a_BlockY),
|
||||
m_BlockZ(a_BlockZ)
|
||||
{
|
||||
m_SlotArea = new cSlotAreaEnchanting(*this, m_BlockX, m_BlockY, m_BlockZ);
|
||||
m_SlotAreas.push_back(m_SlotArea);
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cEnchantingWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player)
|
||||
{
|
||||
if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
|
||||
{
|
||||
ASSERT(!"a_Property is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
m_PropertyValue[a_Property] = a_Value;
|
||||
super::SetProperty(a_Property, a_Value, a_Player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cEnchantingWindow::SetProperty(short a_Property, short a_Value)
|
||||
{
|
||||
if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
|
||||
{
|
||||
ASSERT(!"a_Property is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
m_PropertyValue[a_Property] = a_Value;
|
||||
super::SetProperty(a_Property, a_Value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
short cEnchantingWindow::GetPropertyValue(short a_Property)
|
||||
{
|
||||
if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
|
||||
{
|
||||
ASSERT(!"a_Property is invalid");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_PropertyValue[a_Property];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cEnchantingWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
cSlotAreas AreasInOrder;
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[0])
|
||||
{
|
||||
// Enchanting 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
|
||||
{
|
||||
// Inventory or Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Enchanting */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -21,73 +21,16 @@ class cEnchantingWindow :
|
||||
typedef cWindow super;
|
||||
|
||||
public:
|
||||
cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
|
||||
cWindow(wtEnchantment, "Enchant"),
|
||||
m_SlotArea(),
|
||||
m_BlockX(a_BlockX),
|
||||
m_BlockY(a_BlockY),
|
||||
m_BlockZ(a_BlockZ)
|
||||
{
|
||||
m_SlotArea = new cSlotAreaEnchanting(*this, m_BlockX, m_BlockY, m_BlockZ);
|
||||
m_SlotAreas.push_back(m_SlotArea);
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
|
||||
virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player) override
|
||||
{
|
||||
if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
|
||||
{
|
||||
ASSERT(!"a_Property is invalid");
|
||||
return;
|
||||
}
|
||||
virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player) override;
|
||||
|
||||
m_PropertyValue[a_Property] = a_Value;
|
||||
super::SetProperty(a_Property, a_Value, a_Player);
|
||||
}
|
||||
virtual void SetProperty(short a_Property, short a_Value) override;
|
||||
|
||||
virtual void SetProperty(short a_Property, short a_Value) override
|
||||
{
|
||||
if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
|
||||
{
|
||||
ASSERT(!"a_Property is invalid");
|
||||
return;
|
||||
}
|
||||
/** Return the value of a property */
|
||||
short GetPropertyValue(short a_Property);
|
||||
|
||||
m_PropertyValue[a_Property] = a_Value;
|
||||
super::SetProperty(a_Property, a_Value);
|
||||
}
|
||||
|
||||
/** Return the Value of a Property */
|
||||
short GetPropertyValue(short a_Property)
|
||||
{
|
||||
if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
|
||||
{
|
||||
ASSERT(!"a_Property is invalid");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_PropertyValue[a_Property];
|
||||
}
|
||||
|
||||
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])
|
||||
{
|
||||
// Enchanting 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
|
||||
{
|
||||
// Inventory or Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Enchanting */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
|
||||
cSlotArea * m_SlotArea;
|
||||
|
||||
|
71
src/UI/EnderChestWindow.cpp
Normal file
71
src/UI/EnderChestWindow.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
|
||||
// EnderChestWindow.cpp
|
||||
|
||||
// Representing the UI window for the enderchest block
|
||||
|
||||
#include "Globals.h"
|
||||
#include "../World.h"
|
||||
#include "EnderChestWindow.h"
|
||||
#include "SlotArea.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cEnderChestWindow::cEnderChestWindow(cEnderChestEntity * a_EnderChest) :
|
||||
cWindow(wtChest, "Ender Chest"),
|
||||
m_World(a_EnderChest->GetWorld()),
|
||||
m_BlockX(a_EnderChest->GetPosX()),
|
||||
m_BlockY(a_EnderChest->GetPosY()),
|
||||
m_BlockZ(a_EnderChest->GetPosZ())
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaEnderChest(a_EnderChest, *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, E_BLOCK_ENDER_CHEST);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cEnderChestWindow::~cEnderChestWindow()
|
||||
{
|
||||
// Send out the chest-close packet:
|
||||
m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 0, E_BLOCK_ENDER_CHEST);
|
||||
|
||||
// Play the closing sound
|
||||
m_World->BroadcastSoundEffect("random.chestclosed", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cEnderChestWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -22,51 +22,11 @@ class cEnderChestWindow :
|
||||
typedef cWindow super;
|
||||
|
||||
public:
|
||||
cEnderChestWindow(cEnderChestEntity * a_EnderChest) :
|
||||
cWindow(wtChest, "Ender Chest"),
|
||||
m_World(a_EnderChest->GetWorld()),
|
||||
m_BlockX(a_EnderChest->GetPosX()),
|
||||
m_BlockY(a_EnderChest->GetPosY()),
|
||||
m_BlockZ(a_EnderChest->GetPosZ())
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaEnderChest(a_EnderChest, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
cEnderChestWindow(cEnderChestEntity * a_EnderChest);
|
||||
|
||||
// Play the opening sound:
|
||||
m_World->BroadcastSoundEffect("random.chestopen", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 1, 1);
|
||||
~cEnderChestWindow();
|
||||
|
||||
// Send out the chest-open packet:
|
||||
m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 1, E_BLOCK_ENDER_CHEST);
|
||||
}
|
||||
|
||||
~cEnderChestWindow()
|
||||
{
|
||||
// Send out the chest-close packet:
|
||||
m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 0, E_BLOCK_ENDER_CHEST);
|
||||
|
||||
// Play the closing sound
|
||||
m_World->BroadcastSoundEffect("random.chestclosed", (double)m_BlockX, (double)m_BlockY, (double)m_BlockZ, 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);
|
||||
}
|
||||
}
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
|
||||
protected:
|
||||
cWorld * m_World;
|
||||
|
74
src/UI/FurnaceWindow.cpp
Normal file
74
src/UI/FurnaceWindow.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
|
||||
// FurnaceWindow.cpp
|
||||
|
||||
// Representing the UI window for the furnace block
|
||||
|
||||
#include "Globals.h"
|
||||
#include "FurnaceWindow.h"
|
||||
#include "SlotArea.h"
|
||||
#include "../FurnaceRecipe.h"
|
||||
#include "../Root.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cFurnaceWindow::cFurnaceWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceEntity * a_Furnace) :
|
||||
cWindow(wtFurnace, "Furnace")
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaFurnace(a_Furnace, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cFurnaceWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
cSlotAreas AreasInOrder;
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[0])
|
||||
{
|
||||
// Furnace Area
|
||||
if (a_Slot == 2)
|
||||
{
|
||||
// Result Slot
|
||||
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
|
||||
{
|
||||
// Furnace Input/Fuel Slot
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cFurnaceRecipe * FurnaceRecipes = cRoot::Get()->GetFurnaceRecipe();
|
||||
if ((FurnaceRecipes->GetRecipeFrom(a_ItemStack) != nullptr) || (FurnaceRecipes->IsFuel(a_ItemStack)))
|
||||
{
|
||||
// The item is a valid input item or fuel
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Furnace Area */
|
||||
}
|
||||
else if (a_ClickedArea == m_SlotAreas[1])
|
||||
{
|
||||
// Inventory Area
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hotbar Area
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
}
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Window.h"
|
||||
#include "../Root.h"
|
||||
|
||||
|
||||
|
||||
@ -22,58 +21,10 @@ class cFurnaceWindow :
|
||||
typedef cWindow super;
|
||||
|
||||
public:
|
||||
cFurnaceWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceEntity * a_Furnace) :
|
||||
cWindow(wtFurnace, "Furnace")
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaFurnace(a_Furnace, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
cFurnaceWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceEntity * a_Furnace);
|
||||
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
|
||||
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])
|
||||
{
|
||||
// Furnace Area
|
||||
if (a_Slot == 2)
|
||||
{
|
||||
// Result Slot
|
||||
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
|
||||
{
|
||||
// Furnace Input/Fuel Slot
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cFurnaceRecipe * FurnaceRecipes = cRoot::Get()->GetFurnaceRecipe();
|
||||
if ((FurnaceRecipes->GetRecipeFrom(a_ItemStack) != nullptr) || (FurnaceRecipes->IsFuel(a_ItemStack)))
|
||||
{
|
||||
// The item is a valid input item or fuel
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Furnace Area */
|
||||
}
|
||||
else if (a_ClickedArea == m_SlotAreas[1])
|
||||
{
|
||||
// Inventory Area
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hotbar Area
|
||||
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
|
||||
}
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
48
src/UI/HopperWindow.cpp
Normal file
48
src/UI/HopperWindow.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
// HopperWindow.cpp
|
||||
|
||||
// Representing the UI window for the hopper block
|
||||
|
||||
#include "Globals.h"
|
||||
#include "../BlockEntities/HopperEntity.h"
|
||||
#include "HopperWindow.h"
|
||||
#include "../BlockEntities/DropperEntity.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cHopperWindow::cHopperWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperEntity * a_Hopper) :
|
||||
super(wtHopper, "Hopper")
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaItemGrid(a_Hopper->GetContents(), *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cHopperWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
cSlotAreas AreasInOrder;
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[0])
|
||||
{
|
||||
// Hopper 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
|
||||
{
|
||||
// Inventory or Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Hopper */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Window.h"
|
||||
#include "../BlockEntities/DropperEntity.h"
|
||||
|
||||
|
||||
|
||||
@ -22,33 +21,10 @@ class cHopperWindow :
|
||||
typedef cWindow super;
|
||||
|
||||
public:
|
||||
cHopperWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperEntity * a_Hopper) :
|
||||
super(wtHopper, "Hopper")
|
||||
{
|
||||
m_SlotAreas.push_back(new cSlotAreaItemGrid(a_Hopper->GetContents(), *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
cHopperWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperEntity * a_Hopper);
|
||||
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
|
||||
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])
|
||||
{
|
||||
// Hopper 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
|
||||
{
|
||||
// Inventory or Hotbar
|
||||
AreasInOrder.push_back(m_SlotAreas[0]); /* Hopper */
|
||||
super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
73
src/UI/InventoryWindow.cpp
Normal file
73
src/UI/InventoryWindow.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
|
||||
// InventoryWindow.cpp
|
||||
|
||||
// Representing the UI window for the player inventory
|
||||
|
||||
#include "Globals.h"
|
||||
#include "InventoryWindow.h"
|
||||
#include "SlotArea.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cInventoryWindow::cInventoryWindow(cPlayer & a_Player) :
|
||||
cWindow(wtInventory, "Inventory"),
|
||||
m_Player(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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cInventoryWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
|
||||
{
|
||||
cSlotAreas AreasInOrder;
|
||||
|
||||
if (a_ClickedArea == m_SlotAreas[0])
|
||||
{
|
||||
// Crafting Area
|
||||
if (a_Slot == 0)
|
||||
{
|
||||
// Result Slot
|
||||
AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */
|
||||
}
|
||||
else
|
||||
{
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */
|
||||
AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */
|
||||
}
|
||||
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::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::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::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -21,59 +21,9 @@ class cInventoryWindow :
|
||||
typedef cWindow super;
|
||||
|
||||
public:
|
||||
cInventoryWindow(cPlayer & a_Player) :
|
||||
cWindow(wtInventory, "Inventory"),
|
||||
m_Player(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));
|
||||
}
|
||||
cInventoryWindow(cPlayer & 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])
|
||||
{
|
||||
// Crafting Area
|
||||
if (a_Slot == 0)
|
||||
{
|
||||
// Result Slot
|
||||
AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */
|
||||
}
|
||||
else
|
||||
{
|
||||
AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */
|
||||
AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */
|
||||
}
|
||||
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::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::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::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
|
||||
}
|
||||
}
|
||||
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
|
||||
|
||||
protected:
|
||||
cPlayer & m_Player;
|
||||
|
Loading…
Reference in New Issue
Block a user