mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-23 10:35:35 -04:00
Reload the tileset image when imported from a tmx file
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
#include "TileSet.h"
|
||||
#include "TileMap.h"
|
||||
|
||||
TileMapImporterDialog::TileMapImporterDialog(wxWindow* parent, TileSet tileset, TileMap tilemap, gd::ResourcesManager &resManager)
|
||||
TileMapImporterDialog::TileMapImporterDialog(wxWindow* parent, TileSet tileset, TileMap tilemap, gd::Project &project)
|
||||
: TileMapImporterDialogBase(parent),
|
||||
m_tileset(tileset),
|
||||
m_tilemap(tilemap),
|
||||
m_resManager(resManager)
|
||||
m_project(project)
|
||||
{
|
||||
m_okBt->Disable();
|
||||
}
|
||||
@@ -41,7 +41,7 @@ void TileMapImporterDialog::OnImportButtonClicked(wxCommandEvent& event)
|
||||
m_importOptionsCheckList->IsChecked(1),
|
||||
m_importOptionsCheckList->IsChecked(2),
|
||||
m_importOptionsCheckList->IsChecked(3),
|
||||
m_resManager))
|
||||
m_project))
|
||||
{
|
||||
m_okBt->Disable();
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
class TileSet;
|
||||
class TileMap;
|
||||
namespace gd{ class ResourcesManager; }
|
||||
namespace gd{ class Project; }
|
||||
|
||||
class TileMapImporterDialog : public TileMapImporterDialogBase
|
||||
{
|
||||
public:
|
||||
TileMapImporterDialog(wxWindow* parent, TileSet tileset, TileMap tilemap, gd::ResourcesManager &resManager);
|
||||
TileMapImporterDialog(wxWindow* parent, TileSet tileset, TileMap tilemap, gd::Project &project);
|
||||
virtual ~TileMapImporterDialog();
|
||||
|
||||
const TileSet& GetTileSet() const { return m_tileset; }
|
||||
@@ -27,7 +27,7 @@ protected:
|
||||
private:
|
||||
TileSet m_tileset;
|
||||
TileMap m_tilemap;
|
||||
gd::ResourcesManager &m_resManager;
|
||||
gd::Project &m_project;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -222,7 +222,7 @@ void TileMapObjectEditor::OnUndoToolClicked(wxCommandEvent& event)
|
||||
|
||||
void TileMapObjectEditor::OnTmxImportButtonClicked(wxCommandEvent& event)
|
||||
{
|
||||
TileMapImporterDialog dialog(this, tileSet, tileMap, game.GetResourcesManager());
|
||||
TileMapImporterDialog dialog(this, tileSet, tileMap, game);
|
||||
|
||||
if(dialog.ShowModal() == 1)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include <wx/filename.h>
|
||||
#include "GDCore/Project/Project.h"
|
||||
#include "GDCore/Project/ResourcesManager.h"
|
||||
#include "GDCore/IDE/NewNameGenerator.h"
|
||||
#include "GDCore/Tools/Localization.h"
|
||||
#include "GDCore/Tools/Log.h"
|
||||
@@ -33,7 +35,7 @@ TileMapImporter::TileMapImporter(const wxString &filePath)
|
||||
|
||||
bool TileMapImporter::ImportTileMap(TileSet &tileSet, TileMap &tileMap,
|
||||
bool importTileMap, bool importTileSetConf, bool importTileSetImage,
|
||||
bool importHitboxes, gd::ResourcesManager &resManager)
|
||||
bool importHitboxes, gd::Project &project)
|
||||
{
|
||||
//Checks the map type
|
||||
if(m_map->GetOrientation() != Tmx::TMX_MO_ORTHOGONAL)
|
||||
@@ -68,15 +70,18 @@ bool TileMapImporter::ImportTileMap(TileSet &tileSet, TileMap &tileMap,
|
||||
|
||||
gd::String newResourceName = gd::NewNameGenerator::Generate(
|
||||
u8"imported_" + imageFileName.GetFullName(),
|
||||
[&resManager](const gd::String &name) -> bool { return resManager.HasResource(name); }
|
||||
[&project](const gd::String &name) -> bool { return project.GetResourcesManager().HasResource(name); }
|
||||
);
|
||||
|
||||
gd::LogMessage(_("The image is imported as ") + "\"" + newResourceName + "\".");
|
||||
|
||||
resManager.AddResource(newResourceName, imageFileName.GetFullPath(wxPATH_UNIX));
|
||||
project.GetResourcesManager().AddResource(newResourceName, imageFileName.GetFullPath(wxPATH_UNIX));
|
||||
|
||||
tileSet.textureName = newResourceName;
|
||||
|
||||
//Reload the texture
|
||||
tileSet.LoadResources(project);
|
||||
|
||||
gd::LogStatus(_("Tileset image importation completed."));
|
||||
}
|
||||
|
||||
@@ -85,9 +90,8 @@ bool TileMapImporter::ImportTileMap(TileSet &tileSet, TileMap &tileMap,
|
||||
{
|
||||
const Tmx::Tileset *importedTileset = m_map->GetTileset(0);
|
||||
|
||||
if(!importTileSetImage && ( //If the tileset image was imported, it should be ok.
|
||||
importedTileset->GetImage()->GetWidth() != tileSet.GetWxBitmap().GetWidth() ||
|
||||
importedTileset->GetImage()->GetHeight() != tileSet.GetWxBitmap().GetHeight()))
|
||||
if(importedTileset->GetImage()->GetWidth() != tileSet.GetWxBitmap().GetWidth() ||
|
||||
importedTileset->GetImage()->GetHeight() != tileSet.GetWxBitmap().GetHeight())
|
||||
{
|
||||
gd::LogWarning(_("Tileset image size is not the same. Some tiles may not be rendered correctly."));
|
||||
}
|
||||
@@ -152,9 +156,9 @@ bool TileMapImporter::ImportTileMap(TileSet &tileSet, TileMap &tileMap,
|
||||
const Tmx::Tileset *importedTileset = m_map->GetTileset(0);
|
||||
|
||||
//Set all tiles not collidable in the tileset
|
||||
tileSet.ResetHitboxes();
|
||||
for(std::size_t i = 0; i < tileSet.GetTilesCount(); i++)
|
||||
tileSet.SetTileCollidable(i, false);
|
||||
tileSet.ResetHitboxes();
|
||||
|
||||
if(!importTileSetConf && !importTileSetImage)
|
||||
CheckTilesCount(tileSet);
|
||||
|
||||
@@ -12,7 +12,7 @@ class TileMap;
|
||||
class TileSet;
|
||||
namespace gd
|
||||
{
|
||||
class ResourcesManager;
|
||||
class Project;
|
||||
}
|
||||
|
||||
class TileMapImporter
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
|
||||
bool ImportTileMap(TileSet &tileSet, TileMap &tileMap,
|
||||
bool importTileMap, bool importTileSetConf, bool importTileSetImage,
|
||||
bool importHitboxes, gd::ResourcesManager &resManager);
|
||||
bool importHitboxes, gd::Project &project);
|
||||
|
||||
private:
|
||||
wxString m_filePath;
|
||||
|
||||
Reference in New Issue
Block a user