Fix subtile picking in TileMap editor

Fixes #29445.
This commit is contained in:
Michael Alexsander Silva Dias 2019-06-04 11:27:00 -03:00
parent 328805ae31
commit 6be7fea798

View file

@ -567,23 +567,25 @@ void TileMapEditor::_pick_tile(const Point2 &p_pos) {
if (id == TileMap::INVALID_CELL) if (id == TileMap::INVALID_CELL)
return; return;
if (search_box->get_text().strip_edges() != "") { if (search_box->get_text() != "") {
search_box->set_text(""); search_box->set_text("");
_update_palette(); _update_palette();
} }
Vector<int> selected;
selected.push_back(id);
set_selected_tiles(selected);
flip_h = node->is_cell_x_flipped(p_pos.x, p_pos.y); 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); flip_v = node->is_cell_y_flipped(p_pos.x, p_pos.y);
transpose = node->is_cell_transposed(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); autotile_coord = node->get_cell_autotile_coord(p_pos.x, p_pos.y);
Vector<int> selected;
selected.push_back(id);
set_selected_tiles(selected);
_update_palette(); _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(); CanvasItemEditor::get_singleton()->update_viewport();
} }
@ -975,7 +977,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
return true; return true;
} else { } else {
// Mousebutton was released // Mousebutton was released.
if (tool != TOOL_NONE) { if (tool != TOOL_NONE) {
if (tool == TOOL_PAINTING) { if (tool == TOOL_PAINTING) {
@ -1039,7 +1041,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport(); 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) { } else if (tool == TOOL_SELECTING) {
CanvasItemEditor::get_singleton()->update_viewport(); CanvasItemEditor::get_singleton()->update_viewport();
@ -1063,7 +1065,10 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
_finish_undo(); _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; return true;
} }
@ -1190,7 +1195,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (tool == TOOL_PAINTING) { 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<Point2i> points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y); Vector<Point2i> points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y);
Vector<int> ids = get_selected_tiles(); Vector<int> ids = get_selected_tiles();
@ -1211,7 +1216,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (tool == TOOL_ERASING) { 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<Point2i> points = line(old_over_tile.x, over_tile.x, old_over_tile.y, over_tile.y); Vector<Point2i> 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<InputEvent> &p_event) {
} }
if (!mouse_over) { 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; return false;
} }
if (ED_IS_SHORTCUT("tile_map_editor/paint_tile", p_event)) { if (ED_IS_SHORTCUT("tile_map_editor/paint_tile", p_event)) {
// NOTE: We do not set tool = TOOL_PAINTING as this begins painting // 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; tool = TOOL_NONE;
CanvasItemEditor::get_singleton()->update_viewport(); CanvasItemEditor::get_singleton()->update_viewport();
@ -1424,7 +1429,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
CanvasItemEditor::get_singleton()->update_viewport(); CanvasItemEditor::get_singleton()->update_viewport();
return true; return true;
} }
} else if (k.is_valid()) { // release event } else if (k.is_valid()) { // Release event.
if (tool == TOOL_NONE) { if (tool == TOOL_NONE) {
@ -1440,7 +1445,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
#else #else
if (k->get_scancode() == KEY_CONTROL) { if (k->get_scancode() == KEY_CONTROL) {
#endif #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; tool = last_tool;
CanvasItemEditor::get_singleton()->update_viewport(); CanvasItemEditor::get_singleton()->update_viewport();