Revert "Fix drag and drop on 2d viewport"
This reverts commitsa9d8da91b7
and4230b22558
.
This commit is contained in:
parent
51c5a12f43
commit
ea987256f6
|
@ -3428,19 +3428,20 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons
|
||||||
for (int i = 0; i < files.size(); i++) {
|
for (int i = 0; i < files.size(); i++) {
|
||||||
String path = files[i];
|
String path = files[i];
|
||||||
RES res = ResourceLoader::load(path);
|
RES res = ResourceLoader::load(path);
|
||||||
Ref<Texture> texture = Ref<Texture>(res->cast_to<Texture>());
|
String type = res->get_type();
|
||||||
Ref<PackedScene> scene = Ref<PackedScene>(res->cast_to<PackedScene>());
|
if (type == "ImageTexture" || type == "PackedScene") {
|
||||||
if (texture != NULL || scene != NULL) {
|
if (type == "ImageTexture") {
|
||||||
if (texture != NULL) {
|
Ref<ImageTexture> texture = Ref<ImageTexture>(ResourceCache::get(path)->cast_to<ImageTexture>());
|
||||||
Sprite *sprite = memnew(Sprite);
|
Sprite *sprite = memnew(Sprite);
|
||||||
sprite->set_texture(texture);
|
sprite->set_texture(texture);
|
||||||
sprite->set_opacity(0.7f);
|
sprite->set_opacity(0.7f);
|
||||||
preview->add_child(sprite);
|
preview->add_child(sprite);
|
||||||
label->show();
|
label->show();
|
||||||
label_desc->show();
|
label_desc->show();
|
||||||
} else {
|
} else if (type == "PackedScene") {
|
||||||
if (scene.is_valid()) {
|
Ref<PackedScene> scn = ResourceLoader::load(path);
|
||||||
Node *instance = scene->instance();
|
if (scn.is_valid()) {
|
||||||
|
Node *instance = scn->instance();
|
||||||
if (instance) {
|
if (instance) {
|
||||||
preview->add_child(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) {
|
void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point) {
|
||||||
child->set_name(path.get_file().basename());
|
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();
|
Size2 texture_size = texture->get_size();
|
||||||
|
|
||||||
editor_data->get_undo_redo().add_do_method(parent, "add_child", child);
|
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()) {
|
if (res.is_null()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Ref<Texture> texture = Ref<Texture>(res->cast_to<Texture>());
|
String type = res->get_type();
|
||||||
Ref<PackedScene> scene = Ref<PackedScene>(res->cast_to<PackedScene>());
|
if (type == "ImageTexture") {
|
||||||
if (texture != NULL) {
|
|
||||||
Node *child;
|
Node *child;
|
||||||
if (default_type == "Light2D")
|
if (default_type == "Light2D")
|
||||||
child = memnew(Light2D);
|
child = memnew(Light2D);
|
||||||
|
@ -3615,7 +3615,7 @@ void CanvasItemEditorViewport::_perform_drop_data() {
|
||||||
child = memnew(Sprite); // default
|
child = memnew(Sprite); // default
|
||||||
|
|
||||||
_create_nodes(target_node, child, path, drop_pos);
|
_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);
|
bool success = _create_instance(target_node, path, drop_pos);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
error_files.push_back(path);
|
error_files.push_back(path);
|
||||||
|
@ -3770,11 +3770,11 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
|
||||||
|
|
||||||
btn_group = memnew(ButtonGroup);
|
btn_group = memnew(ButtonGroup);
|
||||||
btn_group->set_h_size_flags(0);
|
btn_group->set_h_size_flags(0);
|
||||||
|
btn_group->connect("button_selected", this, "_on_select_type");
|
||||||
|
|
||||||
for (int i = 0; i < types.size(); i++) {
|
for (int i = 0; i < types.size(); i++) {
|
||||||
CheckBox *check = memnew(CheckBox);
|
CheckBox *check = memnew(CheckBox);
|
||||||
check->set_text(types[i]);
|
check->set_text(types[i]);
|
||||||
check->connect("button_selected", this, "_on_select_type", varray(check));
|
|
||||||
btn_group->add_child(check);
|
btn_group->add_child(check);
|
||||||
}
|
}
|
||||||
vbc->add_child(btn_group);
|
vbc->add_child(btn_group);
|
||||||
|
@ -3797,8 +3797,8 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
|
||||||
|
|
||||||
label_desc = memnew(Label);
|
label_desc = memnew(Label);
|
||||||
label_desc->set_text(TTR("Drag & drop + Shift : Add node as sibling\nDrag & drop + Alt : Change node type"));
|
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", Color(0.6, 0.6, 0.6, 1));
|
||||||
label_desc->add_color_override("font_color_shadow", Color(0.2f, 0.2f, 0.2f, 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("shadow_as_outline", 1 * EDSCALE);
|
||||||
label_desc->add_constant_override("line_spacing", 0);
|
label_desc->add_constant_override("line_spacing", 0);
|
||||||
label_desc->hide();
|
label_desc->hide();
|
||||||
|
|
Loading…
Reference in New Issue