summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_autoload_settings.cpp193
-rw-r--r--editor/editor_autoload_settings.h10
-rw-r--r--editor/editor_properties.cpp3
-rw-r--r--editor/import/editor_import_collada.cpp2
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp17
5 files changed, 144 insertions, 81 deletions
diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp
index 708bff252a..de9203232c 100644
--- a/editor/editor_autoload_settings.cpp
+++ b/editor/editor_autoload_settings.cpp
@@ -52,6 +52,13 @@ void EditorAutoloadSettings::_notification(int p_what) {
file_dialog->add_filter("*." + E->get());
}
+
+ for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) {
+ AutoLoadInfo &info = E->get();
+ if (info.node && info.in_editor) {
+ get_tree()->get_root()->call_deferred("add_child", info.node);
+ }
+ }
}
}
@@ -291,6 +298,36 @@ void EditorAutoloadSettings::_autoload_file_callback(const String &p_path) {
autoload_add_name->set_text(p_path.get_file().get_basename());
}
+Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {
+ RES res = ResourceLoader::load(p_path);
+ ERR_EXPLAIN("Can't autoload: " + p_path);
+ ERR_FAIL_COND_V(res.is_null(), NULL);
+ Node *n = NULL;
+ if (res->is_class("PackedScene")) {
+ Ref<PackedScene> ps = res;
+ n = ps->instance();
+ } else if (res->is_class("Script")) {
+ Ref<Script> s = res;
+ StringName ibt = s->get_instance_base_type();
+ bool valid_type = ClassDB::is_parent_class(ibt, "Node");
+ ERR_EXPLAIN("Script does not inherit a Node: " + p_path);
+ ERR_FAIL_COND_V(!valid_type, NULL);
+
+ Object *obj = ClassDB::instance(ibt);
+
+ ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt));
+ ERR_FAIL_COND_V(obj == NULL, NULL);
+
+ n = Object::cast_to<Node>(obj);
+ n->set_script(s.get_ref_ptr());
+ }
+
+ ERR_EXPLAIN("Path in autoload not a node or script: " + p_path);
+ ERR_FAIL_COND_V(!n, NULL);
+
+ return n;
+}
+
void EditorAutoloadSettings::update_autoload() {
if (updating_autoload)
@@ -299,15 +336,11 @@ void EditorAutoloadSettings::update_autoload() {
updating_autoload = true;
Map<String, AutoLoadInfo> to_remove;
- Map<String, AutoLoadInfo> to_remove_singleton;
- List<AutoLoadInfo> to_add;
- List<String> to_add_singleton; // Only for when the node is still the same
+ List<AutoLoadInfo *> to_add;
for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) {
- to_remove.insert(E->get().name, E->get());
- if (E->get().is_singleton) {
- to_remove_singleton.insert(E->get().name, E->get());
- }
+ AutoLoadInfo &info = E->get();
+ to_remove.insert(info.name, info);
}
autoload_cache.clear();
@@ -331,11 +364,6 @@ void EditorAutoloadSettings::update_autoload() {
if (name.empty())
continue;
- AutoLoadInfo old_info;
- if (to_remove.has(name)) {
- old_info = to_remove[name];
- }
-
AutoLoadInfo info;
info.is_singleton = path.begins_with("*");
@@ -347,28 +375,31 @@ void EditorAutoloadSettings::update_autoload() {
info.path = path;
info.order = ProjectSettings::get_singleton()->get_order(pi.name);
- if (old_info.name == info.name) {
+ bool need_to_add = true;
+ if (to_remove.has(name)) {
+ AutoLoadInfo &old_info = to_remove[name];
if (old_info.path == info.path) {
- // Still the same resource, check singleton status
- to_remove.erase(name);
- if (info.is_singleton) {
- if (old_info.is_singleton) {
- to_remove_singleton.erase(name);
+ // Still the same resource, check status
+ info.node = old_info.node;
+ if (info.node) {
+ Ref<Script> scr = info.node->get_script();
+ info.in_editor = scr.is_valid() && scr->is_tool();
+ if (info.is_singleton == old_info.is_singleton && info.in_editor == old_info.in_editor) {
+ to_remove.erase(name);
+ need_to_add = false;
} else {
- to_add_singleton.push_back(name);
+ info.node = NULL;
}
}
- } else {
- // Resource changed
- to_add.push_back(info);
}
- } else {
- // New autoload
- to_add.push_back(info);
}
autoload_cache.push_back(info);
+ if (need_to_add) {
+ to_add.push_back(&(autoload_cache.back()->get()));
+ }
+
TreeItem *item = tree->create_item(root);
item->set_text(0, name);
item->set_editable(0, true);
@@ -387,71 +418,54 @@ void EditorAutoloadSettings::update_autoload() {
item->set_selectable(3, false);
}
- // Remove autoload constants
- for (Map<String, AutoLoadInfo>::Element *E = to_remove_singleton.front(); E; E = E->next()) {
- for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- ScriptServer::get_language(i)->remove_named_global_constant(E->get().name);
- }
- }
-
- // Remove obsolete nodes from the tree
+ // Remove deleted/changed autoloads
for (Map<String, AutoLoadInfo>::Element *E = to_remove.front(); E; E = E->next()) {
AutoLoadInfo &info = E->get();
- Node *al = get_node("/root/" + info.name);
- ERR_CONTINUE(!al);
- get_tree()->get_root()->remove_child(al);
- memdelete(al);
- }
+ if (info.is_singleton) {
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
+ ScriptServer::get_language(i)->remove_named_global_constant(info.name);
+ }
+ }
+ if (info.in_editor) {
+ ERR_CONTINUE(!info.node);
+ get_tree()->get_root()->remove_child(info.node);
+ }
- // Register new singletons already in the tree
- for (List<String>::Element *E = to_add_singleton.front(); E; E = E->next()) {
- Node *al = get_node("/root/" + E->get());
- ERR_CONTINUE(!al);
- for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- ScriptServer::get_language(i)->add_named_global_constant(E->get(), al);
+ if (info.node) {
+ memdelete(info.node);
+ info.node = NULL;
}
}
- // Add new nodes to the tree
+ // Load new/changed autoloads
List<Node *> nodes_to_add;
- for (List<AutoLoadInfo>::Element *E = to_add.front(); E; E = E->next()) {
- AutoLoadInfo &info = E->get();
+ for (List<AutoLoadInfo *>::Element *E = to_add.front(); E; E = E->next()) {
+ AutoLoadInfo *info = E->get();
- RES res = ResourceLoader::load(info.path);
- ERR_EXPLAIN("Can't autoload: " + info.path);
- ERR_CONTINUE(res.is_null());
- Node *n = NULL;
- if (res->is_class("PackedScene")) {
- Ref<PackedScene> ps = res;
- n = ps->instance();
- } else if (res->is_class("Script")) {
- Ref<Script> s = res;
- StringName ibt = s->get_instance_base_type();
- bool valid_type = ClassDB::is_parent_class(ibt, "Node");
- ERR_EXPLAIN("Script does not inherit a Node: " + info.path);
- ERR_CONTINUE(!valid_type);
-
- Object *obj = ClassDB::instance(ibt);
-
- ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt));
- ERR_CONTINUE(obj == NULL);
-
- n = Object::cast_to<Node>(obj);
- n->set_script(s.get_ref_ptr());
- }
+ info->node = _create_autoload(info->path);
- ERR_EXPLAIN("Path in autoload not a node or script: " + info.path);
- ERR_CONTINUE(!n);
- n->set_name(info.name);
+ ERR_CONTINUE(!info->node);
+ info->node->set_name(info->name);
- //defer so references are all valid on _ready()
- nodes_to_add.push_back(n);
+ Ref<Script> scr = info->node->get_script();
+ info->in_editor = scr.is_valid() && scr->is_tool();
- if (info.is_singleton) {
+ if (info->in_editor) {
+ //defer so references are all valid on _ready()
+ nodes_to_add.push_back(info->node);
+ }
+
+ if (info->is_singleton) {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- ScriptServer::get_language(i)->add_named_global_constant(info.name, n);
+ ScriptServer::get_language(i)->add_named_global_constant(info->name, info->node);
}
}
+
+ if (!info->in_editor && !info->is_singleton) {
+ // No reason to keep this node
+ memdelete(info->node);
+ info->node = NULL;
+ }
}
for (List<Node *>::Element *E = nodes_to_add.front(); E; E = E->next()) {
@@ -728,6 +742,24 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
info.name = name;
info.path = path;
info.order = ProjectSettings::get_singleton()->get_order(pi.name);
+ info.node = _create_autoload(path);
+
+ if (info.node) {
+ Ref<Script> scr = info.node->get_script();
+ info.in_editor = scr.is_valid() && scr->is_tool();
+ info.node->set_name(info.name);
+ }
+
+ if (info.is_singleton) {
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
+ ScriptServer::get_language(i)->add_named_global_constant(info.name, info.node);
+ }
+ }
+
+ if (!info.is_singleton && !info.in_editor) {
+ memdelete(info.node);
+ info.node = NULL;
+ }
autoload_cache.push_back(info);
}
@@ -796,3 +828,12 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
add_child(tree, true);
}
+
+EditorAutoloadSettings::~EditorAutoloadSettings() {
+ for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) {
+ AutoLoadInfo &info = E->get();
+ if (info.node && !info.in_editor) {
+ memdelete(info.node);
+ }
+ }
+}
diff --git a/editor/editor_autoload_settings.h b/editor/editor_autoload_settings.h
index 1797c10e61..0b75faa009 100644
--- a/editor/editor_autoload_settings.h
+++ b/editor/editor_autoload_settings.h
@@ -52,11 +52,19 @@ class EditorAutoloadSettings : public VBoxContainer {
String name;
String path;
bool is_singleton;
+ bool in_editor;
int order;
+ Node *node;
bool operator==(const AutoLoadInfo &p_info) {
return order == p_info.order;
}
+
+ AutoLoadInfo() {
+ is_singleton = false;
+ in_editor = false;
+ node = NULL;
+ }
};
List<AutoLoadInfo> autoload_cache;
@@ -78,6 +86,7 @@ class EditorAutoloadSettings : public VBoxContainer {
void _autoload_activated();
void _autoload_open(const String &fpath);
void _autoload_file_callback(const String &p_path);
+ Node *_create_autoload(const String &p_path);
Variant get_drag_data_fw(const Point2 &p_point, Control *p_control);
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control) const;
@@ -93,6 +102,7 @@ public:
void autoload_remove(const String &p_name);
EditorAutoloadSettings();
+ ~EditorAutoloadSettings();
};
#endif
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 0625aeee54..d1968468f8 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -1522,7 +1522,8 @@ EditorPropertyColor::EditorPropertyColor() {
void EditorPropertyNodePath::_node_selected(const NodePath &p_path) {
- emit_signal("property_changed", get_edited_property(), p_path);
+ Node *base_node = Object::cast_to<Node>(get_edited_object());
+ emit_signal("property_changed", get_edited_property(), base_node->get_path().rel_path_to(p_path));
update_property();
}
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp
index 1d7545f182..2fb3bf7b1e 100644
--- a/editor/import/editor_import_collada.cpp
+++ b/editor/import/editor_import_collada.cpp
@@ -339,7 +339,7 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) {
NodeMap nm;
nm.node = node;
node_map[p_node->id] = nm;
- node_name_map[p_node->name] = p_node->id;
+ node_name_map[node->get_name()] = p_node->id;
Transform xf = p_node->default_transform;
xf = collada.fix_transform(xf) * p_node->post_transform;
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
index d21c84eb61..d595d4dd98 100644
--- a/editor/plugins/asset_library_editor_plugin.cpp
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -705,7 +705,18 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByt
int len = image_data.size();
PoolByteArray::Read r = image_data.read();
- Ref<Image> image = Ref<Image>(memnew(Image(r.ptr(), len)));
+ Ref<Image> image = Ref<Image>(memnew(Image));
+
+ uint8_t png_signature[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
+ uint8_t jpg_signature[3] = { 255, 216, 255 };
+
+ if (r.ptr()) {
+ if (memcmp(&r[0], &png_signature[0], 8) == 0) {
+ image->copy_internals_from(Image::_png_mem_loader_func(r.ptr(), len));
+ } else if (memcmp(&r[0], &jpg_signature[0], 3) == 0) {
+ image->copy_internals_from(Image::_jpg_mem_loader_func(r.ptr(), len));
+ }
+ }
if (!image->empty()) {
switch (image_queue[p_queue_id].image_type) {
@@ -750,7 +761,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons
ERR_FAIL_COND(!image_queue.has(p_queue_id));
- if (p_status == HTTPRequest::RESULT_SUCCESS) {
+ if (p_status == HTTPRequest::RESULT_SUCCESS && p_code < HTTPClient::RESPONSE_BAD_REQUEST) {
if (p_code != HTTPClient::RESPONSE_NOT_MODIFIED) {
for (int i = 0; i < headers.size(); i++) {
@@ -781,7 +792,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons
_image_update(p_code == HTTPClient::RESPONSE_NOT_MODIFIED, true, p_data, p_queue_id);
} else {
- WARN_PRINTS("Error getting PNG file from URL: " + image_queue[p_queue_id].image_url);
+ // WARN_PRINTS("Error getting image file from URL: " + image_queue[p_queue_id].image_url);
Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target);
if (obj) {
obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("DefaultProjectIcon", "EditorIcons"));