diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index b95ef73144..e7189b0f43 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3428,19 +3428,20 @@ void CanvasItemEditorViewport::_create_preview(const Vector &files) cons for (int i = 0; i < files.size(); i++) { String path = files[i]; RES res = ResourceLoader::load(path); - Ref texture = Ref(res->cast_to()); - Ref scene = Ref(res->cast_to()); - if (texture != NULL || scene != NULL) { - if (texture != NULL) { + String type = res->get_type(); + if (type == "ImageTexture" || type == "PackedScene") { + if (type == "ImageTexture") { + Ref texture = Ref(ResourceCache::get(path)->cast_to()); Sprite *sprite = memnew(Sprite); sprite->set_texture(texture); sprite->set_opacity(0.7f); preview->add_child(sprite); label->show(); label_desc->show(); - } else { - if (scene.is_valid()) { - Node *instance = scene->instance(); + } else if (type == "PackedScene") { + Ref scn = ResourceLoader::load(path); + if (scn.is_valid()) { + Node *instance = scn->instance(); if (instance) { preview->add_child(instance); } @@ -3480,7 +3481,7 @@ bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_targe void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point) { child->set_name(path.get_file().basename()); - Ref texture = Ref(ResourceCache::get(path)->cast_to()); + Ref texture = Ref(ResourceCache::get(path)->cast_to()); Size2 texture_size = texture->get_size(); editor_data->get_undo_redo().add_do_method(parent, "add_child", child); @@ -3595,9 +3596,8 @@ void CanvasItemEditorViewport::_perform_drop_data() { if (res.is_null()) { continue; } - Ref texture = Ref(res->cast_to()); - Ref scene = Ref(res->cast_to()); - if (texture != NULL) { + String type = res->get_type(); + if (type == "ImageTexture") { Node *child; if (default_type == "Light2D") child = memnew(Light2D); @@ -3615,7 +3615,7 @@ void CanvasItemEditorViewport::_perform_drop_data() { child = memnew(Sprite); // default _create_nodes(target_node, child, path, drop_pos); - } else if (scene != NULL) { + } else if (type == "PackedScene") { bool success = _create_instance(target_node, path, drop_pos); if (!success) { error_files.push_back(path); @@ -3770,11 +3770,11 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte btn_group = memnew(ButtonGroup); btn_group->set_h_size_flags(0); + btn_group->connect("button_selected", this, "_on_select_type"); for (int i = 0; i < types.size(); i++) { CheckBox *check = memnew(CheckBox); check->set_text(types[i]); - check->connect("button_selected", this, "_on_select_type", varray(check)); btn_group->add_child(check); } vbc->add_child(btn_group); @@ -3797,8 +3797,8 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte label_desc = memnew(Label); label_desc->set_text(TTR("Drag & drop + Shift : Add node as sibling\nDrag & drop + Alt : Change node type")); - label_desc->add_color_override("font_color", Color(0.6f, 0.6f, 0.6f, 1)); - label_desc->add_color_override("font_color_shadow", Color(0.2f, 0.2f, 0.2f, 1)); + label_desc->add_color_override("font_color", Color(0.6, 0.6, 0.6, 1)); + label_desc->add_color_override("font_color_shadow", Color(0.2, 0.2, 0.2, 1)); label_desc->add_constant_override("shadow_as_outline", 1 * EDSCALE); label_desc->add_constant_override("line_spacing", 0); label_desc->hide();