Working on the Map and Map Editor to support Polygon Objects.

This commit is contained in:
Martín Lucas Golini
2013-01-12 02:06:09 -03:00
parent 0a741f2bc3
commit bc0601f7d9
16 changed files with 388 additions and 32 deletions

View File

@@ -24,6 +24,10 @@ Uint32 String::Hash( const Uint8 * str ) {
return 0;
}
Uint32 String::Hash( const char * str ) {
return String::Hash( reinterpret_cast<const Uint8*>( str ) );
}
Uint32 String::Hash( const std::string& str ) {
return String::Hash( reinterpret_cast<const Uint8*>( &str[0] ) );
}

View File

@@ -0,0 +1,91 @@
#include <eepp/gaming/cgameobjectobject.hpp>
#include <eepp/gaming/cmap.hpp>
#include <eepp/gaming/clayer.hpp>
#include <eepp/gaming/ctilelayer.hpp>
#include <eepp/graphics/cprimitives.hpp>
using namespace EE::Graphics;
namespace EE { namespace Gaming {
cGameObjectObject::cGameObjectObject( Uint32 DataId, cLayer * Layer, const Uint32& Flags ) :
cGameObject( Flags, Layer ),
//mRect( Layer->Map()->GetObjPoly( DataId ) ),
mPos( mRect.Pos() ),
mDataId( DataId )
{
}
cGameObjectObject::cGameObjectObject( Uint32 DataId, const eeRecti& rect, cLayer * Layer, const Uint32& Flags ) :
cGameObject( Flags, Layer ),
mRect( rect.Left, rect.Top, rect.Right, rect.Bottom ),
mPos( mRect.Pos() ),
mDataId( DataId )
{
}
cGameObjectObject::~cGameObjectObject() {
}
Uint32 cGameObjectObject::Type() const {
return GAMEOBJECT_TYPE_OBJECT;
}
bool cGameObjectObject::IsType( const Uint32& type ) {
return ( cGameObjectObject::Type() == type ) ? true : cGameObject::IsType( type );
}
eeSize cGameObjectObject::Size() {
return eeSize( mRect.Size().x, mRect.Size().y );
}
void cGameObjectObject::Draw() {
cPrimitives P;
P.FillMode( EE_DRAW_FILL );
P.SetColor( eeColorA( 100, 100, 100, 30 ) );
P.DrawRectangle( mRect );
P.FillMode( EE_DRAW_LINE );
P.SetColor( eeColorA( 50, 50, 50, 200 ) );
P.DrawRectangle( mRect );
}
eeVector2f cGameObjectObject::Pos() const {
return mPos;
}
void cGameObjectObject::Pos( eeVector2f pos ) {
mPos = pos;
mRect = eeRectf( pos, eeSizef( Size().x, Size().y ) );
}
Uint32 cGameObjectObject::DataId() {
return mDataId;
}
void cGameObjectObject::DataId( Uint32 Id ) {
mDataId = Id;
}
void cGameObjectObject::ClearProperties() {
mProperties.clear();
}
void cGameObjectObject::AddProperty( std::string Text, std::string Value ) {
mProperties[ Text ] = Value;
}
void cGameObjectObject::EditProperty( std::string Text, std::string Value ) {
mProperties[ Text ] = Value;
}
void cGameObjectObject::RemoveProperty( std::string Text ) {
mProperties.erase( Text );
}
cGameObjectObject::PropertiesMap& cGameObjectObject::GetProperties() {
return mProperties;
}
}}

View File

@@ -53,6 +53,11 @@ void cLayer::Offset( const eeVector2f& offset ) {
mOffset = offset;
}
void cLayer::Name( const std::string& name ) {
mName = name;
mNameHash = String::Hash( mName );
}
const std::string& cLayer::Name() const {
return mName;
}

View File

