diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_folding.cpp | 32 | ||||
-rw-r--r-- | editor/editor_node.cpp | 21 | ||||
-rw-r--r-- | editor/editor_node.h | 1 |
3 files changed, 37 insertions, 17 deletions
diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp index 776342582c..a88cd740db 100644 --- a/editor/editor_folding.cpp +++ b/editor/editor_folding.cpp @@ -1,8 +1,8 @@ #include "editor_folding.h" #include "core/os/file_access.h" -#include "editor_settings.h" #include "editor_inspector.h" +#include "editor_settings.h" PoolVector<String> EditorFolding::_get_unfolds(const Object *p_object) { @@ -172,7 +172,6 @@ bool EditorFolding::has_folding_data(const String &p_path) { return FileAccess::exists(file); } - void EditorFolding::_do_object_unfolds(Object *p_object, Set<RES> &resources) { List<PropertyInfo> plist; @@ -185,34 +184,33 @@ void EditorFolding::_do_object_unfolds(Object *p_object, Set<RES> &resources) { for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { if (E->get().usage & PROPERTY_USAGE_CATEGORY) { - group=""; - group_base=""; + group = ""; + group_base = ""; } if (E->get().usage & PROPERTY_USAGE_GROUP) { group = E->get().name; group_base = E->get().hint_string; if (group_base.ends_with("_")) { - group_base=group_base.substr(0,group_base.length()-1); + group_base = group_base.substr(0, group_base.length() - 1); } } //can unfold if (E->get().usage & PROPERTY_USAGE_EDITOR) { - if (group != "") { //group - if (group_base==String() || E->get().name.begins_with(group_base)) { - bool can_revert = EditorPropertyRevert::can_property_revert(p_object,E->get().name); - if (can_revert) { + if (group_base == String() || E->get().name.begins_with(group_base)) { + bool can_revert = EditorPropertyRevert::can_property_revert(p_object, E->get().name); + if (can_revert) { unfold_group.insert(group); } } } else { //path int last = E->get().name.find_last("/"); - if (last!=-1) { - bool can_revert = EditorPropertyRevert::can_property_revert(p_object,E->get().name); + if (last != -1) { + bool can_revert = EditorPropertyRevert::can_property_revert(p_object, E->get().name); if (can_revert) { - unfold_group.insert(E->get().name.substr(0,last)); + unfold_group.insert(E->get().name.substr(0, last)); } } } @@ -223,13 +221,13 @@ void EditorFolding::_do_object_unfolds(Object *p_object, Set<RES> &resources) { if (res.is_valid() && !resources.has(res) && res->get_path() != String() && !res->get_path().is_resource_file()) { resources.insert(res); - _do_object_unfolds(res.ptr(),resources); + _do_object_unfolds(res.ptr(), resources); } } } - for (Set<String>::Element *E=unfold_group.front();E;E=E->next()) { - p_object->editor_set_section_unfold(E->get(),true); + for (Set<String>::Element *E = unfold_group.front(); E; E = E->next()) { + p_object->editor_set_section_unfold(E->get(), true); } } @@ -243,7 +241,7 @@ void EditorFolding::_do_node_unfolds(Node *p_root, Node *p_node, Set<RES> &resou } } - _do_object_unfolds(p_node,resources); + _do_object_unfolds(p_node, resources); for (int i = 0; i < p_node->get_child_count(); i++) { _do_node_unfolds(p_root, p_node->get_child(i), resources); @@ -253,7 +251,7 @@ void EditorFolding::_do_node_unfolds(Node *p_root, Node *p_node, Set<RES> &resou void EditorFolding::unfold_scene(Node *p_scene) { Set<RES> resources; - _do_node_unfolds(p_scene,p_scene,resources); + _do_node_unfolds(p_scene, p_scene, resources); } EditorFolding::EditorFolding() { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 40a7b8310f..157dd4d66f 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -999,6 +999,22 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); } +bool EditorNode::_validate_scene_recursive(const String &p_filename, Node *p_node) { + + for (int i = 0; i < p_node->get_child_count(); i++) { + Node *child = p_node->get_child(i); + if (child->get_filename() == p_filename) { + return true; + } + + if (_validate_scene_recursive(p_filename, child)) { + return true; + } + } + + return false; +} + void EditorNode::_save_scene(String p_file, int idx) { Node *scene = editor_data.get_edited_scene_root(idx); @@ -1009,6 +1025,11 @@ void EditorNode::_save_scene(String p_file, int idx) { return; } + if (scene->get_filename() != String() && _validate_scene_recursive(scene->get_filename(), scene)) { + show_accept(TTR("This scene can't be saved because there is a cyclic instancing inclusion.\nPlease resolve it and then attempt to save again."), TTR("OK")); + return; + } + editor_data.apply_changes_in_editors(); _save_default_environment(); diff --git a/editor/editor_node.h b/editor/editor_node.h index e220daf8a9..3fa762c20b 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -445,6 +445,7 @@ private: void _show_messages(); void _vp_resized(); + bool _validate_scene_recursive(const String &p_filename, Node *p_node); void _save_scene(String p_file, int idx = -1); void _save_all_scenes(); int _next_unsaved_scene(bool p_valid_filename, int p_start = 0); |