From 6be7fea798e5559f3df31ba58f2ca8e59f91ce53 Mon Sep 17 00:00:00 2001 From: Michael Alexsander Silva Dias Date: Tue, 4 Jun 2019 11:27:00 -0300 Subject: [PATCH] Fix subtile picking in TileMap editor Fixes #29445. --- editor/plugins/tile_map_editor_plugin.cpp | 37 +++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 7aa3d69bfac..433a18a516f 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -567,23 +567,25 @@ void TileMapEditor::_pick_tile(const Point2 &p_pos) { if (id == TileMap::INVALID_CELL) return; - if (search_box->get_text().strip_edges() != "") { - + if (search_box->get_text() != "") { search_box->set_text(""); _update_palette(); } - Vector selected; - - selected.push_back(id); - set_selected_tiles(selected); - flip_h = node->is_cell_x_flipped(p_pos.x, p_pos.y); flip_v = node->is_cell_y_flipped(p_pos.x, p_pos.y); transpose = node->is_cell_transposed(p_pos.x, p_pos.y); autotile_coord = node->get_cell_autotile_coord(p_pos.x, p_pos.y); + Vector selected; + selected.push_back(id); + set_selected_tiles(selected); _update_palette(); + + if ((manual_autotile && node->get_tileset()->tile_get_tile_mode(id) == TileSet::AUTO_TILE) || (!priority_atlastile && node->get_tileset()->tile_get_tile_mode(id) == TileSet::ATLAS_TILE)) { + manual_palette->select(manual_palette->find_metadata((Point2)autotile_coord)); + } + CanvasItemEditor::get_singleton()->update_viewport(); } @@ -975,7 +977,7 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { return true; } else { - // Mousebutton was released + // Mousebutton was released. if (tool != TOOL_NONE) { if (tool == TOOL_PAINTING) { @@ -1039,7 +1041,7 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { CanvasItemEditor::get_singleton()->update_viewport(); - return true; // We want to keep the Pasting tool + return true; // We want to keep the Pasting tool. } else if (tool == TOOL_SELECTING) { CanvasItemEditor::get_singleton()->update_viewport(); @@ -1063,7 +1065,10 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { _finish_undo(); - // We want to keep the bucket-tool active + // So the fill preview is cleared right after the click. + CanvasItemEditor::get_singleton()->update_viewport(); + + // We want to keep the bucket-tool active. return true; } @@ -1190,7 +1195,7 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { if (tool == TOOL_PAINTING) { - // Paint using bresenham line to prevent holes in painting if the user moves fast + // Paint using bresenham line to prevent holes in painting if the user moves fast. Vector points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y); Vector ids = get_selected_tiles(); @@ -1211,7 +1216,7 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { if (tool == TOOL_ERASING) { - // erase using bresenham line to prevent holes in painting if the user moves fast + // Erase using bresenham line to prevent holes in painting if the user moves fast. Vector points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y); @@ -1336,13 +1341,13 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { } if (!mouse_over) { - // Editor shortcuts should not fire if mouse not in viewport + // Editor shortcuts should not fire if mouse not in viewport. return false; } if (ED_IS_SHORTCUT("tile_map_editor/paint_tile", p_event)) { // NOTE: We do not set tool = TOOL_PAINTING as this begins painting - // immediately without pressing the left mouse button first + // immediately without pressing the left mouse button first. tool = TOOL_NONE; CanvasItemEditor::get_singleton()->update_viewport(); @@ -1424,7 +1429,7 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { CanvasItemEditor::get_singleton()->update_viewport(); return true; } - } else if (k.is_valid()) { // release event + } else if (k.is_valid()) { // Release event. if (tool == TOOL_NONE) { @@ -1440,7 +1445,7 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { #else if (k->get_scancode() == KEY_CONTROL) { #endif - // go back to that last tool if KEY_CONTROL was released + // Go back to that last tool if KEY_CONTROL was released. tool = last_tool; CanvasItemEditor::get_singleton()->update_viewport();