From 6edbf33ac6d4fe61ced487d98721f0c8ff48506b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 28 Jan 2018 04:55:26 -0300 Subject: [PATCH] Some bugfixes and added Map Editor tool. --HG-- branch : dev-2.1 --- .hgignore | 1 + include/eepp/maps/mapeditor/mapeditor.hpp | 2 + include/eepp/system/color.hpp | 2 +- premake4.lua | 6 ++ projects/linux/ee.files | 1 + src/eepp/core/memorymanager.cpp | 5 ++ src/eepp/graphics/textureatlasloader.cpp | 2 +- src/eepp/maps/gameobject.cpp | 2 +- src/eepp/maps/gameobjectsprite.cpp | 14 +++-- src/eepp/maps/mapeditor/mapeditor.cpp | 4 ++ src/eepp/maps/tilemap.cpp | 22 ++++++-- src/tools/mapeditor/mapeditor.cpp | 68 +++++++++++++++++++++++ 12 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 src/tools/mapeditor/mapeditor.cpp diff --git a/.hgignore b/.hgignore index fb7a8329c..63a143739 100644 --- a/.hgignore +++ b/.hgignore @@ -49,3 +49,4 @@ bin/libeepp.dylib *.iml .idea eepp.kdev4 +bin/eepp-MapEditor* diff --git a/include/eepp/maps/mapeditor/mapeditor.hpp b/include/eepp/maps/mapeditor/mapeditor.hpp index 0b7154968..df0068c68 100644 --- a/include/eepp/maps/mapeditor/mapeditor.hpp +++ b/include/eepp/maps/mapeditor/mapeditor.hpp @@ -38,6 +38,8 @@ class EE_API MapEditor { public: typedef cb::Callback0 MapEditorCloseCb; + static MapEditor * New( UIWindow * AttatchTo = NULL, const MapEditorCloseCb& callback = MapEditorCloseCb() ); + MapEditor( UIWindow * AttatchTo = NULL, const MapEditorCloseCb& callback = MapEditorCloseCb() ); ~MapEditor(); diff --git a/include/eepp/system/color.hpp b/include/eepp/system/color.hpp index abd52f5b4..be3a1fb7d 100755 --- a/include/eepp/system/color.hpp +++ b/include/eepp/system/color.hpp @@ -140,7 +140,7 @@ class tColor { //! @return The color represented as an Uint32 ( as 0xRRGGBBAA for Little Endian ) Uint32 getValue() const { - return Value; + return BitOp::swapBE32( Value ); } /** @brief Assign the RGBA colors, from each component. */ diff --git a/premake4.lua b/premake4.lua index fc66e7d74..7b2a508f3 100644 --- a/premake4.lua +++ b/premake4.lua @@ -959,6 +959,12 @@ solution "eepp" files { "src/tools/textureatlaseditor/*.cpp" } build_link_configuration( "eepp-TextureAtlasEditor", true ) + project "eepp-mapeditor" + set_kind() + language "C++" + files { "src/tools/mapeditor/*.cpp" } + build_link_configuration( "eepp-MapEditor", true ) + if os.isfile("external_projects.lua") then dofile("external_projects.lua") end diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 31c1dfbf1..a5c9c4594 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -6,6 +6,7 @@ ../../src/eepp/window/backend/SFML/displaymanagersfml.cpp ../../src/eepp/window/backend/SFML/displaymanagersfml.hpp ../../src/eepp/window/displaymanager.cpp +../../src/tools/mapeditor/mapeditor.cpp ../../src/tools/textureatlaseditor/textureatlaseditor.cpp ../../include/eepp/graphics/arcdrawable.hpp ../../include/eepp/graphics/circledrawable.hpp diff --git a/src/eepp/core/memorymanager.cpp b/src/eepp/core/memorymanager.cpp index ca710cfae..0253cbe11 100644 --- a/src/eepp/core/memorymanager.cpp +++ b/src/eepp/core/memorymanager.cpp @@ -6,8 +6,11 @@ #include #include #include +#include + using namespace EE::System; +using namespace EE::Window; namespace EE { @@ -90,6 +93,8 @@ void MemoryManager::showResults() { EE::PrintDebugInLog = false; } + Engine::destroySingleton(); + eePRINTL("\n|--Memory Manager Report-------------------------------------|"); eePRINTL("|"); diff --git a/src/eepp/graphics/textureatlasloader.cpp b/src/eepp/graphics/textureatlasloader.cpp index 46fad8bcd..3b41d6c27 100644 --- a/src/eepp/graphics/textureatlasloader.cpp +++ b/src/eepp/graphics/textureatlasloader.cpp @@ -319,7 +319,7 @@ bool TextureAtlasLoader::updateTextureAtlas() { if ( NULL != tTextureRegion ) { tSh->OffsetX = tTextureRegion->getOffset().x; - tSh->OffsetY = tTextureRegion->getOffset().x; + tSh->OffsetY = tTextureRegion->getOffset().y; tSh->DestWidth = (Int32)tTextureRegion->getDestSize().x; tSh->DestHeight = (Int32)tTextureRegion->getDestSize().y; } diff --git a/src/eepp/maps/gameobject.cpp b/src/eepp/maps/gameobject.cpp index e4408130e..d92bed66a 100644 --- a/src/eepp/maps/gameobject.cpp +++ b/src/eepp/maps/gameobject.cpp @@ -128,7 +128,7 @@ RenderMode GameObject::getRenderModeFromFlags() { } BlendMode GameObject::getBlendModeFromFlags() { - return isBlendAdd() ? BlendAdd : BlendAlpha; + return isBlendAdd() ? BlendMode( BlendMode::DstColor, BlendMode::One ) : BlendAlpha; } MapLayer * GameObject::getLayer() const { diff --git a/src/eepp/maps/gameobjectsprite.cpp b/src/eepp/maps/gameobjectsprite.cpp index 7fe7e440c..5eb6fe171 100644 --- a/src/eepp/maps/gameobjectsprite.cpp +++ b/src/eepp/maps/gameobjectsprite.cpp @@ -32,10 +32,14 @@ bool GameObjectSprite::isType( const Uint32& type ) { void GameObjectSprite::draw() { if ( NULL != mSprite ) { - TextureRegion * TextureRegion = mSprite->getCurrentTextureRegion(); - Sizef destSizeO = TextureRegion->getDestSize(); - Sizei realSize = TextureRegion->getRealSize(); - TextureRegion->setDestSize( Sizef( (Float)realSize.getWidth(), (Float)realSize.getHeight() ) ); + TextureRegion * textureRegion = mSprite->getCurrentTextureRegion(); + + if ( NULL == textureRegion ) + return; + + Sizef destSizeO = textureRegion->getDestSize(); + Sizei realSize = textureRegion->getRealSize(); + textureRegion->setDestSize( Sizef( (Float)realSize.getWidth(), (Float)realSize.getHeight() ) ); mSprite->setRotation( getRotation() ); @@ -73,7 +77,7 @@ void GameObjectSprite::draw() { mSprite->draw(); - TextureRegion->setDestSize( destSizeO ); + textureRegion->setDestSize( destSizeO ); } } diff --git a/src/eepp/maps/mapeditor/mapeditor.cpp b/src/eepp/maps/mapeditor/mapeditor.cpp index 5b8a43a57..46a449312 100644 --- a/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/eepp/maps/mapeditor/mapeditor.cpp @@ -37,6 +37,10 @@ static UITextView * createTextBox( const String& Text = "", UINode * Parent = NU return Ctrl; } +MapEditor *MapEditor::New(UIWindow * AttatchTo, const MapEditor::MapEditorCloseCb & callback) { + return eeNew( MapEditor, ( AttatchTo, callback ) ); +} + MapEditor::MapEditor( UIWindow * AttatchTo, const MapEditorCloseCb& callback ) : mUIWindow( AttatchTo ), mTheme( UIThemeManager::instance()->getDefaultTheme() ), diff --git a/src/eepp/maps/tilemap.cpp b/src/eepp/maps/tilemap.cpp index e27eabf08..6600625f4 100644 --- a/src/eepp/maps/tilemap.cpp +++ b/src/eepp/maps/tilemap.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -836,7 +837,15 @@ bool TileMap::loadFromStream( IOStream& IOS ) { if ( NULL == TextureAtlasManager::instance()->getByName( sgname ) ) { TextureAtlasLoader * tgl = eeNew( TextureAtlasLoader, () ); - tgl->loadFromFile( Sys::getProcessPath() + TextureAtlases[i] ); + if ( !VirtualFileSystem::instance()->fileExists( TextureAtlases[i] ) && !FileSystem::fileExists( TextureAtlases[i] ) ) { + std::string path( FileSystem::fileRemoveFileName( mPath ) ); + + if ( FileSystem::fileExists( path + TextureAtlases[i] ) || VirtualFileSystem::instance()->fileExists( path + TextureAtlases[i] ) ) { + TextureAtlases[i] = path + TextureAtlases[i]; + } + } + + tgl->loadFromFile( TextureAtlases[i] ); eeSAFE_DELETE( tgl ); } @@ -1046,7 +1055,6 @@ bool TileMap::loadFromFile( const std::string& path ) { Pack * tPack = PackManager::instance()->exists( tPath ) ; if ( NULL != tPack ) { - mPath = tPath; return loadFromPack( tPack, tPath ); } } @@ -1060,6 +1068,8 @@ bool TileMap::loadFromPack( Pack * Pack, const std::string& FilePackPath ) { Pack->extractFileToMemory( FilePackPath, PData ); + mPath = FilePackPath; + return loadFromMemory( reinterpret_cast ( PData.data ), PData.size ); } @@ -1120,6 +1130,10 @@ void TileMap::saveToStream( IOStream& IOS ) { memset( tSG.Path, 0, MAP_TEXTUREATLAS_PATH_SIZE ); + if ( !mPath.empty() && String::startsWith( TextureAtlases[i], FileSystem::fileRemoveFileName( mPath ) ) ) { + TextureAtlases[i] = TextureAtlases[i].substr( FileSystem::fileRemoveFileName( mPath ).size() ); + } + String::strCopy( tSG.Path, TextureAtlases[i].c_str(), MAP_TEXTUREATLAS_PATH_SIZE ); IOS.write( (const char*)&tSG, sizeof(sMapTextureAtlas) ); @@ -1359,11 +1373,11 @@ void TileMap::saveToStream( IOStream& IOS ) { void TileMap::saveToFile( const std::string& path ) { if ( !FileSystem::isDirectory( path ) ) { + mPath = path; + IOStreamFile IOS( path, std::ios::out | std::ios::binary ); saveToStream( IOS ); - - mPath = path; } } diff --git a/src/tools/mapeditor/mapeditor.cpp b/src/tools/mapeditor/mapeditor.cpp new file mode 100644 index 000000000..c6c784397 --- /dev/null +++ b/src/tools/mapeditor/mapeditor.cpp @@ -0,0 +1,68 @@ +#include + +EE::Window::Window * win = NULL; +UIMessageBox * MsgBox = NULL; + +void mainLoop() { + win->getInput()->update(); + + if ( win->getInput()->isKeyUp( KEY_ESCAPE ) && NULL == MsgBox ) { + MsgBox = UIMessageBox::New( MSGBOX_OKCANCEL, "Do you really want to close the current map?\nAll changes will be lost." ); + MsgBox->addEventListener( UIEvent::MsgBoxConfirmClick, cb::Make1( []( const UIEvent * event ) { win->close(); } ) ); + MsgBox->addEventListener( UIEvent::OnClose, cb::Make1( []( const UIEvent * event ) { MsgBox = NULL; } ) ); + MsgBox->setTitle( "Close Map?" ); + MsgBox->center(); + MsgBox->show(); + } + + UIManager::instance()->update(); + + if ( UIManager::instance()->getMainControl()->invalidated() ) { + win->clear(); + + UIManager::instance()->draw(); + + win->display(); + } else { + Sys::sleep( Milliseconds(8) ); + } +} + +EE_MAIN_FUNC int main (int argc, char * argv []) { + Display * currentDisplay = Engine::instance()->getDisplayManager()->getDisplayIndex(0); + Float pixelDensity = PixelDensity::toFloat( currentDisplay->getPixelDensity() ); + DisplayMode currentMode = currentDisplay->getCurrentMode(); + + Uint32 width = eemin( currentMode.Width, (Uint32)( 1280 * pixelDensity ) ); + Uint32 height = eemin( currentMode.Height, (Uint32)( 720 * pixelDensity ) ); + + win = Engine::instance()->createWindow( WindowSettings( width, height, "eepp - Texture Atlas Editor", WindowStyle::Default, WindowBackend::Default, 32, "assets/icon/ee.png", pixelDensity ), ContextSettings( true, GLv_default, true, 24, 1, 0, false ) ); + + if ( win->isOpen() ) { + UIManager::instance()->init( UI_MANAGER_USE_DRAW_INVALIDATION ); + + { + std::string pd; + if ( PixelDensity::getPixelDensity() >= 1.5f ) pd = "1.5x"; + else if ( PixelDensity::getPixelDensity() >= 2.f ) pd = "2x"; + + TextureAtlasLoader tgl( "assets/ui/uitheme" + pd + ".eta" ); + + UITheme * theme = UITheme::loadFromTextureAtlas( UIThemeDefault::New( "uitheme" + pd, "uitheme" + pd ), TextureAtlasManager::instance()->getByName( "uitheme" + pd ) ); + + FontTrueType * font = FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" ); + + UIThemeManager::instance()->setDefaultEffectsEnabled( true )->setDefaultTheme( theme )->setDefaultFont( font )->add( theme ); + } + + MapEditor::New(); + + win->runMainLoop( &mainLoop ); + } + + Engine::destroySingleton(); + + MemoryManager::showResults(); + + return EXIT_SUCCESS; +}