From a9d8da91b72fe8493f9087563056bb4ade4ca2c7 Mon Sep 17 00:00:00 2001 From: volzhs Date: Mon, 13 Mar 2017 19:35:27 +0900 Subject: [PATCH] Fix drag and drop on 2d viewport (cherry picked from commit 4d0a75750fdb8d1cd150976cdbd6c3d1c7ab513b) --- editor/plugins/canvas_item_editor_plugin.cpp | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index e7189b0f435..18ab39fda99 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3428,20 +3428,19 @@ 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); - String type = res->get_type(); - if (type == "ImageTexture" || type == "PackedScene") { - if (type == "ImageTexture") { - Ref texture = Ref(ResourceCache::get(path)->cast_to()); + Ref texture = Ref(res->cast_to()); + Ref scene = Ref(res->cast_to()); + if (texture != NULL || scene != NULL) { + if (texture != NULL) { Sprite *sprite = memnew(Sprite); sprite->set_texture(texture); sprite->set_opacity(0.7f); preview->add_child(sprite); label->show(); label_desc->show(); - } else if (type == "PackedScene") { - Ref scn = ResourceLoader::load(path); - if (scn.is_valid()) { - Node *instance = scn->instance(); + } else { + if (scene.is_valid()) { + Node *instance = scene->instance(); if (instance) { preview->add_child(instance); } @@ -3481,7 +3480,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); @@ -3534,7 +3533,7 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String & if (default_type == "Polygon2D" || default_type == "TouchScreenButton" || default_type == "TextureFrame" || default_type == "Patch9Frame") { target_pos -= texture_size / 2; } - editor_data->get_undo_redo().add_do_method(child, "set_pos", target_pos); + editor_data->get_undo_redo().add_do_method(child, "set_position", target_pos); } bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, const Point2 &p_point) { @@ -3596,8 +3595,9 @@ void CanvasItemEditorViewport::_perform_drop_data() { if (res.is_null()) { continue; } - String type = res->get_type(); - if (type == "ImageTexture") { + Ref texture = Ref(res->cast_to()); + Ref scene = Ref(res->cast_to()); + if (texture != NULL) { 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 (type == "PackedScene") { + } else if (scene != NULL) { 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.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_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_constant_override("shadow_as_outline", 1 * EDSCALE); label_desc->add_constant_override("line_spacing", 0); label_desc->hide();