diff options
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 275 |
1 files changed, 154 insertions, 121 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 52f7366dd7..0b96900053 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -31,7 +31,6 @@ #include "editor_node.h" #include "core/config/project_settings.h" -#include "core/extension/native_extension_manager.h" #include "core/input/input.h" #include "core/io/config_file.h" #include "core/io/file_access.h" @@ -134,6 +133,7 @@ #include "editor/plugins/asset_library_editor_plugin.h" #include "editor/plugins/audio_stream_editor_plugin.h" #include "editor/plugins/audio_stream_randomizer_editor_plugin.h" +#include "editor/plugins/bit_map_editor_plugin.h" #include "editor/plugins/camera_3d_editor_plugin.h" #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/collision_polygon_2d_editor_plugin.h" @@ -171,6 +171,7 @@ #include "editor/plugins/physical_bone_3d_editor_plugin.h" #include "editor/plugins/polygon_2d_editor_plugin.h" #include "editor/plugins/polygon_3d_editor_plugin.h" +#include "editor/plugins/ray_cast_2d_editor_plugin.h" #include "editor/plugins/replication_editor_plugin.h" #include "editor/plugins/resource_preloader_editor_plugin.h" #include "editor/plugins/root_motion_editor_plugin.h" @@ -214,12 +215,12 @@ static const String META_TEXT_TO_COPY = "text_to_copy"; void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames) { // Keep track of a list of "index sets," i.e. sets of indices // within disambiguated_scene_names which contain the same name. - Vector<Set<int>> index_sets; - Map<String, int> scene_name_to_set_index; + Vector<RBSet<int>> index_sets; + HashMap<String, int> scene_name_to_set_index; for (int i = 0; i < r_filenames.size(); i++) { String scene_name = r_filenames[i]; if (!scene_name_to_set_index.has(scene_name)) { - index_sets.append(Set<int>()); + index_sets.append(RBSet<int>()); scene_name_to_set_index.insert(r_filenames[i], index_sets.size() - 1); } index_sets.write[scene_name_to_set_index[scene_name]].insert(i); @@ -227,10 +228,10 @@ void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vecto // For each index set with a size > 1, we need to disambiguate. for (int i = 0; i < index_sets.size(); i++) { - Set<int> iset = index_sets[i]; + RBSet<int> iset = index_sets[i]; while (iset.size() > 1) { // Append the parent folder to each scene name. - for (Set<int>::Element *E = iset.front(); E; E = E->next()) { + for (RBSet<int>::Element *E = iset.front(); E; E = E->next()) { int set_idx = E->get(); String scene_name = r_filenames[set_idx]; String full_path = p_full_paths[set_idx]; @@ -265,11 +266,11 @@ void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vecto // Loop back through scene names and remove non-ambiguous names. bool can_proceed = false; - Set<int>::Element *E = iset.front(); + RBSet<int>::Element *E = iset.front(); while (E) { String scene_name = r_filenames[E->get()]; bool duplicate_found = false; - for (Set<int>::Element *F = iset.front(); F; F = F->next()) { + for (RBSet<int>::Element *F = iset.front(); F; F = F->next()) { if (E->get() == F->get()) { continue; } @@ -280,7 +281,7 @@ void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vecto } } - Set<int>::Element *to_erase = duplicate_found ? nullptr : E; + RBSet<int>::Element *to_erase = duplicate_found ? nullptr : E; // We need to check that we could actually append anymore names // if we wanted to for disambiguation. If we can't, then we have @@ -388,7 +389,7 @@ void EditorNode::_update_scene_tabs() { } Rect2 last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1); - int hsep = scene_tabs->get_theme_constant(SNAME("hseparation")); + int hsep = scene_tabs->get_theme_constant(SNAME("h_separation")); if (scene_tabs->is_layout_rtl()) { scene_tab_add->set_position(Point2(last_tab.position.x - scene_tab_add->get_size().x - hsep, last_tab.position.y)); } else { @@ -416,7 +417,7 @@ void EditorNode::_version_control_menu_option(int p_idx) { void EditorNode::_update_title() { const String appname = ProjectSettings::get_singleton()->get("application/config/name"); - String title = (appname.is_empty() ? "Unnamed Project" : appname) + String(" - ") + VERSION_NAME; + String title = (appname.is_empty() ? TTR("Unnamed Project") : appname) + String(" - ") + VERSION_NAME; const String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_scene_file_path() : String(); if (!edited.is_empty()) { // Display the edited scene name before the program name so that it can be seen in the OS task bar. @@ -430,7 +431,7 @@ void EditorNode::_update_title() { DisplayServer::get_singleton()->window_set_title(title); } -void EditorNode::unhandled_input(const Ref<InputEvent> &p_event) { +void EditorNode::shortcut_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventKey> k = p_event; @@ -622,8 +623,6 @@ void EditorNode::_notification(int p_what) { ResourceImporterTexture::get_singleton()->update_imports(); - // if using a main thread only renderer, we need to update the resource previews - EditorResourcePreview::get_singleton()->update(); } break; case NOTIFICATION_ENTER_TREE: { @@ -787,12 +786,12 @@ void EditorNode::_notification(int p_what) { PopupMenu *p = help_menu->get_popup(); p->set_item_icon(p->get_item_index(HELP_SEARCH), gui_base->get_theme_icon(SNAME("HelpSearch"), SNAME("EditorIcons"))); - p->set_item_icon(p->get_item_index(HELP_DOCS), gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); - p->set_item_icon(p->get_item_index(HELP_QA), gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); - p->set_item_icon(p->get_item_index(HELP_REPORT_A_BUG), gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); - p->set_item_icon(p->get_item_index(HELP_SUGGEST_A_FEATURE), gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); - p->set_item_icon(p->get_item_index(HELP_SEND_DOCS_FEEDBACK), gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); - p->set_item_icon(p->get_item_index(HELP_COMMUNITY), gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); + p->set_item_icon(p->get_item_index(HELP_DOCS), gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons"))); + p->set_item_icon(p->get_item_index(HELP_QA), gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons"))); + p->set_item_icon(p->get_item_index(HELP_REPORT_A_BUG), gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons"))); + p->set_item_icon(p->get_item_index(HELP_SUGGEST_A_FEATURE), gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons"))); + p->set_item_icon(p->get_item_index(HELP_SEND_DOCS_FEEDBACK), gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons"))); + p->set_item_icon(p->get_item_index(HELP_COMMUNITY), gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons"))); p->set_item_icon(p->get_item_index(HELP_ABOUT), gui_base->get_theme_icon(SNAME("Godot"), SNAME("EditorIcons"))); p->set_item_icon(p->get_item_index(HELP_SUPPORT_GODOT_DEVELOPMENT), gui_base->get_theme_icon(SNAME("Heart"), SNAME("EditorIcons"))); @@ -801,7 +800,7 @@ void EditorNode::_notification(int p_what) { main_editor_buttons.write[i]->add_theme_font_size_override("font_size", gui_base->get_theme_font_size(SNAME("main_button_font_size"), SNAME("EditorFonts"))); } - Set<String> updated_textfile_extensions; + RBSet<String> updated_textfile_extensions; bool extensions_match = true; const Vector<String> textfile_ext = ((String)(EditorSettings::get_singleton()->get("docks/filesystem/textfile_extensions"))).split(",", false); for (const String &E : textfile_ext) { @@ -908,11 +907,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()) { + for (RBSet<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()) { + for (RBSet<EditorFileDialog *>::Element *E = editor_file_dialogs.front(); E; E = E->next()) { E->get()->invalidate(); } @@ -935,7 +934,7 @@ void EditorNode::_fs_changed() { } if (export_preset.is_null()) { - DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (da->file_exists("res://export_presets.cfg")) { export_error = vformat( "Invalid export preset name: %s.\nThe following presets were detected in this project's `export_presets.cfg`:\n\n", @@ -1058,7 +1057,7 @@ void EditorNode::_scan_external_changes() { // Check if any edited scene has changed. for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { - DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (editor_data.get_scene_path(i) == "" || !da->file_exists(editor_data.get_scene_path(i))) { continue; } @@ -1176,7 +1175,7 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d Error err; - RES res; + Ref<Resource> res; if (ResourceLoader::exists(p_resource, "")) { res = ResourceLoader::load(p_resource, "", ResourceFormatLoader::CACHE_MODE_REUSE, &err); } else if (textfile_extensions.has(p_resource.get_extension())) { @@ -1186,7 +1185,7 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d if (!p_ignore_broken_deps && dependency_errors.has(p_resource)) { Vector<String> errors; - for (Set<String>::Element *E = dependency_errors[p_resource].front(); E; E = E->next()) { + for (RBSet<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); @@ -1418,7 +1417,7 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { ERR_FAIL_COND_MSG(err != OK, "Cannot save config file to '" + path + "'."); } -bool EditorNode::_find_and_save_resource(RES p_res, Map<RES, bool> &processed, int32_t flags) { +bool EditorNode::_find_and_save_resource(Ref<Resource> p_res, HashMap<Ref<Resource>, bool> &processed, int32_t flags) { if (p_res.is_null()) { return false; } @@ -1444,7 +1443,7 @@ bool EditorNode::_find_and_save_resource(RES p_res, Map<RES, bool> &processed, i } } -bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> &processed, int32_t flags) { +bool EditorNode::_find_and_save_edited_subresources(Object *obj, HashMap<Ref<Resource>, bool> &processed, int32_t flags) { bool ret_changed = false; List<PropertyInfo> pi; obj->get_property_list(&pi); @@ -1455,7 +1454,7 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> switch (E.type) { case Variant::OBJECT: { - RES res = obj->get(E.name); + Ref<Resource> res = obj->get(E.name); if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; @@ -1467,7 +1466,7 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> int len = varray.size(); for (int i = 0; i < len; i++) { const Variant &v = varray.get(i); - RES res = v; + Ref<Resource> res = v; if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; } @@ -1480,7 +1479,7 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> d.get_key_list(&keys); for (const Variant &F : keys) { Variant v = d[F]; - RES res = v; + Ref<Resource> res = v; if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; } @@ -1494,7 +1493,7 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> return ret_changed; } -void EditorNode::_save_edited_subresources(Node *scene, Map<RES, bool> &processed, int32_t flags) { +void EditorNode::_save_edited_subresources(Node *scene, HashMap<Ref<Resource>, bool> &processed, int32_t flags) { _find_and_save_edited_subresources(scene, processed, flags); for (int i = 0; i < scene->get_child_count(); i++) { @@ -1623,7 +1622,7 @@ bool EditorNode::_validate_scene_recursive(const String &p_filename, Node *p_nod return false; } -static bool _find_edited_resources(const Ref<Resource> &p_resource, Set<Ref<Resource>> &edited_resources) { +static bool _find_edited_resources(const Ref<Resource> &p_resource, RBSet<Ref<Resource>> &edited_resources) { if (p_resource->is_edited()) { edited_resources.insert(p_resource); return true; @@ -1635,7 +1634,7 @@ static bool _find_edited_resources(const Ref<Resource> &p_resource, Set<Ref<Reso for (const PropertyInfo &E : plist) { if (E.type == Variant::OBJECT && E.usage & PROPERTY_USAGE_STORAGE && !(E.usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT)) { - RES res = p_resource->get(E.name); + Ref<Resource> res = p_resource->get(E.name); if (res.is_null()) { continue; } @@ -1660,7 +1659,7 @@ int EditorNode::_save_external_resources() { } flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; - Set<Ref<Resource>> edited_subresources; + RBSet<Ref<Resource>> edited_subresources; int saved = 0; List<Ref<Resource>> cached; ResourceCache::get_cached_resources(&cached); @@ -1678,7 +1677,7 @@ int EditorNode::_save_external_resources() { // Clear later, because user may have put the same subresource in two different resources, // which will be shared until the next reload. - for (Set<Ref<Resource>>::Element *E = edited_subresources.front(); E; E = E->next()) { + for (RBSet<Ref<Resource>>::Element *E = edited_subresources.front(); E; E = E->next()) { Ref<Resource> res = E->get(); res->set_edited(false); } @@ -1881,7 +1880,7 @@ void EditorNode::_dialog_action(String p_file) { ProjectSettings::get_singleton()->save(); // TODO: Would be nice to show the project manager opened with the highlighted field. - if (pick_main_scene->has_meta("from_native") && (bool)pick_main_scene->get_meta("from_native")) { + if ((bool)pick_main_scene->get_meta("from_native", false)) { run_native->resume_run_native(); } else { _run(false, ""); // Automatically run the project. @@ -2041,7 +2040,7 @@ bool EditorNode::item_has_editor(Object *p_object) { return editor_data.get_subeditors(p_object).size() > 0; } -void EditorNode::edit_item_resource(RES p_resource) { +void EditorNode::edit_item_resource(Ref<Resource> p_resource) { edit_item(p_resource.ptr()); } @@ -2126,7 +2125,7 @@ void EditorNode::_save_default_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; + HashMap<Ref<Resource>, bool> processed; _find_and_save_edited_subresources(fallback.ptr(), processed, 0); save_resource_in_path(fallback, fallback->get_path()); } @@ -2164,7 +2163,7 @@ 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; - RES res = Object::cast_to<Resource>(current_obj); + Ref<Resource> 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. @@ -2304,7 +2303,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { if (main_plugin) { // Special case if use of external editor is true. Resource *current_res = Object::cast_to<Resource>(current_obj); - if (main_plugin->get_name() == "Script" && current_obj->is_class("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 (main_plugin->get_name() == "Script" && !current_obj->is_class("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); } @@ -2658,25 +2657,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { 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; - } - - List<String> extensions; - Ref<MeshLibrary> ml(memnew(MeshLibrary)); - ResourceSaver::get_recognized_extensions(ml, &extensions); - file_export_lib->clear_filters(); - for (const String &E : extensions) { - file_export_lib->add_filter("*." + E); - } - - file_export_lib->popup_file_dialog(); - file_export_lib->set_title(TTR("Export Mesh Library")); - - } break; - case FILE_EXTERNAL_OPEN_SCENE: { if (unsaved_cache && !p_confirmed) { confirmation->get_ok_button()->set_text(TTR("Open")); @@ -3020,6 +3000,40 @@ void EditorNode::_tool_menu_option(int p_idx) { } } +void EditorNode::_export_as_menu_option(int p_idx) { + if (p_idx == 0) { // MeshLibrary + current_menu_option = 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")); + return; + } + + List<String> extensions; + Ref<MeshLibrary> ml(memnew(MeshLibrary)); + ResourceSaver::get_recognized_extensions(ml, &extensions); + file_export_lib->clear_filters(); + for (const String &E : extensions) { + file_export_lib->add_filter("*." + E); + } + + file_export_lib->popup_file_dialog(); + file_export_lib->set_title(TTR("Export Mesh Library")); + } else { // Custom menu options added by plugins + if (export_as_menu->get_item_submenu(p_idx).is_empty()) { // If not a submenu + Callable callback = export_as_menu->get_item_metadata(p_idx); + Callable::CallError ce; + Variant result; + callback.call(nullptr, 0, result, ce); + + if (ce.error != Callable::CallError::CALL_OK) { + String err = Variant::get_callable_error_text(callback, nullptr, 0, ce); + ERR_PRINT("Error calling function from export_as menu: " + err); + } + } + } +} + 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)) { @@ -3389,6 +3403,9 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) { } void EditorNode::_remove_scene(int index, bool p_change_tab) { + // Clear icon cache in case some scripts are no longer needed. + script_icon_cache.clear(); + if (editor_data.get_edited_scene() == index) { // Scene to remove is current scene. _remove_edited_scene(p_change_tab); @@ -3646,7 +3663,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b if (!p_ignore_broken_deps && dependency_errors.has(lpath)) { current_menu_option = -1; Vector<String> errors; - for (Set<String>::Element *E = dependency_errors[lpath].front(); E; E = E->next()) { + for (RBSet<String>::Element *E = dependency_errors[lpath].front(); E; E = E->next()) { errors.push_back(E->get()); } dependency_error->show(DependencyErrorDialog::MODE_SCENE, lpath, errors); @@ -3661,9 +3678,9 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b dependency_errors.erase(lpath); // At least not self path. - for (KeyValue<String, Set<String>> &E : dependency_errors) { + for (KeyValue<String, RBSet<String>> &E : dependency_errors) { String txt = vformat(TTR("Scene '%s' has broken dependencies:"), E.key) + "\n"; - for (Set<String>::Element *F = E.value.front(); F; F = F->next()) { + for (RBSet<String>::Element *F = E.value.front(); F; F = F->next()) { txt += "\t" + F->get() + "\n"; } add_io_error(txt); @@ -3745,7 +3762,7 @@ void EditorNode::open_request(const String &p_path) { load_scene(p_path); // As it will be opened in separate tab. } -void EditorNode::edit_foreign_resource(RES p_resource) { +void EditorNode::edit_foreign_resource(Ref<Resource> p_resource) { load_scene(p_resource->get_path().get_slice("::", 0)); InspectorDock::get_singleton()->call_deferred("edit_resource", p_resource); } @@ -3854,7 +3871,7 @@ 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; + EditorNode *en = static_cast<EditorNode *>(p_ud); en->load_errors->add_image(en->gui_base->get_theme_icon(SNAME("Error"), SNAME("EditorIcons"))); en->load_errors->add_text(p_text + "\n"); en->load_error_dialog->popup_centered_ratio(0.5); @@ -3925,12 +3942,9 @@ void EditorNode::register_editor_types() { GDREGISTER_CLASS(EditorScenePostImport); GDREGISTER_CLASS(EditorCommandPalette); GDREGISTER_CLASS(EditorDebuggerPlugin); - - NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_EDITOR); } void EditorNode::unregister_editor_types() { - NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_EDITOR); _init_callbacks.clear(); if (EditorPaths::get_singleton()) { EditorPaths::free(); @@ -4042,7 +4056,7 @@ void EditorNode::_pick_main_scene_custom_action(const String &p_custom_action_na } } -Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String &p_fallback) const { +Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String &p_fallback) { ERR_FAIL_COND_V(!p_object || !gui_base, nullptr); Ref<Script> script = p_object->get_script(); @@ -4050,13 +4064,14 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String script = p_object; } - if (script.is_valid()) { + if (script.is_valid() && !script_icon_cache.has(script)) { Ref<Script> base_script = script; while (base_script.is_valid()) { StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path()); String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name); Ref<ImageTexture> icon = _load_custom_class_icon(icon_path); if (icon.is_valid()) { + script_icon_cache[script] = icon; return icon; } @@ -4066,12 +4081,18 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String const Vector<EditorData::CustomType> &types = EditorNode::get_editor_data().get_custom_types()[base]; for (int i = 0; i < types.size(); ++i) { if (types[i].script == base_script && types[i].icon.is_valid()) { + script_icon_cache[script] = types[i].icon; return types[i].icon; } } } base_script = base_script->get_base_script(); } + + // If no icon found, cache it as null. + script_icon_cache[script] = Ref<Texture>(); + } else if (script.is_valid() && script_icon_cache.has(script) && script_icon_cache[script].is_valid()) { + return script_icon_cache[script]; } // TODO: Should probably be deprecated in 4.x. @@ -4094,26 +4115,35 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p ERR_FAIL_COND_V_MSG(p_class.is_empty(), nullptr, "Class name cannot be empty."); if (ScriptServer::is_global_class(p_class)) { - Ref<ImageTexture> icon; - Ref<Script> script = EditorNode::get_editor_data().script_class_load_script(p_class); - StringName name = p_class; - - while (script.is_valid()) { - name = EditorNode::get_editor_data().script_class_get_name(script->get_path()); - String current_icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name); - icon = _load_custom_class_icon(current_icon_path); - if (icon.is_valid()) { - return icon; - } - script = script->get_base_script(); - } + String class_name = p_class; + Ref<Script> script = EditorNode::get_editor_data().script_class_load_script(class_name); - if (icon.is_null()) { - icon = gui_base->get_theme_icon(ScriptServer::get_global_class_base(name), SNAME("EditorIcons")); + while (true) { + String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(class_name); + Ref<Texture> icon = _load_custom_class_icon(icon_path); + if (icon.is_valid()) { + return icon; // Current global class has icon. + } + + // Find next global class along the inheritance chain. + do { + Ref<Script> base_script = script->get_base_script(); + if (base_script.is_null()) { + // We've reached a native class, use its icon. + String base_type; + script->get_language()->get_global_class_name(script->get_path(), &base_type); + if (gui_base->has_theme_icon(base_type, "EditorIcons")) { + return gui_base->get_theme_icon(base_type, "EditorIcons"); + } + return gui_base->get_theme_icon(p_fallback, "EditorIcons"); + } + script = base_script; + class_name = EditorNode::get_editor_data().script_class_get_name(script->get_path()); + } while (class_name.is_empty()); } } - const Map<String, Vector<EditorData::CustomType>> &p_map = EditorNode::get_editor_data().get_custom_types(); + const HashMap<String, Vector<EditorData::CustomType>> &p_map = EditorNode::get_editor_data().get_custom_types(); for (const KeyValue<String, Vector<EditorData::CustomType>> &E : p_map) { const Vector<EditorData::CustomType> &ct = E.value; for (int i = 0; i < ct.size(); ++i) { @@ -4261,7 +4291,7 @@ void EditorNode::_copy_warning(const String &p_str) { void EditorNode::_dock_floating_close_request(Control *p_control) { // Through the MarginContainer to the Window. - Window *window = (Window *)p_control->get_parent()->get_parent(); + Window *window = static_cast<Window *>(p_control->get_parent()->get_parent()); int window_slot = window->get_meta("dock_slot"); p_control->get_parent()->remove_child(p_control); @@ -5465,6 +5495,10 @@ void EditorNode::remove_tool_menu_item(const String &p_name) { } } +PopupMenu *EditorNode::get_export_as_menu() { + return export_as_menu; +} + void EditorNode::_global_menu_scene(const Variant &p_tag) { int idx = (int)p_tag; scene_tabs->set_current_tab(idx); @@ -5478,7 +5512,7 @@ void EditorNode::_global_menu_new_window(const Variant &p_tag) { } } -void EditorNode::_dropped_files(const Vector<String> &p_files, int p_screen) { +void EditorNode::_dropped_files(const Vector<String> &p_files) { String to_path = ProjectSettings::get_singleton()->globalize_path(FileSystemDock::get_singleton()->get_selected_path()); _add_dropped_files_recursive(p_files, to_path); @@ -5487,7 +5521,7 @@ 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); + Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); for (int i = 0; i < p_files.size(); i++) { String from = p_files[i]; @@ -5496,7 +5530,7 @@ void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, Str if (dir->dir_exists(from)) { Vector<String> sub_files; - DirAccessRef sub_dir = DirAccess::open(from); + Ref<DirAccess> sub_dir = DirAccess::open(from); sub_dir->list_dir_begin(); String next_file = sub_dir->get_next(); @@ -5669,7 +5703,7 @@ void EditorNode::_rendering_driver_selected(int p_which) { _update_rendering_driver_color(); } -void EditorNode::_resource_saved(RES p_resource, const String &p_path) { +void EditorNode::_resource_saved(Ref<Resource> p_resource, const String &p_path) { if (EditorFileSystem::get_singleton()) { EditorFileSystem::get_singleton()->update_file(p_path); } @@ -5677,7 +5711,7 @@ void EditorNode::_resource_saved(RES p_resource, const String &p_path) { singleton->editor_folding.save_resource_folding(p_resource, p_path); } -void EditorNode::_resource_loaded(RES p_resource, const String &p_path) { +void EditorNode::_resource_loaded(Ref<Resource> p_resource, const String &p_path) { singleton->editor_folding.load_resource_folding(p_resource, p_path); } @@ -5773,7 +5807,7 @@ static Node *_resource_get_edited_scene() { } void EditorNode::_print_handler(void *p_this, const String &p_string, bool p_error) { - EditorNode *en = (EditorNode *)p_this; + EditorNode *en = static_cast<EditorNode *>(p_this); en->log->add_message(p_string, p_error ? EditorLog::MSG_TYPE_ERROR : EditorLog::MSG_TYPE_STD); } @@ -5860,6 +5894,7 @@ EditorNode::EditorNode() { SceneState::set_disable_placeholders(true); ResourceLoader::clear_translation_remaps(); // Using no remaps if in editor. ResourceLoader::clear_path_remaps(); + ResourceLoader::set_create_missing_resources_if_class_unavailable(true); Input *id = Input::get_singleton(); @@ -5875,11 +5910,10 @@ EditorNode::EditorNode() { // Only if no touchscreen ui hint, disable emulation just in case. id->set_emulate_touch_from_mouse(false); } - DisplayServer::get_singleton()->cursor_set_custom_image(RES()); + DisplayServer::get_singleton()->cursor_set_custom_image(Ref<Resource>()); } singleton = this; - last_checked_version = 0; TranslationServer::get_singleton()->set_enabled(false); // Load settings. @@ -5997,18 +6031,22 @@ EditorNode::EditorNode() { import_scene.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_scene); + Ref<ResourceImporterScene> import_animation; + import_animation = Ref<ResourceImporterScene>(memnew(ResourceImporterScene(true))); + ResourceFormatImporter::get_singleton()->add_importer(import_animation); + { Ref<EditorSceneFormatImporterCollada> import_collada; import_collada.instantiate(); - import_scene->add_importer(import_collada); + ResourceImporterScene::add_importer(import_collada); Ref<EditorOBJImporter> import_obj2; import_obj2.instantiate(); - import_scene->add_importer(import_obj2); + ResourceImporterScene::add_importer(import_obj2); Ref<EditorSceneFormatImporterESCN> import_escn; import_escn.instantiate(); - import_scene->add_importer(import_escn); + ResourceImporterScene::add_importer(import_escn); } Ref<ResourceImporterBitMap> import_bitmap; @@ -6229,8 +6267,6 @@ EditorNode::EditorNode() { dock_vb->add_child(dock_float); dock_select_popup->reset_size(); - dock_select_rect_over_idx = -1; - dock_popup_selected_idx = -1; for (int i = 0; i < DOCK_SLOT_MAX; i++) { dock_slot[i]->set_custom_minimum_size(Size2(170, 0) * EDSCALE); @@ -6435,12 +6471,12 @@ EditorNode::EditorNode() { p->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/quick_open_script", TTR("Quick Open Script..."), KeyModifierMask::CMD + KeyModifierMask::ALT + Key::O), FILE_QUICK_OPEN_SCRIPT); p->add_separator(); - PopupMenu *pm_export = memnew(PopupMenu); - pm_export->set_name("Export"); - p->add_child(pm_export); - p->add_submenu_item(TTR("Convert To..."), "Export"); - pm_export->add_shortcut(ED_SHORTCUT("editor/convert_to_MeshLibrary", TTR("MeshLibrary...")), FILE_EXPORT_MESH_LIBRARY); - pm_export->connect("id_pressed", callable_mp(this, &EditorNode::_menu_option)); + export_as_menu = memnew(PopupMenu); + export_as_menu->set_name("Export"); + p->add_child(export_as_menu); + p->add_submenu_item(TTR("Export As..."), "Export"); + export_as_menu->add_shortcut(ED_SHORTCUT("editor/export_as_mesh_library", TTR("MeshLibrary...")), FILE_EXPORT_MESH_LIBRARY); + export_as_menu->connect("index_pressed", callable_mp(this, &EditorNode::_export_as_menu_option)); p->add_separator(); p->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO, true); @@ -6579,12 +6615,12 @@ EditorNode::EditorNode() { ED_SHORTCUT_OVERRIDE("editor/editor_help", "macos", KeyModifierMask::ALT | Key::SPACE); p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("HelpSearch"), SNAME("EditorIcons")), ED_GET_SHORTCUT("editor/editor_help"), HELP_SEARCH); p->add_separator(); - p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/online_docs", TTR("Online Documentation")), HELP_DOCS); - p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/q&a", TTR("Questions & Answers")), HELP_QA); - p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/report_a_bug", TTR("Report a Bug")), HELP_REPORT_A_BUG); - p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/suggest_a_feature", TTR("Suggest a Feature")), HELP_SUGGEST_A_FEATURE); - p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/send_docs_feedback", TTR("Send Docs Feedback")), HELP_SEND_DOCS_FEEDBACK); - p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/community", TTR("Community")), HELP_COMMUNITY); + p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/online_docs", TTR("Online Documentation")), HELP_DOCS); + p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/q&a", TTR("Questions & Answers")), HELP_QA); + p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/report_a_bug", TTR("Report a Bug")), HELP_REPORT_A_BUG); + p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/suggest_a_feature", TTR("Suggest a Feature")), HELP_SUGGEST_A_FEATURE); + p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/send_docs_feedback", TTR("Send Docs Feedback")), HELP_SEND_DOCS_FEEDBACK); + p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/community", TTR("Community")), HELP_COMMUNITY); p->add_separator(); p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("Godot"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/about", TTR("About Godot")), HELP_ABOUT); p->add_icon_shortcut(gui_base->get_theme_icon(SNAME("Heart"), SNAME("EditorIcons")), ED_SHORTCUT_AND_COMMAND("editor/support_development", TTR("Support Godot Development")), HELP_SUPPORT_GODOT_DEVELOPMENT); @@ -6777,7 +6813,6 @@ EditorNode::EditorNode() { // Define corresponding default layout. const String docks_section = "docks"; - overridden_default_layout = -1; default_layout.instantiate(); // Dock numbers are based on DockSlot enum value + 1. default_layout->set_value(docks_section, "dock_3", "Scene,Import"); @@ -6856,8 +6891,6 @@ EditorNode::EditorNode() { Button *output_button = add_bottom_panel_item(TTR("Output"), log); log->set_tool_button(output_button); - old_split_ofs = 0; - center_split->connect("resized", callable_mp(this, &EditorNode::_vp_resized)); native_shader_source_visualizer = memnew(EditorNativeShaderSourceVisualizer); @@ -7062,6 +7095,8 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(TextControlEditorPlugin)); add_editor_plugin(memnew(ControlEditorPlugin)); add_editor_plugin(memnew(GradientTexture2DEditorPlugin)); + add_editor_plugin(memnew(BitMapEditorPlugin)); + add_editor_plugin(memnew(RayCast2DEditorPlugin)); for (int i = 0; i < EditorPlugins::get_plugin_count(); i++) { add_editor_plugin(EditorPlugins::create(i)); @@ -7080,6 +7115,7 @@ EditorNode::EditorNode() { resource_preview->add_preview_generator(Ref<EditorMeshPreviewPlugin>(memnew(EditorMeshPreviewPlugin))); resource_preview->add_preview_generator(Ref<EditorBitmapPreviewPlugin>(memnew(EditorBitmapPreviewPlugin))); resource_preview->add_preview_generator(Ref<EditorFontPreviewPlugin>(memnew(EditorFontPreviewPlugin))); + resource_preview->add_preview_generator(Ref<EditorGradientPreviewPlugin>(memnew(EditorGradientPreviewPlugin))); { Ref<StandardMaterial3DConversionPlugin> spatial_mat_convert; @@ -7120,7 +7156,6 @@ EditorNode::EditorNode() { } update_spinner_step_msec = OS::get_singleton()->get_ticks_msec(); update_spinner_step_frame = Engine::get_singleton()->get_frames_drawn(); - update_spinner_step = 0; editor_plugin_screen = nullptr; editor_plugins_over = memnew(EditorPluginList); @@ -7154,9 +7189,6 @@ EditorNode::EditorNode() { open_imported->connect("custom_action", callable_mp(this, &EditorNode::_inherit_imported)); gui_base->add_child(open_imported); - saved_version = 1; - _last_instantiated_scene = nullptr; - quick_open = memnew(EditorQuickOpen); gui_base->add_child(quick_open); quick_open->connect("quick_open", callable_mp(this, &EditorNode::_quick_opened)); @@ -7168,7 +7200,7 @@ EditorNode::EditorNode() { _update_recent_scenes(); editor_data.restore_editor_global_states(); - set_process_unhandled_input(true); + set_process_shortcut_input(true); load_errors = memnew(RichTextLabel); load_error_dialog = memnew(AcceptDialog); @@ -7245,6 +7277,7 @@ EditorNode::EditorNode() { EditorNode::~EditorNode() { EditorInspector::cleanup_plugins(); EditorTranslationParser::get_singleton()->clean_parsers(); + ResourceImporterScene::clean_up_importer_plugins(); remove_print_handler(&print_handler); EditorHelp::cleanup_doc(); |