Skip to content

Commit b7ce2e9

Browse files
committed
Active connections overlay
1 parent 5df1e2e commit b7ce2e9

8 files changed

Lines changed: 102 additions & 10 deletions

File tree

export_presets.cfg

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[gd_resource type="ShaderMaterial" load_steps=2 format=3 uid="uid://cebf5h3c4353j"]
2+
3+
[sub_resource type="Shader" id="Shader_pewh7"]
4+
code = "shader_type canvas_item;
5+
6+
void fragment() {
7+
float f = smoothstep(0.0,0.5,abs(fract(UV.x*0.25-TIME)-0.5));
8+
COLOR = vec4(vec3(0.0), f*0.5);
9+
}
10+
"
11+
12+
[resource]
13+
shader = SubResource("Shader_pewh7")

material_maker/panels/graph_edit/graph_edit.gd

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ var undoredo_move_node_selection_changed : bool = true
4040
enum ConnectionStyle {DIRECT, BEZIER, ROUNDED, MANHATTAN, DIAGONAL}
4141
var connection_line_style : int = ConnectionStyle.BEZIER
4242

43+
var active_connections : Array[Dictionary]
44+
var should_draw_active_overlays : bool = true
45+
4346
@onready var drag_cut_cursor = preload("res://material_maker/icons/knife.png")
4447
var connections_to_cut : Array[Dictionary]
4548
var drag_cut_line : PackedVector2Array
@@ -140,6 +143,7 @@ func _gui_input(event) -> void:
140143
connections_to_cut.append_array(conns)
141144
if connections_to_cut.size():
142145
on_cut_connections(connections_to_cut)
146+
update_active_connections()
143147
connections_to_cut.clear()
144148
Input.set_custom_mouse_cursor(null)
145149
drag_cut_line.clear()
@@ -215,7 +219,11 @@ func _gui_input(event) -> void:
215219
if not (event.ctrl_pressed or event.shift_pressed or event.alt_pressed):
216220
node_popup.position = Vector2i(get_screen_transform()*get_local_mouse_position())
217221
node_popup.show_popup()
222+
elif event.button_index == MOUSE_BUTTON_MIDDLE:
223+
should_draw_active_overlays = not event.is_pressed()
224+
queue_redraw()
218225
else:
226+
219227
if event.button_index == MOUSE_BUTTON_LEFT:
220228
if event.double_click:
221229
if get_nodes_under_mouse().is_empty():
@@ -305,9 +313,7 @@ func get_padded_node_rect(graph_node:GraphNode) -> Rect2:
305313
func _draw() -> void:
306314
if drag_cut_line.size() > 1:
307315
draw_polyline(drag_cut_line, get_theme_color("connection_knife", "GraphEdit"), 1.0)
308-
if lasso_points.size() > 1:
309-
draw_polyline(lasso_points + PackedVector2Array([lasso_points[0]]),
310-
get_theme_color("lasso_stroke", "GraphEdit"), 1.0)
316+
$HighlightsOverlay.queue_redraw()
311317

312318

