From 69f6f787c07f0c9e6cf1a5a161999585e180533b Mon Sep 17 00:00:00 2001 From: Guilherme Felipe Date: Mon, 2 Jul 2018 10:39:39 -0300 Subject: Add Z-Index for Autotile --- scene/2d/tile_map.cpp | 4 ++++ scene/resources/tile_set.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++ scene/resources/tile_set.h | 4 ++++ 3 files changed, 55 insertions(+) (limited to 'scene') diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 8fe65f53a9..641cb161ca 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -327,6 +327,10 @@ void TileMap::update_dirty_quadrants() { Ref mat = tile_set->tile_get_material(c.id); int z_index = tile_set->tile_get_z_index(c.id); + if (tile_set->tile_get_tile_mode(c.id) == TileSet::AUTO_TILE) { + z_index += tile_set->autotile_get_z_index(c.id, Vector2(c.autotile_coord_x, c.autotile_coord_y)); + } + RID canvas_item; RID debug_canvas_item; diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index f852ecd7eb..88dbc67e01 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -129,6 +129,22 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { } p.pop_front(); } + } else if (what == "z_index_map") { + tile_map[id].autotile_data.z_index_map.clear(); + Array p = p_value; + Vector3 val; + Vector2 v; + int z_index; + while (p.size() > 0) { + val = p[0]; + if (val.z > 1) { + v.x = val.x; + v.y = val.y; + z_index = (int)val.z; + tile_map[id].autotile_data.z_index_map[v] = z_index; + } + p.pop_front(); + } } } else if (what == "shape") tile_set_shape(id, 0, p_value); @@ -228,6 +244,19 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { } } r_ret = p; + } else if (what == "z_index_map") { + Array p; + Vector3 v; + for (Map::Element *E = tile_map[id].autotile_data.z_index_map.front(); E; E = E->next()) { + if (E->value() != 0) { + //Don't save default value + v.x = E->key().x; + v.y = E->key().y; + v.z = E->value(); + p.push_back(v); + } + } + r_ret = p; } } else if (what == "shape") r_ret = tile_get_shape(id, 0); @@ -278,6 +307,7 @@ void TileSet::_get_property_list(List *p_list) const { p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/priority_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); + p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/z_index_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); } else if (tile_get_tile_mode(id) == ATLAS_TILE) { p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); @@ -476,6 +506,23 @@ int TileSet::autotile_get_subtile_priority(int p_id, const Vector2 &p_coord) { return 1; } +void TileSet::autotile_set_z_index(int p_id, const Vector2 &p_coord, int p_z_index) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + tile_map[p_id].autotile_data.z_index_map[p_coord] = p_z_index; + emit_changed(); +} + +int TileSet::autotile_get_z_index(int p_id, const Vector2 &p_coord) { + + ERR_FAIL_COND_V(!tile_map.has(p_id), 1); + if (tile_map[p_id].autotile_data.z_index_map.has(p_coord)) { + return tile_map[p_id].autotile_data.z_index_map[p_coord]; + } + //When not custom z index set return the default value + return 0; +} + const Map &TileSet::autotile_get_priority_map(int p_id) const { static Map dummy; diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index 1802bf12b6..2ab771b1b0 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -87,6 +87,7 @@ public: Map > occluder_map; Map > navpoly_map; Map priority_map; + Map z_index_map; // Default size to prevent invalid value explicit AutotileData() : @@ -172,6 +173,9 @@ public: int autotile_get_subtile_priority(int p_id, const Vector2 &p_coord); const Map &autotile_get_priority_map(int p_id) const; + void autotile_set_z_index(int p_id, const Vector2 &p_coord, int p_z_index); + int autotile_get_z_index(int p_id, const Vector2 &p_coord); + void autotile_set_bitmask(int p_id, Vector2 p_coord, uint16_t p_flag); uint16_t autotile_get_bitmask(int p_id, Vector2 p_coord); const Map &autotile_get_bitmask_map(int p_id); -- cgit v1.2.3