You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Merge pull request #71883 from MinusKube/script-editor-members-real-bug
Remove coupling between ConnectDialog and selected signal
This commit is contained in:
@@ -448,10 +448,18 @@ Node *ConnectDialog::get_source() const {
|
|||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConnectDialog::ConnectionData ConnectDialog::get_source_connection_data() const {
|
||||||
|
return source_connection_data;
|
||||||
|
}
|
||||||
|
|
||||||
StringName ConnectDialog::get_signal_name() const {
|
StringName ConnectDialog::get_signal_name() const {
|
||||||
return signal;
|
return signal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PackedStringArray ConnectDialog::get_signal_args() const {
|
||||||
|
return signal_args;
|
||||||
|
}
|
||||||
|
|
||||||
NodePath ConnectDialog::get_dst_path() const {
|
NodePath ConnectDialog::get_dst_path() const {
|
||||||
return dst_path;
|
return dst_path;
|
||||||
}
|
}
|
||||||
@@ -500,11 +508,12 @@ bool ConnectDialog::is_editing() const {
|
|||||||
* If creating a connection from scratch, sensible defaults are used.
|
* If creating a connection from scratch, sensible defaults are used.
|
||||||
* If editing an existing connection, previous data is retained.
|
* If editing an existing connection, previous data is retained.
|
||||||
*/
|
*/
|
||||||
void ConnectDialog::init(ConnectionData p_cd, bool p_edit) {
|
void ConnectDialog::init(const ConnectionData &p_cd, const PackedStringArray &p_signal_args, bool p_edit) {
|
||||||
set_hide_on_ok(false);
|
set_hide_on_ok(false);
|
||||||
|
|
||||||
source = static_cast<Node *>(p_cd.source);
|
source = static_cast<Node *>(p_cd.source);
|
||||||
signal = p_cd.signal;
|
signal = p_cd.signal;
|
||||||
|
signal_args = p_signal_args;
|
||||||
|
|
||||||
tree->set_selected(nullptr);
|
tree->set_selected(nullptr);
|
||||||
tree->set_marked(source, true);
|
tree->set_marked(source, true);
|
||||||
@@ -522,22 +531,7 @@ void ConnectDialog::init(ConnectionData p_cd, bool p_edit) {
|
|||||||
deferred->set_pressed(b_deferred);
|
deferred->set_pressed(b_deferred);
|
||||||
one_shot->set_pressed(b_oneshot);
|
one_shot->set_pressed(b_oneshot);
|
||||||
|
|
||||||
MethodInfo r_signal;
|
unbind_count->set_max(p_signal_args.size());
|
||||||
Ref<Script> source_script = source->get_script();
|
|
||||||
if (source_script.is_valid() && source_script->has_script_signal(signal)) {
|
|
||||||
List<MethodInfo> signals;
|
|
||||||
source_script->get_script_signal_list(&signals);
|
|
||||||
for (MethodInfo &mi : signals) {
|
|
||||||
if (mi.name == signal) {
|
|
||||||
r_signal = mi;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ClassDB::get_signal(source->get_class(), signal, &r_signal);
|
|
||||||
}
|
|
||||||
|
|
||||||
unbind_count->set_max(r_signal.arguments.size());
|
|
||||||
|
|
||||||
unbind_count->set_value(p_cd.unbinds);
|
unbind_count->set_value(p_cd.unbinds);
|
||||||
_unbind_count_changed(p_cd.unbinds);
|
_unbind_count_changed(p_cd.unbinds);
|
||||||
@@ -547,6 +541,8 @@ void ConnectDialog::init(ConnectionData p_cd, bool p_edit) {
|
|||||||
cdbinds->notify_changed();
|
cdbinds->notify_changed();
|
||||||
|
|
||||||
edit_mode = p_edit;
|
edit_mode = p_edit;
|
||||||
|
|
||||||
|
source_connection_data = p_cd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectDialog::popup_dialog(const String &p_for_signal) {
|
void ConnectDialog::popup_dialog(const String &p_for_signal) {
|
||||||
@@ -794,9 +790,6 @@ void ConnectionsDock::_filter_changed(const String &p_text) {
|
|||||||
* Creates or edits connections based on state of the ConnectDialog when "Connect" is pressed.
|
* Creates or edits connections based on state of the ConnectDialog when "Connect" is pressed.
|
||||||
*/
|
*/
|
||||||
void ConnectionsDock::_make_or_edit_connection() {
|
void ConnectionsDock::_make_or_edit_connection() {
|
||||||
TreeItem *it = tree->get_selected();
|
|
||||||
ERR_FAIL_COND(!it);
|
|
||||||
|
|
||||||
NodePath dst_path = connect_dialog->get_dst_path();
|
NodePath dst_path = connect_dialog->get_dst_path();
|
||||||
Node *target = selected_node->get_node(dst_path);
|
Node *target = selected_node->get_node(dst_path);
|
||||||
ERR_FAIL_COND(!target);
|
ERR_FAIL_COND(!target);
|
||||||
@@ -834,27 +827,21 @@ void ConnectionsDock::_make_or_edit_connection() {
|
|||||||
|
|
||||||
add_script_function = !found_inherited_function;
|
add_script_function = !found_inherited_function;
|
||||||
}
|
}
|
||||||
PackedStringArray script_function_args;
|
|
||||||
if (add_script_function) {
|
|
||||||
// Pick up args here before "it" is deleted by update_tree.
|
|
||||||
script_function_args = it->get_metadata(0).operator Dictionary()["args"];
|
|
||||||
script_function_args.resize(script_function_args.size() - cd.unbinds);
|
|
||||||
for (int i = 0; i < cd.binds.size(); i++) {
|
|
||||||
script_function_args.push_back("extra_arg_" + itos(i) + ":" + Variant::get_type_name(cd.binds[i].get_type()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connect_dialog->is_editing()) {
|
if (connect_dialog->is_editing()) {
|
||||||
_disconnect(*it);
|
_disconnect(connect_dialog->get_source_connection_data());
|
||||||
_connect(cd);
|
_connect(cd);
|
||||||
} else {
|
} else {
|
||||||
_connect(cd);
|
_connect(cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMPORTANT NOTE: _disconnect and _connect cause an update_tree, which will delete the object "it" is pointing to.
|
|
||||||
it = nullptr;
|
|
||||||
|
|
||||||
if (add_script_function) {
|
if (add_script_function) {
|
||||||
|
PackedStringArray script_function_args = connect_dialog->get_signal_args();
|
||||||
|
script_function_args.resize(script_function_args.size() - cd.unbinds);
|
||||||
|
for (int i = 0; i < cd.binds.size(); i++) {
|
||||||
|
script_function_args.push_back("extra_arg_" + itos(i) + ":" + Variant::get_type_name(cd.binds[i].get_type()));
|
||||||
|
}
|
||||||
|
|
||||||
EditorNode::get_singleton()->emit_signal(SNAME("script_add_function_request"), target, cd.method, script_function_args);
|
EditorNode::get_singleton()->emit_signal(SNAME("script_add_function_request"), target, cd.method, script_function_args);
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
@@ -865,7 +852,7 @@ void ConnectionsDock::_make_or_edit_connection() {
|
|||||||
/*
|
/*
|
||||||
* Creates single connection w/ undo-redo functionality.
|
* Creates single connection w/ undo-redo functionality.
|
||||||
*/
|
*/
|
||||||
void ConnectionsDock::_connect(ConnectDialog::ConnectionData p_cd) {
|
void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {
|
||||||
Node *source = Object::cast_to<Node>(p_cd.source);
|
Node *source = Object::cast_to<Node>(p_cd.source);
|
||||||
Node *target = Object::cast_to<Node>(p_cd.target);
|
Node *target = Object::cast_to<Node>(p_cd.target);
|
||||||
|
|
||||||
@@ -889,18 +876,15 @@ void ConnectionsDock::_connect(ConnectDialog::ConnectionData p_cd) {
|
|||||||
/*
|
/*
|
||||||
* Break single connection w/ undo-redo functionality.
|
* Break single connection w/ undo-redo functionality.
|
||||||
*/
|
*/
|
||||||
void ConnectionsDock::_disconnect(TreeItem &p_item) {
|
void ConnectionsDock::_disconnect(const ConnectDialog::ConnectionData &p_cd) {
|
||||||
Connection connection = p_item.get_metadata(0);
|
ERR_FAIL_COND(p_cd.source != selected_node); // Shouldn't happen but... Bugcheck.
|
||||||
ConnectDialog::ConnectionData cd = connection;
|
|
||||||
|
|
||||||
ERR_FAIL_COND(cd.source != selected_node); // Shouldn't happen but... Bugcheck.
|
|
||||||
|
|
||||||
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
||||||
undo_redo->create_action(vformat(TTR("Disconnect '%s' from '%s'"), cd.signal, cd.method));
|
undo_redo->create_action(vformat(TTR("Disconnect '%s' from '%s'"), p_cd.signal, p_cd.method));
|
||||||
|
|
||||||
Callable callable = cd.get_callable();
|
Callable callable = p_cd.get_callable();
|
||||||
undo_redo->add_do_method(selected_node, "disconnect", cd.signal, callable);
|
undo_redo->add_do_method(selected_node, "disconnect", p_cd.signal, callable);
|
||||||
undo_redo->add_undo_method(selected_node, "connect", cd.signal, callable, cd.binds, cd.flags);
|
undo_redo->add_undo_method(selected_node, "connect", p_cd.signal, callable, p_cd.flags);
|
||||||
undo_redo->add_do_method(this, "update_tree");
|
undo_redo->add_do_method(this, "update_tree");
|
||||||
undo_redo->add_undo_method(this, "update_tree");
|
undo_redo->add_undo_method(this, "update_tree");
|
||||||
undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
|
undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
|
||||||
@@ -930,7 +914,7 @@ void ConnectionsDock::_disconnect_all() {
|
|||||||
if (!_is_connection_inherited(connection)) {
|
if (!_is_connection_inherited(connection)) {
|
||||||
ConnectDialog::ConnectionData cd = connection;
|
ConnectDialog::ConnectionData cd = connection;
|
||||||
undo_redo->add_do_method(selected_node, "disconnect", cd.signal, cd.get_callable());
|
undo_redo->add_do_method(selected_node, "disconnect", cd.signal, cd.get_callable());
|
||||||
undo_redo->add_undo_method(selected_node, "connect", cd.signal, cd.get_callable(), cd.binds, cd.flags);
|
undo_redo->add_undo_method(selected_node, "connect", cd.signal, cd.get_callable(), cd.flags);
|
||||||
}
|
}
|
||||||
child = child->get_next();
|
child = child->get_next();
|
||||||
}
|
}
|
||||||
@@ -984,7 +968,10 @@ bool ConnectionsDock::_is_connection_inherited(Connection &p_connection) {
|
|||||||
* Open connection dialog with TreeItem data to CREATE a brand-new connection.
|
* Open connection dialog with TreeItem data to CREATE a brand-new connection.
|
||||||
*/
|
*/
|
||||||
void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {
|
void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {
|
||||||
String signal_name = p_item.get_metadata(0).operator Dictionary()["name"];
|
Dictionary sinfo = p_item.get_metadata(0);
|
||||||
|
String signal_name = sinfo["name"];
|
||||||
|
PackedStringArray signal_args = sinfo["args"];
|
||||||
|
|
||||||
const String &signal_name_ref = signal_name;
|
const String &signal_name_ref = signal_name;
|
||||||
|
|
||||||
Node *dst_node = selected_node->get_owner() ? selected_node->get_owner() : selected_node;
|
Node *dst_node = selected_node->get_owner() ? selected_node->get_owner() : selected_node;
|
||||||
@@ -998,22 +985,30 @@ void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {
|
|||||||
cd.target = dst_node;
|
cd.target = dst_node;
|
||||||
cd.method = ConnectDialog::generate_method_callback_name(cd.source, signal_name, cd.target);
|
cd.method = ConnectDialog::generate_method_callback_name(cd.source, signal_name, cd.target);
|
||||||
connect_dialog->popup_dialog(signal_name_ref);
|
connect_dialog->popup_dialog(signal_name_ref);
|
||||||
connect_dialog->init(cd);
|
connect_dialog->init(cd, signal_args);
|
||||||
connect_dialog->set_title(TTR("Connect a Signal to a Method"));
|
connect_dialog->set_title(TTR("Connect a Signal to a Method"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open connection dialog with Connection data to EDIT an existing connection.
|
* Open connection dialog with Connection data to EDIT an existing connection.
|
||||||
*/
|
*/
|
||||||
void ConnectionsDock::_open_connection_dialog(ConnectDialog::ConnectionData p_cd) {
|
void ConnectionsDock::_open_edit_connection_dialog(TreeItem &p_item) {
|
||||||
Node *src = Object::cast_to<Node>(p_cd.source);
|
TreeItem *signal_item = p_item.get_parent();
|
||||||
Node *dst = Object::cast_to<Node>(p_cd.target);
|
ERR_FAIL_COND(!signal_item);
|
||||||
|
|
||||||
|
Connection connection = p_item.get_metadata(0);
|
||||||
|
ConnectDialog::ConnectionData cd = connection;
|
||||||
|
|
||||||
|
Node *src = Object::cast_to<Node>(cd.source);
|
||||||
|
Node *dst = Object::cast_to<Node>(cd.target);
|
||||||
|
|
||||||
if (src && dst) {
|
if (src && dst) {
|
||||||
const String &signal_name_ref = p_cd.signal;
|
const String &signal_name_ref = cd.signal;
|
||||||
connect_dialog->set_title(TTR("Edit Connection:") + p_cd.signal);
|
PackedStringArray signal_args = signal_item->get_metadata(0).operator Dictionary()["args"];
|
||||||
|
|
||||||
|
connect_dialog->set_title(vformat(TTR("Edit Connection: '%s'"), cd.signal));
|
||||||
connect_dialog->popup_dialog(signal_name_ref);
|
connect_dialog->popup_dialog(signal_name_ref);
|
||||||
connect_dialog->init(p_cd, true);
|
connect_dialog->init(cd, signal_args, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1088,14 +1083,14 @@ void ConnectionsDock::_handle_slot_menu_option(int p_option) {
|
|||||||
|
|
||||||
switch (p_option) {
|
switch (p_option) {
|
||||||
case EDIT: {
|
case EDIT: {
|
||||||
Connection connection = item->get_metadata(0);
|
_open_edit_connection_dialog(*item);
|
||||||
_open_connection_dialog(connection);
|
|
||||||
} break;
|
} break;
|
||||||
case GO_TO_SCRIPT: {
|
case GO_TO_SCRIPT: {
|
||||||
_go_to_script(*item);
|
_go_to_script(*item);
|
||||||
} break;
|
} break;
|
||||||
case DISCONNECT: {
|
case DISCONNECT: {
|
||||||
_disconnect(*item);
|
Connection connection = item->get_metadata(0);
|
||||||
|
_disconnect(connection);
|
||||||
update_tree();
|
update_tree();
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
@@ -1146,7 +1141,8 @@ void ConnectionsDock::_connect_pressed() {
|
|||||||
if (_is_item_signal(*item)) {
|
if (_is_item_signal(*item)) {
|
||||||
_open_connection_dialog(*item);
|
_open_connection_dialog(*item);
|
||||||
} else {
|
} else {
|
||||||
_disconnect(*item);
|
Connection connection = item->get_metadata(0);
|
||||||
|
_disconnect(connection);
|
||||||
update_tree();
|
update_tree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public:
|
|||||||
method = base_callable.get_method();
|
method = base_callable.get_method();
|
||||||
}
|
}
|
||||||
|
|
||||||
Callable get_callable() {
|
Callable get_callable() const {
|
||||||
if (unbinds > 0) {
|
if (unbinds > 0) {
|
||||||
return Callable(target, method).unbind(unbinds);
|
return Callable(target, method).unbind(unbinds);
|
||||||
} else if (!binds.is_empty()) {
|
} else if (!binds.is_empty()) {
|
||||||
@@ -107,7 +107,9 @@ private:
|
|||||||
Label *connect_to_label = nullptr;
|
Label *connect_to_label = nullptr;
|
||||||
LineEdit *from_signal = nullptr;
|
LineEdit *from_signal = nullptr;
|
||||||
Node *source = nullptr;
|
Node *source = nullptr;
|
||||||
|
ConnectionData source_connection_data;
|
||||||
StringName signal;
|
StringName signal;
|
||||||
|
PackedStringArray signal_args;
|
||||||
LineEdit *dst_method = nullptr;
|
LineEdit *dst_method = nullptr;
|
||||||
ConnectDialogBinds *cdbinds = nullptr;
|
ConnectDialogBinds *cdbinds = nullptr;
|
||||||
bool edit_mode = false;
|
bool edit_mode = false;
|
||||||
@@ -161,7 +163,9 @@ protected:
|
|||||||
public:
|
public:
|
||||||
static StringName generate_method_callback_name(Node *p_source, String p_signal_name, Node *p_target);
|
static StringName generate_method_callback_name(Node *p_source, String p_signal_name, Node *p_target);
|
||||||
Node *get_source() const;
|
Node *get_source() const;
|
||||||
|
ConnectionData get_source_connection_data() const;
|
||||||
StringName get_signal_name() const;
|
StringName get_signal_name() const;
|
||||||
|
PackedStringArray get_signal_args() const;
|
||||||
NodePath get_dst_path() const;
|
NodePath get_dst_path() const;
|
||||||
void set_dst_node(Node *p_node);
|
void set_dst_node(Node *p_node);
|
||||||
StringName get_dst_method_name() const;
|
StringName get_dst_method_name() const;
|
||||||
@@ -173,7 +177,7 @@ public:
|
|||||||
bool get_one_shot() const;
|
bool get_one_shot() const;
|
||||||
bool is_editing() const;
|
bool is_editing() const;
|
||||||
|
|
||||||
void init(ConnectionData p_cd, bool p_edit = false);
|
void init(const ConnectionData &p_cd, const PackedStringArray &p_signal_args, bool p_edit = false);
|
||||||
|
|
||||||
void popup_dialog(const String &p_for_signal);
|
void popup_dialog(const String &p_for_signal);
|
||||||
ConnectDialog();
|
ConnectDialog();
|
||||||
@@ -219,8 +223,8 @@ class ConnectionsDock : public VBoxContainer {
|
|||||||
void _filter_changed(const String &p_text);
|
void _filter_changed(const String &p_text);
|
||||||
|
|
||||||
void _make_or_edit_connection();
|
void _make_or_edit_connection();
|
||||||
void _connect(ConnectDialog::ConnectionData p_cd);
|
void _connect(const ConnectDialog::ConnectionData &p_cd);
|
||||||
void _disconnect(TreeItem &p_item);
|
void _disconnect(const ConnectDialog::ConnectionData &p_cd);
|
||||||
void _disconnect_all();
|
void _disconnect_all();
|
||||||
|
|
||||||
void _tree_item_selected();
|
void _tree_item_selected();
|
||||||
@@ -229,7 +233,7 @@ class ConnectionsDock : public VBoxContainer {
|
|||||||
bool _is_connection_inherited(Connection &p_connection);
|
bool _is_connection_inherited(Connection &p_connection);
|
||||||
|
|
||||||
void _open_connection_dialog(TreeItem &p_item);
|
void _open_connection_dialog(TreeItem &p_item);
|
||||||
void _open_connection_dialog(ConnectDialog::ConnectionData p_cd);
|
void _open_edit_connection_dialog(TreeItem &p_item);
|
||||||
void _go_to_script(TreeItem &p_item);
|
void _go_to_script(TreeItem &p_item);
|
||||||
|
|
||||||
void _handle_signal_menu_option(int p_option);
|
void _handle_signal_menu_option(int p_option);
|
||||||
|
|||||||
Reference in New Issue
Block a user