Fix layer navigation keys in LayeredTileMapLayerEditor even when not using layer nodes.

This commit is contained in:
Relintai 2024-04-06 21:04:57 +02:00
parent aa82d20e4b
commit d255d381cb

View File

@ -3807,6 +3807,8 @@ void LayeredTileMapLayerEditor::_notification(int p_what) {
case NOTIFICATION_READY: { case NOTIFICATION_READY: {
get_tree()->connect("node_added", this, "_node_change"); get_tree()->connect("node_added", this, "_node_change");
get_tree()->connect("node_removed", this, "_node_change"); get_tree()->connect("node_removed", this, "_node_change");
layers_in_scene_list_cache_needs_update = true;
} break; } break;
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
@ -4271,12 +4273,6 @@ void LayeredTileMapLayerEditor::_tab_changed(int p_tab_id) {
} }
void LayeredTileMapLayerEditor::_layers_select_next_or_previous(bool p_next) { void LayeredTileMapLayerEditor::_layers_select_next_or_previous(bool p_next) {
_update_tile_map_layers_in_scene_list_cache();
if (tile_map_layers_in_scene_cache.size() == 0) {
return;
}
const LayeredTileMapLayer *edited_layer = _get_edited_layer(); const LayeredTileMapLayer *edited_layer = _get_edited_layer();
if (!edited_layer) { if (!edited_layer) {
return; return;
@ -4292,10 +4288,11 @@ void LayeredTileMapLayerEditor::_layers_select_next_or_previous(bool p_next) {
if (edited_layer->get_index_in_tile_map() >= 0) { if (edited_layer->get_index_in_tile_map() >= 0) {
// Part of a TileMap. // Part of a TileMap.
LayeredTileMap *tile_map = Object::cast_to<LayeredTileMap>(edited_layer->get_parent()); LayeredTileMap *tile_map = Object::cast_to<LayeredTileMap>(edited_layer->get_parent());
new_selected_layer = Object::cast_to<LayeredTileMapLayer>(tile_map->get_child(Math::posmod(edited_layer->get_index_in_tile_map() + inc, tile_map->get_layers_count()))); new_selected_layer = tile_map->get_layer(Math::posmod(edited_layer->get_index_in_tile_map() + inc, tile_map->get_layers_count()));
} else { } else {
// Individual layer. // Individual layer.
_update_tile_map_layers_in_scene_list_cache(); _update_tile_map_layers_in_scene_list_cache();
int edited_index = -1; int edited_index = -1;
for (int i = 0; i < tile_map_layers_in_scene_cache.size(); i++) { for (int i = 0; i < tile_map_layers_in_scene_cache.size(); i++) {
if (tile_map_layers_in_scene_cache[i] == edited_layer) { if (tile_map_layers_in_scene_cache[i] == edited_layer) {
@ -4314,6 +4311,7 @@ void LayeredTileMapLayerEditor::_layers_select_next_or_previous(bool p_next) {
en->get_editor_selection()->clear(); en->get_editor_selection()->clear();
en->get_editor_selection()->add_node(new_selected_layer); en->get_editor_selection()->add_node(new_selected_layer);
} else { } else {
edit(new_selected_layer); edit(new_selected_layer);
} }
} }