summaryrefslogtreecommitdiffstats
path: root/editor/editor_node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r--editor/editor_node.cpp192
1 files changed, 167 insertions, 25 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 66fd2cf904..184176391a 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -926,11 +926,7 @@ void EditorNode::_resources_changed(const Vector<String> &p_resources) {
}
if (!res->editor_can_reload_from_file()) {
- Ref<Script> scr = res;
- // Scripts are reloaded via the script editor.
- if (scr.is_null() || ScriptEditor::get_singleton()->get_open_scripts().has(scr)) {
- continue;
- }
+ continue;
}
if (!res->get_path().is_resource_file() && !res->get_path().is_absolute_path()) {
continue;
@@ -3436,6 +3432,98 @@ void EditorNode::_update_file_menu_closed() {
file_menu->set_item_disabled(file_menu->get_item_index(FILE_OPEN_PREV), false);
}
+void EditorNode::replace_resources_in_object(Object *p_object, const Vector<Ref<Resource>> &p_source_resources, const Vector<Ref<Resource>> &p_target_resource) {
+ List<PropertyInfo> pi;
+ p_object->get_property_list(&pi);
+
+ for (const PropertyInfo &E : pi) {
+ if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
+ continue;
+ }
+
+ switch (E.type) {
+ case Variant::OBJECT: {
+ if (E.hint == PROPERTY_HINT_RESOURCE_TYPE) {
+ const Variant &v = p_object->get(E.name);
+ Ref<Resource> res = v;
+
+ if (res.is_valid()) {
+ int res_idx = p_source_resources.find(res);
+ if (res_idx != -1) {
+ p_object->set(E.name, p_target_resource.get(res_idx));
+ } else {
+ replace_resources_in_object(v, p_source_resources, p_target_resource);
+ }
+ }
+ }
+ } break;
+ case Variant::ARRAY: {
+ Array varray = p_object->get(E.name);
+ int len = varray.size();
+ bool array_requires_updating = false;
+ for (int i = 0; i < len; i++) {
+ const Variant &v = varray.get(i);
+ Ref<Resource> res = v;
+
+ if (res.is_valid()) {
+ int res_idx = p_source_resources.find(res);
+ if (res_idx != -1) {
+ varray.set(i, p_target_resource.get(res_idx));
+ array_requires_updating = true;
+ } else {
+ replace_resources_in_object(v, p_source_resources, p_target_resource);
+ }
+ }
+ }
+ if (array_requires_updating) {
+ p_object->set(E.name, varray);
+ }
+ } break;
+ case Variant::DICTIONARY: {
+ Dictionary d = p_object->get(E.name);
+ List<Variant> keys;
+ bool dictionary_requires_updating = false;
+ d.get_key_list(&keys);
+ for (const Variant &F : keys) {
+ Variant v = d[F];
+ Ref<Resource> res = v;
+
+ if (res.is_valid()) {
+ int res_idx = p_source_resources.find(res);
+ if (res_idx != -1) {
+ d[F] = p_target_resource.get(res_idx);
+ dictionary_requires_updating = true;
+ } else {
+ replace_resources_in_object(v, p_source_resources, p_target_resource);
+ }
+ }
+ }
+ if (dictionary_requires_updating) {
+ p_object->set(E.name, d);
+ }
+ } break;
+ default: {
+ }
+ }
+ }
+
+ Node *n = Object::cast_to<Node>(p_object);
+ if (n) {
+ for (int i = 0; i < n->get_child_count(); i++) {
+ replace_resources_in_object(n->get_child(i), p_source_resources, p_target_resource);
+ }
+ }
+}
+
+void EditorNode::replace_resources_in_scenes(const Vector<Ref<Resource>> &p_source_resources, const Vector<Ref<Resource>> &p_target_resource) {
+ for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
+ Node *edited_scene_root = editor_data.get_edited_scene_root(i);
+ if (edited_scene_root) {
+ replace_resources_in_object(edited_scene_root, p_source_resources, p_target_resource);
+ }
+ }
+}
+
void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) {
if (p_editor->has_main_screen()) {
singleton->editor_main_screen->add_main_plugin(p_editor);
@@ -4021,7 +4109,9 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
_update_title();
scene_tabs->update_scene_tabs();
- _add_to_recent_scenes(lpath);
+ if (!restoring_scenes) {
+ _add_to_recent_scenes(lpath);
+ }
return OK;
}
@@ -4862,8 +4952,10 @@ String EditorNode::_get_system_info() const {
godot_version += " " + hash;
}
+ String display_session_type;
#ifdef LINUXBSD_ENABLED
- const String display_server = OS::get_singleton()->get_environment("XDG_SESSION_TYPE").capitalize().replace(" ", ""); // `replace` is necessary, because `capitalize` introduces a whitespace between "x" and "11".
+ // `replace` is necessary, because `capitalize` introduces a whitespace between "x" and "11".
+ display_session_type = OS::get_singleton()->get_environment("XDG_SESSION_TYPE").capitalize().replace(" ", "");
#endif // LINUXBSD_ENABLED
String driver_name = OS::get_singleton()->get_current_rendering_driver_name().to_lower();
String rendering_method = OS::get_singleton()->get_current_rendering_method().to_lower();
@@ -4924,16 +5016,33 @@ String EditorNode::_get_system_info() const {
// Join info.
Vector<String> info;
info.push_back(godot_version);
+ String distribution_display_session_type = distribution_name;
if (!distribution_version.is_empty()) {
- info.push_back(distribution_name + " " + distribution_version);
- } else {
- info.push_back(distribution_name);
+ distribution_display_session_type += " " + distribution_version;
}
-#ifdef LINUXBSD_ENABLED
- if (!display_server.is_empty()) {
- info.push_back(display_server);
+ if (!display_session_type.is_empty()) {
+ distribution_display_session_type += " on " + display_session_type;
}
+ info.push_back(distribution_display_session_type);
+
+ String display_driver_window_mode;
+#ifdef LINUXBSD_ENABLED
+ // `replace` is necessary, because `capitalize` introduces a whitespace between "x" and "11".
+ display_driver_window_mode = DisplayServer::get_singleton()->get_name().capitalize().replace(" ", "") + " display driver";
#endif // LINUXBSD_ENABLED
+ if (!display_driver_window_mode.is_empty()) {
+ display_driver_window_mode += ", ";
+ }
+ display_driver_window_mode += get_viewport()->is_embedding_subwindows() ? "Single-window" : "Multi-window";
+
+ if (DisplayServer::get_singleton()->get_screen_count() == 1) {
+ display_driver_window_mode += ", " + itos(DisplayServer::get_singleton()->get_screen_count()) + " monitor";
+ } else {
+ display_driver_window_mode += ", " + itos(DisplayServer::get_singleton()->get_screen_count()) + " monitors";
+ }
+
+ info.push_back(display_driver_window_mode);
+
info.push_back(vformat("%s (%s)", driver_name, rendering_method));
String graphics;
@@ -4952,7 +5061,7 @@ String EditorNode::_get_system_info() const {
}
info.push_back(graphics);
- info.push_back(vformat("%s (%d Threads)", processor_name, processor_count));
+ info.push_back(vformat("%s (%d threads)", processor_name, processor_count));
return String(" - ").join(info);
}
@@ -5249,14 +5358,18 @@ void EditorNode::_load_open_scenes_from_config(Ref<ConfigFile> p_layout) {
PackedStringArray scenes = p_layout->get_value(EDITOR_NODE_CONFIG_SECTION, "open_scenes");
for (int i = 0; i < scenes.size(); i++) {
- load_scene(scenes[i]);
+ if (FileAccess::exists(scenes[i])) {
+ load_scene(scenes[i]);
+ }
}
if (p_layout->has_section_key(EDITOR_NODE_CONFIG_SECTION, "current_scene")) {
String current_scene = p_layout->get_value(EDITOR_NODE_CONFIG_SECTION, "current_scene");
- int current_scene_idx = scenes.find(current_scene);
- if (current_scene_idx >= 0) {
- _set_current_scene(current_scene_idx);
+ for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
+ if (editor_data.get_scene_path(i) == current_scene) {
+ _set_current_scene(i);
+ break;
+ }
}
}
@@ -5567,6 +5680,7 @@ Dictionary 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);
+ label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
Ref<Texture2D> preview;
@@ -5619,6 +5733,7 @@ Dictionary EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Contro
HBoxContainer *hbox = memnew(HBoxContainer);
TextureRect *icon = memnew(TextureRect);
Label *label = memnew(Label);
+ label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
if (p_paths[i].ends_with("/")) {
label->set_text(p_paths[i].substr(0, p_paths[i].length() - 1).get_file());
@@ -6350,12 +6465,32 @@ void EditorNode::remove_resource_conversion_plugin(const Ref<EditorResourceConve
resource_conversion_plugins.erase(p_plugin);
}
-Vector<Ref<EditorResourceConversionPlugin>> EditorNode::find_resource_conversion_plugin(const Ref<Resource> &p_for_resource) {
+Vector<Ref<EditorResourceConversionPlugin>> EditorNode::find_resource_conversion_plugin_for_resource(const Ref<Resource> &p_for_resource) {
+ if (p_for_resource.is_null()) {
+ return Vector<Ref<EditorResourceConversionPlugin>>();
+ }
+
+ Vector<Ref<EditorResourceConversionPlugin>> ret;
+ for (Ref<EditorResourceConversionPlugin> resource_conversion_plugin : resource_conversion_plugins) {
+ if (resource_conversion_plugin.is_valid() && resource_conversion_plugin->handles(p_for_resource)) {
+ ret.push_back(resource_conversion_plugin);
+ }
+ }
+
+ return ret;
+}
+
+Vector<Ref<EditorResourceConversionPlugin>> EditorNode::find_resource_conversion_plugin_for_type_name(const String &p_type) {
Vector<Ref<EditorResourceConversionPlugin>> ret;
- for (int i = 0; i < resource_conversion_plugins.size(); i++) {
- if (resource_conversion_plugins[i].is_valid() && resource_conversion_plugins[i]->handles(p_for_resource)) {
- ret.push_back(resource_conversion_plugins[i]);
+ if (ClassDB::can_instantiate(p_type)) {
+ Ref<Resource> temp = Object::cast_to<Resource>(ClassDB::instantiate(p_type));
+ if (temp.is_valid()) {
+ for (Ref<EditorResourceConversionPlugin> resource_conversion_plugin : resource_conversion_plugins) {
+ if (resource_conversion_plugin.is_valid() && resource_conversion_plugin->handles(temp)) {
+ ret.push_back(resource_conversion_plugin);
+ }
+ }
}
}
@@ -6557,6 +6692,8 @@ EditorNode::EditorNode() {
DEV_ASSERT(!singleton);
singleton = this;
+ set_translation_domain("godot.editor");
+
Resource::_get_local_scene_func = _resource_get_edited_scene;
{
@@ -7790,9 +7927,14 @@ EditorNode::EditorNode() {
title_bar->set_can_move_window(true);
}
- String exec = OS::get_singleton()->get_executable_path();
- // Save editor executable path for third-party tools.
- EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "executable_path", exec);
+ {
+ const String exec = OS::get_singleton()->get_executable_path();
+ const String old_exec = EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "executable_path", "");
+ // Save editor executable path for third-party tools.
+ if (exec != old_exec) {
+ EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "executable_path", exec);
+ }
+ }
follow_system_theme = EDITOR_GET("interface/theme/follow_system_theme");
use_system_accent_color = EDITOR_GET("interface/theme/use_system_accent_color");