313319
# Misc. useful functions
@@ -428,6 +434,7 @@ func do_disconnect_node(from : String, from_slot : int, to : String, to_slot : i
428434
return false
429435

430436
func on_cut_connections(connections_to_cut : Array):
437+
queue_redraw()
431438
var generator_hier_name : String = generator.get_hier_name()
432439
var conns : Array = []
433440
for c in connections_to_cut:
@@ -1027,14 +1034,20 @@ func _on_ButtonTransmitsSeed_toggled(button_pressed) -> void:
10271034

10281035
var highlighting_connections : bool = false
10291036

1037+
func update_active_connections() -> void:
1038+
active_connections.clear()
1039+
for c in get_connection_list():
1040+
if get_node(NodePath(c.from_node)).selected or get_node(NodePath(c.to_node)).selected:
1041+
active_connections.append(c)
1042+
10301043
func highlight_connections() -> void:
10311044
if highlighting_connections:
10321045
return
10331046
highlighting_connections = true
10341047
while Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
10351048
await get_tree().process_frame
1036-
for c in get_connection_list():
1037-
set_connection_activity(c.from_node, c.from_port, c.to_node, c.to_port, 1.0 if get_node(NodePath(c.from_node)).selected or get_node(NodePath(c.to_node)).selected else 0.0)
1049+
update_active_connections()
1050+
queue_redraw()
10381051
highlighting_connections = false
10391052

10401053
func _on_GraphEdit_node_selected(node : GraphElement) -> void:
@@ -1274,6 +1287,7 @@ func undoredo_command(command : Dictionary) -> void:
12741287
_:
12751288
print("Unknown undo/redo command:")
12761289
print(command)
1290+
$HighlightsOverlay.queue_redraw.call_deferred()
12771291

12781292
func undoredo_move_node(node_name : String, old_pos : Vector2, new_pos : Vector2):
12791293
if old_pos == new_pos:
@@ -1750,3 +1764,16 @@ func color_comment_nodes() -> void:
17501764
picker.popup_hide.connect(picker.queue_free)
17511765
picker.popup_hide.connect(undoredo.end_group)
17521766
picker.popup()
1767+
1768+
func _on_connection_drag_started(_from_node: StringName, _from_port: int, _is_output: bool) -> void:
1769+
active_connections.clear()
1770+
should_draw_active_overlays = false
1771+
1772+
func _on_end_node_move() -> void:
1773+
should_draw_active_overlays = true
1774+
1775+
func _on_begin_node_move() -> void:
1776+
should_draw_active_overlays = false
1777+
1778+
func _on_connection_drag_ended() -> void:
1779+
should_draw_active_overlays = true

material_maker/panels/graph_edit/graph_edit.tscn

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[gd_scene load_steps=8 format=3 uid="uid://dy1u50we7gtru"]
1+
[gd_scene load_steps=9 format=3 uid="uid://dy1u50we7gtru"]
22

33
[ext_resource type="Script" uid="uid://dkp4w3at1o6cm" path="res://material_maker/panels/graph_edit/graph_edit.gd" id="1"]
44
[ext_resource type="Texture2D" uid="uid://c0j4px4n72di5" path="res://material_maker/icons/icons.tres" id="2"]
55
[ext_resource type="Script" uid="uid://bne3k0g56crmy" path="res://material_maker/tools/undo_redo/undo_redo.gd" id="3"]
66
[ext_resource type="PackedScene" uid="uid://buj231c2gxm4o" path="res://material_maker/widgets/desc_button/desc_button.tscn" id="4"]
7+
[ext_resource type="Script" uid="uid://dlah77kjy12l6" path="res://material_maker/panels/graph_edit/highlights_overlay.gd" id="5_u5byk"]
78

89
[sub_resource type="AtlasTexture" id="3"]
910
atlas = ExtResource("2")
@@ -85,12 +86,22 @@ layout_mode = 2
8586
[node name="UndoRedo" type="Node" parent="."]
8687
script = ExtResource("3")
8788

89+
[node name="HighlightsOverlay" type="Control" parent="."]
90+
anchors_preset = 0
91+
offset_right = 40.0
92+
offset_bottom = 40.0
93+
script = ExtResource("5_u5byk")
94+
95+
[connection signal="begin_node_move" from="." to="." method="_on_begin_node_move"]
96+
[connection signal="connection_drag_ended" from="." to="." method="_on_connection_drag_ended"]
97+
[connection signal="connection_drag_started" from="." to="." method="_on_connection_drag_started"]
8898
[connection signal="connection_from_empty" from="." to="." method="request_popup" binds= [true]]
8999
[connection signal="connection_request" from="." to="." method="on_connect_node"]
90100
[connection signal="connection_to_empty" from="." to="." method="request_popup" binds= [false]]
91101
[connection signal="copy_nodes_request" from="." to="." method="copy"]
92102
[connection signal="disconnection_request" from="." to="." method="on_disconnect_node"]
93103
[connection signal="duplicate_nodes_request" from="." to="." method="duplicate_selected"]
104+
[connection signal="end_node_move" from="." to="." method="_on_end_node_move"]
94105
[connection signal="node_deselected" from="." to="." method="_on_GraphEdit_node_unselected"]
95106
[connection signal="node_selected" from="." to="." method="_on_GraphEdit_node_selected"]
96107
[connection signal="paste_nodes_request" from="." to="." method="paste"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
extends Control
2+
3+
func _ready() -> void:
4+
owner.child_order_changed.connect(_move_above_connections.call_deferred)
5+
6+
func _move_above_connections() -> void:
7+
owner.move_child(self, owner.get_node("_connection_layer").get_index()+1)
8+
9+
func _draw() -> void:
10+
var zoom : float = owner.zoom
11+
for node in get_children():
12+
if node is Line2D:
13+
remove_child(node)
14+
node.free()
15+
if owner.active_connections.size() and owner.should_draw_active_overlays:
16+
for line in owner.active_connections:
17+
if owner.has_node(NodePath(line.to_node)) and owner.has_node(NodePath(line.to_node)):
18+
var from_node : GraphNode = owner.get_node(NodePath(line.from_node))
19+
var to_node : GraphNode = owner.get_node(NodePath(line.to_node))
20+
if from_node and to_node:
21+
var from_pos := from_node.get_output_port_position(line.from_port)*zoom + from_node.position
22+
var to_pos := to_node.get_input_port_position(line.to_port)*zoom + to_node.position
23+
var line2d : Line2D = Line2D.new()
24+
if get_viewport_rect().has_point(from_pos) or get_viewport_rect().has_point(to_pos):
25+
line2d.texture_mode = Line2D.LINE_TEXTURE_TILE
26+
line2d.material = load("res://material_maker/panels/graph_edit/active_connection_overlay.tres")
27+
line2d.points = owner._get_connection_line(from_pos, to_pos)
28+
line2d.width = owner.connection_lines_thickness
29+
line2d.round_precision = 4
30+
line2d.begin_cap_mode = Line2D.LINE_CAP_ROUND
31+
line2d.end_cap_mode = Line2D.LINE_CAP_ROUND
32+
add_child(line2d)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://dlah77kjy12l6

parse_args.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func export_files(files, output_dir, target, target_file, image_size) -> void:
8686
get_tree().quit()
8787

8888
func _ready():
89+
# Briefly show the shader at launch to allow it to compile
90+
# to avoid the initial stutter when highlighting active connections
91+
$ActiveOutlineOverlay.free()
92+
8993
var args : PackedStringArray = OS.get_cmdline_args()
9094
if ("--export" in args) or ("--export-material" in args):
9195
print("Exporting...")

parse_args.tscn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
[gd_scene load_steps=2 format=3 uid="uid://bwfnpjyf1wqiu"]
1+
[gd_scene load_steps=3 format=3 uid="uid://bwfnpjyf1wqiu"]
22

33
[ext_resource type="Script" uid="uid://bcslbmkx1lijb" path="res://parse_args.gd" id="1_or0h6"]
4+
[ext_resource type="Material" uid="uid://cebf5h3c4353j" path="res://material_maker/panels/graph_edit/active_connection_overlay.tres" id="2_ai1me"]
45

56
[node name="ParseArgs" type="Node"]
67
script = ExtResource("1_or0h6")
8+
9+
[node name="ActiveOutlineOverlay" type="ColorRect" parent="."]
10+
material = ExtResource("2_ai1me")

0 commit comments

Comments
 (0)