From 9f92ca789e5152c64e4217e8f0e95c11fd710568 Mon Sep 17 00:00:00 2001 From: "spartanj@gmail.com" Date: Wed, 27 Jul 2011 04:15:08 -0300 Subject: [PATCH] Added flags ( lights, clipping, etc ) selection for the map creation. Added base color map color changer. Added a way to enable/disable lights in layers. Added save/load of the map lights ( this changed the map format a little ). Some fixes to the lighting system. And some minor changes. --- src/gaming/cgameobjectshape.cpp | 3 - src/gaming/cgameobjectshape.hpp | 2 - src/gaming/cgameobjectsprite.cpp | 3 - src/gaming/cgameobjectsprite.hpp | 2 - src/gaming/cgameobjectvirtual.cpp | 48 ++++++++++- src/gaming/cgameobjectvirtual.hpp | 2 - src/gaming/clayer.cpp | 4 +- src/gaming/clightmanager.cpp | 34 ++++++-- src/gaming/clightmanager.hpp | 12 ++- src/gaming/cmap.cpp | 77 +++++++++++++++-- src/gaming/cmap.hpp | 8 ++ src/gaming/ctilelayer.cpp | 10 +++ src/gaming/ctilelayer.hpp | 2 + src/gaming/mapeditor/cmapeditor.cpp | 26 ++++-- src/gaming/mapeditor/cmapeditor.hpp | 5 +- src/gaming/mapeditor/cmapproperties.cpp | 93 +++++++++++++++++++- src/gaming/mapeditor/cmapproperties.hpp | 14 +++ src/gaming/mapeditor/cuimapnew.cpp | 110 ++++++++++++++++++++++-- src/gaming/mapeditor/cuimapnew.hpp | 18 ++++ src/gaming/maphelper.hpp | 14 ++- 20 files changed, 430 insertions(+), 57 deletions(-) diff --git a/src/gaming/cgameobjectshape.cpp b/src/gaming/cgameobjectshape.cpp index a49f19cc7..b0b2c3901 100644 --- a/src/gaming/cgameobjectshape.cpp +++ b/src/gaming/cgameobjectshape.cpp @@ -68,9 +68,6 @@ void cGameObjectShape::Draw() { } } -void cGameObjectShape::Update() { -} - eeVector2f cGameObjectShape::Pos() const { return mPos; } diff --git a/src/gaming/cgameobjectshape.hpp b/src/gaming/cgameobjectshape.hpp index 7453aa2a7..4700536e4 100644 --- a/src/gaming/cgameobjectshape.hpp +++ b/src/gaming/cgameobjectshape.hpp @@ -17,8 +17,6 @@ class EE_API cGameObjectShape : public cGameObject { virtual void Draw(); - virtual void Update(); - virtual eeVector2f Pos() const; virtual eeSize Size(); diff --git a/src/gaming/cgameobjectsprite.cpp b/src/gaming/cgameobjectsprite.cpp index f2aefc7bf..51f8fb293 100644 --- a/src/gaming/cgameobjectsprite.cpp +++ b/src/gaming/cgameobjectsprite.cpp @@ -59,9 +59,6 @@ void cGameObjectSprite::Draw() { } } -void cGameObjectSprite::Update() { -} - eeVector2f cGameObjectSprite::Pos() const { if ( NULL != mSprite ) return mSprite->Position(); diff --git a/src/gaming/cgameobjectsprite.hpp b/src/gaming/cgameobjectsprite.hpp index d24864d3a..b769464e2 100644 --- a/src/gaming/cgameobjectsprite.hpp +++ b/src/gaming/cgameobjectsprite.hpp @@ -17,8 +17,6 @@ class EE_API cGameObjectSprite : public cGameObject { virtual void Draw(); - virtual void Update(); - eeVector2f Pos() const; virtual void Pos( eeVector2f pos ); diff --git a/src/gaming/cgameobjectvirtual.cpp b/src/gaming/cgameobjectvirtual.cpp index f447ffb33..5265929e4 100644 --- a/src/gaming/cgameobjectvirtual.cpp +++ b/src/gaming/cgameobjectvirtual.cpp @@ -2,6 +2,7 @@ #include "cmap.hpp" #include "clayer.hpp" +#include "ctilelayer.hpp" #include "../graphics/cprimitives.hpp" using namespace EE::Graphics; @@ -52,7 +53,49 @@ eeSize cGameObjectVirtual::Size() { void cGameObjectVirtual::Draw() { if ( NULL != mShape ) { - mShape->Draw( mPos.x, mPos.y, eeColorA(), 0.f, 1.f, ALPHA_NORMAL, RenderTypeFromFlags() ); + if ( mLayer->Map()->LightsEnabled() && mLayer->LightsEnabled() ) { + cLightManager * LM = mLayer->Map()->GetLightManager(); + + if ( MAP_LAYER_TILED == mLayer->Type() ) { + eeVector2i Tile = reinterpret_cast ( mLayer )->GetCurrentTile(); + + if ( LM->IsByVertex() ) { + mShape->Draw( + mPos.x, + mPos.y, + 0.f, + 1.f, + *LM->GetTileColor( Tile, 0 ), + *LM->GetTileColor( Tile, 1 ), + *LM->GetTileColor( Tile, 2 ), + *LM->GetTileColor( Tile, 3 ), + ALPHA_NORMAL, + RenderTypeFromFlags() + ); + } else { + mShape->Draw( mPos.x, mPos.y, *LM->GetTileColor( Tile ), 0.f, 1.f, ALPHA_NORMAL, RenderTypeFromFlags() ); + } + } else { + if ( LM->IsByVertex() ) { + mShape->Draw( + mPos.x, + mPos.y, + 0.f, + 1.f, + LM->GetColorFromPos( eeVector2f( mPos.x, mPos.y ) ), + LM->GetColorFromPos( eeVector2f( mPos.x, mPos.y + mShape->DestHeight() ) ), + LM->GetColorFromPos( eeVector2f( mPos.x + mShape->DestWidth(), mPos.y + mShape->DestHeight() ) ), + LM->GetColorFromPos( eeVector2f( mPos.x + mShape->DestWidth(), mPos.y ) ), + ALPHA_NORMAL, + RenderTypeFromFlags() + ); + } else { + mShape->Draw( mPos.x, mPos.y, LM->GetColorFromPos( eeVector2f( mPos.x, mPos.y ) ), 0.f, 1.f, ALPHA_NORMAL, RenderTypeFromFlags() ); + } + } + } else { + mShape->Draw( mPos.x, mPos.y, eeColorA(), 0.f, 1.f, ALPHA_NORMAL, RenderTypeFromFlags() ); + } } else { cPrimitives P; @@ -70,9 +113,6 @@ void cGameObjectVirtual::Draw() { } } -void cGameObjectVirtual::Update() { -} - eeVector2f cGameObjectVirtual::Pos() const { return mPos; } diff --git a/src/gaming/cgameobjectvirtual.hpp b/src/gaming/cgameobjectvirtual.hpp index 2fe24cc9a..a0877d93a 100644 --- a/src/gaming/cgameobjectvirtual.hpp +++ b/src/gaming/cgameobjectvirtual.hpp @@ -20,8 +20,6 @@ class EE_API cGameObjectVirtual : public cGameObject { virtual void Draw(); - virtual void Update(); - virtual eeVector2f Pos() const; virtual eeSize Size(); diff --git a/src/gaming/clayer.cpp b/src/gaming/clayer.cpp index 71a44d98f..02334433e 100644 --- a/src/gaming/clayer.cpp +++ b/src/gaming/clayer.cpp @@ -90,11 +90,11 @@ bool cLayer::Visible() { } bool cLayer::LightsEnabled() { - return FlagGet( LAYER_FLAG_LIGHTS_ENABLED ); + return 0 != FlagGet( LAYER_FLAG_LIGHTS_ENABLED ); } void cLayer::LightsEnabled( const bool& enabled ) { - enabled ? FlagSet( MAP_FLAG_LIGHTS_ENABLED ) : FlagClear( MAP_FLAG_LIGHTS_ENABLED ); + enabled ? FlagSet( LAYER_FLAG_LIGHTS_ENABLED ) : FlagClear( LAYER_FLAG_LIGHTS_ENABLED ); } }} diff --git a/src/gaming/clightmanager.cpp b/src/gaming/clightmanager.cpp index 0fa5b7891..d47e7ec18 100644 --- a/src/gaming/clightmanager.cpp +++ b/src/gaming/clightmanager.cpp @@ -46,10 +46,10 @@ void cLightManager::UpdateByVertex() { if ( !mLights.size() ) return; - for ( std::list::iterator it = mLights.begin(); it != mLights.end(); it++ ) { + for ( LightsList::iterator it = mLights.begin(); it != mLights.end(); it++ ) { cLight * Light = (*it); - if ( Intersect( VisibleArea, Light->GetAABB() ) ) { + if ( firstLight || Intersect( VisibleArea, Light->GetAABB() ) ) { for ( Int32 x = start.x; x < end.x; x++ ) { for ( Int32 y = start.y; y < end.y; y++ ) { if ( firstLight ) { @@ -90,10 +90,10 @@ void cLightManager::UpdateByTile() { if ( !mLights.size() ) return; - for ( std::list::iterator it = mLights.begin(); it != mLights.end(); it++ ) { + for ( LightsList::iterator it = mLights.begin(); it != mLights.end(); it++ ) { cLight * Light = (*it); - if ( Intersect( VisibleArea, Light->GetAABB() ) ) { + if ( firstLight || Intersect( VisibleArea, Light->GetAABB() ) ) { for ( Int32 x = start.x; x < end.x; x++ ) { for ( Int32 y = start.y; y < end.y; y++ ) { if ( firstLight ) { @@ -124,7 +124,7 @@ eeColorA cLightManager::GetColorFromPos( const eeVector2f& Pos ) { if ( !mLights.size() ) return Col; - for ( std::list::iterator it = mLights.begin(); it != mLights.end(); it++ ) { + for ( LightsList::iterator it = mLights.begin(); it != mLights.end(); it++ ) { cLight * Light = (*it); if ( Contains( Light->GetAABB(), Pos ) ) { @@ -140,7 +140,7 @@ void cLightManager::AddLight( cLight * Light ) { } void cLightManager::RemoveLight( const eeVector2f& OverPos ) { - for ( std::list::reverse_iterator it = mLights.rbegin(); it != mLights.rend(); it++ ) { + for ( LightsList::reverse_iterator it = mLights.rbegin(); it != mLights.rend(); it++ ) { cLight * Light = (*it); if ( Contains( Light->GetAABB(), OverPos ) ) { @@ -151,13 +151,21 @@ void cLightManager::RemoveLight( const eeVector2f& OverPos ) { } } -eeColorA * cLightManager::GetTileColor( const eeVector2i& TilePos ) { +const eeColorA * cLightManager::GetTileColor( const eeVector2i& TilePos ) { eeASSERT( 1 == mNumVertex ); + + if ( !mLights.size() ) + return &mMap->BaseColor(); + return mTileColors[ TilePos.x ][ TilePos.y ][0]; } -eeColorA * cLightManager::GetTileColor( const eeVector2i& TilePos, const Uint32& Vertex ) { +const eeColorA * cLightManager::GetTileColor( const eeVector2i& TilePos, const Uint32& Vertex ) { eeASSERT( 4 == mNumVertex ); + + if ( !mLights.size() ) + return &mMap->BaseColor(); + return mTileColors[ TilePos.x ][ TilePos.y ][Vertex]; } @@ -197,10 +205,18 @@ void cLightManager::DeallocateColors() { } void cLightManager::DestroyLights() { - for ( std::list::iterator it = mLights.begin(); it != mLights.end(); it++ ) { + for ( LightsList::iterator it = mLights.begin(); it != mLights.end(); it++ ) { cLight * Light = (*it); eeSAFE_DELETE( Light ); } } +Uint32 cLightManager::Count() { + return (Uint32)mLights.size(); +} + +cLightManager::LightsList& cLightManager::GetLights() { + return mLights; +} + }} diff --git a/src/gaming/clightmanager.hpp b/src/gaming/clightmanager.hpp index a683b6d4a..681911564 100644 --- a/src/gaming/clightmanager.hpp +++ b/src/gaming/clightmanager.hpp @@ -10,6 +10,8 @@ class cMap; class cLightManager { public: + typedef std::list LightsList; + cLightManager( cMap * Map, bool ByVertex ); virtual ~cLightManager(); @@ -20,18 +22,22 @@ class cLightManager { void RemoveLight( const eeVector2f& OverPos ); - eeColorA * GetTileColor( const eeVector2i& TilePos ); + Uint32 Count(); - eeColorA * GetTileColor( const eeVector2i& TilePos, const Uint32& Vertex ); + const eeColorA * GetTileColor( const eeVector2i& TilePos ); + + const eeColorA * GetTileColor( const eeVector2i& TilePos, const Uint32& Vertex ); eeColorA GetColorFromPos( const eeVector2f& Pos ); const bool& IsByVertex() const; + + LightsList& GetLights(); protected: cMap * mMap; Int32 mNumVertex; eeColorA**** mTileColors; - std::list mLights; + LightsList mLights; bool mIsByVertex; void AllocateColors(); diff --git a/src/gaming/cmap.cpp b/src/gaming/cmap.cpp index 02e9ede37..49a28646f 100644 --- a/src/gaming/cmap.cpp +++ b/src/gaming/cmap.cpp @@ -23,7 +23,7 @@ cMap::cMap() : mMaxLayers( 0 ), mLayerCount( 0 ), mViewSize( 800, 600 ), - mBaseColor( 255, 255, 255, 255 ), + mBaseColor( 150, 150, 150, 255 ), mTileTex( NULL ), mLightManager( NULL ) { @@ -42,7 +42,7 @@ void cMap::Reset() { mFlags = 0; mMaxLayers = 0; mViewSize = eeSize( 800, 600 ); - mBaseColor = eeColorA( 255, 255, 255, 255 ); + mBaseColor = eeColorA( 150, 150, 150, 255 ); } void cMap::DeleteLayers() { @@ -72,7 +72,7 @@ void cMap::Create( eeSize Size, Uint32 MaxLayers, eeSize TileSize, Uint32 Flags, mLayers = eeNewArray( cLayer*, mMaxLayers ); if ( LightsEnabled() ) - mLightManager = eeNew( cLightManager, ( this, ( mFlags & MAP_FLAG_LIGHTS_BYVERTEX ) ? true : false ) ); + CreateLightManager(); for ( Uint32 i = 0; i < mMaxLayers; i++ ) mLayers[i] = NULL; @@ -82,6 +82,11 @@ void cMap::Create( eeSize Size, Uint32 MaxLayers, eeSize TileSize, Uint32 Flags, CreateEmptyTile(); } +void cMap::CreateLightManager() { + eeSAFE_DELETE( mLightManager ); + mLightManager = eeNew( cLightManager, ( this, ( mFlags & MAP_FLAG_LIGHTS_BYVERTEX ) ? true : false ) ); +} + void cMap::CreateEmptyTile() { //! I create a texture representing an empty tile to render instead of rendering with primitives because is a lot faster, at least with NVIDIA GPUs. cTextureFactory * TF = cTextureFactory::instance(); @@ -271,7 +276,7 @@ void cMap::GetMouseOverTile() { } void cMap::UpdateScreenAABB() { - mScreenAABB = eeAABB( mOffset.x, mOffset.y, mOffset.x + mViewSize.Width(), mOffset.y + mViewSize.Height() ); + mScreenAABB = eeAABB( -mOffset.x, -mOffset.y, -mOffset.x + mViewSize.Width(), -mOffset.y + mViewSize.Height() ); } const eeAABB& cMap::GetViewAreaAABB() const { @@ -336,6 +341,14 @@ const eeVector2i& cMap::EndTile() const { return mEndTile; } +void cMap::ExtraTiles( const eeVector2i& extra ) { + mExtraTiles = extra; +} + +const eeVector2i& cMap::ExtraTiles() const { + return mExtraTiles; +} + void cMap::Offset( const eeVector2f& offset ) { mOffset = offset; @@ -349,10 +362,10 @@ void cMap::CalcTilesClip() { eeVector2f ffoff( FixOffset() ); eeVector2i foff( (Int32)ffoff.x, (Int32)ffoff.y ); - mStartTile.x = -foff.x / mTileSize.x; - mStartTile.y = -foff.y / mTileSize.y; - mEndTile.x = mStartTile.x + eeRound( (eeFloat)mViewSize.x / (eeFloat)mTileSize.x ) + 1; - mEndTile.y = mStartTile.y + eeRound( (eeFloat)mViewSize.y / (eeFloat)mTileSize.y ) + 1; + mStartTile.x = -foff.x / mTileSize.x - mExtraTiles.x; + mStartTile.y = -foff.y / mTileSize.y - mExtraTiles.y; + mEndTile.x = mStartTile.x + eeRound( (eeFloat)mViewSize.x / (eeFloat)mTileSize.x ) + 1 + mExtraTiles.x; + mEndTile.y = mStartTile.y + eeRound( (eeFloat)mViewSize.y / (eeFloat)mTileSize.y ) + 1 + mExtraTiles.y; if ( mStartTile.x < 0 ) mStartTile.x = 0; @@ -422,7 +435,7 @@ Uint32 cMap::ClipedArea() const { } Uint32 cMap::ClampBorders() const { - return mFlags & MAP_FLAG_CLAMP_BODERS; + return mFlags & MAP_FLAG_CLAMP_BORDERS; } Uint32 cMap::DrawTileOver() const { @@ -632,6 +645,8 @@ bool cMap::LoadFromStream( cIOStream& IOS ) { if ( MapHdr.Magic == ( ( 'E' << 0 ) | ( 'E' << 8 ) | ( 'M' << 16 ) | ( 'P' << 24 ) ) ) { Create( eeSize( MapHdr.SizeX, MapHdr.SizeY ), MapHdr.MaxLayers, eeSize( MapHdr.TileSizeX, MapHdr.TileSizeY ), MapHdr.Flags ); + BaseColor( eeColorA( MapHdr.BaseColor ) ); + //! Load Properties if ( MapHdr.PropertyCount ) { sPropertyHdr tProp[ MapHdr.PropertyCount ]; @@ -766,6 +781,26 @@ bool cMap::LoadFromStream( cIOStream& IOS ) { } } } + + if ( MapHdr.LightsCount ) { + CreateLightManager(); + + sMapLightHdr tLighsHdr[ MapHdr.LightsCount ]; + sMapLightHdr * tLightHdr; + + 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 ) ) + ); + } + } } return true; @@ -827,6 +862,12 @@ void cMap::SaveToStream( cIOStream& IOS ) { MapHdr.PropertyCount = mProperties.size(); MapHdr.ShapeGroupCount = ShapeGroups.size(); MapHdr.VirtualObjectTypesCount = mObjTypes.size(); //! This is only usefull for the Map Editor, to auto add on the load the virtual object types that where used to create the map. + MapHdr.BaseColor = mBaseColor.GetUint32(); + + if ( LightsEnabled() && NULL != mLightManager ) + MapHdr.LightsCount = mLightManager->Count(); + else + MapHdr.LightsCount = 0; if ( IOS.IsOpen() ) { //! Writes the map header @@ -1021,6 +1062,24 @@ void cMap::SaveToStream( cIOStream& IOS ) { } } } + + if ( MapHdr.LightsCount && NULL != mLightManager ) { + cLightManager::LightsList& Lights = mLightManager->GetLights(); + + for ( cLightManager::LightsList::iterator LightsIt = Lights.begin(); LightsIt != Lights.end(); LightsIt++ ) { + cLight * Light = (*LightsIt); + + sMapLightHdr tLightHdr; + + tLightHdr.Radius = Light->Radius(); + tLightHdr.PosX = (Int32)Light->Position().x; + tLightHdr.PosY = (Int32)Light->Position().y; + tLightHdr.Color = eeColorA( Light->Color() ).GetUint32(); + tLightHdr.Type = Light->Type(); + + IOS.Write( (const char*)&tLightHdr, sizeof(sMapLightHdr) ); + } + } } } diff --git a/src/gaming/cmap.hpp b/src/gaming/cmap.hpp index 92c25b8e9..b0fef1337 100644 --- a/src/gaming/cmap.hpp +++ b/src/gaming/cmap.hpp @@ -150,6 +150,11 @@ class EE_API cMap { const eeAABB& GetViewAreaAABB() const; cLightManager * GetLightManager() const; + + /** Tiles to add or subtract from the real values of StartTile and EndTile ( so it will loop over more/less tiles than the required to render every tile on screen ). */ + void ExtraTiles( const eeVector2i& extra ); + + const eeVector2i& ExtraTiles() const; protected: Window::cWindow * mWindow; cLayer** mLayers; @@ -164,6 +169,7 @@ class EE_API cMap { eeVector2i mScreenPos; eeVector2i mStartTile; eeVector2i mEndTile; + eeVector2i mExtraTiles; eeVector2i mMouseOverTile; eeVector2i mMouseOverTileFinal; eeVector2i mMouseMapPos; @@ -198,6 +204,8 @@ class EE_API cMap { void CreateEmptyTile(); void UpdateScreenAABB(); + + void CreateLightManager(); }; }} diff --git a/src/gaming/ctilelayer.cpp b/src/gaming/ctilelayer.cpp index c068a866b..970c5138e 100644 --- a/src/gaming/ctilelayer.cpp +++ b/src/gaming/ctilelayer.cpp @@ -102,6 +102,16 @@ void cTileLayer::RemoveGameObject( const eeVector2i& TilePos ) { } } +void cTileLayer::MoveTileObject( const eeVector2i& FromPos, const eeVector2i& ToPos ) { + RemoveGameObject( ToPos ); + + cGameObject * tObj = mTiles[ FromPos.x ][ FromPos.y ]; + + mTiles[ FromPos.x ][ FromPos.y ] = NULL; + + mTiles[ ToPos.x ][ ToPos.y ] = tObj; +} + cGameObject * cTileLayer::GetGameObject( const eeVector2i& TilePos ) { return mTiles[ TilePos.x ][ TilePos.y ]; } diff --git a/src/gaming/ctilelayer.hpp b/src/gaming/ctilelayer.hpp index 9bc3cc268..f169972f2 100644 --- a/src/gaming/ctilelayer.hpp +++ b/src/gaming/ctilelayer.hpp @@ -18,6 +18,8 @@ class EE_API cTileLayer : public cLayer { virtual void RemoveGameObject( const eeVector2i& TilePos ); + virtual void MoveTileObject( const eeVector2i& FromPos, const eeVector2i& ToPos ); + virtual cGameObject * GetGameObject( const eeVector2i& TilePos ); const eeVector2i& GetCurrentTile() const; diff --git a/src/gaming/mapeditor/cmapeditor.cpp b/src/gaming/mapeditor/cmapeditor.cpp index 624ec7d04..29326fbbe 100644 --- a/src/gaming/mapeditor/cmapeditor.cpp +++ b/src/gaming/mapeditor/cmapeditor.cpp @@ -116,8 +116,14 @@ void cMapEditor::CreateWinMenu() { PU5->AddSeparator(); PU5->Add( "Layer Properties..." ); PU5->AddSeparator(); - Uint32 LayerChkBoxIndex = PU5->AddCheckBox( "Visible" ); - mLayerCheckbox = reinterpret_cast ( PU5->GetItem( LayerChkBoxIndex ) ); + + Uint32 LayerChkBoxIndex = PU5->AddCheckBox( "Lights Enabled" ); + mLayerChkLights = reinterpret_cast ( PU5->GetItem( LayerChkBoxIndex ) ); + + PU5->AddSeparator(); + + LayerChkBoxIndex = PU5->AddCheckBox( "Visible" ); + mLayerChkVisible = reinterpret_cast ( PU5->GetItem( LayerChkBoxIndex ) ); PU5->AddEventListener( cUIEvent::EventOnItemClicked, cb::Make1( this, &cMapEditor::LayerMenuClick ) ); WinMenu->AddMenuButton( "Layer", PU5 ); @@ -405,6 +411,10 @@ void cMapEditor::CreateNewMap() { eeNew( cUIMapNew, ( mUIMap, cb::Make0( this, &cMapEditor::MapCreated ) ) ); } +void cMapEditor::CreateNewEmptyMap() { + mUIMap->Map()->Create( eeSize( 100, 100 ), 16, eeSize( 32, 32 ), MAP_EDITOR_DEFAULT_FLAGS | MAP_FLAG_LIGHTS_ENABLED, mUIMap->Size() ); +} + void cMapEditor::MapCreated() { mCurLayer = NULL; mLayerList->ListBox()->Clear(); @@ -424,7 +434,7 @@ void cMapEditor::CreateUIMap() { mUIMap = eeNew( cUIMap, ( Params ) ); mUIMap->Visible( true ); mUIMap->Enabled( true ); - mUIMap->Map()->Create( eeSize( 100, 100 ), 16, eeSize( 32, 32 ), MAP_EDITOR_DEFAULT_FLAGS, Params.Size ); + CreateNewEmptyMap(); mUIMap->AddEventListener( cUIEvent::EventOnSizeChange, cb::Make1( this, &cMapEditor::OnMapSizeChange ) ); mUIMap->AddEventListener( cUIEvent::EventMouseDown, cb::Make1( this, &cMapEditor::OnMapMouseDown ) ); mUIMap->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cMapEditor::OnMapMouseClick ) ); @@ -529,7 +539,7 @@ void cMapEditor::FileMenuClick( const cUIEvent * Event ) { } void cMapEditor::OnMapClose( const cUIEvent * Event ) { - mUIMap->Map()->Create( eeSize( 100, 100 ), 16, eeSize( 32, 32 ), MAP_EDITOR_DEFAULT_FLAGS, mUIMap->Size() ); + CreateNewEmptyMap(); MapCreated(); @@ -598,6 +608,10 @@ void cMapEditor::LayerMenuClick( const cUIEvent * Event ) { MsgBox->Center(); MsgBox->Show(); } + } else if ( "Lights Enabled" == txt ) { + if ( NULL != mCurLayer ) { + mCurLayer->LightsEnabled( !mCurLayer->LightsEnabled() ); + } } else if ( "Visible" == txt ) { if ( NULL != mCurLayer ) { mCurLayer->Visible( !mCurLayer->Visible() ); @@ -684,7 +698,9 @@ void cMapEditor::OnLayerSelect( const cUIEvent * Event ) { if ( NULL != tLayer ) { mCurLayer = tLayer; - mLayerCheckbox->Active( mCurLayer->Visible() ); + mLayerChkVisible->Active( mCurLayer->Visible() ); + + mLayerChkLights->Active( mCurLayer->LightsEnabled() ); } } diff --git a/src/gaming/mapeditor/cmapeditor.hpp b/src/gaming/mapeditor/cmapeditor.hpp index 734eadca9..32f56bf04 100644 --- a/src/gaming/mapeditor/cmapeditor.hpp +++ b/src/gaming/mapeditor/cmapeditor.hpp @@ -47,7 +47,8 @@ class EE_API cMapEditor { cUIComplexControl * mDICont; cUICheckBox * mChkDI; cUITextInput * mDataIdInput; - cUIMenuCheckBox * mLayerCheckbox; + cUIMenuCheckBox * mLayerChkVisible; + cUIMenuCheckBox * mLayerChkLights; void WindowClose( const cUIEvent * Event ); @@ -138,6 +139,8 @@ class EE_API cMapEditor { void RemoveLayer(); void RefreshLayersList(); + + void CreateNewEmptyMap(); }; }}} diff --git a/src/gaming/mapeditor/cmapproperties.cpp b/src/gaming/mapeditor/cmapproperties.cpp index ac1794ead..de6871852 100644 --- a/src/gaming/mapeditor/cmapproperties.cpp +++ b/src/gaming/mapeditor/cmapproperties.cpp @@ -22,9 +22,60 @@ cMapProperties::cMapProperties( cMap * Map ) : mUIWindow->AddEventListener( cUIEvent::EventOnWindowClose, cb::Make1( this, &cMapProperties::WindowClose ) ); mUIWindow->Title( "Map Properties" ); + + Uint32 DiffIfLights = 0; + + if ( mMap->LightsEnabled() ) { + DiffIfLights = 100; + + cUITextBox * Txt = mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( 50, 16 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Map Base Color:" ); + + cUIComplexControl::CreateParams ComParams; + ComParams.Parent( mUIWindow->Container() ); + ComParams.PosSet( Txt->Pos().x, Txt->Pos().y + Txt->Size().Height() + 4 ); + ComParams.SizeSet( 64, 64 ); + ComParams.Background.Color( eeColorA( 255, 255, 255, 255 ) ); + ComParams.Border.Color( eeColorA( 100, 100, 100, 200 ) ); + ComParams.Flags |= UI_FILL_BACKGROUND | UI_BORDER; + mUIBaseColor = eeNew( cUIComplexControl, ( ComParams ) ); + mUIBaseColor->Visible( true ); + mUIBaseColor->Enabled( true ); + + Txt = mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIBaseColor->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Red Color:" ); + mUIRedSlider = mUITheme->CreateSlider( mUIWindow->Container(), eeSize( 255, 20 ), eeVector2i( Txt->Pos().x + Txt->Size().Width() + 16, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUIRedSlider->MaxValue( 255 ); + mUIRedSlider->Value( mMap->BaseColor().R() ); + mUIRedSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapProperties::OnRedChange ) ); + + mUIRedTxt = mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIRedSlider->Pos().x + mUIRedSlider->Size().Width() + 4, mUIRedSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIRedTxt->Text( toStr( (Uint32)mMap->BaseColor().R() ) ); + + Txt = mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIRedSlider->Pos().y + mUIRedSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Green Color:" ); + mUIGreenSlider = mUITheme->CreateSlider( mUIWindow->Container(), eeSize( 255, 20 ), eeVector2i( mUIRedSlider->Pos().x, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUIGreenSlider->MaxValue( 255 ); + mUIGreenSlider->Value( mMap->BaseColor().G() ); + mUIGreenSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapProperties::OnGreenChange ) ); + + mUIGreenTxt = mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIGreenSlider->Pos().x + mUIGreenSlider->Size().Width() + 4, mUIGreenSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIGreenTxt->Text( toStr( (Uint32)mMap->BaseColor().G() ) ); + + Txt = mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIGreenSlider->Pos().y + mUIGreenSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Blue Color:" ); + mUIBlueSlider = mUITheme->CreateSlider( mUIWindow->Container(), eeSize( 255, 20 ), eeVector2i( mUIRedSlider->Pos().x, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUIBlueSlider->MaxValue( 255 ); + mUIBlueSlider->Value( mMap->BaseColor().B() ); + mUIBlueSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cMapProperties::OnBlueChange ) ); + + mUIBlueTxt = mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIBlueSlider->Pos().x + mUIBlueSlider->Size().Width() + 4, mUIBlueSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIBlueTxt->Text( toStr( (Uint32)mMap->BaseColor().B() ) ); + } + Uint32 TxtBoxFlags = UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_HALIGN_CENTER | UI_VALIGN_CENTER; - mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(192, 24), eeVector2i(50,10), TxtBoxFlags )->Text( "Property Name" ); - mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(192, 24), eeVector2i(50+192,10), TxtBoxFlags )->Text( "Property Value" ); + cUITextBox * TxtBox = mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(192, 24), eeVector2i( 50, 10 + DiffIfLights ), TxtBoxFlags ); TxtBox->Text( "Property Name" ); + mUITheme->CreateTextBox( mUIWindow->Container(), eeSize(192, 24), eeVector2i(50+192, TxtBox->Pos().y ), TxtBoxFlags )->Text( "Property Value" ); cUIPushButton * OKButton = mUITheme->CreatePushButton( mUIWindow->Container(), eeSize( 80, 22 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mUITheme->GetIconByName( "ok" ) ); OKButton->Pos( mUIWindow->Container()->Size().Width() - OKButton->Size().Width() - 4, mUIWindow->Container()->Size().Height() - OKButton->Size().Height() - 4 ); @@ -38,8 +89,8 @@ cMapProperties::cMapProperties( cMap * Map ) : cUIGenericGrid::CreateParams GridParams; GridParams.Parent( mUIWindow->Container() ); - GridParams.PosSet( 50, 30 ); - GridParams.SizeSet( 400, 400 ); + GridParams.PosSet( 50, TxtBox->Pos().y + 20 ); + GridParams.SizeSet( 400, 400 - DiffIfLights ); GridParams.Flags = UI_AUTO_PADDING; GridParams.RowHeight = 24; GridParams.CollumnsCount = 5; @@ -77,6 +128,40 @@ cMapProperties::cMapProperties( cMap * Map ) : cMapProperties::~cMapProperties() { } +void cMapProperties::OnRedChange( const cUIEvent * Event ) { + eeColorA Col = mUIBaseColor->Background()->Color(); + Col.Red = (Uint8)mUIRedSlider->Value(); + mUIBaseColor->Background()->Color( Col ); + mUIRedTxt->Text( toStr( (Int32)mUIRedSlider->Value() ) ); + + eeColorA MapCol = mMap->BaseColor(); + MapCol.Red = Col.Red; + mMap->BaseColor( MapCol ); +} + +void cMapProperties::OnGreenChange( const cUIEvent * Event ) { + eeColorA Col = mUIBaseColor->Background()->Color(); + Col.Green = (Uint8)mUIGreenSlider->Value(); + mUIBaseColor->Background()->Color( Col ); + mUIGreenTxt->Text( toStr( (Uint32)mUIGreenSlider->Value() ) ); + + eeColorA MapCol = mMap->BaseColor(); + MapCol.Green = Col.Green; + mMap->BaseColor( MapCol ); +} + +void cMapProperties::OnBlueChange( const cUIEvent * Event ) { + eeColorA Col = mUIBaseColor->Background()->Color(); + Col.Blue = (Uint8)mUIBlueSlider->Value(); + mUIBaseColor->Background()->Color( Col ); + mUIBlueTxt->Text( toStr( (Uint32)mUIBlueSlider->Value() ) ); + + eeColorA MapCol = mMap->BaseColor(); + MapCol.Blue = Col.Blue; + mMap->BaseColor( MapCol ); +} + + void cMapProperties::SaveProperties() { mMap->ClearProperties(); diff --git a/src/gaming/mapeditor/cmapproperties.hpp b/src/gaming/mapeditor/cmapproperties.hpp index 486c435ca..dd216b5bb 100644 --- a/src/gaming/mapeditor/cmapproperties.hpp +++ b/src/gaming/mapeditor/cmapproperties.hpp @@ -6,6 +6,7 @@ #include "../../ui/cuiwindow.hpp" #include "../../ui/cuigenericgrid.hpp" #include "../../ui/cuitextinput.hpp" +#include "../../ui/cuislider.hpp" using namespace EE::UI; @@ -22,6 +23,13 @@ class cMapProperties { cUIWindow * mUIWindow; cUIGenericGrid * mGenGrid; cMap * mMap; + cUIComplexControl * mUIBaseColor; + cUISlider * mUIRedSlider; + cUISlider * mUIGreenSlider; + cUISlider * mUIBlueSlider; + cUITextBox * mUIRedTxt; + cUITextBox * mUIGreenTxt; + cUITextBox * mUIBlueTxt; void WindowClose( const cUIEvent * Event ); @@ -33,6 +41,12 @@ class cMapProperties { void RemoveCellClick( const cUIEvent * Event ); + void OnRedChange( const cUIEvent * Event ); + + void OnGreenChange( const cUIEvent * Event ); + + void OnBlueChange( const cUIEvent * Event ); + void CreateGridElems(); void SaveProperties(); diff --git a/src/gaming/mapeditor/cuimapnew.cpp b/src/gaming/mapeditor/cuimapnew.cpp index 47f5aebf0..cd883f002 100644 --- a/src/gaming/mapeditor/cuimapnew.cpp +++ b/src/gaming/mapeditor/cuimapnew.cpp @@ -1,5 +1,7 @@ #include "cuimapnew.hpp" #include "../../ui/cuispinbox.hpp" +#include "../../ui/cuicheckbox.hpp" +#include "../../ui/cuislider.hpp" namespace EE { namespace Gaming { namespace MapEditor { @@ -14,7 +16,7 @@ cUIMapNew::cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb ) : if ( NULL == mTheme ) return; - mUIWindow = mTheme->CreateWindow( NULL, eeSize( 278, 214 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ); + mUIWindow = mTheme->CreateWindow( NULL, eeSize( 320, 360 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED, UI_WIN_DEFAULT_FLAGS | UI_WIN_MODAL ); mUIWindow->AddEventListener( cUIEvent::EventOnWindowClose, cb::Make1( this, &cUIMapNew::WindowClose ) ); mUIWindow->Title( "New Map" ); @@ -22,7 +24,7 @@ cUIMapNew::cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb ) : Int32 DistFromTitle = 18; cUITextBox * Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( 16, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); - Txt->Text( "Map size" ); + Txt->Text( "Map Size" ); Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize( 46, 24 ), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW ); Txt->Text( "Width:" ); @@ -37,7 +39,7 @@ cUIMapNew::cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb ) : mUIMapHeight->MinValue(1); Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIWindow->Container()->Size().Width() / 2, InitialY ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); - Txt->Text( "Tile size" ); + Txt->Text( "Tile Size" ); Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize( 46, 24 ), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW ); Txt->Text( "Width:" ); @@ -51,11 +53,71 @@ cUIMapNew::cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb ) : mUIMapTHeight = mTheme->CreateSpinBox( mUIWindow->Container(), eeSize( 53, 24 ), eeVector2i( Txt->Pos().x + Txt->Size().Width(), Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS, 32, false ); mUIMapTHeight->MinValue(1); - Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( 16, mUIWindow->Container()->Size().Height() / 2 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); - Txt->Text( "Max layers" ); + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( 16, mUIMapTHeight->Pos().y + mUIMapTHeight->Size().Height() + 8 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Max Layers" ); mUIMapMaxLayers = mTheme->CreateSpinBox( mUIWindow->Container(), eeSize( 53, 24 ), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + DistFromTitle ), UI_CONTROL_DEFAULT_FLAGS, 8, false ); + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( Txt->Pos().x, mUIMapMaxLayers->Pos().y + mUIMapMaxLayers->Size().Height() + 8 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Map Flags:" ); + + mUILightsEnabled = mTheme->CreateCheckBox( mUIWindow->Container(), eeSize(), eeVector2i( Txt->Pos().x + DistFromTitle, Txt->Pos().y + Txt->Size().Height() + 16 ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUILightsEnabled->Text( "Lights Enabled" ); + + mUILightsByVertex = mTheme->CreateCheckBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIWindow->Container()->Size().Width() / 2, mUILightsEnabled->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUILightsByVertex->Text( "Lights By Vertex" ); + + mUIClampBorders = mTheme->CreateCheckBox( mUIWindow->Container(), eeSize(), eeVector2i( Txt->Pos().x + DistFromTitle, mUILightsEnabled->Pos().y + mUILightsEnabled->Size().Height() + 16 ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUIClampBorders->Text( "Clamp Boders" ); + mUIClampBorders->Active( true ); + + mUIClipArea = mTheme->CreateCheckBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIWindow->Container()->Size().Width() / 2, mUIClampBorders->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUIClipArea->Text( "Clip View Area" ); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( Txt->Pos().x, mUIClipArea->Pos().y + mUIClipArea->Size().Height() + 8 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Map Base Color:" ); + + cUIComplexControl::CreateParams ComParams; + ComParams.Parent( mUIWindow->Container() ); + ComParams.PosSet( Txt->Pos().x, Txt->Pos().y + Txt->Size().Height() + 4 ); + ComParams.SizeSet( 64, 64 ); + ComParams.Background.Color( eeColorA( 255, 255, 255, 255 ) ); + ComParams.Border.Color( eeColorA( 100, 100, 100, 200 ) ); + ComParams.Flags |= UI_FILL_BACKGROUND | UI_BORDER; + mUIBaseColor = eeNew( cUIComplexControl, ( ComParams ) ); + mUIBaseColor->Visible( true ); + mUIBaseColor->Enabled( true ); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIBaseColor->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Red Color:" ); + mUIRedSlider = mTheme->CreateSlider( mUIWindow->Container(), eeSize( 128, 20 ), eeVector2i( Txt->Pos().x + Txt->Size().Width() + 16, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUIRedSlider->MaxValue( 255 ); + mUIRedSlider->Value( 255 ); + mUIRedSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIMapNew::OnRedChange ) ); + + mUIRedTxt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIRedSlider->Pos().x + mUIRedSlider->Size().Width() + 4, mUIRedSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIRedTxt->Text( toStr( 255 ) ); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIRedSlider->Pos().y + mUIRedSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Green Color:" ); + mUIGreenSlider = mTheme->CreateSlider( mUIWindow->Container(), eeSize( 128, 20 ), eeVector2i( mUIRedSlider->Pos().x, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUIGreenSlider->MaxValue( 255 ); + mUIGreenSlider->Value( 255 ); + mUIGreenSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIMapNew::OnGreenChange ) ); + + mUIGreenTxt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIGreenSlider->Pos().x + mUIGreenSlider->Size().Width() + 4, mUIGreenSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIGreenTxt->Text( toStr( 255 ) ); + + Txt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIBaseColor->Pos().x + mUIBaseColor->Size().Width() + 4, mUIGreenSlider->Pos().y + mUIGreenSlider->Size().Height() + 4 ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + Txt->Text( "Blue Color:" ); + mUIBlueSlider = mTheme->CreateSlider( mUIWindow->Container(), eeSize( 128, 20 ), eeVector2i( mUIRedSlider->Pos().x, Txt->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_AUTO_SIZE ); + mUIBlueSlider->MaxValue( 255 ); + mUIBlueSlider->Value( 255 ); + mUIBlueSlider->AddEventListener( cUIEvent::EventOnValueChange, cb::Make1( this, &cUIMapNew::OnBlueChange ) ); + + mUIBlueTxt = mTheme->CreateTextBox( mUIWindow->Container(), eeSize(), eeVector2i( mUIBlueSlider->Pos().x + mUIBlueSlider->Size().Width() + 4, mUIBlueSlider->Pos().y ), UI_CONTROL_DEFAULT_FLAGS | UI_DRAW_SHADOW | UI_AUTO_SIZE ); + mUIBlueTxt->Text( toStr( 255 ) ); + cUIPushButton * OKButton = mTheme->CreatePushButton( mUIWindow->Container(), eeSize( 80, 22 ), eeVector2i(), UI_CONTROL_DEFAULT_FLAGS_CENTERED | UI_AUTO_SIZE, mTheme->GetIconByName( "ok" ) ); OKButton->Pos( mUIWindow->Container()->Size().Width() - OKButton->Size().Width() - 4, mUIWindow->Container()->Size().Height() - OKButton->Size().Height() - 4 ); OKButton->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cUIMapNew::OKClick ) ); @@ -72,6 +134,27 @@ cUIMapNew::cUIMapNew( cUIMap * Map, cb::Callback0 NewMapCb ) : cUIMapNew::~cUIMapNew() { } +void cUIMapNew::OnRedChange( const cUIEvent * Event ) { + eeColorA Col = mUIBaseColor->Background()->Color(); + Col.Red = (Uint8)mUIRedSlider->Value(); + mUIBaseColor->Background()->Color( Col ); + mUIRedTxt->Text( toStr( (Int32)mUIRedSlider->Value() ) ); +} + +void cUIMapNew::OnGreenChange( const cUIEvent * Event ) { + eeColorA Col = mUIBaseColor->Background()->Color(); + Col.Green = (Uint8)mUIGreenSlider->Value(); + mUIBaseColor->Background()->Color( Col ); + mUIGreenTxt->Text( toStr( (Uint32)mUIGreenSlider->Value() ) ); +} + +void cUIMapNew::OnBlueChange( const cUIEvent * Event ) { + eeColorA Col = mUIBaseColor->Background()->Color(); + Col.Blue = (Uint8)mUIBlueSlider->Value(); + mUIBaseColor->Background()->Color( Col ); + mUIBlueTxt->Text( toStr( (Uint32)mUIBlueSlider->Value() ) ); +} + void cUIMapNew::OKClick( const cUIEvent * Event ) { Int32 w = static_cast( mUIMapWidth->Value() ); Int32 h = static_cast( mUIMapHeight->Value() ); @@ -79,8 +162,23 @@ void cUIMapNew::OKClick( const cUIEvent * Event ) { Int32 th = static_cast( mUIMapTHeight->Value() ); Int32 ml = static_cast( mUIMapMaxLayers->Value() ); + Uint32 Flags = MAP_EDITOR_DEFAULT_FLAGS; + + if ( mUILightsEnabled->Active() ) + Flags |= MAP_FLAG_LIGHTS_ENABLED; + + if ( mUILightsByVertex->Active() ) + Flags |= MAP_FLAG_LIGHTS_BYVERTEX; + + if ( mUIClampBorders->Active() ) + Flags |= MAP_FLAG_CLAMP_BORDERS; + + if ( mUIClipArea->Active() ) + Flags |= MAP_FLAG_CLIP_AREA; + if ( w > 0 && h > 0 && tw > 0 && th > 0 && ml > 0 ) { - mUIMap->Map()->Create( eeSize( w, h ), ml, eeSize( tw, th ), MAP_EDITOR_DEFAULT_FLAGS, mUIMap->Map()->ViewSize() ); + mUIMap->Map()->Create( eeSize( w, h ), ml, eeSize( tw, th ), Flags, mUIMap->Map()->ViewSize() ); + mUIMap->Map()->BaseColor( mUIBaseColor->Background()->Color() ); if ( mNewMapCb.IsSet() ) mNewMapCb(); diff --git a/src/gaming/mapeditor/cuimapnew.hpp b/src/gaming/mapeditor/cuimapnew.hpp index 27fc70a16..d2fa6e27d 100644 --- a/src/gaming/mapeditor/cuimapnew.hpp +++ b/src/gaming/mapeditor/cuimapnew.hpp @@ -23,6 +23,18 @@ class cUIMapNew { cUISpinBox * mUIMapTWidth; cUISpinBox * mUIMapTHeight; cUISpinBox * mUIMapMaxLayers; + cUICheckBox * mUILightsEnabled; + cUICheckBox * mUILightsByVertex; + cUICheckBox * mUIClampBorders; + cUICheckBox * mUIClipArea; + cUIComplexControl * mUIBaseColor; + cUISlider * mUIRedSlider; + cUISlider * mUIGreenSlider; + cUISlider * mUIBlueSlider; + cUITextBox * mUIRedTxt; + cUITextBox * mUIGreenTxt; + cUITextBox * mUIBlueTxt; + cb::Callback0 mNewMapCb; void WindowClose( const cUIEvent * Event ); @@ -30,6 +42,12 @@ class cUIMapNew { void CancelClick( const cUIEvent * Event ); void OKClick( const cUIEvent * Event ); + + void OnRedChange( const cUIEvent * Event ); + + void OnGreenChange( const cUIEvent * Event ); + + void OnBlueChange( const cUIEvent * Event ); }; }}} diff --git a/src/gaming/maphelper.hpp b/src/gaming/maphelper.hpp index 4adc47420..8e795cc14 100644 --- a/src/gaming/maphelper.hpp +++ b/src/gaming/maphelper.hpp @@ -32,6 +32,8 @@ typedef struct sMapHdrS { Uint32 PropertyCount; Uint32 ShapeGroupCount; Uint32 VirtualObjectTypesCount; + Uint32 BaseColor; + Uint32 LightsCount; } sMapHdr; typedef struct sLayerHdrS { @@ -58,6 +60,14 @@ typedef struct sMapObjGOHdrS { Int32 PosY; } sMapObjGOHdr; +typedef struct sMapLightHdrS { + Uint32 Radius; + Int32 PosX; + Int32 PosY; + Uint32 Color; + Uint32 Type; +} sMapLightHdr; + class GObjFlags { public: enum EE_GAMEOBJECT_FLAGS { @@ -83,7 +93,7 @@ enum EE_LAYER_TYPE { }; enum EE_MAP_FLAGS { - MAP_FLAG_CLAMP_BODERS = ( 1 << 0 ), + MAP_FLAG_CLAMP_BORDERS = ( 1 << 0 ), MAP_FLAG_CLIP_AREA = ( 1 << 1 ), MAP_FLAG_DRAW_GRID = ( 1 << 2 ), MAP_FLAG_DRAW_TILE_OVER = ( 1 << 3 ), @@ -92,7 +102,7 @@ enum EE_MAP_FLAGS { MAP_FLAG_LIGHTS_BYVERTEX = ( 1 << 6 ) }; -#define MAP_EDITOR_DEFAULT_FLAGS ( MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA | MAP_FLAG_DRAW_GRID | MAP_FLAG_DRAW_BACKGROUND | MAP_FLAG_LIGHTS_ENABLED ) +#define MAP_EDITOR_DEFAULT_FLAGS ( MAP_FLAG_CLAMP_BORDERS | MAP_FLAG_CLIP_AREA | MAP_FLAG_DRAW_GRID | MAP_FLAG_DRAW_BACKGROUND ) enum EE_LAYER_FLAGS { LAYER_FLAG_VISIBLE = ( 1 << 0 ),