|
46 | 46 | #include "editor/themes/editor_scale.h" |
47 | 47 | #include "scene/gui/button.h" |
48 | 48 | #include "scene/gui/check_box.h" |
| 49 | +#include "scene/gui/flow_container.h" |
49 | 50 | #include "scene/gui/label.h" |
50 | 51 | #include "scene/gui/line_edit.h" |
51 | 52 | #include "scene/gui/margin_container.h" |
@@ -195,6 +196,8 @@ void ConnectDialog::_unbind_count_changed(double p_count) { |
195 | 196 | e->set_read_only(p_count > 0); |
196 | 197 | } |
197 | 198 | } |
| 199 | + |
| 200 | + append_source->set_disabled(p_count > 0); |
198 | 201 | } |
199 | 202 |
|
200 | 203 | void ConnectDialog::_method_selected() { |
@@ -626,6 +629,10 @@ bool ConnectDialog::get_one_shot() const { |
626 | 629 | return one_shot->is_pressed(); |
627 | 630 | } |
628 | 631 |
|
| 632 | +bool ConnectDialog::get_append_source() const { |
| 633 | + return !append_source->is_disabled() && append_source->is_pressed(); |
| 634 | +} |
| 635 | + |
629 | 636 | /* |
630 | 637 | * Returns true if ConnectDialog is being used to edit an existing connection. |
631 | 638 | */ |
@@ -667,14 +674,15 @@ void ConnectDialog::init(const ConnectionData &p_cd, const PackedStringArray &p_ |
667 | 674 |
|
668 | 675 | _update_ok_enabled(); |
669 | 676 |
|
670 | | - bool b_deferred = (p_cd.flags & CONNECT_DEFERRED) == CONNECT_DEFERRED; |
671 | | - bool b_oneshot = (p_cd.flags & CONNECT_ONE_SHOT) == CONNECT_ONE_SHOT; |
| 677 | + bool b_deferred = (p_cd.flags & CONNECT_DEFERRED); |
| 678 | + bool b_oneshot = (p_cd.flags & CONNECT_ONE_SHOT); |
| 679 | + bool b_append_source = (p_cd.flags & CONNECT_APPEND_SOURCE_OBJECT); |
672 | 680 |
|
673 | 681 | deferred->set_pressed(b_deferred); |
674 | 682 | one_shot->set_pressed(b_oneshot); |
| 683 | + append_source->set_pressed(b_append_source); |
675 | 684 |
|
676 | 685 | unbind_count->set_max(p_signal_args.size()); |
677 | | - |
678 | 686 | unbind_count->set_value(p_cd.unbinds); |
679 | 687 | _unbind_count_changed(p_cd.unbinds); |
680 | 688 |
|
@@ -892,20 +900,23 @@ ConnectDialog::ConnectDialog() { |
892 | 900 | advanced->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "use_advanced_connections", false)); |
893 | 901 | advanced->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_advanced_pressed)); |
894 | 902 |
|
895 | | - HBoxContainer *hbox = memnew(HBoxContainer); |
896 | | - vbc_right->add_child(hbox); |
| 903 | + FlowContainer *fc_flags = memnew(FlowContainer); |
| 904 | + vbc_right->add_child(fc_flags); |
897 | 905 |
|
898 | 906 | deferred = memnew(CheckBox); |
899 | | - deferred->set_h_size_flags(0); |
900 | 907 | deferred->set_text(TTR("Deferred")); |
901 | 908 | deferred->set_tooltip_text(TTR("Defers the signal, storing it in a queue and only firing it at idle time.")); |
902 | | - hbox->add_child(deferred); |
| 909 | + fc_flags->add_child(deferred); |
903 | 910 |
|
904 | 911 | one_shot = memnew(CheckBox); |
905 | | - one_shot->set_h_size_flags(0); |
906 | 912 | one_shot->set_text(TTR("One Shot")); |
907 | 913 | one_shot->set_tooltip_text(TTR("Disconnects the signal after its first emission.")); |
908 | | - hbox->add_child(one_shot); |
| 914 | + fc_flags->add_child(one_shot); |
| 915 | + |
| 916 | + append_source = memnew(CheckBox); |
| 917 | + append_source->set_text(TTRC("Append Source")); |
| 918 | + append_source->set_tooltip_text(TTRC("The source object is automatically sent when the signal is emitted.")); |
| 919 | + fc_flags->add_child(append_source); |
909 | 920 |
|
910 | 921 | cdbinds = memnew(ConnectDialogBinds); |
911 | 922 |
|
@@ -961,7 +972,8 @@ void ConnectionsDock::_make_or_edit_connection() { |
961 | 972 | } |
962 | 973 | bool b_deferred = connect_dialog->get_deferred(); |
963 | 974 | bool b_oneshot = connect_dialog->get_one_shot(); |
964 | | - cd.flags = CONNECT_PERSIST | (b_deferred ? CONNECT_DEFERRED : 0) | (b_oneshot ? CONNECT_ONE_SHOT : 0); |
| 975 | + bool b_append_source = connect_dialog->get_append_source(); |
| 976 | + cd.flags = CONNECT_PERSIST | (b_deferred ? CONNECT_DEFERRED : 0) | (b_oneshot ? CONNECT_ONE_SHOT : 0) | (b_append_source ? CONNECT_APPEND_SOURCE_OBJECT : 0); |
965 | 977 |
|
966 | 978 | // If the function is found in target's own script, check the editor setting |
967 | 979 | // to determine if the script should be opened. |
@@ -1003,6 +1015,45 @@ void ConnectionsDock::_make_or_edit_connection() { |
1003 | 1015 | if (add_script_function_request) { |
1004 | 1016 | PackedStringArray script_function_args = connect_dialog->get_signal_args(); |
1005 | 1017 | script_function_args.resize(script_function_args.size() - cd.unbinds); |
| 1018 | + |
| 1019 | + // Append the source. |
| 1020 | + if (b_append_source) { |
| 1021 | + String class_name = cd.source->get_class(); |
| 1022 | + bool found = false; |
| 1023 | + |
| 1024 | + Ref<Script> source_script = cd.source->get_script(); |
| 1025 | + if (source_script.is_valid()) { |
| 1026 | + found = source_script->has_script_signal(cd.signal); |
| 1027 | + if (found) { |
| 1028 | + // Check global name in script inheritance chain. |
| 1029 | + bool need_check = found; |
| 1030 | + Ref<Script> base_script = source_script->get_base_script(); |
| 1031 | + while (base_script.is_valid()) { |
| 1032 | + need_check = base_script->has_script_signal(cd.signal); |
| 1033 | + if (!need_check) { |
| 1034 | + break; |
| 1035 | + } |
| 1036 | + source_script = base_script; |
| 1037 | + base_script = source_script->get_base_script(); |
| 1038 | + } |
| 1039 | + class_name = source_script->get_global_name(); |
| 1040 | + } |
| 1041 | + } |
| 1042 | + |
| 1043 | + if (!found) { |
| 1044 | + while (!class_name.is_empty()) { |
| 1045 | + // Search in ClassDB according to the inheritance chain. |
| 1046 | + found = ClassDB::has_signal(class_name, cd.signal, true); |
| 1047 | + if (found) { |
| 1048 | + break; |
| 1049 | + } |
| 1050 | + class_name = ClassDB::get_parent_class(class_name); |
| 1051 | + } |
| 1052 | + } |
| 1053 | + |
| 1054 | + script_function_args.push_back("source:" + class_name); |
| 1055 | + } |
| 1056 | + |
1006 | 1057 | for (int i = 0; i < cd.binds.size(); i++) { |
1007 | 1058 | script_function_args.push_back("extra_arg_" + itos(i) + ":" + Variant::get_type_name(cd.binds[i].get_type())); |
1008 | 1059 | } |
@@ -1587,6 +1638,9 @@ void ConnectionsDock::update_tree() { |
1587 | 1638 | if (cd.flags & CONNECT_ONE_SHOT) { |
1588 | 1639 | path += " (one-shot)"; |
1589 | 1640 | } |
| 1641 | + if (cd.flags & CONNECT_APPEND_SOURCE_OBJECT) { |
| 1642 | + path += " (source)"; |
| 1643 | + } |
1590 | 1644 | if (cd.unbinds > 0) { |
1591 | 1645 | path += " unbinds(" + itos(cd.unbinds) + ")"; |
1592 | 1646 | } else if (!cd.binds.is_empty()) { |
|
0 commit comments