diff options
author | ShyRed <ShyRed@users.noreply.github.com> | 2018-03-11 12:24:50 +0100 |
---|---|---|
committer | ShyRed <ShyRed@users.noreply.github.com> | 2018-03-11 12:24:50 +0100 |
commit | 67f4944a21487dce92746bdb716303a7860b081c (patch) | |
tree | f03e349c3a265e8dc1d5ea2525ef4afa8b553f57 /scene | |
parent | eceba5aa6a36521c878cf976845123e820d27161 (diff) |
Update TileMap when its TileSet changes
Make TileMap monitor its TileSet for changes and emit a signal when the TileSet changes. This makes the editor update and show the updated version of the TileSet.
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/tile_map.cpp | 19 | ||||
-rw-r--r-- | scene/2d/tile_map.h | 2 |
2 files changed, 18 insertions, 3 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 2aa55e2825..3af77bfcc7 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -142,16 +142,20 @@ void TileMap::_update_quadrant_transform() { void TileMap::set_tileset(const Ref<TileSet> &p_tileset) { - if (tile_set.is_valid()) + if (tile_set.is_valid()) { tile_set->disconnect("changed", this, "_recreate_quadrants"); + tile_set->remove_change_receptor(this); + } _clear_quadrants(); tile_set = p_tileset; - if (tile_set.is_valid()) + if (tile_set.is_valid()) { tile_set->connect("changed", this, "_recreate_quadrants"); - else + tile_set->add_change_receptor(this); + } else { clear(); + } _recreate_quadrants(); emit_signal("settings_changed"); @@ -1573,6 +1577,12 @@ void TileMap::_bind_methods() { BIND_ENUM_CONSTANT(TILE_ORIGIN_BOTTOM_LEFT); } +void TileMap::_changed_callback(Object *p_changed, const char *p_prop) { + if (tile_set.is_valid() && tile_set.ptr() == p_changed) { + emit_signal("settings_changed"); + } +} + TileMap::TileMap() { rect_cache_dirty = true; @@ -1601,5 +1611,8 @@ TileMap::TileMap() { TileMap::~TileMap() { + if (tile_set.is_valid()) + tile_set->remove_change_receptor(this); + clear(); } diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 973e527b42..104842d52f 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -217,6 +217,8 @@ protected: void _notification(int p_what); static void _bind_methods(); + virtual void _changed_callback(Object *p_changed, const char *p_prop); + public: enum { INVALID_CELL = -1 |