2012-06-14 13:06:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-05-28 19:12:47 +00:00
|
|
|
#include "../BlockEntities/BlockEntity.h"
|
2013-08-19 09:39:13 +00:00
|
|
|
#include "../Entities/Entity.h"
|
2012-09-23 17:19:34 +00:00
|
|
|
#include "Window.h"
|
2012-09-20 13:25:54 +00:00
|
|
|
|
2015-07-31 14:49:10 +00:00
|
|
|
/* Being a descendant of cWindowOwner means that the class can own one window. That window can be
|
2012-09-20 13:25:54 +00:00
|
|
|
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
|
2015-07-31 14:49:10 +00:00
|
|
|
for entities / players in motion to close their windows when they get too far away from the window "source". */
|
2012-08-06 20:10:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 13:06:06 +00:00
|
|
|
|
2015-07-31 14:49:10 +00:00
|
|
|
/** Base class for the window owning */
|
2012-06-14 13:06:06 +00:00
|
|
|
class cWindowOwner
|
|
|
|
{
|
|
|
|
public:
|
2012-08-07 12:05:35 +00:00
|
|
|
cWindowOwner() :
|
2014-10-20 20:55:07 +00:00
|
|
|
m_Window(nullptr)
|
2012-08-07 12:05:35 +00:00
|
|
|
{
|
|
|
|
}
|
2014-09-27 18:19:28 +00:00
|
|
|
|
2014-03-28 20:35:45 +00:00
|
|
|
virtual ~cWindowOwner()
|
|
|
|
{
|
|
|
|
}
|
2014-09-27 18:19:28 +00:00
|
|
|
|
2012-08-07 12:05:35 +00:00
|
|
|
void CloseWindow(void)
|
|
|
|
{
|
2014-10-20 20:55:07 +00:00
|
|
|
m_Window = nullptr;
|
2012-08-07 12:05:35 +00:00
|
|
|
}
|
2014-09-27 18:19:28 +00:00
|
|
|
|
2012-08-07 12:05:35 +00:00
|
|
|
void OpenWindow(cWindow * a_Window)
|
|
|
|
{
|
|
|
|
m_Window = a_Window;
|
2012-09-20 13:25:54 +00:00
|
|
|
m_Window->SetOwner(this);
|
2012-08-07 12:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cWindow * GetWindow(void) const
|
|
|
|
{
|
|
|
|
return m_Window;
|
|
|
|
}
|
2014-09-27 18:19:28 +00:00
|
|
|
|
2015-07-31 14:49:10 +00:00
|
|
|
/** Returns the block position at which the element owning the window is */
|
2014-09-27 18:19:28 +00:00
|
|
|
virtual Vector3i GetBlockPos(void) = 0;
|
|
|
|
|
2012-08-07 12:05:35 +00:00
|
|
|
private:
|
|
|
|
cWindow * m_Window;
|
2014-09-12 22:18:02 +00:00
|
|
|
};
|
2012-06-14 13:06:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-27 18:19:28 +00:00
|
|
|
|
2015-07-31 14:49:10 +00:00
|
|
|
/** Window owner that is associated with a block entity (chest, furnace, ...) */
|
2014-09-27 18:19:28 +00:00
|
|
|
class cBlockEntityWindowOwner :
|
|
|
|
public cWindowOwner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cBlockEntityWindowOwner(cBlockEntity * a_BlockEntity) :
|
|
|
|
m_BlockEntity(a_BlockEntity)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Vector3i GetBlockPos(void) override
|
|
|
|
{
|
|
|
|
return Vector3i(m_BlockEntity->GetPosX(), m_BlockEntity->GetPosY(), m_BlockEntity->GetPosZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
cBlockEntity * m_BlockEntity;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-31 14:49:10 +00:00
|
|
|
/** Window owner that is associated with an entity (chest minecart etc.) */
|
2014-09-27 18:19:28 +00:00
|
|
|
class cEntityWindowOwner :
|
|
|
|
public cWindowOwner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cEntityWindowOwner(cEntity * a_Entity) :
|
|
|
|
m_Entity(a_Entity)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Vector3i GetBlockPos(void) override
|
|
|
|
{
|
|
|
|
return m_Entity->GetPosition().Floor();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
cEntity * m_Entity;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|