Skip to content

Commit

Permalink
Moved window code into cpp files
Browse files Browse the repository at this point in the history
  • Loading branch information
Howaner committed Mar 10, 2015
1 parent a96c21f commit 685f6e3
Show file tree
Hide file tree
Showing 23 changed files with 839 additions and 519 deletions.
2 changes: 1 addition & 1 deletion src/BlockEntities/BeaconEntity.cpp
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Expand Up @@ -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
)

Expand Down Expand Up @@ -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)
Expand Down
83 changes: 83 additions & 0 deletions src/UI/AnvilWindow.cpp
@@ -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);
}




51 changes: 6 additions & 45 deletions src/UI/AnvilWindow.h
Expand Up @@ -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;
}

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);
}
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;

protected:
cSlotAreaAnvil * m_AnvilSlotArea;
Expand Down
76 changes: 76 additions & 0 deletions src/UI/BeaconWindow.cpp
@@ -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());
}




53 changes: 3 additions & 50 deletions src/UI/BeaconWindow.h
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/UI/CMakeLists.txt
Expand Up @@ -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
Expand Down

0 comments on commit 685f6e3

Please sign in to comment.