@@ -3,6 +3,7 @@
#include <eepp/gaming/cgameobjectsubtexture.hpp>
#include <eepp/gaming/cgameobjectsubtextureex.hpp>
#include <eepp/gaming/cgameobjectsprite.hpp>
#include <eepp/gaming/cgameobjectobject.hpp>
#include <eepp/gaming/ctilelayer.hpp>
#include <eepp/gaming/cobjectlayer.hpp>
@@ -35,7 +36,8 @@ cMap::cMap() :
mBackAlpha( 255 ),
mMouseOver( false ),
mScale( 1 ),
mOffscale( 1, 1 )
mOffscale( 1, 1 ),
mLastObjId( 0 )
{
ViewSize( mViewSize );
}
@@ -573,7 +575,6 @@ void cMap::Move( const eeFloat& offsetx, const eeFloat& offsety ) {
cGameObject * cMap::CreateGameObject( const Uint32& Type, const Uint32& Flags, cLayer * Layer, const Uint32& DataId ) {
switch ( Type ) {
case GAMEOBJECT_TYPE_SHAPE:
case GAMEOBJECT_TYPE_SUBTEXTURE:
{
cGameObjectSubTexture * tSubTexture = eeNew( cGameObjectSubTexture, ( Flags, Layer ) );
@@ -582,7 +583,6 @@ cGameObject * cMap::CreateGameObject( const Uint32& Type, const Uint32& Flags, c
return tSubTexture;
}
case GAMEOBJECT_TYPE_SHAPEEX:
case GAMEOBJECT_TYPE_SUBTEXTUREEX:
{
cGameObjectSubTextureEx * tSubTextureEx = eeNew( cGameObjectSubTextureEx, ( Flags, Layer ) );
@@ -599,6 +599,10 @@ cGameObject * cMap::CreateGameObject( const Uint32& Type, const Uint32& Flags, c
return tSprite;
}
case GAMEOBJECT_TYPE_OBJECT:
{
//cGameObjectObject * tObject = eeNew( cGameObjectObject, ( Layer, Flags ) );
}
default:
{
if ( mCreateGOCb.IsSet() ) {
@@ -1318,4 +1322,8 @@ void cMap::BackColor( const eeColorA& col ) {
mBackColor = col;
}
Uint32 cMap::GetNewObjectId() {
return ++mLastObjId;
}
}}

View File

@@ -12,6 +12,7 @@
#include <eepp/gaming/cgameobjectsubtexture.hpp>
#include <eepp/gaming/cgameobjectsubtextureex.hpp>
#include <eepp/gaming/cgameobjectsprite.hpp>
#include <eepp/gaming/cgameobjectobject.hpp>
#include <eepp/ui/cuimanager.hpp>
#include <eepp/ui/cuithememanager.hpp>
#include <eepp/ui/cuiwinmenu.hpp>
@@ -369,7 +370,7 @@ void cMapEditor::CreateLightContainer() {
mLightTypeChk->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapEditor::OnLightTypeChange ) );
}
void cMapEditor::AddObjContButton( String text ) {
cUISelectButton * cMapEditor::AddObjContButton( String text ) {
static Int32 lastY = 0;
cUISelectButton * Button = mTheme->CreateSelectButton( mObjectCont, eeSize( mObjectCont->Size().Width(), 22 ), eeVector2i( 0, lastY ) );
@@ -381,14 +382,26 @@ void cMapEditor::AddObjContButton( String text ) {
lastY += Button->Size().Height() + 4;
mObjContButton.push_back( Button );
return Button;
}
void cMapEditor::CreateObjectsContainer() {
AddObjContButton( "Select Objects" );
AddObjContButton( "Edit Polygons" );
AddObjContButton( "Insert Object" );
AddObjContButton( "Insert Object" )->Select();
AddObjContButton( "Insert Polygon" );
AddObjContButton( "Select Polyline" );
cUISelectButton * Button = AddObjContButton( "Select Polyline" );
Int32 nextY = Button->Pos().y + Button->Size().Height() + 4;
Uint32 ChkFlags = UI_CONTROL_DEFAULT_ALIGN | UI_AUTO_SIZE | UI_ANCHOR_RIGHT | UI_ANCHOR_TOP;
mChkClampToTile = mTheme->CreateCheckBox( mObjectCont, eeSize(), eeVector2i( 12, nextY ), ChkFlags );
mChkClampToTile->Text( "Clamp Position to Tile" );
mChkClampToTile->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::ChkClickClampToTile ) );
mChkClampToTile->Active( true );
}
void cMapEditor::OnObjectModeSel( const cUIEvent * Event ) {
@@ -420,6 +433,7 @@ void cMapEditor::CreateUIMap() {
mUIMap->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::OnMapMouseClick ) );
mUIMap->SetLightSelectCb( cb::Make1( this, &cMapEditor::OnLightSelect ) );
mUIMap->SetLightRadiusChangeCb( cb::Make1( this, &cMapEditor::OnLightRadiusChange ) );
mUIMap->SetAddObjectCallback( cb::Make2( this, &cMapEditor::OnAddObject ) );
mMapHScroll = mTheme->CreateScrollBar( mWinContainer, eeSize( Params.Size.Width(), 15 ), eeVector2i( 0, Params.Size.Height() ), UI_ANCHOR_LEFT | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM );
mMapHScroll->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapEditor::OnScrollMapH ) );
@@ -430,6 +444,31 @@ void cMapEditor::CreateUIMap() {
MapCreated();
}
void cMapEditor::OnAddObject( Uint32 Type, eePolygon2f poly ) {
if ( NULL == mCurLayer ) {
CreateNoLayerAlert( "No layers found" )->SetFocus();
return;
}
if ( mCurLayer->Type() != MAP_LAYER_OBJECT ) {
CreateAlert( "Wrong Layer", "Objects only can be added to an Object Layer" )->SetFocus();
return;
}
if ( GAMEOBJECT_TYPE_OBJECT == Type ) {
cObjectLayer * OL = static_cast<cObjectLayer*> ( mCurLayer );
eeRectf Rect = poly.ToAABB();
cGameObjectObject * tObj = eeNew( cGameObjectObject, ( mUIMap->Map()->GetNewObjectId(), eeRecti( Rect.Left, Rect.Top, Rect.Right, Rect.Bottom ), mCurLayer ) );
OL->AddGameObject( tObj );
} else if ( GAMEOBJECT_TYPE_POLYGON == Type || GAMEOBJECT_TYPE_POLYGON == Type ) {
}
}
void cMapEditor::OnLightTypeChange( const cUIEvent * Event ) {
if ( NULL != mUIMap->GetSelectedLight() ) {
mUIMap->GetSelectedLight()->Type( mLightTypeChk->Active() ? LIGHT_ISOMETRIC : LIGHT_NORMAL );
@@ -518,6 +557,10 @@ void cMapEditor::ChkClickDI( const cUIEvent * Event ) {
}
}
void cMapEditor::ChkClickClampToTile( const cUIEvent * Event ) {
mUIMap->ClampToTile( mChkClampToTile->Active() );
}
void cMapEditor::UpdateGfx() {
if ( mChkMirrored->Active() && mChkFliped->Active() )
mGfxPreview->RenderMode( RN_FLIPMIRROR );
@@ -956,11 +999,16 @@ void cMapEditor::LayerMenuClick( const cUIEvent * Event ) {
}
}
void cMapEditor::CreateNoLayerAlert( const String title ) {
cUIMessageBox * MsgBox = mTheme->CreateMessageBox( MSGBOX_OK, "First select and add a new layer." );
cUIMessageBox * cMapEditor::CreateAlert( const String& title, const String& text ) {
cUIMessageBox * MsgBox = mTheme->CreateMessageBox( MSGBOX_OK, text );
MsgBox->Title( title );
MsgBox->Center();
MsgBox->Show();
return MsgBox;
}
cUIMessageBox * cMapEditor::CreateNoLayerAlert( const String title ) {
return CreateAlert( title, "First select and add a new layer." );
}
void cMapEditor::MoveLayerUp() {

View File

@@ -9,13 +9,16 @@ cUIMap::cUIMap( const cUIComplexControl::CreateParams& Params, cMap * Map ) :
mEditingLights( false ),
mEditingObjects( false ),
mEditingObjMode( INSERT_OBJECT ),
mObjAddType( GAMEOBJECT_TYPE_OBJECT ),
mAddLight( NULL ),
mSelLight( NULL )
mSelLight( NULL ),
mClampToTile(true)
{
if ( NULL == Map ) {
mMap = eeNew( cMap, () );
mMap->SetDrawCallback( cb::Make0( this, &cUIMap::MapDraw ) );
}
mMap->SetDrawCallback( cb::Make0( this, &cUIMap::MapDraw ) );
}
cUIMap::~cUIMap() {
@@ -48,10 +51,10 @@ void cUIMap::Update() {
if ( NULL != mMap ) {
mMap->Update();
if ( mEnabled && mVisible ) {
if ( mEditingLights && IsMouseOver() ) {
Uint32 Flags = cUIManager::instance()->GetInput()->ClickTrigger();
if ( mEnabled && mVisible && IsMouseOver() ) {
Uint32 Flags = cUIManager::instance()->GetInput()->ClickTrigger();
if ( mEditingLights ) {
if ( NULL != mSelLight ) {
if ( Flags & EE_BUTTONS_WUWD ) {
if ( Flags & EE_BUTTON_WUMASK ) {
@@ -84,7 +87,6 @@ void cUIMap::Update() {
}
}
Flags = cUIManager::instance()->GetInput()->PressTrigger();
if ( Flags & EE_BUTTON_MMASK ) {
@@ -95,11 +97,53 @@ void cUIMap::Update() {
TryToSelectLight();
}
}
} else if ( mEditingObjects ) {
ManageObject( Flags );
}
}
}
}
void cUIMap::ManageObject( Uint32 Flags ) {
Uint32 PFlags = cUIManager::instance()->GetInput()->PressTrigger();
switch ( mEditingObjMode )
{
case INSERT_OBJECT:
{
if ( PFlags & EE_BUTTON_LMASK ) {
eeVector2f mp( mMap->GetMouseMapPosf() );
if ( mClampToTile ) {
eeVector2i mpc( mMap->GetTileCoords( mMap->GetMouseTilePos() + 1 ) );
mp = eeVector2f( mpc.x, mpc.y );
}
if ( !mObjRECTEditing ) {
mObjRECTEditing = true;
mObjRECT = eeRectf( mp, eeSizef(0,0) );
} else {
if ( mObjRECT.Pos().x < mp.x && mObjRECT.Pos().y < mp.y ) {
mObjRECT = eeRectf( mObjRECT.Pos(), eeSizef( mp - mObjRECT.Pos() ) );
}
}
}
if ( Flags & EE_BUTTON_LMASK ){
if ( mObjRECTEditing ) {
mAddObjectCallback( mObjAddType, eePolygon2f( mObjRECT ) );
mObjRECTEditing = false;
}
}
break;
}
default:
{
}
}
}
void cUIMap::TryToSelectLight() {
cLight * tLight = mSelLight;
mSelLight = mMap->GetLightManager()->GetLightOver( mMap->GetMouseMapPosf(), mSelLight );
@@ -149,15 +193,26 @@ void cUIMap::AddLight( cLight * Light ) {
}
void cUIMap::MapDraw() {
if ( mEditingLights && NULL != mSelLight ) {
cPrimitives P;
P.SetColor( eeColorA( 255, 0, 0, (Uint8)mAlpha ) );
if ( mEditingLights ) {
if ( NULL != mSelLight ) {
mP.SetColor( eeColorA( 255, 0, 0, (Uint8)mAlpha ) );
eeVector2f Pos( mSelLight->GetAABB().Left, mSelLight->GetAABB().Top );
eeAABB AB( mSelLight->GetAABB() );
eeVector2f Pos( mSelLight->GetAABB().Left, mSelLight->GetAABB().Top );
eeAABB AB( mSelLight->GetAABB() );
P.FillMode( EE_DRAW_LINE );
P.DrawRectangle( eeRectf( Pos, AB.Size() ) );
mP.FillMode( EE_DRAW_LINE );
mP.DrawRectangle( eeRectf( Pos, AB.Size() ) );
}
} else if ( mEditingObjects ) {
if ( mObjRECTEditing ) {
mP.FillMode( EE_DRAW_FILL );
mP.SetColor( eeColorA( 100, 100, 100, (Uint8)( 50 * mAlpha ) ) );
mP.DrawRectangle( mObjRECT );
mP.FillMode( EE_DRAW_LINE );
mP.SetColor( eeColorA( 255, 0, 0, (Uint8)( 200 * mAlpha ) ) );
mP.DrawRectangle( mObjRECT );
}
}
}
@@ -184,7 +239,7 @@ const bool& cUIMap::EditingLights() {
}
void cUIMap::PrivEditingObjects( const bool& editing ) {
mEditingObjects = false;
mEditingObjects = editing;
}
void cUIMap::EditingObjects( const bool& editing ) {
@@ -220,6 +275,10 @@ void cUIMap::SetLightRadiusChangeCb( LightRadiusChangeCb Cb ) {
mLightRadiusChangeCb = Cb;
}
void cUIMap::SetAddObjectCallback( ObjAddCb Cb ) {
mAddObjectCallback = Cb;
}
void cUIMap::ClearLights() {
mSelLight = NULL;
mAddLight = NULL;
@@ -233,4 +292,12 @@ void cUIMap::OnAlphaChange() {
}
}
void cUIMap::ClampToTile( const bool& clamp ) {
mClampToTile = clamp;
}
const bool& cUIMap::ClampToTile() const {
return mClampToTile;
}
}}}

View File

@@ -15,6 +15,7 @@ class EE_API cUIMap : public cUIComplexControl {
public:
typedef cb::Callback1<void, cLight *> LightSelectCb;
typedef cb::Callback1<void, cLight *> LightRadiusChangeCb;
typedef cb::Callback2<void, Uint32, eePolygon2f> ObjAddCb;
cUIMap( const cUIComplexControl::CreateParams& Params, cMap * Map = NULL );
@@ -46,7 +47,13 @@ class EE_API cUIMap : public cUIComplexControl {
void SetLightRadiusChangeCb( LightRadiusChangeCb Cb );
void SetAddObjectCallback( ObjAddCb Cb );
void ClearLights();
void ClampToTile( const bool& clamp );
const bool& ClampToTile() const;
protected:
cMap * mMap;
bool mEditingLights;
@@ -61,6 +68,7 @@ class EE_API cUIMap : public cUIComplexControl {
};
Uint32 mEditingObjMode;
Uint32 mObjAddType;
cLight * mAddLight;
cLight * mSelLight;
@@ -68,6 +76,12 @@ class EE_API cUIMap : public cUIComplexControl {
LightSelectCb mLightSelCb;
LightRadiusChangeCb mLightRadiusChangeCb;
bool mObjRECTEditing;
bool mClampToTile;
eeRectf mObjRECT;
cPrimitives mP;
ObjAddCb mAddObjectCallback;
virtual Uint32 OnMouseMove( const eeVector2i& Pos, const Uint32 Flags );
virtual void OnSizeChange();
@@ -83,6 +97,8 @@ class EE_API cUIMap : public cUIComplexControl {
void PrivEditingLights( const bool& editing );
void PrivEditingObjects( const bool& editing );
void ManageObject( Uint32 Flags );
};
}}}