1
0
cuberite-2a/src/UI/WindowOwner.h

101 lines
1.7 KiB
C
Raw Normal View History

#pragma once
#include "../BlockEntities/BlockEntity.h"
#include "../Entities/Entity.h"
#include "Window.h"
2015-07-31 10:49:10 -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
2015-07-31 10:49:10 -04:00
for entities / players in motion to close their windows when they get too far away from the window "source". */
2015-07-31 10:49:10 -04:00
/** Base class for the window owning */
class cWindowOwner
{
public:
cWindowOwner() :
2014-10-20 16:55:07 -04:00
m_Window(nullptr)
{
}
2014-09-27 14:19:28 -04:00
virtual ~cWindowOwner()
{
}
2014-09-27 14:19:28 -04:00
void CloseWindow(void)
{
2014-10-20 16:55:07 -04:00
m_Window = nullptr;
}
2014-09-27 14:19:28 -04:00
void OpenWindow(cWindow * a_Window)
{
m_Window = a_Window;
m_Window->SetOwner(this);
}
cWindow * GetWindow(void) const
{
return m_Window;
}
2014-09-27 14:19:28 -04:00
2015-07-31 10:49:10 -04:00
/** Returns the block position at which the element owning the window is */
2014-09-27 14:19:28 -04:00
virtual Vector3i GetBlockPos(void) = 0;
private:
cWindow * m_Window;
2014-09-12 18:18:02 -04:00
};
2014-09-27 14:19:28 -04:00
2015-07-31 10:49:10 -04:00
/** Window owner that is associated with a block entity (chest, furnace, ...) */
2014-09-27 14:19:28 -04: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 10:49:10 -04:00
/** Window owner that is associated with an entity (chest minecart etc.) */
2014-09-27 14:19:28 -04: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;
};