diff --git a/src/ee.h b/src/ee.h index ab59097d7..a5d4f58b4 100755 --- a/src/ee.h +++ b/src/ee.h @@ -23,13 +23,9 @@ /** @TODO Check for endianness problems, and make EEPP endianness agnostic. - @TODO Add backend for SDL 1.3 ( support for Android ). And may be SFML backend ( may be implement as the default build-in backend with sfml-window static linked ). + @TODO May be SFML backend ( may be implement as the default build-in backend with sfml-window static linked ). @TODO Support for Android and iOS. - @TODO Support color cursors \n - SDL 1.2 Not even posible ( win32 and x11 backends for this ready ) \n - Allegro 5 DONE @TODO Add Scripting support ( squirrel or python ). - @TODO Fix classes bad padding, optimize memory consumption. */ // General includes and declarations @@ -148,11 +144,6 @@ #include "graphics/cvertexbuffervbo.hpp" using namespace EE::Graphics; - // Gaming - #include "gaming/clight.hpp" - #include "gaming/cisomap.hpp" - using namespace EE::Gaming; - // UI #include "ui/cuibackground.hpp" #include "ui/cuiborder.hpp" @@ -197,6 +188,19 @@ #include "ui/cuicommondialog.hpp" using namespace EE::UI; + // Gaming + #include "gaming/clight.hpp" + #include "gaming/cisomap.hpp" + #include "gaming/cgameobject.hpp" + #include "gaming/cgameobjectshape.hpp" + #include "gaming/cgameobjectshapeex.hpp" + #include "gaming/cgameobjectsprite.hpp" + #include "gaming/clayer.hpp" + #include "gaming/ctilelayer.hpp" + #include "gaming/cobjectlayer.hpp" + #include "gaming/cmap.hpp" + using namespace EE::Gaming; + #include "physics/cphysicsmanager.hpp" #include "physics/cshape.hpp" #include "physics/cshapecircle.hpp" diff --git a/src/gaming/cgameobject.cpp b/src/gaming/cgameobject.cpp new file mode 100644 index 000000000..f585122fb --- /dev/null +++ b/src/gaming/cgameobject.cpp @@ -0,0 +1,67 @@ +#include "cgameobject.hpp" + +namespace EE { namespace Gaming { + +cGameObject::cGameObject( const Uint32& Flags ) : + mFlags( Flags ) +{ +} + +cGameObject::~cGameObject() +{ +} + +bool cGameObject::IsType( const Uint32& type ) { + return type == Type(); +} + +bool cGameObject::InheritsFrom( const Uint32& Type ) { + return false; +} + +bool cGameObject::IsTypeOrInheritsFrom( const Uint32& Type ) { + return IsType( Type ) || InheritsFrom( Type ); +} + +const Uint32& cGameObject::Flags() const { + return mFlags; +} + +Uint32 cGameObject::FlagGet( const Uint32& Flag ) { + return mFlags & Flag; +} + +void cGameObject::FlagSet( const Uint32& Flag ) { + if ( !( mFlags & Flag ) ) { + mFlags |= Flag; + } +} + +void cGameObject::FlagClear( const Uint32& Flag ) { + if ( mFlags & Flag ) { + mFlags &= ~Flag; + } +} + +Uint32 cGameObject::IsBlocked() const { + return mFlags & GObjFlags::GAMEOBJECT_BLOCKED; +} + +void cGameObject::Draw() { +} + +void cGameObject::Update() { +} + +eeVector2f cGameObject::Pos() const { + return eeVector2f(); +} + +void cGameObject::Pos( eeVector2f pos ) { +} + +Uint32 cGameObject::Type() const { + return GAMEOBJECT_TYPE_BASE; +} + +}} diff --git a/src/gaming/cgameobject.hpp b/src/gaming/cgameobject.hpp new file mode 100644 index 000000000..f3d58ce80 --- /dev/null +++ b/src/gaming/cgameobject.hpp @@ -0,0 +1,46 @@ +#ifndef EE_GAMINGCGAMEOBJECT_HPP +#define EE_GAMINGCGAMEOBJECT_HPP + +#include "base.hpp" +#include "maphelper.hpp" + +namespace EE { namespace Gaming { + +class cGameObject { + public: + cGameObject( const Uint32& Flags ); + + virtual ~cGameObject(); + + virtual void Draw(); + + virtual void Update(); + + virtual eeVector2f Pos() const; + + virtual void Pos( eeVector2f pos ); + + virtual Uint32 Type() const; + + bool IsType( const Uint32& type ); + + virtual bool InheritsFrom( const Uint32& Type ); + + bool IsTypeOrInheritsFrom( const Uint32& Type ); + + const Uint32& Flags() const; + + Uint32 FlagGet( const Uint32& Flag ); + + void FlagSet( const Uint32& Flag ); + + void FlagClear( const Uint32& Flag ); + + Uint32 IsBlocked() const; + protected: + Uint32 mFlags; +}; + +}} + +#endif diff --git a/src/gaming/cgameobjectshape.cpp b/src/gaming/cgameobjectshape.cpp new file mode 100644 index 000000000..3ba75591a --- /dev/null +++ b/src/gaming/cgameobjectshape.cpp @@ -0,0 +1,60 @@ +#include "cgameobjectshape.hpp" + +namespace EE { namespace Gaming { + +cGameObjectShape::cGameObjectShape( const Uint32& Flags, cShape * Shape, const eeVector2f& Pos ) : + cGameObject( Flags ), + mShape( Shape ), + mPos( Pos ) +{ +} + +cGameObjectShape::~cGameObjectShape() { +} + +Uint32 cGameObjectShape::Type() const { + return GAMEOBJECT_TYPE_SHAPE; +} + +void cGameObjectShape::Draw() { + if ( NULL != mShape ) { + Uint8 Both = 0; + EE_RENDERTYPE Render = RN_NORMAL; + + if ( mFlags & GObjFlags::GAMEOBJECT_MIRRORED ) { + Render = RN_MIRROR; + Both |= 1 << RN_MIRROR; + } + + if ( mFlags & GObjFlags::GAMEOBJECT_FLIPED ) { + Render = RN_FLIP; + Both |= 1 << RN_FLIP; + } + + if ( ( Both & RN_MIRROR ) && ( Both & RN_FLIP ) ) + Render = RN_FLIPMIRROR; + + mShape->Draw( mPos.x, mPos.y, eeColorA(), 0.f, 1.f, ALPHA_NORMAL, Render ); + } +} + +void cGameObjectShape::Update() { +} + +eeVector2f cGameObjectShape::Pos() const { + return mPos; +} + +void cGameObjectShape::Pos( eeVector2f pos ) { + mPos = pos; +} + +cShape * cGameObjectShape::Shape() const { + return mShape; +} + +void cGameObjectShape::Shape( cShape * shape ) { + mShape = shape; +} + +}} diff --git a/src/gaming/cgameobjectshape.hpp b/src/gaming/cgameobjectshape.hpp new file mode 100644 index 000000000..152d15c7b --- /dev/null +++ b/src/gaming/cgameobjectshape.hpp @@ -0,0 +1,38 @@ +#ifndef EE_GAMINGCGAMEOBJECTSHAPE_HPP +#define EE_GAMINGCGAMEOBJECTSHAPE_HPP + +#include "base.hpp" +#include "cgameobject.hpp" + +#include "../graphics/cshape.hpp" +using namespace EE::Graphics; + +namespace EE { namespace Gaming { + +class cGameObjectShape : public cGameObject { + public: + cGameObjectShape( const Uint32& Flags = GObjFlags::GAMEOBJECT_STATIC, cShape * Shape = NULL, const eeVector2f& Pos = eeVector2f() ); + + virtual ~cGameObjectShape(); + + virtual void Draw(); + + virtual void Update(); + + virtual eeVector2f Pos() const; + + virtual void Pos( eeVector2f pos ); + + cShape * Shape() const; + + void Shape( cShape * shape ); + + virtual Uint32 Type() const; + protected: + cShape * mShape; + eeVector2f mPos; +}; + +}} + +#endif diff --git a/src/gaming/cgameobjectshapeex.cpp b/src/gaming/cgameobjectshapeex.cpp new file mode 100644 index 000000000..a311830ea --- /dev/null +++ b/src/gaming/cgameobjectshapeex.cpp @@ -0,0 +1,33 @@ +#include "cgameobjectshapeex.hpp" + +namespace EE { namespace Gaming { + +cGameObjectShapeEx::cGameObjectShapeEx( const Uint32& Flags, cShape * Shape, const eeVector2f& Pos, EE_PRE_BLEND_FUNC Blend, EE_RENDERTYPE Render, eeFloat Angle, eeFloat Scale, eeColorA Color) : + cGameObjectShape( Flags, Shape, Pos ), + mBlend( Blend ), + mRender( Render ), + mAngle( Angle ), + mScale( Scale ), + mColor( Color ), + mVertexColors( NULL ) +{ +} + +cGameObjectShapeEx::~cGameObjectShapeEx() +{ +} + +Uint32 cGameObjectShapeEx::Type() const { + return GAMEOBJECT_TYPE_SHAPEEX; +} + +void cGameObjectShapeEx::Draw() { + if ( NULL != mShape ) { + if ( NULL != mVertexColors ) + mShape->Draw( mPos.x, mPos.y, mAngle, mScale, mVertexColors[0], mVertexColors[1], mVertexColors[2], mVertexColors[4], mBlend, mRender ); + else + mShape->Draw( mPos.x, mPos.y, mColor, mAngle, mScale, mBlend, mRender ); + } +} + +}} diff --git a/src/gaming/cgameobjectshapeex.hpp b/src/gaming/cgameobjectshapeex.hpp new file mode 100644 index 000000000..ff553b806 --- /dev/null +++ b/src/gaming/cgameobjectshapeex.hpp @@ -0,0 +1,29 @@ +#ifndef CGAMEOBJECTSHAPEEX_HPP +#define CGAMEOBJECTSHAPEEX_HPP + +#include "base.hpp" +#include "cgameobjectshape.hpp" + +namespace EE { namespace Gaming { + +class cGameObjectShapeEx : public cGameObjectShape { + public: + cGameObjectShapeEx( const Uint32& Flags = GObjFlags::GAMEOBJECT_STATIC, cShape * Shape = NULL, const eeVector2f& Pos = eeVector2f(), EE_PRE_BLEND_FUNC Blend = ALPHA_NORMAL, EE_RENDERTYPE Render = RN_NORMAL, eeFloat Angle = 0.f, eeFloat Scale = 1.f, eeColorA Color = eeColorA() ); + + virtual ~cGameObjectShapeEx(); + + virtual void Draw(); + + virtual Uint32 Type() const; + protected: + EE_PRE_BLEND_FUNC mBlend; + EE_RENDERTYPE mRender; + eeFloat mAngle; + eeFloat mScale; + eeColorA mColor; + eeColorA * mVertexColors; +}; + +}} + +#endif diff --git a/src/gaming/cgameobjectsprite.cpp b/src/gaming/cgameobjectsprite.cpp new file mode 100644 index 000000000..4d68b11a5 --- /dev/null +++ b/src/gaming/cgameobjectsprite.cpp @@ -0,0 +1,48 @@ +#include "cgameobjectsprite.hpp" + +namespace EE { namespace Gaming { + +cGameObjectSprite::cGameObjectSprite( const Uint32& Flags, cSprite * Sprite ) : + cGameObject( Flags ), + mSprite( Sprite ) +{ +} + +cGameObjectSprite::~cGameObjectSprite() { + eeSAFE_DELETE( mSprite ); +} + +Uint32 cGameObjectSprite::Type() const { + return GAMEOBJECT_TYPE_SPRITE; +} + +void cGameObjectSprite::Draw() { + if ( NULL != mSprite ) { + mSprite->Draw(); + } +} + +void cGameObjectSprite::Update() { +} + +eeVector2f cGameObjectSprite::Pos() const { + eeASSERT( NULL != mSprite ) + + return mSprite->Position(); +} + +void cGameObjectSprite::Pos( eeVector2f pos ) { + eeASSERT( NULL != mSprite ); + + mSprite->Position( pos ); +} + +cSprite * cGameObjectSprite::Sprite() const { + return mSprite; +} + +void cGameObjectSprite::Sprite( cSprite * sprite ) { + mSprite = sprite; +} + +}} diff --git a/src/gaming/cgameobjectsprite.hpp b/src/gaming/cgameobjectsprite.hpp new file mode 100644 index 000000000..9ede96d74 --- /dev/null +++ b/src/gaming/cgameobjectsprite.hpp @@ -0,0 +1,37 @@ +#ifndef EE_GAMINGCGAMEOBJECTSPRITE_HPP +#define EE_GAMINGCGAMEOBJECTSPRITE_HPP + +#include "base.hpp" +#include "cgameobject.hpp" + +#include "../graphics/csprite.hpp" +using namespace EE::Graphics; + +namespace EE { namespace Gaming { + +class cGameObjectSprite : public cGameObject { + public: + cGameObjectSprite( const Uint32& Flags = GObjFlags::GAMEOBJECT_ANIMATED, cSprite * Sprite = NULL ); + + virtual ~cGameObjectSprite(); + + virtual void Draw(); + + virtual void Update(); + + eeVector2f Pos() const; + + virtual void Pos( eeVector2f pos ); + + cSprite * Sprite() const; + + void Sprite( cSprite * sprite ); + + virtual Uint32 Type() const; + private: + cSprite * mSprite; +}; + +}} + +#endif diff --git a/src/gaming/cisomap.hpp b/src/gaming/cisomap.hpp index cc4715006..15ba99ac3 100755 --- a/src/gaming/cisomap.hpp +++ b/src/gaming/cisomap.hpp @@ -1,5 +1,5 @@ -#ifndef mEE_GAMINGCISOMAP_H -#define mEE_GAMINGCISOMAP_H +#ifndef EE_GAMINGCISOMAP_H +#define EE_GAMINGCISOMAP_H #include "base.hpp" diff --git a/src/gaming/clayer.cpp b/src/gaming/clayer.cpp new file mode 100644 index 000000000..ef87f1f03 --- /dev/null +++ b/src/gaming/clayer.cpp @@ -0,0 +1,65 @@ +#include "clayer.hpp" +#include "cmap.hpp" + +namespace EE { namespace Gaming { + +cLayer::cLayer( cMap * map, Uint32 type, Uint32 flags, std::string name, eeVector2f offset ) : + mMap( map ), + mType( type ), + mFlags( flags ), + mOffset( offset ), + mNameHash( MakeHash( name ) ), + mName( name ) +{ +} + +cLayer::~cLayer() { + +} + +const Uint32& cLayer::Flags() const { + return mFlags; +} + +Uint32 cLayer::FlagGet( const Uint32& Flag ) { + return mFlags & Flag; +} + +void cLayer::FlagSet( const Uint32& Flag ) { + if ( !( mFlags & Flag ) ) { + mFlags |= Flag; + } +} + +void cLayer::FlagClear( const Uint32& Flag ) { + if ( mFlags & Flag ) { + mFlags &= ~Flag; + } +} + +const Uint32& cLayer::Type() const { + return mType; +} + +cMap * cLayer::Map() const { + return mMap; +} + +const eeVector2f& cLayer::Offset() const { + return mOffset; +} + +void cLayer::Offset( const eeVector2f& offset ) { + mOffset = offset; +} + +const std::string& cLayer::Name() const { + return mName; +} + +const Uint32& cLayer::Id() const { + return mNameHash; +} + +}} + diff --git a/src/gaming/clayer.hpp b/src/gaming/clayer.hpp new file mode 100644 index 000000000..1b9ca028d --- /dev/null +++ b/src/gaming/clayer.hpp @@ -0,0 +1,52 @@ +#ifndef EE_GAMINGCLAYER_HPP +#define EE_GAMINGCLAYER_HPP + +#include "base.hpp" + +namespace EE { namespace Gaming { + +class cMap; + +class cLayer { + public: + virtual ~cLayer(); + + virtual void Draw( const eeVector2f& Offset = eeVector2f(0,0) ) = 0; + + virtual void Update() = 0; + + const Uint32& Flags() const; + + Uint32 FlagGet( const Uint32& Flag ); + + void FlagSet( const Uint32& Flag ); + + void FlagClear( const Uint32& Flag ); + + const Uint32& Type() const; + + cMap * Map() const; + + const eeVector2f& Offset() const; + + void Offset( const eeVector2f& offset ); + + const std::string& Name() const; + + const Uint32& Id() const; + protected: + friend class cMap; + + cMap * mMap; + Uint32 mType; + Uint32 mFlags; + eeVector2f mOffset; + Uint32 mNameHash; + std::string mName; + + cLayer( cMap * map, Uint32 type, Uint32 flags, std::string name = "", eeVector2f offset = eeVector2f(0,0) ); +}; + +}} + +#endif diff --git a/src/gaming/cmap.cpp b/src/gaming/cmap.cpp new file mode 100644 index 000000000..172eb1b6c --- /dev/null +++ b/src/gaming/cmap.cpp @@ -0,0 +1,266 @@ +#include "cmap.hpp" +#include "cgameobjectshape.hpp" +#include "cgameobjectshapeex.hpp" +#include "cgameobjectsprite.hpp" +#include "ctilelayer.hpp" +#include "cobjectlayer.hpp" + +#include "../graphics/cprimitives.hpp" +using namespace EE::Graphics; + +namespace EE { namespace Gaming { + +cMap::cMap() : + mWindow( NULL ), + mLayers( NULL ), + mFlags( 0 ), + mMaxLayers( 0 ), + mLayerCount( 0 ), + mViewSize( 640, 480 ) +{ + ViewSize( mViewSize ); +} + +cMap::~cMap() { + for ( Uint32 i = 0; i < mLayerCount; i++ ) + eeSAFE_DELETE( mLayers[i] ); + + eeSAFE_DELETE( mLayers ); +} + +void cMap::Create( eeSize Size, Uint32 MaxLayers, eeSize TileSize, Uint32 Flags, eeSize viewSize, cWindow * Window ) { + mWindow = Window; + + if ( NULL == mWindow ) + mWindow = cEngine::instance()->GetCurrentWindow(); + + mFlags = Flags; + mMaxLayers = MaxLayers; + mSize = Size; + mTileSize = TileSize; + mLayers = eeNewArray( cLayer*, mMaxLayers ); + + for ( Uint32 i = 0; i < mMaxLayers; i++ ) + mLayers[i] = NULL; + + ViewSize( viewSize ); +} + +void cMap::AddLayer( Uint32 Type, Uint32 flags, std::string name ) { + eeASSERT( NULL != mLayers ); + + switch ( Type ) { + case MAP_LAYER_TILED: + mLayers[ mLayerCount ] = eeNew( cTileLayer, ( this, mSize, flags, name ) ); + break; + case MAP_LAYER_OBJECT: + mLayers[ mLayerCount ] = eeNew( cObjectLayer, ( this, flags, name ) ); + break; + default: + return; + } + + mLayerCount++; +} + +cLayer* cMap::GetLayer( Uint32 index ) { + eeASSERT( index < mLayerCount ); + return mLayers[ index ]; +} + +cLayer* cMap::GetLayerByHash( Uint32 hash ) { + for ( Uint32 i = 0; i < mLayerCount; i++ ) { + if ( mLayers[i]->Id() == hash ) + return mLayers[i]; + } + + return NULL; +} + +cLayer* cMap::GetLayer( const std::string& name ) { + return GetLayerByHash( MakeHash( name ) ); +} + +void cMap::Draw() { + cGlobalBatchRenderer::instance()->Draw(); + + if ( ClipedArea() ) { + mWindow->ClipEnable( mScreenPos.x, mScreenPos.y, mViewSize.x, mViewSize.y ); + } + + eeVector2f offsetFixed = eeVector2f( (eeFloat)mScreenPos.x, (eeFloat)mScreenPos.y ) + FixOffset(); + + GetMouseOverTile(); + + for ( Uint32 i = 0; i < mLayerCount; i++ ) { + mLayers[i]->Draw( offsetFixed ); + } + + if ( ClipedArea() ) { + mWindow->ClipDisable(); + } +} + +void cMap::GetMouseOverTile() { + eeVector2i mouse = mWindow->GetInput()->GetMousePos(); + + mMouseOverTile.x = ( mouse.x - mScreenPos.x - mOffset.x ) / mTileSize.Width(); + mMouseOverTile.y = ( mouse.y - mScreenPos.y - mOffset.y ) / mTileSize.Height(); + + if ( mMouseOverTile.x < 0 ) + mMouseOverTile.x = 0; + + if ( mMouseOverTile.y < 0 ) + mMouseOverTile.y = 0; + + if ( mMouseOverTile.x >= mSize.Width() ) + mMouseOverTile.x = mSize.Width() - 1; + + if ( mMouseOverTile.y >= mSize.Height() ) + mMouseOverTile.y = mSize.Height() - 1; +} + +void cMap::Update() { + for ( Uint32 i = 0; i < mLayerCount; i++ ) + mLayers[i]->Update(); +} + +const eeSize& cMap::ViewSize() const { + return mViewSize; +} + +void cMap::ViewSize( const eeSize& viewSize ) { + mViewSize = viewSize; + + Clamp(); + + CalcTilesClip(); +} + +const eeVector2i& cMap::Position() const { + return mScreenPos; +} + +void cMap::Position( const eeVector2i& position ) { + mScreenPos = position; +} + +const eeVector2f& cMap::Offset() const { + return mOffset; +} + +const eeVector2i& cMap::StartTile() const { + return mStartTile; +} + +const eeVector2i& cMap::EndTile() const { + return mEndTile; +} + +void cMap::Offset( const eeVector2f& offset ) { + mOffset = offset; + + Clamp(); + + CalcTilesClip(); +} + +void cMap::CalcTilesClip() { + if ( mTileSize.x > 0 && mTileSize.y > 0 ) { + 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 + mViewSize.x / mTileSize.x + 1; + mEndTile.y = mStartTile.y + mViewSize.y / mTileSize.y + 1; + + if ( mStartTile.x < 0 ) + mStartTile.x = 0; + + if ( mStartTile.y < 0 ) + mStartTile.y = 0; + + if ( mEndTile.x > mSize.x ) + mEndTile.x = mSize.x; + + if ( mEndTile.y > mSize.y ) + mEndTile.y = mSize.y; + } +} + +void cMap::Clamp() { + if ( !ClampBorders() ) + return; + + if ( mOffset.x > 0 ) + mOffset.x = 0; + + if ( mOffset.y > 0 ) + mOffset.y = 0; + + if ( -mOffset.x + mViewSize.x > mTileSize.x * mSize.x ) + mOffset.x = -( mTileSize.x * mSize.x - mViewSize.x ); + + if ( -mOffset.y + mViewSize.y > mTileSize.y * mSize.y ) + mOffset.y = -( mTileSize.y * mSize.y - mViewSize.y ); +} + +Uint32 cMap::ClipedArea() const { + return mFlags & MAP_FLAG_CLIP_AREA; +} + +Uint32 cMap::ClampBorders() const { + return mFlags & MAP_FLAG_CLAMP_BODERS; +} + +eeVector2f cMap::FixOffset() { + return eeVector2f( (eeFloat)static_cast( mOffset.x ), (eeFloat)static_cast( mOffset.y ) ); +} + +void cMap::Move( const eeVector2f& offset ) { + Move( offset.x, offset.y ); +} + +void cMap::Move( const eeFloat& offsetx, const eeFloat& offsety ) { + Offset( eeVector2f( mOffset.x + offsetx, mOffset.y + offsety ) ); +} + +cGameObject * cMap::CreateGameObject( const Uint32& Type, const Uint32& Flags ) { + switch ( Type ) { + case GAMEOBJECT_TYPE_SHAPE: + return eeNew( cGameObjectShape, ( Flags ) ); + case GAMEOBJECT_TYPE_SHAPEEX: + return eeNew( cGameObjectShapeEx, ( Flags ) ); + case GAMEOBJECT_TYPE_SPRITE: + return eeNew( cGameObjectSprite, ( Flags ) ); + } + + return NULL; +} + +const eeSize& cMap::TileSize() const { + return mTileSize; +} + +const eeSize& cMap::Size() const { + return mSize; +} + +const Uint32& cMap::LayerCount() const { + return mLayerCount; +} + +const Uint32& cMap::MaxLayers() const { + return mMaxLayers; +} + +void cMap::Load( const std::string& path ) { + +} + +void cMap::Save( const std::string& path ) { + +} + +}} diff --git a/src/gaming/cmap.hpp b/src/gaming/cmap.hpp new file mode 100644 index 000000000..80fa6b1b1 --- /dev/null +++ b/src/gaming/cmap.hpp @@ -0,0 +1,102 @@ +#ifndef EE_GAMINGCTILEMAP_HPP +#define EE_GAMINGCTILEMAP_HPP + +#include "base.hpp" + +#include "cgameobject.hpp" +#include "clight.hpp" +#include "clayer.hpp" + +#include "../window/cinput.hpp" +#include "../window/cengine.hpp" +#include "../window/cwindow.hpp" +using namespace EE::Window; + +namespace EE { namespace Gaming { + +class cMap { + public: + cMap(); + + virtual ~cMap(); + + virtual void Create( eeSize Size, Uint32 MaxLayers, eeSize TileSize, Uint32 Flags = 0, eeSize viewSize = eeSize( 640, 480 ), cWindow * Window = NULL ); + + virtual void AddLayer( Uint32 Type, Uint32 flags, std::string name ); + + virtual cLayer* GetLayer( Uint32 index ); + + virtual cLayer* GetLayerByHash( Uint32 hash ); + + virtual cLayer* GetLayer( const std::string& name ); + + virtual void Load( const std::string& path ); + + virtual void Save( const std::string& path ); + + virtual void Draw(); + + virtual void Update(); + + const eeSize& TileSize() const; + + const eeSize& Size() const; + + const Uint32& LayerCount() const; + + const Uint32& MaxLayers() const; + + const eeSize& ViewSize() const; + + void ViewSize( const eeSize& viewSize ); + + const eeVector2f& Offset() const; + + void Offset( const eeVector2f& offset ); + + const eeVector2i& Position() const; + + void Position( const eeVector2i& position ); + + void Move( const eeVector2f& offset ); + + void Move( const eeFloat& offsetx, const eeFloat& offsety ); + + const eeVector2i& StartTile() const; + + const eeVector2i& EndTile() const; + + const Uint32& Flags() const; + + Uint32 ClampBorders() const; + + Uint32 ClipedArea() const; + protected: + cWindow * mWindow; + cLayer** mLayers; + Uint32 mFlags; + Uint32 mMaxLayers; + Uint32 mLayerCount; + eeSize mSize; + eeSize mTileSize; + eeSize mViewSize; + eeVector2f mOffset; + eeVector2i mScreenPos; + eeVector2i mStartTile; + eeVector2i mEndTile; + eeVector2i mMouseOverTile; + + cGameObject * CreateGameObject( const Uint32& Type, const Uint32& Flags ); + + eeVector2f FixOffset(); + + void CalcTilesClip(); + + void Clamp(); + + void GetMouseOverTile(); +}; + +}} + +#endif diff --git a/src/gaming/cobjectlayer.cpp b/src/gaming/cobjectlayer.cpp new file mode 100644 index 000000000..ed62a7287 --- /dev/null +++ b/src/gaming/cobjectlayer.cpp @@ -0,0 +1,58 @@ +#include "cobjectlayer.hpp" +#include "cmap.hpp" + +#include "../graphics/cglobalbatchrenderer.hpp" +#include "../graphics/renderer/cgl.hpp" +using namespace EE::Graphics; + +namespace EE { namespace Gaming { + +cObjectLayer::cObjectLayer( cMap * map, Uint32 flags, std::string name, eeVector2f offset ) : + cLayer( map, MAP_LAYER_OBJECT, flags, name, offset ) +{ +} + +cObjectLayer::~cObjectLayer() { +} + +void cObjectLayer::AllocateLayer() { + +} + +void cObjectLayer::DeallocateLayer() { + for ( ObjList::iterator it = mObjects.begin(); it != mObjects.end(); it++ ) { + eeSAFE_DELETE( *it ); + } +} + +void cObjectLayer::Draw( const eeVector2f &Offset ) { + cGlobalBatchRenderer::instance()->Draw(); + + GLi->LoadIdentity(); + GLi->PushMatrix(); + GLi->Translatef( mOffset.x + Offset.x, mOffset.y + Offset.y, 0.0f ); + + for ( ObjList::iterator it = mObjects.begin(); it != mObjects.end(); it++ ) { + (*it)->Draw(); + } + + cGlobalBatchRenderer::instance()->Draw(); + + GLi->PopMatrix(); +} + +void cObjectLayer::Update() { + for ( ObjList::iterator it = mObjects.begin(); it != mObjects.end(); it++ ) { + (*it)->Update(); + } +} + +void cObjectLayer::AddGameObject( cGameObject * obj ) { + mObjects.push_back( obj ); +} + +void cObjectLayer::RemoveGameObject( cGameObject * obj ) { + mObjects.remove( obj ); +} + +}} diff --git a/src/gaming/cobjectlayer.hpp b/src/gaming/cobjectlayer.hpp new file mode 100644 index 000000000..e9efc83ef --- /dev/null +++ b/src/gaming/cobjectlayer.hpp @@ -0,0 +1,38 @@ +#ifndef EE_GAMINGCOBJECTLAYER_HPP +#define EE_GAMINGCOBJECTLAYER_HPP + +#include "clayer.hpp" +#include "cgameobject.hpp" + +namespace EE { namespace Gaming { + +class cMap; + +class cObjectLayer : public cLayer { + public: + virtual ~cObjectLayer(); + + virtual void Draw( const eeVector2f &Offset = eeVector2f(0,0) ); + + virtual void Update(); + + virtual void AddGameObject( cGameObject * obj ); + + virtual void RemoveGameObject( cGameObject * obj ); + protected: + friend class cMap; + + typedef std::list ObjList; + + ObjList mObjects; + + cObjectLayer( cMap * map, Uint32 flags, std::string name = "", eeVector2f offset = eeVector2f(0,0) ); + + void AllocateLayer(); + + void DeallocateLayer(); +}; + +}} + +#endif diff --git a/src/gaming/ctilelayer.cpp b/src/gaming/ctilelayer.cpp new file mode 100644 index 000000000..b34a525cf --- /dev/null +++ b/src/gaming/ctilelayer.cpp @@ -0,0 +1,93 @@ +#include "ctilelayer.hpp" +#include "cmap.hpp" + +#include "../graphics/cglobalbatchrenderer.hpp" +#include "../graphics/renderer/cgl.hpp" +using namespace EE::Graphics; + +namespace EE { namespace Gaming { + +cTileLayer::cTileLayer( cMap * map, eeSize size, Uint32 flags, std::string name, eeVector2f offset ) : + cLayer( map, MAP_LAYER_TILED, flags, name, offset ), + mSize( size ) +{ + AllocateLayer(); +} + +cTileLayer::~cTileLayer() { + DeallocateLayer(); +} + +void cTileLayer::cTileLayer::Draw( const eeVector2f &Offset ) { + cGlobalBatchRenderer::instance()->Draw(); + + GLi->LoadIdentity(); + GLi->PushMatrix(); + GLi->Translatef( mOffset.x + Offset.x, mOffset.y + Offset.y, 0.0f ); + + eeVector2i start = mMap->StartTile(); + eeVector2i end = mMap->EndTile(); + + for ( Int32 x = start.x; x < end.x; x++ ) { + for ( Int32 y = start.y; y < end.y; y++ ) { + if ( NULL != mTiles[x][y] ) + mTiles[x][y]->Draw(); + } + } + + cGlobalBatchRenderer::instance()->Draw(); + + GLi->PopMatrix(); +} + +void cTileLayer::Update() { + eeVector2i start = mMap->StartTile(); + eeVector2i end = mMap->EndTile(); + + for ( Int32 x = start.x; x < end.x; x++ ) { + for ( Int32 y = start.y; y < end.y; y++ ) { + if ( NULL != mTiles[x][y] ) + mTiles[x][y]->Update(); + } + } +} + +void cTileLayer::AllocateLayer() { + mTiles = eeNewArray( cGameObject**, mSize.Width() ); + + for ( Int32 x = 0; x < mSize.x; x++ ) { + mTiles[x] = eeNewArray( cGameObject*, mSize.Height() ); + + for ( Int32 y = 0; y < mSize.y; y++ ) { + mTiles[x][y] = NULL; + } + } +} + +void cTileLayer::DeallocateLayer() { + for ( Int32 x = 0; x < mSize.x; x++ ) { + for ( Int32 y = 0; y < mSize.y; y++ ) { + eeSAFE_DELETE( mTiles[x][y] ); + } + + eeSAFE_DELETE_ARRAY( mTiles[x] ); + } + + eeSAFE_DELETE_ARRAY( mTiles ); +} + +void cTileLayer::AddGameObject( cGameObject * obj, const eeVector2u& TilePos ) { + RemoveGameObject( TilePos ); + + mTiles[ TilePos.x ][ TilePos.y ] = obj; + + obj->Pos( eeVector2f( TilePos.x * mMap->TileSize().x, TilePos.y * mMap->TileSize().y ) ); +} + +void cTileLayer::RemoveGameObject( const eeVector2u& TilePos ) { + if ( NULL != mTiles[ TilePos.x ][ TilePos.y ] ) { + eeSAFE_DELETE( mTiles[ TilePos.x ][ TilePos.y ] ); + } +} + +}} diff --git a/src/gaming/ctilelayer.hpp b/src/gaming/ctilelayer.hpp new file mode 100644 index 000000000..bc53014c3 --- /dev/null +++ b/src/gaming/ctilelayer.hpp @@ -0,0 +1,35 @@ +#ifndef EE_GAMINGCTILELAYER_HPP +#define EE_GAMINGCTILELAYER_HPP + +#include "clayer.hpp" +#include "cgameobject.hpp" + +namespace EE { namespace Gaming { + +class cTileLayer : public cLayer { + public: + virtual ~cTileLayer(); + + virtual void Draw( const eeVector2f &Offset = eeVector2f(0,0) ); + + virtual void Update(); + + virtual void AddGameObject( cGameObject * obj, const eeVector2u& TilePos ); + + virtual void RemoveGameObject( const eeVector2u& TilePos ); + protected: + friend class cMap; + + cGameObject*** mTiles; + eeSize mSize; + + cTileLayer( cMap * map, eeSize size, Uint32 flags, std::string name = "", eeVector2f offset = eeVector2f(0,0) ); + + void AllocateLayer(); + + void DeallocateLayer(); +}; + +}} + +#endif diff --git a/src/gaming/maphelper.hpp b/src/gaming/maphelper.hpp new file mode 100644 index 000000000..7be57a995 --- /dev/null +++ b/src/gaming/maphelper.hpp @@ -0,0 +1,37 @@ +#ifndef EE_GAMINGMAPHELPER_HPP +#define EE_GAMINGMAPHELPER_HPP + +namespace EE { namespace Gaming { + +class GObjFlags { + public: + enum EE_GAMEOBJECT_FLAGS { + GAMEOBJECT_STATIC = 0, + GAMEOBJECT_ANIMATED, + GAMEOBJECT_MIRRORED, + GAMEOBJECT_FLIPED, + GAMEOBJECT_BLOCKED + }; +}; + +enum EE_GAMEOBJECT_TYPE { + GAMEOBJECT_TYPE_BASE, + GAMEOBJECT_TYPE_SHAPE, + GAMEOBJECT_TYPE_SHAPEEX, + GAMEOBJECT_TYPE_SPRITE, + GAMEOBJECT_TYPE_USER = 100 +}; + +enum EE_LAYER_TYPE { + MAP_LAYER_TILED, + MAP_LAYER_OBJECT +}; + +enum EE_MAP_FLAGS { + MAP_FLAG_CLAMP_BODERS = ( 1 << 0 ), + MAP_FLAG_CLIP_AREA = ( 1 << 1 ) +}; + +}} + +#endif diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index dfb660591..c0b79a90d 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -63,6 +63,7 @@ void cEETest::Init() { run = ( mWindow->Created() && PAK.IsOpen() ); if ( run ) { + #ifdef EE_DEBUG std::cout << "Size of Callback0: " << sizeof( cb::Callback0 ) << std::endl; std::cout << "Size of cWaypoints: " << sizeof( cWaypoints ) << std::endl; std::cout << "Size of UIEventsMap: " << sizeof( std::map< Uint32, std::map > ) << std::endl; @@ -74,16 +75,18 @@ void cEETest::Init() { std::cout << "Size of cUIControlAnim: " << sizeof(cUIControlAnim) << std::endl; std::cout << "Size of cUITextBox: " << sizeof(cUITextBox) << std::endl; std::cout << "Size of cUIComplexControl: " << sizeof(cUIComplexControl) << std::endl; + #endif SetScreen( 0 ); mWindow->Caption( "EE++ Test Application" ); + TF = cTextureFactory::instance(); TF->Allocate(40); - Log = cLog::instance(); - KM = mWindow->GetInput(); - JM = KM->GetJoystickManager(); + Log = cLog::instance(); + KM = mWindow->GetInput(); + JM = KM->GetJoystickManager(); PS.resize(5); @@ -106,6 +109,7 @@ void cEETest::Init() { CreateShaders(); Mus = eeNew( cMusic, () ); + if ( Mus->OpenFromPack( &PAK, "music.ogg" ) ) { Mus->Loop(true); Mus->Volume( 100.f ); @@ -554,7 +558,7 @@ void cEETest::CreateUI() { cUICommonDialog::CreateParams CDParams; CDParams.Flags = UI_HALIGN_CENTER; - CDParams.WinFlags |= cUIWindow::UI_WIN_MAXIMIZE_BUTTON; + CDParams.WinFlags |= cUIWindow::UI_WIN_MAXIMIZE_BUTTON; // | cUIWindow::UI_WIN_MODAL CDParams.Size = eeSize( 420, 267 ); cUICommonDialog * CDialog = eeNew( cUICommonDialog, ( CDParams ) ); CDialog->AddFilePattern( "*.hpp;*.cpp", true ); @@ -882,6 +886,24 @@ void cEETest::LoadTextures() { CreateTiling(Wireframe); Log->Writef( "Map creation time: %f", te.Elapsed() ); + + cMTRand Rand( 0xFF00FF00 ); + mMap = eeNew( cMap, () ); + mMap->Create( eeSize(25,25), 8, eeSize(32,32), MAP_FLAG_CLAMP_BODERS | MAP_FLAG_CLIP_AREA ); + mMap->AddLayer( MAP_LAYER_TILED, 0, "ground" ); + mMap->Position( eeVector2i( mWindow->GetWidth() / 2 - mMap->ViewSize().Width() / 2, mWindow->GetHeight() / 2 - mMap->ViewSize().Height() / 2 ) ); + + cTileLayer * TLayer = reinterpret_cast ( mMap->GetLayer(0) ); + + for ( x = 0; x < mMap->Size().Width(); x++ ) { + for ( y = 0; y < mMap->Size().Height(); y++ ) { + TLayer->AddGameObject( + eeNew( + cGameObjectShape, ( GObjFlags::GAMEOBJECT_STATIC, Tiles[ Rand.RandRange( 0, 5 ) ] ) + ), eeVector2u( x, y ) + ); + } + } } void cEETest::RandomizeHeights() { @@ -1145,7 +1167,11 @@ void cEETest::Screen4() { } void cEETest::Screen5() { + mMap->Update(); + mMap->Draw(); + cPrimitives p; + p.DrawRectangle( mMap->Position().x, mMap->Position().y, mMap->ViewSize().Width(), mMap->ViewSize().Height(), 0, 1, EE_DRAW_LINE ); } void cEETest::Render() { @@ -1408,17 +1434,21 @@ void cEETest::Input() { Map.Move( 0, -mWindow->Elapsed() * 0.2f ); } - if ( KM->IsKeyDown(KEY_LEFT) ) - Map.Move( (mWindow->Elapsed() * 0.2f), 0 ); + if ( KM->IsKeyDown(KEY_LEFT) ) { + Map.Move( mWindow->Elapsed() * 0.2f, 0 ); + } - if ( KM->IsKeyDown(KEY_RIGHT) ) + if ( KM->IsKeyDown(KEY_RIGHT) ) { Map.Move( -mWindow->Elapsed() * 0.2f, 0 ); + } - if ( KM->IsKeyDown(KEY_UP) ) - Map.Move( 0, (mWindow->Elapsed() * 0.2f) ); + if ( KM->IsKeyDown(KEY_UP) ) { + Map.Move( 0, mWindow->Elapsed() * 0.2f ); + } - if ( KM->IsKeyDown(KEY_DOWN) ) + if ( KM->IsKeyDown(KEY_DOWN) ) { Map.Move( 0, -mWindow->Elapsed() * 0.2f ); + } if ( KM->IsKeyDown(KEY_KP_MINUS) ) Map.BaseLight().Radius( Map.BaseLight().Radius() - mWindow->Elapsed() * 0.2f ); @@ -1473,6 +1503,24 @@ void cEETest::Input() { ShowParticles = !ShowParticles; } + break; + case 5: + if ( KM->IsKeyDown(KEY_LEFT) ) { + mMap->Move( mWindow->Elapsed() * 0.2f, 0 ); + } + + if ( KM->IsKeyDown(KEY_RIGHT) ) { + mMap->Move( -mWindow->Elapsed() * 0.2f, 0 ); + } + + if ( KM->IsKeyDown(KEY_UP) ) { + mMap->Move( 0, mWindow->Elapsed() * 0.2f ); + } + + if ( KM->IsKeyDown(KEY_DOWN) ) { + mMap->Move( 0, -mWindow->Elapsed() * 0.2f ); + } + break; } } @@ -1512,6 +1560,7 @@ void cEETest::End() { eeSAFE_DELETE( mBlindyPtr ); eeSAFE_DELETE( mBoxSprite ); eeSAFE_DELETE( mCircleSprite ); + eeSAFE_DELETE( mMap ); cLog::instance()->Save(); diff --git a/src/test/eetest.hpp b/src/test/eetest.hpp index 3cf40a62a..13184d462 100644 --- a/src/test/eetest.hpp +++ b/src/test/eetest.hpp @@ -269,6 +269,8 @@ class cEETest : private cThread { Int32 mCurDemo; cSprite * mBoxSprite; cSprite * mCircleSprite; + + cMap * mMap; }; #endif diff --git a/src/ui/cuicommondialog.cpp b/src/ui/cuicommondialog.cpp index 0cab2e0ce..863692561 100644 --- a/src/ui/cuicommondialog.cpp +++ b/src/ui/cuicommondialog.cpp @@ -9,7 +9,8 @@ namespace EE { namespace UI { cUICommonDialog::cUICommonDialog( const cUICommonDialog::CreateParams& Params ) : cUIWindow( Params ), - mCurPath( Params.DefaultDirectory ) + mCurPath( Params.DefaultDirectory ), + mCDLFlags( Params.CDLFlags ) { mType = UI_TYPE_COMMONDIALOG; @@ -25,7 +26,11 @@ cUICommonDialog::cUICommonDialog( const cUICommonDialog::CreateParams& Params ) if ( mMinWindowSize.Height() < CDLG_MIN_HEIGHT ) mMinWindowSize.Height( CDLG_MIN_HEIGHT ); - Title( "Select a file" ); + if ( AllowFolderSelect() ) { + Title( "Select a folder" ); + } else { + Title( "Select a file" ); + } cUITextBox::CreateParams TxtBoxParams; TxtBoxParams.Parent( Container() ); @@ -44,7 +49,11 @@ cUICommonDialog::cUICommonDialog( const cUICommonDialog::CreateParams& Params ) mButtonOpen = eeNew( cUIPushButton, ( ButtonParams ) ); mButtonOpen->Visible( true ); mButtonOpen->Enabled( true ); - mButtonOpen->Text( "Open" ); + + if ( IsSaveDialog() ) + mButtonOpen->Text( "Save" ); + else + mButtonOpen->Text( "Open" ); ButtonParams.Pos.y = mButtonOpen->Pos().y + mButtonOpen->Size().Height() + 6; mButtonCancel = eeNew( cUIPushButton, ( ButtonParams ) ); @@ -110,7 +119,7 @@ cUICommonDialog::cUICommonDialog( const cUICommonDialog::CreateParams& Params ) mFiletype = eeNew( cUIDropDownList, ( DDLParams ) ); mFiletype->Visible( true ); mFiletype->Enabled( true ); - mFiletype->ListBox()->AddListBoxItem( "*" ); + mFiletype->ListBox()->AddListBoxItem( Params.DefaultFilePattern ); mFiletype->ListBox()->SetSelected(0); ApplyDefaultTheme(); @@ -118,6 +127,9 @@ cUICommonDialog::cUICommonDialog( const cUICommonDialog::CreateParams& Params ) RefreshFolder(); } +cUICommonDialog::~cUICommonDialog() { +} + void cUICommonDialog::RefreshFolder() { std::vector flist = FilesGetInPath( String( mCurPath ) ); std::vector files; @@ -134,7 +146,7 @@ void cUICommonDialog::RefreshFolder() { } for ( i = 0; i < flist.size(); i++ ) { - if ( IsDirectory( mCurPath + flist[i] ) ) { + if ( FoldersFirst() && IsDirectory( mCurPath + flist[i] ) ) { folders.push_back( flist[i] ); } else { accepted = false; @@ -155,11 +167,17 @@ void cUICommonDialog::RefreshFolder() { } } - std::sort( folders.begin(), folders.end() ); - std::sort( files.begin(), files.end() ); + if ( SortAlphabetically() ) { + std::sort( folders.begin(), folders.end() ); + std::sort( files.begin(), files.end() ); + } mList->Clear(); - mList->AddListBoxItems( folders ); + + if ( FoldersFirst() ) { + mList->AddListBoxItems( folders ); + } + mList->AddListBoxItems( files ); } @@ -212,6 +230,14 @@ Uint32 cUICommonDialog::OnMessage( const cUIMessage *Msg ) { void cUICommonDialog::Open() { if ( "" != mList->GetItemSelectedText() ) { + if ( !AllowFolderSelect() ) { + if ( IsDirectory( GetFullPath() ) ) + return; + } else { + if ( !IsDirectory( GetFullPath() ) ) + return; + } + SendCommonEvent( cUIEvent::EventOpenFile ); CloseWindow(); @@ -228,6 +254,46 @@ void cUICommonDialog::AddFilePattern( std::string pattern, bool select ) { } } +bool cUICommonDialog::IsSaveDialog() { + return 0 != ( mCDLFlags & CDL_FLAG_SAVE_DIALOG ); +} + +bool cUICommonDialog::SortAlphabetically() { + return 0 != ( mCDLFlags & CDL_FLAG_SORT_ALPHABETICALLY ); +} + +bool cUICommonDialog::FoldersFirst() { + return 0 != ( mCDLFlags & CDL_FLAG_FOLDERS_FISRT ); +} + +bool cUICommonDialog::AllowFolderSelect() { + return 0 != ( mCDLFlags & CDL_FLAG_ALLOW_FOLDER_SELECT ); +} + +void cUICommonDialog::SortAlphabetically( const bool& sortAlphabetically ) { + SetFlagValue( &mCDLFlags, CDL_FLAG_SORT_ALPHABETICALLY, sortAlphabetically ? 1 : 0 ); + RefreshFolder(); +} + +void cUICommonDialog::FoldersFirst( const bool& foldersFirst ) { + SetFlagValue( &mCDLFlags, CDL_FLAG_FOLDERS_FISRT , foldersFirst ? 1 : 0 ); + RefreshFolder(); +} + +void cUICommonDialog::AllowFolderSelect( const bool& allowFolderSelect ) { + SetFlagValue( &mCDLFlags, CDL_FLAG_ALLOW_FOLDER_SELECT, allowFolderSelect ? 1 : 0 ); +} + +std::string cUICommonDialog::GetFullPath() { + std::string tPath = mCurPath; + + DirPathAddSlashAtEnd( tPath ); + + tPath += GetCurFile(); + + return tPath; +} + std::string cUICommonDialog::GetCurPath() const { return mCurPath; } diff --git a/src/ui/cuicommondialog.hpp b/src/ui/cuicommondialog.hpp index edb643546..d9066adb4 100644 --- a/src/ui/cuicommondialog.hpp +++ b/src/ui/cuicommondialog.hpp @@ -13,21 +13,34 @@ namespace EE { namespace UI { class cUICommonDialog : public cUIWindow { public: + enum CommonDialogFlags { + CDL_FLAG_SAVE_DIALOG = ( 1 << 0 ), + CDL_FLAG_FOLDERS_FISRT = ( 1 << 1 ), + CDL_FLAG_SORT_ALPHABETICALLY = ( 1 << 2 ), + CDL_FLAG_ALLOW_FOLDER_SELECT = ( 1 << 3 ) + }; + class CreateParams : public cUIWindow::CreateParams { public: inline CreateParams() : cUIWindow::CreateParams(), - DefaultDirectory( GetProcessPath() ) + DefaultDirectory( GetProcessPath() ), + DefaultFilePattern( "*" ), + CDLFlags( CDL_FLAG_FOLDERS_FISRT | CDL_FLAG_SORT_ALPHABETICALLY ) { } inline ~CreateParams() {} std::string DefaultDirectory; + std::string DefaultFilePattern; + Uint32 CDLFlags; }; cUICommonDialog( const cUICommonDialog::CreateParams& Params ); + ~cUICommonDialog(); + void RefreshFolder(); virtual Uint32 OnMessage( const cUIMessage *Msg ); @@ -38,6 +51,8 @@ class cUICommonDialog : public cUIWindow { std::string GetCurFile() const; + std::string GetFullPath(); + cUIPushButton * GetButtonOpen() const; cUIPushButton * GetButtonCancel() const; @@ -53,6 +68,20 @@ class cUICommonDialog : public cUIWindow { cUIDropDownList * GetFiletypeList() const; void AddFilePattern( std::string pattern, bool select = false ); + + bool IsSaveDialog(); + + bool SortAlphabetically(); + + bool FoldersFirst(); + + bool AllowFolderSelect(); + + void SortAlphabetically( const bool& sortAlphabetically ); + + void FoldersFirst( const bool& foldersFirst ); + + void AllowFolderSelect( const bool& allowFolderSelect ); protected: std::string mCurPath; cUIPushButton * mButtonOpen; @@ -62,6 +91,7 @@ class cUICommonDialog : public cUIWindow { cUITextInput * mPath; cUITextInput * mFile; cUIDropDownList * mFiletype; + Uint32 mCDLFlags; }; }} diff --git a/src/ui/cuicontrol.cpp b/src/ui/cuicontrol.cpp index 6a8a48c07..01beb77cb 100644 --- a/src/ui/cuicontrol.cpp +++ b/src/ui/cuicontrol.cpp @@ -45,8 +45,7 @@ cUIControl::~cUIControl() { eeSAFE_DELETE( mBackground ); eeSAFE_DELETE( mBorder ); - while( NULL != mChild ) - eeDelete( mChild ); + ChildDeleteAll(); if ( NULL != mParentCtrl ) mParentCtrl->ChildRemove( this ); @@ -607,8 +606,9 @@ void cUIControl::MatrixUnset() { } void cUIControl::ChildDeleteAll() { - while( NULL != mChild ) + while( NULL != mChild ) { eeDelete( mChild ); + } } void cUIControl::ChildAdd( cUIControl * ChildCtrl ) { diff --git a/src/ui/cuiwindow.cpp b/src/ui/cuiwindow.cpp index 9f99eab13..057b8acfe 100644 --- a/src/ui/cuiwindow.cpp +++ b/src/ui/cuiwindow.cpp @@ -11,6 +11,7 @@ cUIWindow::cUIWindow( const cUIWindow::CreateParams& Params ) : mButtonMinimize( NULL ), mButtonMaximize( NULL ), mTitle( NULL ), + mModalCtrl( NULL ), mDecoSize( Params.DecorationSize ), mBorderSize( Params.BorderSize ), mMinWindowSize( Params.MinWindowSize ), @@ -118,6 +119,11 @@ void cUIWindow::ButtonCloseClick( const cUIEvent * Event ) { } void cUIWindow::CloseWindow() { + if ( NULL != mModalCtrl ) { + mModalCtrl->Close(); + mModalCtrl = NULL; + } + if ( 0 != cUIThemeManager::instance()->ControlsFadeOutTime() ) CloseFadeOut( cUIThemeManager::instance()->ControlsFadeOutTime() ); else @@ -576,6 +582,19 @@ bool cUIWindow::Show() { StartAlphaAnim( mAlpha, mBaseAlpha, cUIThemeManager::instance()->ControlsFadeInTime() ); } + if ( IsModal() ) { + if ( NULL == mModalCtrl ) { + cUIControl * Ctrl = cUIManager::instance()->MainControl(); + mModalCtrl = eeNew( cUIControl, ( cUIControl::CreateParams( Ctrl , eeVector2i(0,0), Ctrl->Size(), UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ) ) ); + } + + mModalCtrl->Enabled( true ); + mModalCtrl->Visible( true ); + mModalCtrl->ToFront(); + + ToFront(); + } + return true; } @@ -593,6 +612,11 @@ bool cUIWindow::Hide() { cUIManager::instance()->MainControl()->SetFocus(); + if ( NULL != mModalCtrl ) { + mModalCtrl->Enabled( false ); + mModalCtrl->Visible( false ); + } + return true; } @@ -722,4 +746,12 @@ bool cUIWindow::RemoveShortcut( const Uint32& KeyCode, const Uint32& Mod ) { return false; } +bool cUIWindow::IsModal() { + return 0 != ( mWinFlags & UI_WIN_MODAL ); +} + +cUIControl * cUIWindow::GetModalControl() const { + return mModalCtrl; +} + }} diff --git a/src/ui/cuiwindow.hpp b/src/ui/cuiwindow.hpp index 8a03003fe..2af1f4baf 100644 --- a/src/ui/cuiwindow.hpp +++ b/src/ui/cuiwindow.hpp @@ -17,7 +17,8 @@ class cUIWindow : public cUIComplexControl { UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS = ( 1 << 4 ), UI_WIN_RESIZEABLE = ( 1 << 5 ), UI_WIN_DRAGABLE_CONTAINER = ( 1 << 6 ), - UI_WIN_SHARE_ALPHA_WITH_CHILDS = ( 1 << 7 ) + UI_WIN_SHARE_ALPHA_WITH_CHILDS = ( 1 << 7 ), + UI_WIN_MODAL = ( 1 << 8 ) }; class CreateParams : public cUIComplexControl::CreateParams { @@ -92,6 +93,10 @@ class cUIWindow : public cUIComplexControl { bool AddShortcut( const Uint32& KeyCode, const Uint32& Mod, cUIPushButton * Button ); bool RemoveShortcut( const Uint32& KeyCode, const Uint32& Mod ); + + bool IsModal(); + + cUIControl * GetModalControl() const; protected: class KeyboardShortcut { public: @@ -139,6 +144,8 @@ class cUIWindow : public cUIComplexControl { cUIComplexControl * mButtonMaximize; cUITextBox * mTitle; + cUIControl * mModalCtrl; + eeSize mDecoSize; eeSize mBorderSize; eeSize mMinWindowSize; diff --git a/src/utils/vector2.hpp b/src/utils/vector2.hpp index 2b1590f3d..66842c8ba 100755 --- a/src/utils/vector2.hpp +++ b/src/utils/vector2.hpp @@ -298,6 +298,7 @@ typedef Vector2 eeVector2i; typedef Vector2 eeVector2f; typedef Vector2 eeVector2d; typedef Vector2 eeVector2ff; +typedef Vector2 eeVector2u; }}