diff options
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 111 |
1 files changed, 88 insertions, 23 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e23afec5b8..8a9835c977 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -291,6 +291,8 @@ void EditorNode::_notification(int p_what) { get_tree()->get_root()->set_as_audio_listener_2d(false); get_tree()->set_auto_accept_quit(false); get_tree()->connect("files_dropped", this, "_dropped_files"); + + /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */ } if (p_what == NOTIFICATION_EXIT_TREE) { @@ -305,7 +307,8 @@ void EditorNode::_notification(int p_what) { _editor_select(EDITOR_3D); _update_debug_options(); - _load_docks(); + + /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */ } if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) { @@ -527,14 +530,17 @@ void EditorNode::_resources_reimported(const Vector<String> &p_resources) { void EditorNode::_sources_changed(bool p_exist) { if (waiting_for_first_scan) { + waiting_for_first_scan = false; + + EditorResourcePreview::get_singleton()->start(); //start previes now that it's safe + + _load_docks(); if (defer_load_scene != "") { load_scene(defer_load_scene); defer_load_scene = ""; } - - waiting_for_first_scan = false; } } @@ -1017,6 +1023,70 @@ bool EditorNode::_validate_scene_recursive(const String &p_filename, Node *p_nod return false; } +static bool _find_edited_resources(const Ref<Resource> &p_resource, Set<Ref<Resource> > &edited_resources) { + + if (p_resource->is_edited()) { + edited_resources.insert(p_resource); + return true; + } + + List<PropertyInfo> plist; + + p_resource->get_property_list(&plist); + + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { + if (E->get().type == Variant::OBJECT && E->get().usage & PROPERTY_USAGE_STORAGE && !(E->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT)) { + RES res = p_resource->get(E->get().name); + if (res.is_null()) { + continue; + } + if (res->get_path().is_resource_file()) { //not a subresource, continue + continue; + } + if (_find_edited_resources(res, edited_resources)) { + return true; + } + } + } + + return false; +} + +int EditorNode::_save_external_resources() { + //save external resources and its subresources if any was modified + + int flg = 0; + if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) + flg |= ResourceSaver::FLAG_COMPRESS; + flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; + + Set<Ref<Resource> > edited_subresources; + int saved = 0; + List<Ref<Resource> > cached; + ResourceCache::get_cached_resources(&cached); + for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) { + + Ref<Resource> res = E->get(); + if (!res->get_path().is_resource_file()) + continue; + //not only check if this resourec is edited, check contained subresources too + if (_find_edited_resources(res, edited_subresources)) { + ResourceSaver::save(res->get_path(), res, flg); + saved++; + } + } + + // clear later, because user may have put the same subresource in two different resources, + // which will be shared until the next reload + + for (Set<Ref<Resource> >::Element *E = edited_subresources.front(); E; E = E->next()) { + Ref<Resource> res = E->get(); + res->set_edited(false); + } + + return saved; +} + void EditorNode::_save_scene(String p_file, int idx) { Node *scene = editor_data.get_edited_scene_root(idx); @@ -1075,22 +1145,8 @@ void EditorNode::_save_scene(String p_file, int idx) { flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; err = ResourceSaver::save(p_file, sdata, flg); - //Map<RES, bool> processed; - //this method is slow and not always works, deprecating - //_save_edited_subresources(scene, processed, flg); - { //instead, just find globally unsaved subresources and save them - - List<Ref<Resource> > cached; - ResourceCache::get_cached_resources(&cached); - for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) { - - Ref<Resource> res = E->get(); - if (res->is_edited() && res->get_path().is_resource_file()) { - ResourceSaver::save(res->get_path(), res, flg); - res->set_edited(false); - } - } - } + + _save_external_resources(); editor_data.save_editor_external_data(); if (err == OK) { @@ -1843,7 +1899,15 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { if (!scene) { - show_accept(TTR("This operation can't be done without a tree root."), TTR("OK")); + int saved = _save_external_resources(); + String err_text; + if (saved > 0) { + err_text = vformat(TTR("Saved %s modified resource(s)."), itos(saved)); + } else { + err_text = TTR("A root node is required to save the scene."); + } + + show_accept(err_text, TTR("OK")); break; } @@ -3605,6 +3669,9 @@ void EditorNode::_dock_select_draw() { void EditorNode::_save_docks() { + if (waiting_for_first_scan) { + return; //scanning, do not touch docks + } Ref<ConfigFile> config; config.instance(); @@ -3818,9 +3885,8 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String } } - int fs_split_ofs = 0; if (p_layout->has_section_key(p_section, "dock_filesystem_split")) { - fs_split_ofs = p_layout->get_value(p_section, "dock_filesystem_split"); + int fs_split_ofs = p_layout->get_value(p_section, "dock_filesystem_split"); filesystem_dock->set_split_offset(fs_split_ofs); } @@ -3833,7 +3899,6 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String FileSystemDock::FileListDisplayMode dock_filesystem_file_list_display_mode = FileSystemDock::FileListDisplayMode(int(p_layout->get_value(p_section, "dock_filesystem_file_list_display_mode"))); filesystem_dock->set_file_list_display_mode(dock_filesystem_file_list_display_mode); } - filesystem_dock->set_split_offset(fs_split_ofs); for (int i = 0; i < vsplits.size(); i++) { |