From 3870313cfbe2d2960006bcff8b3becb625f8766a Mon Sep 17 00:00:00 2001 From: victorlevasseur Date: Sun, 7 Sep 2014 17:33:09 +0200 Subject: [PATCH] Add an action to change the tileset texture --- .../Basic level editor with tile map object.gdg | 1 + Extensions/TileMapObject/Extension.cpp | 15 +++++++++++++++ Extensions/TileMapObject/RuntimeTileMapObject.cpp | 8 ++++++++ Extensions/TileMapObject/RuntimeTileMapObject.h | 2 ++ 4 files changed, 26 insertions(+) diff --git a/Binaries/Output/Release_Windows/Examples/Basic level editor with tile map object.gdg b/Binaries/Output/Release_Windows/Examples/Basic level editor with tile map object.gdg index 160a7ef580..5d1c96b0ac 100644 --- a/Binaries/Output/Release_Windows/Examples/Basic level editor with tile map object.gdg +++ b/Binaries/Output/Release_Windows/Examples/Basic level editor with tile map object.gdg @@ -41,6 +41,7 @@ + diff --git a/Extensions/TileMapObject/Extension.cpp b/Extensions/TileMapObject/Extension.cpp index 136bd8518a..e563017797 100644 --- a/Extensions/TileMapObject/Extension.cpp +++ b/Extensions/TileMapObject/Extension.cpp @@ -167,6 +167,21 @@ void DeclareTileMapObjectExtension(gd::PlatformExtension & extension) .MarkAsSimple() .codeExtraInformation.SetFunctionName("LoadFromString").SetIncludeFile("TileMapObject/RuntimeTileMapObject.h"); + + + obj.AddAction("ChangeTexture", + _("Change the tileset texture"), + _("Change the tileset texture."), + _("Change the tileset texture of _PARAM0_ to _PARAM1_"), + _("Tileset"), + "CppPlatform/Extensions/TileMapIcon24.png", + "res/TileMapIcon16.png") + .AddParameter("objectList", _("Tile Map Object"), "TileMap", false) + .AddParameter("string", _("The new texture name")) + .AddCodeOnlyParameter("currentScene", "") + .MarkAsSimple() + .codeExtraInformation.SetFunctionName("ChangeTexture").SetIncludeFile("TileMapObject/RuntimeTileMapObject.h"); + #endif } diff --git a/Extensions/TileMapObject/RuntimeTileMapObject.cpp b/Extensions/TileMapObject/RuntimeTileMapObject.cpp index 1fb985f6c3..2a11544922 100644 --- a/Extensions/TileMapObject/RuntimeTileMapObject.cpp +++ b/Extensions/TileMapObject/RuntimeTileMapObject.cpp @@ -217,6 +217,14 @@ void RuntimeTileMapObject::LoadFromString(const std::string &str) needGeneration = true; } +void RuntimeTileMapObject::ChangeTexture(const std::string &textureName, RuntimeScene &scene) +{ + tileSet.Get().textureName = textureName; + tileSet.Get().LoadResources(*(scene.game)); + tileSet.Get().Generate(); + needGeneration = true; +} + namespace { /** diff --git a/Extensions/TileMapObject/RuntimeTileMapObject.h b/Extensions/TileMapObject/RuntimeTileMapObject.h index 3a0cde5d4a..2142b54154 100644 --- a/Extensions/TileMapObject/RuntimeTileMapObject.h +++ b/Extensions/TileMapObject/RuntimeTileMapObject.h @@ -93,6 +93,8 @@ public : std::string SaveAsString() const; void LoadFromString(const std::string &str); + void ChangeTexture(const std::string &textureName, RuntimeScene &scene); + TileSetProxy tileSet; TileMapProxy tileMap;