diff options
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 849 |
1 files changed, 316 insertions, 533 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 849908c132..8b7014fabe 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -32,7 +32,7 @@ #include "core/bind/core_bind.h" #include "core/class_db.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/config_file.h" #include "core/io/image_loader.h" #include "core/io/resource_loader.h" @@ -42,7 +42,6 @@ #include "core/os/file_access.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/path_remap.h" #include "core/print_string.h" #include "core/project_settings.h" #include "core/translation.h" @@ -98,6 +97,7 @@ #include "editor/import/resource_importer_layered_texture.h" #include "editor/import/resource_importer_obj.h" #include "editor/import/resource_importer_scene.h" +#include "editor/import/resource_importer_shader_file.h" #include "editor/import/resource_importer_texture.h" #include "editor/import/resource_importer_texture_atlas.h" #include "editor/import/resource_importer_wav.h" @@ -148,6 +148,7 @@ #include "editor/plugins/script_editor_plugin.h" #include "editor/plugins/script_text_editor.h" #include "editor/plugins/shader_editor_plugin.h" +#include "editor/plugins/shader_file_editor_plugin.h" #include "editor/plugins/skeleton_2d_editor_plugin.h" #include "editor/plugins/skeleton_3d_editor_plugin.h" #include "editor/plugins/skeleton_ik_3d_editor_plugin.h" @@ -156,6 +157,7 @@ #include "editor/plugins/style_box_editor_plugin.h" #include "editor/plugins/text_editor.h" #include "editor/plugins/texture_editor_plugin.h" +#include "editor/plugins/texture_layered_editor_plugin.h" #include "editor/plugins/texture_region_editor_plugin.h" #include "editor/plugins/theme_editor_plugin.h" #include "editor/plugins/tile_map_editor_plugin.h" @@ -178,7 +180,6 @@ EditorNode *EditorNode::singleton = nullptr; void EditorNode::_update_scene_tabs() { - bool show_rb = EditorSettings::get_singleton()->get("interface/scene_tabs/show_script_button"); if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_GLOBAL_MENU)) { @@ -188,7 +189,6 @@ void EditorNode::_update_scene_tabs() { scene_tabs->clear_tabs(); Ref<Texture2D> script_icon = gui_base->get_theme_icon("Script", "EditorIcons"); for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { - Node *type_node = editor_data.get_edited_scene_root(i); Ref<Texture2D> icon; if (type_node) { @@ -230,44 +230,41 @@ void EditorNode::_update_scene_tabs() { scene_tabs->add_child(scene_tab_add); } Rect2 last_tab = Rect2(); - if (scene_tabs->get_tab_count() != 0) + if (scene_tabs->get_tab_count() != 0) { last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1); + } scene_tab_add->set_position(Point2(last_tab.get_position().x + last_tab.get_size().x + 3, last_tab.get_position().y)); } } void EditorNode::_version_control_menu_option(int p_idx) { - switch (vcs_actions_menu->get_item_id(p_idx)) { case RUN_VCS_SETTINGS: { - VersionControlEditorPlugin::get_singleton()->popup_vcs_set_up_dialog(gui_base); } break; case RUN_VCS_SHUT_DOWN: { - VersionControlEditorPlugin::get_singleton()->shut_down(); } break; } } void EditorNode::_update_title() { - String appname = ProjectSettings::get_singleton()->get("application/config/name"); String title = appname.empty() ? String(VERSION_FULL_NAME) : String(VERSION_NAME + String(" - ") + appname); String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String(); - if (!edited.empty()) + if (!edited.empty()) { title += " - " + String(edited.get_file()); - if (unsaved_cache) + } + if (unsaved_cache) { title += " (*)"; + } DisplayServer::get_singleton()->window_set_title(title); } void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) { - Ref<InputEventKey> k = p_event; if (k.is_valid() && k->is_pressed() && !k->is_echo()) { - EditorPlugin *old_editor = editor_plugin_screen; if (ED_IS_SHORTCUT("editor/next_tab", p_event)) { @@ -307,14 +304,13 @@ void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) { } void EditorNode::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_PROCESS: { - if (opening_prev && !confirmation->is_visible()) + if (opening_prev && !confirmation->is_visible()) { opening_prev = false; + } if (unsaved_cache != (saved_version != editor_data.get_undo_redo().get_version())) { - unsaved_cache = (saved_version != editor_data.get_undo_redo().get_version()); _update_title(); } @@ -329,10 +325,10 @@ void EditorNode::_notification(int p_what) { uint32_t tick = OS::get_singleton()->get_ticks_msec(); if (frame != update_spinner_step_frame && (tick - update_spinner_step_msec) > (1000 / 8)) { - update_spinner_step++; - if (update_spinner_step >= 8) + if (update_spinner_step >= 8) { update_spinner_step = 0; + } update_spinner_step_msec = tick; update_spinner_step_frame = frame + 1; @@ -379,6 +375,8 @@ void EditorNode::_notification(int p_what) { RS::get_singleton()->shadows_quality_set(shadows_quality); RS::ShadowQuality directional_shadow_quality = RS::ShadowQuality(int(GLOBAL_GET("rendering/quality/directional_shadow/soft_shadow_quality"))); RS::get_singleton()->directional_shadow_quality_set(directional_shadow_quality); + float probe_update_speed = GLOBAL_GET("rendering/lightmapper/probe_capture_update_speed"); + RS::get_singleton()->lightmap_set_probe_capture_update_speed(probe_update_speed); } ResourceImporterTexture::get_singleton()->update_imports(); @@ -404,7 +402,6 @@ void EditorNode::_notification(int p_what) { } break; case NOTIFICATION_READY: { - { _initializing_addons = true; Vector<String> addons; @@ -434,7 +431,6 @@ void EditorNode::_notification(int p_what) { } break; case NOTIFICATION_WM_FOCUS_IN: { - // Restore the original FPS cap after focusing back on the editor OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec"))); @@ -442,18 +438,15 @@ void EditorNode::_notification(int p_what) { } break; case NOTIFICATION_WM_FOCUS_OUT: { - // Set a low FPS cap to decrease CPU/GPU usage while the editor is unfocused OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec"))); } break; case NOTIFICATION_WM_ABOUT: { - show_about(); } break; case NOTIFICATION_WM_CLOSE_REQUEST: { - _menu_option_confirm(FILE_QUIT, false); } break; @@ -486,12 +479,12 @@ void EditorNode::_notification(int p_what) { recent_scenes->set_as_minsize(); // debugger area - if (EditorDebuggerNode::get_singleton()->is_visible()) + if (EditorDebuggerNode::get_singleton()->is_visible()) { bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")); + } // update_icons for (int i = 0; i < singleton->main_editor_buttons.size(); i++) { - ToolButton *tb = singleton->main_editor_buttons[i]; EditorPlugin *p_editor = singleton->editor_table[i]; Ref<Texture2D> icon = p_editor->get_icon(); @@ -553,8 +546,9 @@ void EditorNode::_update_update_spinner() { void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_name) { Ref<Script> script = Object::cast_to<Script>(p_script); - if (script.is_null()) + if (script.is_null()) { return; + } if (p_activate_name.length()) { set_addon_plugin_enabled(p_activate_name, true); } @@ -564,23 +558,24 @@ void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_nam } void EditorNode::_resources_changed(const Vector<String> &p_resources) { - List<Ref<Resource>> changed; int rc = p_resources.size(); for (int i = 0; i < rc; i++) { - Ref<Resource> res(ResourceCache::get(p_resources.get(i))); if (res.is_null()) { continue; } - if (!res->editor_can_reload_from_file()) + if (!res->editor_can_reload_from_file()) { continue; - if (!res->get_path().is_resource_file() && !res->get_path().is_abs_path()) + } + if (!res->get_path().is_resource_file() && !res->get_path().is_abs_path()) { continue; - if (!FileAccess::exists(res->get_path())) + } + if (!FileAccess::exists(res->get_path())) { continue; + } if (res->get_import_path() != String()) { //this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback @@ -598,14 +593,11 @@ void EditorNode::_resources_changed(const Vector<String> &p_resources) { } void EditorNode::_fs_changed() { - for (Set<FileDialog *>::Element *E = file_dialogs.front(); E; E = E->next()) { - E->get()->invalidate(); } for (Set<EditorFileDialog *>::Element *E = editor_file_dialogs.front(); E; E = E->next()) { - E->get()->invalidate(); } @@ -675,7 +667,6 @@ void EditorNode::_fs_changed() { } void EditorNode::_resources_reimported(const Vector<String> &p_resources) { - List<String> scenes; //will load later int current_tab = scene_tabs->get_current_tab(); @@ -705,13 +696,11 @@ 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; // Reload the global shader variables, but this time // loading texures, as they are now properly imported. - print_line("done scanning, reload textures"); RenderingServer::get_singleton()->global_variables_load_settings(true); // Start preview thread now that it's safe. @@ -732,13 +721,12 @@ void EditorNode::_vp_resized() { } void EditorNode::_node_renamed() { - - if (get_inspector()) + if (get_inspector()) { get_inspector()->update_tree(); + } } void EditorNode::_editor_select_next() { - int editor = _get_current_main_editor(); do { @@ -753,7 +741,6 @@ void EditorNode::_editor_select_next() { } void EditorNode::_editor_select_prev() { - int editor = _get_current_main_editor(); do { @@ -768,7 +755,6 @@ void EditorNode::_editor_select_prev() { } Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_deps) { - dependency_errors.clear(); Error err; @@ -776,11 +762,9 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d ERR_FAIL_COND_V(!res.is_valid(), ERR_CANT_OPEN); if (!p_ignore_broken_deps && dependency_errors.has(p_resource)) { - //current_option = -1; Vector<String> errors; for (Set<String>::Element *E = dependency_errors[p_resource].front(); E; E = E->next()) { - errors.push_back(E->get()); } dependency_error->show(DependencyErrorDialog::MODE_RESOURCE, p_resource, errors); @@ -794,16 +778,15 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d } void EditorNode::edit_node(Node *p_node) { - push_item(p_node); } void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path) { - editor_data.apply_changes_in_editors(); int flg = 0; - if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) + if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) { flg |= ResourceSaver::FLAG_COMPRESS; + } String path = ProjectSettings::get_singleton()->localize_path(p_path); Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); @@ -823,7 +806,6 @@ void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const St } void EditorNode::save_resource(const Ref<Resource> &p_resource) { - if (p_resource->get_path().is_resource_file()) { save_resource_in_path(p_resource, p_resource->get_path()); } else { @@ -832,7 +814,6 @@ void EditorNode::save_resource(const Ref<Resource> &p_resource) { } void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path) { - { String path = p_resource->get_path(); int srpos = path.find("::"); @@ -856,7 +837,6 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String List<String> preferred; for (int i = 0; i < extensions.size(); i++) { - if (p_resource->is_class("Script") && (extensions[i] == "tres" || extensions[i] == "res" || extensions[i] == "xml")) { //this serves no purpose and confused people continue; @@ -866,7 +846,6 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String } if (p_at_path != String()) { - file->set_current_dir(p_at_path); if (p_resource->get_path().is_resource_file()) { file->set_current_file(p_resource->get_path().get_file()); @@ -878,7 +857,6 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String } } } else if (p_resource->get_path() != "") { - file->set_current_path(p_resource->get_path()); if (extensions.size()) { String ext = p_resource->get_path().get_extension().to_lower(); @@ -887,7 +865,6 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String } } } else if (preferred.size()) { - String existing; if (extensions.size()) { existing = "new_" + p_resource->get_class().to_lower() + "." + preferred.front()->get().to_lower(); @@ -899,31 +876,23 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String } void EditorNode::_menu_option(int p_option) { - _menu_option_confirm(p_option, false); } void EditorNode::_menu_confirm_current() { - _menu_option_confirm(current_option, true); } void EditorNode::_dialog_display_save_error(String p_file, Error p_error) { - if (p_error) { - switch (p_error) { - case ERR_FILE_CANT_WRITE: { - show_accept(TTR("Can't open file for writing:") + " " + p_file.get_extension(), TTR("OK")); } break; case ERR_FILE_UNRECOGNIZED: { - show_accept(TTR("Requested file format unknown:") + " " + p_file.get_extension(), TTR("OK")); } break; default: { - show_accept(TTR("Error while saving."), TTR("OK")); } break; } @@ -931,29 +900,21 @@ void EditorNode::_dialog_display_save_error(String p_file, Error p_error) { } void EditorNode::_dialog_display_load_error(String p_file, Error p_error) { - if (p_error) { - switch (p_error) { - case ERR_CANT_OPEN: { - show_accept(vformat(TTR("Can't open '%s'. The file could have been moved or deleted."), p_file.get_file()), TTR("OK")); } break; case ERR_PARSE_ERROR: { - show_accept(vformat(TTR("Error while parsing '%s'."), p_file.get_file()), TTR("OK")); } break; case ERR_FILE_CORRUPT: { - show_accept(vformat(TTR("Unexpected end of file '%s'."), p_file.get_file()), TTR("OK")); } break; case ERR_FILE_NOT_FOUND: { - show_accept(vformat(TTR("Missing '%s' or its dependencies."), p_file.get_file()), TTR("OK")); } break; default: { - show_accept(vformat(TTR("Error while loading '%s'."), p_file.get_file()), TTR("OK")); } break; } @@ -961,11 +922,11 @@ void EditorNode::_dialog_display_load_error(String p_file, Error p_error) { } void EditorNode::_get_scene_metadata(const String &p_file) { - Node *scene = editor_data.get_edited_scene_root(); - if (!scene) + if (!scene) { return; + } String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); @@ -973,15 +934,15 @@ void EditorNode::_get_scene_metadata(const String &p_file) { cf.instance(); Error err = cf->load(path); - if (err != OK || !cf->has_section("editor_states")) + if (err != OK || !cf->has_section("editor_states")) { return; //must not exist + } List<String> esl; cf->get_section_keys("editor_states", &esl); Dictionary md; for (List<String>::Element *E = esl.front(); E; E = E->next()) { - Variant st = cf->get_value("editor_states", E->get()); if (st.get_type() != Variant::NIL) { md[E->get()] = st; @@ -992,11 +953,11 @@ void EditorNode::_get_scene_metadata(const String &p_file) { } void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { - Node *scene = editor_data.get_edited_scene_root(p_idx); - if (!scene) + if (!scene) { return; + } scene->set_meta("__editor_run_settings__", Variant()); //clear it (no point in keeping it) scene->set_meta("__editor_plugin_states__", Variant()); @@ -1018,7 +979,6 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { md.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - cf->set_value("editor_states", E->get(), md[E->get()]); } @@ -1027,12 +987,11 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { } bool EditorNode::_find_and_save_resource(RES p_res, Map<RES, bool> &processed, int32_t flags) { - - if (p_res.is_null()) + if (p_res.is_null()) { return false; + } if (processed.has(p_res)) { - return processed[p_res]; } @@ -1049,55 +1008,51 @@ bool EditorNode::_find_and_save_resource(RES p_res, Map<RES, bool> &processed, i processed[p_res] = false; //because it's a file return false; } else { - processed[p_res] = changed; return changed; } } bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> &processed, int32_t flags) { - bool ret_changed = false; List<PropertyInfo> pi; obj->get_property_list(&pi); for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } switch (E->get().type) { case Variant::OBJECT: { - RES res = obj->get(E->get().name); - if (_find_and_save_resource(res, processed, flags)) + if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; + } } break; case Variant::ARRAY: { - Array varray = obj->get(E->get().name); int len = varray.size(); for (int i = 0; i < len; i++) { - const Variant &v = varray.get(i); RES res = v; - if (_find_and_save_resource(res, processed, flags)) + if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; + } } } break; case Variant::DICTIONARY: { - Dictionary d = obj->get(E->get().name); List<Variant> keys; d.get_key_list(&keys); for (List<Variant>::Element *F = keys.front(); F; F = F->next()) { - Variant v = d[F->get()]; RES res = v; - if (_find_and_save_resource(res, processed, flags)) + if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; + } } } break; default: { @@ -1109,34 +1064,34 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> } void EditorNode::_save_edited_subresources(Node *scene, Map<RES, bool> &processed, int32_t flags) { - _find_and_save_edited_subresources(scene, processed, flags); for (int i = 0; i < scene->get_child_count(); i++) { - Node *n = scene->get_child(i); - if (n->get_owner() != editor_data.get_edited_scene_root()) + if (n->get_owner() != editor_data.get_edited_scene_root()) { continue; + } _save_edited_subresources(n, processed, flags); } } void EditorNode::_find_node_types(Node *p_node, int &count_2d, int &count_3d) { - - if (p_node->is_class("Viewport") || (p_node != editor_data.get_edited_scene_root() && p_node->get_owner() != editor_data.get_edited_scene_root())) + if (p_node->is_class("Viewport") || (p_node != editor_data.get_edited_scene_root() && p_node->get_owner() != editor_data.get_edited_scene_root())) { return; + } - if (p_node->is_class("CanvasItem")) + if (p_node->is_class("CanvasItem")) { count_2d++; - else if (p_node->is_class("Node3D")) + } else if (p_node->is_class("Node3D")) { count_3d++; + } - for (int i = 0; i < p_node->get_child_count(); i++) + for (int i = 0; i < p_node->get_child_count(); i++) { _find_node_types(p_node->get_child(i), count_2d, count_3d); + } } void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { - EditorProgress save("save", TTR("Saving Scene"), 4); if (editor_data.get_edited_scene_root() != nullptr) { @@ -1164,7 +1119,6 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { } if (img.is_valid()) { - img = img->duplicate(); save.step(TTR("Creating Thumbnail"), 2); @@ -1193,8 +1147,6 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { } img->convert(Image::FORMAT_RGB8); - img->flip_y(); - //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 String temp_path = EditorSettings::get_singleton()->get_cache_dir(); String cache_base = ProjectSettings::get_singleton()->globalize_path(p_file).md5_text(); @@ -1218,7 +1170,6 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { } 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) { @@ -1234,7 +1185,6 @@ bool EditorNode::_validate_scene_recursive(const String &p_filename, Node *p_nod } 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; @@ -1266,8 +1216,9 @@ 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")) + 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; @@ -1275,10 +1226,10 @@ int EditorNode::_save_external_resources() { 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()) + 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); @@ -1298,11 +1249,9 @@ int EditorNode::_save_external_resources() { } void EditorNode::_save_scene(String p_file, int idx) { - Node *scene = editor_data.get_edited_scene_root(idx); if (!scene) { - show_accept(TTR("This operation can't be done without a tree root."), TTR("OK")); return; } @@ -1325,17 +1274,17 @@ void EditorNode::_save_scene(String p_file, int idx) { // old version still work for referencing changes in instanced or inherited scenes sdata = Ref<PackedScene>(Object::cast_to<PackedScene>(ResourceCache::get(p_file))); - if (sdata.is_valid()) + if (sdata.is_valid()) { sdata->recreate_state(); - else + } else { sdata.instance(); + } } else { sdata.instance(); } Error err = sdata->pack(scene); if (err != OK) { - show_accept(TTR("Couldn't save scene. Likely dependencies (instances or inheritance) couldn't be satisfied."), TTR("OK")); return; } @@ -1350,8 +1299,9 @@ void EditorNode::_save_scene(String p_file, int idx) { memdelete(dummy_scene); int flg = 0; - if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) + if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) { flg |= ResourceSaver::FLAG_COMPRESS; + } flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; err = ResourceSaver::save(p_file, sdata, flg); @@ -1361,29 +1311,27 @@ void EditorNode::_save_scene(String p_file, int idx) { editor_data.save_editor_external_data(); if (err == OK) { scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_file)); - if (idx < 0 || idx == editor_data.get_edited_scene()) + if (idx < 0 || idx == editor_data.get_edited_scene()) { set_current_version(editor_data.get_undo_redo().get_version()); - else + } else { editor_data.set_edited_scene_version(0, idx); + } editor_folding.save_scene_folding(scene, p_file); _update_title(); _update_scene_tabs(); } else { - _dialog_display_save_error(p_file, err); } } void EditorNode::save_all_scenes() { - _menu_option_confirm(RUN_STOP, true); _save_all_scenes(); } void EditorNode::save_scene_list(Vector<String> p_scene_filenames) { - for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { Node *scene = editor_data.get_edited_scene_root(i); @@ -1394,7 +1342,6 @@ void EditorNode::save_scene_list(Vector<String> p_scene_filenames) { } void EditorNode::restart_editor() { - exiting = true; String to_reopen; @@ -1416,14 +1363,14 @@ void EditorNode::restart_editor() { } void EditorNode::_save_all_scenes() { - for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { Node *scene = editor_data.get_edited_scene_root(i); if (scene && scene->get_filename() != "") { - if (i != editor_data.get_edited_scene()) + if (i != editor_data.get_edited_scene()) { _save_scene(scene->get_filename(), i); - else + } else { _save_scene_with_preview(scene->get_filename()); + } } // else: ignore new scenes } @@ -1431,20 +1378,19 @@ void EditorNode::_save_all_scenes() { } void EditorNode::_mark_unsaved_scenes() { - for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { - Node *node = editor_data.get_edited_scene_root(i); - if (!node) + if (!node) { continue; + } String path = node->get_filename(); if (!(path == String() || FileAccess::exists(path))) { - - if (i == editor_data.get_edited_scene()) + if (i == editor_data.get_edited_scene()) { set_current_version(-1); - else + } else { editor_data.set_edited_scene_version(-1, i); + } } } @@ -1453,23 +1399,20 @@ void EditorNode::_mark_unsaved_scenes() { } void EditorNode::_dialog_action(String p_file) { - switch (current_option) { case FILE_NEW_INHERITED_SCENE: { - Node *scene = editor_data.get_edited_scene_root(); // If the previous scene is rootless, just close it in favor of the new one. - if (!scene) + if (!scene) { _menu_option_confirm(FILE_CLOSE, true); + } load_scene(p_file, false, true); } break; case FILE_OPEN_SCENE: { - load_scene(p_file); } break; case SETTINGS_PICK_MAIN_SCENE: { - ProjectSettings::get_singleton()->set("application/run/main_scene", p_file); ProjectSettings::get_singleton()->save(); //would be nice to show the project manager opened with the highlighted field.. @@ -1486,14 +1429,14 @@ void EditorNode::_dialog_action(String p_file) { case SCENE_TAB_CLOSE: case FILE_SAVE_SCENE: case FILE_SAVE_AS_SCENE: { - int scene_idx = (current_option == FILE_SAVE_SCENE || current_option == FILE_SAVE_AS_SCENE) ? -1 : tab_closing; if (file->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) { bool same_open_scene = false; for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { - if (editor_data.get_scene_path(i) == p_file && i != scene_idx) + if (editor_data.get_scene_path(i) == p_file && i != scene_idx) { same_open_scene = true; + } } if (same_open_scene) { @@ -1506,15 +1449,15 @@ void EditorNode::_dialog_action(String p_file) { _add_to_recent_scenes(p_file); save_layout(); - if (scene_idx != -1) + if (scene_idx != -1) { _discard_changes(); + } } } break; case FILE_SAVE_AND_RUN: { if (file->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) { - _save_default_environment(); _save_scene_with_preview(p_file); _run(false, p_file); @@ -1522,7 +1465,6 @@ void EditorNode::_dialog_action(String p_file) { } break; case FILE_EXPORT_MESH_LIBRARY: { - Ref<MeshLibrary> ml; if (file_export_lib_merge->is_pressed() && FileAccess::exists(p_file)) { ml = ResourceLoader::load(p_file, "MeshLibrary"); @@ -1547,7 +1489,6 @@ void EditorNode::_dialog_action(String p_file) { } break; case FILE_EXPORT_TILESET: { - Ref<TileSet> tileset; if (FileAccess::exists(p_file) && file_export_lib_merge->is_pressed()) { tileset = ResourceLoader::load(p_file, "TileSet"); @@ -1565,7 +1506,6 @@ void EditorNode::_dialog_action(String p_file) { Error err = ResourceSaver::save(p_file, tileset); if (err) { - show_accept(TTR("Error saving TileSet!"), TTR("OK")); return; } @@ -1573,7 +1513,6 @@ void EditorNode::_dialog_action(String p_file) { case RESOURCE_SAVE: case RESOURCE_SAVE_AS: { - ERR_FAIL_COND(saving_resource.is_null()); save_resource_in_path(saving_resource, p_file); saving_resource = Ref<Resource>(); @@ -1583,9 +1522,9 @@ void EditorNode::_dialog_action(String p_file) { current_obj->_change_notify(); } break; case SETTINGS_LAYOUT_SAVE: { - - if (p_file.empty()) + if (p_file.empty()) { return; + } Ref<ConfigFile> config; config.instance(); @@ -1611,9 +1550,9 @@ void EditorNode::_dialog_action(String p_file) { } break; case SETTINGS_LAYOUT_DELETE: { - - if (p_file.empty()) + if (p_file.empty()) { return; + } Ref<ConfigFile> config; config.instance(); @@ -1652,7 +1591,6 @@ void EditorNode::_dialog_action(String p_file) { } bool EditorNode::item_has_editor(Object *p_object) { - if (_is_class_editor_disabled_by_feature_profile(p_object->get_class())) { return false; } @@ -1665,7 +1603,6 @@ void EditorNode::edit_item_resource(RES p_resource) { } bool EditorNode::_is_class_editor_disabled_by_feature_profile(const StringName &p_class) { - Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); if (profile.is_null()) { return false; @@ -1674,7 +1611,6 @@ bool EditorNode::_is_class_editor_disabled_by_feature_profile(const StringName & StringName class_name = p_class; while (class_name != StringName()) { - if (profile->is_class_disabled(class_name)) { return true; } @@ -1688,7 +1624,6 @@ bool EditorNode::_is_class_editor_disabled_by_feature_profile(const StringName & } void EditorNode::edit_item(Object *p_object) { - Vector<EditorPlugin *> sub_plugins; if (p_object) { @@ -1699,7 +1634,6 @@ void EditorNode::edit_item(Object *p_object) { } if (!sub_plugins.empty()) { - bool same = true; if (sub_plugins.size() == editor_plugins_over->get_plugins_list().size()) { for (int i = 0; i < sub_plugins.size(); i++) { @@ -1722,7 +1656,6 @@ void EditorNode::edit_item(Object *p_object) { } void EditorNode::push_item(Object *p_object, const String &p_property, bool p_inspector_only) { - if (!p_object) { get_inspector()->edit(nullptr); node_dock->set_node(nullptr); @@ -1733,21 +1666,20 @@ void EditorNode::push_item(Object *p_object, const String &p_property, bool p_in ObjectID id = p_object->get_instance_id(); if (id != editor_history.get_current()) { - if (p_inspector_only) { editor_history.add_object_inspector_only(id); - } else if (p_property == "") + } else if (p_property == "") { editor_history.add_object(id); - else + } else { editor_history.add_object(id, p_property); + } } _edit_current(); } void EditorNode::_save_default_environment() { - - Ref<Environment> fallback = get_tree()->get_root()->get_world()->get_fallback_environment(); + Ref<Environment> fallback = get_tree()->get_root()->get_world_3d()->get_fallback_environment(); if (fallback.is_valid() && fallback->get_path().is_resource_file()) { Map<RES, bool> processed; @@ -1757,7 +1689,6 @@ void EditorNode::_save_default_environment() { } void EditorNode::hide_top_editors() { - _display_top_editors(false); editor_plugins_over->clear(); @@ -1776,17 +1707,16 @@ void EditorNode::_set_editing_top_editors(Object *p_current_object) { } static bool overrides_external_editor(Object *p_object) { - Script *script = Object::cast_to<Script>(p_object); - if (!script) + if (!script) { return false; + } return script->get_language()->overrides_external_editor(); } void EditorNode::_edit_current() { - ObjectID current = editor_history.get_current(); Object *current_obj = current.is_valid() ? ObjectDB::get_instance(current) : nullptr; bool inspector_only = editor_history.is_current_inspector_only(); @@ -1794,7 +1724,6 @@ void EditorNode::_edit_current() { this->current = current_obj; if (!current_obj) { - scene_tree_dock->set_selected(nullptr); get_inspector()->edit(nullptr); node_dock->set_node(nullptr); @@ -1815,7 +1744,6 @@ void EditorNode::_edit_current() { String editable_warning; //none by default if (is_resource) { - Resource *current_res = Object::cast_to<Resource>(current_obj); ERR_FAIL_COND(!current_res); get_inspector()->edit(current_res); @@ -1840,7 +1768,6 @@ void EditorNode::_edit_current() { } } } else if (is_node) { - Node *current_node = Object::cast_to<Node>(current_obj); ERR_FAIL_COND(!current_node); @@ -1863,7 +1790,6 @@ void EditorNode::_edit_current() { } } else { - Node *selected_node = nullptr; if (current_obj->is_class("EditorDebuggerRemoteObject")) { @@ -1916,7 +1842,6 @@ void EditorNode::_edit_current() { /* Take care of PLUGIN EDITOR */ if (!inspector_only) { - EditorPlugin *main_plugin = editor_data.get_editor(current_obj); for (int i = 0; i < editor_table.size(); i++) { @@ -1926,20 +1851,20 @@ void EditorNode::_edit_current() { } if (main_plugin) { - // special case if use of external editor is true if (main_plugin->get_name() == "Script" && current_obj->get_class_name() != StringName("VisualScript") && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) { - if (!changing_scene) + if (!changing_scene) { main_plugin->edit(current_obj); + } } else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) { // update screen main_plugin if (!changing_scene) { - - if (editor_plugin_screen) + if (editor_plugin_screen) { editor_plugin_screen->make_visible(false); + } editor_plugin_screen = main_plugin; editor_plugin_screen->edit(current_obj); @@ -1951,13 +1876,11 @@ void EditorNode::_edit_current() { } for (int i = 0; i < editor_table.size(); i++) { - main_editor_buttons[i]->set_pressed(editor_table[i] == main_plugin); } } } else { - editor_plugin_screen->edit(current_obj); } } @@ -1975,7 +1898,6 @@ void EditorNode::_edit_current() { _set_editing_top_editors(current_obj); _display_top_editors(true); } else if (!editor_plugins_over->get_plugins_list().empty()) { - hide_top_editors(); } } @@ -1985,7 +1907,6 @@ void EditorNode::_edit_current() { } void EditorNode::_run(bool p_current, const String &p_custom) { - if (editor_run.get_status() == EditorRun::STATUS_PLAY) { play_button->set_pressed(!_playing_edited); play_scene_button->set_pressed(_playing_edited); @@ -2005,7 +1926,6 @@ void EditorNode::_run(bool p_current, const String &p_custom) { bool skip_breakpoints; if (p_current || (editor_data.get_edited_scene_root() && p_custom == editor_data.get_edited_scene_root()->get_filename())) { - Node *scene = editor_data.get_edited_scene_root(); if (!scene) { @@ -2025,7 +1945,6 @@ void EditorNode::_run(bool p_current, const String &p_custom) { } if (run_filename == "") { - //evidently, run the scene if (!ensure_main_scene(false)) { return; @@ -2033,15 +1952,12 @@ void EditorNode::_run(bool p_current, const String &p_custom) { } if (bool(EDITOR_GET("run/auto_save/save_before_running"))) { - if (unsaved_cache) { - Node *scene = editor_data.get_edited_scene_root(); if (scene) { //only autosave if there is a scene obviously if (scene->get_filename() == "") { - show_accept(TTR("Current scene was never saved, please save it prior to running."), TTR("OK")); return; } @@ -2053,8 +1969,9 @@ void EditorNode::_run(bool p_current, const String &p_custom) { editor_data.save_editor_external_data(); } - if (!call_build()) + if (!call_build()) { return; + } if (bool(EDITOR_GET("run/output/always_clear_output_on_play"))) { log->clear(); @@ -2070,9 +1987,10 @@ void EditorNode::_run(bool p_current, const String &p_custom) { args = ProjectSettings::get_singleton()->get("editor/main_run_args"); skip_breakpoints = EditorDebuggerNode::get_singleton()->is_skip_breakpoints(); + EditorDebuggerNode::get_singleton()->start(); Error error = editor_run.run(run_filename, args, breakpoints, skip_breakpoints); if (error != OK) { - + EditorDebuggerNode::get_singleton()->stop(); show_accept(TTR("Could not start subprocess!"), TTR("OK")); return; } @@ -2094,26 +2012,41 @@ void EditorNode::_run(bool p_current, const String &p_custom) { _playing_edited = p_current; } -void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { +void EditorNode::_run_native(const Ref<EditorExportPreset> &p_preset) { + bool autosave = EDITOR_GET("run/auto_save/save_before_running"); + if (autosave) { + _menu_option_confirm(FILE_SAVE_ALL_SCENES, false); + } + if (run_native->is_deploy_debug_remote_enabled()) { + _menu_option_confirm(RUN_STOP, true); + + if (!call_build()) { + return; // build failed + } - if (!p_confirmed) //this may be a hack.. + EditorDebuggerNode::get_singleton()->start(p_preset->get_platform()->get_debug_protocol()); + emit_signal("play_pressed"); + editor_run.run_native_notify(); + } +} + +void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { + if (!p_confirmed) { //this may be a hack.. current_option = (MenuOptions)p_option; + } switch (p_option) { case FILE_NEW_SCENE: { - new_scene(); } break; case FILE_NEW_INHERITED_SCENE: case FILE_OPEN_SCENE: { - file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions); file->clear_filters(); for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } @@ -2126,27 +2059,24 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_QUICK_OPEN: { - quick_open->popup_dialog("Resource", true); quick_open->set_title(TTR("Quick Open...")); } break; case FILE_QUICK_OPEN_SCENE: { - quick_open->popup_dialog("PackedScene", true); quick_open->set_title(TTR("Quick Open Scene...")); } break; case FILE_QUICK_OPEN_SCRIPT: { - quick_open->popup_dialog("Script", true); quick_open->set_title(TTR("Quick Open Script...")); } break; case FILE_OPEN_PREV: { - - if (previous_scenes.empty()) + if (previous_scenes.empty()) { break; + } opening_prev = true; open_request(previous_scenes.back()->get()); previous_scenes.pop_back(); @@ -2160,20 +2090,21 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { next_tab %= editor_data.get_edited_scene_count(); _scene_tab_closed(next_tab, current_option); } else { - if (current_option != FILE_CLOSE_ALL) + if (current_option != FILE_CLOSE_ALL) { current_option = -1; - else + } else { _scene_tab_closed(editor_data.get_edited_scene()); + } } - if (p_confirmed) + if (p_confirmed) { _menu_option_confirm(SCENE_TAB_CLOSE, true); + } } break; case FILE_CLOSE_ALL_AND_QUIT: case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER: case FILE_CLOSE: { - if (!p_confirmed) { tab_closing = p_option == FILE_CLOSE ? editor_data.get_edited_scene() : _next_unsaved_scene(false); @@ -2197,19 +2128,19 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } case SCENE_TAB_CLOSE: case FILE_SAVE_SCENE: { - int scene_idx = (p_option == FILE_SAVE_SCENE) ? -1 : tab_closing; Node *scene = editor_data.get_edited_scene_root(scene_idx); if (scene && scene->get_filename() != "") { - - if (scene_idx != editor_data.get_edited_scene()) + if (scene_idx != editor_data.get_edited_scene()) { _save_scene_with_preview(scene->get_filename(), scene_idx); - else + } else { _save_scene_with_preview(scene->get_filename()); + } - if (scene_idx != -1) + if (scene_idx != -1) { _discard_changes(); + } save_layout(); break; @@ -2222,7 +2153,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { Node *scene = editor_data.get_edited_scene_root(scene_idx); if (!scene) { - int saved = _save_external_resources(); String err_text; if (saved > 0) { @@ -2242,7 +2172,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { ResourceSaver::get_recognized_extensions(sd, &extensions); file->clear_filters(); for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } @@ -2255,7 +2184,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } } else { - String existing; if (extensions.size()) { String root_name(scene->get_name()); @@ -2269,7 +2197,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_SAVE_ALL_SCENES: { - _save_all_scenes(); } break; case FILE_SAVE_BEFORE_RUN: { @@ -2286,14 +2213,11 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_EXPORT_PROJECT: { - project_export->popup_export(); } break; case FILE_EXPORT_MESH_LIBRARY: { - if (!editor_data.get_edited_scene_root()) { - show_accept(TTR("This operation can't be done without a scene."), TTR("OK")); break; } @@ -2311,7 +2235,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_EXPORT_TILESET: { - //Make sure that the scene has a root before trying to convert to tileset if (!editor_data.get_edited_scene_root()) { show_accept(TTR("This operation can't be done without a root node."), TTR("OK")); @@ -2332,9 +2255,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_IMPORT_SUBSCENE: { - if (!editor_data.get_edited_scene_root()) { - show_accept(TTR("This operation can't be done without a selected node."), TTR("OK")); break; } @@ -2344,9 +2265,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_EXTERNAL_OPEN_SCENE: { - if (unsaved_cache && !p_confirmed) { - confirmation->get_ok()->set_text(TTR("Open")); confirmation->set_text(TTR("Current scene not saved. Open anyway?")); confirmation->popup_centered(); @@ -2363,8 +2282,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case EDIT_UNDO: { - - if (InputFilter::get_singleton()->get_mouse_button_mask() & 0x7) { + if (Input::get_singleton()->get_mouse_button_mask() & 0x7) { log->add_message("Can't undo while mouse buttons are pressed.", EditorLog::MSG_TYPE_EDITOR); } else { String action = editor_data.get_undo_redo().get_current_action_name(); @@ -2377,8 +2295,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } break; case EDIT_REDO: { - - if (InputFilter::get_singleton()->get_mouse_button_mask() & 0x7) { + if (Input::get_singleton()->get_mouse_button_mask() & 0x7) { log->add_message("Can't redo while mouse buttons are pressed.", EditorLog::MSG_TYPE_EDITOR); } else { if (!editor_data.get_undo_redo().redo()) { @@ -2390,12 +2307,12 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } break; - case EDIT_REVERT: { - + case EDIT_RELOAD_SAVED_SCENE: { Node *scene = get_edited_scene(); - if (!scene) + if (!scene) { break; + } String filename = scene->get_filename(); @@ -2405,8 +2322,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } if (unsaved_cache && !p_confirmed) { - confirmation->get_ok()->set_text(TTR("Revert")); - confirmation->set_text(TTR("This action cannot be undone. Revert anyway?")); + confirmation->get_ok()->set_text(TTR("Reload Saved Scene")); + confirmation->set_text( + TTR("The current scene has unsaved changes.\nReload the saved scene anyway? This action cannot be undone.")); confirmation->popup_centered(); break; } @@ -2414,8 +2332,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { int cur_idx = editor_data.get_edited_scene(); _remove_edited_scene(); Error err = load_scene(filename); - if (err != OK) + if (err != OK) { ERR_PRINT("Failed to load scene"); + } editor_data.move_edited_scene_to_index(cur_idx); get_undo_redo()->clear_history(false); scene_tabs->set_current_tab(cur_idx); @@ -2440,9 +2359,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case RUN_STOP: { - - if (editor_run.get_status() == EditorRun::STATUS_STOP) + if (editor_run.get_status() == EditorRun::STATUS_STOP) { break; + } editor_run.stop(); run_custom_filename.clear(); @@ -2462,6 +2381,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } } + EditorDebuggerNode::get_singleton()->stop(); emit_signal("stop_pressed"); } break; @@ -2474,38 +2394,18 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case RUN_PLAY_SCENE: { - _save_default_environment(); _menu_option_confirm(RUN_STOP, true); _run(true); } break; - case RUN_PLAY_NATIVE: { - - bool autosave = EDITOR_GET("run/auto_save/save_before_running"); - if (autosave) { - _menu_option_confirm(FILE_SAVE_ALL_SCENES, false); - } - if (run_native->is_deploy_debug_remote_enabled()) { - _menu_option_confirm(RUN_STOP, true); - - if (!call_build()) - break; // build failed - - emit_signal("play_pressed"); - editor_run.run_native_notify(); - } - } break; case RUN_SCENE_SETTINGS: { - run_settings_dialog->popup_run_settings(); } break; case RUN_SETTINGS: { - project_settings->popup_project_settings(); } break; case FILE_INSTALL_ANDROID_SOURCE: { - if (p_confirmed) { export_template_manager->install_android_template(); } else { @@ -2526,14 +2426,11 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_QUIT: case RUN_PROJECT_MANAGER: { - if (!p_confirmed) { bool save_each = EDITOR_GET("interface/editor/save_each_scene_on_quit"); if (_next_unsaved_scene(!save_each) == -1) { - bool confirm = EDITOR_GET("interface/editor/quit_confirmation"); if (confirm) { - confirmation->get_ok()->set_text(p_option == FILE_QUIT ? TTR("Quit") : TTR("Yes")); confirmation->set_text(p_option == FILE_QUIT ? TTR("Exit the editor?") : TTR("Open Project Manager?")); confirmation->popup_centered(); @@ -2542,12 +2439,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { break; } } else { - if (save_each) { - _menu_option_confirm(p_option == FILE_QUIT ? FILE_CLOSE_ALL_AND_QUIT : FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER, false); } else { - String unsaved_scenes; int i = _next_unsaved_scene(true, 0); while (i != -1) { @@ -2571,65 +2465,52 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { _discard_changes(); } break; case SETTINGS_UPDATE_CONTINUOUSLY: { - EditorSettings::get_singleton()->set("interface/editor/update_continuously", true); _update_update_spinner(); show_accept(TTR("This option is deprecated. Situations where refresh must be forced are now considered a bug. Please report."), TTR("OK")); } break; case SETTINGS_UPDATE_WHEN_CHANGED: { - EditorSettings::get_singleton()->set("interface/editor/update_continuously", false); _update_update_spinner(); } break; case SETTINGS_UPDATE_SPINNER_HIDE: { - EditorSettings::get_singleton()->set("interface/editor/show_update_spinner", false); _update_update_spinner(); } break; case SETTINGS_PREFERENCES: { - settings_config_dialog->popup_edit_settings(); } break; case SETTINGS_EDITOR_DATA_FOLDER: { - OS::get_singleton()->shell_open(String("file://") + EditorSettings::get_singleton()->get_data_dir()); } break; case SETTINGS_EDITOR_CONFIG_FOLDER: { - OS::get_singleton()->shell_open(String("file://") + EditorSettings::get_singleton()->get_settings_dir()); } break; case SETTINGS_MANAGE_EXPORT_TEMPLATES: { - export_template_manager->popup_manager(); } break; case SETTINGS_MANAGE_FEATURE_PROFILES: { - feature_profile_manager->popup_centered_clamped(Size2(900, 800) * EDSCALE, 0.8); } break; case SETTINGS_TOGGLE_FULLSCREEN: { - DisplayServer::get_singleton()->window_set_mode(DisplayServer::get_singleton()->window_get_mode() == DisplayServer::WINDOW_MODE_FULLSCREEN ? DisplayServer::WINDOW_MODE_WINDOWED : DisplayServer::WINDOW_MODE_FULLSCREEN); } break; case SETTINGS_TOGGLE_CONSOLE: { - bool was_visible = DisplayServer::get_singleton()->is_console_visible(); DisplayServer::get_singleton()->console_set_visible(!was_visible); EditorSettings::get_singleton()->set_setting("interface/editor/hide_console_window", was_visible); } break; case EDITOR_SCREENSHOT: { - screenshot_timer->start(); } break; case SETTINGS_PICK_MAIN_SCENE: { - file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions); file->clear_filters(); for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } @@ -2664,7 +2545,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case SET_VIDEO_DRIVER_SAVE_AND_RESTART: { - ProjectSettings::get_singleton()->set("rendering/quality/driver/driver_name", video_driver_request); ProjectSettings::get_singleton()->save(); @@ -2688,7 +2568,6 @@ void EditorNode::_screenshot(bool p_use_utc) { } void EditorNode::_save_screenshot(NodePath p_path) { - SubViewport *viewport = Object::cast_to<SubViewport>(EditorInterface::get_singleton()->get_editor_viewport()->get_viewport()); viewport->set_clear_mode(SubViewport::CLEAR_MODE_ONLY_NEXT_FRAME); Ref<Image> img = viewport->get_texture()->get_data(); @@ -2722,17 +2601,17 @@ void EditorNode::_tool_menu_option(int p_idx) { } int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) { - for (int i = p_start; i < editor_data.get_edited_scene_count(); i++) { - - if (!editor_data.get_edited_scene_root(i)) + if (!editor_data.get_edited_scene_root(i)) { continue; + } int current = editor_data.get_edited_scene(); bool unsaved = (i == current) ? saved_version != editor_data.get_undo_redo().get_version() : editor_data.get_scene_version(i) != 0; if (unsaved) { String scene_filename = editor_data.get_edited_scene_root(i)->get_filename(); - if (p_valid_filename && scene_filename.length() == 0) + if (p_valid_filename && scene_filename.length() == 0) { continue; + } return i; } } @@ -2751,9 +2630,7 @@ void EditorNode::_exit_editor() { } void EditorNode::_discard_changes(const String &p_str) { - switch (current_option) { - case FILE_CLOSE_ALL_AND_QUIT: case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER: case FILE_CLOSE: @@ -2761,7 +2638,6 @@ void EditorNode::_discard_changes(const String &p_str) { case FILE_CLOSE_RIGHT: case FILE_CLOSE_ALL: case SCENE_TAB_CLOSE: { - Node *scene = editor_data.get_edited_scene_root(tab_closing); if (scene != nullptr) { String scene_filename = scene->get_filename(); @@ -2795,13 +2671,11 @@ void EditorNode::_discard_changes(const String &p_str) { } } break; case FILE_QUIT: { - _menu_option_confirm(RUN_STOP, true); _exit_editor(); } break; case RUN_PROJECT_MANAGER: { - _menu_option_confirm(RUN_STOP, true); _exit_editor(); String exec = OS::get_singleton()->get_executable_path(); @@ -2819,7 +2693,6 @@ void EditorNode::_discard_changes(const String &p_str) { } void EditorNode::_update_file_menu_opened() { - Ref<ShortCut> close_scene_sc = ED_GET_SHORTCUT("editor/close_scene"); close_scene_sc->set_name(TTR("Close Scene")); Ref<ShortCut> reopen_closed_scene_sc = ED_GET_SHORTCUT("editor/reopen_closed_scene"); @@ -2834,20 +2707,20 @@ void EditorNode::_update_file_menu_closed() { } Control *EditorNode::get_viewport() { - return viewport; } void EditorNode::_editor_select(int p_which) { - static bool selecting = false; - if (selecting || changing_scene) + if (selecting || changing_scene) { return; + } ERR_FAIL_INDEX(p_which, editor_table.size()); - if (!main_editor_buttons[p_which]->is_visible()) //button hidden, no editor + if (!main_editor_buttons[p_which]->is_visible()) { //button hidden, no editor return; + } selecting = true; @@ -2860,8 +2733,9 @@ void EditorNode::_editor_select(int p_which) { EditorPlugin *new_editor = editor_table[p_which]; ERR_FAIL_COND(!new_editor); - if (editor_plugin_screen == new_editor) + if (editor_plugin_screen == new_editor) { return; + } if (editor_plugin_screen) { editor_plugin_screen->make_visible(false); @@ -2899,9 +2773,7 @@ void EditorNode::select_editor_by_name(const String &p_name) { } void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) { - if (p_editor->has_main_screen()) { - ToolButton *tb = memnew(ToolButton); tb->set_toggle_mode(true); tb->connect("pressed", callable_mp(singleton, &EditorNode::_editor_select), varray(singleton->main_editor_buttons.size())); @@ -2923,18 +2795,15 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed } singleton->editor_data.add_editor_plugin(p_editor); singleton->add_child(p_editor); - if (p_config_changed) + if (p_config_changed) { p_editor->enable_plugin(); + } } void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) { - if (p_editor->has_main_screen()) { - for (int i = 0; i < singleton->main_editor_buttons.size(); i++) { - if (p_editor->get_name() == singleton->main_editor_buttons[i]->get_text()) { - if (singleton->main_editor_buttons[i]->is_pressed()) { singleton->_editor_select(EDITOR_SCRIPT); } @@ -2950,8 +2819,9 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan } p_editor->make_visible(false); p_editor->clear(); - if (p_config_changed) + if (p_config_changed) { p_editor->disable_plugin(); + } singleton->editor_plugins_over->get_plugins_list().erase(p_editor); singleton->remove_child(p_editor); singleton->editor_data.remove_editor_plugin(p_editor); @@ -2959,9 +2829,9 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan } void EditorNode::_update_addon_config() { - - if (_initializing_addons) + if (_initializing_addons) { return; + } Vector<String> enabled_addons; @@ -2979,12 +2849,10 @@ void EditorNode::_update_addon_config() { } void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed) { - ERR_FAIL_COND(p_enabled && plugin_addons.has(p_addon)); ERR_FAIL_COND(!p_enabled && !plugin_addons.has(p_addon)); if (!p_enabled) { - EditorPlugin *addon = plugin_addons[p_addon]; remove_editor_plugin(addon, p_config_changed); memdelete(addon); //bye @@ -3061,7 +2929,6 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, } bool EditorNode::is_addon_plugin_enabled(const String &p_addon) const { - return plugin_addons.has(p_addon); } @@ -3082,7 +2949,9 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) { ScriptEditor::get_singleton()->close_builtin_scripts_from_scene(editor_data.get_scene_path(old_index)); } - if (p_change_tab) _scene_tab_changed(new_index); + if (p_change_tab) { + _scene_tab_changed(new_index); + } editor_data.remove_scene(old_index); editor_data.get_undo_redo().clear_history(false); _update_title(); @@ -3090,7 +2959,6 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) { } void EditorNode::_remove_scene(int index, bool p_change_tab) { - if (editor_data.get_edited_scene() == index) { //Scene to remove is current scene _remove_edited_scene(p_change_tab); @@ -3101,37 +2969,39 @@ void EditorNode::_remove_scene(int index, bool p_change_tab) { } void EditorNode::set_edited_scene(Node *p_scene) { - if (get_editor_data().get_edited_scene_root()) { - if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) + if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) { scene_root->remove_child(get_editor_data().get_edited_scene_root()); + } } get_editor_data().set_edited_scene_root(p_scene); - if (Object::cast_to<Popup>(p_scene)) + if (Object::cast_to<Popup>(p_scene)) { Object::cast_to<Popup>(p_scene)->show(); //show popups + } scene_tree_dock->set_edited_scene(p_scene); - if (get_tree()) + if (get_tree()) { get_tree()->set_edited_scene_root(p_scene); + } if (p_scene) { - if (p_scene->get_parent() != scene_root) + if (p_scene->get_parent() != scene_root) { scene_root->add_child(p_scene); + } } } int EditorNode::_get_current_main_editor() { - for (int i = 0; i < editor_table.size(); i++) { - if (editor_table[i] == editor_plugin_screen) + if (editor_table[i] == editor_plugin_screen) { return i; + } } return 0; } Dictionary EditorNode::_get_main_scene_state() { - Dictionary state; state["main_tab"] = _get_current_main_editor(); state["scene_tree_offset"] = scene_tree_dock->get_tree_editor()->get_scene_tree()->get_vscroll_bar()->get_value(); @@ -3142,9 +3012,9 @@ Dictionary EditorNode::_get_main_scene_state() { } void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { - - if (get_edited_scene() != p_for_scene && p_for_scene != nullptr) + if (get_edited_scene() != p_for_scene && p_for_scene != nullptr) { return; //not for this scene + } changing_scene = false; @@ -3178,13 +3048,16 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { } } - if (p_state.has("scene_tree_offset")) + if (p_state.has("scene_tree_offset")) { scene_tree_dock->get_tree_editor()->get_scene_tree()->get_vscroll_bar()->set_value(p_state["scene_tree_offset"]); - if (p_state.has("property_edit_offset")) + } + if (p_state.has("property_edit_offset")) { get_inspector()->set_scroll_offset(p_state["property_edit_offset"]); + } - if (p_state.has("node_filter")) + if (p_state.has("node_filter")) { scene_tree_dock->set_filter(p_state["node_filter"]); + } //this should only happen at the very end @@ -3194,7 +3067,6 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { } void EditorNode::set_current_version(uint64_t p_version) { - saved_version = p_version; editor_data.set_edited_scene_version(p_version); } @@ -3204,19 +3076,19 @@ bool EditorNode::is_changing_scene() const { } void EditorNode::_clear_undo_history() { - get_undo_redo()->clear_history(false); } void EditorNode::set_current_scene(int p_idx) { - //Save the folding in case the scene gets reloaded. - if (editor_data.get_scene_path(p_idx) != "" && editor_data.get_edited_scene_root(p_idx)) + if (editor_data.get_scene_path(p_idx) != "" && editor_data.get_edited_scene_root(p_idx)) { editor_folding.save_scene_folding(editor_data.get_edited_scene_root(p_idx), editor_data.get_scene_path(p_idx)); + } if (editor_data.check_and_update_scene(p_idx)) { - if (editor_data.get_scene_path(p_idx) != "") + if (editor_data.get_scene_path(p_idx) != "") { editor_folding.load_scene_folding(editor_data.get_edited_scene_root(p_idx), editor_data.get_scene_path(p_idx)); + } call_deferred("_clear_undo_history"); } @@ -3225,8 +3097,9 @@ void EditorNode::set_current_scene(int p_idx) { editor_data.save_edited_scene_state(editor_selection, &editor_history, _get_main_scene_state()); if (get_editor_data().get_edited_scene_root()) { - if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) + if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) { scene_root->remove_child(get_editor_data().get_edited_scene_root()); + } } editor_selection->clear(); @@ -3234,16 +3107,19 @@ void EditorNode::set_current_scene(int p_idx) { Node *new_scene = editor_data.get_edited_scene_root(); - if (Object::cast_to<Popup>(new_scene)) + if (Object::cast_to<Popup>(new_scene)) { Object::cast_to<Popup>(new_scene)->show(); //show popups + } scene_tree_dock->set_edited_scene(new_scene); - if (get_tree()) + if (get_tree()) { get_tree()->set_edited_scene_root(new_scene); + } if (new_scene) { - if (new_scene->get_parent() != scene_root) + if (new_scene->get_parent() != scene_root) { scene_root->add_child(new_scene); + } } Dictionary state = editor_data.restore_edited_scene_state(editor_selection, &editor_history); @@ -3255,10 +3131,10 @@ void EditorNode::set_current_scene(int p_idx) { } bool EditorNode::is_scene_open(const String &p_path) { - for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { - if (editor_data.get_scene_path(i) == p_path) + if (editor_data.get_scene_path(i) == p_path) { return true; + } } return false; @@ -3277,16 +3153,13 @@ int EditorNode::new_scene() { } Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, bool p_set_inherited, bool p_clear_errors, bool p_force_open_imported) { - if (!is_inside_tree()) { defer_load_scene = p_scene; return OK; } if (!p_set_inherited) { - for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { - if (editor_data.get_scene_path(i) == p_scene) { _scene_tab_changed(i); return OK; @@ -3302,13 +3175,13 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b } } - if (p_clear_errors) + if (p_clear_errors) { load_errors->clear(); + } String lpath = ProjectSettings::get_singleton()->localize_path(p_scene); if (!lpath.begins_with("res://")) { - show_accept(TTR("Error loading scene, it must be inside the project path. Use 'Import' to open the scene, then save it inside the project path."), TTR("OK")); opening_prev = false; return ERR_FILE_NOT_FOUND; @@ -3328,7 +3201,6 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b Error err; Ref<PackedScene> sdata = ResourceLoader::load(lpath, "", true, &err); if (!sdata.is_valid()) { - _dialog_display_load_error(lpath, err); opening_prev = false; @@ -3340,11 +3212,9 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b } if (!p_ignore_broken_deps && dependency_errors.has(lpath)) { - current_option = -1; Vector<String> errors; for (Set<String>::Element *E = dependency_errors[lpath].front(); E; E = E->next()) { - errors.push_back(E->get()); } dependency_error->show(DependencyErrorDialog::MODE_SCENE, lpath, errors); @@ -3360,7 +3230,6 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b dependency_errors.erase(lpath); //at least not self path for (Map<String, Set<String>>::Element *E = dependency_errors.front(); E; E = E->next()) { - String txt = vformat(TTR("Scene '%s' has broken dependencies:"), E->key()) + "\n"; for (Set<String>::Element *F = E->get().front(); F; F = F->next()) { txt += "\t" + F->get() + "\n"; @@ -3384,7 +3253,6 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b Node *new_scene = sdata->instance(PackedScene::GEN_EDIT_STATE_MAIN); if (!new_scene) { - sdata.unref(); _dialog_display_load_error(lpath, ERR_FILE_NOT_FOUND); opening_prev = false; @@ -3435,7 +3303,6 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b } void EditorNode::open_request(const String &p_path) { - if (!opening_prev) { List<String>::Element *prev_scene = previous_scenes.find(p_path); if (prev_scene != nullptr) { @@ -3447,12 +3314,10 @@ void EditorNode::open_request(const String &p_path) { } void EditorNode::request_instance_scene(const String &p_path) { - scene_tree_dock->instance(p_path); } void EditorNode::request_instance_scenes(const Vector<String> &p_files) { - scene_tree_dock->instance_scenes(p_files); } @@ -3461,66 +3326,58 @@ ImportDock *EditorNode::get_import_dock() { } FileSystemDock *EditorNode::get_filesystem_dock() { - return filesystem_dock; } -SceneTreeDock *EditorNode::get_scene_tree_dock() { +SceneTreeDock *EditorNode::get_scene_tree_dock() { return scene_tree_dock; } -InspectorDock *EditorNode::get_inspector_dock() { +InspectorDock *EditorNode::get_inspector_dock() { return inspector_dock; } void EditorNode::_inherit_request(String p_file) { - current_option = FILE_NEW_INHERITED_SCENE; _dialog_action(p_file); } void EditorNode::_instance_request(const Vector<String> &p_files) { - request_instance_scenes(p_files); } void EditorNode::_close_messages() { - old_split_ofs = center_split->get_split_offset(); center_split->set_split_offset(0); } void EditorNode::_show_messages() { - center_split->set_split_offset(old_split_ofs); } void EditorNode::_add_to_recent_scenes(const String &p_scene) { - Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scenes", Array()); - if (rc.find(p_scene) != -1) + if (rc.find(p_scene) != -1) { rc.erase(p_scene); + } rc.push_front(p_scene); - if (rc.size() > 10) + if (rc.size() > 10) { rc.resize(10); + } EditorSettings::get_singleton()->set_project_metadata("recent_files", "scenes", rc); _update_recent_scenes(); } void EditorNode::_open_recent_scene(int p_idx) { - if (p_idx == recent_scenes->get_item_count() - 1) { - EditorSettings::get_singleton()->set_project_metadata("recent_files", "scenes", Array()); call_deferred("_update_recent_scenes"); } else { - Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scenes", Array()); ERR_FAIL_INDEX(p_idx, rc.size()); if (load_scene(rc[p_idx]) != OK) { - rc.remove(p_idx); EditorSettings::get_singleton()->set_project_metadata("recent_files", "scenes", rc); _update_recent_scenes(); @@ -3529,13 +3386,11 @@ void EditorNode::_open_recent_scene(int p_idx) { } void EditorNode::_update_recent_scenes() { - Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scenes", Array()); recent_scenes->clear(); String path; for (int i = 0; i < rc.size(); i++) { - path = rc[i]; recent_scenes->add_item(path.replace("res://", ""), i); } @@ -3546,7 +3401,6 @@ void EditorNode::_update_recent_scenes() { } void EditorNode::_quick_opened() { - Vector<String> files = quick_open->get_selected_files(); for (int i = 0; i < files.size(); i++) { @@ -3561,12 +3415,10 @@ void EditorNode::_quick_opened() { } void EditorNode::_quick_run() { - _run(false, quick_run->get_selected()); } void EditorNode::notify_all_debug_sessions_exited() { - _menu_option_confirm(RUN_STOP, false); stop_button->set_pressed(false); editor_run.stop(); @@ -3577,7 +3429,6 @@ void EditorNode::add_io_error(const String &p_error) { } void EditorNode::_load_error_notify(void *p_ud, const String &p_text) { - EditorNode *en = (EditorNode *)p_ud; en->load_errors->add_image(en->gui_base->get_theme_icon("Error", "EditorIcons")); en->load_errors->add_text(p_text + "\n"); @@ -3585,13 +3436,11 @@ void EditorNode::_load_error_notify(void *p_ud, const String &p_text) { } bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const { - if (p_node->get_filename() == p_path) { return true; } for (int i = 0; i < p_node->get_child_count(); i++) { - if (_find_scene_in_use(p_node->get_child(i), p_path)) { return true; } @@ -3601,15 +3450,14 @@ bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const { } bool EditorNode::is_scene_in_use(const String &p_path) { - Node *es = get_edited_scene(); - if (es) + if (es) { return _find_scene_in_use(es, p_path); + } return false; } void EditorNode::register_editor_types() { - ResourceLoader::set_timestamp_on_load(true); ResourceSaver::set_timestamp_on_save(true); @@ -3646,16 +3494,15 @@ void EditorNode::register_editor_types() { } void EditorNode::unregister_editor_types() { - _init_callbacks.clear(); } void EditorNode::stop_child_process(OS::ProcessID p_pid) { - if (has_child_process(p_pid)) { editor_run.stop_child_process(p_pid); - if (!editor_run.get_child_process_count()) // All children stopped. Closing. + if (!editor_run.get_child_process_count()) { // All children stopped. Closing. _menu_option_confirm(RUN_STOP, false); + } } } @@ -3702,8 +3549,9 @@ StringName EditorNode::get_object_custom_type_name(const Object *p_object) const Ref<Script> base_script = script; while (base_script.is_valid()) { StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path()); - if (name != StringName()) + if (name != StringName()) { return name; + } // should probably be deprecated in 4.x StringName base = base_script->get_instance_base_type(); @@ -3769,14 +3617,17 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String } // should probably be deprecated in 4.x - if (p_object->has_meta("_editor_icon")) + if (p_object->has_meta("_editor_icon")) { return p_object->get_meta("_editor_icon"); + } - if (gui_base->has_theme_icon(p_object->get_class(), "EditorIcons")) + if (gui_base->has_theme_icon(p_object->get_class(), "EditorIcons")) { return gui_base->get_theme_icon(p_object->get_class(), "EditorIcons"); + } - if (p_fallback.length()) + if (p_fallback.length()) { return gui_base->get_theme_icon(p_fallback, "EditorIcons"); + } return nullptr; } @@ -3826,14 +3677,14 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p } } - if (p_fallback.length() && gui_base->has_theme_icon(p_fallback, "EditorIcons")) + if (p_fallback.length() && gui_base->has_theme_icon(p_fallback, "EditorIcons")) { return gui_base->get_theme_icon(p_fallback, "EditorIcons"); + } return nullptr; } void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) { - if (singleton->cmdline_export_mode) { print_line(p_task + ": begin: " + p_label + " steps: " + itos(p_steps)); } else { @@ -3842,18 +3693,15 @@ void EditorNode::progress_add_task(const String &p_task, const String &p_label, } bool EditorNode::progress_task_step(const String &p_task, const String &p_state, int p_step, bool p_force_refresh) { - if (singleton->cmdline_export_mode) { print_line("\t" + p_task + ": step " + itos(p_step) + ": " + p_state); return false; } else { - return singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh); } } void EditorNode::progress_end_task(const String &p_task) { - if (singleton->cmdline_export_mode) { print_line(p_task + ": end"); } else { @@ -3862,29 +3710,23 @@ void EditorNode::progress_end_task(const String &p_task) { } void EditorNode::progress_add_task_bg(const String &p_task, const String &p_label, int p_steps) { - singleton->progress_hb->add_task(p_task, p_label, p_steps); } void EditorNode::progress_task_step_bg(const String &p_task, int p_step) { - singleton->progress_hb->task_step(p_task, p_step); } void EditorNode::progress_end_task_bg(const String &p_task) { - singleton->progress_hb->end_task(p_task); } Ref<Texture2D> EditorNode::_file_dialog_get_icon(const String &p_path) { - EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->get_filesystem_path(p_path.get_base_dir()); if (efsd) { - String file = p_path.get_file(); for (int i = 0; i < efsd->get_file_count(); i++) { if (efsd->get_file(i) == file) { - String type = efsd->get_file_type(i); if (singleton->icon_type_cache.has(type)) { @@ -3900,42 +3742,36 @@ Ref<Texture2D> EditorNode::_file_dialog_get_icon(const String &p_path) { } void EditorNode::_build_icon_type_cache() { - List<StringName> tl; StringName ei = "EditorIcons"; theme_base->get_theme()->get_icon_list(ei, &tl); for (List<StringName>::Element *E = tl.front(); E; E = E->next()) { - - if (!ClassDB::class_exists(E->get())) + if (!ClassDB::class_exists(E->get())) { continue; + } icon_type_cache[E->get()] = theme_base->get_theme()->get_icon(E->get(), ei); } } void EditorNode::_file_dialog_register(FileDialog *p_dialog) { - singleton->file_dialogs.insert(p_dialog); } void EditorNode::_file_dialog_unregister(FileDialog *p_dialog) { - singleton->file_dialogs.erase(p_dialog); } void EditorNode::_editor_file_dialog_register(EditorFileDialog *p_dialog) { - singleton->editor_file_dialogs.insert(p_dialog); } void EditorNode::_editor_file_dialog_unregister(EditorFileDialog *p_dialog) { - singleton->editor_file_dialogs.erase(p_dialog); } Vector<EditorNodeInitCallback> EditorNode::_init_callbacks; Error EditorNode::export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only) { - export_defer.preset = p_preset; export_defer.path = p_path; export_defer.debug = p_debug; @@ -3952,7 +3788,6 @@ void EditorNode::show_accept(const String &p_text, const String &p_title) { } void EditorNode::show_warning(const String &p_text, const String &p_title) { - if (warning->is_inside_tree()) { warning->set_text(p_text); warning->set_title(p_title); @@ -3963,7 +3798,6 @@ void EditorNode::show_warning(const String &p_text, const String &p_title) { } void EditorNode::_copy_warning(const String &p_str) { - DisplayServer::get_singleton()->clipboard_set(warning->get_text()); } @@ -4028,7 +3862,6 @@ void EditorNode::_dock_make_float() { } void EditorNode::_update_dock_containers() { - for (int i = 0; i < DOCK_SLOT_MAX; i++) { if (dock_slot[i]->get_tab_count() == 0 && dock_slot[i]->is_visible()) { dock_slot[i]->hide(); @@ -4039,24 +3872,24 @@ void EditorNode::_update_dock_containers() { } for (int i = 0; i < vsplits.size(); i++) { bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count(); - if (in_use) + if (in_use) { vsplits[i]->show(); - else + } else { vsplits[i]->hide(); + } } - if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) + if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) { right_hsplit->show(); - else + } else { right_hsplit->hide(); + } } void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) { - Ref<InputEventMouse> me = p_input; if (me.is_valid()) { - Vector2 point = me->get_position(); int nrect = -1; @@ -4072,8 +3905,9 @@ void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) { dock_select_rect_over = nrect; } - if (nrect == -1) + if (nrect == -1) { return; + } Ref<InputEventMouseButton> mb = me; @@ -4086,7 +3920,6 @@ void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) { dock_slot[dock_popup_selected]->hide(); } else { - dock_slot[dock_popup_selected]->set_current_tab(0); } @@ -4105,24 +3938,23 @@ void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) { } void EditorNode::_dock_popup_exit() { - dock_select_rect_over = -1; dock_select->update(); } void EditorNode::_dock_pre_popup(int p_which) { - dock_popup_selected = p_which; } void EditorNode::_dock_move_left() { - - if (dock_popup_selected < 0 || dock_popup_selected >= DOCK_SLOT_MAX) + if (dock_popup_selected < 0 || dock_popup_selected >= DOCK_SLOT_MAX) { return; + } Control *current = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab()); Control *prev = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab() - 1); - if (!current || !prev) + if (!current || !prev) { return; + } dock_slot[dock_popup_selected]->move_child(current, prev->get_index()); dock_slot[dock_popup_selected]->set_current_tab(dock_slot[dock_popup_selected]->get_current_tab() - 1); dock_select->update(); @@ -4131,11 +3963,11 @@ void EditorNode::_dock_move_left() { } void EditorNode::_dock_move_right() { - Control *current = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab()); Control *next = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab() + 1); - if (!current || !next) + if (!current || !next) { return; + } dock_slot[dock_popup_selected]->move_child(next, current->get_index()); dock_slot[dock_popup_selected]->set_current_tab(dock_slot[dock_popup_selected]->get_current_tab() + 1); dock_select->update(); @@ -4166,18 +3998,15 @@ void EditorNode::_dock_select_draw() { dock_tab_move_right->set_disabled(true); if (dock_popup_selected != -1 && dock_slot[dock_popup_selected]->get_tab_count()) { - dock_tab_move_left->set_disabled(dock_slot[dock_popup_selected]->get_current_tab() == 0); dock_tab_move_right->set_disabled(dock_slot[dock_popup_selected]->get_current_tab() >= dock_slot[dock_popup_selected]->get_tab_count() - 1); } for (int i = 0; i < DOCK_SLOT_MAX; i++) { - Vector2 ofs; switch (i) { case DOCK_SLOT_LEFT_UL: { - } break; case DOCK_SLOT_LEFT_BL: { ofs.y += s.y; @@ -4218,22 +4047,21 @@ void EditorNode::_dock_select_draw() { } else if (dock_slot[i]->get_child_count() == 0) { dock_select->draw_rect(r, unused); } else { - dock_select->draw_rect(r, used); } for (int j = 0; j < MIN(3, dock_slot[i]->get_child_count()); j++) { int xofs = (r.size.width / 3) * j; Color c = used; - if (i == dock_popup_selected && (dock_slot[i]->get_current_tab() > 3 || dock_slot[i]->get_current_tab() == j)) + if (i == dock_popup_selected && (dock_slot[i]->get_current_tab() > 3 || dock_slot[i]->get_current_tab() == j)) { c = tab_selected; + } dock_select->draw_rect(Rect2(2 + ofs.x + xofs, ofs.y, r.size.width / 3 - 1, 3), c); } } } void EditorNode::_save_docks() { - if (waiting_for_first_scan) { return; //scanning, do not touch docks } @@ -4248,13 +4076,13 @@ void EditorNode::_save_docks() { } void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) { - for (int i = 0; i < DOCK_SLOT_MAX; i++) { String names; for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) { String name = dock_slot[i]->get_tab_control(j)->get_name(); - if (names != "") + if (names != "") { names += ","; + } names += name; } @@ -4268,14 +4096,12 @@ void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p p_layout->set_value(p_section, "dock_filesystem_file_list_display_mode", filesystem_dock->get_file_list_display_mode()); for (int i = 0; i < vsplits.size(); i++) { - if (vsplits[i]->is_visible_in_tree()) { p_layout->set_value(p_section, "dock_split_" + itos(i + 1), vsplits[i]->get_split_offset()); } } for (int i = 0; i < hsplits.size(); i++) { - p_layout->set_value(p_section, "dock_hsplit_" + itos(i + 1), hsplits[i]->get_split_offset()); } } @@ -4293,17 +4119,14 @@ void EditorNode::_save_open_scenes_to_config(Ref<ConfigFile> p_layout, const Str } void EditorNode::save_layout() { - dock_drag_timer->start(); } void EditorNode::_dock_split_dragged(int ofs) { - dock_drag_timer->start(); } void EditorNode::_load_docks() { - Ref<ConfigFile> config; config.instance(); Error err = config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); @@ -4322,9 +4145,7 @@ void EditorNode::_load_docks() { } void EditorNode::_update_dock_slots_visibility() { - if (!docks_visible) { - for (int i = 0; i < DOCK_SLOT_MAX; i++) { dock_slot[i]->hide(); } @@ -4337,48 +4158,47 @@ void EditorNode::_update_dock_slots_visibility() { bottom_panel->hide(); } else { for (int i = 0; i < DOCK_SLOT_MAX; i++) { - int tabs_visible = 0; for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) { if (!dock_slot[i]->get_tab_hidden(j)) { tabs_visible++; } } - if (tabs_visible) + if (tabs_visible) { dock_slot[i]->show(); - else + } else { dock_slot[i]->hide(); + } } for (int i = 0; i < vsplits.size(); i++) { bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count(); - if (in_use) + if (in_use) { vsplits[i]->show(); - else + } else { vsplits[i]->hide(); + } } for (int i = 0; i < DOCK_SLOT_MAX; i++) { - if (dock_slot[i]->is_visible() && dock_slot[i]->get_tab_count()) { dock_slot[i]->set_current_tab(0); } } bottom_panel->show(); - if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) + if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) { right_hsplit->show(); - else + } else { right_hsplit->hide(); + } } } void EditorNode::_dock_tab_changed(int p_tab) { - // update visibility but don't set current tab if (!docks_visible) { - for (int i = 0; i < DOCK_SLOT_MAX; i++) { dock_slot[i]->hide(); } @@ -4391,55 +4211,58 @@ void EditorNode::_dock_tab_changed(int p_tab) { bottom_panel->hide(); } else { for (int i = 0; i < DOCK_SLOT_MAX; i++) { - - if (dock_slot[i]->get_tab_count()) + if (dock_slot[i]->get_tab_count()) { dock_slot[i]->show(); - else + } else { dock_slot[i]->hide(); + } } for (int i = 0; i < vsplits.size(); i++) { bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count(); - if (in_use) + if (in_use) { vsplits[i]->show(); - else + } else { vsplits[i]->hide(); + } } bottom_panel->show(); - if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) + if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) { right_hsplit->show(); - else + } else { right_hsplit->hide(); + } } } void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section) { - for (int i = 0; i < DOCK_SLOT_MAX; i++) { - - if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1))) + if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1))) { continue; + } Vector<String> names = String(p_layout->get_value(p_section, "dock_" + itos(i + 1))).split(","); for (int j = 0; j < names.size(); j++) { - String name = names[j]; //find it, in a horribly inefficient way int atidx = -1; Control *node = nullptr; for (int k = 0; k < DOCK_SLOT_MAX; k++) { - if (!dock_slot[k]->has_node(name)) + if (!dock_slot[k]->has_node(name)) { continue; + } node = Object::cast_to<Control>(dock_slot[k]->get_node(name)); - if (!node) + if (!node) { continue; + } atidx = k; break; } - if (atidx == -1) //well, it's not anywhere + if (atidx == -1) { //well, it's not anywhere continue; + } if (atidx == i) { node->raise(); @@ -4472,36 +4295,38 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String } for (int i = 0; i < vsplits.size(); i++) { - - if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1))) + if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1))) { continue; + } int ofs = p_layout->get_value(p_section, "dock_split_" + itos(i + 1)); vsplits[i]->set_split_offset(ofs); } for (int i = 0; i < hsplits.size(); i++) { - if (!p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1))) + if (!p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1))) { continue; + } int ofs = p_layout->get_value(p_section, "dock_hsplit_" + itos(i + 1)); hsplits[i]->set_split_offset(ofs); } for (int i = 0; i < vsplits.size(); i++) { bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count(); - if (in_use) + if (in_use) { vsplits[i]->show(); - else + } else { vsplits[i]->hide(); + } } - if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) + if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) { right_hsplit->show(); - else + } else { right_hsplit->hide(); + } for (int i = 0; i < DOCK_SLOT_MAX; i++) { - if (dock_slot[i]->is_visible() && dock_slot[i]->get_tab_count()) { dock_slot[i]->set_current_tab(0); } @@ -4550,7 +4375,6 @@ bool EditorNode::ensure_main_scene(bool p_from_native) { String main_scene = GLOBAL_DEF("application/run/main_scene", ""); if (main_scene == "") { - current_option = -1; pick_main_scene->set_text(TTR("No main scene has ever been defined, select one?\nYou can change it later in \"Project Settings\" under the 'application' category.")); pick_main_scene->popup_centered(); @@ -4558,7 +4382,6 @@ bool EditorNode::ensure_main_scene(bool p_from_native) { } if (!FileAccess::exists(main_scene)) { - current_option = -1; pick_main_scene->set_text(vformat(TTR("Selected scene '%s' does not exist, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), main_scene)); pick_main_scene->popup_centered(); @@ -4566,7 +4389,6 @@ bool EditorNode::ensure_main_scene(bool p_from_native) { } if (ResourceLoader::get_resource_type(main_scene) != "PackedScene") { - current_option = -1; pick_main_scene->set_text(vformat(TTR("Selected scene '%s' is not a scene file, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), main_scene)); pick_main_scene->popup_centered(); @@ -4594,7 +4416,6 @@ void EditorNode::set_current_tab(int p_tab) { } void EditorNode::_update_layouts_menu() { - editor_layouts->clear(); overridden_default_layout = -1; @@ -4615,7 +4436,6 @@ void EditorNode::_update_layouts_menu() { config.ptr()->get_sections(&layouts); for (List<String>::Element *E = layouts.front(); E; E = E->next()) { - String layout = E->get(); if (layout == TTR("Default")) { @@ -4628,11 +4448,8 @@ void EditorNode::_update_layouts_menu() { } void EditorNode::_layout_menu_option(int p_id) { - switch (p_id) { - case SETTINGS_LAYOUT_SAVE: { - current_option = p_id; layout_dialog->set_title(TTR("Save Layout")); layout_dialog->get_ok()->set_text(TTR("Save")); @@ -4640,7 +4457,6 @@ void EditorNode::_layout_menu_option(int p_id) { layout_dialog->set_name_line_enabled(true); } break; case SETTINGS_LAYOUT_DELETE: { - current_option = p_id; layout_dialog->set_title(TTR("Delete Layout")); layout_dialog->get_ok()->set_text(TTR("Delete")); @@ -4648,12 +4464,10 @@ void EditorNode::_layout_menu_option(int p_id) { layout_dialog->set_name_line_enabled(false); } break; case SETTINGS_LAYOUT_DEFAULT: { - _load_docks_from_config(default_layout, "docks"); _save_docks(); } break; default: { - Ref<ConfigFile> config; config.instance(); Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); @@ -4668,10 +4482,10 @@ void EditorNode::_layout_menu_option(int p_id) { } void EditorNode::_scene_tab_script_edited(int p_tab) { - Ref<Script> script = editor_data.get_scene_root_script(p_tab); - if (script.is_valid()) + if (script.is_valid()) { inspector_dock->edit_resource(script); + } } void EditorNode::_scene_tab_closed(int p_tab, int option) { @@ -4722,7 +4536,6 @@ void EditorNode::_scene_tab_input(const Ref<InputEvent> &p_input) { Ref<InputEventMouseButton> mb = p_input; if (mb.is_valid()) { - if (scene_tabs->get_hovered_tab() >= 0) { if (mb->get_button_index() == BUTTON_MIDDLE && mb->is_pressed()) { _scene_tab_closed(scene_tabs->get_hovered_tab()); @@ -4733,7 +4546,6 @@ void EditorNode::_scene_tab_input(const Ref<InputEvent> &p_input) { } } if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { - // context menu scene_tabs_context_menu->clear(); scene_tabs_context_menu->set_size(Size2(1, 1)); @@ -4790,8 +4602,9 @@ void EditorNode::_scene_tab_changed(int p_tab) { bool unsaved = (saved_version != editor_data.get_undo_redo().get_version()); - if (p_tab == editor_data.get_edited_scene()) + if (p_tab == editor_data.get_edited_scene()) { return; //pointless + } uint64_t next_scene_version = editor_data.get_scene_version(p_tab); @@ -4807,7 +4620,6 @@ void EditorNode::_scene_tab_changed(int p_tab) { } ToolButton *EditorNode::add_bottom_panel_item(String p_text, Control *p_item) { - ToolButton *tb = memnew(ToolButton); tb->connect("toggled", callable_mp(this, &EditorNode::_bottom_panel_switch), varray(bottom_panel_items.size())); tb->set_text(p_text); @@ -4828,19 +4640,17 @@ ToolButton *EditorNode::add_bottom_panel_item(String p_text, Control *p_item) { } bool EditorNode::are_bottom_panels_hidden() const { - for (int i = 0; i < bottom_panel_items.size(); i++) { - if (bottom_panel_items[i].button->is_pressed()) + if (bottom_panel_items[i].button->is_pressed()) { return false; + } } return true; } void EditorNode::hide_bottom_panel() { - for (int i = 0; i < bottom_panel_items.size(); i++) { - if (bottom_panel_items[i].control->is_visible()) { _bottom_panel_switch(false, i); break; @@ -4849,9 +4659,7 @@ void EditorNode::hide_bottom_panel() { } void EditorNode::make_bottom_panel_item_visible(Control *p_item) { - for (int i = 0; i < bottom_panel_items.size(); i++) { - if (bottom_panel_items[i].control == p_item) { _bottom_panel_switch(true, i); break; @@ -4860,9 +4668,7 @@ void EditorNode::make_bottom_panel_item_visible(Control *p_item) { } void EditorNode::raise_bottom_panel_item(Control *p_item) { - for (int i = 0; i < bottom_panel_items.size(); i++) { - if (bottom_panel_items[i].control == p_item) { bottom_panel_items[i].button->raise(); SWAP(bottom_panel_items.write[i], bottom_panel_items.write[bottom_panel_items.size() - 1]); @@ -4877,9 +4683,7 @@ void EditorNode::raise_bottom_panel_item(Control *p_item) { } void EditorNode::remove_bottom_panel_item(Control *p_item) { - for (int i = 0; i < bottom_panel_items.size(); i++) { - if (bottom_panel_items[i].control == p_item) { if (p_item->is_visible_in_tree()) { _bottom_panel_switch(false, i); @@ -4899,7 +4703,6 @@ void EditorNode::remove_bottom_panel_item(Control *p_item) { } void EditorNode::_bottom_panel_switch(bool p_enable, int p_idx) { - ERR_FAIL_INDEX(p_idx, bottom_panel_items.size()); if (bottom_panel_items[p_idx].control->is_visible() == p_enable) { @@ -4908,7 +4711,6 @@ void EditorNode::_bottom_panel_switch(bool p_enable, int p_idx) { if (p_enable) { for (int i = 0; i < bottom_panel_items.size(); i++) { - bottom_panel_items[i].button->set_pressed(i == p_idx); bottom_panel_items[i].control->set_visible(i == p_idx); } @@ -4947,7 +4749,6 @@ bool EditorNode::get_docks_visible() const { } void EditorNode::_toggle_distraction_free_mode() { - if (EditorSettings::get_singleton()->get("interface/editor/separate_distraction_mode")) { int screen = -1; for (int i = 0; i < editor_table.size(); i++) { @@ -4970,7 +4771,6 @@ void EditorNode::_toggle_distraction_free_mode() { } void EditorNode::set_distraction_free_mode(bool p_enter) { - distraction_free->set_pressed(p_enter); if (p_enter) { @@ -4993,7 +4793,6 @@ void EditorNode::add_control_to_dock(DockSlot p_slot, Control *p_control) { } void EditorNode::remove_control_from_dock(Control *p_control) { - Control *dock = nullptr; for (int i = 0; i < DOCK_SLOT_MAX; i++) { if (p_control->get_parent() == dock_slot[i]) { @@ -5009,7 +4808,6 @@ void EditorNode::remove_control_from_dock(Control *p_control) { } Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) { - Control *drag_control = memnew(Control); TextureRect *drag_preview = memnew(TextureRect); Label *label = memnew(Label); @@ -5125,8 +4923,9 @@ void EditorNode::add_tool_submenu_item(const String &p_name, PopupMenu *p_submen void EditorNode::remove_tool_menu_item(const String &p_name) { for (int i = 0; i < tool_menu->get_item_count(); i++) { - if (tool_menu->get_item_id(i) != TOOLS_CUSTOM) + if (tool_menu->get_item_id(i) != TOOLS_CUSTOM) { continue; + } if (tool_menu->get_item_text(i) == p_name) { if (tool_menu->get_item_submenu(i) != "") { @@ -5158,7 +4957,6 @@ void EditorNode::_global_menu_new_window(const Variant &p_tag) { } void EditorNode::_dropped_files(const Vector<String> &p_files, int p_screen) { - String to_path = ProjectSettings::get_singleton()->globalize_path(get_filesystem_dock()->get_selected_path()); _add_dropped_files_recursive(p_files, to_path); @@ -5167,17 +4965,14 @@ void EditorNode::_dropped_files(const Vector<String> &p_files, int p_screen) { } void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, String to_path) { - DirAccessRef dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); Vector<String> just_copy = String("ttf,otf").split(","); for (int i = 0; i < p_files.size(); i++) { - String from = p_files[i]; String to = to_path.plus_file(from.get_file()); if (dir->dir_exists(from)) { - Vector<String> sub_files; DirAccessRef sub_dir = DirAccess::open(from); @@ -5210,19 +5005,16 @@ void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, Str } void EditorNode::_file_access_close_error_notify(const String &p_str) { - add_io_error("Unable to write to file '" + p_str + "', file in use, locked or lacking permissions."); } void EditorNode::reload_scene(const String &p_path) { - //first of all, reload internal textures, materials, meshes, etc. as they might have changed on disk List<Ref<Resource>> cached; ResourceCache::get_cached_resources(&cached); List<Ref<Resource>> to_clear; //clear internal resources from previous scene from being used for (List<Ref<Resource>>::Element *E = cached.front(); E; E = E->next()) { - if (E->get()->get_path().begins_with(p_path + "::")) { //subresources of existing scene to_clear.push_back(E->get()); } @@ -5236,7 +5028,6 @@ void EditorNode::reload_scene(const String &p_path) { int scene_idx = -1; for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { - if (editor_data.get_scene_path(i) == p_path) { scene_idx = i; break; @@ -5275,7 +5066,6 @@ void EditorNode::reload_scene(const String &p_path) { int EditorNode::plugin_init_callback_count = 0; void EditorNode::add_plugin_init_callback(EditorPluginInitializeCallback p_callback) { - ERR_FAIL_COND(plugin_init_callback_count == MAX_INIT_CALLBACKS); plugin_init_callbacks[plugin_init_callback_count++] = p_callback; @@ -5286,7 +5076,6 @@ EditorPluginInitializeCallback EditorNode::plugin_init_callbacks[EditorNode::MAX int EditorNode::build_callback_count = 0; void EditorNode::add_build_callback(EditorBuildCallback p_callback) { - ERR_FAIL_COND(build_callback_count == MAX_INIT_CALLBACKS); build_callbacks[build_callback_count++] = p_callback; @@ -5295,7 +5084,6 @@ void EditorNode::add_build_callback(EditorBuildCallback p_callback) { EditorBuildCallback EditorNode::build_callbacks[EditorNode::MAX_BUILD_CALLBACKS]; bool EditorNode::call_build() { - bool builds_successful = true; for (int i = 0; i < build_callback_count && builds_successful; i++) { @@ -5314,13 +5102,11 @@ bool EditorNode::call_build() { } void EditorNode::_inherit_imported(const String &p_action) { - open_imported->hide(); load_scene(open_import_request, true, true); } void EditorNode::_open_imported() { - load_scene(open_import_request, true, false, true, true); } @@ -5340,7 +5126,6 @@ bool EditorNode::is_editor_dimmed() const { } void EditorNode::open_export_template_manager() { - export_template_manager->popup_manager(); } @@ -5353,7 +5138,6 @@ void EditorNode::remove_resource_conversion_plugin(const Ref<EditorResourceConve } Vector<Ref<EditorResourceConversionPlugin>> EditorNode::find_resource_conversion_plugin(const Ref<Resource> &p_for_resource) { - Vector<Ref<EditorResourceConversionPlugin>> ret; for (int i = 0; i < resource_conversion_plugins.size(); i++) { @@ -5366,12 +5150,10 @@ Vector<Ref<EditorResourceConversionPlugin>> EditorNode::find_resource_conversion } void EditorNode::_bottom_panel_raise_toggled(bool p_pressed) { - top_split->set_visible(!p_pressed); } void EditorNode::_update_video_driver_color() { - // TODO: Probably should de-hardcode this and add to editor settings. if (video_driver->get_text() == "GLES2") { video_driver->add_theme_color_override("font_color", Color::hex(0x5586a4ff)); @@ -5381,7 +5163,6 @@ void EditorNode::_update_video_driver_color() { } void EditorNode::_video_driver_selected(int p_which) { - String driver = video_driver->get_item_metadata(p_which); String current = ""; //OS::get_singleton()->get_video_driver_name(OS::get_singleton()->get_current_video_driver()); @@ -5405,33 +5186,30 @@ void EditorNode::_resource_saved(RES p_resource, const String &p_path) { } void EditorNode::_resource_loaded(RES p_resource, const String &p_path) { - singleton->editor_folding.load_resource_folding(p_resource, p_path); } void EditorNode::_feature_profile_changed() { - Ref<EditorFeatureProfile> profile = feature_profile_manager->get_current_profile(); TabContainer *import_tabs = cast_to<TabContainer>(import_dock->get_parent()); TabContainer *node_tabs = cast_to<TabContainer>(node_dock->get_parent()); TabContainer *fs_tabs = cast_to<TabContainer>(filesystem_dock->get_parent()); if (profile.is_valid()) { - import_tabs->set_tab_hidden(import_dock->get_index(), profile->is_feature_disabled(EditorFeatureProfile::FEATURE_IMPORT_DOCK)); node_tabs->set_tab_hidden(node_dock->get_index(), profile->is_feature_disabled(EditorFeatureProfile::FEATURE_NODE_DOCK)); fs_tabs->set_tab_hidden(filesystem_dock->get_index(), profile->is_feature_disabled(EditorFeatureProfile::FEATURE_FILESYSTEM_DOCK)); main_editor_buttons[EDITOR_3D]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D)); main_editor_buttons[EDITOR_SCRIPT]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT)); - if (StreamPeerSSL::is_available()) + if (StreamPeerSSL::is_available()) { main_editor_buttons[EDITOR_ASSETLIB]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB)); + } if ((profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) && singleton->main_editor_buttons[EDITOR_3D]->is_pressed()) || (profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT) && singleton->main_editor_buttons[EDITOR_SCRIPT]->is_pressed()) || (StreamPeerSSL::is_available() && profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) && singleton->main_editor_buttons[EDITOR_ASSETLIB]->is_pressed())) { _editor_select(EDITOR_2D); } } else { - import_tabs->set_tab_hidden(import_dock->get_index(), false); node_tabs->set_tab_hidden(node_dock->get_index(), false); fs_tabs->set_tab_hidden(filesystem_dock->get_index(), false); @@ -5440,15 +5218,15 @@ void EditorNode::_feature_profile_changed() { filesystem_dock->set_visible(true); main_editor_buttons[EDITOR_3D]->set_visible(true); main_editor_buttons[EDITOR_SCRIPT]->set_visible(true); - if (StreamPeerSSL::is_available()) + if (StreamPeerSSL::is_available()) { main_editor_buttons[EDITOR_ASSETLIB]->set_visible(true); + } } _update_dock_slots_visibility(); } void EditorNode::_bind_methods() { - ClassDB::bind_method("_editor_select", &EditorNode::_editor_select); ClassDB::bind_method("_node_renamed", &EditorNode::_node_renamed); ClassDB::bind_method("edit_node", &EditorNode::edit_node); @@ -5492,7 +5270,6 @@ void EditorNode::_bind_methods() { } static Node *_resource_get_edited_scene() { - return EditorNode::get_singleton()->get_edited_scene(); } @@ -5502,7 +5279,6 @@ void EditorNode::_print_handler(void *p_this, const String &p_string, bool p_err } static void _execute_thread(void *p_ud) { - EditorNode::ExecuteThreadArgs *eta = (EditorNode::ExecuteThreadArgs *)p_ud; Error err = OS::get_singleton()->execute(eta->path, eta->args, true, nullptr, &eta->output, &eta->exitcode, true, &eta->execute_output_mutex); print_verbose("Thread exit status: " + itos(eta->exitcode)); @@ -5514,7 +5290,6 @@ static void _execute_thread(void *p_ud) { } int EditorNode::execute_and_show_output(const String &p_title, const String &p_path, const List<String> &p_arguments, bool p_close_on_ok, bool p_close_on_errors) { - execute_output_dialog->set_title(p_title); execute_output_dialog->get_ok()->set_disabled(true); execute_outputs->clear(); @@ -5563,8 +5338,7 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p } EditorNode::EditorNode() { - - InputFilter::get_singleton()->set_use_accumulated_input(true); + Input::get_singleton()->set_use_accumulated_input(true); Resource::_get_local_scene_func = _resource_get_edited_scene; RenderingServer::get_singleton()->set_debug_generate_wireframes(true); @@ -5580,10 +5354,9 @@ EditorNode::EditorNode() { ResourceLoader::clear_translation_remaps(); //no remaps using during editor ResourceLoader::clear_path_remaps(); - InputFilter *id = InputFilter::get_singleton(); + Input *id = Input::get_singleton(); if (id) { - bool found_touchscreen = false; for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) { if (DisplayServer::get_singleton()->screen_is_touchscreen(i)) { @@ -5591,7 +5364,7 @@ EditorNode::EditorNode() { } } - if (!found_touchscreen && InputFilter::get_singleton()) { + if (!found_touchscreen && Input::get_singleton()) { //only if no touchscreen ui hint, set emulation id->set_emulate_touch_from_mouse(false); //just disable just in case } @@ -5612,8 +5385,9 @@ EditorNode::EditorNode() { TranslationServer::get_singleton()->set_enabled(false); // load settings - if (!EditorSettings::get_singleton()) + if (!EditorSettings::get_singleton()) { EditorSettings::create(); + } FileAccess::set_backup_save(EDITOR_GET("filesystem/on_save/safe_save_on_backup_then_rename")); @@ -5677,7 +5451,7 @@ EditorNode::EditorNode() { import_texture.instance(); ResourceFormatImporter::get_singleton()->add_importer(import_texture); - /* Ref<ResourceImporterLayeredTexture> import_cubemap; + Ref<ResourceImporterLayeredTexture> import_cubemap; import_cubemap.instance(); import_cubemap->set_mode(ResourceImporterLayeredTexture::MODE_CUBEMAP); ResourceFormatImporter::get_singleton()->add_importer(import_cubemap); @@ -5691,7 +5465,12 @@ EditorNode::EditorNode() { import_cubemap_array.instance(); import_cubemap_array->set_mode(ResourceImporterLayeredTexture::MODE_CUBEMAP_ARRAY); ResourceFormatImporter::get_singleton()->add_importer(import_cubemap_array); -*/ + + /*Ref<ResourceImporterLayeredTexture> import_3d; + import_3d.instance(); + import_3d->set_mode(ResourceImporterLayeredTexture::MODE_3D); + ResourceFormatImporter::get_singleton()->add_importer(import_3d);*/ + Ref<ResourceImporterImage> import_image; import_image.instance(); ResourceFormatImporter::get_singleton()->add_importer(import_image); @@ -5716,6 +5495,10 @@ EditorNode::EditorNode() { import_obj.instance(); ResourceFormatImporter::get_singleton()->add_importer(import_obj); + Ref<ResourceImporterShaderFile> import_shader_file; + import_shader_file.instance(); + ResourceFormatImporter::get_singleton()->add_importer(import_shader_file); + Ref<ResourceImporterScene> import_scene; import_scene.instance(); ResourceFormatImporter::get_singleton()->add_importer(import_scene); @@ -6152,7 +5935,7 @@ EditorNode::EditorNode() { p->add_shortcut(ED_SHORTCUT("editor/redo", TTR("Redo"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_Z), EDIT_REDO, true); p->add_separator(); - p->add_shortcut(ED_SHORTCUT("editor/revert_scene", TTR("Revert Scene")), EDIT_REVERT); + p->add_shortcut(ED_SHORTCUT("editor/reload_saved_scene", TTR("Reload Saved Scene")), EDIT_RELOAD_SAVED_SCENE); p->add_shortcut(ED_SHORTCUT("editor/close_scene", TTR("Close Scene"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_W), FILE_CLOSE); recent_scenes = memnew(PopupMenu); @@ -6231,8 +6014,11 @@ EditorNode::EditorNode() { left_menu_hb->add_child(settings_menu); p = settings_menu->get_popup(); - +#ifdef OSX_ENABLED + p->add_shortcut(ED_SHORTCUT("editor/editor_settings", TTR("Editor Settings..."), KEY_MASK_CMD + KEY_COMMA), SETTINGS_PREFERENCES); +#else p->add_shortcut(ED_SHORTCUT("editor/editor_settings", TTR("Editor Settings...")), SETTINGS_PREFERENCES); +#endif p->add_separator(); editor_layouts = memnew(PopupMenu); @@ -6334,7 +6120,7 @@ EditorNode::EditorNode() { run_native = memnew(EditorRunNative); play_hb->add_child(run_native); - run_native->connect("native_run", callable_mp(this, &EditorNode::_menu_option), varray(RUN_PLAY_NATIVE)); + run_native->connect("native_run", callable_mp(this, &EditorNode::_run_native)); play_scene_button = memnew(ToolButton); play_hb->add_child(play_scene_button); @@ -6476,8 +6262,9 @@ EditorNode::EditorNode() { default_layout->set_value(docks_section, "dock_4", "FileSystem"); default_layout->set_value(docks_section, "dock_5", "Inspector,Node"); - for (int i = 0; i < vsplits.size(); i++) + for (int i = 0; i < vsplits.size(); i++) { default_layout->set_value(docks_section, "dock_split_" + itos(i + 1), 0); + } default_layout->set_value(docks_section, "dock_hsplit_1", 0); default_layout->set_value(docks_section, "dock_hsplit_2", 70 * EDSCALE); default_layout->set_value(docks_section, "dock_hsplit_3", -70 * EDSCALE); @@ -6633,6 +6420,7 @@ EditorNode::EditorNode() { add_editor_plugin(VersionControlEditorPlugin::get_singleton()); add_editor_plugin(memnew(ShaderEditorPlugin(this))); + add_editor_plugin(memnew(ShaderFileEditorPlugin(this))); add_editor_plugin(memnew(VisualShaderEditorPlugin(this))); add_editor_plugin(memnew(Camera3DEditorPlugin(this))); @@ -6657,7 +6445,7 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(SpriteFramesEditorPlugin(this))); add_editor_plugin(memnew(TextureRegionEditorPlugin(this))); add_editor_plugin(memnew(GIProbeEditorPlugin(this))); - //add_editor_plugin(memnew(BakedLightmapEditorPlugin(this))); + add_editor_plugin(memnew(BakedLightmapEditorPlugin(this))); add_editor_plugin(memnew(Path2DEditorPlugin(this))); add_editor_plugin(memnew(Path3DEditorPlugin(this))); add_editor_plugin(memnew(Line2DEditorPlugin(this))); @@ -6668,6 +6456,7 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(CollisionShape2DEditorPlugin(this))); add_editor_plugin(memnew(CurveEditorPlugin(this))); add_editor_plugin(memnew(TextureEditorPlugin(this))); + add_editor_plugin(memnew(TextureLayeredEditorPlugin(this))); add_editor_plugin(memnew(AudioStreamEditorPlugin(this))); add_editor_plugin(memnew(AudioBusesEditorPlugin(audio_bus_editor))); add_editor_plugin(memnew(Skeleton3DEditorPlugin(this))); @@ -6676,8 +6465,9 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(MeshEditorPlugin(this))); add_editor_plugin(memnew(MaterialEditorPlugin(this))); - for (int i = 0; i < EditorPlugins::get_plugin_count(); i++) + for (int i = 0; i < EditorPlugins::get_plugin_count(); i++) { add_editor_plugin(EditorPlugins::create(i, this)); + } for (int i = 0; i < plugin_init_callback_count; i++) { plugin_init_callbacks[i](); @@ -6797,8 +6587,9 @@ EditorNode::EditorNode() { pick_main_scene->get_ok()->set_text(TTR("Select")); pick_main_scene->connect("confirmed", callable_mp(this, &EditorNode::_menu_option), varray(SETTINGS_PICK_MAIN_SCENE)); - for (int i = 0; i < _init_callbacks.size(); i++) + for (int i = 0; i < _init_callbacks.size(); i++) { _init_callbacks[i](); + } editor_data.add_edited_scene(-1); editor_data.set_edited_scene(0); @@ -6844,7 +6635,6 @@ EditorNode::EditorNode() { } EditorNode::~EditorNode() { - EditorInspector::cleanup_plugins(); remove_print_handler(&print_handler); @@ -6863,21 +6653,18 @@ EditorNode::~EditorNode() { */ void EditorPluginList::make_visible(bool p_visible) { - for (int i = 0; i < plugins_list.size(); i++) { plugins_list[i]->make_visible(p_visible); } } void EditorPluginList::edit(Object *p_object) { - for (int i = 0; i < plugins_list.size(); i++) { plugins_list[i]->edit(p_object); } } bool EditorPluginList::forward_gui_input(const Ref<InputEvent> &p_event) { - bool discard = false; for (int i = 0; i < plugins_list.size(); i++) { @@ -6906,28 +6693,24 @@ bool EditorPluginList::forward_spatial_gui_input(Camera3D *p_camera, const Ref<I } void EditorPluginList::forward_canvas_draw_over_viewport(Control *p_overlay) { - for (int i = 0; i < plugins_list.size(); i++) { plugins_list[i]->forward_canvas_draw_over_viewport(p_overlay); } } void EditorPluginList::forward_canvas_force_draw_over_viewport(Control *p_overlay) { - for (int i = 0; i < plugins_list.size(); i++) { plugins_list[i]->forward_canvas_force_draw_over_viewport(p_overlay); } } void EditorPluginList::forward_spatial_draw_over_viewport(Control *p_overlay) { - for (int i = 0; i < plugins_list.size(); i++) { plugins_list[i]->forward_spatial_draw_over_viewport(p_overlay); } } void EditorPluginList::forward_spatial_force_draw_over_viewport(Control *p_overlay) { - for (int i = 0; i < plugins_list.size(); i++) { plugins_list[i]->forward_spatial_force_draw_over_viewport(p_overlay); } |