diff options
Diffstat (limited to 'editor/gui/scene_tree_editor.cpp')
-rw-r--r-- | editor/gui/scene_tree_editor.cpp | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index 056e4f8d9d..ba4fa994b7 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -50,7 +50,7 @@ #include "scene/main/window.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(); @@ -498,6 +498,18 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { EditorNode::get_singleton()->is_object_of_custom_type(p_node, E)) { valid = true; break; + } else { + Ref<Script> node_script = p_node->get_script(); + while (node_script.is_valid()) { + if (node_script->get_path() == E) { + valid = true; + break; + } + node_script = node_script->get_base_script(); + } + if (valid) { + break; + } } } @@ -656,6 +668,18 @@ bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_select EditorNode::get_singleton()->is_object_of_custom_type(n, E)) { selectable = true; break; + } else { + Ref<Script> node_script = n->get_script(); + while (node_script.is_valid()) { + if (node_script->get_path() == E) { + selectable = true; + break; + } + node_script = node_script->get_base_script(); + } + if (selectable) { + break; + } } } } @@ -1218,11 +1242,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 instantiated scene. - if (!n->get_owner() || n->get_owner() == get_scene_node() || n->get_owner()->get_scene_file_path().is_empty()) { - selected_nodes.push_back(n); - icons.push_back(next->get_icon(0)); - } + selected_nodes.push_back(n); + icons.push_back(next->get_icon(0)); } next = tree->get_next_selected(next); } @@ -1336,7 +1357,21 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d } } - return String(d["type"]) == "nodes" && filter.is_empty(); + if (filter.is_empty() && String(d["type"]) == "nodes") { + Array nodes = d["nodes"]; + + for (int i = 0; i < nodes.size(); i++) { + Node *n = get_node(nodes[i]); + // Nodes from an instantiated scene can't be rearranged. + if (n && n->get_owner() && n->get_owner() != get_scene_node() && !n->get_owner()->get_scene_file_path().is_empty()) { + return false; + } + } + + return true; + } + + return false; } void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { @@ -1548,16 +1583,29 @@ void SceneTreeDialog::set_valid_types(const Vector<StringName> &p_valid) { HBoxContainer *hb = memnew(HBoxContainer); hflow->add_child(hb); + // Attempt to get the correct name and icon for script path types. + String name = type; + Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type); + + // If we can't find a global class icon, try to find one for the script. + if (icon.is_null() && ResourceLoader::exists(type, "Script")) { + Ref<Script> node_script = ResourceLoader::load(type); + if (node_script.is_valid()) { + name = name.get_file(); + icon = EditorNode::get_singleton()->get_object_icon(node_script.ptr()); + } + } + TextureRect *trect = memnew(TextureRect); hb->add_child(trect); trect->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE); trect->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); - trect->set_meta("type", type); + trect->set_meta("icon", icon); valid_type_icons.push_back(trect); Label *label = memnew(Label); hb->add_child(label); - label->set_text(type); + label->set_text(name); label->set_auto_translate(false); } @@ -1583,7 +1631,7 @@ void SceneTreeDialog::_notification(int p_what) { filter->set_right_icon(get_editor_theme_icon(SNAME("Search"))); for (TextureRect *trect : valid_type_icons) { trect->set_custom_minimum_size(Vector2(get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)), 0)); - trect->set_texture(EditorNode::get_singleton()->get_class_icon(trect->get_meta("type"))); + trect->set_texture(trect->get_meta("icon")); } } break; |