/**************************************************************************/ /* tile_map_layer_editor.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #include "tile_map_layer_editor.h" #include "tiles_editor_plugin.h" #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" #include "editor/editor_settings.h" #include "editor/editor_undo_redo_manager.h" #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/themes/editor_scale.h" #include "scene/2d/camera_2d.h" #include "scene/2d/tile_map_layer.h" #include "scene/gui/center_container.h" #include "scene/gui/split_container.h" #include "core/input/input.h" #include "core/math/geometry_2d.h" #include "core/os/keyboard.h" TileMapLayer *TileMapLayerSubEditorPlugin::_get_edited_layer() const { return Object::cast_to(ObjectDB::get_instance(edited_tile_map_layer_id)); } void TileMapLayerEditorTilesPlugin::tile_set_changed() { _update_fix_selected_and_hovered(); _update_tile_set_sources_list(); _update_source_display(); _update_patterns_list(); } void TileMapLayerEditorTilesPlugin::_on_random_tile_checkbox_toggled(bool p_pressed) { scatter_controls_container->set_visible(p_pressed); } void TileMapLayerEditorTilesPlugin::_on_scattering_spinbox_changed(double p_value) { scattering = p_value; } void TileMapLayerEditorTilesPlugin::_update_toolbar() { // Stop draggig if needed. _stop_dragging(); // Hide all settings. for (int i = 0; i < tools_settings->get_child_count(); i++) { Object::cast_to(tools_settings->get_child(i))->hide(); } // Show only the correct settings. if (tool_buttons_group->get_pressed_button() == select_tool_button) { transform_toolbar->show(); } else if (tool_buttons_group->get_pressed_button() != bucket_tool_button) { tools_settings_vsep->show(); picker_button->show(); erase_button->show(); transform_toolbar->show(); tools_settings_vsep_2->show(); random_tile_toggle->show(); scatter_label->show(); scatter_spinbox->show(); } else { tools_settings_vsep->show(); picker_button->show(); erase_button->show(); transform_toolbar->show(); tools_settings_vsep_2->show(); bucket_contiguous_checkbox->show(); random_tile_toggle->show(); scatter_label->show(); scatter_spinbox->show(); } } void TileMapLayerEditorTilesPlugin::_update_transform_buttons() { TileMapLayer *edited_layer = _get_edited_layer(); if (!edited_layer) { return; } Ref tile_set = edited_layer->get_effective_tile_set(); if (tile_set.is_null() || selection_pattern.is_null()) { return; } bool has_scene_tile = false; for (const KeyValue &E : selection_pattern->get_pattern()) { if (Object::cast_to(tile_set->get_source(E.value.source_id).ptr())) { has_scene_tile = true; break; } } if (has_scene_tile) { _set_transform_buttons_state({}, { transform_button_rotate_left, transform_button_rotate_right, transform_button_flip_h, transform_button_flip_v }, TTR("Can't transform scene tiles.")); } else if (tile_set->get_tile_shape() != TileSet::TILE_SHAPE_SQUARE && selection_pattern->get_size() != Vector2i(1, 1)) { _set_transform_buttons_state({ transform_button_flip_h, transform_button_flip_v }, { transform_button_rotate_left, transform_button_rotate_right }, TTR("Can't rotate patterns when using non-square tile grid.")); } else { _set_transform_buttons_state({ transform_button_rotate_left, transform_button_rotate_right, transform_button_flip_h, transform_button_flip_v }, {}, ""); } } void TileMapLayerEditorTilesPlugin::_set_transform_buttons_state(const Vector