From 70a4cd1afe8fe065ced55c299ca8aa0c95a1e8c9 Mon Sep 17 00:00:00 2001 From: Michael Auderer Date: Fri, 2 Oct 2020 01:48:14 -0400 Subject: Reset TileMapEditor painting on application refocus Treats application unfocus as a mouse release for TOOL_PAINTING, by finishing the undo state and resetting the tool. Also sets a flag to prevent extra lines from being drawn when the application is refocused. fixes #42398, fixes #24970 --- editor/plugins/tile_map_editor_plugin.cpp | 25 +++++++++++++++++++++++++ editor/plugins/tile_map_editor_plugin.h | 1 + 2 files changed, 26 insertions(+) diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 8cd8aaf277..9261113706 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -89,6 +89,25 @@ void TileMapEditor::_notification(int p_what) { case NOTIFICATION_EXIT_TREE: { get_tree()->disconnect("node_removed", callable_mp(this, &TileMapEditor::_node_removed)); } break; + + case NOTIFICATION_APPLICATION_FOCUS_OUT: { + if (tool == TOOL_PAINTING) { + Vector ids = get_selected_tiles(); + + if (ids.size() > 0 && ids[0] != TileMap::INVALID_CELL) { + _set_cell(over_tile, ids, flip_h, flip_v, transpose); + _finish_undo(); + + paint_undo.clear(); + } + + tool = TOOL_NONE; + _update_button_tool(); + } + + // set flag to ignore over_tile on refocus + refocus_over_tile = true; + } break; } } @@ -1299,6 +1318,12 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { CanvasItemEditor::get_singleton()->update_viewport(); } + if (refocus_over_tile) { + // editor lost focus; forget last tile position + old_over_tile = new_over_tile; + refocus_over_tile = false; + } + int tile_under = node->get_cell(over_tile.x, over_tile.y); String tile_name = "none"; diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h index 996e904853..c77f15c671 100644 --- a/editor/plugins/tile_map_editor_plugin.h +++ b/editor/plugins/tile_map_editor_plugin.h @@ -119,6 +119,7 @@ class TileMapEditor : public VBoxContainer { Rect2i rectangle; Point2i over_tile; + bool refocus_over_tile; bool *bucket_cache_visited; Rect2i bucket_cache_rect; -- cgit v1.2.3 From 6d510453e5c2ec7cfc411f6883d45e5f217463e5 Mon Sep 17 00:00:00 2001 From: Michael Auderer Date: Fri, 2 Oct 2020 10:42:12 -0400 Subject: initialize refocus_over_tile to false Co-authored-by: Tomek --- editor/plugins/tile_map_editor_plugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h index c77f15c671..f57616db1f 100644 --- a/editor/plugins/tile_map_editor_plugin.h +++ b/editor/plugins/tile_map_editor_plugin.h @@ -119,7 +119,7 @@ class TileMapEditor : public VBoxContainer { Rect2i rectangle; Point2i over_tile; - bool refocus_over_tile; + bool refocus_over_tile = false; bool *bucket_cache_visited; Rect2i bucket_cache_rect; -- cgit v1.2.3