/**************************************************************************/ /* 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 "../tile_map.h" #include "../tile_map_layer.h" #include "tiles_editor_plugin.h" #include "core/input/input.h" #include "core/math/geometry_2d.h" #include "core/math/random_pcg.h" #include "core/object/callable_mp.h" #include "core/object/class_db.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" #include "editor/editor_undo_redo_manager.h" #include "editor/inspector/editor_resource_preview.h" #include "editor/inspector/multi_node_edit.h" #include "editor/scene/canvas_item_editor_plugin.h" #include "editor/settings/editor_command_palette.h" #include "editor/settings/editor_settings.h" #include "editor/themes/editor_scale.h" #include "scene/gui/grid_container.h" #include "scene/gui/split_container.h" #include "scene/main/scene_tree.h" void SwitchSeparator::set_vertical(bool p_vertical) { h_separator->set_visible(p_vertical); v_separator->set_visible(!p_vertical); } SwitchSeparator::SwitchSeparator() { h_separator = memnew(HSeparator); h_separator->hide(); add_child(h_separator); v_separator = memnew(VSeparator); add_child(v_separator); } TileMapLayer *TileMapLayerSubEditorPlugin::_get_edited_layer() const { return ObjectDB::get_instance(edited_tile_map_layer_id); } void TileMapLayerSubEditorPlugin::_add_to_output_if_tile_changed(HashMap &p_output, const TileMapLayer *p_layer, Vector2i p_coords, const TileMapCell &p_cell) { if (p_cell != p_layer->get_cell(p_coords)) { p_output[p_coords] = p_cell; } } void TileMapLayerSubEditorPlugin::draw_tile_coords_over_viewport(Control *p_overlay, const TileMapLayer *p_edited_layer, Ref p_tile_set, bool p_show_rectangle_size, const Vector2i &p_rectangle_origin) { Point2 msgpos = Point2(20 * EDSCALE, p_overlay->get_size().y - 20 * EDSCALE); String text = String(p_tile_set->local_to_map(p_edited_layer->get_local_mouse_position())); if (p_show_rectangle_size) { Vector2i rect_size = p_tile_set->local_to_map(p_edited_layer->get_local_mouse_position()) - p_tile_set->local_to_map(p_rectangle_origin); text += vformat(" %s (%dx%d)", TTR("Drawing Rect:"), Math::abs(rect_size.x) + 1, Math::abs(rect_size.y) + 1); } Ref font = p_overlay->get_theme_font(SceneStringName(font), SNAME("Label")); int font_size = p_overlay->get_theme_font_size(SceneStringName(font_size), SNAME("Label")); p_overlay->draw_string(font, msgpos + Point2(1, 1), text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(0, 0, 0, 0.8)); p_overlay->draw_string(font, msgpos + Point2(-1, -1), text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(0, 0, 0, 0.8)); p_overlay->draw_string(font, msgpos, text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(1, 1, 1, 1)); } 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 dragging if needed. _stop_dragging(); // Show only the correct settings. const BaseButton *pressed_tool = tool_buttons_group->get_pressed_button(); bool using_select = (pressed_tool == select_tool_button); tools_settings_vsep->set_visible(!using_select); picker_button->set_visible(!using_select); erase_button->set_visible(!using_select); random_tile_toggle->set_visible(!using_select); bucket_contiguous_checkbox->set_visible(!using_select && pressed_tool == bucket_tool_button); scatter_controls_container->set_visible(!using_select && random_tile_toggle->is_pressed()); CanvasItemEditor::get_singleton()->set_current_tool(CanvasItemEditor::TOOL_SELECT); } void TileMapLayerEditorTilesPlugin::_update_transform_buttons() { TileMapLayer *edited_layer = _get_edited_layer(); if (!edited_layer) { return; } Ref tile_set = edited_layer->get_tile_set(); if (tile_set.is_null() || selection_pattern.is_null()) { return; } 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 }, TTRC("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