Skip to content

Commit cdcb2fc

Browse files
committed
View resource signals in the Connections Dock
1 parent 4a1c1c4 commit cdcb2fc

File tree

6 files changed

+79
-56
lines changed

6 files changed

+79
-56
lines changed

editor/docks/node_dock.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,24 @@ void NodeDock::update_lists() {
8787
connections->update_tree();
8888
}
8989

90-
void NodeDock::set_node(Node *p_node) {
91-
connections->set_node(p_node);
92-
groups->set_current(p_node);
90+
void NodeDock::set_object(Object *p_object) {
91+
connections->set_object(p_object);
92+
groups->set_current(Object::cast_to<Node>(p_object));
9393

94-
if (p_node) {
94+
if (p_object) {
9595
if (connections_button->is_pressed()) {
9696
connections->show();
9797
} else {
9898
groups->show();
9999
}
100100

101+
if (Object::cast_to<Resource>(p_object)) {
102+
show_connections();
103+
groups_button->set_disabled(true);
104+
} else {
105+
groups_button->set_disabled(false);
106+
}
107+
101108
mode_hb->show();
102109
select_a_node->hide();
103110
} else {
@@ -148,7 +155,7 @@ NodeDock::NodeDock() {
148155

149156
select_a_node = memnew(Label);
150157
select_a_node->set_focus_mode(FOCUS_ACCESSIBILITY);
151-
select_a_node->set_text(TTRC("Select a single node to edit its signals and groups."));
158+
select_a_node->set_text(TTRC("Select a single node to edit its signals and groups, or select an independent resource to view its signals."));
152159
select_a_node->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
153160
select_a_node->set_v_size_flags(SIZE_EXPAND_FILL);
154161
select_a_node->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);

editor/docks/node_dock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class NodeDock : public VBoxContainer {
6262
static void _bind_methods();
6363

6464
public:
65-
void set_node(Node *p_node);
65+
void set_object(Object *p_object);
6666

6767
void show_groups();
6868
void show_connections();

editor/docks/scene_tree_dock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
13591359
undo_redo->add_undo_method(node, "set_scene_file_path", node->get_scene_file_path());
13601360
_node_replace_owner(node, node, root);
13611361
_node_strip_signal_inheritance(node);
1362-
NodeDock::get_singleton()->set_node(node); // Refresh.
1362+
NodeDock::get_singleton()->set_object(node); // Refresh.
13631363
undo_redo->add_do_method(scene_tree, "update_tree");
13641364
undo_redo->add_undo_method(scene_tree, "update_tree");
13651365
undo_redo->commit_action();
@@ -2859,7 +2859,7 @@ void SceneTreeDock::_delete_confirm(bool p_cut) {
28592859
editor_history->cleanup_history();
28602860
InspectorDock::get_singleton()->call("_prepare_history");
28612861
InspectorDock::get_singleton()->update(nullptr);
2862-
NodeDock::get_singleton()->set_node(nullptr);
2862+
NodeDock::get_singleton()->set_object(nullptr);
28632863
}
28642864

28652865
void SceneTreeDock::_update_script_button() {

editor/editor_node.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,7 @@ void EditorNode::push_node_item(Node *p_node) {
26652665
void EditorNode::push_item(Object *p_object, const String &p_property, bool p_inspector_only) {
26662666
if (!p_object) {
26672667
InspectorDock::get_inspector_singleton()->edit(nullptr);
2668-
NodeDock::get_singleton()->set_node(nullptr);
2668+
NodeDock::get_singleton()->set_object(nullptr);
26692669
SceneTreeDock::get_singleton()->set_selected(nullptr);
26702670
InspectorDock::get_singleton()->update(nullptr);
26712671
hide_unused_editors();
@@ -2786,7 +2786,7 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
27862786
if (!current_obj) {
27872787
SceneTreeDock::get_singleton()->set_selected(nullptr);
27882788
InspectorDock::get_inspector_singleton()->edit(nullptr);
2789-
NodeDock::get_singleton()->set_node(nullptr);
2789+
NodeDock::get_singleton()->set_object(nullptr);
27902790
InspectorDock::get_singleton()->update(nullptr);
27912791
EditorDebuggerNode::get_singleton()->clear_remote_tree_selection();
27922792
hide_unused_editors();
@@ -2820,7 +2820,7 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
28202820
if (!p_skip_inspector_update) {
28212821
InspectorDock::get_inspector_singleton()->edit(current_res);
28222822
SceneTreeDock::get_singleton()->set_selected(nullptr);
2823-
NodeDock::get_singleton()->set_node(nullptr);
2823+
NodeDock::get_singleton()->set_object(current_res);
28242824
InspectorDock::get_singleton()->update(nullptr);
28252825
EditorDebuggerNode::get_singleton()->clear_remote_tree_selection();
28262826
ImportDock::get_singleton()->set_edit_path(current_res->get_path());
@@ -2850,7 +2850,7 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
28502850

28512851
InspectorDock::get_inspector_singleton()->edit(current_node);
28522852
if (current_node->is_inside_tree()) {
2853-
NodeDock::get_singleton()->set_node(current_node);
2853+
NodeDock::get_singleton()->set_object(current_node);
28542854
SceneTreeDock::get_singleton()->set_selected(current_node);
28552855
SceneTreeDock::get_singleton()->set_selection({ current_node });
28562856
InspectorDock::get_singleton()->update(current_node);
@@ -2862,7 +2862,7 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
28622862
}
28632863
}
28642864
} else {
2865-
NodeDock::get_singleton()->set_node(nullptr);
2865+
NodeDock::get_singleton()->set_object(nullptr);
28662866
SceneTreeDock::get_singleton()->set_selected(nullptr);
28672867
InspectorDock::get_singleton()->update(nullptr);
28682868
}
@@ -2910,7 +2910,7 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
29102910
}
29112911

29122912
InspectorDock::get_inspector_singleton()->edit(current_obj);
2913-
NodeDock::get_singleton()->set_node(nullptr);
2913+
NodeDock::get_singleton()->set_object(nullptr);
29142914
SceneTreeDock::get_singleton()->set_selected(selected_node);
29152915
SceneTreeDock::get_singleton()->set_selection(multi_nodes);
29162916
InspectorDock::get_singleton()->update(nullptr);

editor/scene/connections_dialog.cpp

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ void ConnectDialog::_tree_node_selected() {
199199
return;
200200
}
201201

202-
dst_path = source->get_path_to(current);
202+
Node *source_node = Object::cast_to<Node>(source);
203+
if (source_node) {
204+
dst_path = source_node->get_path_to(current);
205+
}
206+
203207
if (!edit_mode) {
204208
set_dst_method(generate_method_callback_name(source, signal, current));
205209
}
@@ -212,7 +216,7 @@ void ConnectDialog::_tree_node_selected() {
212216
}
213217

214218
void ConnectDialog::_focus_currently_connected() {
215-
tree->set_selected(source);
219+
tree->set_selected(Object::cast_to<Node>(source));
216220
}
217221

218222
void ConnectDialog::_unbind_count_changed(double p_count) {
@@ -267,8 +271,9 @@ void ConnectDialog::_remove_bind() {
267271
/*
268272
* Automatically generates a name for the callback method.
269273
*/
270-
StringName ConnectDialog::generate_method_callback_name(Node *p_source, const String &p_signal_name, Node *p_target) {
271-
String node_name = p_source->get_name();
274+
StringName ConnectDialog::generate_method_callback_name(Object *p_source, const String &p_signal_name, Object *p_target) {
275+
String node_name = p_source->call("get_name");
276+
272277
for (int i = 0; i < node_name.length(); i++) { // TODO: Regex filter may be cleaner.
273278
char32_t c = node_name[i];
274279
if ((i == 0 && !is_unicode_identifier_start(c)) || (i > 0 && !is_unicode_identifier_continue(c))) {
@@ -492,7 +497,8 @@ void ConnectDialog::_update_ok_enabled() {
492497
}
493498

494499
void ConnectDialog::_update_warning_label() {
495-
Node *dst = source->get_node(dst_path);
500+
Node *dst = Object::cast_to<Node>(source)->get_node(dst_path);
501+
496502
if (dst == nullptr) {
497503
warning_label->set_visible(false);
498504
return;
@@ -537,7 +543,7 @@ void ConnectDialog::_bind_methods() {
537543
ADD_SIGNAL(MethodInfo("connected"));
538544
}
539545

540-
Node *ConnectDialog::get_source() const {
546+
Object *ConnectDialog::get_source() const {
541547
return source;
542548
}
543549

@@ -693,15 +699,15 @@ void ConnectDialog::shortcut_input(const Ref<InputEvent> &p_event) {
693699
void ConnectDialog::init(const ConnectionData &p_cd, const PackedStringArray &p_signal_args, bool p_edit) {
694700
set_hide_on_ok(false);
695701

696-
source = static_cast<Node *>(p_cd.source);
702+
source = p_cd.source;
697703
signal = p_cd.signal;
698704
signal_args = p_signal_args;
699705

700706
tree->set_selected(nullptr);
701-
tree->set_marked(source);
707+
tree->set_marked(Object::cast_to<Node>(source));
702708

703709
if (p_cd.target) {
704-
set_dst_node(static_cast<Node *>(p_cd.target));
710+
set_dst_node(Object::cast_to<Node>(p_cd.target));
705711
set_dst_method(p_cd.method);
706712
}
707713

@@ -984,7 +990,8 @@ void ConnectionsDock::_filter_changed(const String &p_text) {
984990
*/
985991
void ConnectionsDock::_make_or_edit_connection() {
986992
NodePath dst_path = connect_dialog->get_dst_path();
987-
Node *target = selected_node->get_node(dst_path);
993+
Node *target = Object::cast_to<Node>(selected_object)->get_node(dst_path);
994+
988995
ERR_FAIL_NULL(target);
989996

990997
ConnectDialog::ConnectionData cd;
@@ -1077,7 +1084,7 @@ void ConnectionsDock::_make_or_edit_connection() {
10771084
script_function_args.push_back("extra_arg_" + itos(i) + ": " + Variant::get_type_name(cd.binds[i].get_type()));
10781085
}
10791086

1080-
EditorNode::get_singleton()->emit_signal(SNAME("script_add_function_request"), target, cd.method, script_function_args);
1087+
EditorNode::get_singleton()->emit_signal(SNAME("script_add_function_request"), cd.target, cd.method, script_function_args);
10811088
}
10821089

10831090
if (connect_dialog->is_editing()) {
@@ -1094,7 +1101,7 @@ void ConnectionsDock::_make_or_edit_connection() {
10941101
* Creates single connection w/ undo-redo functionality.
10951102
*/
10961103
void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {
1097-
Node *source = Object::cast_to<Node>(p_cd.source);
1104+
Object *source = p_cd.source;
10981105
Node *target = Object::cast_to<Node>(p_cd.target);
10991106

11001107
if (!source || !target) {
@@ -1118,14 +1125,14 @@ void ConnectionsDock::_connect(const ConnectDialog::ConnectionData &p_cd) {
11181125
* Break single connection w/ undo-redo functionality.
11191126
*/
11201127
void ConnectionsDock::_disconnect(const ConnectDialog::ConnectionData &p_cd) {
1121-
ERR_FAIL_COND(p_cd.source != selected_node); // Shouldn't happen but... Bugcheck.
1128+
ERR_FAIL_COND(p_cd.source != selected_object); // Shouldn't happen but... Bugcheck.
11221129

11231130
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
11241131
undo_redo->create_action(vformat(TTR("Disconnect '%s' from '%s'"), p_cd.signal, p_cd.method));
11251132

11261133
Callable callable = p_cd.get_callable();
1127-
undo_redo->add_do_method(selected_node, "disconnect", p_cd.signal, callable);
1128-
undo_redo->add_undo_method(selected_node, "connect", p_cd.signal, callable, p_cd.flags);
1134+
undo_redo->add_do_method(selected_object, "disconnect", p_cd.signal, callable);
1135+
undo_redo->add_undo_method(selected_object, "connect", p_cd.signal, callable, p_cd.flags);
11291136
undo_redo->add_do_method(this, "update_tree");
11301137
undo_redo->add_undo_method(this, "update_tree");
11311138
undo_redo->add_do_method(SceneTreeDock::get_singleton()->get_tree_editor(), "update_tree"); // To force redraw of scene tree.
@@ -1153,8 +1160,8 @@ void ConnectionsDock::_disconnect_all() {
11531160
Connection connection = child->get_metadata(0);
11541161
if (!_is_connection_inherited(connection)) {
11551162
ConnectDialog::ConnectionData cd = connection;
1156-
undo_redo->add_do_method(selected_node, "disconnect", cd.signal, cd.get_callable());
1157-
undo_redo->add_undo_method(selected_node, "connect", cd.signal, cd.get_callable(), cd.flags);
1163+
undo_redo->add_do_method(selected_object, "disconnect", cd.signal, cd.get_callable());
1164+
undo_redo->add_undo_method(selected_object, "connect", cd.signal, cd.get_callable(), cd.flags);
11581165
}
11591166
child = child->get_next();
11601167
}
@@ -1172,7 +1179,7 @@ void ConnectionsDock::_tree_item_selected() {
11721179
if (item && _get_item_type(*item) == TREE_ITEM_TYPE_SIGNAL) {
11731180
connect_button->set_text(TTR("Connect..."));
11741181
connect_button->set_button_icon(get_editor_theme_icon(SNAME("Instance")));
1175-
connect_button->set_disabled(false);
1182+
connect_button->set_disabled(is_editing_resource);
11761183
} else if (item && _get_item_type(*item) == TREE_ITEM_TYPE_CONNECTION) {
11771184
connect_button->set_text(TTR("Disconnect"));
11781185
connect_button->set_button_icon(get_editor_theme_icon(SNAME("Unlinked")));
@@ -1219,19 +1226,24 @@ bool ConnectionsDock::_is_connection_inherited(Connection &p_connection) {
12191226
* Open connection dialog with TreeItem data to CREATE a brand-new connection.
12201227
*/
12211228
void ConnectionsDock::_open_connection_dialog(TreeItem &p_item) {
1229+
if (is_editing_resource) {
1230+
return;
1231+
}
1232+
12221233
const Dictionary sinfo = p_item.get_metadata(0);
12231234
const StringName signal_name = sinfo["name"];
12241235
const PackedStringArray signal_args = sinfo["args"];
12251236

1237+
ConnectDialog::ConnectionData cd;
1238+
1239+
Node *selected_node = Object::cast_to<Node>(selected_object);
12261240
Node *dst_node = selected_node->get_owner() ? selected_node->get_owner() : selected_node;
12271241
if (!dst_node || dst_node->get_script().is_null()) {
12281242
dst_node = _find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root());
12291243
}
1230-
1231-
ConnectDialog::ConnectionData cd;
1232-
cd.source = selected_node;
1233-
cd.signal = signal_name;
1244+
cd.source = selected_object;
12341245
cd.target = dst_node;
1246+
cd.signal = signal_name;
12351247
cd.method = ConnectDialog::generate_method_callback_name(cd.source, signal_name, cd.target);
12361248
connect_dialog->init(cd, signal_args);
12371249
connect_dialog->set_title(TTR("Connect a Signal to a Method"));
@@ -1248,8 +1260,8 @@ void ConnectionsDock::_open_edit_connection_dialog(TreeItem &p_item) {
12481260
Connection connection = p_item.get_metadata(0);
12491261
ConnectDialog::ConnectionData cd = connection;
12501262

1251-
Node *src = Object::cast_to<Node>(cd.source);
1252-
Node *dst = Object::cast_to<Node>(cd.target);
1263+
Object *src = cd.source;
1264+
Object *dst = cd.target;
12531265

12541266
if (src && dst) {
12551267
const StringName &signal_name = cd.signal;
@@ -1271,7 +1283,7 @@ void ConnectionsDock::_go_to_method(TreeItem &p_item) {
12711283

12721284
Connection connection = p_item.get_metadata(0);
12731285
ConnectDialog::ConnectionData cd = connection;
1274-
ERR_FAIL_COND(cd.source != selected_node); // Shouldn't happen but... bugcheck.
1286+
ERR_FAIL_COND(cd.source != selected_object); // Shouldn't happen but... bugcheck.
12751287

12761288
if (!cd.target) {
12771289
return;
@@ -1342,6 +1354,7 @@ void ConnectionsDock::_signal_menu_about_to_popup() {
13421354
}
13431355
}
13441356

1357+
signal_menu->set_item_disabled(signal_menu->get_item_index(SIGNAL_MENU_CONNECT), is_editing_resource);
13451358
signal_menu->set_item_disabled(signal_menu->get_item_index(SIGNAL_MENU_DISCONNECT_ALL), disable_disconnect_all);
13461359
signal_menu->set_item_disabled(signal_menu->get_item_index(SIGNAL_MENU_OPEN_DOCS), String(meta["class"]).is_empty());
13471360
}
@@ -1509,8 +1522,9 @@ void ConnectionsDock::_bind_methods() {
15091522
ClassDB::bind_method("update_tree", &ConnectionsDock::update_tree);
15101523
}
15111524

1512-
void ConnectionsDock::set_node(Node *p_node) {
1513-
selected_node = p_node;
1525+
void ConnectionsDock::set_object(Object *p_obj) {
1526+
selected_object = p_obj;
1527+
is_editing_resource = (Object::cast_to<Resource>(selected_object) != nullptr);
15141528
update_tree();
15151529
}
15161530

@@ -1521,15 +1535,15 @@ void ConnectionsDock::update_tree() {
15211535
}
15221536
tree->clear();
15231537

1524-
if (!selected_node) {
1538+
if (!selected_object) {
15251539
return;
15261540
}
15271541

15281542
TreeItem *root = tree->create_item();
15291543
DocTools *doc_data = EditorHelp::get_doc_data();
15301544
EditorData &editor_data = EditorNode::get_editor_data();
1531-
StringName native_base = selected_node->get_class();
1532-
Ref<Script> script_base = selected_node->get_script();
1545+
StringName native_base = selected_object->get_class();
1546+
Ref<Script> script_base = selected_object->get_script();
15331547

15341548
while (native_base != StringName()) {
15351549
String class_name;
@@ -1643,7 +1657,7 @@ void ConnectionsDock::update_tree() {
16431657

16441658
// List existing connections.
16451659
List<Object::Connection> existing_connections;
1646-
selected_node->get_signal_connection_list(signal_name, &existing_connections);
1660+
selected_object->get_signal_connection_list(signal_name, &existing_connections);
16471661

16481662
for (const Object::Connection &F : existing_connections) {
16491663
Connection connection = F;
@@ -1657,7 +1671,7 @@ void ConnectionsDock::update_tree() {
16571671
continue;
16581672
}
16591673

1660-
String path = String(selected_node->get_path_to(target)) + " :: " + cd.method + "()";
1674+
String path = String(Object::cast_to<Node>(selected_object)->get_path_to(target)) + " :: " + cd.method + "()";
16611675
if (cd.flags & CONNECT_DEFERRED) {
16621676
path += " (deferred)";
16631677
}
@@ -1694,7 +1708,7 @@ void ConnectionsDock::update_tree() {
16941708
}
16951709
}
16961710

1697-
connect_button->set_text(TTR("Connect..."));
1711+
connect_button->set_text(TTRC("Connect..."));
16981712
connect_button->set_button_icon(get_editor_theme_icon(SNAME("Instance")));
16991713
connect_button->set_disabled(true);
17001714
}

0 commit comments

Comments
 (0)