1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Tilemap fix displaced textures and shapes and added center texture and compatibility mode

This commit fix #22989 #15249 #28206. Main problem is that tilemap displace textures in different tile origins in a strange way and doesn´t respect coincidence between texture and shapes in not uniform tiles. This issue is present in godot 3.0 and godot 3.1. To maintain compatibility are added a compatibility mode and a center texture option. Other related issues and pull request: #28896 #29487 #29519 #29961. Idications of #30204 are added
This commit is contained in:
Ranoller
2019-07-01 22:43:52 +02:00
parent d40dbd6d11
commit 14e2a99129
4 changed files with 207 additions and 22 deletions

View File

@@ -782,8 +782,9 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p
r.position += (r.size + Vector2(spacing, spacing)) * offset;
}
Size2 sc = p_xform.get_scale();
/* For a future CheckBox to Center Texture:
Size2 cell_size = node->get_cell_size(); */
Size2 cell_size = node->get_cell_size();
bool centered_texture = node->is_centered_textures_enabled();
bool compatibility_mode_enabled = node->is_compatibility_mode_enabled();
Rect2 rect = Rect2();
rect.position = node->map_to_world(p_point) + node->get_cell_draw_offset();
@@ -793,13 +794,24 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p
rect.size = r.size;
}
if (compatibility_mode_enabled && !centered_texture) {
if (rect.size.y > rect.size.x) {
if ((p_flip_h && (p_flip_v || p_transpose)) || (p_flip_v && !p_transpose))
tile_ofs.y += rect.size.y - rect.size.x;
} else if (rect.size.y < rect.size.x) {
if ((p_flip_v && (p_flip_h || p_transpose)) || (p_flip_h && !p_transpose))
tile_ofs.x += rect.size.x - rect.size.y;
}
}
if (p_transpose) {
SWAP(tile_ofs.x, tile_ofs.y);
/* For a future CheckBox to Center Texture:
rect.position.x += cell_size.x / 2 - rect.size.y / 2;
rect.position.y += cell_size.y / 2 - rect.size.x / 2;
} else {
rect.position += cell_size / 2 - rect.size / 2; */
if (centered_texture) {
rect.position.x += cell_size.x / 2 - rect.size.y / 2;
rect.position.y += cell_size.y / 2 - rect.size.x / 2;
}
} else if (centered_texture) {
rect.position += cell_size / 2 - rect.size / 2;
}
if (p_flip_h) {
@@ -812,7 +824,44 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p
tile_ofs.y *= -1.0;
}
rect.position += tile_ofs;
if (compatibility_mode_enabled && !centered_texture) {
if (node->get_tile_origin() == TileMap::TILE_ORIGIN_TOP_LEFT) {
rect.position += tile_ofs;
} else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_BOTTOM_LEFT) {
rect.position += tile_ofs;
if (p_transpose) {
if (p_flip_h)
rect.position.x -= cell_size.x;
else
rect.position.x += cell_size.x;
} else {
if (p_flip_v)
rect.position.y -= cell_size.y;
else
rect.position.y += cell_size.y;
}
} else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_CENTER) {
rect.position += tile_ofs;
if (p_flip_h)
rect.position.x -= cell_size.x / 2;
else
rect.position.x += cell_size.x / 2;
if (p_flip_v)
rect.position.y -= cell_size.y / 2;
else
rect.position.y += cell_size.y / 2;
}
} else {
rect.position += tile_ofs;
}
rect.position = p_xform.xform(rect.position);
rect.size *= sc;