Adds z-index properties to TileSets.
This commit is contained in:
parent
b6a7c5693f
commit
20dd2204db
@ -149,6 +149,7 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
|
||||
p_library->tile_set_light_occluder(id, occluder);
|
||||
p_library->tile_set_occluder_offset(id, -phys_offset);
|
||||
p_library->tile_set_navigation_polygon_offset(id, -phys_offset);
|
||||
p_library->tile_set_z_index(id, mi->get_z_index());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,6 +304,7 @@ void TileMap::_update_dirty_quadrants() {
|
||||
}
|
||||
q.occluder_instances.clear();
|
||||
Ref<ShaderMaterial> prev_material;
|
||||
int prev_z_index;
|
||||
RID prev_canvas_item;
|
||||
RID prev_debug_canvas_item;
|
||||
|
||||
@ -324,11 +325,12 @@ void TileMap::_update_dirty_quadrants() {
|
||||
continue;
|
||||
|
||||
Ref<ShaderMaterial> mat = tile_set->tile_get_material(c.id);
|
||||
int z_index = tile_set->tile_get_z_index(c.id);
|
||||
|
||||
RID canvas_item;
|
||||
RID debug_canvas_item;
|
||||
|
||||
if (prev_canvas_item == RID() || prev_material != mat) {
|
||||
if (prev_canvas_item == RID() || prev_material != mat || prev_z_index != z_index) {
|
||||
|
||||
canvas_item = vs->canvas_item_create();
|
||||
if (mat.is_valid())
|
||||
@ -339,6 +341,7 @@ void TileMap::_update_dirty_quadrants() {
|
||||
xform.set_origin(q.pos);
|
||||
vs->canvas_item_set_transform(canvas_item, xform);
|
||||
vs->canvas_item_set_light_mask(canvas_item, get_light_mask());
|
||||
vs->canvas_item_set_z_index(canvas_item, z_index);
|
||||
|
||||
q.canvas_items.push_back(canvas_item);
|
||||
|
||||
@ -354,6 +357,7 @@ void TileMap::_update_dirty_quadrants() {
|
||||
|
||||
prev_canvas_item = canvas_item;
|
||||
prev_material = mat;
|
||||
prev_z_index = z_index;
|
||||
|
||||
} else {
|
||||
canvas_item = prev_canvas_item;
|
||||
|
@ -142,6 +142,8 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
|
||||
tile_set_navigation_polygon(id, p_value);
|
||||
else if (what == "navigation_offset")
|
||||
tile_set_navigation_polygon_offset(id, p_value);
|
||||
else if (what == "z_index")
|
||||
tile_set_z_index(id, p_value);
|
||||
else
|
||||
return false;
|
||||
|
||||
@ -239,6 +241,8 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
r_ret = tile_get_navigation_polygon(id);
|
||||
else if (what == "navigation_offset")
|
||||
r_ret = tile_get_navigation_polygon_offset(id);
|
||||
else if (what == "z_index")
|
||||
r_ret = tile_get_z_index(id);
|
||||
else
|
||||
return false;
|
||||
|
||||
@ -278,6 +282,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D", PROPERTY_USAGE_EDITOR));
|
||||
p_list->push_back(PropertyInfo(Variant::BOOL, pre + "shape_one_way", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
|
||||
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "shapes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
|
||||
p_list->push_back(PropertyInfo(Variant::INT, pre + "z_index", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -748,6 +753,19 @@ Vector<TileSet::ShapeData> TileSet::tile_get_shapes(int p_id) const {
|
||||
return tile_map[p_id].shapes_data;
|
||||
}
|
||||
|
||||
int TileSet::tile_get_z_index(int p_id) const {
|
||||
|
||||
ERR_FAIL_COND_V(!tile_map.has(p_id), 0);
|
||||
return tile_map[p_id].z_index;
|
||||
}
|
||||
|
||||
void TileSet::tile_set_z_index(int p_id, int p_z_index) {
|
||||
|
||||
ERR_FAIL_COND(!tile_map.has(p_id));
|
||||
tile_map[p_id].z_index = p_z_index;
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
|
||||
|
||||
ERR_FAIL_COND(!tile_map.has(p_id));
|
||||
@ -929,6 +947,8 @@ void TileSet::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("tile_get_light_occluder", "id"), &TileSet::tile_get_light_occluder);
|
||||
ClassDB::bind_method(D_METHOD("tile_set_occluder_offset", "id", "occluder_offset"), &TileSet::tile_set_occluder_offset);
|
||||
ClassDB::bind_method(D_METHOD("tile_get_occluder_offset", "id"), &TileSet::tile_get_occluder_offset);
|
||||
ClassDB::bind_method(D_METHOD("tile_set_z_index", "id", "z_index"), &TileSet::tile_set_z_index);
|
||||
ClassDB::bind_method(D_METHOD("tile_get_z_index", "id"), &TileSet::tile_get_z_index);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("remove_tile", "id"), &TileSet::remove_tile);
|
||||
ClassDB::bind_method(D_METHOD("clear"), &TileSet::clear);
|
||||
|
@ -113,11 +113,13 @@ private:
|
||||
Color modulate;
|
||||
TileMode tile_mode;
|
||||
AutotileData autotile_data;
|
||||
int z_index;
|
||||
|
||||
// Default modulate for back-compat
|
||||
explicit TileData() :
|
||||
tile_mode(SINGLE_TILE),
|
||||
modulate(1, 1, 1) {}
|
||||
modulate(1, 1, 1),
|
||||
z_index(0) {}
|
||||
};
|
||||
|
||||
Map<int, TileData> tile_map;
|
||||
@ -220,6 +222,9 @@ public:
|
||||
Ref<NavigationPolygon> autotile_get_navigation_polygon(int p_id, const Vector2 &p_coord) const;
|
||||
const Map<Vector2, Ref<NavigationPolygon> > &autotile_get_navigation_map(int p_id) const;
|
||||
|
||||
void tile_set_z_index(int p_id, int p_z_index);
|
||||
int tile_get_z_index(int p_id) const;
|
||||
|
||||
void remove_tile(int p_id);
|
||||
|
||||
bool has_tile(int p_id) const;
|
||||
|
Loading…
Reference in New Issue
Block a user