@@ -382,6 +382,15 @@ void OrchestratorGraphEdit::for_each_graph_node(std::function<void(OrchestratorG
382
382
}
383
383
}
384
384
385
+ void OrchestratorGraphEdit::for_each_graph_knot (std::function<void (OrchestratorGraphKnot*)> p_func)
386
+ {
387
+ for (int i = 0 ; i < get_child_count (); i++)
388
+ {
389
+ if (OrchestratorGraphKnot* knot = Object::cast_to<OrchestratorGraphKnot>(get_child (i)))
390
+ p_func (knot);
391
+ }
392
+ }
393
+
385
394
void OrchestratorGraphEdit::execute_action (const String& p_action_name)
386
395
{
387
396
Ref<InputEventAction> action = memnew (InputEventAction);
@@ -709,6 +718,29 @@ void OrchestratorGraphEdit::_drop_data(const Vector2& p_position, const Variant&
709
718
}
710
719
}
711
720
721
+ bool OrchestratorGraphEdit::highlight_selected_connections () const
722
+ {
723
+ return OrchestratorSettings::get_singleton ()->get_setting (" ui/nodes/highlight_selected_connections" , false );
724
+ }
725
+
726
+ Vector<Ref<OScriptNode>> OrchestratorGraphEdit::_get_linked_script_nodes (const Vector<Ref<OScriptNode>>& p_selected)
727
+ {
728
+ Vector<Ref<OScriptNode>> linked;
729
+ for (const Ref<OScriptNode>& selected : p_selected)
730
+ {
731
+ for (const Ref<OScriptNodePin>& pin : selected->get_all_pins ())
732
+ {
733
+ for (const Ref<OScriptNodePin>& connection : pin->get_connections ())
734
+ {
735
+ const Ref<OScriptNode> node = connection->get_owning_node ();
736
+ if (!p_selected.has (node) && !linked.has (node))
737
+ linked.push_back (node);
738
+ }
739
+ }
740
+ }
741
+ return linked;
742
+ }
743
+
712
744
void OrchestratorGraphEdit::_cache_connection_knots ()
713
745
{
714
746
_knots.clear ();
@@ -761,6 +793,10 @@ PackedVector2Array OrchestratorGraphEdit::_get_connection_knot_points(const OScr
761
793
762
794
void OrchestratorGraphEdit::_create_connection_knot (const Dictionary& p_connection, const Vector2& p_position)
763
795
{
796
+ // Deselect all nodes
797
+ for (OrchestratorGraphNode* node : get_selected_nodes ())
798
+ node->set_selected (false );
799
+
764
800
// Knots should be stored within any zoom applied.
765
801
const Vector2 position = p_position / get_zoom ();
766
802
const Vector2 transformed_position = position + (get_scroll_offset () / get_zoom ());
@@ -1073,6 +1109,8 @@ void OrchestratorGraphEdit::_synchronize_graph_knots()
1073
1109
if (!source)
1074
1110
continue ;
1075
1111
1112
+ Color color = source->get_output_port_color (connection.from_port );
1113
+
1076
1114
for (int i = 0 ; i < E.value .size (); i++)
1077
1115
{
1078
1116
const Ref<KnotPoint>& point = E.value [i];
@@ -1081,7 +1119,7 @@ void OrchestratorGraphEdit::_synchronize_graph_knots()
1081
1119
graph_knot->set_owning_script (_script);
1082
1120
graph_knot->set_connection (connection);
1083
1121
graph_knot->set_knot (point);
1084
- graph_knot->set_color (source-> get_output_port_color (connection. from_port ) );
1122
+ graph_knot->set_color (color );
1085
1123
add_child (graph_knot);
1086
1124
1087
1125
graph_knot->connect (" knot_position_changed" , callable_mp_lambda (this , [&](const Vector2& position) {
@@ -1372,9 +1410,6 @@ void OrchestratorGraphEdit::_on_attempt_connection_to_empty(const StringName& p_
1372
1410
1373
1411
void OrchestratorGraphEdit::_on_node_selected (Node* p_node)
1374
1412
{
1375
- if (!p_node)
1376
- return ;
1377
-
1378
1413
OrchestratorGraphNode* graph_node = Object::cast_to<OrchestratorGraphNode>(p_node);
1379
1414
if (!graph_node)
1380
1415
return ;
@@ -1383,43 +1418,48 @@ void OrchestratorGraphEdit::_on_node_selected(Node* p_node)
1383
1418
if (node.is_null ())
1384
1419
return ;
1385
1420
1386
- OrchestratorSettings* os = OrchestratorSettings::get_singleton ();
1387
- if (os->get_setting (" ui/nodes/highlight_selected_connections" , false ))
1421
+ if (highlight_selected_connections ())
1388
1422
{
1389
- // Get list of all selected nodes
1390
- List<Ref<OScriptNode>> selected_nodes;
1391
- for_each_graph_node ([&](OrchestratorGraphNode* other) {
1392
- if (other && other->is_selected ())
1393
- selected_nodes.push_back (other->get_script_node ());
1394
- });
1395
-
1423
+ Vector<Ref<OScriptNode>> selected_nodes = get_selected_script_nodes ();
1396
1424
if (!selected_nodes.is_empty ())
1397
1425
{
1398
- for_each_graph_node ([&](OrchestratorGraphNode* loop_node) {
1399
- loop_node->set_all_inputs_opacity (0 .3f );
1400
- loop_node->set_all_outputs_opacity (0 .3f );
1426
+ // For each graph node, dim connection pins and wires
1427
+ for_each_graph_node ([&](OrchestratorGraphNode* gn) {
1428
+ gn->set_all_inputs_opacity (0 .3f );
1429
+ gn->set_all_outputs_opacity (0 .3f );
1401
1430
});
1402
- }
1403
1431
1404
- List<Ref<OScriptNode>> linked_nodes;
1405
- for (const Ref<OScriptNode>& selected : selected_nodes)
1432
+ // For all knots, dim them.
1433
+ for_each_graph_knot ([&](OrchestratorGraphKnot* gk) {
1434
+ gk->set_modulate (Color (1 , 1 , 1 , 0 .3f ));
1435
+ });
1436
+
1437
+ // Get collection of all nodes linked to the selected nodes
1438
+ const Vector<Ref<OScriptNode>> linked_nodes = _get_linked_script_nodes (selected_nodes);
1439
+
1440
+ // For each graph node selected, dim non-connected nodes
1441
+ for_each_graph_node ([&](OrchestratorGraphNode* gn) {
1442
+ // Initially set each node dimmed
1443
+ gn->set_modulate (Color (1 , 1 , 1 , 0.5 ));
1444
+
1445
+ // If linked, undim
1446
+ if (selected_nodes.has (gn->get_script_node ()) || linked_nodes.has (gn->get_script_node ()))
1447
+ gn->set_modulate (Color (1 , 1 , 1 , 1 ));
1448
+ });
1449
+ }
1450
+ else
1406
1451
{
1407
- Vector<Ref<OScriptNodePin>> pins = selected-> get_all_pins ();
1408
- for ( const Ref<OScriptNodePin>& pin : pins)
1409
- {
1410
- const Vector<Ref<OScriptNodePin>> connections = pin-> get_connections ();
1411
- for ( const Ref<OScriptNodePin>& connection : connections)
1412
- {
1413
- if (!selected_nodes. find (connection-> get_owning_node ()))
1414
- linked_nodes. push_back (connection-> get_owning_node ());
1415
- }
1416
- }
1452
+ // For each graph node, undim connection pins and wires
1453
+ for_each_graph_node ([&](OrchestratorGraphNode* gn) {
1454
+ gn-> set_all_inputs_opacity ();
1455
+ gn-> set_all_outputs_opacity ();
1456
+ });
1457
+
1458
+ // For all knots, undim them.
1459
+ for_each_graph_knot ([&](OrchestratorGraphKnot* gk) {
1460
+ gk-> set_modulate ( Color ( 1 , 1 , 1 , 1 ));
1461
+ });
1417
1462
}
1418
- for_each_graph_node ([&](OrchestratorGraphNode* other) {
1419
- other->set_modulate (Color (1 , 1 , 1 , 0.5 ));
1420
- if (selected_nodes.find (other->get_script_node ()) || linked_nodes.find (other->get_script_node ()))
1421
- other->set_modulate (Color (1 , 1 , 1 , 1 ));
1422
- });
1423
1463
}
1424
1464
1425
1465
if (!node->can_inspect_node_properties ())
@@ -1440,46 +1480,40 @@ void OrchestratorGraphEdit::_on_node_selected(Node* p_node)
1440
1480
1441
1481
void OrchestratorGraphEdit::_on_node_deselected (Node* p_node)
1442
1482
{
1483
+ OrchestratorGraphNode* graph_node = Object::cast_to<OrchestratorGraphNode>(p_node);
1484
+ if (!graph_node)
1485
+ return ;
1486
+
1443
1487
_plugin->get_editor_interface ()->inspect_object (nullptr );
1444
1488
1445
- OrchestratorSettings* os = OrchestratorSettings::get_singleton ();
1446
- if (os->get_setting (" ui/nodes/highlight_selected_connections" , false ))
1489
+ if (highlight_selected_connections ())
1447
1490
{
1448
- // Get list of all selected nodes
1449
- List<Ref<OScriptNode>> selected_nodes;
1450
- for_each_graph_node ([&](OrchestratorGraphNode* other) {
1451
- if (other && other->is_selected ())
1452
- selected_nodes.push_back (other->get_script_node ());
1453
- });
1454
-
1491
+ Vector<Ref<OScriptNode>> selected_nodes = get_selected_script_nodes ();
1455
1492
if (selected_nodes.is_empty ())
1456
1493
{
1457
- for_each_graph_node ([&](OrchestratorGraphNode* other) {
1458
- other->set_modulate (Color (1 , 1 , 1 , 1.0 ));
1459
- other->set_all_inputs_opacity ();
1460
- other->set_all_outputs_opacity ();
1494
+ // For all graph nodes, undim them, their pins and connection wires
1495
+ for_each_graph_node ([&](OrchestratorGraphNode* gn) {
1496
+ gn->set_modulate (Color (1 , 1 , 1 , 1 ));
1497
+ gn->set_all_inputs_opacity ();
1498
+ gn->set_all_outputs_opacity ();
1499
+ });
1500
+
1501
+ // For all knots, undim them.
1502
+ for_each_graph_knot ([&](OrchestratorGraphKnot* gk) {
1503
+ gk->set_modulate (Color (1 , 1 , 1 , 1 ));
1461
1504
});
1462
1505
}
1463
1506
else
1464
1507
{
1465
- List<Ref<OScriptNode>> linked_nodes;
1466
- for (const Ref<OScriptNode>& selected : selected_nodes)
1467
- {
1468
- Vector<Ref<OScriptNodePin>> pins = selected->get_all_pins ();
1469
- for (const Ref<OScriptNodePin>& pin : pins)
1470
- {
1471
- const Vector<Ref<OScriptNodePin>> connections = pin->get_connections ();
1472
- for (const Ref<OScriptNodePin>& connection : connections)
1473
- {
1474
- if (!selected_nodes.find (connection->get_owning_node ()))
1475
- linked_nodes.push_back (connection->get_owning_node ());
1476
- }
1477
- }
1478
- }
1479
- for_each_graph_node ([&](OrchestratorGraphNode* other) {
1480
- other->set_modulate (Color (1 , 1 , 1 , 0.5 ));
1481
- if (selected_nodes.find (other->get_script_node ()) || linked_nodes.find (other->get_script_node ()))
1482
- other->set_modulate (Color (1 , 1 , 1 , 1 ));
1508
+ const Vector<Ref<OScriptNode>> linked_nodes = _get_linked_script_nodes (selected_nodes);
1509
+ // For each graph node selected, dim non-connected nodes
1510
+ for_each_graph_node ([&](OrchestratorGraphNode* gn) {
1511
+ // Initially set each node dimmed
1512
+ gn->set_modulate (Color (1 , 1 , 1 , 0.5 ));
1513
+
1514
+ // If linked, undim
1515
+ if (selected_nodes.has (gn->get_script_node ()) || linked_nodes.has (gn->get_script_node ()))
1516
+ gn->set_modulate (Color (1 , 1 , 1 , 1 ));
1483
1517
});
1484
1518
}
1485
1519
}
0 commit comments