1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-13 13:31:48 +00:00

Reworked signal connection system, added support for Callable and Signal objects and made them default.

This commit is contained in:
Juan Linietsky
2020-02-19 16:27:19 -03:00
committed by Juan Linietsky
parent 1a4be2cd8f
commit 69c95f4b4c
275 changed files with 3831 additions and 2948 deletions

View File

@@ -304,7 +304,7 @@ bool ConnectDialog::is_editing() const {
* If creating a connection from scratch, sensible defaults are used.
* If editing an existing connection, previous data is retained.
*/
void ConnectDialog::init(Connection c, bool bEdit) {
void ConnectDialog::init(ConnectionData c, bool bEdit) {
set_hide_on_ok(false);
@@ -389,8 +389,8 @@ ConnectDialog::ConnectDialog() {
tree = memnew(SceneTreeEditor(false));
tree->set_connecting_signal(true);
tree->get_scene_tree()->connect("item_activated", this, "_ok");
tree->connect("node_selected", this, "_tree_node_selected");
tree->get_scene_tree()->connect_compat("item_activated", this, "_ok");
tree->connect_compat("node_selected", this, "_tree_node_selected");
tree->set_connect_to_script_mode(true);
Node *mc = vbc_left->add_margin_child(TTR("Connect to Script:"), tree, true);
@@ -429,12 +429,12 @@ ConnectDialog::ConnectDialog() {
Button *add_bind = memnew(Button);
add_bind->set_text(TTR("Add"));
add_bind_hb->add_child(add_bind);
add_bind->connect("pressed", this, "_add_bind");
add_bind->connect_compat("pressed", this, "_add_bind");
Button *del_bind = memnew(Button);
del_bind->set_text(TTR("Remove"));
add_bind_hb->add_child(del_bind);
del_bind->connect("pressed", this, "_remove_bind");
del_bind->connect_compat("pressed", this, "_remove_bind");
vbc_right->add_margin_child(TTR("Add Extra Call Argument:"), add_bind_hb);
@@ -447,13 +447,13 @@ ConnectDialog::ConnectDialog() {
dst_method = memnew(LineEdit);
dst_method->set_h_size_flags(SIZE_EXPAND_FILL);
dst_method->connect("text_entered", this, "_builtin_text_entered");
dst_method->connect_compat("text_entered", this, "_builtin_text_entered");
dstm_hb->add_child(dst_method);
advanced = memnew(CheckButton);
dstm_hb->add_child(advanced);
advanced->set_text(TTR("Advanced"));
advanced->connect("pressed", this, "_advanced_pressed");
advanced->connect_compat("pressed", this, "_advanced_pressed");
// Add spacing so the tree and inspector are the same size.
Control *spacing = memnew(Control);
@@ -525,7 +525,7 @@ void ConnectionsDock::_make_or_edit_connection() {
Node *target = selectedNode->get_node(dst_path);
ERR_FAIL_COND(!target);
Connection cToMake;
ConnectDialog::ConnectionData cToMake;
cToMake.source = connect_dialog->get_source();
cToMake.target = target;
cToMake.signal = connect_dialog->get_signal_name();
@@ -585,7 +585,7 @@ void ConnectionsDock::_make_or_edit_connection() {
/*
* Creates single connection w/ undo-redo functionality.
*/
void ConnectionsDock::_connect(Connection cToMake) {
void ConnectionsDock::_connect(ConnectDialog::ConnectionData cToMake) {
Node *source = static_cast<Node *>(cToMake.source);
Node *target = static_cast<Node *>(cToMake.target);
@@ -595,8 +595,10 @@ void ConnectionsDock::_connect(Connection cToMake) {
undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), String(cToMake.signal), String(cToMake.method)));
undo_redo->add_do_method(source, "connect", cToMake.signal, target, cToMake.method, cToMake.binds, cToMake.flags);
undo_redo->add_undo_method(source, "disconnect", cToMake.signal, target, cToMake.method);
Callable c(target, cToMake.method);
undo_redo->add_do_method(source, "connect", cToMake.signal, c, cToMake.binds, cToMake.flags);
undo_redo->add_undo_method(source, "disconnect", cToMake.signal, c);
undo_redo->add_do_method(this, "update_tree");
undo_redo->add_undo_method(this, "update_tree");
undo_redo->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); //to force redraw of scene tree
@@ -610,13 +612,15 @@ void ConnectionsDock::_connect(Connection cToMake) {
*/
void ConnectionsDock::_disconnect(TreeItem &item) {
Connection c = item.get_metadata(0);
Connection cd = item.get_metadata(0);
ConnectDialog::ConnectionData c = cd;
ERR_FAIL_COND(c.source != selectedNode); // Shouldn't happen but... Bugcheck.
undo_redo->create_action(vformat(TTR("Disconnect '%s' from '%s'"), c.signal, c.method));
undo_redo->add_do_method(selectedNode, "disconnect", c.signal, c.target, c.method);
undo_redo->add_undo_method(selectedNode, "connect", c.signal, c.target, c.method, c.binds, c.flags);
undo_redo->add_do_method(selectedNode, "disconnect", c.signal, Callable(c.target, c.method));
undo_redo->add_undo_method(selectedNode, "connect", c.signal, Callable(c.target, c.method), c.binds, c.flags);
undo_redo->add_do_method(this, "update_tree");
undo_redo->add_undo_method(this, "update_tree");
undo_redo->add_do_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
@@ -641,9 +645,10 @@ void ConnectionsDock::_disconnect_all() {
undo_redo->create_action(vformat(TTR("Disconnect all from signal: '%s'"), signalName));
while (child) {
Connection c = child->get_metadata(0);
undo_redo->add_do_method(selectedNode, "disconnect", c.signal, c.target, c.method);
undo_redo->add_undo_method(selectedNode, "connect", c.signal, c.target, c.method, c.binds, c.flags);
Connection cd = child->get_metadata(0);
ConnectDialog::ConnectionData c = cd;
undo_redo->add_do_method(selectedNode, "disconnect", c.signal, Callable(c.target, c.method));
undo_redo->add_undo_method(selectedNode, "connect", c.signal, Callable(c.target, c.method), c.binds, c.flags);
child = child->get_next();
}
@@ -720,7 +725,7 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
StringName dst_method = "_on_" + midname + "_" + signal;
Connection c;
ConnectDialog::ConnectionData c;
c.source = selectedNode;
c.signal = StringName(signalname);
c.target = dst_node;
@@ -733,7 +738,7 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &item) {
/*
* Open connection dialog with Connection data to EDIT an existing connection.
*/
void ConnectionsDock::_open_connection_dialog(Connection cToEdit) {
void ConnectionsDock::_open_connection_dialog(ConnectDialog::ConnectionData cToEdit) {
Node *src = static_cast<Node *>(cToEdit.source);
Node *dst = static_cast<Node *>(cToEdit.target);
@@ -753,7 +758,8 @@ void ConnectionsDock::_go_to_script(TreeItem &item) {
if (_is_item_signal(item))
return;
Connection c = item.get_metadata(0);
Connection cd = item.get_metadata(0);
ConnectDialog::ConnectionData c = cd;
ERR_FAIL_COND(c.source != selectedNode); //shouldn't happen but...bugcheck
if (!c.target)
@@ -1014,7 +1020,7 @@ void ConnectionsDock::update_tree() {
for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) {
Object::Connection &c = F->get();
ConnectDialog::ConnectionData c = F->get();
if (!(c.flags & CONNECT_PERSIST))
continue;
@@ -1041,7 +1047,8 @@ void ConnectionsDock::update_tree() {
TreeItem *item2 = tree->create_item(item);
item2->set_text(0, path);
item2->set_metadata(0, c);
Connection cd = c;
item2->set_metadata(0, cd);
item2->set_icon(0, get_icon("Slot", "EditorIcons"));
}
}
@@ -1077,7 +1084,7 @@ ConnectionsDock::ConnectionsDock(EditorNode *p_editor) {
vbc->add_child(hb);
hb->add_spacer();
hb->add_child(connect_button);
connect_button->connect("pressed", this, "_connect_pressed");
connect_button->connect_compat("pressed", this, "_connect_pressed");
connect_dialog = memnew(ConnectDialog);
connect_dialog->set_as_toplevel(true);
@@ -1086,26 +1093,26 @@ ConnectionsDock::ConnectionsDock(EditorNode *p_editor) {
disconnect_all_dialog = memnew(ConfirmationDialog);
disconnect_all_dialog->set_as_toplevel(true);
add_child(disconnect_all_dialog);
disconnect_all_dialog->connect("confirmed", this, "_disconnect_all");
disconnect_all_dialog->connect_compat("confirmed", this, "_disconnect_all");
disconnect_all_dialog->set_text(TTR("Are you sure you want to remove all connections from this signal?"));
signal_menu = memnew(PopupMenu);
add_child(signal_menu);
signal_menu->connect("id_pressed", this, "_handle_signal_menu_option");
signal_menu->connect_compat("id_pressed", this, "_handle_signal_menu_option");
signal_menu->add_item(TTR("Connect..."), CONNECT);
signal_menu->add_item(TTR("Disconnect All"), DISCONNECT_ALL);
slot_menu = memnew(PopupMenu);
add_child(slot_menu);
slot_menu->connect("id_pressed", this, "_handle_slot_menu_option");
slot_menu->connect_compat("id_pressed", this, "_handle_slot_menu_option");
slot_menu->add_item(TTR("Edit..."), EDIT);
slot_menu->add_item(TTR("Go To Method"), GO_TO_SCRIPT);
slot_menu->add_item(TTR("Disconnect"), DISCONNECT);
connect_dialog->connect("connected", this, "_make_or_edit_connection");
tree->connect("item_selected", this, "_tree_item_selected");
tree->connect("item_activated", this, "_tree_item_activated");
tree->connect("item_rmb_selected", this, "_rmb_pressed");
connect_dialog->connect_compat("connected", this, "_make_or_edit_connection");
tree->connect_compat("item_selected", this, "_tree_item_selected");
tree->connect_compat("item_activated", this, "_tree_item_activated");
tree->connect_compat("item_rmb_selected", this, "_rmb_pressed");
add_constant_override("separation", 3 * EDSCALE);
}