diff options
Diffstat (limited to 'editor/scene_tree_editor.cpp')
-rw-r--r-- | editor/scene_tree_editor.cpp | 103 |
1 files changed, 63 insertions, 40 deletions
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index 1b818036e1..b9a3e2a801 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,9 +30,10 @@ #include "scene_tree_editor.h" -#include "core/message_queue.h" -#include "core/print_string.h" +#include "core/object/message_queue.h" +#include "core/string/print_string.h" #include "editor/editor_node.h" +#include "editor/editor_scale.h" #include "editor/node_dock.h" #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/canvas_item_editor_plugin.h" @@ -155,7 +156,7 @@ void SceneTreeEditor::_toggle_visible(Node *p_node) { } } -bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { +bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll_to_selected) { if (!p_node) { return false; } @@ -250,34 +251,42 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { if (can_rename) { //should be can edit.. String warning = p_node->get_configuration_warning(); - if (warning != String()) { + if (!warning.is_empty()) { item->add_button(0, get_theme_icon("NodeWarning", "EditorIcons"), BUTTON_WARNING, false, TTR("Node configuration warning:") + "\n" + p_node->get_configuration_warning()); } int num_connections = p_node->get_persistent_signal_connection_count(); int num_groups = p_node->get_persistent_group_count(); + String msg_temp; + if (num_connections >= 1) { + Array arr; + arr.push_back(num_connections); + msg_temp += TTRN("Node has one connection.", "Node has {num} connections.", num_connections).format(arr, "{num}"); + msg_temp += " "; + } + if (num_groups >= 1) { + Array arr; + arr.push_back(num_groups); + msg_temp += TTRN("Node is in one group.", "Node is in {num} groups.", num_groups).format(arr, "{num}"); + } + if (num_connections >= 1 || num_groups >= 1) { + msg_temp += "\n" + TTR("Click to show signals dock."); + } + + Ref<Texture2D> icon_temp; + auto signal_temp = BUTTON_SIGNALS; if (num_connections >= 1 && num_groups >= 1) { - item->add_button( - 0, - get_theme_icon("SignalsAndGroups", "EditorIcons"), - BUTTON_SIGNALS, - false, - vformat(TTR("Node has %s connection(s) and %s group(s).\nClick to show signals dock."), num_connections, num_groups)); + icon_temp = get_theme_icon("SignalsAndGroups", "EditorIcons"); } else if (num_connections >= 1) { - item->add_button( - 0, - get_theme_icon("Signals", "EditorIcons"), - BUTTON_SIGNALS, - false, - vformat(TTR("Node has %s connection(s).\nClick to show signals dock."), num_connections)); + icon_temp = get_theme_icon("Signals", "EditorIcons"); } else if (num_groups >= 1) { - item->add_button( - 0, - get_theme_icon("Groups", "EditorIcons"), - BUTTON_GROUPS, - false, - vformat(TTR("Node is in %s group(s).\nClick to show groups dock."), num_groups)); + icon_temp = get_theme_icon("Groups", "EditorIcons"); + signal_temp = BUTTON_GROUPS; + } + + if (num_connections >= 1 || num_groups >= 1) { + item->add_button(0, icon_temp, signal_temp, false, msg_temp); } } @@ -382,15 +391,19 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { } } + bool scroll = false; + if (editor_selection) { if (editor_selection->is_selected(p_node)) { item->select(0); + scroll = p_scroll_to_selected; } } if (selected == p_node) { if (!editor_selection) { item->select(0); + scroll = p_scroll_to_selected; } item->set_as_cursor(0); } @@ -398,7 +411,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { bool keep = (filter.is_subsequence_ofi(String(p_node->get_name()))); for (int i = 0; i < p_node->get_child_count(); i++) { - bool child_keep = _add_nodes(p_node->get_child(i), item); + bool child_keep = _add_nodes(p_node->get_child(i), item, p_scroll_to_selected); keep = keep || child_keep; } @@ -429,6 +442,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { memdelete(item); return false; } else { + if (scroll) { + tree->scroll_to_item(item); + } return true; } } @@ -516,7 +532,7 @@ void SceneTreeEditor::_node_renamed(Node *p_node) { } } -void SceneTreeEditor::_update_tree() { +void SceneTreeEditor::_update_tree(bool p_scroll_to_selected) { if (!is_inside_tree()) { tree_dirty = false; return; @@ -525,7 +541,7 @@ void SceneTreeEditor::_update_tree() { updating_tree = true; tree->clear(); if (get_scene_node()) { - _add_nodes(get_scene_node(), nullptr); + _add_nodes(get_scene_node(), nullptr, p_scroll_to_selected); last_hash = hash_djb2_one_64(0); _compute_hash(get_scene_node(), last_hash); } @@ -745,7 +761,7 @@ void SceneTreeEditor::_renamed() { ERR_FAIL_COND(!n); // Empty node names are not allowed, so resets it to previous text and show warning - if (which->get_text(0).strip_edges().empty()) { + if (which->get_text(0).strip_edges().is_empty()) { which->set_text(0, n->get_name()); EditorNode::get_singleton()->show_warning(TTR("No name provided.")); return; @@ -756,7 +772,7 @@ void SceneTreeEditor::_renamed() { error->set_text(TTR("Invalid node name, the following characters are not allowed:") + "\n" + Node::invalid_character); error->popup_centered(); - if (new_name.empty()) { + if (new_name.is_empty()) { which->set_text(0, n->get_name()); return; } @@ -768,6 +784,9 @@ void SceneTreeEditor::_renamed() { return; } + // Trim leading/trailing whitespace to prevent node names from containing accidental whitespace, which would make it more difficult to get the node via `get_node()`. + new_name = new_name.strip_edges(); + if (!undo_redo) { n->set_name(new_name); which->set_metadata(0, n->get_path()); @@ -805,7 +824,7 @@ void SceneTreeEditor::set_marked(Node *p_marked, bool p_selectable, bool p_child void SceneTreeEditor::set_filter(const String &p_filter) { filter = p_filter; - _update_tree(); + _update_tree(true); } String SceneTreeEditor::get_filter() const { @@ -817,10 +836,6 @@ void SceneTreeEditor::set_display_foreign_nodes(bool p_display) { _update_tree(); } -bool SceneTreeEditor::get_display_foreign_nodes() const { - return display_foreign; -} - void SceneTreeEditor::set_valid_types(const Vector<StringName> &p_valid) { valid_types = p_valid; } @@ -902,6 +917,10 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from return Variant(); //not editable tree } + if (tree->get_button_id_at_position(p_point) != -1) { + return Variant(); //dragging from button + } + Vector<Node *> selected; Vector<Ref<Texture2D>> icons; TreeItem *next = tree->get_next_selected(nullptr); @@ -919,7 +938,7 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from next = tree->get_next_selected(next); } - if (selected.empty()) { + if (selected.is_empty()) { return Variant(); } @@ -1072,7 +1091,7 @@ void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, } void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) { - emit_signal("rmb_pressed", tree->get_global_transform().xform(p_pos)); + emit_signal("rmb_pressed", tree->get_screen_transform().xform(p_pos)); } void SceneTreeEditor::_warning_changed(Node *p_for_node) { @@ -1091,7 +1110,7 @@ void SceneTreeEditor::set_connecting_signal(bool p_enable) { } void SceneTreeEditor::_bind_methods() { - ClassDB::bind_method("_update_tree", &SceneTreeEditor::_update_tree); // Still used by some connect_compat. + ClassDB::bind_method(D_METHOD("_update_tree", "scroll_to_selected"), &SceneTreeEditor::_update_tree, DEFVAL(false)); // Still used by some connect_compat. ClassDB::bind_method("_rename_node", &SceneTreeEditor::_rename_node); ClassDB::bind_method("_test_update_tree", &SceneTreeEditor::_test_update_tree); @@ -1138,8 +1157,8 @@ SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_ope } tree = memnew(Tree); - tree->set_anchor(MARGIN_RIGHT, ANCHOR_END); - tree->set_anchor(MARGIN_BOTTOM, ANCHOR_END); + tree->set_anchor(SIDE_RIGHT, ANCHOR_END); + tree->set_anchor(SIDE_BOTTOM, ANCHOR_END); tree->set_begin(Point2(0, p_label ? 18 : 0)); tree->set_end(Point2(0, 0)); tree->add_theme_constant_override("button_margin", 0); @@ -1190,6 +1209,10 @@ SceneTreeEditor::~SceneTreeEditor() { /******** DIALOG *********/ +void SceneTreeDialog::popup_scenetree_dialog() { + popup_centered_clamped(Size2(350, 700) * EDSCALE); +} + void SceneTreeDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { @@ -1237,7 +1260,7 @@ SceneTreeDialog::SceneTreeDialog() { filter = memnew(LineEdit); filter->set_h_size_flags(Control::SIZE_EXPAND_FILL); filter->set_placeholder(TTR("Filter nodes")); - filter->add_theme_constant_override("minimum_spaces", 0); + filter->add_theme_constant_override("minimum_character_width", 0); filter->connect("text_changed", callable_mp(this, &SceneTreeDialog::_filter_changed)); vbc->add_child(filter); |