From 0f07cedf57906ec6efc7d754ef1ac85d46ce7982 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 3 Mar 2024 12:59:36 +0100 Subject: [PATCH] Work on layered tile maps. --- .../editor/atlas_merging_dialog.cpp | 103 ++++++----- .../editor/atlas_merging_dialog.h | 2 + .../editor/layered_tile_atlas_view.cpp | 164 +++++++++--------- .../editor/layered_tile_atlas_view.h | 15 +- .../editor/layered_tile_data_editors.cpp | 100 +++++------ .../editor/layered_tile_data_editors.h | 4 +- .../editor/layered_tile_map_layer_editor.cpp | 66 +++---- .../layered_tile_set_atlas_source_editor.cpp | 164 +++++++++--------- .../editor/layered_tile_set_editor.cpp | 14 +- modules/layered_tile_map/layered_tile_map.cpp | 4 +- .../layered_tile_map_layer.cpp | 6 +- modules/layered_tile_map/layered_tile_set.cpp | 12 +- 12 files changed, 337 insertions(+), 317 deletions(-) diff --git a/modules/layered_tile_map/editor/atlas_merging_dialog.cpp b/modules/layered_tile_map/editor/atlas_merging_dialog.cpp index 35e73a4b5..2960f2000 100644 --- a/modules/layered_tile_map/editor/atlas_merging_dialog.cpp +++ b/modules/layered_tile_map/editor/atlas_merging_dialog.cpp @@ -31,10 +31,13 @@ #include "atlas_merging_dialog.h" -#include "editor/editor_properties_vector.h" -#include "editor/editor_undo_redo_manager.h" -#include "editor/gui/editor_file_dialog.h" -#include "editor/themes/editor_scale.h" +#include "core/object/undo_redo.h" +#include "editor/editor_file_dialog.h" +#include "editor/editor_node.h" +#include "editor/editor_properties.h" +#include "editor/editor_scale.h" +#include "scene/gui/button.h" +#include "scene/gui/label.h" #include "scene/gui/split_container.h" #include "scene/main/control.h" #include "scene/resources/texture.h" @@ -48,7 +51,9 @@ void AtlasMergingDialog::_generate_merged(const Vector= 2) { - Ref output_image = Image::create_empty(1, 1, false, Image::FORMAT_RGBA8); + Ref output_image; + output_image.instance(); + output_image->create(1, 1, false, Image::FORMAT_RGBA8); // Compute the new texture region size. Vector2i new_texture_region_size; @@ -62,7 +67,7 @@ void AtlasMergingDialog::_generate_merged(const Vector &atlas_source = p_atlas_sources[source_index]; - Ref input_image = atlas_source->get_texture()->get_image(); + Ref input_image = atlas_source->get_texture()->get_data(); if (input_image->get_format() != Image::FORMAT_RGBA8) { input_image->convert(Image::FORMAT_RGBA8); } @@ -107,37 +112,46 @@ void AtlasMergingDialog::_generate_merged(const Vectorset_name(p_atlas_sources[0]->get_name()); - merged->set_texture(ImageTexture::create_from_image(output_image)); + + Ref oit; + oit.instance(); + oit->create_from_image(output_image); + + merged->set_texture(oit); merged->set_texture_region_size(new_texture_region_size); // Copy the tiles to the merged LayeredTileSetAtlasSource. for (int source_index = 0; source_index < p_atlas_sources.size(); source_index++) { const Ref &atlas_source = p_atlas_sources[source_index]; - for (KeyValue tile_mapping : merged_mapping[source_index]) { + + for (HashMap::Element *tile_mapping = merged_mapping[source_index].front(); tile_mapping; tile_mapping = tile_mapping->next) { // Create tiles and alternatives, then copy their properties. - for (int alternative_index = 0; alternative_index < atlas_source->get_alternative_tiles_count(tile_mapping.key); alternative_index++) { - int alternative_id = atlas_source->get_alternative_tile_id(tile_mapping.key, alternative_index); + for (int alternative_index = 0; alternative_index < atlas_source->get_alternative_tiles_count(tile_mapping->key()); alternative_index++) { + int alternative_id = atlas_source->get_alternative_tile_id(tile_mapping->key(), alternative_index); int changed_id = -1; if (alternative_id == 0) { - merged->create_tile(tile_mapping.value, atlas_source->get_tile_size_in_atlas(tile_mapping.key)); - int count = atlas_source->get_tile_animation_frames_count(tile_mapping.key); - merged->set_tile_animation_frames_count(tile_mapping.value, count); + merged->create_tile(tile_mapping->value(), atlas_source->get_tile_size_in_atlas(tile_mapping->key())); + int count = atlas_source->get_tile_animation_frames_count(tile_mapping->key()); + merged->set_tile_animation_frames_count(tile_mapping->value(), count); for (int i = 0; i < count; i++) { - merged->set_tile_animation_frame_duration(tile_mapping.value, i, atlas_source->get_tile_animation_frame_duration(tile_mapping.key, i)); + merged->set_tile_animation_frame_duration(tile_mapping->value(), i, atlas_source->get_tile_animation_frame_duration(tile_mapping->key(), i)); } - merged->set_tile_animation_speed(tile_mapping.value, atlas_source->get_tile_animation_speed(tile_mapping.key)); - merged->set_tile_animation_mode(tile_mapping.value, atlas_source->get_tile_animation_mode(tile_mapping.key)); + merged->set_tile_animation_speed(tile_mapping->value(), atlas_source->get_tile_animation_speed(tile_mapping->key())); + merged->set_tile_animation_mode(tile_mapping->value(), atlas_source->get_tile_animation_mode(tile_mapping->key())); } else { - changed_id = merged->create_alternative_tile(tile_mapping.value, alternative_index); + changed_id = merged->create_alternative_tile(tile_mapping->value(), alternative_index); } // Copy the properties. - TileData *src_tile_data = atlas_source->get_tile_data(tile_mapping.key, alternative_id); + LayeredTileData *src_tile_data = atlas_source->get_tile_data(tile_mapping->key(), alternative_id); List properties; src_tile_data->get_property_list(&properties); - TileData *dst_tile_data = merged->get_tile_data(tile_mapping.value, changed_id == -1 ? alternative_id : changed_id); - for (PropertyInfo property : properties) { + LayeredTileData *dst_tile_data = merged->get_tile_data(tile_mapping->value(), changed_id == -1 ? alternative_id : changed_id); + + for (List::Element *E = properties.front(); E; E = E->next()) { + PropertyInfo &property = E->get(); + if (!(property.usage & PROPERTY_USAGE_STORAGE)) { continue; } @@ -166,14 +180,14 @@ void AtlasMergingDialog::_update_texture() { preview->set_texture(merged->get_texture()); preview->show(); select_2_atlases_label->hide(); - get_ok_button()->set_disabled(false); + get_ok()->set_disabled(false); merge_button->set_disabled(false); } else { _generate_merged(Vector>(), next_line_after_column); preview->set_texture(Ref()); preview->hide(); select_2_atlases_label->show(); - get_ok_button()->set_disabled(true); + get_ok()->set_disabled(true); merge_button->set_disabled(true); } } @@ -182,14 +196,15 @@ void AtlasMergingDialog::_merge_confirmed(const String &p_path) { ERR_FAIL_COND(!merged.is_valid()); Ref output_image_texture = merged->get_texture(); - output_image_texture->get_image()->save_png(p_path); + output_image_texture->get_data()->save_png(p_path); ResourceLoader::import(p_path); Ref new_texture_resource = ResourceLoader::load(p_path, "Texture2D"); merged->set_texture(new_texture_resource); - EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); + undo_redo->create_action(TTR("Merge LayeredTileSetAtlasSource")); int next_id = tile_set->get_next_source_id(); undo_redo->add_do_method(*tile_set, "add_source", merged, next_id); @@ -223,13 +238,17 @@ void AtlasMergingDialog::_merge_confirmed(const String &p_path) { hide(); } +void AtlasMergingDialog::_atlases_list_multi_selected(int p_index, bool p_selected) { + _update_texture(); +} + void AtlasMergingDialog::ok_pressed() { delete_original_atlases = false; - editor_file_dialog->popup_file_dialog(); + editor_file_dialog->popup_centered_ratio(); } void AtlasMergingDialog::cancel_pressed() { - EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); for (int i = 0; i < commited_actions_count; i++) { undo_redo->undo(); } @@ -239,7 +258,7 @@ void AtlasMergingDialog::cancel_pressed() { void AtlasMergingDialog::custom_action(const String &p_action) { if (p_action == "merge") { delete_original_atlases = true; - editor_file_dialog->popup_file_dialog(); + editor_file_dialog->popup_centered_ratio(); } } @@ -270,6 +289,13 @@ void AtlasMergingDialog::_notification(int p_what) { } } +void AtlasMergingDialog::_bind_methods() { + ClassDB::bind_method(D_METHOD("_property_changed"), &AtlasMergingDialog::_property_changed); + ClassDB::bind_method(D_METHOD("_update_texture"), &AtlasMergingDialog::_update_texture); + ClassDB::bind_method(D_METHOD("_merge_confirmed"), &AtlasMergingDialog::_merge_confirmed); + ClassDB::bind_method(D_METHOD("_atlases_list_multi_selected"), &AtlasMergingDialog::_atlases_list_multi_selected); +} + void AtlasMergingDialog::update_tile_set(Ref p_tile_set) { ERR_FAIL_COND(!p_tile_set.is_valid()); tile_set = p_tile_set; @@ -288,7 +314,7 @@ void AtlasMergingDialog::update_tile_set(Ref p_tile_set) { } } - get_ok_button()->set_disabled(true); + get_ok()->set_disabled(true); merge_button->set_disabled(true); commited_actions_count = 0; @@ -300,8 +326,8 @@ AtlasMergingDialog::AtlasMergingDialog() { set_hide_on_ok(false); // Ok buttons - set_ok_button_text(TTR("Merge (Keep original Atlases)")); - get_ok_button()->set_disabled(true); + get_ok()->set_text(TTR("Merge (Keep original Atlases)")); + get_ok()->set_disabled(true); merge_button = add_button(TTR("Merge"), true, "merge"); merge_button->set_disabled(true); @@ -312,19 +338,16 @@ AtlasMergingDialog::AtlasMergingDialog() { // Atlas sources item list. atlas_merging_atlases_list = memnew(ItemList); - atlas_merging_atlases_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); atlas_merging_atlases_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE); atlas_merging_atlases_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); atlas_merging_atlases_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); - atlas_merging_atlases_list->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS); atlas_merging_atlases_list->set_custom_minimum_size(Size2(100, 200)); atlas_merging_atlases_list->set_select_mode(ItemList::SELECT_MULTI); - atlas_merging_atlases_list->connect("multi_selected", callable_mp(this, &AtlasMergingDialog::_update_texture).unbind(2)); + atlas_merging_atlases_list->connect("multi_selected", this, "_atlases_list_multi_selected"); atlas_merging_h_split_container->add_child(atlas_merging_atlases_list); VBoxContainer *atlas_merging_right_panel = memnew(VBoxContainer); atlas_merging_right_panel->set_h_size_flags(Control::SIZE_EXPAND_FILL); - atlas_merging_right_panel->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS); atlas_merging_h_split_container->add_child(atlas_merging_right_panel); // Settings. @@ -336,7 +359,7 @@ AtlasMergingDialog::AtlasMergingDialog() { columns_editor_property->set_label(TTR("Next Line After Column")); columns_editor_property->set_object_and_property(this, "next_line_after_column"); columns_editor_property->update_property(); - columns_editor_property->connect("property_changed", callable_mp(this, &AtlasMergingDialog::_property_changed)); + columns_editor_property->connect("property_changed", this, "_property_changed"); atlas_merging_right_panel->add_child(columns_editor_property); // Preview. @@ -347,7 +370,7 @@ AtlasMergingDialog::AtlasMergingDialog() { preview = memnew(TextureRect); preview->set_h_size_flags(Control::SIZE_EXPAND_FILL); preview->set_v_size_flags(Control::SIZE_EXPAND_FILL); - preview->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE); + //preview->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE); preview->hide(); preview->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); atlas_merging_right_panel->add_child(preview); @@ -355,15 +378,15 @@ AtlasMergingDialog::AtlasMergingDialog() { select_2_atlases_label = memnew(Label); select_2_atlases_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); select_2_atlases_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); - select_2_atlases_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); - select_2_atlases_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); + select_2_atlases_label->set_align(Label::ALIGN_CENTER); + select_2_atlases_label->set_valign(Label::VALIGN_CENTER); select_2_atlases_label->set_text(TTR("Please select two atlases or more.")); atlas_merging_right_panel->add_child(select_2_atlases_label); // The file dialog to choose the texture path. editor_file_dialog = memnew(EditorFileDialog); - editor_file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); + editor_file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); editor_file_dialog->add_filter("*.png"); - editor_file_dialog->connect("file_selected", callable_mp(this, &AtlasMergingDialog::_merge_confirmed)); + editor_file_dialog->connect("file_selected", this, "_merge_confirmed"); add_child(editor_file_dialog); } diff --git a/modules/layered_tile_map/editor/atlas_merging_dialog.h b/modules/layered_tile_map/editor/atlas_merging_dialog.h index 3cb9414af..ee7337458 100644 --- a/modules/layered_tile_map/editor/atlas_merging_dialog.h +++ b/modules/layered_tile_map/editor/atlas_merging_dialog.h @@ -68,6 +68,7 @@ private: void _generate_merged(const Vector> &p_atlas_sources, int p_max_columns); void _update_texture(); void _merge_confirmed(const String &p_path); + void _atlases_list_multi_selected(int p_index, bool p_selected); protected: virtual void ok_pressed(); @@ -78,6 +79,7 @@ protected: bool _get(const StringName &p_name, Variant &r_ret) const; void _notification(int p_what); + static void _bind_methods(); public: void update_tile_set(Ref p_tile_set); diff --git a/modules/layered_tile_map/editor/layered_tile_atlas_view.cpp b/modules/layered_tile_map/editor/layered_tile_atlas_view.cpp index 87103ec3b..aa4857372 100644 --- a/modules/layered_tile_map/editor/layered_tile_atlas_view.cpp +++ b/modules/layered_tile_map/editor/layered_tile_atlas_view.cpp @@ -29,13 +29,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "tile_atlas_view.h" +#include "layered_tile_atlas_view.h" +#include "../layered_tile_map.h" #include "core/input/input.h" #include "core/os/keyboard.h" +#include "editor/editor_scale.h" #include "editor/editor_settings.h" -#include "editor/themes/editor_scale.h" -#include "scene/2d/tile_map.h" #include "scene/gui/box_container.h" #include "scene/gui/label.h" #include "scene/gui/panel.h" @@ -50,13 +50,13 @@ void LayeredTileAtlasView::gui_input(const Ref &p_event) { void LayeredTileAtlasView::_pan_callback(Vector2 p_scroll_vec, Ref p_event) { panning += p_scroll_vec; _update_zoom_and_panning(true); - emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); + emit_signal("transform_changed", zoom_widget->get_zoom(), panning); } void LayeredTileAtlasView::_zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref p_event) { zoom_widget->set_zoom(zoom_widget->get_zoom() * p_zoom_factor); _update_zoom_and_panning(true); - emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); + emit_signal("transform_changed", zoom_widget->get_zoom(), panning); } Size2i LayeredTileAtlasView::_compute_base_tiles_control_size() { @@ -133,7 +133,8 @@ void LayeredTileAtlasView::_update_zoom_and_panning(bool p_zoom_on_mouse_pos) { // Center of panel. panning = panning * zoom / previous_zoom; } - button_center_view->set_disabled(panning.is_zero_approx()); + + button_center_view->set_disabled(panning.is_equal_approx(Vector2())); previous_zoom = zoom; @@ -141,20 +142,20 @@ void LayeredTileAtlasView::_update_zoom_and_panning(bool p_zoom_on_mouse_pos) { center_container->set_size(center_container->get_minimum_size()); } -void LayeredTileAtlasView::_zoom_widget_changed() { +void LayeredTileAtlasView::_zoom_widget_changed(float val) { _update_zoom_and_panning(); - emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); + emit_signal("transform_changed", zoom_widget->get_zoom(), panning); } void LayeredTileAtlasView::_center_view() { panning = Vector2(); button_center_view->set_disabled(true); _update_zoom_and_panning(); - emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); + emit_signal("transform_changed", zoom_widget->get_zoom(), panning); } void LayeredTileAtlasView::_base_tiles_root_control_gui_input(const Ref &p_event) { - base_tiles_root_control->set_tooltip_text(""); + base_tiles_root_control->set_tooltip(""); Ref mm = p_event; if (mm.is_valid()) { @@ -163,7 +164,7 @@ void LayeredTileAtlasView::_base_tiles_root_control_gui_input(const Refget_tile_at_coords(coords); if (coords != LayeredTileSetSource::INVALID_ATLAS_COORDS) { - base_tiles_root_control->set_tooltip_text(vformat(TTR("Source: %d\nAtlas coordinates: %s\nAlternative: 0"), source_id, coords)); + base_tiles_root_control->set_tooltip(vformat(TTR("Source: %d\nAtlas coordinates: %s\nAlternative: 0"), source_id, coords)); } } } @@ -287,7 +288,7 @@ void LayeredTileAtlasView::_draw_base_tiles() { } } -RID LayeredTileAtlasView::_get_canvas_item_to_draw(const TileData *p_for_data, const CanvasItem *p_base_item, HashMap, RID> &p_material_map) { +RID LayeredTileAtlasView::_get_canvas_item_to_draw(const LayeredTileData *p_for_data, const CanvasItem *p_base_item, HashMap, RID> &p_material_map) { Ref mat = p_for_data->get_material(); if (mat.is_null()) { return p_base_item->get_canvas_item(); @@ -303,13 +304,13 @@ RID LayeredTileAtlasView::_get_canvas_item_to_draw(const TileData *p_for_data, c } void LayeredTileAtlasView::_clear_material_canvas_items() { - for (KeyValue, RID> kv : material_tiles_draw) { - RS::get_singleton()->free(kv.value); + for (HashMap, RID>::Element *kv = material_tiles_draw.front(); kv; kv = kv->next) { + RS::get_singleton()->free(kv->value()); } material_tiles_draw.clear(); - for (KeyValue, RID> kv : material_alternatives_draw) { - RS::get_singleton()->free(kv.value); + for (HashMap, RID>::Element *kv = material_alternatives_draw.front(); kv; kv = kv->next) { + RS::get_singleton()->free(kv->value()); } material_alternatives_draw.clear(); } @@ -368,7 +369,7 @@ void LayeredTileAtlasView::_draw_base_tiles_shape_grid() { } void LayeredTileAtlasView::_alternative_tiles_root_control_gui_input(const Ref &p_event) { - alternative_tiles_root_control->set_tooltip_text(""); + alternative_tiles_root_control->set_tooltip(""); Ref mm = p_event; if (mm.is_valid()) { @@ -377,7 +378,7 @@ void LayeredTileAtlasView::_alternative_tiles_root_control_gui_input(const Refset_tooltip_text(vformat(TTR("Source: %d\nAtlas coordinates: %s\nAlternative: %d"), source_id, coords, alternative_id)); + alternative_tiles_root_control->set_tooltip(vformat(TTR("Source: %d\nAtlas coordinates: %s\nAlternative: %d"), source_id, coords, alternative_id)); } } } @@ -395,7 +396,7 @@ void LayeredTileAtlasView::_draw_alternatives() { int alternatives_count = tile_set_atlas_source->get_alternative_tiles_count(atlas_coords); for (int j = 1; j < alternatives_count; j++) { int alternative_id = tile_set_atlas_source->get_alternative_tile_id(atlas_coords, j); - TileData *tile_data = tile_set_atlas_source->get_tile_data(atlas_coords, alternative_id); + LayeredTileData *tile_data = tile_set_atlas_source->get_tile_data(atlas_coords, alternative_id); bool transposed = tile_data->get_transpose(); // Different materials need to be drawn with different CanvasItems. @@ -462,12 +463,12 @@ void LayeredTileAtlasView::set_atlas_source(LayeredTileSet *p_tile_set, LayeredT alternative_tiles_drawing_root->set_size(_compute_alternative_tiles_control_size()); // Update. - base_tiles_draw->queue_redraw(); - base_tiles_texture_grid->queue_redraw(); - base_tiles_shape_grid->queue_redraw(); - alternatives_draw->queue_redraw(); - background_left->queue_redraw(); - background_right->queue_redraw(); + base_tiles_draw->update(); + base_tiles_texture_grid->update(); + base_tiles_shape_grid->update(); + alternatives_draw->update(); + background_left->update(); + background_right->update(); } float LayeredTileAtlasView::get_zoom() const { @@ -520,7 +521,7 @@ void LayeredTileAtlasView::_update_alternative_tiles_rect_cache() { int line_height = 0; for (int j = 1; j < alternatives_count; j++) { int alternative_id = tile_set_atlas_source->get_alternative_tile_id(tile_id, j); - TileData *tile_data = tile_set_atlas_source->get_tile_data(tile_id, alternative_id); + LayeredTileData *tile_data = tile_set_atlas_source->get_tile_data(tile_id, alternative_id); bool transposed = tile_data->get_transpose(); current.size = transposed ? Vector2i(texture_region_size.y, texture_region_size.x) : texture_region_size; @@ -540,10 +541,10 @@ void LayeredTileAtlasView::_update_alternative_tiles_rect_cache() { } Vector3i LayeredTileAtlasView::get_alternative_tile_at_pos(const Vector2 p_pos) const { - for (const KeyValue> &E_coords : alternative_tiles_rect_cache) { - for (const KeyValue &E_alternative : E_coords.value) { - if (E_alternative.value.has_point(p_pos)) { - return Vector3i(E_coords.key.x, E_coords.key.y, E_alternative.key); + for (const HashMap>::Element *E_coords = alternative_tiles_rect_cache.front(); E_coords; E_coords = E_coords->next) { + for (const HashMap::Element *E_alternative = E_coords->value().front(); E_alternative; E_alternative = E_alternative->next) { + if (E_alternative->value().has_point(p_pos)) { + return Vector3i(E_coords->key().x, E_coords->key().y, E_alternative->key()); } } } @@ -558,79 +559,82 @@ Rect2i LayeredTileAtlasView::get_alternative_tile_rect(const Vector2i p_coords, return alternative_tiles_rect_cache[p_coords][p_alternative_tile]; } -void LayeredTileAtlasView::queue_redraw() { - base_tiles_draw->queue_redraw(); - base_tiles_texture_grid->queue_redraw(); - base_tiles_shape_grid->queue_redraw(); - alternatives_draw->queue_redraw(); - background_left->queue_redraw(); - background_right->queue_redraw(); -} - -void LayeredTileAtlasView::_update_theme_item_cache() { - Control::_update_theme_item_cache(); - - theme_cache.center_view_icon = get_editor_theme_icon(SNAME("CenterView")); - theme_cache.checkerboard = get_editor_theme_icon(SNAME("Checkerboard")); +void LayeredTileAtlasView::update() { + base_tiles_draw->update(); + base_tiles_texture_grid->update(); + base_tiles_shape_grid->update(); + alternatives_draw->update(); + background_left->update(); + background_right->update(); } void LayeredTileAtlasView::_notification(int p_what) { switch (p_what) { - case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - if (!EditorSettings::get_singleton()->check_changed_settings_in_group("editors/panning")) { - break; - } - [[fallthrough]]; - } + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: case NOTIFICATION_ENTER_TREE: { panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EDITOR_GET("editors/panning/simple_panning"))); } break; case NOTIFICATION_THEME_CHANGED: { + theme_cache.center_view_icon = get_theme_icon("CenterView", "EditorIcons"); + theme_cache.checkerboard = get_theme_icon("Checkerboard", "EditorIcons"); button_center_view->set_icon(theme_cache.center_view_icon); + } break; } } void LayeredTileAtlasView::_bind_methods() { ADD_SIGNAL(MethodInfo("transform_changed", PropertyInfo(Variant::REAL, "zoom"), PropertyInfo(Variant::VECTOR2, "scroll"))); + + ClassDB::bind_method(D_METHOD("_zoom_widget_changed"), &LayeredTileAtlasView::_zoom_widget_changed); + ClassDB::bind_method(D_METHOD("_center_view"), &LayeredTileAtlasView::_center_view); + ClassDB::bind_method(D_METHOD("_zoom_callback"), &LayeredTileAtlasView::_zoom_callback); + ClassDB::bind_method(D_METHOD("gui_input"), &LayeredTileAtlasView::gui_input); + ClassDB::bind_method(D_METHOD("_base_tiles_root_control_gui_input"), &LayeredTileAtlasView::_base_tiles_root_control_gui_input); + ClassDB::bind_method(D_METHOD("_draw_background_left"), &LayeredTileAtlasView::_draw_background_left); + ClassDB::bind_method(D_METHOD("_draw_base_tiles"), &LayeredTileAtlasView::_draw_base_tiles); + ClassDB::bind_method(D_METHOD("_draw_base_tiles_texture_grid"), &LayeredTileAtlasView::_draw_base_tiles_texture_grid); + ClassDB::bind_method(D_METHOD("_draw_base_tiles_shape_grid"), &LayeredTileAtlasView::_draw_base_tiles_shape_grid); + ClassDB::bind_method(D_METHOD("_alternative_tiles_root_control_gui_input"), &LayeredTileAtlasView::_alternative_tiles_root_control_gui_input); + ClassDB::bind_method(D_METHOD("_draw_background_right"), &LayeredTileAtlasView::_draw_background_right); + ClassDB::bind_method(D_METHOD("_draw_alternatives"), &LayeredTileAtlasView::_draw_alternatives); } LayeredTileAtlasView::LayeredTileAtlasView() { - set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); - Panel *panel = memnew(Panel); panel->set_clip_contents(true); panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - panel->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); + panel->set_anchors_and_margins_preset(Control::PRESET_WIDE); panel->set_h_size_flags(SIZE_EXPAND_FILL); panel->set_v_size_flags(SIZE_EXPAND_FILL); add_child(panel); zoom_widget = memnew(EditorZoomWidget); add_child(zoom_widget); - zoom_widget->set_anchors_and_offsets_preset(Control::PRESET_TOP_LEFT, Control::PRESET_MODE_MINSIZE, 2 * EDSCALE); - zoom_widget->connect("zoom_changed", callable_mp(this, &LayeredTileAtlasView::_zoom_widget_changed).unbind(1)); + zoom_widget->set_anchors_and_margins_preset(Control::PRESET_TOP_LEFT, Control::PRESET_MODE_MINSIZE, 2 * EDSCALE); + zoom_widget->connect("zoom_changed", this, "_zoom_widget_changed"); zoom_widget->set_shortcut_context(this); button_center_view = memnew(Button); - button_center_view->set_anchors_and_offsets_preset(Control::PRESET_TOP_RIGHT, Control::PRESET_MODE_MINSIZE, 5); - button_center_view->set_grow_direction_preset(Control::PRESET_TOP_RIGHT); - button_center_view->connect("pressed", callable_mp(this, &LayeredTileAtlasView::_center_view)); + button_center_view->set_anchors_and_margins_preset(Control::PRESET_TOP_RIGHT, Control::PRESET_MODE_MINSIZE, 5); + //button_center_view->set_grow_direction_preset(Control::PRESET_TOP_RIGHT); + button_center_view->connect("pressed", this, "_center_view"); button_center_view->set_flat(true); button_center_view->set_disabled(true); - button_center_view->set_tooltip_text(TTR("Center View")); + button_center_view->set_tooltip(TTR("Center View")); add_child(button_center_view); panner.instance(); - panner->set_callbacks(callable_mp(this, &LayeredTileAtlasView::_pan_callback), callable_mp(this, &LayeredTileAtlasView::_zoom_callback)); + panner->connect("panned", this, "_pan_callback"); + panner->connect("zoomed", this, "_zoom_callback"); panner->set_enable_rmb(true); center_container = memnew(CenterContainer); center_container->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); center_container->set_anchors_preset(Control::PRESET_CENTER); - center_container->connect("gui_input", callable_mp(this, &LayeredTileAtlasView::gui_input)); - center_container->connect("focus_exited", callable_mp(panner.ptr(), &ViewPanner::release_pan_key)); + center_container->connect("gui_input", this, "gui_input"); + center_container->connect("focus_exited", panner.ptr(), "release_pan_key"); center_container->set_focus_mode(FOCUS_CLICK); panel->add_child(center_container); @@ -660,74 +664,70 @@ LayeredTileAtlasView::LayeredTileAtlasView() { Label *base_tile_label = memnew(Label); base_tile_label->set_mouse_filter(Control::MOUSE_FILTER_PASS); base_tile_label->set_text(TTR("Base Tiles")); - base_tile_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); + base_tile_label->set_align(Label::ALIGN_CENTER); left_vbox->add_child(base_tile_label); base_tiles_root_control = memnew(Control); base_tiles_root_control->set_mouse_filter(Control::MOUSE_FILTER_PASS); base_tiles_root_control->set_v_size_flags(Control::SIZE_EXPAND_FILL); - base_tiles_root_control->connect("gui_input", callable_mp(this, &LayeredTileAtlasView::_base_tiles_root_control_gui_input)); + base_tiles_root_control->connect("gui_input", this, "_base_tiles_root_control_gui_input"); left_vbox->add_child(base_tiles_root_control); background_left = memnew(Control); background_left->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - background_left->set_anchors_and_offsets_preset(Control::PRESET_TOP_LEFT); - background_left->set_texture_repeat(TextureRepeat::TEXTURE_REPEAT_ENABLED); - background_left->connect("draw", callable_mp(this, &LayeredTileAtlasView::_draw_background_left)); + background_left->set_anchors_and_margins_preset(Control::PRESET_TOP_LEFT); + background_left->connect("draw", this, "_draw_background_left"); base_tiles_root_control->add_child(background_left); base_tiles_drawing_root = memnew(Control); base_tiles_drawing_root->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - base_tiles_drawing_root->set_texture_filter(TEXTURE_FILTER_NEAREST); base_tiles_root_control->add_child(base_tiles_drawing_root); base_tiles_draw = memnew(Control); base_tiles_draw->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - base_tiles_draw->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); - base_tiles_draw->connect("draw", callable_mp(this, &LayeredTileAtlasView::_draw_base_tiles)); + base_tiles_draw->set_anchors_and_margins_preset(Control::PRESET_WIDE); + base_tiles_draw->connect("draw", this, "_draw_base_tiles"); base_tiles_drawing_root->add_child(base_tiles_draw); base_tiles_texture_grid = memnew(Control); base_tiles_texture_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - base_tiles_texture_grid->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); - base_tiles_texture_grid->connect("draw", callable_mp(this, &LayeredTileAtlasView::_draw_base_tiles_texture_grid)); + base_tiles_texture_grid->set_anchors_and_margins_preset(Control::PRESET_WIDE); + base_tiles_texture_grid->connect("draw", this, "_draw_base_tiles_texture_grid"); base_tiles_drawing_root->add_child(base_tiles_texture_grid); base_tiles_shape_grid = memnew(Control); base_tiles_shape_grid->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - base_tiles_shape_grid->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); - base_tiles_shape_grid->connect("draw", callable_mp(this, &LayeredTileAtlasView::_draw_base_tiles_shape_grid)); + base_tiles_shape_grid->set_anchors_and_margins_preset(Control::PRESET_WIDE); + base_tiles_shape_grid->connect("draw", this, "_draw_base_tiles_shape_grid"); base_tiles_drawing_root->add_child(base_tiles_shape_grid); // Alternative tiles. Label *alternative_tiles_label = memnew(Label); alternative_tiles_label->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); alternative_tiles_label->set_text(TTR("Alternative Tiles")); - alternative_tiles_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); + alternative_tiles_label->set_align(Label::ALIGN_CENTER); right_vbox->add_child(alternative_tiles_label); alternative_tiles_root_control = memnew(Control); alternative_tiles_root_control->set_mouse_filter(Control::MOUSE_FILTER_PASS); alternative_tiles_root_control->set_v_size_flags(Control::SIZE_EXPAND_FILL); - alternative_tiles_root_control->connect("gui_input", callable_mp(this, &LayeredTileAtlasView::_alternative_tiles_root_control_gui_input)); + alternative_tiles_root_control->connect("gui_input", this, "_alternative_tiles_root_control_gui_input"); right_vbox->add_child(alternative_tiles_root_control); background_right = memnew(Control); background_right->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - background_right->set_anchors_and_offsets_preset(Control::PRESET_TOP_LEFT); - background_right->set_texture_repeat(TextureRepeat::TEXTURE_REPEAT_ENABLED); - background_right->connect("draw", callable_mp(this, &LayeredTileAtlasView::_draw_background_right)); + background_right->set_anchors_and_margins_preset(Control::PRESET_TOP_LEFT); + background_right->connect("draw", this, "_draw_background_right"); alternative_tiles_root_control->add_child(background_right); alternative_tiles_drawing_root = memnew(Control); alternative_tiles_drawing_root->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - alternative_tiles_drawing_root->set_texture_filter(TEXTURE_FILTER_NEAREST); alternative_tiles_root_control->add_child(alternative_tiles_drawing_root); alternatives_draw = memnew(Control); alternatives_draw->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); - alternatives_draw->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); - alternatives_draw->connect("draw", callable_mp(this, &LayeredTileAtlasView::_draw_alternatives)); + alternatives_draw->set_anchors_and_margins_preset(Control::PRESET_WIDE); + alternatives_draw->connect("draw", this, "_draw_alternatives"); alternative_tiles_drawing_root->add_child(alternatives_draw); } diff --git a/modules/layered_tile_map/editor/layered_tile_atlas_view.h b/modules/layered_tile_map/editor/layered_tile_atlas_view.h index 52a071b08..99fc82e1d 100644 --- a/modules/layered_tile_map/editor/layered_tile_atlas_view.h +++ b/modules/layered_tile_map/editor/layered_tile_atlas_view.h @@ -33,7 +33,8 @@ /*************************************************************************/ #include "../layered_tile_set.h" -#include "editor/gui/editor_zoom_widget.h" + +#include "editor/editor_zoom_widget.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/center_container.h" @@ -61,7 +62,7 @@ private: CenterContainer *center_container = nullptr; Vector2 panning; void _update_zoom_and_panning(bool p_zoom_on_mouse_pos = false); - void _zoom_widget_changed(); + void _zoom_widget_changed(float val); void _center_view(); virtual void gui_input(const Ref &p_event); @@ -93,7 +94,7 @@ private: HashMap, RID> material_tiles_draw; HashMap, RID> material_alternatives_draw; void _draw_base_tiles(); - RID _get_canvas_item_to_draw(const TileData *p_for_data, const CanvasItem *p_base_item, HashMap, RID> &p_material_map); + RID _get_canvas_item_to_draw(const LayeredTileData *p_for_data, const CanvasItem *p_base_item, HashMap, RID> &p_material_map); void _clear_material_canvas_items(); Control *base_tiles_texture_grid = nullptr; @@ -121,8 +122,6 @@ private: } theme_cache; protected: - virtual void _update_theme_item_cache(); - void _notification(int p_what); static void _bind_methods(); @@ -147,7 +146,7 @@ public: } else { base_tiles_root_control->add_child(p_control); } - p_control->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); + p_control->set_anchors_and_margins_preset(Control::PRESET_WIDE); p_control->set_mouse_filter(Control::MOUSE_FILTER_PASS); }; @@ -161,12 +160,12 @@ public: } else { alternative_tiles_root_control->add_child(p_control); } - p_control->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); + p_control->set_anchors_and_margins_preset(Control::PRESET_WIDE); p_control->set_mouse_filter(Control::MOUSE_FILTER_PASS); }; // Redraw everything. - void queue_redraw(); + void update(); LayeredTileAtlasView(); ~LayeredTileAtlasView(); diff --git a/modules/layered_tile_map/editor/layered_tile_data_editors.cpp b/modules/layered_tile_map/editor/layered_tile_data_editors.cpp index 8cf41bfba..67ed80d7c 100644 --- a/modules/layered_tile_map/editor/layered_tile_data_editors.cpp +++ b/modules/layered_tile_map/editor/layered_tile_data_editors.cpp @@ -265,12 +265,12 @@ void GenericTilePolygonEditor::_base_control_draw() { void GenericTilePolygonEditor::_center_view() { panning = Vector2(); - base_control->queue_redraw(); + base_control->update(); button_center_view->set_disabled(true); } void GenericTilePolygonEditor::_zoom_changed() { - base_control->queue_redraw(); + base_control->update(); } void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) { @@ -291,26 +291,26 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) { polygon.write[i] = polygon[i] * tile_set->get_tile_size(); } undo_redo->add_do_method(this, "add_polygon", polygon); - undo_redo->add_do_method(base_control, "queue_redraw"); + undo_redo->add_do_method(base_control, "update"); undo_redo->add_do_method(this, "emit_signal", "polygons_changed"); undo_redo->add_undo_method(this, "clear_polygons"); for (const PoolVector2Array &poly : polygons) { undo_redo->add_undo_method(this, "add_polygon", poly); } - undo_redo->add_undo_method(base_control, "queue_redraw"); + undo_redo->add_undo_method(base_control, "update"); undo_redo->add_undo_method(this, "emit_signal", "polygons_changed"); undo_redo->commit_action(true); } break; case CLEAR_TILE: { undo_redo->create_action(TTR("Clear Polygons")); undo_redo->add_do_method(this, "clear_polygons"); - undo_redo->add_do_method(base_control, "queue_redraw"); + undo_redo->add_do_method(base_control, "update"); undo_redo->add_do_method(this, "emit_signal", "polygons_changed"); undo_redo->add_undo_method(this, "clear_polygons"); for (const PoolVector2Array &polygon : polygons) { undo_redo->add_undo_method(this, "add_polygon", polygon); } - undo_redo->add_undo_method(base_control, "queue_redraw"); + undo_redo->add_undo_method(base_control, "update"); undo_redo->add_undo_method(this, "emit_signal", "polygons_changed"); undo_redo->commit_action(true); } break; @@ -358,12 +358,12 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) { } undo_redo->add_do_method(this, "set_polygon", i, new_polygon); } - undo_redo->add_do_method(base_control, "queue_redraw"); + undo_redo->add_do_method(base_control, "update"); undo_redo->add_do_method(this, "emit_signal", "polygons_changed"); for (unsigned int i = 0; i < polygons.size(); i++) { undo_redo->add_undo_method(this, "set_polygon", i, polygons[i]); } - undo_redo->add_undo_method(base_control, "queue_redraw"); + undo_redo->add_undo_method(base_control, "update"); undo_redo->add_undo_method(this, "emit_signal", "polygons_changed"); undo_redo->commit_action(true); } break; @@ -545,9 +545,9 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref p_event) undo_redo->add_do_method(this, "clear_polygons"); } undo_redo->add_do_method(this, "add_polygon", in_creation_polygon); - undo_redo->add_do_method(base_control, "queue_redraw"); + undo_redo->add_do_method(base_control, "update"); undo_redo->add_undo_method(this, "remove_polygon", added); - undo_redo->add_undo_method(base_control, "queue_redraw"); + undo_redo->add_undo_method(base_control, "update"); undo_redo->commit_action(false); emit_signal(SNAME("polygons_changed")); } else { @@ -593,8 +593,8 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref p_event) undo_redo->add_do_method(this, "set_polygon", closest_polygon, polygons[closest_polygon]); undo_redo->add_undo_method(this, "set_polygon", closest_polygon, old_polygon); } - undo_redo->add_do_method(base_control, "queue_redraw"); - undo_redo->add_undo_method(base_control, "queue_redraw"); + undo_redo->add_do_method(base_control, "update"); + undo_redo->add_undo_method(base_control, "update"); undo_redo->commit_action(false); emit_signal(SNAME("polygons_changed")); } @@ -603,9 +603,9 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref p_event) if (drag_type == DRAG_TYPE_DRAG_POINT) { undo_redo->create_action(TTR("Edit Polygons")); undo_redo->add_do_method(this, "set_polygon", drag_polygon_index, polygons[drag_polygon_index]); - undo_redo->add_do_method(base_control, "queue_redraw"); + undo_redo->add_do_method(base_control, "update"); undo_redo->add_undo_method(this, "set_polygon", drag_polygon_index, drag_old_polygon); - undo_redo->add_undo_method(base_control, "queue_redraw"); + undo_redo->add_undo_method(base_control, "update"); undo_redo->commit_action(false); emit_signal(SNAME("polygons_changed")); } else if (drag_type == DRAG_TYPE_CREATE_POINT) { @@ -638,8 +638,8 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref p_event) undo_redo->add_do_method(this, "set_polygon", closest_polygon, polygons[closest_polygon]); undo_redo->add_undo_method(this, "set_polygon", closest_polygon, old_polygon); } - undo_redo->add_do_method(base_control, "queue_redraw"); - undo_redo->add_undo_method(base_control, "queue_redraw"); + undo_redo->add_do_method(base_control, "update"); + undo_redo->add_undo_method(base_control, "update"); undo_redo->commit_action(false); emit_signal(SNAME("polygons_changed")); drag_type = DRAG_TYPE_NONE; @@ -664,7 +664,7 @@ void GenericTilePolygonEditor::_base_control_gui_input(Ref p_event) } } - base_control->queue_redraw(); + base_control->update(); if (!use_undo_redo) { memdelete(undo_redo); @@ -675,7 +675,7 @@ void GenericTilePolygonEditor::_set_snap_option(int p_index) { current_snap_option = p_index; button_pixel_snap->set_icon(button_pixel_snap->get_popup()->get_item_icon(p_index)); snap_subdivision->set_visible(p_index == SNAP_GRID); - base_control->queue_redraw(); + base_control->update(); _store_snap_options(); } @@ -745,7 +745,7 @@ void GenericTilePolygonEditor::set_background(Ref p_texture, Rect2 p_re background_v_flip = p_flip_v; background_transpose = p_transpose; background_modulate = p_modulate; - base_control->queue_redraw(); + base_control->update(); } int GenericTilePolygonEditor::get_polygon_count() { @@ -758,13 +758,13 @@ int GenericTilePolygonEditor::add_polygon(const Vector &p_polygon, int p if (p_index < 0) { polygons.push_back(p_polygon); - base_control->queue_redraw(); + base_control->update(); button_edit->set_pressed(true); return polygons.size() - 1; } else { polygons.insert(p_index, p_polygon); button_edit->set_pressed(true); - base_control->queue_redraw(); + base_control->update(); return p_index; } } @@ -776,12 +776,12 @@ void GenericTilePolygonEditor::remove_polygon(int p_index) { if (polygons.size() == 0) { button_create->set_pressed(true); } - base_control->queue_redraw(); + base_control->update(); } void GenericTilePolygonEditor::clear_polygons() { polygons.clear(); - base_control->queue_redraw(); + base_control->update(); } void GenericTilePolygonEditor::set_polygon(int p_polygon_index, const Vector &p_polygon) { @@ -789,7 +789,7 @@ void GenericTilePolygonEditor::set_polygon(int p_polygon_index, const Vectorset_pressed(true); - base_control->queue_redraw(); + base_control->update(); } Vector GenericTilePolygonEditor::get_polygon(int p_polygon_index) { @@ -799,7 +799,7 @@ Vector GenericTilePolygonEditor::get_polygon(int p_polygon_index) { void GenericTilePolygonEditor::set_polygons_color(Color p_color) { polygon_color = p_color; - base_control->queue_redraw(); + base_control->update(); } void GenericTilePolygonEditor::set_multiple_polygon_mode(bool p_multiple_polygon_mode) { @@ -855,7 +855,7 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() { button_expand->set_theme_type_variation("FlatButton"); button_expand->set_toggle_mode(true); button_expand->set_pressed(false); - button_expand->set_tooltip_text(TTR("Expand editor")); + button_expand->set_tooltip(TTR("Expand editor")); button_expand->connect("toggled", callable_mp(this, &GenericTilePolygonEditor::_toggle_expand)); toolbar->add_child(button_expand); @@ -866,21 +866,21 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() { button_create->set_toggle_mode(true); button_create->set_button_group(tools_button_group); button_create->set_pressed(true); - button_create->set_tooltip_text(TTR("Add polygon tool")); + button_create->set_tooltip(TTR("Add polygon tool")); toolbar->add_child(button_create); button_edit = memnew(Button); button_edit->set_theme_type_variation("FlatButton"); button_edit->set_toggle_mode(true); button_edit->set_button_group(tools_button_group); - button_edit->set_tooltip_text(TTR("Edit points tool")); + button_edit->set_tooltip(TTR("Edit points tool")); toolbar->add_child(button_edit); button_delete = memnew(Button); button_delete->set_theme_type_variation("FlatButton"); button_delete->set_toggle_mode(true); button_delete->set_button_group(tools_button_group); - button_delete->set_tooltip_text(TTR("Delete points tool")); + button_delete->set_tooltip(TTR("Delete points tool")); toolbar->add_child(button_delete); button_advanced_menu = memnew(MenuButton); @@ -904,7 +904,7 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() { toolbar->add_child(button_pixel_snap); button_pixel_snap->set_flat(false); button_pixel_snap->set_theme_type_variation("FlatMenuButton"); - button_pixel_snap->set_tooltip_text(TTR("Toggle Grid Snap")); + button_pixel_snap->set_tooltip(TTR("Toggle Grid Snap")); button_pixel_snap->get_popup()->add_item(TTR("Disable Snap"), SNAP_NONE); button_pixel_snap->get_popup()->add_item(TTR("Half-Pixel Snap"), SNAP_HALF_PIXEL); button_pixel_snap->get_popup()->add_item(TTR("Grid Snap"), SNAP_GRID); @@ -923,19 +923,19 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() { add_child(root); panel = memnew(Panel); - panel->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); + panel->set_anchors_and_margins_preset(Control::PRESET_WIDE); panel->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); root->add_child(panel); base_control = memnew(Control); base_control->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); - base_control->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); + base_control->set_anchors_and_margins_preset(Control::PRESET_WIDE); base_control->connect("draw", callable_mp(this, &GenericTilePolygonEditor::_base_control_draw)); base_control->connect("gui_input", callable_mp(this, &GenericTilePolygonEditor::_base_control_gui_input)); base_control->set_clip_contents(true); base_control->set_focus_mode(Control::FOCUS_CLICK); root->add_child(base_control); - snap_subdivision->connect("value_changed", callable_mp((CanvasItem *)base_control, &CanvasItem::queue_redraw).unbind(1)); + snap_subdivision->connect("value_changed", callable_mp((CanvasItem *)base_control, &CanvasItem::update).unbind(1)); snap_subdivision->connect("value_changed", callable_mp(this, &GenericTilePolygonEditor::_store_snap_options).unbind(1)); editor_zoom_widget = memnew(EditorZoomWidget); @@ -946,7 +946,7 @@ GenericTilePolygonEditor::GenericTilePolygonEditor() { root->add_child(editor_zoom_widget); button_center_view = memnew(Button); - button_center_view->set_anchors_and_offsets_preset(Control::PRESET_TOP_RIGHT, Control::PRESET_MODE_MINSIZE, 5); + button_center_view->set_anchors_and_margins_preset(Control::PRESET_TOP_RIGHT, Control::PRESET_MODE_MINSIZE, 5); button_center_view->connect("pressed", callable_mp(this, &GenericTilePolygonEditor::_center_view)); button_center_view->set_theme_type_variation("FlatButton"); button_center_view->set_disabled(true); @@ -1247,8 +1247,8 @@ void TileDataDefaultEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2 } Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); - p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 4), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 3, Color(0, 0, 0)); - p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 4), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color); + p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 4), text, Label::ALIGN_CENTER, string_size.x, font_size, 3, Color(0, 0, 0)); + p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 4), text, Label::ALIGN_CENTER, string_size.x, font_size, color); } } @@ -1284,7 +1284,7 @@ void TileDataDefaultEditor::setup_property_editor(Variant::Type p_type, const St property_editor->set_label(p_label); } property_editor->connect("property_changed", callable_mp(this, &TileDataDefaultEditor::_property_value_changed).unbind(1)); - property_editor->set_tooltip_text(p_property); + property_editor->set_tooltip(p_property); property_editor->update_property(); add_child(property_editor); } @@ -1351,8 +1351,8 @@ void TileDataTextureOriginEditor::draw_over_tile(CanvasItem *p_canvas_item, Tran Vector2 texture_origin = tile_data->get_texture_origin(); String text = vformat("%s", texture_origin); Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); - p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); - p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color); + p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, Label::ALIGN_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); + p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, Label::ALIGN_CENTER, string_size.x, font_size, color); } } @@ -1399,8 +1399,8 @@ void TileDataYSortEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D String text = vformat("%s", tile_data->get_y_sort_origin()); Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); - p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); - p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color); + p_canvas_item->draw_string_outline(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, Label::ALIGN_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); + p_canvas_item->draw_string(font, p_transform.xform(-texture_origin) + Vector2i(-string_size.x / 2, string_size.y / 2), text, Label::ALIGN_CENTER, string_size.x, font_size, color); } } @@ -1524,7 +1524,7 @@ void TileDataCollisionEditor::_polygons_changed() { one_way_property_editor->set_label(one_way_property); one_way_property_editor->connect("property_changed", callable_mp(this, &TileDataCollisionEditor::_property_value_changed).unbind(1)); one_way_property_editor->connect("selected", callable_mp(this, &TileDataCollisionEditor::_property_selected)); - one_way_property_editor->set_tooltip_text(one_way_property_editor->get_edited_property()); + one_way_property_editor->set_tooltip(one_way_property_editor->get_edited_property()); one_way_property_editor->update_property(); add_child(one_way_property_editor); property_editors[one_way_property] = one_way_property_editor; @@ -1536,7 +1536,7 @@ void TileDataCollisionEditor::_polygons_changed() { one_way_margin_property_editor->set_label(one_way_margin_property); one_way_margin_property_editor->connect("property_changed", callable_mp(this, &TileDataCollisionEditor::_property_value_changed).unbind(1)); one_way_margin_property_editor->connect("selected", callable_mp(this, &TileDataCollisionEditor::_property_selected)); - one_way_margin_property_editor->set_tooltip_text(one_way_margin_property_editor->get_edited_property()); + one_way_margin_property_editor->set_tooltip(one_way_margin_property_editor->get_edited_property()); one_way_margin_property_editor->update_property(); add_child(one_way_margin_property_editor); property_editors[one_way_margin_property] = one_way_margin_property_editor; @@ -1702,7 +1702,7 @@ TileDataCollisionEditor::TileDataCollisionEditor() { linear_velocity_editor->set_label("linear_velocity"); linear_velocity_editor->connect("property_changed", callable_mp(this, &TileDataCollisionEditor::_property_value_changed).unbind(1)); linear_velocity_editor->connect("selected", callable_mp(this, &TileDataCollisionEditor::_property_selected)); - linear_velocity_editor->set_tooltip_text(linear_velocity_editor->get_edited_property()); + linear_velocity_editor->set_tooltip(linear_velocity_editor->get_edited_property()); linear_velocity_editor->update_property(); add_child(linear_velocity_editor); property_editors["linear_velocity"] = linear_velocity_editor; @@ -1712,7 +1712,7 @@ TileDataCollisionEditor::TileDataCollisionEditor() { angular_velocity_editor->set_label("angular_velocity"); angular_velocity_editor->connect("property_changed", callable_mp(this, &TileDataCollisionEditor::_property_value_changed).unbind(1)); angular_velocity_editor->connect("selected", callable_mp(this, &TileDataCollisionEditor::_property_selected)); - angular_velocity_editor->set_tooltip_text(angular_velocity_editor->get_edited_property()); + angular_velocity_editor->set_tooltip(angular_velocity_editor->get_edited_property()); angular_velocity_editor->update_property(); add_child(angular_velocity_editor); property_editors["angular_velocity"] = angular_velocity_editor; @@ -1914,8 +1914,8 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(LayeredTileAtlasView *p_til text = "-"; } Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); - p_canvas_item->draw_string_outline(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); - p_canvas_item->draw_string(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color); + p_canvas_item->draw_string_outline(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, Label::ALIGN_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); + p_canvas_item->draw_string(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, Label::ALIGN_CENTER, string_size.x, font_size, color); } } } @@ -2106,8 +2106,8 @@ void TileDataTerrainsEditor::forward_draw_over_alternatives(LayeredTileAtlasView text = "-"; } Vector2 string_size = font->get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size); - p_canvas_item->draw_string_outline(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); - p_canvas_item->draw_string(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, HORIZONTAL_ALIGNMENT_CENTER, string_size.x, font_size, color); + p_canvas_item->draw_string_outline(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, Label::ALIGN_CENTER, string_size.x, font_size, 1, Color(0, 0, 0, 1)); + p_canvas_item->draw_string(font, p_transform.xform(position) + Vector2i(-string_size.x / 2, string_size.y / 2), text, Label::ALIGN_CENTER, string_size.x, font_size, color); } } } @@ -2814,7 +2814,7 @@ TileDataTerrainsEditor::TileDataTerrainsEditor() { terrain_set_property_editor->set_object_and_property(dummy_object, "terrain_set"); terrain_set_property_editor->set_label("Terrain Set"); terrain_set_property_editor->connect("property_changed", callable_mp(this, &TileDataTerrainsEditor::_property_value_changed).unbind(1)); - terrain_set_property_editor->set_tooltip_text(terrain_set_property_editor->get_edited_property()); + terrain_set_property_editor->set_tooltip(terrain_set_property_editor->get_edited_property()); add_child(terrain_set_property_editor); terrain_property_editor = memnew(EditorPropertyEnum); diff --git a/modules/layered_tile_map/editor/layered_tile_data_editors.h b/modules/layered_tile_map/editor/layered_tile_data_editors.h index 5758b3d18..f23ab00cc 100644 --- a/modules/layered_tile_map/editor/layered_tile_data_editors.h +++ b/modules/layered_tile_map/editor/layered_tile_data_editors.h @@ -32,7 +32,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "tile_atlas_view.h" +#include "layered_tile_atlas_view.h" #include "../layered_tile_map.h" #include "editor/editor_properties.h" @@ -54,7 +54,7 @@ private: protected: Ref tile_set; - TileData *_get_tile_data(LayeredTileMapCell p_cell); + LayeredTileData *_get_tile_data(LayeredTileMapCell p_cell); virtual void _tile_set_changed(){}; static void _bind_methods(); diff --git a/modules/layered_tile_map/editor/layered_tile_map_layer_editor.cpp b/modules/layered_tile_map/editor/layered_tile_map_layer_editor.cpp index 393e9f361..b0d84be8c 100644 --- a/modules/layered_tile_map/editor/layered_tile_map_layer_editor.cpp +++ b/modules/layered_tile_map/editor/layered_tile_map_layer_editor.cpp @@ -135,11 +135,11 @@ void LayeredTileMapLayerEditorTilesPlugin::_update_transform_buttons() { void LayeredTileMapLayerEditorTilesPlugin::_set_transform_buttons_state(const Vector