From b0cd6edcebf6c89c174940afb496e499a4dc5d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilles=20Roudi=C3=A8re?= Date: Mon, 13 May 2024 14:34:33 +0200 Subject: [PATCH] Fix TileMap selection pattern being needlessly reorganized --- .../plugins/tiles/tile_map_layer_editor.cpp | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/editor/plugins/tiles/tile_map_layer_editor.cpp b/editor/plugins/tiles/tile_map_layer_editor.cpp index f177245acc2..da0b9f193cb 100644 --- a/editor/plugins/tiles/tile_map_layer_editor.cpp +++ b/editor/plugins/tiles/tile_map_layer_editor.cpp @@ -1628,7 +1628,7 @@ void TileMapLayerEditorTilesPlugin::_update_fix_selected_and_hovered() { hovered_tile.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; } - // Selection if needed. + // Cleanup tile set selection. for (RBSet::Element *E = tile_set_selection.front(); E;) { RBSet::Element *N = E->next(); const TileMapCell *selected = &(E->get()); @@ -1640,12 +1640,15 @@ void TileMapLayerEditorTilesPlugin::_update_fix_selected_and_hovered() { E = N; } - if (!tile_map_selection.is_empty()) { - _update_selection_pattern_from_tilemap_selection(); - } else if (tiles_bottom_panel->is_visible_in_tree()) { - _update_selection_pattern_from_tileset_tiles_selection(); - } else { - _update_selection_pattern_from_tileset_pattern_selection(); + // Cleanup selection. + for (const KeyValue &E : selection_pattern->get_pattern()) { + const Vector2i key = E.key; + const TileMapCell &selected = E.value; + if (!tile_set->has_source(selected.source_id) || + !tile_set->get_source(selected.source_id)->has_tile(selected.get_atlas_coords()) || + !tile_set->get_source(selected.source_id)->has_alternative_tile(selected.get_atlas_coords(), selected.alternative_tile)) { + selection_pattern->remove_cell(key); + } } } @@ -2409,7 +2412,6 @@ TileMapLayerEditorTilesPlugin::TileMapLayerEditorTilesPlugin() { sources_list->set_stretch_ratio(0.25); sources_list->set_custom_minimum_size(Size2(70, 0) * EDSCALE); sources_list->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); - sources_list->connect("item_selected", callable_mp(this, &TileMapLayerEditorTilesPlugin::_update_fix_selected_and_hovered).unbind(1)); sources_list->connect("item_selected", callable_mp(this, &TileMapLayerEditorTilesPlugin::_update_source_display).unbind(1)); sources_list->connect("item_selected", callable_mp(TilesEditorUtils::get_singleton(), &TilesEditorUtils::set_sources_lists_current)); sources_list->connect("item_activated", callable_mp(TilesEditorUtils::get_singleton(), &TilesEditorUtils::display_tile_set_editor_panel).unbind(1)); @@ -3980,10 +3982,14 @@ void TileMapLayerEditor::_update_bottom_panel() { } // Update tabs visibility. - for (TileMapLayerSubEditorPlugin::TabData &tab_data : tabs_data) { - tab_data.panel->hide(); + for (int i = 0; i < int(tabs_data.size()); i++) { + TileMapLayerSubEditorPlugin::TabData &tab_data = tabs_data[i]; + if (i == tabs_bar->get_current_tab()) { + tab_data.panel->set_visible(!cant_edit_label->is_visible()); + } else { + tab_data.panel->hide(); + } } - tabs_data[tabs_bar->get_current_tab()].panel->set_visible(!cant_edit_label->is_visible()); } Vector TileMapLayerEditor::get_line(const TileMapLayer *p_tile_map_layer, Vector2i p_from_cell, Vector2i p_to_cell) {