2012-08-06 16:10:16 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
#pragma once
|
|
|
|
|
2013-05-28 15:12:47 -04:00
|
|
|
#include "../BlockEntities/BlockEntity.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../Entity.h"
|
2012-09-23 13:19:34 -04:00
|
|
|
#include "Window.h"
|
2012-09-20 09:25:54 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Being a descendant of cWindowOwner means that the class can own one window. That window can be
|
|
|
|
queried, opened by other players, closed by players and finally destroyed.
|
|
|
|
Also, a cWindowOwner can be queried for the block coords where the window is displayed. That will be used
|
|
|
|
for entities / players in motion to close their windows when they get too far away from the window "source".
|
|
|
|
*/
|
2012-08-06 16:10:16 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-09-20 09:25:54 -04:00
|
|
|
// class cWindow;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-06 16:10:16 -04:00
|
|
|
/**
|
2012-09-20 09:25:54 -04:00
|
|
|
Base class for the window owning
|
2012-08-06 16:10:16 -04:00
|
|
|
*/
|
2012-06-14 09:06:06 -04:00
|
|
|
class cWindowOwner
|
|
|
|
{
|
|
|
|
public:
|
2012-08-07 08:05:35 -04:00
|
|
|
cWindowOwner() :
|
|
|
|
m_Window(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloseWindow(void)
|
|
|
|
{
|
|
|
|
m_Window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenWindow(cWindow * a_Window)
|
|
|
|
{
|
|
|
|
m_Window = a_Window;
|
2012-09-20 09:25:54 -04:00
|
|
|
m_Window->SetOwner(this);
|
2012-08-07 08:05:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
cWindow * GetWindow(void) const
|
|
|
|
{
|
|
|
|
return m_Window;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the block position at which the element owning the window is
|
|
|
|
virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
cWindow * m_Window;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Window owner that is associated with a block entity (chest, furnace, ...)
|
|
|
|
*/
|
|
|
|
class cBlockEntityWindowOwner :
|
|
|
|
public cWindowOwner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cBlockEntityWindowOwner(void) :
|
|
|
|
m_BlockEntity(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetBlockEntity(cBlockEntity * a_BlockEntity)
|
|
|
|
{
|
|
|
|
m_BlockEntity = a_BlockEntity;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) override
|
|
|
|
{
|
|
|
|
a_BlockX = m_BlockEntity->GetPosX();
|
|
|
|
a_BlockY = m_BlockEntity->GetPosY();
|
|
|
|
a_BlockZ = m_BlockEntity->GetPosZ();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
cBlockEntity * m_BlockEntity;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-08-07 08:05:35 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Window owner that is associated with an entity (chest minecart)
|
|
|
|
*/
|
|
|
|
class cEntityWindowOwner :
|
|
|
|
public cWindowOwner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cEntityWindowOwner(void) :
|
|
|
|
m_Entity(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetEntity(cEntity * a_Entity)
|
|
|
|
{
|
|
|
|
m_Entity = a_Entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) override
|
2012-08-06 16:10:16 -04:00
|
|
|
{
|
2013-05-25 08:00:25 -04:00
|
|
|
a_BlockX = (int)floor(m_Entity->GetPosX() + 0.5);
|
|
|
|
a_BlockY = (int)floor(m_Entity->GetPosY() + 0.5);
|
|
|
|
a_BlockZ = (int)floor(m_Entity->GetPosZ() + 0.5);
|
2012-08-06 16:10:16 -04:00
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
2012-08-07 08:05:35 -04:00
|
|
|
cEntity * m_Entity;
|
|
|
|
} ;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|