diff --git a/include/eepp/gaming/cgameobjectobject.hpp b/include/eepp/gaming/cgameobjectobject.hpp index f3e283398..3a40384aa 100644 --- a/include/eepp/gaming/cgameobjectobject.hpp +++ b/include/eepp/gaming/cgameobjectobject.hpp @@ -14,9 +14,7 @@ class EE_API cGameObjectObject : public cGameObject { public: typedef std::map PropertiesMap; - cGameObjectObject( Uint32 DataId, cLayer * Layer, const Uint32& Flags = GObjFlags::GAMEOBJECT_STATIC ); - - cGameObjectObject( Uint32 DataId, const eeRecti& rect, cLayer * Layer, const Uint32& Flags = GObjFlags::GAMEOBJECT_STATIC ); + cGameObjectObject( Uint32 DataId, const eeRectf& rect, cLayer * Layer, const Uint32& Flags = GObjFlags::GAMEOBJECT_STATIC ); virtual ~cGameObjectObject(); @@ -42,9 +40,23 @@ class EE_API cGameObjectObject : public cGameObject { void RemoveProperty( std::string Text ); + void SetProperties( const PropertiesMap& prop ); + void ClearProperties(); PropertiesMap& GetProperties(); + + Uint32 GetPropertyCount(); + + const std::string& Name() const; + + void Name( const std::string& name ); + + const std::string& TypeName() const; + + void TypeName( const std::string& type ); + + virtual eePolygon2f GetPolygon(); protected: eeRectf mRect; eeVector2f mPos; @@ -54,6 +66,14 @@ class EE_API cGameObjectObject : public cGameObject { PropertiesMap mProperties; }; +class cGameObjectPolyData { + public: + std::string Name; + std::string Type; + cGameObjectObject::PropertiesMap Properties; + eePolygon2f Poly; +}; + }} #endif diff --git a/include/eepp/gaming/cgameobjectpolygon.hpp b/include/eepp/gaming/cgameobjectpolygon.hpp new file mode 100644 index 000000000..8f16ae318 --- /dev/null +++ b/include/eepp/gaming/cgameobjectpolygon.hpp @@ -0,0 +1,33 @@ +#ifndef EE_GAMINGCGAMEOBJECTPOLYGON_HPP +#define EE_GAMINGCGAMEOBJECTPOLYGON_HPP + +#include + +namespace EE { namespace Gaming { + +class EE_API cGameObjectPolygon : public cGameObjectObject { + public: + cGameObjectPolygon( Uint32 DataId, eePolygon2f poly, cLayer * Layer, const Uint32& Flags = GObjFlags::GAMEOBJECT_STATIC ); + + virtual ~cGameObjectPolygon(); + + virtual void Draw(); + + virtual eeVector2f Pos() const; + + virtual eeSize Size(); + + virtual void Pos( eeVector2f pos ); + + virtual Uint32 Type() const; + + virtual bool IsType( const Uint32& type ); + + virtual eePolygon2f GetPolygon(); + protected: + eePolygon2f mPoly; +}; + +}} + +#endif diff --git a/include/eepp/gaming/cgameobjectpolyline.hpp b/include/eepp/gaming/cgameobjectpolyline.hpp new file mode 100644 index 000000000..98b2324fd --- /dev/null +++ b/include/eepp/gaming/cgameobjectpolyline.hpp @@ -0,0 +1,23 @@ +#ifndef EE_GAMINGCGAMEOBJECTPOLYLINE_HPP +#define EE_GAMINGCGAMEOBJECTPOLYLINE_HPP + +#include + +namespace EE { namespace Gaming { + +class EE_API cGameObjectPolyline : public cGameObjectPolygon { + public: + cGameObjectPolyline( Uint32 DataId, eePolygon2f poly, cLayer * Layer, const Uint32& Flags = GObjFlags::GAMEOBJECT_STATIC ); + + virtual ~cGameObjectPolyline(); + + virtual Uint32 Type() const; + + virtual bool IsType( const Uint32& type ); + + virtual void Draw(); +}; + +}} + +#endif diff --git a/include/eepp/gaming/cmap.hpp b/include/eepp/gaming/cmap.hpp index 0129aaa89..3e6847574 100644 --- a/include/eepp/gaming/cmap.hpp +++ b/include/eepp/gaming/cmap.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -209,7 +210,11 @@ class EE_API cMap { eeVector2i GetMaxOffset(); Uint32 GetNewObjectId(); + + cGameObjectPolyData& GetPolyObjData( Uint32 Id ); protected: + typedef std::map PolyObjMap; + Window::cWindow * mWindow; cLayer** mLayers; Uint32 mFlags; @@ -245,6 +250,7 @@ class EE_API cMap { eeFloat mScale; eeVector2f mOffscale; Uint32 mLastObjId; + PolyObjMap mPolyObjs; virtual cGameObject * CreateGameObject( const Uint32& Type, const Uint32& Flags, cLayer * Layer, const Uint32& DataId = 0 ); diff --git a/include/eepp/gaming/mapeditor/cmapeditor.hpp b/include/eepp/gaming/mapeditor/cmapeditor.hpp index 34f1d094c..8bf895788 100644 --- a/include/eepp/gaming/mapeditor/cmapeditor.hpp +++ b/include/eepp/gaming/mapeditor/cmapeditor.hpp @@ -88,7 +88,7 @@ class EE_API cMapEditor { void CreateLightContainer(); - cUISelectButton * AddObjContButton( String text ); + cUISelectButton * AddObjContButton( String text, Uint32 mode ); void CreateObjectsContainer(); diff --git a/include/eepp/gaming/maphelper.hpp b/include/eepp/gaming/maphelper.hpp index 42f340fc8..dc0a6c1f4 100644 --- a/include/eepp/gaming/maphelper.hpp +++ b/include/eepp/gaming/maphelper.hpp @@ -71,11 +71,10 @@ typedef struct sMapLightHdrS { } sMapLightHdr; typedef struct sMapObjObjHdrS { - Uint32 ObjId; char Name[ MAP_PROPERTY_SIZE ]; char Type[ MAP_PROPERTY_SIZE ]; - Uint32 PropertyCount; Uint32 PointCount; + Uint32 PropertyCount; } sMapObjObjHdr; class GObjFlags { diff --git a/include/eepp/graphics/base.hpp b/include/eepp/graphics/base.hpp index 2d18ce37f..a112d6110 100644 --- a/include/eepp/graphics/base.hpp +++ b/include/eepp/graphics/base.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include using namespace EE::Math; diff --git a/include/eepp/graphics/cbatchrenderer.hpp b/include/eepp/graphics/cbatchrenderer.hpp index b0cd35a84..314003e89 100755 --- a/include/eepp/graphics/cbatchrenderer.hpp +++ b/include/eepp/graphics/cbatchrenderer.hpp @@ -2,6 +2,7 @@ #define EE_GRAPHICSCBATCHRENDERER_H #include +#include namespace EE { namespace Graphics { diff --git a/include/eepp/graphics/cprimitives.hpp b/include/eepp/graphics/cprimitives.hpp index a0bcd2f9d..fb77e838d 100755 --- a/include/eepp/graphics/cprimitives.hpp +++ b/include/eepp/graphics/cprimitives.hpp @@ -2,6 +2,7 @@ #define EE_GRAPHICSCPRIMITIVES_H #include +#include namespace EE { namespace Graphics { diff --git a/include/eepp/graphics/ctexture.hpp b/include/eepp/graphics/ctexture.hpp index 99f930ce8..6d8be8b7b 100755 --- a/include/eepp/graphics/ctexture.hpp +++ b/include/eepp/graphics/ctexture.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace EE { namespace Graphics { diff --git a/include/eepp/math/polygon2.hpp b/include/eepp/math/polygon2.hpp index 0e7ec58af..6c46f3a8a 100755 --- a/include/eepp/math/polygon2.hpp +++ b/include/eepp/math/polygon2.hpp @@ -16,6 +16,8 @@ class Polygon2 { ~Polygon2(); + Polygon2( const Polygon2& fromPoly ); + Polygon2( const Triangle2& fromTrig ); Polygon2( const Quad2& fromQuad ); @@ -28,7 +30,7 @@ class Polygon2 { void PopBack(); - void Reset(); + void Clear(); const Vector2& operator[] ( const Uint32& Pos ) const; @@ -73,8 +75,19 @@ class Polygon2 { }; template -Polygon2::Polygon2() : cOffsetX(0), cOffsetY(0) { - Reset(); +Polygon2::Polygon2() : + cOffsetX(0), + cOffsetY(0) +{ + Clear(); +} + +template +Polygon2::Polygon2( const Polygon2& fromPoly ) : + Vector( fromPoly.Vector ), + cOffsetX( fromPoly.cOffsetX ), + cOffsetY( fromPoly.cOffsetY ) +{ } template @@ -105,11 +118,11 @@ Polygon2::Polygon2( const tRECT& fromRect ) : cOffsetX(0), cOffsetY(0) { template Polygon2::~Polygon2() { - Reset(); + Clear(); } template -void Polygon2::Reset() { +void Polygon2::Clear() { Vector.clear(); } diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 95e55a889..f56283d6c 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 62311e2db..b408fa13c 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -575,3 +575,7 @@ ../../src/eepp/audio/csoundfiledefault.hpp ../../include/eepp/gaming/cgameobjectobject.hpp ../../src/eepp/gaming/cgameobjectobject.cpp +../../src/eepp/gaming/cgameobjectpolyline.cpp +../../src/eepp/gaming/cgameobjectpolygon.cpp +../../include/eepp/gaming/cgameobjectpolyline.hpp +../../include/eepp/gaming/cgameobjectpolygon.hpp diff --git a/src/eepp/gaming/cgameobjectobject.cpp b/src/eepp/gaming/cgameobjectobject.cpp index fd1d83cc3..dabfc5076 100644 --- a/src/eepp/gaming/cgameobjectobject.cpp +++ b/src/eepp/gaming/cgameobjectobject.cpp @@ -8,18 +8,9 @@ using namespace EE::Graphics; namespace EE { namespace Gaming { - -cGameObjectObject::cGameObjectObject( Uint32 DataId, cLayer * Layer, const Uint32& Flags ) : +cGameObjectObject::cGameObjectObject( Uint32 DataId, const eeRectf& rect, 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 ), + mRect( rect ), mPos( mRect.Pos() ), mDataId( DataId ) { @@ -43,11 +34,11 @@ eeSize cGameObjectObject::Size() { void cGameObjectObject::Draw() { cPrimitives P; P.FillMode( EE_DRAW_FILL ); - P.SetColor( eeColorA( 100, 100, 100, 30 ) ); + P.SetColor( eeColorA( 100, 100, 100, 100 ) ); P.DrawRectangle( mRect ); P.FillMode( EE_DRAW_LINE ); - P.SetColor( eeColorA( 50, 50, 50, 200 ) ); + P.SetColor( eeColorA( 200, 200, 200, 200 ) ); P.DrawRectangle( mRect ); } @@ -88,4 +79,32 @@ cGameObjectObject::PropertiesMap& cGameObjectObject::GetProperties() { return mProperties; } +Uint32 cGameObjectObject::GetPropertyCount() { + return mProperties.size(); +} + +const std::string& cGameObjectObject::Name() const { + return mName; +} + +void cGameObjectObject::Name( const std::string& name ) { + mName = name; +} + +const std::string& cGameObjectObject::TypeName() const { + return mType; +} + +void cGameObjectObject::TypeName( const std::string& type ) { + mType = type; +} + +eePolygon2f cGameObjectObject::GetPolygon() { + return eePolygon2f( mRect ); +} + +void cGameObjectObject::SetProperties( const PropertiesMap& prop ) { + mProperties = prop; +} + }} diff --git a/src/eepp/gaming/cgameobjectpolygon.cpp b/src/eepp/gaming/cgameobjectpolygon.cpp new file mode 100644 index 000000000..98dc7707c --- /dev/null +++ b/src/eepp/gaming/cgameobjectpolygon.cpp @@ -0,0 +1,55 @@ +#include + +#include +#include +using namespace EE::Graphics; + +namespace EE { namespace Gaming { + +cGameObjectPolygon::cGameObjectPolygon( Uint32 DataId, eePolygon2f poly, cLayer * Layer, const Uint32& Flags ) : + cGameObjectObject( DataId, poly.ToAABB(), Layer, Flags ), + mPoly( poly ) +{ +} + +cGameObjectPolygon::~cGameObjectPolygon() { +} + +Uint32 cGameObjectPolygon::Type() const { + return GAMEOBJECT_TYPE_POLYGON; +} + +bool cGameObjectPolygon::IsType( const Uint32& type ) { + return ( cGameObjectPolygon::Type() == type ) ? true : cGameObject::IsType( type ); +} + +eeSize cGameObjectPolygon::Size() { + return eeSize( mRect.Size().x, mRect.Size().y ); +} + +void cGameObjectPolygon::Draw() { + cPrimitives P; + P.FillMode( EE_DRAW_FILL ); + P.SetColor( eeColorA( 100, 100, 100, 100 ) ); + P.DrawPolygon( mPoly ); + + P.FillMode( EE_DRAW_LINE ); + P.SetColor( eeColorA( 255, 255, 0, 200 ) ); + P.DrawPolygon( mPoly ); +} + +eeVector2f cGameObjectPolygon::Pos() const { + return mPos; +} + +void cGameObjectPolygon::Pos( eeVector2f pos ) { + mPos = pos; + mPoly.Position( pos ); +} + +eePolygon2f cGameObjectPolygon::GetPolygon() { + return mPoly; +} + + +}} diff --git a/src/eepp/gaming/cgameobjectpolyline.cpp b/src/eepp/gaming/cgameobjectpolyline.cpp new file mode 100644 index 000000000..19413476f --- /dev/null +++ b/src/eepp/gaming/cgameobjectpolyline.cpp @@ -0,0 +1,32 @@ +#include + +#include +#include +using namespace EE::Graphics; + +namespace EE { namespace Gaming { + +cGameObjectPolyline::cGameObjectPolyline( Uint32 DataId, eePolygon2f poly, cLayer * Layer, const Uint32& Flags ) : + cGameObjectPolygon( DataId, poly, Layer, Flags ) +{ +} + +cGameObjectPolyline::~cGameObjectPolyline() { +} + +Uint32 cGameObjectPolyline::Type() const { + return GAMEOBJECT_TYPE_POLYGON; +} + +bool cGameObjectPolyline::IsType( const Uint32& type ) { + return ( cGameObjectPolyline::Type() == type ) ? true : cGameObjectPolygon::IsType( type ); +} + +void cGameObjectPolyline::Draw() { + cPrimitives P; + P.FillMode( EE_DRAW_LINE ); + P.SetColor( eeColorA( 255, 255, 0, 200 ) ); + P.DrawPolygon( mPoly ); +} + +}} diff --git a/src/eepp/gaming/cmap.cpp b/src/eepp/gaming/cmap.cpp index 9f7bf342e..9cb662f7b 100644 --- a/src/eepp/gaming/cmap.cpp +++ b/src/eepp/gaming/cmap.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include @@ -573,6 +575,10 @@ void cMap::Move( const eeFloat& offsetx, const eeFloat& offsety ) { Offset( eeVector2f( mOffset.x + offsetx, mOffset.y + offsety ) ); } +cGameObjectPolyData& cMap::GetPolyObjData( Uint32 Id ) { + return mPolyObjs[ Id ]; +} + cGameObject * cMap::CreateGameObject( const Uint32& Type, const Uint32& Flags, cLayer * Layer, const Uint32& DataId ) { switch ( Type ) { case GAMEOBJECT_TYPE_SUBTEXTURE: @@ -600,8 +606,26 @@ cGameObject * cMap::CreateGameObject( const Uint32& Type, const Uint32& Flags, c return tSprite; } case GAMEOBJECT_TYPE_OBJECT: + case GAMEOBJECT_TYPE_POLYGON: + case GAMEOBJECT_TYPE_POLYLINE: { - //cGameObjectObject * tObject = eeNew( cGameObjectObject, ( Layer, Flags ) ); + cGameObjectPolyData& ObjData = GetPolyObjData( DataId ); + + cGameObjectObject * tObject; + + if ( GAMEOBJECT_TYPE_OBJECT == Type ) { + tObject = eeNew( cGameObjectObject, ( DataId, ObjData.Poly.ToAABB(), Layer, Flags ) ); + } else if ( GAMEOBJECT_TYPE_POLYGON == Type ) { + tObject = eeNew( cGameObjectPolygon, ( DataId, ObjData.Poly, Layer, Flags ) ); + } else if ( GAMEOBJECT_TYPE_POLYLINE == Type ) { + tObject = eeNew( cGameObjectPolyline, ( DataId, ObjData.Poly, Layer, Flags ) ); + } + + tObject->Name( ObjData.Name ); + tObject->TypeName( ObjData.Type ); + tObject->SetProperties( ObjData.Properties ); + + return tObject; } default: { @@ -884,22 +908,56 @@ bool cMap::LoadFromStream( cIOStream& IOS ) { tLayerHdr = &( tLayersHdr[i] ); tOLayer = reinterpret_cast ( mLayers[i] ); - sMapObjGOHdr * tOGOsHdr = eeNewArray( sMapObjGOHdr, tLayerHdr->ObjectCount ); - sMapObjGOHdr * tOGOHdr; + for ( Uint32 objCount = 0; objCount < tLayerHdr->ObjectCount; objCount++ ) { + sMapObjGOHdr tOGOHdr; - IOS.Read( (char*)&tOGOsHdr, sizeof(sMapObjGOHdr) * tLayerHdr->ObjectCount ); + IOS.Read( (char*)&tOGOHdr, sizeof(sMapObjGOHdr) ); - for ( z = 0; z < tLayerHdr->ObjectCount; z++ ) { - tOGOHdr = &( tOGOsHdr[z] ); + //! For the polygon objects wee need to read the polygon points, the Name, the TypeName and the Properties. + if ( tOGOHdr.Type == GAMEOBJECT_TYPE_OBJECT || + tOGOHdr.Type == GAMEOBJECT_TYPE_POLYGON || + tOGOHdr.Type == GAMEOBJECT_TYPE_POLYLINE ) + { + cGameObjectPolyData tObjData; - tGO = CreateGameObject( tOGOHdr->Type, tOGOHdr->Flags, mLayers[i], tOGOHdr->Id ); + //! First we read the poly obj header + sMapObjObjHdr tObjObjHdr; - tGO->Pos( eeVector2f( tOGOHdr->PosX, tOGOHdr->PosY ) ); + IOS.Read( (char*)&tObjObjHdr, sizeof(sMapObjObjHdr) ); + + tObjData.Name = std::string( tObjObjHdr.Name ); + tObjData.Type = std::string( tObjObjHdr.Type ); + + //! Reads the properties + for ( Uint32 iProp = 0; iProp < tObjObjHdr.PropertyCount; i++ ) { + sPropertyHdr tObjProp; + + IOS.Read( (char*)&tObjProp, sizeof(sPropertyHdr) ); + + tObjData.Properties[ std::string( tObjProp.Name ) ] = std::string( tObjProp.Value ); + } + + //! Reads the polygon points + for ( Uint32 iPoint = 0; iPoint < tObjObjHdr.PointCount; iPoint++ ) { + eeVector2if p; + + IOS.Read( (char*)&p, sizeof(eeVector2if) ); + + tObjData.Poly.PushBack( eeVector2f( p.x, p.y ) ); + } + + mPolyObjs[ tOGOHdr.Id ] = tObjData; + + //! Recover the last max id + mLastObjId = eemax( mLastObjId, tOGOHdr.Id ); + } + + tGO = CreateGameObject( tOGOHdr.Type, tOGOHdr.Flags, mLayers[i], tOGOHdr.Id ); + + tGO->Pos( eeVector2f( tOGOHdr.PosX, tOGOHdr.PosY ) ); tOLayer->AddGameObject( tGO ); } - - eeSAFE_DELETE_ARRAY( tOGOsHdr ); } } @@ -910,16 +968,13 @@ bool cMap::LoadFromStream( cIOStream& IOS ) { sMapLightHdr * tLighsHdr = eeNewArray( sMapLightHdr, MapHdr.LightsCount ); sMapLightHdr * tLightHdr; - IOS.Read( (char*)&tLighsHdr, sizeof(sMapLightHdr) * MapHdr.LightsCount ); + IOS.Read( (char*)tLighsHdr, sizeof(sMapLightHdr) * MapHdr.LightsCount ); for ( i = 0; i < MapHdr.LightsCount; i++ ) { tLightHdr = &( tLighsHdr[ i ] ); - eeColorA tLightColA( tLightHdr->Color ); - eeColor tLightCol( tLightColA.R(), tLightColA.G(), tLightColA.B() ); - mLightManager->AddLight( - eeNew( cLight, ( tLightHdr->Radius, tLightHdr->PosX, tLightHdr->PosY, tLightCol, (LIGHT_TYPE)tLightHdr->Type ) ) + eeNew( cLight, ( tLightHdr->Radius, tLightHdr->PosX, tLightHdr->PosY, eeColorA( tLightHdr->Color ).ToColor(), (LIGHT_TYPE)tLightHdr->Type ) ) ); } @@ -931,6 +986,8 @@ bool cMap::LoadFromStream( cIOStream& IOS ) { OnMapLoaded(); + mPolyObjs.clear(); + return true; } } @@ -1177,6 +1234,7 @@ void cMap::SaveToStream( cIOStream& IOS ) { sMapObjGOHdr tOGOHdr; //! The DataId should be the SubTexture hash name ( at least in the cases of type SubTexture, SubTextureEx and Sprite. + //! And for the Poly Obj should be an arbitrary value assigned by the map on the moment of creation tOGOHdr.Id = tObj->DataId(); //! If the object type is virtual, means that the real type is stored elsewhere. @@ -1195,6 +1253,50 @@ void cMap::SaveToStream( cIOStream& IOS ) { tOGOHdr.PosY = (Int32)tObj->Pos().y; IOS.Write( (const char*)&tOGOHdr, sizeof(sMapObjGOHdr) ); + + //! For the polygon objects wee need to write the polygon points, the Name, the TypeName and the Properties. + if ( tObj->Type() == GAMEOBJECT_TYPE_OBJECT || + tObj->Type() == GAMEOBJECT_TYPE_POLYGON || + tObj->Type() == GAMEOBJECT_TYPE_POLYLINE ) + { + cGameObjectObject * tObjObj = reinterpret_cast( tObj ); + eePolygon2f tPoly = tObjObj->GetPolygon(); + cGameObjectObject::PropertiesMap tObjObjProp = tObjObj->GetProperties(); + sMapObjObjHdr tObjObjHdr; + + memset( tObjObjHdr.Name, 0, MAP_PROPERTY_SIZE ); + memset( tObjObjHdr.Type, 0, MAP_PROPERTY_SIZE ); + + String::StrCopy( tObjObjHdr.Name, tObjObj->Name().c_str(), MAP_PROPERTY_SIZE ); + String::StrCopy( tObjObjHdr.Type, tObjObj->TypeName().c_str(), MAP_PROPERTY_SIZE ); + + tObjObjHdr.PointCount = tPoly.Size(); + tObjObjHdr.PropertyCount = tObjObjProp.size(); + + //! Writes the ObjObj header + IOS.Write( (const char*)&tObjObjHdr, sizeof(sMapObjObjHdr) ); + + //! Writes the properties of the current polygon object + for ( cGameObjectObject::PropertiesMap::iterator ooit = tObjObjProp.begin(); ooit != tObjObjProp.end(); ooit++ ) { + sPropertyHdr tProp; + + memset( tProp.Name, 0, MAP_PROPERTY_SIZE ); + memset( tProp.Value, 0, MAP_PROPERTY_SIZE ); + + String::StrCopy( tProp.Name, ooit->first.c_str(), MAP_PROPERTY_SIZE ); + String::StrCopy( tProp.Value, ooit->second.c_str(), MAP_PROPERTY_SIZE ); + + IOS.Write( (const char*)&tProp, sizeof(sPropertyHdr) ); + } + + //! Writes the polygon points + for ( Uint32 tPoint = 0; tPoint < tPoly.Size(); tPoint++ ) { + eeVector2f pf( tPoly.GetAt( tPoint ) ); + eeVector2if p( pf.x, pf.y ); //! Convert it to Int32 + + IOS.Write( (const char*)&p, sizeof(eeVector2if) ); + } + } } } } diff --git a/src/eepp/gaming/mapeditor/cmapeditor.cpp b/src/eepp/gaming/mapeditor/cmapeditor.cpp index 6fc266344..ce900265e 100644 --- a/src/eepp/gaming/mapeditor/cmapeditor.cpp +++ b/src/eepp/gaming/mapeditor/cmapeditor.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include #include @@ -370,12 +372,13 @@ void cMapEditor::CreateLightContainer() { mLightTypeChk->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapEditor::OnLightTypeChange ) ); } -cUISelectButton * cMapEditor::AddObjContButton( String text ) { +cUISelectButton * cMapEditor::AddObjContButton( String text, Uint32 mode ) { static Int32 lastY = 0; cUISelectButton * Button = mTheme->CreateSelectButton( mObjectCont, eeSize( mObjectCont->Size().Width(), 22 ), eeVector2i( 0, lastY ) ); Button->Text( text ); + Button->Data( mode ); Button->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::OnObjectModeSel ) ); @@ -387,11 +390,11 @@ cUISelectButton * cMapEditor::AddObjContButton( String text ) { } void cMapEditor::CreateObjectsContainer() { - AddObjContButton( "Select Objects" ); - AddObjContButton( "Edit Polygons" ); - AddObjContButton( "Insert Object" )->Select(); - AddObjContButton( "Insert Polygon" ); - cUISelectButton * Button = AddObjContButton( "Select Polyline" ); + AddObjContButton( "Select Objects", cUIMap::SELECT_OBJECTS ); + AddObjContButton( "Edit Polygons", cUIMap::EDIT_POLYGONS ); + AddObjContButton( "Insert Object", cUIMap::INSERT_OBJECT )->Select(); + AddObjContButton( "Insert Polygon", cUIMap::INSERT_POLYGON ); + cUISelectButton * Button = AddObjContButton( "Insert Polyline", cUIMap::INSERT_POLYLINE ); Int32 nextY = Button->Pos().y + Button->Size().Height() + 4; @@ -415,6 +418,8 @@ void cMapEditor::OnObjectModeSel( const cUIEvent * Event ) { } Button->Select(); + + mUIMap->EditingObjMode( (cUIMap::EDITING_OBJ_MODE)Button->Data() ); } void cMapEditor::CreateUIMap() { @@ -455,17 +460,14 @@ void cMapEditor::OnAddObject( Uint32 Type, eePolygon2f poly ) { return; } + cObjectLayer * OL = static_cast ( mCurLayer ); + if ( GAMEOBJECT_TYPE_OBJECT == Type ) { - cObjectLayer * OL = static_cast ( 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 ) { - + OL->AddGameObject( eeNew( cGameObjectObject, ( mUIMap->Map()->GetNewObjectId(), poly.ToAABB(), mCurLayer ) ) ); + } else if ( GAMEOBJECT_TYPE_POLYGON == Type ) { + OL->AddGameObject( eeNew( cGameObjectPolygon, ( mUIMap->Map()->GetNewObjectId(), poly, mCurLayer ) ) ); + } else if ( GAMEOBJECT_TYPE_POLYLINE == Type ) { + OL->AddGameObject( eeNew( cGameObjectPolyline, ( mUIMap->Map()->GetNewObjectId(), poly, mCurLayer ) ) ); } } diff --git a/src/eepp/gaming/mapeditor/cuimap.cpp b/src/eepp/gaming/mapeditor/cuimap.cpp index 5d28d862e..90a5605a7 100644 --- a/src/eepp/gaming/mapeditor/cuimap.cpp +++ b/src/eepp/gaming/mapeditor/cuimap.cpp @@ -6,13 +6,13 @@ namespace EE { namespace Gaming { namespace MapEditor { cUIMap::cUIMap( const cUIComplexControl::CreateParams& Params, cMap * Map ) : cUIComplexControl( Params ), mMap( Map ), - mEditingLights( false ), - mEditingObjects( false ), + mEditingMode( 0 ), mEditingObjMode( INSERT_OBJECT ), - mObjAddType( GAMEOBJECT_TYPE_OBJECT ), mAddLight( NULL ), mSelLight( NULL ), - mClampToTile(true) + mClampToTile(true), + mObjRECTEditing(false), + mObjPolyEditing(false) { if ( NULL == Map ) { mMap = eeNew( cMap, () ); @@ -54,7 +54,7 @@ void cUIMap::Update() { if ( mEnabled && mVisible && IsMouseOver() ) { Uint32 Flags = cUIManager::instance()->GetInput()->ClickTrigger(); - if ( mEditingLights ) { + if ( EDITING_LIGHT == mEditingMode ) { if ( NULL != mSelLight ) { if ( Flags & EE_BUTTONS_WUWD ) { if ( Flags & EE_BUTTON_WUMASK ) { @@ -97,13 +97,24 @@ void cUIMap::Update() { TryToSelectLight(); } } - } else if ( mEditingObjects ) { + } else if ( EDITING_OBJECT == mEditingMode ) { ManageObject( Flags ); } } } } +eeVector2f cUIMap::GetMouseMapPos() { + eeVector2f mp( mMap->GetMouseMapPosf() ); + + if ( mClampToTile ) { + eeVector2i mpc( mMap->GetTileCoords( mMap->GetMouseTilePos() + 1 ) ); + mp = eeVector2f( mpc.x, mpc.y ); + } + + return mp; +} + void cUIMap::ManageObject( Uint32 Flags ) { Uint32 PFlags = cUIManager::instance()->GetInput()->PressTrigger(); @@ -112,12 +123,7 @@ void cUIMap::ManageObject( Uint32 Flags ) { 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 ); - } + eeVector2f mp( GetMouseMapPos() ); if ( !mObjRECTEditing ) { mObjRECTEditing = true; @@ -131,13 +137,26 @@ void cUIMap::ManageObject( Uint32 Flags ) { if ( Flags & EE_BUTTON_LMASK ){ if ( mObjRECTEditing ) { - mAddObjectCallback( mObjAddType, eePolygon2f( mObjRECT ) ); + mAddObjectCallback( GAMEOBJECT_TYPE_OBJECT, eePolygon2f( mObjRECT ) ); mObjRECTEditing = false; } } break; } + case INSERT_POLYLINE: + case INSERT_POLYGON: + { + if ( Flags & EE_BUTTON_LMASK ) { + mObjPoly.PushBack( GetMouseMapPos() ); + } else if ( Flags & EE_BUTTON_RMASK ) { + mAddObjectCallback( ( INSERT_POLYGON == mEditingObjMode ) ? GAMEOBJECT_TYPE_POLYGON : GAMEOBJECT_TYPE_POLYLINE, mObjPoly ); + + mObjPoly.Clear(); + } + + break; + } default: { } @@ -165,7 +184,7 @@ void cUIMap::OnSizeChange() { Uint32 cUIMap::OnMouseMove( const eeVector2i& Pos, const Uint32 Flags ) { if ( NULL != mMap ) { - if ( mEditingLights && NULL != mAddLight ) { + if ( EDITING_LIGHT == mEditingMode && NULL != mAddLight ) { mAddLight->Position( mMap->GetMouseMapPosf() ); } } @@ -193,7 +212,7 @@ void cUIMap::AddLight( cLight * Light ) { } void cUIMap::MapDraw() { - if ( mEditingLights ) { + if ( EDITING_LIGHT == mEditingMode ) { if ( NULL != mSelLight ) { mP.SetColor( eeColorA( 255, 0, 0, (Uint8)mAlpha ) ); @@ -203,21 +222,66 @@ void cUIMap::MapDraw() { 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 ); + } else if ( EDITING_OBJECT == mEditingMode ) { + switch ( mEditingObjMode ) { + case INSERT_OBJECT: + { + if ( mObjRECTEditing ) { + mP.FillMode( EE_DRAW_FILL ); + mP.SetColor( eeColorA( 100, 100, 100, 20 ) ); + mP.DrawRectangle( mObjRECT ); - mP.FillMode( EE_DRAW_LINE ); - mP.SetColor( eeColorA( 255, 0, 0, (Uint8)( 200 * mAlpha ) ) ); - mP.DrawRectangle( mObjRECT ); + mP.FillMode( EE_DRAW_LINE ); + mP.SetColor( eeColorA( 255, 0, 0, 200 ) ); + mP.DrawRectangle( mObjRECT ); + } + + break; + } + case INSERT_POLYGON: + { + mP.FillMode( EE_DRAW_FILL ); + mP.SetColor( eeColorA( 50, 50, 50, 50 ) ); + mP.DrawPolygon( mObjPoly ); + + mP.FillMode( EE_DRAW_LINE ); + mP.SetColor( eeColorA( 255, 0, 0, 200 ) ); + mP.DrawPolygon( mObjPoly ); + + eePolygon2f polyN( mObjPoly ); + polyN.PushBack( GetMouseMapPos() ); + + mP.FillMode( EE_DRAW_FILL ); + mP.SetColor( eeColorA( 100, 100, 100, 100 ) ); + mP.DrawPolygon( polyN ); + + mP.FillMode( EE_DRAW_LINE ); + mP.SetColor( eeColorA( 255, 255, 0, 200 ) ); + mP.DrawPolygon( polyN ); + + break; + } + case INSERT_POLYLINE: + { + mP.FillMode( EE_DRAW_LINE ); + mP.SetColor( eeColorA( 255, 0, 0, 200 ) ); + mP.DrawPolygon( mObjPoly ); + + eePolygon2f polyN( mObjPoly ); + polyN.PushBack( GetMouseMapPos() ); + + mP.FillMode( EE_DRAW_LINE ); + mP.SetColor( eeColorA( 255, 255, 0, 200 ) ); + mP.DrawPolygon( polyN ); + + break; + } } } } -void cUIMap::PrivEditingLights( const bool& editing ) { - mEditingLights = editing; +void cUIMap::EditingLights( const bool& editing ) { + mEditingMode = ( editing ) ? EDITING_LIGHT : 0; if ( editing && NULL != mMap->GetLightManager() && NULL != mAddLight ) { mMap->GetLightManager()->RemoveLight( mAddLight ); @@ -226,37 +290,20 @@ void cUIMap::PrivEditingLights( const bool& editing ) { } } -void cUIMap::EditingLights( const bool& editing ) { - PrivEditingLights( editing ); - - if ( editing ) { - PrivEditingObjects( false ); - } -} - -const bool& cUIMap::EditingLights() { - return mEditingLights; -} - -void cUIMap::PrivEditingObjects( const bool& editing ) { - mEditingObjects = editing; +bool cUIMap::EditingLights() { + return EDITING_LIGHT == mEditingMode; } void cUIMap::EditingObjects( const bool& editing ) { - PrivEditingObjects( editing ); - - if ( editing ) { - PrivEditingLights( false ); - } + mEditingMode = ( editing ) ? EDITING_OBJECT : 0; } -const bool& cUIMap::EditingObjects() { - return mEditingObjects; +bool cUIMap::EditingObjects() { + return EDITING_OBJECT == mEditingMode; } void cUIMap::EditingDisabled() { - EditingLights( false ); - EditingObjects( false ); + mEditingMode = 0; } cLight * cUIMap::GetSelectedLight() { @@ -300,4 +347,10 @@ const bool& cUIMap::ClampToTile() const { return mClampToTile; } +void cUIMap::EditingObjMode( EDITING_OBJ_MODE mode ) { + mObjPoly.Clear(); + + mEditingObjMode = mode; +} + }}} diff --git a/src/eepp/gaming/mapeditor/cuimap.hpp b/src/eepp/gaming/mapeditor/cuimap.hpp index 38ce65e75..e20506f3b 100644 --- a/src/eepp/gaming/mapeditor/cuimap.hpp +++ b/src/eepp/gaming/mapeditor/cuimap.hpp @@ -13,6 +13,14 @@ namespace EE { namespace Gaming { namespace MapEditor { class EE_API cUIMap : public cUIComplexControl { public: + enum EDITING_OBJ_MODE { + SELECT_OBJECTS, + EDIT_POLYGONS, + INSERT_OBJECT, + INSERT_POLYGON, + INSERT_POLYLINE + }; + typedef cb::Callback1 LightSelectCb; typedef cb::Callback1 LightRadiusChangeCb; typedef cb::Callback2 ObjAddCb; @@ -29,13 +37,13 @@ class EE_API cUIMap : public cUIComplexControl { void EditingLights( const bool& editing ); - const bool& EditingLights(); + bool EditingLights(); void EditingObjects( const bool& editing ); void EditingDisabled(); - const bool& EditingObjects(); + bool EditingObjects(); cLight * GetSelectedLight(); @@ -54,33 +62,34 @@ class EE_API cUIMap : public cUIComplexControl { void ClampToTile( const bool& clamp ); const bool& ClampToTile() const; - protected: - cMap * mMap; - bool mEditingLights; - bool mEditingObjects; - enum EDITING_OBJ_MODE { - SELECT_OBJECTS, - EDIT_POLYGONS, - INSERT_OBJECT, - INSERT_POLYGON, - INSERT_POLYLINE + void EditingObjMode( EDITING_OBJ_MODE mode ); + protected: + enum EDITING_MODE { + EDITING_LIGHT = 1, + EDITING_OBJECT }; + cMap * mMap; + Uint32 mEditingMode; + cPrimitives mP; + Uint32 mEditingObjMode; - Uint32 mObjAddType; cLight * mAddLight; cLight * mSelLight; LightSelectCb mLightSelCb; LightRadiusChangeCb mLightRadiusChangeCb; + ObjAddCb mAddObjectCallback; + + bool mClampToTile; bool mObjRECTEditing; - bool mClampToTile; eeRectf mObjRECT; - cPrimitives mP; - ObjAddCb mAddObjectCallback; + + bool mObjPolyEditing; + eePolygon2f mObjPoly; virtual Uint32 OnMouseMove( const eeVector2i& Pos, const Uint32 Flags ); @@ -94,11 +103,9 @@ class EE_API cUIMap : public cUIComplexControl { void TryToSelectLight(); - void PrivEditingLights( const bool& editing ); - - void PrivEditingObjects( const bool& editing ); - void ManageObject( Uint32 Flags ); + + eeVector2f GetMouseMapPos(); }; }}}