summaryrefslogtreecommitdiffstats
path: root/editor/plugins/canvas_item_editor_plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/canvas_item_editor_plugin.cpp')
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 2ab53effed..b3a4362eea 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -5695,8 +5695,11 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons
}
void CanvasItemEditorViewport::_remove_preview() {
- if (preview_node->get_parent()) {
+ if (!canvas_item_editor->message.is_empty()) {
canvas_item_editor->message = "";
+ canvas_item_editor->update_viewport();
+ }
+ if (preview_node->get_parent()) {
for (int i = preview_node->get_child_count() - 1; i >= 0; i--) {
Node *node = preview_node->get_child(i);
node->queue_free();
@@ -5709,7 +5712,7 @@ void CanvasItemEditorViewport::_remove_preview() {
}
}
-bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) {
+bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) const {
if (p_desired_node->get_scene_file_path() == p_target_scene_path) {
return true;
}
@@ -5853,7 +5856,7 @@ void CanvasItemEditorViewport::_perform_drop_data() {
return;
}
- Vector<String> error_files;
+ PackedStringArray error_files;
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action_for_history(TTR("Create Node"), EditorNode::get_editor_data().get_current_edited_scene_history_id());
@@ -5872,12 +5875,12 @@ void CanvasItemEditorViewport::_perform_drop_data() {
// Without root node act the same as "Load Inherited Scene"
Error err = EditorNode::get_singleton()->load_scene(path, false, true);
if (err != OK) {
- error_files.push_back(path);
+ error_files.push_back(path.get_file());
}
} else {
bool success = _create_instance(target_node, path, drop_pos);
if (!success) {
- error_files.push_back(path);
+ error_files.push_back(path.get_file());
}
}
} else {
@@ -5893,12 +5896,7 @@ void CanvasItemEditorViewport::_perform_drop_data() {
undo_redo->commit_action();
if (error_files.size() > 0) {
- String files_str;
- for (int i = 0; i < error_files.size(); i++) {
- files_str += error_files[i].get_file().get_basename() + ",";
- }
- files_str = files_str.substr(0, files_str.length() - 1);
- accept->set_text(vformat(TTR("Error instantiating scene from %s"), files_str.get_data()));
+ accept->set_text(vformat(TTR("Error instantiating scene from %s."), String(", ").join(error_files)));
accept->popup_centered();
}
}
@@ -5912,6 +5910,8 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian
Vector<String> files = d["files"];
bool can_instantiate = false;
+ bool is_cyclical_dep = false;
+ String error_file;
// Check if at least one of the dragged files is a texture or scene.
for (int i = 0; i < files.size(); i++) {
@@ -5929,12 +5929,25 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian
if (!instantiated_scene) {
continue;
}
+
+ Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
+ if (_cyclical_dependency_exists(edited_scene->get_scene_file_path(), instantiated_scene)) {
+ memdelete(instantiated_scene);
+ can_instantiate = false;
+ is_cyclical_dep = true;
+ error_file = files[i].get_file();
+ break;
+ }
memdelete(instantiated_scene);
}
can_instantiate = true;
- break;
}
}
+ if (is_cyclical_dep) {
+ canvas_item_editor->message = vformat(TTR("Can't instantiate: %s."), vformat(TTR("Circular dependency found at %s"), error_file));
+ canvas_item_editor->update_viewport();
+ return false;
+ }
if (can_instantiate) {
if (!preview_node->get_parent()) { // create preview only once
_create_preview(files);