Skip to content

Commit ec67cbe

Browse files
committed
Merge pull request godotengine#120102 from bruvzg/sct_drop
[Editor] Fix `SceneTreeEditor` drop.
2 parents 9d87674 + 363610d commit ec67cbe

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

editor/scene/scene_tree_editor.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,11 @@ bool SceneTreeEditor::_is_script_type(const StringName &p_type) const {
19141914
return (script_types->has(p_type));
19151915
}
19161916

1917+
bool SceneTreeEditor::_has_drop_selection(TreeItem *p_item, const Point2 &p_point) const {
1918+
int section = (p_point == Vector2(Math::INF, Math::INF)) ? tree->get_drop_section_at_position(tree->get_item_rect(p_item).position) : tree->get_drop_section_at_position(p_point);
1919+
return !(section < -1 || (section == -1 && !p_item->get_parent()));
1920+
}
1921+
19171922
bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
19181923
if (!can_rename) {
19191924
return false; // Not editable tree.
@@ -1934,11 +1939,6 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
19341939
return false;
19351940
}
19361941

1937-
int section = (p_point == Vector2(Math::INF, Math::INF)) ? tree->get_drop_section_at_position(tree->get_item_rect(item).position) : tree->get_drop_section_at_position(p_point);
1938-
if (section < -1 || (section == -1 && !item->get_parent())) {
1939-
return false;
1940-
}
1941-
19421942
if (String(d["type"]) == "files") {
19431943
Vector<String> files = d["files"];
19441944

@@ -1948,7 +1948,7 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
19481948

19491949
if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(files[0]))) {
19501950
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
1951-
return true;
1951+
return _has_drop_selection(item, p_point);
19521952
}
19531953

19541954
bool scene_drop = true;
@@ -1965,7 +1965,7 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
19651965

19661966
if (scene_drop) {
19671967
tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM);
1968-
return true;
1968+
return _has_drop_selection(item, p_point);
19691969
}
19701970

19711971
if (audio_drop) {
@@ -1974,15 +1974,14 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
19741974
} else {
19751975
tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM);
19761976
}
1977-
return true;
1977+
return _has_drop_selection(item, p_point);
19781978
}
19791979

19801980
if (files.size() > 1) {
19811981
return false;
19821982
}
19831983
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
1984-
1985-
return true;
1984+
return _has_drop_selection(item, p_point);
19861985
}
19871986

19881987
if (String(d["type"]) == "script_list_element") {
@@ -1991,7 +1990,7 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
19911990
String sp = se->get_edited_resource()->get_path();
19921991
if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(sp))) {
19931992
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
1994-
return true;
1993+
return _has_drop_selection(item, p_point);
19951994
}
19961995
}
19971996
}
@@ -2007,7 +2006,7 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
20072006
}
20082007
}
20092008

2010-
return true;
2009+
return _has_drop_selection(item, p_point);
20112010
}
20122011

20132012
return false;

editor/scene/scene_tree_editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class SceneTreeEditor : public Control {
220220
Timer *update_timer = nullptr;
221221

222222
LocalVector<StringName> *script_types;
223+
bool _has_drop_selection(TreeItem *p_item, const Point2 &p_point) const;
223224
bool _is_script_type(const StringName &p_type) const;
224225

225226
Vector<StringName> valid_types;

0 commit comments

Comments
 (0)