Skip to content

Commit caa2a38

Browse files
Serialization of Callable now works with bind and unbind at the same time
Removed exclusivity between unbind and bind in many places, both on display elements, connection dock and within serialization. A signal can now be connected with both unbound and bound arguments through the editor
1 parent 2a9ff39 commit caa2a38

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
@@ -185,22 +185,6 @@ void ConnectDialog::_focus_currently_connected() {
185185
tree->set_selected(source);
186186
}
187187

188-
void ConnectDialog::_unbind_count_changed(double p_count) {
189-
for (Control *control : bind_controls) {
190-
BaseButton *b = Object::cast_to<BaseButton>(control);
191-
if (b) {
192-
b->set_disabled(p_count > 0);
193-
}
194-
195-
EditorInspector *e = Object::cast_to<EditorInspector>(control);
196-
if (e) {
197-
e->set_read_only(p_count > 0);
198-
}
199-
}
200-
201-
append_source->set_disabled(p_count > 0);
202-
}
203-
204188
void ConnectDialog::_method_selected() {
205189
TreeItem *selected_item = method_tree->get_selected();
206190
dst_method->set_text(selected_item->get_metadata(0));
@@ -295,10 +279,9 @@ List<MethodInfo> ConnectDialog::_filter_method_list(const List<MethodInfo> &p_me
295279
PropertyInfo pi = p_signal.arguments[i];
296280
effective_args.push_back(Pair(pi.type, pi.class_name));
297281
}
298-
if (unbind == 0) {
299-
for (const Variant &variant : get_binds()) {
300-
effective_args.push_back(Pair(variant.get_type(), StringName()));
301-
}
282+
283+
for (const Variant &variant : get_binds()) {
284+
effective_args.push_back(Pair(variant.get_type(), StringName()));
302285
}
303286

304287
for (const MethodInfo &mi : p_methods) {
@@ -687,7 +670,6 @@ void ConnectDialog::init(const ConnectionData &p_cd, const PackedStringArray &p_
687670

688671
unbind_count->set_max(p_signal_args.size());
689672
unbind_count->set_value(p_cd.unbinds);
690-
_unbind_count_changed(p_cd.unbinds);
691673

692674
cdbinds->params.clear();
693675
cdbinds->params = p_cd.binds;
@@ -872,7 +854,6 @@ ConnectDialog::ConnectDialog() {
872854
unbind_count = memnew(SpinBox);
873855
unbind_count->set_tooltip_text(TTR("Allows to drop arguments sent by signal emitter."));
874856
unbind_count->set_accessibility_name(TTRC("Unbind Signal Arguments:"));
875-
unbind_count->connect(SceneStringName(value_changed), callable_mp(this, &ConnectDialog::_unbind_count_changed));
876857

877858
vbc_right->add_margin_child(TTR("Unbind Signal Arguments:"), unbind_count);
878859

@@ -963,9 +944,8 @@ void ConnectionsDock::_make_or_edit_connection() {
963944
cd.signal = connect_dialog->get_signal_name();
964945
cd.method = connect_dialog->get_dst_method_name();
965946
cd.unbinds = connect_dialog->get_unbinds();
966-
if (cd.unbinds == 0) {
967-
cd.binds = connect_dialog->get_binds();
968-
}
947+
cd.binds = connect_dialog->get_binds();
948+
969949
bool b_deferred = connect_dialog->get_deferred();
970950
bool b_oneshot = connect_dialog->get_one_shot();
971951
bool b_append_source = connect_dialog->get_append_source();
@@ -1639,7 +1619,8 @@ void ConnectionsDock::update_tree() {
16391619
}
16401620
if (cd.unbinds > 0) {
16411621
path += " unbinds(" + itos(cd.unbinds) + ")";
1642-
} else if (!cd.binds.is_empty()) {
1622+
}
1623+
if (!cd.binds.is_empty()) {
16431624
path += " binds(";
16441625
for (int i = 0; i < cd.binds.size(); i++) {
16451626
if (i > 0) {

editor/scene/connections_dialog.h

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

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

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

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

scene/resources/packed_scene.cpp

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

595595
Callable callable(cto, snames[c.method]);
596-
if (c.unbinds > 0) {
597-
callable = callable.unbind(c.unbinds);
598-
} else {
599-
Array binds;
600-
if (c.flags & CONNECT_APPEND_SOURCE_OBJECT) {
601-
binds.push_back(cfrom);
602-
}
603596

604-
if (!c.binds.is_empty()) {
605-
for (int j = 0; j < c.binds.size(); j++) {
606-
binds.push_back(props[c.binds[j]]);
607-
}
608-
}
597+
Array binds;
598+
if (c.flags & CONNECT_APPEND_SOURCE_OBJECT) {
599+
binds.push_back(cfrom);
600+
}
609601

610-
if (!binds.is_empty()) {
611-
callable = callable.bindv(binds);
612-
}
602+
for (int bind : c.binds) {
603+
binds.push_back(props[bind]);
604+
}
605+
606+
if (!binds.is_empty()) {
607+
callable = callable.bindv(binds);
608+
}
609+
610+
if (c.unbinds > 0) {
611+
callable = callable.unbind(c.unbinds);
613612
}
614613

615614
cfrom->connect(snames[c.signal], callable, CONNECT_PERSIST | c.flags | (p_edit_state == GEN_EDIT_STATE_MAIN ? 0 : CONNECT_INHERITED));
@@ -1083,20 +1082,22 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, HashMap<String
10831082
CallableCustomBind *ccb = dynamic_cast<CallableCustomBind *>(c.callable.get_custom());
10841083
if (ccb) {
10851084
binds = ccb->get_binds();
1086-
1087-
// The source object may already be bound, ignore it to avoid saving the source object.
1088-
if ((c.flags & CONNECT_APPEND_SOURCE_OBJECT) && (p_node == binds[0])) {
1089-
binds.remove_at(0);
1090-
}
1085+
unbinds = ccb->get_unbound_arguments_count();
10911086

10921087
base_callable = ccb->get_callable();
10931088
}
10941089

10951090
CallableCustomUnbind *ccu = dynamic_cast<CallableCustomUnbind *>(c.callable.get_custom());
10961091
if (ccu) {
1092+
ccu->get_bound_arguments(binds);
10971093
unbinds = ccu->get_unbinds();
10981094
base_callable = ccu->get_callable();
10991095
}
1096+
1097+
// The source object may already be bound, ignore it to avoid saving the source object.
1098+
if ((c.flags & CONNECT_APPEND_SOURCE_OBJECT) && (p_node == binds[0])) {
1099+
binds.remove_at(0);
1100+
}
11001101
} else {
11011102
base_callable = c.callable;
11021103
}

0 commit comments

Comments
 (0)