diff options
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 97 |
1 files changed, 53 insertions, 44 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 3f20734e3f..cca8bc1b29 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -477,6 +477,7 @@ void EditorNode::_update_from_settings() { RS::get_singleton()->environment_set_ssao_quality(RS::EnvironmentSSAOQuality(int(GLOBAL_GET("rendering/environment/ssao/quality"))), GLOBAL_GET("rendering/environment/ssao/half_size"), GLOBAL_GET("rendering/environment/ssao/adaptive_target"), GLOBAL_GET("rendering/environment/ssao/blur_passes"), GLOBAL_GET("rendering/environment/ssao/fadeout_from"), GLOBAL_GET("rendering/environment/ssao/fadeout_to")); RS::get_singleton()->screen_space_roughness_limiter_set_active(GLOBAL_GET("rendering/anti_aliasing/screen_space_roughness_limiter/enabled"), GLOBAL_GET("rendering/anti_aliasing/screen_space_roughness_limiter/amount"), GLOBAL_GET("rendering/anti_aliasing/screen_space_roughness_limiter/limit")); bool glow_bicubic = int(GLOBAL_GET("rendering/environment/glow/upscale_mode")) > 0; + RS::get_singleton()->environment_set_ssil_quality(RS::EnvironmentSSILQuality(int(GLOBAL_GET("rendering/environment/ssil/quality"))), GLOBAL_GET("rendering/environment/ssil/half_size"), GLOBAL_GET("rendering/environment/ssil/adaptive_target"), GLOBAL_GET("rendering/environment/ssil/blur_passes"), GLOBAL_GET("rendering/environment/ssil/fadeout_from"), GLOBAL_GET("rendering/environment/ssil/fadeout_to")); RS::get_singleton()->environment_glow_set_use_bicubic_upscale(glow_bicubic); bool glow_high_quality = GLOBAL_GET("rendering/environment/glow/use_high_quality"); RS::get_singleton()->environment_glow_set_use_high_quality(glow_high_quality); @@ -521,8 +522,8 @@ void EditorNode::_update_from_settings() { Viewport::SDFScale sdf_scale = Viewport::SDFScale(int(GLOBAL_GET("rendering/2d/sdf/scale"))); scene_root->set_sdf_scale(sdf_scale); - float lod_threshold = GLOBAL_GET("rendering/mesh_lod/lod_change/threshold_pixels"); - scene_root->set_lod_threshold(lod_threshold); + float mesh_lod_threshold = GLOBAL_GET("rendering/mesh_lod/lod_change/threshold_pixels"); + scene_root->set_mesh_lod_threshold(mesh_lod_threshold); RS::get_singleton()->decals_set_filter(RS::DecalFilter(int(GLOBAL_GET("rendering/textures/decals/filter")))); RS::get_singleton()->light_projectors_set_filter(RS::LightProjectorFilter(int(GLOBAL_GET("rendering/textures/light_projectors/filter")))); @@ -858,7 +859,7 @@ void EditorNode::_resources_changed(const Vector<String> &p_resources) { continue; } - if (res->get_import_path() != String()) { + if (!res->get_import_path().is_empty()) { // this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback continue; } @@ -886,7 +887,7 @@ void EditorNode::_fs_changed() { // FIXME: Move this to a cleaner location, it's hacky to do this is _fs_changed. String export_error; - if (export_defer.preset != "" && !EditorFileSystem::get_singleton()->is_scanning()) { + if (!export_defer.preset.is_empty() && !EditorFileSystem::get_singleton()->is_scanning()) { String preset_name = export_defer.preset; // Ensures export_project does not loop infinitely, because notifications may // come during the export. @@ -1006,7 +1007,7 @@ void EditorNode::_sources_changed(bool p_exist) { _load_docks(); - if (defer_load_scene != "") { + if (!defer_load_scene.is_empty()) { load_scene(defer_load_scene); defer_load_scene = ""; } @@ -1242,7 +1243,7 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String preferred.move_to_front(tres_element); } - if (p_at_path != String()) { + if (!p_at_path.is_empty()) { 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()); @@ -1254,7 +1255,7 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String file->set_current_file(String()); } } - } else if (p_resource->get_path() != "") { + } else if (!p_resource->get_path().is_empty()) { file->set_current_path(p_resource->get_path()); if (extensions.size()) { String ext = p_resource->get_path().get_extension().to_lower(); @@ -1676,7 +1677,7 @@ void EditorNode::_save_scene(String p_file, int idx) { return; } - if (scene->get_scene_file_path() != String() && _validate_scene_recursive(scene->get_scene_file_path(), scene)) { + if (!scene->get_scene_file_path().is_empty() && _validate_scene_recursive(scene->get_scene_file_path(), scene)) { show_accept(TTR("This scene can't be saved because there is a cyclic instancing inclusion.\nPlease resolve it and then attempt to save again."), TTR("OK")); return; } @@ -1780,7 +1781,7 @@ void EditorNode::restart_editor() { args.push_back("--path"); args.push_back(ProjectSettings::get_singleton()->get_resource_path()); args.push_back("-e"); - if (to_reopen != String()) { + if (!to_reopen.is_empty()) { args.push_back(to_reopen); } @@ -1792,13 +1793,13 @@ 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) { - if (scene->get_scene_file_path() != "" && DirAccess::exists(scene->get_scene_file_path().get_base_dir())) { + if (!scene->get_scene_file_path().is_empty() && DirAccess::exists(scene->get_scene_file_path().get_base_dir())) { if (i != editor_data.get_edited_scene()) { _save_scene(scene->get_scene_file_path(), i); } else { _save_scene_with_preview(scene->get_scene_file_path()); } - } else if (scene->get_scene_file_path() != "") { + } else if (!scene->get_scene_file_path().is_empty()) { all_saved = false; } } @@ -1818,7 +1819,7 @@ void EditorNode::_mark_unsaved_scenes() { } String path = node->get_scene_file_path(); - if (!(path == String() || FileAccess::exists(path))) { + if (!(path.is_empty() || FileAccess::exists(path))) { if (i == editor_data.get_edited_scene()) { set_current_version(-1); } else { @@ -2080,7 +2081,7 @@ void EditorNode::push_item(Object *p_object, const String &p_property, bool p_in 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.is_empty()) { editor_history.add_object(id); } else { editor_history.add_object(id, p_property); @@ -2128,11 +2129,19 @@ static bool overrides_external_editor(Object *p_object) { return script->get_language()->overrides_external_editor(); } -void EditorNode::_edit_current() { +void EditorNode::_edit_current(bool p_skip_foreign) { 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(); + RES res = Object::cast_to<Resource>(current_obj); + if (p_skip_foreign && res.is_valid()) { + if (res->get_path().find("::") > -1 && res->get_path().get_slice("::", 0) != editor_data.get_scene_path(get_current_tab())) { + // Trying to edit resource that belongs to another scene; abort. + current_obj = nullptr; + } + } + + bool inspector_only = editor_history.is_current_inspector_only(); this->current = current_obj; if (!current_obj) { @@ -2193,7 +2202,7 @@ void EditorNode::_edit_current() { inspector_dock->update(nullptr); } - if (get_edited_scene() && get_edited_scene()->get_scene_file_path() != String()) { + if (get_edited_scene() && !get_edited_scene()->get_scene_file_path().is_empty()) { String source_scene = get_edited_scene()->get_scene_file_path(); if (FileAccess::exists(source_scene + ".import")) { editable_warning = TTR("This scene was imported, so changes to it won't be kept.\nInstancing it or inheriting will allow making changes to it.\nPlease read the documentation relevant to importing scenes to better understand this workflow."); @@ -2263,8 +2272,8 @@ void EditorNode::_edit_current() { if (main_plugin) { // special case if use of external editor is true - Resource *res = Object::cast_to<Resource>(current_obj); - if (main_plugin->get_name() == "Script" && current_obj->get_class_name() != StringName("VisualScript") && res && !res->is_built_in() && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) { + Resource *current_res = Object::cast_to<Resource>(current_obj); + if (main_plugin->get_name() == "Script" && current_obj->get_class_name() != StringName("VisualScript") && current_res && !current_res->is_built_in() && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) { if (!changing_scene) { main_plugin->edit(current_obj); } @@ -2316,7 +2325,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) { String run_filename; - if (p_current || (editor_data.get_edited_scene_root() && p_custom != String() && p_custom == editor_data.get_edited_scene_root()->get_scene_file_path())) { + if (p_current || (editor_data.get_edited_scene_root() && !p_custom.is_empty() && p_custom == editor_data.get_edited_scene_root()->get_scene_file_path())) { Node *scene = editor_data.get_edited_scene_root(); if (!scene) { @@ -2324,7 +2333,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) { return; } - if (scene->get_scene_file_path() == "") { + if (scene->get_scene_file_path().is_empty()) { current_option = -1; _menu_option(FILE_SAVE_AS_SCENE); // Set the option to save and run so when the dialog is accepted, the scene runs. @@ -2334,11 +2343,11 @@ void EditorNode::_run(bool p_current, const String &p_custom) { } run_filename = scene->get_scene_file_path(); - } else if (p_custom != "") { + } else if (!p_custom.is_empty()) { run_filename = p_custom; } - if (run_filename == "") { + if (run_filename.is_empty()) { // evidently, run the scene if (!ensure_main_scene(false)) { return; @@ -2349,7 +2358,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) { if (unsaved_cache) { Node *scene = editor_data.get_edited_scene_root(); - if (scene && scene->get_scene_file_path() != "") { // Only autosave if there is a scene and if it has a path. + if (scene && !scene->get_scene_file_path().is_empty()) { // Only autosave if there is a scene and if it has a path. _save_scene_with_preview(scene->get_scene_file_path()); } } @@ -2381,7 +2390,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) { if (p_current) { play_scene_button->set_pressed(true); play_scene_button->set_icon(gui_base->get_theme_icon(SNAME("Reload"), SNAME("EditorIcons"))); - } else if (p_custom != "") { + } else if (!p_custom.is_empty()) { run_custom_filename = p_custom; play_custom_scene_button->set_pressed(true); play_custom_scene_button->set_icon(gui_base->get_theme_icon(SNAME("Reload"), SNAME("EditorIcons"))); @@ -2501,7 +2510,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { if (scene_root) { String scene_filename = scene_root->get_scene_file_path(); save_confirmation->get_ok_button()->set_text(TTR("Save & Close")); - save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene_filename != "" ? scene_filename : "unsaved scene")); + save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), !scene_filename.is_empty() ? scene_filename : "unsaved scene")); save_confirmation->popup_centered(); break; } @@ -2519,7 +2528,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { 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_scene_file_path() != "") { + if (scene && !scene->get_scene_file_path().is_empty()) { if (DirAccess::exists(scene->get_scene_file_path().get_base_dir())) { if (scene_idx != editor_data.get_edited_scene()) { _save_scene_with_preview(scene->get_scene_file_path(), scene_idx); @@ -2575,7 +2584,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper()); } - if (scene->get_scene_file_path() != "") { + if (!scene->get_scene_file_path().is_empty()) { String path = scene->get_scene_file_path(); file->set_current_path(path); if (extensions.size()) { @@ -2649,7 +2658,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { if (!editor_data.get_undo_redo().undo()) { log->add_message(TTR("Nothing to undo."), EditorLog::MSG_TYPE_EDITOR); - } else if (action != "") { + } else if (!action.is_empty()) { log->add_message(vformat(TTR("Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR); } } @@ -2676,7 +2685,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { String filename = scene->get_scene_file_path(); - if (filename == String()) { + if (filename.is_empty()) { show_warning(TTR("Can't reload a scene that was never saved.")); break; } @@ -2746,7 +2755,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case FILE_SHOW_IN_FILESYSTEM: { String path = editor_data.get_scene_path(editor_data.get_edited_scene()); - if (path != String()) { + if (!path.is_empty()) { filesystem_dock->navigate_to_path(path); } } break; @@ -3011,7 +3020,7 @@ void EditorNode::_discard_changes(const String &p_str) { Node *scene = editor_data.get_edited_scene_root(tab_closing); if (scene != nullptr) { String scene_filename = scene->get_scene_file_path(); - if (scene_filename != "") { + if (!scene_filename.is_empty()) { previous_scenes.push_back(scene_filename); } } @@ -3138,7 +3147,7 @@ void EditorNode::_editor_select(int p_which) { } void EditorNode::select_editor_by_name(const String &p_name) { - ERR_FAIL_COND(p_name == ""); + ERR_FAIL_COND(p_name.is_empty()); for (int i = 0; i < main_editor_buttons.size(); i++) { if (main_editor_buttons[i]->get_text() == p_name) { @@ -3493,7 +3502,7 @@ void EditorNode::set_current_scene(int p_idx) { } Dictionary state = editor_data.restore_edited_scene_state(editor_selection, &editor_history); - _edit_current(); + _edit_current(true); _update_title(); @@ -4491,13 +4500,13 @@ void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p 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.is_empty()) { names += ","; } names += name; } - if (names != "") { + if (!names.is_empty()) { p_layout->set_value(p_section, "dock_" + itos(i + 1), names); } } @@ -4522,7 +4531,7 @@ void EditorNode::_save_open_scenes_to_config(Ref<ConfigFile> p_layout, const Str Array scenes; for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { String path = editor_data.get_scene_path(i); - if (path == "") { + if (path.is_empty()) { continue; } scenes.push_back(path); @@ -4789,7 +4798,7 @@ bool EditorNode::ensure_main_scene(bool p_from_native) { pick_main_scene->set_meta("from_native", p_from_native); // whether from play button or native run String main_scene = GLOBAL_DEF("application/run/main_scene", ""); - if (main_scene == "") { + if (main_scene.is_empty()) { 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(); @@ -4852,7 +4861,7 @@ bool EditorNode::is_run_playing() const { String EditorNode::get_run_playing_scene() const { String run_filename = editor_run.get_running_scene(); - if (run_filename == "" && is_run_playing()) { + if (run_filename.is_empty() && is_run_playing()) { run_filename = GLOBAL_DEF("application/run/main_scene", ""); // Must be the main scene then. } @@ -4978,7 +4987,7 @@ void EditorNode::_scene_tab_closed(int p_tab, int option) { : editor_data.get_scene_version(p_tab) != 0; if (unsaved) { save_confirmation->get_ok_button()->set_text(TTR("Save & Close")); - save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), scene->get_scene_file_path() != "" ? scene->get_scene_file_path() : "unsaved scene")); + save_confirmation->set_text(vformat(TTR("Save changes to '%s' before closing?"), !scene->get_scene_file_path().is_empty() ? scene->get_scene_file_path() : "unsaved scene")); save_confirmation->popup_centered(); } else { _discard_changes(); @@ -4998,7 +5007,7 @@ void EditorNode::_scene_tab_hovered(int p_tab) { tab_preview_panel->hide(); } else { String path = editor_data.get_scene_path(p_tab); - if (path != String()) { + if (!path.is_empty()) { EditorResourcePreview::get_singleton()->queue_resource_preview(path, this, "_thumbnail_done", p_tab); } } @@ -5307,7 +5316,7 @@ Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) { drag_control->add_child(drag_preview); if (p_res->get_path().is_resource_file()) { label->set_text(p_res->get_path().get_file()); - } else if (p_res->get_name() != "") { + } else if (!p_res->get_name().is_empty()) { label->set_text(p_res->get_name()); } else { label->set_text(p_res->get_class()); @@ -5446,7 +5455,7 @@ void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, Str sub_dir->list_dir_begin(); String next_file = sub_dir->get_next(); - while (next_file != "") { + while (!next_file.is_empty()) { if (next_file == "." || next_file == "..") { next_file = sub_dir->get_next(); continue; |