Work on fixing compile when layered tile maps are enabled.

This commit is contained in:
Relintai 2024-03-07 07:00:43 +01:00
parent 3d791b4d4a
commit 2e45ffc5ea
2 changed files with 117 additions and 73 deletions

View File

@ -31,23 +31,28 @@
#include "layered_tile_set_editor.h" #include "layered_tile_set_editor.h"
#include "core/core_string_names.h"
#include "layered_tile_data_editors.h" #include "layered_tile_data_editors.h"
#include "layered_tiles_editor_plugin.h" #include "layered_tiles_editor_plugin.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_file_system.h" #include "editor/editor_file_system.h"
#include "editor/editor_inspector.h" #include "editor/editor_inspector.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_scale.h" #include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "core/object/undo_redo.h" #include "core/object/undo_redo.h"
#include "scene/gui/box_container.h" #include "scene/gui/box_container.h"
#include "scene/gui/dialogs.h" #include "scene/gui/dialogs.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/tab_container.h" #include "scene/gui/tab_container.h"
#include "scene/main/control.h" #include "scene/main/control.h"
#include <limits.h>
LayeredTileSetEditor *LayeredTileSetEditor::singleton = nullptr; LayeredTileSetEditor *LayeredTileSetEditor::singleton = nullptr;
void LayeredTileSetEditor::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { void LayeredTileSetEditor::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
@ -105,7 +110,9 @@ void LayeredTileSetEditor::_load_texture_files(const Vector<String> &p_paths) {
int source_id = LayeredTileSet::INVALID_SOURCE; int source_id = LayeredTileSet::INVALID_SOURCE;
Vector<Ref<LayeredTileSetAtlasSource>> atlases; Vector<Ref<LayeredTileSetAtlasSource>> atlases;
for (const String &p_path : p_paths) { for (int i = 0; i < p_paths.size(); ++i) {
const String &p_path = p_paths[i];
Ref<Texture> texture = ResourceLoader::load(p_path); Ref<Texture> texture = ResourceLoader::load(p_path);
if (texture.is_null()) { if (texture.is_null()) {
@ -127,7 +134,7 @@ void LayeredTileSetEditor::_load_texture_files(const Vector<String> &p_paths) {
undo_redo->add_undo_method(*tile_set, "remove_source", source_id); undo_redo->add_undo_method(*tile_set, "remove_source", source_id);
undo_redo->commit_action(); undo_redo->commit_action();
atlases.append(atlas_source); atlases.push_back(atlas_source);
} }
if (!atlases.empty()) { if (!atlases.empty()) {
@ -164,7 +171,10 @@ void LayeredTileSetEditor::_update_sources_list(int force_selected_id) {
// Update the atlas sources. // Update the atlas sources.
List<int> source_ids = LayeredTilesEditorUtils::get_singleton()->get_sorted_sources(tile_set); List<int> source_ids = LayeredTilesEditorUtils::get_singleton()->get_sorted_sources(tile_set);
for (const int &source_id : source_ids) {
for (const List<int>::Element *E = source_ids.front(); E; E = E->next()) {
const int source_id = E->get();
LayeredTileSetSource *source = *tile_set->get_source(source_id); LayeredTileSetSource *source = *tile_set->get_source(source_id);
Ref<Texture> texture; Ref<Texture> texture;
@ -191,7 +201,7 @@ void LayeredTileSetEditor::_update_sources_list(int force_selected_id) {
// Scene collection source. // Scene collection source.
LayeredTileSetScenesCollectionSource *scene_collection_source = Object::cast_to<LayeredTileSetScenesCollectionSource>(source); LayeredTileSetScenesCollectionSource *scene_collection_source = Object::cast_to<LayeredTileSetScenesCollectionSource>(source);
if (scene_collection_source) { if (scene_collection_source) {
texture = get_theme_icon(SNAME("PackedScene"), "EditorIcons"); texture = get_theme_icon("PackedScene", "EditorIcons");
if (item_text.empty()) { if (item_text.empty()) {
if (scene_collection_source->get_scene_tiles_count() > 0) { if (scene_collection_source->get_scene_tiles_count() > 0) {
item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id); item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id);
@ -220,7 +230,7 @@ void LayeredTileSetEditor::_update_sources_list(int force_selected_id) {
sources_list->set_current(i); sources_list->set_current(i);
sources_list->ensure_current_is_visible(); sources_list->ensure_current_is_visible();
if (old_selected != to_select) { if (old_selected != to_select) {
sources_list->emit_signal(SNAME("item_selected"), sources_list->get_current()); sources_list->emit_signal("item_selected", sources_list->get_current());
} }
break; break;
} }
@ -231,7 +241,7 @@ void LayeredTileSetEditor::_update_sources_list(int force_selected_id) {
if (sources_list->get_current() < 0 && sources_list->get_item_count() > 0) { if (sources_list->get_current() < 0 && sources_list->get_item_count() > 0) {
sources_list->set_current(0); sources_list->set_current(0);
if (old_selected != int(sources_list->get_item_metadata(0))) { if (old_selected != int(sources_list->get_item_metadata(0))) {
sources_list->emit_signal(SNAME("item_selected"), sources_list->get_current()); sources_list->emit_signal("item_selected", sources_list->get_current());
} }
} }
@ -300,16 +310,17 @@ void LayeredTileSetEditor::_source_add_id_pressed(int p_id_pressed) {
if (!texture_file_dialog) { if (!texture_file_dialog) {
texture_file_dialog = memnew(EditorFileDialog); texture_file_dialog = memnew(EditorFileDialog);
add_child(texture_file_dialog); add_child(texture_file_dialog);
texture_file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES); texture_file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILES);
texture_file_dialog->connect("files_selected", callable_mp(this, &LayeredTileSetEditor::_load_texture_files)); texture_file_dialog->connect("files_selected", this, "_load_texture_files");
List<String> extensions; List<String> extensions;
ResourceLoader::get_recognized_extensions_for_type("Texture", &extensions); ResourceLoader::get_recognized_extensions_for_type("Texture", &extensions);
for (const String &E : extensions) {
texture_file_dialog->add_filter("*." + E, E.to_upper()); for (const List<String>::Element *E = extensions.front(); E; E = E->next()) {
texture_file_dialog->add_filter("*." + E->get() + ";" + E->get().to_upper());
} }
} }
texture_file_dialog->popup_file_dialog(); texture_file_dialog->popup_centered();
} break; } break;
case 1: { case 1: {
int source_id = tile_set->get_next_source_id(); int source_id = tile_set->get_next_source_id();
@ -362,14 +373,34 @@ void LayeredTileSetEditor::_set_source_sort(int p_sort) {
EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "tile_source_sort", p_sort); EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "tile_source_sort", p_sort);
} }
void LayeredTileSetEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_load_texture_files"), &LayeredTileSetEditor::_load_texture_files);
ClassDB::bind_method(D_METHOD("_tile_set_changed"), &LayeredTileSetEditor::_tile_set_changed);
ClassDB::bind_method(D_METHOD("_pattern_preview_done"), &LayeredTileSetEditor::_pattern_preview_done);
ClassDB::bind_method(D_METHOD("_tab_changed"), &LayeredTileSetEditor::_tab_changed);
ClassDB::bind_method(D_METHOD("_drop_data_fw"), &LayeredTileSetEditor::_drop_data_fw);
ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &LayeredTileSetEditor::_can_drop_data_fw);
ClassDB::bind_method(D_METHOD("_set_source_sort"), &LayeredTileSetEditor::_set_source_sort);
ClassDB::bind_method(D_METHOD("_source_selected"), &LayeredTileSetEditor::_source_selected);
ClassDB::bind_method(D_METHOD("_source_delete_pressed"), &LayeredTileSetEditor::_source_delete_pressed);
ClassDB::bind_method(D_METHOD("_source_add_id_pressed"), &LayeredTileSetEditor::_source_add_id_pressed);
ClassDB::bind_method(D_METHOD("_sources_advanced_menu_id_pressed"), &LayeredTileSetEditor::_sources_advanced_menu_id_pressed);
ClassDB::bind_method(D_METHOD("_update_sources_list"), &LayeredTileSetEditor::_update_sources_list);
ClassDB::bind_method(D_METHOD("_patterns_item_list_gui_input"), &LayeredTileSetEditor::_patterns_item_list_gui_input);
ClassDB::bind_method(D_METHOD("_move_tile_set_array_element"), &LayeredTileSetEditor::_move_tile_set_array_element);
}
void LayeredTileSetEditor::_notification(int p_what) { void LayeredTileSetEditor::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
sources_delete_button->set_icon(get_theme_icon(SNAME("Remove"), "EditorIcons")); sources_delete_button->set_icon(get_theme_icon("Remove", "EditorIcons"));
sources_add_button->set_icon(get_theme_icon(SNAME("Add"), "EditorIcons")); sources_add_button->set_icon(get_theme_icon("Add", "EditorIcons"));
source_sort_button->set_icon(get_theme_icon(SNAME("Sort"), "EditorIcons")); source_sort_button->set_icon(get_theme_icon("Sort", "EditorIcons"));
sources_advanced_menu_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), "EditorIcons")); sources_advanced_menu_button->set_icon(get_theme_icon("GuiTabMenuHl", "EditorIcons"));
missing_texture_texture = get_theme_icon(SNAME("LayeredTileSet"), "EditorIcons"); missing_texture_texture = get_theme_icon("LayeredTileSet", "EditorIcons");
expanded_area->add_theme_style_override("panel", get_theme_stylebox("panel", "Tree")); expanded_area->add_theme_style_override("panel", get_theme_stylebox("panel", "Tree"));
_update_sources_list(); _update_sources_list();
} break; } break;
@ -381,9 +412,9 @@ void LayeredTileSetEditor::_notification(int p_what) {
} }
read_only = false; read_only = false;
if (tile_set.is_valid()) { //if (tile_set.is_valid()) {
read_only = EditorNode::get_singleton()->is_resource_read_only(tile_set); // read_only = EditorNode::get_singleton()->is_resource_read_only(tile_set);
} //}
_update_sources_list(); _update_sources_list();
_update_patterns_list(); _update_patterns_list();
@ -407,10 +438,6 @@ void LayeredTileSetEditor::_notification(int p_what) {
void LayeredTileSetEditor::_patterns_item_list_gui_input(const Ref<InputEvent> &p_event) { void LayeredTileSetEditor::_patterns_item_list_gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(!tile_set.is_valid()); ERR_FAIL_COND(!tile_set.is_valid());
if (EditorNode::get_singleton()->is_resource_read_only(tile_set)) {
return;
}
if (ED_IS_SHORTCUT("tiles_editor/delete", p_event) && p_event->is_pressed() && !p_event->is_echo()) { if (ED_IS_SHORTCUT("tiles_editor/delete", p_event) && p_event->is_pressed() && !p_event->is_echo()) {
Vector<int> selected = patterns_item_list->get_selected_items(); Vector<int> selected = patterns_item_list->get_selected_items();
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
@ -441,10 +468,11 @@ void LayeredTileSetEditor::_update_patterns_list() {
// Recreate the items. // Recreate the items.
patterns_item_list->clear(); patterns_item_list->clear();
for (int i = 0; i < tile_set->get_patterns_count(); i++) { for (int i = 0; i < tile_set->get_patterns_count(); i++) {
int id = patterns_item_list->add_item(""); patterns_item_list->add_item("");
int id = patterns_item_list->get_item_count() - 1;
patterns_item_list->set_item_metadata(id, tile_set->get_pattern(i)); patterns_item_list->set_item_metadata(id, tile_set->get_pattern(i));
patterns_item_list->set_item_tooltip(id, vformat(TTR("Index: %d"), i)); patterns_item_list->set_item_tooltip(id, vformat(TTR("Index: %d"), i));
LayeredTilesEditorUtils::get_singleton()->queue_pattern_preview(tile_set, tile_set->get_pattern(i), callable_mp(this, &LayeredTileSetEditor::_pattern_preview_done)); LayeredTilesEditorUtils::get_singleton()->queue_pattern_preview(tile_set, tile_set->get_pattern(i), this, "_pattern_preview_done");
} }
// Update the label visibility. // Update the label visibility.
@ -539,7 +567,10 @@ void LayeredTileSetEditor::_move_tile_set_array_element(Object *p_undo_redo, Obj
// Save layers' properties. // Save layers' properties.
List<PropertyInfo> properties; List<PropertyInfo> properties;
ed_tile_set->get_property_list(&properties); ed_tile_set->get_property_list(&properties);
for (PropertyInfo pi : properties) {
for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
PropertyInfo pi = E->get();
if (pi.name.begins_with(p_array_prefix)) { if (pi.name.begins_with(p_array_prefix)) {
String str = pi.name.trim_prefix(p_array_prefix); String str = pi.name.trim_prefix(p_array_prefix);
int to_char_index = 0; int to_char_index = 0;
@ -568,7 +599,7 @@ void LayeredTileSetEditor::_move_tile_set_array_element(Object *p_undo_redo, Obj
Vector2i tile_id = tas->get_tile_id(j); Vector2i tile_id = tas->get_tile_id(j);
for (int k = 0; k < tas->get_alternative_tiles_count(tile_id); k++) { for (int k = 0; k < tas->get_alternative_tiles_count(tile_id); k++) {
int alternative_id = tas->get_alternative_tile_id(tile_id, k); int alternative_id = tas->get_alternative_tile_id(tile_id, k);
TileData *tile_data = tas->get_tile_data(tile_id, alternative_id); LayeredTileData *tile_data = tas->get_tile_data(tile_id, alternative_id);
ERR_FAIL_NULL(tile_data); ERR_FAIL_NULL(tile_data);
// Actually saving stuff. // Actually saving stuff.
@ -712,33 +743,25 @@ void LayeredTileSetEditor::_undo_redo_inspector_callback(Object *p_undo_redo, Ob
} }
void LayeredTileSetEditor::edit(Ref<LayeredTileSet> p_tile_set) { void LayeredTileSetEditor::edit(Ref<LayeredTileSet> p_tile_set) {
bool new_read_only_state = false; if (p_tile_set == tile_set) {
if (p_tile_set.is_valid()) {
new_read_only_state = EditorNode::get_singleton()->is_resource_read_only(p_tile_set);
}
if (p_tile_set == tile_set && new_read_only_state == read_only) {
return; return;
} }
// Remove listener. // Remove listener.
if (tile_set.is_valid()) { if (tile_set.is_valid()) {
tile_set->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &LayeredTileSetEditor::_tile_set_changed)); tile_set->disconnect(CoreStringNames::get_singleton()->changed, this, "_tile_set_changed");
} }
// Change the edited object. // Change the edited object.
tile_set = p_tile_set; tile_set = p_tile_set;
// Read-only status is false by default
read_only = new_read_only_state;
// Add the listener again and check for read-only status. // Add the listener again and check for read-only status.
if (tile_set.is_valid()) { if (tile_set.is_valid()) {
sources_add_button->set_disabled(read_only); sources_add_button->set_disabled(read_only);
sources_advanced_menu_button->set_disabled(read_only); sources_advanced_menu_button->set_disabled(read_only);
source_sort_button->set_disabled(read_only); source_sort_button->set_disabled(read_only);
tile_set->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &LayeredTileSetEditor::_tile_set_changed)); tile_set->connect(CoreStringNames::get_singleton()->changed, this, "_tile_set_changed");
if (first_edit) { if (first_edit) {
first_edit = false; first_edit = false;
_set_source_sort(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "tile_source_sort", 0)); _set_source_sort(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "tile_source_sort", 0));
@ -770,11 +793,14 @@ void LayeredTileSetEditor::add_expanded_editor(Control *p_editor) {
ERR_FAIL_NULL(parent_container); ERR_FAIL_NULL(parent_container);
expanded_editor->set_meta("reparented", true); expanded_editor->set_meta("reparented", true);
expanded_editor->reparent(expanded_area); expanded_editor->get_parent()->remove_child(expanded_editor);
expanded_area->add_child(expanded_editor);
expanded_area->show(); expanded_area->show();
expanded_area->set_size(Vector2(parent_container->get_global_rect().get_end().x - expanded_area->get_global_position().x, expanded_area->get_size().y)); expanded_area->set_size(Vector2(parent_container->get_global_rect().get_end().x - expanded_area->get_global_position().x, expanded_area->get_size().y));
for (SplitContainer *split : disable_on_expand) { for (int i = 0; i < disable_on_expand.size(); ++i) {
SplitContainer *split = disable_on_expand[i];
split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN); split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
} }
} }
@ -787,15 +813,18 @@ void LayeredTileSetEditor::remove_expanded_editor() {
Node *original_parent = Object::cast_to<Node>(ObjectDB::get_instance(expanded_editor_parent)); Node *original_parent = Object::cast_to<Node>(ObjectDB::get_instance(expanded_editor_parent));
if (original_parent) { if (original_parent) {
expanded_editor->remove_meta("reparented"); expanded_editor->remove_meta("reparented");
expanded_editor->reparent(original_parent); expanded_editor->get_parent()->remove_child(expanded_editor);
expanded_area->add_child(original_parent);
} else { } else {
expanded_editor->queue_free(); expanded_editor->queue_delete();
} }
expanded_editor = nullptr; expanded_editor = nullptr;
expanded_editor_parent = ObjectID(); expanded_editor_parent = ObjectID();
expanded_area->hide(); expanded_area->hide();
for (SplitContainer *split : disable_on_expand) { for (int i = 0; i < disable_on_expand.size(); ++i) {
SplitContainer *split = disable_on_expand[i];
split->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE); split->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE);
} }
} }
@ -815,11 +844,11 @@ LayeredTileSetEditor::LayeredTileSetEditor() {
// Tabs. // Tabs.
tabs_bar = memnew(Tabs); tabs_bar = memnew(Tabs);
tabs_bar->set_tab_alignment(Tabs::ALIGNMENT_CENTER); tabs_bar->set_tab_align(Tabs::ALIGN_CENTER);
tabs_bar->set_clip_tabs(false); //tabs_bar->set_clip_tabs(false);
tabs_bar->add_tab(TTR("Tiles")); tabs_bar->add_tab(TTR("Tiles"));
tabs_bar->add_tab(TTR("Patterns")); tabs_bar->add_tab(TTR("Patterns"));
tabs_bar->connect("tab_changed", callable_mp(this, &LayeredTileSetEditor::_tab_changed)); tabs_bar->connect("tab_changed", this, "_tab_changed");
tile_set_toolbar = memnew(HBoxContainer); tile_set_toolbar = memnew(HBoxContainer);
tile_set_toolbar->set_h_size_flags(SIZE_EXPAND_FILL); tile_set_toolbar->set_h_size_flags(SIZE_EXPAND_FILL);
@ -848,7 +877,7 @@ LayeredTileSetEditor::LayeredTileSetEditor() {
source_sort_button->set_tooltip(TTR("Sort Sources")); source_sort_button->set_tooltip(TTR("Sort Sources"));
PopupMenu *p = source_sort_button->get_popup(); PopupMenu *p = source_sort_button->get_popup();
p->connect("id_pressed", callable_mp(this, &LayeredTileSetEditor::_set_source_sort)); p->connect("id_pressed", this, "_set_source_sort");
p->add_radio_check_item(TTR("Sort by ID (Ascending)"), LayeredTilesEditorUtils::SOURCE_SORT_ID); p->add_radio_check_item(TTR("Sort by ID (Ascending)"), LayeredTilesEditorUtils::SOURCE_SORT_ID);
p->add_radio_check_item(TTR("Sort by ID (Descending)"), LayeredTilesEditorUtils::SOURCE_SORT_ID_REVERSE); p->add_radio_check_item(TTR("Sort by ID (Descending)"), LayeredTilesEditorUtils::SOURCE_SORT_ID_REVERSE);
p->add_radio_check_item(TTR("Sort by Name (Ascending)"), LayeredTilesEditorUtils::SOURCE_SORT_NAME); p->add_radio_check_item(TTR("Sort by Name (Ascending)"), LayeredTilesEditorUtils::SOURCE_SORT_NAME);
@ -856,27 +885,27 @@ LayeredTileSetEditor::LayeredTileSetEditor() {
p->set_item_checked(LayeredTilesEditorUtils::SOURCE_SORT_ID, true); p->set_item_checked(LayeredTilesEditorUtils::SOURCE_SORT_ID, true);
sources_list = memnew(ItemList); sources_list = memnew(ItemList);
sources_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
sources_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE); sources_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE);
sources_list->set_h_size_flags(SIZE_EXPAND_FILL); sources_list->set_h_size_flags(SIZE_EXPAND_FILL);
sources_list->set_v_size_flags(SIZE_EXPAND_FILL); sources_list->set_v_size_flags(SIZE_EXPAND_FILL);
sources_list->connect("item_selected", callable_mp(this, &LayeredTileSetEditor::_source_selected)); sources_list->connect("item_selected", this, "_source_selected");
sources_list->connect("item_selected", callable_mp(LayeredTilesEditorUtils::get_singleton(), &LayeredTilesEditorUtils::set_sources_lists_current)); sources_list->connect("item_selected", LayeredTilesEditorUtils::get_singleton(), "set_sources_lists_current");
sources_list->connect("visibility_changed", callable_mp(LayeredTilesEditorUtils::get_singleton(), &LayeredTilesEditorUtils::synchronize_sources_list).bind(sources_list, source_sort_button)); sources_list->connect("visibility_changed", LayeredTilesEditorUtils::get_singleton(), "synchronize_sources_list", varray(sources_list, source_sort_button));
sources_list->add_user_signal(MethodInfo("sort_request")); sources_list->add_user_signal(MethodInfo("sort_request"));
sources_list->connect("sort_request", callable_mp(this, &LayeredTileSetEditor::_update_sources_list).bind(-1)); sources_list->connect("sort_request", this, "_update_sources_list");
sources_list->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST);
SET_DRAG_FORWARDING_CDU(sources_list, LayeredTileSetEditor); sources_list->set_drag_forwarding(this);
split_container_left_side->add_child(sources_list); split_container_left_side->add_child(sources_list);
HBoxContainer *sources_bottom_actions = memnew(HBoxContainer); HBoxContainer *sources_bottom_actions = memnew(HBoxContainer);
sources_bottom_actions->set_alignment(BoxContainer::ALIGNMENT_END); sources_bottom_actions->set_alignment(BoxContainer::ALIGN_END);
split_container_left_side->add_child(sources_bottom_actions); split_container_left_side->add_child(sources_bottom_actions);
sources_delete_button = memnew(Button); sources_delete_button = memnew(Button);
sources_delete_button->set_theme_type_variation("FlatButton"); sources_delete_button->set_theme_type_variation("FlatButton");
sources_delete_button->set_disabled(true); sources_delete_button->set_disabled(true);
sources_delete_button->connect("pressed", callable_mp(this, &LayeredTileSetEditor::_source_delete_pressed)); sources_delete_button->connect("pressed", this, "_source_delete_pressed");
sources_bottom_actions->add_child(sources_delete_button); sources_bottom_actions->add_child(sources_delete_button);
sources_add_button = memnew(MenuButton); sources_add_button = memnew(MenuButton);
@ -884,7 +913,7 @@ LayeredTileSetEditor::LayeredTileSetEditor() {
sources_add_button->set_theme_type_variation("FlatButton"); sources_add_button->set_theme_type_variation("FlatButton");
sources_add_button->get_popup()->add_item(TTR("Atlas")); sources_add_button->get_popup()->add_item(TTR("Atlas"));
sources_add_button->get_popup()->add_item(TTR("Scenes Collection")); sources_add_button->get_popup()->add_item(TTR("Scenes Collection"));
sources_add_button->get_popup()->connect("id_pressed", callable_mp(this, &LayeredTileSetEditor::_source_add_id_pressed)); sources_add_button->get_popup()->connect("id_pressed", this, "_source_add_id_pressed");
sources_bottom_actions->add_child(sources_add_button); sources_bottom_actions->add_child(sources_add_button);
sources_advanced_menu_button = memnew(MenuButton); sources_advanced_menu_button = memnew(MenuButton);
@ -892,7 +921,7 @@ LayeredTileSetEditor::LayeredTileSetEditor() {
sources_advanced_menu_button->set_theme_type_variation("FlatButton"); sources_advanced_menu_button->set_theme_type_variation("FlatButton");
sources_advanced_menu_button->get_popup()->add_item(TTR("Open Atlas Merging Tool")); sources_advanced_menu_button->get_popup()->add_item(TTR("Open Atlas Merging Tool"));
sources_advanced_menu_button->get_popup()->add_item(TTR("Manage Tile Proxies")); sources_advanced_menu_button->get_popup()->add_item(TTR("Manage Tile Proxies"));
sources_advanced_menu_button->get_popup()->connect("id_pressed", callable_mp(this, &LayeredTileSetEditor::_sources_advanced_menu_id_pressed)); sources_advanced_menu_button->get_popup()->connect("id_pressed", this, "_sources_advanced_menu_id_pressed");
sources_bottom_actions->add_child(sources_advanced_menu_button); sources_bottom_actions->add_child(sources_advanced_menu_button);
sources_bottom_actions->add_child(source_sort_button); sources_bottom_actions->add_child(source_sort_button);
@ -921,7 +950,7 @@ LayeredTileSetEditor::LayeredTileSetEditor() {
tile_set_atlas_source_editor = memnew(LayeredTileSetAtlasSourceEditor); tile_set_atlas_source_editor = memnew(LayeredTileSetAtlasSourceEditor);
tile_set_atlas_source_editor->set_h_size_flags(SIZE_EXPAND_FILL); tile_set_atlas_source_editor->set_h_size_flags(SIZE_EXPAND_FILL);
tile_set_atlas_source_editor->set_v_size_flags(SIZE_EXPAND_FILL); tile_set_atlas_source_editor->set_v_size_flags(SIZE_EXPAND_FILL);
tile_set_atlas_source_editor->connect("source_id_changed", callable_mp(this, &LayeredTileSetEditor::_update_sources_list)); tile_set_atlas_source_editor->connect("source_id_changed", this, "_update_sources_list");
split_container_right_side->add_child(tile_set_atlas_source_editor); split_container_right_side->add_child(tile_set_atlas_source_editor);
tile_set_atlas_source_editor->hide(); tile_set_atlas_source_editor->hide();
@ -929,21 +958,20 @@ LayeredTileSetEditor::LayeredTileSetEditor() {
tile_set_scenes_collection_source_editor = memnew(LayeredTileSetScenesCollectionSourceEditor); tile_set_scenes_collection_source_editor = memnew(LayeredTileSetScenesCollectionSourceEditor);
tile_set_scenes_collection_source_editor->set_h_size_flags(SIZE_EXPAND_FILL); tile_set_scenes_collection_source_editor->set_h_size_flags(SIZE_EXPAND_FILL);
tile_set_scenes_collection_source_editor->set_v_size_flags(SIZE_EXPAND_FILL); tile_set_scenes_collection_source_editor->set_v_size_flags(SIZE_EXPAND_FILL);
tile_set_scenes_collection_source_editor->connect("source_id_changed", callable_mp(this, &LayeredTileSetEditor::_update_sources_list)); tile_set_scenes_collection_source_editor->connect("source_id_changed", this, "_update_sources_list");
split_container_right_side->add_child(tile_set_scenes_collection_source_editor); split_container_right_side->add_child(tile_set_scenes_collection_source_editor);
tile_set_scenes_collection_source_editor->hide(); tile_set_scenes_collection_source_editor->hide();
//// Patterns //// //// Patterns ////
int thumbnail_size = 64; int thumbnail_size = 64;
patterns_item_list = memnew(ItemList); patterns_item_list = memnew(ItemList);
patterns_item_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
patterns_item_list->set_max_columns(0); patterns_item_list->set_max_columns(0);
patterns_item_list->set_icon_mode(ItemList::ICON_MODE_TOP); patterns_item_list->set_icon_mode(ItemList::ICON_MODE_TOP);
patterns_item_list->set_fixed_column_width(thumbnail_size * 3 / 2); patterns_item_list->set_fixed_column_width(thumbnail_size * 3 / 2);
patterns_item_list->set_max_text_lines(2); patterns_item_list->set_max_text_lines(2);
patterns_item_list->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size)); patterns_item_list->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size));
patterns_item_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); patterns_item_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
patterns_item_list->connect("gui_input", callable_mp(this, &LayeredTileSetEditor::_patterns_item_list_gui_input)); patterns_item_list->connect("gui_input", this, "_patterns_item_list_gui_input");
main_vb->add_child(patterns_item_list); main_vb->add_child(patterns_item_list);
patterns_item_list->hide(); patterns_item_list->hide();
@ -960,8 +988,14 @@ LayeredTileSetEditor::LayeredTileSetEditor() {
expanded_area->hide(); expanded_area->hide();
// Registers UndoRedo inspector callback. // Registers UndoRedo inspector callback.
EditorNode::get_editor_data().add_move_array_element_function(SNAME("LayeredTileSet"), callable_mp(this, &LayeredTileSetEditor::_move_tile_set_array_element));
EditorNode::get_editor_data().add_undo_redo_inspector_hook_callback(callable_mp(this, &LayeredTileSetEditor::_undo_redo_inspector_callback)); Ref<FuncRef> fref;
fref.instance();
fref->set_instance(this);
fref->set_function("_move_tile_set_array_element");
EditorNode::get_editor_data().add_move_array_element_function("LayeredTileSet", fref);
//EditorNode::get_editor_data().add_undo_redo_inspector_hook_callback(callable_mp(this, &LayeredTileSetEditor::_undo_redo_inspector_callback));
} }
void LayeredTileSourceInspectorPlugin::_show_id_edit_dialog(Object *p_for_source) { void LayeredTileSourceInspectorPlugin::_show_id_edit_dialog(Object *p_for_source) {
@ -973,19 +1007,20 @@ void LayeredTileSourceInspectorPlugin::_show_id_edit_dialog(Object *p_for_source
id_edit_dialog->add_child(vbox); id_edit_dialog->add_child(vbox);
Label *label = memnew(Label(TTR("Warning: Modifying a source ID will result in all LayeredTileMaps using that source to reference an invalid source instead. This may result in unexpected data loss. Change this ID carefully."))); Label *label = memnew(Label(TTR("Warning: Modifying a source ID will result in all LayeredTileMaps using that source to reference an invalid source instead. This may result in unexpected data loss. Change this ID carefully.")));
label->set_autowrap_mode(TextServer::AUTOWRAP_WORD); label->set_autowrap(true);
vbox->add_child(label); vbox->add_child(label);
id_input = memnew(SpinBox); id_input = memnew(SpinBox);
vbox->add_child(id_input); vbox->add_child(id_input);
id_input->set_max(INT_MAX); id_input->set_max(INT_MAX);
id_edit_dialog->connect("confirmed", callable_mp(this, &LayeredTileSourceInspectorPlugin::_confirm_change_id)); id_edit_dialog->connect("confirmed", this, "_confirm_change_id");
} }
edited_source = p_for_source; edited_source = p_for_source;
id_input->set_value(p_for_source->get("id")); id_input->set_value(p_for_source->get("id"));
id_edit_dialog->popup_centered(Vector2i(400, 0) * EDSCALE); id_edit_dialog->popup_centered(Vector2i(400, 0) * EDSCALE);
callable_mp((Control *)id_input->get_line_edit(), &Control::grab_focus).call_deferred();
id_input->get_line_edit()->call_deferred("grab_focus");
} }
void LayeredTileSourceInspectorPlugin::_confirm_change_id() { void LayeredTileSourceInspectorPlugin::_confirm_change_id() {
@ -997,7 +1032,7 @@ bool LayeredTileSourceInspectorPlugin::can_handle(Object *p_object) {
return p_object->is_class("LayeredTileSetAtlasSourceProxyObject") || p_object->is_class("LayeredTileSetScenesCollectionProxyObject"); return p_object->is_class("LayeredTileSetAtlasSourceProxyObject") || p_object->is_class("LayeredTileSetScenesCollectionProxyObject");
} }
bool LayeredTileSourceInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) { bool LayeredTileSourceInspectorPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage) {
if (p_path == "id") { if (p_path == "id") {
const Variant value = p_object->get("id"); const Variant value = p_object->get("id");
if (value.get_type() == Variant::NIL) { // May happen if the object is not yet initialized. if (value.get_type() == Variant::NIL) { // May happen if the object is not yet initialized.
@ -1007,7 +1042,7 @@ bool LayeredTileSourceInspectorPlugin::parse_property(Object *p_object, const Va
EditorProperty *ep = memnew(EditorProperty); EditorProperty *ep = memnew(EditorProperty);
HBoxContainer *hbox = memnew(HBoxContainer); HBoxContainer *hbox = memnew(HBoxContainer);
hbox->set_alignment(BoxContainer::ALIGNMENT_CENTER); hbox->set_alignment(BoxContainer::ALIGN_CENTER);
id_label = memnew(Label(itos(value))); id_label = memnew(Label(itos(value)));
id_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); id_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
@ -1016,7 +1051,7 @@ bool LayeredTileSourceInspectorPlugin::parse_property(Object *p_object, const Va
Button *button = memnew(Button(TTR("Edit"))); Button *button = memnew(Button(TTR("Edit")));
button->set_h_size_flags(Control::SIZE_EXPAND_FILL); button->set_h_size_flags(Control::SIZE_EXPAND_FILL);
hbox->add_child(button); hbox->add_child(button);
button->connect("pressed", callable_mp(this, &LayeredTileSourceInspectorPlugin::_show_id_edit_dialog).bind(p_object)); button->connect("pressed", this, "_show_id_edit_dialog", varray(p_object));
ep->add_child(hbox); ep->add_child(hbox);
add_property_editor(p_path, ep); add_property_editor(p_path, ep);
@ -1024,3 +1059,8 @@ bool LayeredTileSourceInspectorPlugin::parse_property(Object *p_object, const Va
} }
return false; return false;
} }
void LayeredTileSourceInspectorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("_confirm_change_id"), &LayeredTileSourceInspectorPlugin::_confirm_change_id);
ClassDB::bind_method(D_METHOD("_show_id_edit_dialog"), &LayeredTileSourceInspectorPlugin::_show_id_edit_dialog);
}

View File

@ -114,6 +114,7 @@ private:
void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value); void _undo_redo_inspector_callback(Object *p_undo_redo, Object *p_edited, const String &p_property, const Variant &p_new_value);
protected: protected:
static void _bind_methods();
void _notification(int p_what); void _notification(int p_what);
public: public:
@ -141,7 +142,10 @@ class LayeredTileSourceInspectorPlugin : public EditorInspectorPlugin {
public: public:
virtual bool can_handle(Object *p_object); virtual bool can_handle(Object *p_object);
virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false); virtual bool parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage);
protected:
static void _bind_methods();
}; };
#endif // TILE_SET_EDITOR_H #endif // TILE_SET_EDITOR_H