Skip to content

Commit 55bedbf

Browse files
committed
Merge pull request #108741 from AriaTheCurseling/Allow-concurrent-unbind-and-binding-of-signal-arguments-in-editor
Allow concurrent unbinding and binding of signal arguments in editor
2 parents 6a3d1f1 + caa2a38 commit 55bedbf

File tree

3 files changed

+45
-57
lines changed

3 files changed

+45
-57
lines changed

editor/scene/connections_dialog.cpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,6 @@ void ConnectDialog::_focus_currently_connected() {
219219
tree->set_selected(Object::cast_to<Node>(source));
220220
}
221221

222-
void ConnectDialog::_unbind_count_changed(double p_count) {
223-
for (Control *control : bind_controls) {
224-
BaseButton *b = Object::cast_to<BaseButton>(control);
225-
if (b) {
226-
b->set_disabled(p_count > 0);
227-
}
228-
229-
EditorInspector *e = Object::cast_to<EditorInspector>(control);
230-
if (e) {
231-
e->set_read_only(p_count > 0);
232-
}
233-
}
234-
235-
append_source->set_disabled(p_count > 0);
236-
}
237-
238222
void ConnectDialog::_method_selected() {
239223
TreeItem *selected_item = method_tree->get_selected();
240224
dst_method->set_text(selected_item->get_metadata(0));
@@ -330,10 +314,9 @@ List<MethodInfo> ConnectDialog::_filter_method_list(const List<MethodInfo> &p_me
330314
PropertyInfo pi = p_signal.arguments[i];
331315
effective_args.push_back(Pair(pi.type, pi.class_name));
332316
}
333-
if (unbind == 0) {
334-
for (const Variant &variant : get_binds()) {
335-
effective_args.push_back(Pair(variant.get_type(), StringName()));
336-
}
317+
318+
for (const Variant &variant : get_binds()) {
319+
effective_args.push_back(Pair(variant.get_type(), StringName()));
337320
}
338321

339322
for (const MethodInfo &mi : p_methods) {
@@ -723,7 +706,6 @@ void ConnectDialog::init(const ConnectionData &p_cd, const PackedStringArray &p_
723706

724707
unbind_count->set_max(p_signal_args.size());
725708
unbind_count->set_value(p_cd.unbinds);
726-
_unbind_count_changed(p_cd.unbinds);
727709

728710
cdbinds->params.clear();
729711
cdbinds->params = p_cd.binds;
@@ -909,7 +891,6 @@ ConnectDialog::ConnectDialog() {
909891
unbind_count = memnew(SpinBox);
910892
unbind_count->set_tooltip_text(TTR("Allows to drop arguments sent by signal emitter."));
911893
unbind_count->set_accessibility_name(TTRC("Unbind Signal Arguments:"));
912-
unbind_count->connect(SceneStringName(value_changed), callable_mp(this, &ConnectDialog::_unbind_count_changed));
913894

914895
vbc_right->add_margin_child(TTR("Unbind Signal Arguments:"), unbind_count);
915896

@@ -1001,9 +982,8 @@ void ConnectionsDock::_make_or_edit_connection() {
1001982
cd.signal = connect_dialog->get_signal_name();
1002983
cd.method = connect_dialog->get_dst_method_name();
1003984
cd.unbinds = connect_dialog->get_unbinds();
1004-
if (cd.unbinds == 0) {
1005-
cd.binds = connect_dialog->get_binds();
1006-
}
985+
cd.binds = connect_dialog->get_binds();
986+
1007987
bool b_deferred = connect_dialog->get_deferred();
1008988
bool b_oneshot = connect_dialog->get_one_shot();
1009989
bool b_append_source = connect_dialog->get_append_source();
@@ -1685,7 +1665,8 @@ void ConnectionsDock::update_tree() {
16851665
}
16861666
if (cd.unbinds > 0) {
16871667
path += " unbinds(" + itos(cd.unbinds) + ")";
1688-
} else if (!cd.binds.is_empty()) {
1668+
}
1669+
if (!cd.binds.is_empty()) {
16891670
path += " binds(";
16901671
for (int i = 0; i < cd.binds.size(); i++) {
16911672
if (i > 0) {

editor/scene/connections_dialog.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,38 +73,44 @@ class ConnectDialog : public ConfirmationDialog {
7373
CallableCustomBind *ccb = dynamic_cast<CallableCustomBind *>(p_connection.callable.get_custom());
7474
if (ccb) {
7575
binds = ccb->get_binds();
76-
77-
// The source object may already be bound, ignore it to prevent display of the source object.
78-
if ((flags & CONNECT_APPEND_SOURCE_OBJECT) && (source == binds[0])) {
79-
binds.remove_at(0);
80-
}
76+
unbinds = ccb->get_unbound_arguments_count();
8177

8278
base_callable = ccb->get_callable();
8379
}
8480

8581
CallableCustomUnbind *ccu = dynamic_cast<CallableCustomUnbind *>(p_connection.callable.get_custom());
8682
if (ccu) {
83+
ccu->get_bound_arguments(binds);
8784
unbinds = ccu->get_unbinds();
8885
base_callable = ccu->get_callable();
8986
}
87+
88+
// The source object may already be bound, ignore it to prevent display of the source object.
89+
if ((flags & CONNECT_APPEND_SOURCE_OBJECT) && (source == binds[0])) {
90+
binds.remove_at(0);
91+
}
9092
} else {
9193
base_callable = p_connection.callable;
9294
}
9395
method = base_callable.get_method();
9496
}
9597

9698
Callable get_callable() const {
97-
if (unbinds > 0) {
98-
return Callable(target, method).unbind(unbinds);
99-
} else if (!binds.is_empty()) {
99+
Callable callable = Callable(target, method);
100+
101+
if (!binds.is_empty()) {
100102
const Variant **argptrs = (const Variant **)alloca(sizeof(Variant *) * binds.size());
101103
for (int i = 0; i < binds.size(); i++) {
102104
argptrs[i] = &binds[i];
103105
}
104-
return Callable(target, method).bindp(argptrs, binds.size());
105-
} else {
106-
return Callable(target, method);
106+
callable = callable.bindp(argptrs, binds.size());
107107
}
108+
109+
if (unbinds > 0) {
110+
callable = callable.unbind(unbinds);
111+
}
112+
113+
return callable;
108114
}
109115
};
110116

scene/resources/packed_scene.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -663,23 +663,22 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
663663
}
664664

665665
Callable callable(cto, snames[c.method]);
666-
if (c.unbinds > 0) {
667-
callable = callable.unbind(c.unbinds);
668-
} else {
669-
Array binds;
670-
if (c.flags & CONNECT_APPEND_SOURCE_OBJECT) {
671-
binds.push_back(cfrom);
672-
}
673666

674-
if (!c.binds.is_empty()) {
675-
for (int j = 0; j < c.binds.size(); j++) {
676-
binds.push_back(props[c.binds[j]]);
677-
}
678-
}
667+
Array binds;
668+
if (c.flags & CONNECT_APPEND_SOURCE_OBJECT) {
669+
binds.push_back(cfrom);
670+
}
679671

680-
if (!binds.is_empty()) {
681-
callable = callable.bindv(binds);
682-
}
672+
for (int bind : c.binds) {
673+
binds.push_back(props[bind]);
674+
}
675+
676+
if (!binds.is_empty()) {
677+
callable = callable.bindv(binds);
678+
}
679+
680+
if (c.unbinds > 0) {
681+
callable = callable.unbind(c.unbinds);
683682
}
684683

685684
cfrom->connect(snames[c.signal], callable, CONNECT_PERSIST | c.flags | (p_edit_state == GEN_EDIT_STATE_MAIN ? 0 : CONNECT_INHERITED));
@@ -1179,20 +1178,22 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, HashMap<String
11791178
CallableCustomBind *ccb = dynamic_cast<CallableCustomBind *>(c.callable.get_custom());
11801179
if (ccb) {
11811180
binds = ccb->get_binds();
1182-
1183-
// The source object may already be bound, ignore it to avoid saving the source object.
1184-
if ((c.flags & CONNECT_APPEND_SOURCE_OBJECT) && (p_node == binds[0])) {
1185-
binds.remove_at(0);
1186-
}
1181+
unbinds = ccb->get_unbound_arguments_count();
11871182

11881183
base_callable = ccb->get_callable();
11891184
}
11901185

11911186
CallableCustomUnbind *ccu = dynamic_cast<CallableCustomUnbind *>(c.callable.get_custom());
11921187
if (ccu) {
1188+
ccu->get_bound_arguments(binds);
11931189
unbinds = ccu->get_unbinds();
11941190
base_callable = ccu->get_callable();
11951191
}
1192+
1193+
// The source object may already be bound, ignore it to avoid saving the source object.
1194+
if ((c.flags & CONNECT_APPEND_SOURCE_OBJECT) && (p_node == binds[0])) {
1195+
binds.remove_at(0);
1196+
}
11961197
} else {
11971198
base_callable = c.callable;
11981199
}

0 commit comments

Comments
 (0)