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
This commit is contained in:
@ -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<Node *>(c.target));
|
||||
set_dst_method(c.method);
|
||||
if (c.target) {
|
||||
get_ok()->set_disabled(false);
|
||||
set_dst_node(static_cast<Node *>(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<Label>(vbc_left->get_child(mc->get_index() - 1));
|
||||
|
||||
VBoxContainer *vbc_right = memnew(VBoxContainer);
|
||||
error_label = memnew(Label);
|
||||
error_label->set_text(TTR("Scene does not contain any script."));
|
||||
vbc_left->add_child(error_label);
|
||||
error_label->hide();
|
||||
|
||||
vbc_right = memnew(VBoxContainer);
|
||||
main_hb->add_child(vbc_right);
|
||||
vbc_right->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
vbc_right->hide();
|
||||
|
||||
HBoxContainer *add_bind_hb = memnew(HBoxContainer);
|
||||
|
||||
@ -347,16 +405,18 @@ ConnectDialog::ConnectDialog() {
|
||||
|
||||
vbc_right->add_margin_child(TTR("Extra Call Arguments:"), bind_editor, true);
|
||||
|
||||
dst_path = memnew(LineEdit);
|
||||
vbc->add_margin_child(TTR("Path to Node:"), dst_path);
|
||||
|
||||
HBoxContainer *dstm_hb = memnew(HBoxContainer);
|
||||
vbc->add_margin_child("Method In Node:", dstm_hb);
|
||||
vbc_left->add_margin_child("Method to Create:", dstm_hb);
|
||||
|
||||
dst_method = memnew(LineEdit);
|
||||
dst_method->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
dstm_hb->add_child(dst_method);
|
||||
|
||||
advanced = memnew(CheckBox);
|
||||
dstm_hb->add_child(advanced);
|
||||
advanced->set_text(TTR("Advanced.."));
|
||||
advanced->connect("pressed", this, "_advanced_pressed");
|
||||
|
||||
/*
|
||||
dst_method_list = memnew( MenuButton );
|
||||
dst_method_list->set_text("List...");
|
||||
@ -368,19 +428,13 @@ ConnectDialog::ConnectDialog() {
|
||||
dst_method_list->set_end( Point2( 15,39 ) );
|
||||
*/
|
||||
|
||||
make_callback = memnew(CheckButton);
|
||||
make_callback->set_toggle_mode(true);
|
||||
make_callback->set_pressed(EDITOR_DEF("text_editor/tools/create_signal_callbacks", true));
|
||||
make_callback->set_text(TTR("Make Function"));
|
||||
dstm_hb->add_child(make_callback);
|
||||
|
||||
deferred = memnew(CheckButton);
|
||||
deferred->set_text(TTR("Deferred"));
|
||||
dstm_hb->add_child(deferred);
|
||||
vbc_right->add_child(deferred);
|
||||
|
||||
oneshot = memnew(CheckButton);
|
||||
oneshot->set_text(TTR("Oneshot"));
|
||||
dstm_hb->add_child(oneshot);
|
||||
vbc_right->add_child(oneshot);
|
||||
|
||||
set_as_toplevel(true);
|
||||
|
||||
@ -429,7 +483,8 @@ void ConnectionsDock::_make_or_edit_connection() {
|
||||
bool oshot = connect_dialog->get_oneshot();
|
||||
cToMake.flags = CONNECT_PERSIST | (defer ? CONNECT_DEFERRED : 0) | (oshot ? CONNECT_ONESHOT : 0);
|
||||
|
||||
bool add_script_function = connect_dialog->get_make_callback();
|
||||
//conditions to add function, must have a script and must have a method
|
||||
bool add_script_function = !target->get_script().is_null() && !ClassDB::has_method(target->get_class(), cToMake.method);
|
||||
PoolStringArray script_function_args;
|
||||
if (add_script_function) {
|
||||
// pick up args here before "it" is deleted by update_tree
|
||||
@ -568,6 +623,7 @@ bool ConnectionsDock::_is_item_signal(TreeItem &item) {
|
||||
/*
|
||||
Open connection dialog with TreeItem data to CREATE a brand-new connection.
|
||||
*/
|
||||
|
||||
void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
|
||||
|
||||
String signal = item.get_metadata(0).operator Dictionary()["name"];
|
||||
@ -590,6 +646,10 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
|
||||
}
|
||||
|
||||
Node *dst_node = selectedNode->get_owner() ? selectedNode->get_owner() : selectedNode;
|
||||
if (!dst_node || dst_node->get_script().is_null()) {
|
||||
dst_node = _find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root());
|
||||
}
|
||||
|
||||
StringName dst_method = "_on_" + midname + "_" + signal;
|
||||
|
||||
Connection c;
|
||||
@ -598,9 +658,10 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
|
||||
c.target = dst_node;
|
||||
c.method = dst_method;
|
||||
|
||||
//connect_dialog->set_title(TTR("Connect Signal: ") + signalname);
|
||||
connect_dialog->popup_dialog(signalname, false);
|
||||
connect_dialog->init(c);
|
||||
connect_dialog->set_title(TTR("Connect Signal: ") + signalname);
|
||||
connect_dialog->popup_centered_ratio();
|
||||
connect_dialog->set_title(TTR("Connect a Signal to a Method"));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -612,9 +673,9 @@ void ConnectionsDock::_open_connection_dialog(Connection cToEdit) {
|
||||
Node *dst = static_cast<Node *>(cToEdit.target);
|
||||
|
||||
if (src && dst) {
|
||||
connect_dialog->init(cToEdit, true);
|
||||
connect_dialog->set_title(TTR("Edit Connection: ") + cToEdit.signal);
|
||||
connect_dialog->set_title(TTR("Edit Connection:") + cToEdit.signal);
|
||||
connect_dialog->popup_centered_ratio();
|
||||
connect_dialog->init(cToEdit, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user