Merge pull request #29460 from YeldhamDev/tilemapeditor_atlas_copy_fix

Fix TileMap editor not correctly copying atlas tiles
This commit is contained in:
Rémi Verschelde 2019-06-04 16:56:59 +02:00 committed by GitHub
commit 33163c0040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 21 deletions

View File

@ -299,9 +299,13 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p
Vector2 position;
int current = manual_palette->get_current();
if (current != -1) {
if (tool != TOOL_PASTING) {
position = manual_palette->get_item_metadata(current);
} else {
// if there is no manual tile selected, that either means that
position = p_autotile_coord;
}
} else {
// If there is no manual tile selected, that either means that
// autotiling is enabled, or the given tile is not autotiling. Either
// way, the coordinate of the tile does not matter, so assigning it to
// the coordinate of the existing tile works fine.
@ -309,7 +313,7 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p
}
if (p_value == prev_val && p_flip_h == prev_flip_h && p_flip_v == prev_flip_v && p_transpose == prev_transpose && prev_position == position)
return; //check that it's actually different
return; // Check that it's actually different.
for (int y = p_pos.y - 1; y <= p_pos.y + 1; y++) {
for (int x = p_pos.x - 1; x <= p_pos.x + 1; x++) {
@ -322,23 +326,21 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p
node->_set_celld(p_pos, _create_cell_dictionary(p_value, p_flip_h, p_flip_v, p_transpose, p_autotile_coord));
if (tool == TOOL_PASTING)
return;
if (manual_autotile || (p_value != -1 && node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE)) {
if (current != -1) {
node->set_cell_autotile_coord(p_pos.x, p_pos.y, position);
} else if (tool != TOOL_PASTING && node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE && priority_atlastile) {
// BIND_CENTER is used to indicate that bitmask should not update for this tile cell
} else if (node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE && priority_atlastile) {
// BIND_CENTER is used to indicate that bitmask should not update for this tile cell.
node->get_tileset()->autotile_set_bitmask(p_value, Vector2(p_pos.x, p_pos.y), TileSet::BIND_CENTER);
node->update_cell_bitmask(p_pos.x, p_pos.y);
}
} else {
// manually placing tiles should not update bitmasks
if (tool != TOOL_PASTING) {
node->update_bitmask_area(Point2(p_pos));
}
}
}
void TileMapEditor::_manual_toggled(bool p_enabled) {
manual_autotile = p_enabled;
@ -759,16 +761,16 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p
Rect2 r = node->get_tileset()->tile_get_region(p_cell);
if (node->get_tileset()->tile_get_tile_mode(p_cell) == TileSet::AUTO_TILE || node->get_tileset()->tile_get_tile_mode(p_cell) == TileSet::ATLAS_TILE) {
Vector2 offset;
if (tool != TOOL_PASTING) {
int selected = manual_palette->get_current();
if ((manual_autotile || (node->get_tileset()->tile_get_tile_mode(p_cell) == TileSet::ATLAS_TILE && !priority_atlastile)) && selected != -1) {
offset = manual_palette->get_item_metadata(selected);
} else {
if (tool != TOOL_PASTING) {
offset = node->get_tileset()->autotile_get_icon_coordinate(p_cell);
}
} else {
offset = p_autotile_coord;
}
}
int spacing = node->get_tileset()->autotile_get_spacing(p_cell);
r.size = node->get_tileset()->autotile_get_size(p_cell);
@ -810,11 +812,12 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p
Color modulate = node->get_tileset()->tile_get_modulate(p_cell);
modulate.a = 0.5;
if (r.has_no_area())
if (r.has_no_area()) {
p_viewport->draw_texture_rect(t, rect, false, modulate, p_transpose);
else
} else {
p_viewport->draw_texture_rect_region(t, rect, r, modulate, p_transpose);
}
}
void TileMapEditor::_draw_fill_preview(Control *p_viewport, int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i p_autotile_coord, const Transform2D &p_xform) {
@ -848,7 +851,6 @@ void TileMapEditor::_update_copydata() {
TileData tcd;
tcd.cell = node->get_cell(j, i);
if (tcd.cell != TileMap::INVALID_CELL) {
tcd.pos = Point2i(j, i);
tcd.flip_h = node->is_cell_x_flipped(j, i);