Revert "Fix drag and drop on 2d viewport"

This reverts commits a9d8da91b7
and 4230b22558.
This commit is contained in:
Rémi Verschelde 2017-03-20 16:56:55 +01:00
parent 51c5a12f43
commit ea987256f6

View file

@ -3428,19 +3428,20 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons
for (int i = 0; i < files.size(); i++) {
String path = files[i];
RES res = ResourceLoader::load(path);
Ref<Texture> texture = Ref<Texture>(res->cast_to<Texture>());
Ref<PackedScene> scene = Ref<PackedScene>(res->cast_to<PackedScene>());
if (texture != NULL || scene != NULL) {
if (texture != NULL) {
String type = res->get_type();
if (type == "ImageTexture" || type == "PackedScene") {
if (type == "ImageTexture") {
Ref<ImageTexture> texture = Ref<ImageTexture>(ResourceCache::get(path)->cast_to<ImageTexture>());
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<PackedScene> 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> texture = Ref<Texture>(ResourceCache::get(path)->cast_to<Texture>());
Ref<ImageTexture> texture = Ref<ImageTexture>(ResourceCache::get(path)->cast_to<ImageTexture>());
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> texture = Ref<Texture>(res->cast_to<Texture>());
Ref<PackedScene> scene = Ref<PackedScene>(res->cast_to<PackedScene>());
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();