Prepared WindowOwner class hierarchy for minecart with chest.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@719 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
37c2ffad43
commit
b53b40b561
@ -28,6 +28,7 @@ cChestEntity::cChestEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
|
|||||||
, m_JoinedChest( NULL )
|
, m_JoinedChest( NULL )
|
||||||
{
|
{
|
||||||
m_Content = new cItem[ c_ChestHeight * c_ChestWidth ];
|
m_Content = new cItem[ c_ChestHeight * c_ChestWidth ];
|
||||||
|
SetBlockEntity(this); // cBlockEntityWindowOwner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -173,7 +174,6 @@ void cChestEntity::UsedBy(cPlayer * a_Player)
|
|||||||
cWindow * Window = new cWindow(this, true, cWindow::Chest, 1);
|
cWindow * Window = new cWindow(this, true, cWindow::Chest, 1);
|
||||||
Window->SetSlots(GetContents(), GetChestHeight() * c_ChestWidth);
|
Window->SetSlots(GetContents(), GetChestHeight() * c_ChestWidth);
|
||||||
Window->SetWindowTitle("UberChest");
|
Window->SetWindowTitle("UberChest");
|
||||||
Window->GetOwner()->SetEntity(this);
|
|
||||||
OpenWindow( Window );
|
OpenWindow( Window );
|
||||||
}
|
}
|
||||||
if ( GetWindow() )
|
if ( GetWindow() )
|
||||||
|
@ -25,7 +25,7 @@ class cNBTData;
|
|||||||
|
|
||||||
class cChestEntity :
|
class cChestEntity :
|
||||||
public cBlockEntity,
|
public cBlockEntity,
|
||||||
public cWindowOwner
|
public cBlockEntityWindowOwner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cChestEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
|
cChestEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
|
||||||
|
@ -30,6 +30,7 @@ cFurnaceEntity::cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
|
|||||||
, m_BurnTime( 0 )
|
, m_BurnTime( 0 )
|
||||||
, m_TimeBurned( 0 )
|
, m_TimeBurned( 0 )
|
||||||
{
|
{
|
||||||
|
SetBlockEntity(this); // cBlockEntityWindowOwner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +84,6 @@ void cFurnaceEntity::UsedBy( cPlayer * a_Player )
|
|||||||
cWindow* Window = new cFurnaceWindow( this );
|
cWindow* Window = new cFurnaceWindow( this );
|
||||||
Window->SetSlots( m_Items, 3 );
|
Window->SetSlots( m_Items, 3 );
|
||||||
Window->SetWindowTitle("UberFurnace");
|
Window->SetWindowTitle("UberFurnace");
|
||||||
Window->GetOwner()->SetEntity(this);
|
|
||||||
OpenWindow( Window );
|
OpenWindow( Window );
|
||||||
}
|
}
|
||||||
if( GetWindow() )
|
if( GetWindow() )
|
||||||
|
@ -23,7 +23,7 @@ class cServer;
|
|||||||
|
|
||||||
class cFurnaceEntity :
|
class cFurnaceEntity :
|
||||||
public cBlockEntity,
|
public cBlockEntity,
|
||||||
public cWindowOwner
|
public cBlockEntityWindowOwner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
|
cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
|
||||||
|
@ -75,6 +75,9 @@ protected:
|
|||||||
short m_EquippedSlot;
|
short m_EquippedSlot;
|
||||||
|
|
||||||
cPlayer* m_Owner;
|
cPlayer* m_Owner;
|
||||||
|
|
||||||
|
// cWindowOwner override:
|
||||||
|
virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) override {} // UNUSED for an inventory
|
||||||
}; //tolua_export
|
}; //tolua_export
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cBlockEntity.h"
|
#include "cBlockEntity.h"
|
||||||
|
#include "cEntity.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -14,29 +15,101 @@ class cWindow;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Implements the base behavior expected from a class that can handle UI windows for block entities.
|
Base class for the behavior expected from a class that can handle UI windows for block entities.
|
||||||
*/
|
*/
|
||||||
class cWindowOwner
|
class cWindowOwner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cWindowOwner() : m_Window( NULL ) {}
|
cWindowOwner() :
|
||||||
void CloseWindow() { m_Window = NULL; }
|
m_Window(NULL)
|
||||||
void OpenWindow( cWindow* a_Window ) { m_Window = a_Window; }
|
|
||||||
|
|
||||||
cWindow* GetWindow() { return m_Window; }
|
|
||||||
|
|
||||||
void SetEntity(cBlockEntity * a_Entity) { m_Entity = a_Entity; }
|
|
||||||
void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
|
|
||||||
{
|
{
|
||||||
a_BlockX = m_Entity->GetPosX();
|
}
|
||||||
a_BlockY = m_Entity->GetPosY();
|
|
||||||
a_BlockZ = m_Entity->GetPosZ();
|
void CloseWindow(void)
|
||||||
|
{
|
||||||
|
m_Window = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenWindow(cWindow * a_Window)
|
||||||
|
{
|
||||||
|
m_Window = a_Window;
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
private:
|
||||||
cWindow * m_Window;
|
cBlockEntity * m_BlockEntity;
|
||||||
cBlockEntity * m_Entity;
|
} ;
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
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
|
||||||
|
{
|
||||||
|
a_BlockX = (int)(m_Entity->GetPosX());
|
||||||
|
a_BlockY = (int)(m_Entity->GetPosY());
|
||||||
|
a_BlockZ = (int)(m_Entity->GetPosZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
cEntity * m_Entity;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user