1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Make drag and drop into viewport add to root node by default

When dragging and dropping a texture, mesh, or scene from the FileSystem into the
2D or 3D viewport, it will be added as a child of the current scene's root node.
This commit is contained in:
foxydevloper
2021-07-29 07:15:46 -04:00
parent 48857194b3
commit f641327dcf
2 changed files with 32 additions and 24 deletions

View File

@@ -4066,6 +4066,7 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_
}
bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT);
bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CTRL);
selected_files.clear();
Dictionary d = p_data;
@@ -4073,29 +4074,32 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_
selected_files = d["files"];
}
List<Node *> list = editor->get_editor_selection()->get_selected_node_list();
if (list.size() == 0) {
Node *root_node = editor->get_edited_scene();
List<Node *> selected_nodes = editor->get_editor_selection()->get_selected_node_list();
Node *root_node = editor->get_edited_scene();
if (selected_nodes.size() == 1) {
Node *selected_node = selected_nodes[0];
target_node = root_node;
if (is_ctrl) {
target_node = selected_node;
} else if (is_shift && selected_node != root_node) {
target_node = selected_node->get_parent();
}
} else if (selected_nodes.size() == 0) {
if (root_node) {
list.push_back(root_node);
target_node = root_node;
} else {
accept->set_text(TTR("No parent to instance a child at."));
accept->set_text(TTR("Cannot drag and drop into scene with no root node."));
accept->popup_centered();
_remove_preview();
return;
}
}
if (list.size() != 1) {
accept->set_text(TTR("This operation requires a single selected node."));
} else {
accept->set_text(TTR("Cannot drag and drop into multiple selected nodes."));
accept->popup_centered();
_remove_preview();
return;
}
target_node = list[0];
if (is_shift && target_node != editor->get_edited_scene()) {
target_node = target_node->get_parent();
}
drop_pos = p_point;
_perform_drop_data();