From 9f4b5a91c054a538bd5d3581200c56473140f390 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 11 Apr 2019 23:21:48 -0300 Subject: [PATCH] Reorganized connection dialog for much improved ease of use. -Removed dest path field -Added a "Source" signal -Added an "Advanced" button to hide complexity -Fix bug on Tree to make sure "ensure visible" works on hidden trees -Fix bug on TextEdit to ensure signals created with script not open sill focus the right line --- editor/connections_dialog.cpp | 127 +++++++++++++++++++++++++--------- editor/connections_dialog.h | 12 +++- editor/scene_tree_editor.cpp | 34 ++++++++- editor/scene_tree_editor.h | 4 ++ scene/gui/text_edit.cpp | 7 ++ scene/gui/text_edit.h | 1 + scene/gui/tree.cpp | 9 ++- 7 files changed, 153 insertions(+), 41 deletions(-) diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 045158504a8..685c5de76c2 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -37,6 +37,25 @@ #include "scene/gui/label.h" #include "scene/gui/popup_menu.h" +static Node *_find_first_script(Node *p_root, Node *p_node) { + if (p_node != p_root && p_node->get_owner() != p_root) { + return NULL; + } + if (!p_node->get_script().is_null()) { + return p_node; + } + + for (int i = 0; i < p_node->get_child_count(); i++) { + + Node *ret = _find_first_script(p_root, p_node->get_child(i)); + if (ret) { + return ret; + } + } + + return NULL; +} + class ConnectDialogBinds : public Object { GDCLASS(ConnectDialogBinds, Object); @@ -122,17 +141,8 @@ void ConnectDialog::_tree_node_selected() { Node *current = tree->get_selected(); - if (!current) { - make_callback->hide(); - return; - } - - if (current->get_script().is_null()) - make_callback->hide(); - else - make_callback->show(); - - dst_path->set_text(source->get_path_to(current)); + dst_path = source->get_path_to(current); + get_ok()->set_disabled(false); } /* @@ -195,6 +205,7 @@ void ConnectDialog::_notification(int p_what) { void ConnectDialog::_bind_methods() { + ClassDB::bind_method("_advanced_pressed", &ConnectDialog::_advanced_pressed); ClassDB::bind_method("_cancel", &ConnectDialog::_cancel_pressed); ClassDB::bind_method("_tree_node_selected", &ConnectDialog::_tree_node_selected); ClassDB::bind_method("_add_bind", &ConnectDialog::_add_bind); @@ -215,7 +226,7 @@ StringName ConnectDialog::get_signal_name() const { NodePath ConnectDialog::get_dst_path() const { - return dst_path->get_text(); + return dst_path; } void ConnectDialog::set_dst_node(Node *p_node) { @@ -272,8 +283,13 @@ void ConnectDialog::init(Connection c, bool bEdit) { tree->set_selected(NULL); tree->set_marked(source, true); - set_dst_node(static_cast(c.target)); - set_dst_method(c.method); + if (c.target) { + get_ok()->set_disabled(false); + set_dst_node(static_cast(c.target)); + set_dst_method(c.method); + } else { + get_ok()->set_disabled(true); + } bool bDeferred = (c.flags & CONNECT_DEFERRED) == CONNECT_DEFERRED; bool bOneshot = (c.flags & CONNECT_ONESHOT) == CONNECT_ONESHOT; @@ -288,6 +304,36 @@ void ConnectDialog::init(Connection c, bool bEdit) { bEditMode = bEdit; } +void ConnectDialog::popup_dialog(const String &p_for_signal, bool p_advanced) { + + advanced->set_pressed(p_advanced); + from_signal->set_text(p_for_signal); + error_label->add_color_override("font_color", get_color("error_color", "Editor")); + + if (p_advanced) { + + popup_centered(Size2(900, 500) * EDSCALE); + connect_to_label->set_text("Connect to Node:"); + tree->set_connect_to_script_mode(false); + error_label->hide(); + } else { + popup_centered(Size2(700, 500) * EDSCALE); + connect_to_label->set_text("Connect to Script:"); + tree->set_connect_to_script_mode(true); + + if (!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root())) { + error_label->show(); + } else { + error_label->hide(); + } + } +} + +void ConnectDialog::_advanced_pressed() { + vbc_right->set_visible(advanced->is_pressed()); + popup_dialog(from_signal->get_text(), advanced->is_pressed()); +} + ConnectDialog::ConnectDialog() { VBoxContainer *vbc = memnew(VBoxContainer); @@ -301,15 +347,27 @@ ConnectDialog::ConnectDialog() { main_hb->add_child(vbc_left); vbc_left->set_h_size_flags(SIZE_EXPAND_FILL); + from_signal = memnew(LineEdit); + from_signal->set_editable(false); + vbc_left->add_margin_child(TTR("From Signal:"), from_signal); + tree = memnew(SceneTreeEditor(false)); tree->get_scene_tree()->connect("item_activated", this, "_ok"); tree->connect("node_selected", this, "_tree_node_selected"); + tree->set_connect_to_script_mode(true); - vbc_left->add_margin_child(TTR("Connect To Node:"), tree, true); + Node *mc = vbc_left->add_margin_child(TTR("Connect To Script:"), tree, true); + connect_to_label = Object::cast_to