Polygons working on Maps and Map Editor. Still WIP. Not everything is implemented.

This commit is contained in:
Martín Lucas Golini
2013-01-12 19:25:04 -03:00
parent bc0601f7d9
commit ee7d738114
20 changed files with 495 additions and 125 deletions

View File

@@ -14,9 +14,7 @@ class EE_API cGameObjectObject : public cGameObject {
public:
typedef std::map<std::string, std::string> 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

View File

@@ -0,0 +1,33 @@
#ifndef EE_GAMINGCGAMEOBJECTPOLYGON_HPP
#define EE_GAMINGCGAMEOBJECTPOLYGON_HPP
#include <eepp/gaming/cgameobjectobject.hpp>
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

View File

@@ -0,0 +1,23 @@
#ifndef EE_GAMINGCGAMEOBJECTPOLYLINE_HPP
#define EE_GAMINGCGAMEOBJECTPOLYLINE_HPP
#include <eepp/gaming/cgameobjectpolygon.hpp>
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

View File

@@ -4,6 +4,7 @@
#include <eepp/gaming/base.hpp>
#include <eepp/gaming/cgameobject.hpp>
#include <eepp/gaming/cgameobjectobject.hpp>
#include <eepp/gaming/clight.hpp>
#include <eepp/gaming/clightmanager.hpp>
#include <eepp/gaming/clayer.hpp>
@@ -209,7 +210,11 @@ class EE_API cMap {
eeVector2i GetMaxOffset();
Uint32 GetNewObjectId();
cGameObjectPolyData& GetPolyObjData( Uint32 Id );
protected:
typedef std::map<Uint32, cGameObjectPolyData> 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 );

View File

@@ -88,7 +88,7 @@ class EE_API cMapEditor {
void CreateLightContainer();
cUISelectButton * AddObjContButton( String text );
cUISelectButton * AddObjContButton( String text, Uint32 mode );
void CreateObjectsContainer();

View File

@@ -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 {

View File

@@ -7,7 +7,6 @@
#include <eepp/math/vector3.hpp>
#include <eepp/math/rect.hpp>
#include <eepp/math/vector2.hpp>
#include <eepp/math/polygon2.hpp>
#include <eepp/math/math.hpp>
using namespace EE::Math;

View File

@@ -2,6 +2,7 @@
#define EE_GRAPHICSCBATCHRENDERER_H
#include <eepp/graphics/base.hpp>
#include <eepp/math/polygon2.hpp>
namespace EE { namespace Graphics {

View File

@@ -2,6 +2,7 @@
#define EE_GRAPHICSCPRIMITIVES_H
#include <eepp/graphics/base.hpp>
#include <eepp/math/polygon2.hpp>
namespace EE { namespace Graphics {

View File

@@ -4,6 +4,7 @@
#include <eepp/graphics/base.hpp>
#include <eepp/graphics/cimage.hpp>
#include <eepp/graphics/ctexturefactory.hpp>
#include <eepp/math/polygon2.hpp>
namespace EE { namespace Graphics {

View File

@@ -16,6 +16,8 @@ class Polygon2 {
~Polygon2();
Polygon2( const Polygon2<T>& fromPoly );
Polygon2( const Triangle2<T>& fromTrig );
Polygon2( const Quad2<T>& fromQuad );
@@ -28,7 +30,7 @@ class Polygon2 {
void PopBack();
void Reset();
void Clear();
const Vector2<T>& operator[] ( const Uint32& Pos ) const;
@@ -73,8 +75,19 @@ class Polygon2 {
};
template <typename T>
Polygon2<T>::Polygon2() : cOffsetX(0), cOffsetY(0) {
Reset();
Polygon2<T>::Polygon2() :
cOffsetX(0),
cOffsetY(0)
{
Clear();
}
template <typename T>
Polygon2<T>::Polygon2( const Polygon2<T>& fromPoly ) :
Vector( fromPoly.Vector ),
cOffsetX( fromPoly.cOffsetX ),
cOffsetY( fromPoly.cOffsetY )
{
}
template <typename T>
@@ -105,11 +118,11 @@ Polygon2<T>::Polygon2( const tRECT<T>& fromRect ) : cOffsetX(0), cOffsetY(0) {
template <typename T>
Polygon2<T>::~Polygon2() {
Reset();
Clear();
}
template <typename T>
void Polygon2<T>::Reset() {
void Polygon2<T>::Clear() {
Vector.clear();
}

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by Qt Creator 2.6.1, 2013-01-12T02:03:25. -->
<!-- Written by Qt Creator 2.6.1, 2013-01-12T11:40:20. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>

View File

@@ -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

View File

@@ -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;
}
}}

View File

@@ -0,0 +1,55 @@
#include <eepp/gaming/cgameobjectpolygon.hpp>
#include <eepp/gaming/clayer.hpp>
#include <eepp/graphics/cprimitives.hpp>
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;
}
}}

View File

@@ -0,0 +1,32 @@
#include <eepp/gaming/cgameobjectpolyline.hpp>
#include <eepp/gaming/clayer.hpp>
#include <eepp/graphics/cprimitives.hpp>
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 );
}
}}

View File

@@ -4,6 +4,8 @@
#include <eepp/gaming/cgameobjectsubtextureex.hpp>
#include <eepp/gaming/cgameobjectsprite.hpp>
#include <eepp/gaming/cgameobjectobject.hpp>
#include <eepp/gaming/cgameobjectpolygon.hpp>
#include <eepp/gaming/cgameobjectpolyline.hpp>
#include <eepp/gaming/ctilelayer.hpp>
#include <eepp/gaming/cobjectlayer.hpp>
@@ -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<cObjectLayer*> ( 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<cGameObjectObject*>( 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) );
}
}
}
}
}

View File

@@ -13,6 +13,8 @@
#include <eepp/gaming/cgameobjectsubtextureex.hpp>
#include <eepp/gaming/cgameobjectsprite.hpp>
#include <eepp/gaming/cgameobjectobject.hpp>
#include <eepp/gaming/cgameobjectpolygon.hpp>
#include <eepp/gaming/cgameobjectpolyline.hpp>
#include <eepp/ui/cuimanager.hpp>
#include <eepp/ui/cuithememanager.hpp>
#include <eepp/ui/cuiwinmenu.hpp>
@@ -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<cObjectLayer*> ( mCurLayer );
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 ) {
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 ) ) );
}
}

View File

@@ -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;
}
}}}

View File

@@ -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<void, cLight *> LightSelectCb;
typedef cb::Callback1<void, cLight *> LightRadiusChangeCb;
typedef cb::Callback2<void, Uint32, eePolygon2f> 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();
};
}}}