Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Allow dragging editable children #85827

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions editor/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "scene/main/viewport.h"
#include "scene/resources/packed_scene.h"

Node *SceneTreeEditor::get_scene_node() {
Node *SceneTreeEditor::get_scene_node() const {
ERR_FAIL_COND_V(!is_inside_tree(), nullptr);

return get_tree()->get_edited_scene_root();
Expand Down Expand Up @@ -995,11 +995,8 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from

Node *n = get_node(np);
if (n) {
// Only allow selection if not part of an instanced scene.
if (!n->get_owner() || n->get_owner() == get_scene_node() || n->get_owner()->get_filename() == String()) {
selected.push_back(n);
icons.push_back(next->get_icon(0));
}
selected.push_back(n);
icons.push_back(next->get_icon(0));
}
next = tree->get_next_selected(next);
}
Expand Down Expand Up @@ -1110,7 +1107,21 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
}
}

return String(d["type"]) == "nodes" && filter == String();
if (filter.empty() && String(d["type"]) == "nodes") {
Array nodes = d["nodes"];

for (int i = 0; i < nodes.size(); i++) {
Node *n = get_node(nodes[i]);
// Only allow selection if not part of an instanced scene.
if (n && n->get_owner() && n->get_owner() != get_scene_node() && !n->get_owner()->get_filename().empty()) {
return false;
}
}

return true;
}

return false;
}
void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
if (!can_drop_data_fw(p_point, p_data, p_from)) {
Expand Down
2 changes: 1 addition & 1 deletion editor/scene_tree_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SceneTreeEditor : public Control {
void _update_visibility_color(Node *p_node, TreeItem *p_item);

void _selection_changed();
Node *get_scene_node();
Node *get_scene_node() const;

Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
Expand Down
Loading