diff --git a/include/eepp/base/string.hpp b/include/eepp/base/string.hpp index b738db46c..dfe0c0448 100644 --- a/include/eepp/base/string.hpp +++ b/include/eepp/base/string.hpp @@ -56,6 +56,9 @@ class EE_API String { /** @return string hash */ static Uint32 Hash( const Uint8 * str ); + /** @return string hash */ + static Uint32 Hash( const char * str ); + /** @return string hash */ static Uint32 Hash( const std::string& str ); diff --git a/include/eepp/gaming/cgameobjectobject.hpp b/include/eepp/gaming/cgameobjectobject.hpp new file mode 100644 index 000000000..f3e283398 --- /dev/null +++ b/include/eepp/gaming/cgameobjectobject.hpp @@ -0,0 +1,59 @@ +#ifndef EE_GAMINGCGAMEOBJECTOBJECT_HPP +#define EE_GAMINGCGAMEOBJECTOBJECT_HPP + +#include +#include +#include +using namespace EE::Graphics; + +namespace EE { namespace Gaming { + +class cLayer; + +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 ); + + virtual ~cGameObjectObject(); + + 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 Uint32 DataId(); + + virtual void DataId( Uint32 Id ); + + void AddProperty( std::string Text, std::string Value ); + + void EditProperty( std::string Text, std::string Value ); + + void RemoveProperty( std::string Text ); + + void ClearProperties(); + + PropertiesMap& GetProperties(); + protected: + eeRectf mRect; + eeVector2f mPos; + Uint32 mDataId; + std::string mName; + std::string mType; + PropertiesMap mProperties; +}; + +}} + +#endif diff --git a/include/eepp/gaming/clayer.hpp b/include/eepp/gaming/clayer.hpp index bb48bd4d0..b831b482f 100644 --- a/include/eepp/gaming/clayer.hpp +++ b/include/eepp/gaming/clayer.hpp @@ -33,6 +33,8 @@ class EE_API cLayer { void Offset( const eeVector2f& offset ); + void Name( const std::string& name ); + const std::string& Name() const; const Uint32& Id() const; diff --git a/include/eepp/gaming/cmap.hpp b/include/eepp/gaming/cmap.hpp index 6e9366044..0129aaa89 100644 --- a/include/eepp/gaming/cmap.hpp +++ b/include/eepp/gaming/cmap.hpp @@ -207,6 +207,8 @@ class EE_API cMap { void Scale( const eeFloat& scale ); eeVector2i GetMaxOffset(); + + Uint32 GetNewObjectId(); protected: Window::cWindow * mWindow; cLayer** mLayers; @@ -242,6 +244,7 @@ class EE_API cMap { std::string mPath; eeFloat mScale; eeVector2f mOffscale; + Uint32 mLastObjId; 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 304155d38..34f1d094c 100644 --- a/include/eepp/gaming/mapeditor/cmapeditor.hpp +++ b/include/eepp/gaming/mapeditor/cmapeditor.hpp @@ -9,6 +9,10 @@ #include #include +namespace EE { namespace UI { +class cUIMessageBox; +}} + using namespace EE::UI; namespace EE { namespace Gaming { namespace MapEditor { @@ -61,6 +65,7 @@ class EE_API cMapEditor { cUIMenuCheckBox * mChkShowGrid; cUIMenuCheckBox * mChkMarkTileOver; cUIMenuCheckBox * mChkShowBlocked; + cUICheckBox * mChkClampToTile; //! Light Color cUIComplexControl * mUIBaseColor; @@ -83,7 +88,7 @@ class EE_API cMapEditor { void CreateLightContainer(); - void AddObjContButton( String text ); + cUISelectButton * AddObjContButton( String text ); void CreateObjectsContainer(); @@ -149,6 +154,8 @@ class EE_API cMapEditor { void ChkClickDI( const cUIEvent * Event ); + void ChkClickClampToTile( const cUIEvent * Event ); + void OnMapMouseDown( const cUIEvent * Event ); void OnMapMouseClick( const cUIEvent * Event ); @@ -173,6 +180,8 @@ class EE_API cMapEditor { void OnNewGOTypeAdded( std::string name, Uint32 hash ); + void OnAddObject( Uint32 Type, eePolygon2f poly ); + void UpdateGfx(); void UpdateFlags(); @@ -209,7 +218,9 @@ class EE_API cMapEditor { void ZoomOut(); - void CreateNoLayerAlert( const String title ); + cUIMessageBox * CreateAlert( const String& title, const String& text ); + + cUIMessageBox * CreateNoLayerAlert( const String title ); void OnTabSelected( const cUIEvent * Event ); diff --git a/include/eepp/gaming/maphelper.hpp b/include/eepp/gaming/maphelper.hpp index b2facacc8..42f340fc8 100644 --- a/include/eepp/gaming/maphelper.hpp +++ b/include/eepp/gaming/maphelper.hpp @@ -1,6 +1,8 @@ #ifndef EE_GAMINGMAPHELPER_HPP #define EE_GAMINGMAPHELPER_HPP +#include + namespace EE { namespace Gaming { #define MAP_PROPERTY_SIZE (64) @@ -68,6 +70,14 @@ typedef struct sMapLightHdrS { Uint32 Type; } sMapLightHdr; +typedef struct sMapObjObjHdrS { + Uint32 ObjId; + char Name[ MAP_PROPERTY_SIZE ]; + char Type[ MAP_PROPERTY_SIZE ]; + Uint32 PropertyCount; + Uint32 PointCount; +} sMapObjObjHdr; + class GObjFlags { public: enum EE_GAMEOBJECT_FLAGS { @@ -82,13 +92,14 @@ class GObjFlags { }; enum EE_GAMEOBJECT_TYPE { - GAMEOBJECT_TYPE_BASE = 236430550u, //String::Hash( "Base" ), - GAMEOBJECT_TYPE_VIRTUAL = 4069800883u, //String::Hash( "Virtual" ), - GAMEOBJECT_TYPE_SHAPE = 3517332124u, //String::Hash( "Shape" ) == 3517332124u for backward compatibility - GAMEOBJECT_TYPE_SUBTEXTURE = 1772101792u, //String::Hash( "SubTexture" ) == 1772101792u, - GAMEOBJECT_TYPE_SHAPEEX = 3708695628u, //String::Hash( "ShapeEx" ) == 3708695628u for backward compatibility - GAMEOBJECT_TYPE_SUBTEXTUREEX = 1378537981u, //String::Hash( "SubTextureEx" ) == 1378537981u, - GAMEOBJECT_TYPE_SPRITE = 2088954976u //String::Hash( "Sprite" ) + GAMEOBJECT_TYPE_BASE = 2088954976UL, //String::Hash( "Base" ) + GAMEOBJECT_TYPE_VIRTUAL = 3708695628UL, //String::Hash( "Virtual" ) + GAMEOBJECT_TYPE_SUBTEXTURE = 1772101792UL, //String::Hash( "SubTexture" ) + GAMEOBJECT_TYPE_SUBTEXTUREEX = 1378537981UL, //String::Hash( "SubTextureEx" ) + GAMEOBJECT_TYPE_SPRITE = 3517332124UL, //String::Hash( "Sprite" ) + GAMEOBJECT_TYPE_OBJECT = 3343895260UL, //String::Hash( "Object" ) + GAMEOBJECT_TYPE_POLYGON = 482716845UL, //String::Hash( "Polygon" ) + GAMEOBJECT_TYPE_POLYLINE = 3044927249UL //String::Hash( "Polyline" ) }; enum EE_LAYER_TYPE { diff --git a/include/eepp/math/polygon2.hpp b/include/eepp/math/polygon2.hpp index f43ac510e..0e7ec58af 100755 --- a/include/eepp/math/polygon2.hpp +++ b/include/eepp/math/polygon2.hpp @@ -62,6 +62,8 @@ class Polygon2 { bool PointInside( const Vector2& point ); + tRECT ToAABB(); + static Polygon2 CreateRoundedPolygon( const T& x, const T& y, const T& width, const T& height, const eeUint& Radius = 8 ); static bool IntersectQuad2( const Quad2& q0, const Quad2& q1, const Vector2& q0Pos = Vector2(0,0), const Vector2& q1Pos = Vector2(0,0) ); @@ -326,6 +328,30 @@ bool Polygon2::IntersectQuad2( const Quad2& q0, const Quad2& q1, const return Tmp1.Intersect( Tmp2 ); } +template +tRECT Polygon2::ToAABB() { + tRECT TmpR; + + if ( Vector.size() < 4 ) { + return TmpR; + } + + eeFloat MinX = Vector[0].x, MaxX = Vector[0].x, MinY = Vector[0].y, MaxY = Vector[0].y; + + for (Uint8 i = 1; i < Vector.size(); i++ ) { + if ( MinX > Vector[i].x ) MinX = Vector[i].x; + if ( MaxX < Vector[i].x ) MaxX = Vector[i].x; + if ( MinY > Vector[i].y ) MinY = Vector[i].y; + if ( MaxY < Vector[i].y ) MaxY = Vector[i].y; + } + + TmpR.Left = MinX + cOffsetX; + TmpR.Right = MaxX + cOffsetX; + TmpR.Top = MinY + cOffsetY; + TmpR.Bottom = MaxY + cOffsetY; + + return TmpR; +} typedef Polygon2 eePolygon2f; diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index e860b9041..95e55a889 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 e133b5338..62311e2db 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -573,3 +573,5 @@ ../../premake4.lua ../../src/eepp/audio/csoundfileogg.hpp ../../src/eepp/audio/csoundfiledefault.hpp +../../include/eepp/gaming/cgameobjectobject.hpp +../../src/eepp/gaming/cgameobjectobject.cpp diff --git a/src/eepp/base/string.cpp b/src/eepp/base/string.cpp index 300021297..8c418f550 100644 --- a/src/eepp/base/string.cpp +++ b/src/eepp/base/string.cpp @@ -24,6 +24,10 @@ Uint32 String::Hash( const Uint8 * str ) { return 0; } +Uint32 String::Hash( const char * str ) { + return String::Hash( reinterpret_cast( str ) ); +} + Uint32 String::Hash( const std::string& str ) { return String::Hash( reinterpret_cast( &str[0] ) ); } diff --git a/src/eepp/gaming/cgameobjectobject.cpp b/src/eepp/gaming/cgameobjectobject.cpp new file mode 100644 index 000000000..fd1d83cc3 --- /dev/null +++ b/src/eepp/gaming/cgameobjectobject.cpp @@ -0,0 +1,91 @@ +#include + +#include +#include +#include +#include +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; +} + +}} diff --git a/src/eepp/gaming/clayer.cpp b/src/eepp/gaming/clayer.cpp index 34373492a..a36dcbca3 100644 --- a/src/eepp/gaming/clayer.cpp +++ b/src/eepp/gaming/clayer.cpp @@ -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; } diff --git a/src/eepp/gaming/cmap.cpp b/src/eepp/gaming/cmap.cpp index 53246dfa1..9f7bf342e 100644 --- a/src/eepp/gaming/cmap.cpp +++ b/src/eepp/gaming/cmap.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -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; +} + }} diff --git a/src/eepp/gaming/mapeditor/cmapeditor.cpp b/src/eepp/gaming/mapeditor/cmapeditor.cpp index 5c0331ade..6fc266344 100644 --- a/src/eepp/gaming/mapeditor/cmapeditor.cpp +++ b/src/eepp/gaming/mapeditor/cmapeditor.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -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 ( 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() { diff --git a/src/eepp/gaming/mapeditor/cuimap.cpp b/src/eepp/gaming/mapeditor/cuimap.cpp index b9f93f249..5d28d862e 100644 --- a/src/eepp/gaming/mapeditor/cuimap.cpp +++ b/src/eepp/gaming/mapeditor/cuimap.cpp @@ -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; +} + }}} diff --git a/src/eepp/gaming/mapeditor/cuimap.hpp b/src/eepp/gaming/mapeditor/cuimap.hpp index 2c3b6bc43..38ce65e75 100644 --- a/src/eepp/gaming/mapeditor/cuimap.hpp +++ b/src/eepp/gaming/mapeditor/cuimap.hpp @@ -15,6 +15,7 @@ class EE_API cUIMap : public cUIComplexControl { public: typedef cb::Callback1 LightSelectCb; typedef cb::Callback1 LightRadiusChangeCb; + typedef cb::Callback2 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 ); }; }}}