summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-07-30 09:02:09 +0200
committerGitHub <noreply@github.com>2021-07-30 09:02:09 +0200
commit74aa7e26e9eca919358fddb1c6ab811d3d244816 (patch)
tree79313b4e71bbb538debf29b4887118abc6042e27 /editor/plugins
parent57cd7878bca1b1d2dd88f81c101cda7b126252c5 (diff)
parentf641327dcf541b9ef542983e46892e429fe59334 (diff)
Merge pull request #51011 from foxydevloper/drag-drop-root-default
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp28
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp28
2 files changed, 32 insertions, 24 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 9bbafcc79d..accc96ab4e 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -5733,11 +5733,14 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons
preview_node->add_child(sprite);
label->show();
label_desc->show();
+ label_desc->set_text(TTR("Drag and drop to add as child of current scene's root node.\nHold Ctrl when dropping to add as child of selected node.\nHold Shift when dropping to add as sibling of selected node.\nHold Alt when dropping to add as a different node type."));
} else {
if (scene.is_valid()) {
Node *instance = scene->instantiate();
if (instance) {
preview_node->add_child(instance);
+ label_desc->show();
+ label_desc->set_text(TTR("Drag and drop to add as child of current scene's root node.\nHold Ctrl when dropping to add as child of selected node.\nHold Shift when dropping to add as sibling of selected node."));
}
}
}
@@ -6036,6 +6039,7 @@ bool CanvasItemEditorViewport::_only_packed_scenes_selected() const {
void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) {
bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT);
+ bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CTRL);
bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT);
selected_files.clear();
@@ -6047,24 +6051,25 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p
return;
}
- 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() > 0) {
+ 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 (root_node) {
- list.push_back(root_node);
+ target_node = root_node;
} else {
drop_pos = p_point;
target_node = nullptr;
}
}
- if (list.size() > 0) {
- target_node = list[0];
- if (is_shift && target_node != editor->get_edited_scene()) {
- target_node = target_node->get_parent();
- }
- }
-
drop_pos = p_point;
if (is_alt && !_only_packed_scenes_selected()) {
@@ -6145,7 +6150,6 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
canvas_item_editor->get_controls_container()->add_child(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->add_theme_color_override("font_color", Color(0.6f, 0.6f, 0.6f, 1));
label_desc->add_theme_color_override("font_shadow_color", Color(0.2f, 0.2f, 0.2f, 1));
label_desc->add_theme_constant_override("shadow_as_outline", 1 * EDSCALE);
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<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();