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_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);
|
||||
Window->SetSlots(GetContents(), GetChestHeight() * c_ChestWidth);
|
||||
Window->SetWindowTitle("UberChest");
|
||||
Window->GetOwner()->SetEntity(this);
|
||||
OpenWindow( Window );
|
||||
}
|
||||
if ( GetWindow() )
|
||||
|
@ -25,7 +25,7 @@ class cNBTData;
|
||||
|
||||
class cChestEntity :
|
||||
public cBlockEntity,
|
||||
public cWindowOwner
|
||||
public cBlockEntityWindowOwner
|
||||
{
|
||||
public:
|
||||
cChestEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
cFurnaceEntity::cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
|
||||
: cBlockEntity( E_BLOCK_FURNACE, a_X, a_Y, a_Z, a_World )
|
||||
: cBlockEntity( E_BLOCK_FURNACE, a_X, a_Y, a_Z, a_World )
|
||||
, m_Items( new cItem[3] )
|
||||
, m_CookingItem( 0 )
|
||||
, m_CookTime( 0 )
|
||||
@ -30,6 +30,7 @@ cFurnaceEntity::cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
|
||||
, m_BurnTime( 0 )
|
||||
, m_TimeBurned( 0 )
|
||||
{
|
||||
SetBlockEntity(this); // cBlockEntityWindowOwner
|
||||
}
|
||||
|
||||
|
||||
@ -83,7 +84,6 @@ void cFurnaceEntity::UsedBy( cPlayer * a_Player )
|
||||
cWindow* Window = new cFurnaceWindow( this );
|
||||
Window->SetSlots( m_Items, 3 );
|
||||
Window->SetWindowTitle("UberFurnace");
|
||||
Window->GetOwner()->SetEntity(this);
|
||||
OpenWindow( Window );
|
||||
}
|
||||
if( GetWindow() )
|
||||
|
@ -23,7 +23,7 @@ class cServer;
|
||||
|
||||
class cFurnaceEntity :
|
||||
public cBlockEntity,
|
||||
public cWindowOwner
|
||||
public cBlockEntityWindowOwner
|
||||
{
|
||||
public:
|
||||
cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
|
||||
|
@ -75,6 +75,9 @@ protected:
|
||||
short m_EquippedSlot;
|
||||
|
||||
cPlayer* m_Owner;
|
||||
|
||||
// cWindowOwner override:
|
||||
virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) override {} // UNUSED for an inventory
|
||||
}; //tolua_export
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#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
|
||||
{
|
||||
public:
|
||||
cWindowOwner() : m_Window( NULL ) {}
|
||||
void CloseWindow() { 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)
|
||||
cWindowOwner() :
|
||||
m_Window(NULL)
|
||||
{
|
||||
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:
|
||||
cWindow * m_Window;
|
||||
cBlockEntity * m_Entity;
|
||||
};
|
||||
cBlockEntity * m_BlockEntity;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
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