From f641327dcf541b9ef542983e46892e429fe59334 Mon Sep 17 00:00:00 2001 From: foxydevloper <12120644+foxydevloper@users.noreply.github.com> Date: Thu, 29 Jul 2021 07:15:46 -0400 Subject: 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. --- editor/plugins/node_3d_editor_plugin.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'editor/plugins/node_3d_editor_plugin.cpp') diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index ebd6615ac1..a278b5a37f 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -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 list = editor->get_editor_selection()->get_selected_node_list(); - if (list.size() == 0) { - Node *root_node = editor->get_edited_scene(); + List 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(); -- cgit v1.2.3