Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions material_maker/nodes/base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ func _draw() -> void:
if control.get("modulate"):
control.modulate.a = opacity

get_parent().get_node("HighlightsOverlay").update_connections()


func draw_portgroup_stylebox(first_port : Vector2, last_port : Vector2) -> void:
var stylebox_position: Vector2 = first_port + Vector2(-0.5,-0.5) * portgroup_width
var stylebox_size: Vector2 = Vector2(portgroup_width, last_port.y - first_port.y + portgroup_width)
Expand Down
14 changes: 0 additions & 14 deletions material_maker/panels/graph_edit/graph_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1086,18 +1086,6 @@ func _on_ButtonTransmitsSeed_toggled(button_pressed) -> void:

# Node selection

var highlighting_connections : bool = false

func highlight_connections() -> void:
if highlighting_connections:
return
highlighting_connections = true
while Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
await get_tree().process_frame
for c in get_connection_list():
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)
highlighting_connections = false

func _on_GraphEdit_node_selected(node : GraphElement) -> void:
if node is MMGraphComment:
#print("Selecting enclosed nodes...")
Expand All @@ -1108,7 +1096,6 @@ func _on_GraphEdit_node_selected(node : GraphElement) -> void:
elif node is MMGraphCommentLine:
pass
else:
highlight_connections()
await get_tree().process_frame
if current_preview[0] != null:
for n in get_selected_nodes():
Expand All @@ -1127,7 +1114,6 @@ func _on_GraphEdit_node_selected(node : GraphElement) -> void:
mm_globals.main_window.update_menus()

func _on_GraphEdit_node_unselected(_node):
highlight_connections()
undoredo_move_node_selection_changed = true
mm_globals.main_window.update_menus()

Expand Down
40 changes: 28 additions & 12 deletions material_maker/panels/graph_edit/graph_edit.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[gd_scene load_steps=8 format=3 uid="uid://dy1u50we7gtru"]
[gd_scene format=3 uid="uid://dy1u50we7gtru"]

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

[sub_resource type="AtlasTexture" id="3"]
atlas = ExtResource("2")
Expand All @@ -17,7 +18,17 @@ region = Rect2(15.4016, 47.1451, 16.7512, 17.8319)
atlas = ExtResource("2")
region = Rect2(0, 48, 16, 16)

[node name="GraphEdit" type="GraphEdit" groups=["mm_graphedit"]]
[sub_resource type="Shader" id="Shader_u5byk"]
code = "shader_type canvas_item;

void fragment() {
COLOR = vec4(vec3(0.0), 0.25 * sin(UV.x - TIME * TAU) + 0.25);
}"

[sub_resource type="ShaderMaterial" id="ShaderMaterial_nlxn2"]
shader = SubResource("Shader_u5byk")

[node name="GraphEdit" type="GraphEdit" unique_id=175822157 groups=["mm_graphedit"]]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
Expand All @@ -34,11 +45,11 @@ show_menu = false
show_zoom_label = true
script = ExtResource("1")

[node name="Timer" type="Timer" parent="."]
[node name="Timer" type="Timer" parent="." unique_id=654752788]
wait_time = 0.2
one_shot = true

[node name="GraphUI" type="HBoxContainer" parent="."]
[node name="GraphUI" type="HBoxContainer" parent="." unique_id=45635343]
top_level = true
custom_minimum_size = Vector2(0, 25)
layout_mode = 1
Expand All @@ -51,43 +62,48 @@ offset_bottom = 31.0
grow_horizontal = 0
alignment = 2

[node name="SubGraphUI" type="HBoxContainer" parent="GraphUI"]
[node name="SubGraphUI" type="HBoxContainer" parent="GraphUI" unique_id=1847281688]
layout_mode = 2
size_flags_horizontal = 9

[node name="Label" type="LineEdit" parent="GraphUI/SubGraphUI"]
[node name="Label" type="LineEdit" parent="GraphUI/SubGraphUI" unique_id=1166036264]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
size_flags_horizontal = 9

[node name="Description" parent="GraphUI/SubGraphUI" instance=ExtResource("4")]
[node name="Description" parent="GraphUI/SubGraphUI" unique_id=610946558 instance=ExtResource("4")]
layout_mode = 2

[node name="ButtonTransmitsSeed" type="Button" parent="GraphUI/SubGraphUI"]
[node name="ButtonTransmitsSeed" type="Button" parent="GraphUI/SubGraphUI" unique_id=1858333769]
layout_mode = 2
size_flags_horizontal = 9
tooltip_text = "Affect children seeds"
toggle_mode = true
icon = SubResource("3")

[node name="ButtonUp" type="Button" parent="GraphUI/SubGraphUI"]
[node name="ButtonUp" type="Button" parent="GraphUI/SubGraphUI" unique_id=1608742490]
layout_mode = 2
size_flags_horizontal = 9
tooltip_text = "Back to parent"
icon = SubResource("4")

[node name="ButtonShowTree" type="Button" parent="GraphUI"]
[node name="ButtonShowTree" type="Button" parent="GraphUI" unique_id=1663795300]
layout_mode = 2
tooltip_text = "Show hierarchy"
icon = SubResource("5")

[node name="Control" type="Control" parent="GraphUI"]
[node name="Control" type="Control" parent="GraphUI" unique_id=265307966]
custom_minimum_size = Vector2(14, 0)
layout_mode = 2

[node name="UndoRedo" type="Node" parent="."]
[node name="UndoRedo" type="Node" parent="." unique_id=476880472]
script = ExtResource("3")

[node name="HighlightsOverlay" type="Control" parent="." unique_id=2128156926]
anchors_preset = 0
script = ExtResource("5_u5byk")
line_material = SubResource("ShaderMaterial_nlxn2")

[connection signal="connection_drag_ended" from="." to="." method="_on_connection_drag_ended"]
[connection signal="connection_drag_started" from="." to="." method="_on_connection_drag_started"]
[connection signal="connection_from_empty" from="." to="." method="request_popup" binds= [true]]
Expand Down
110 changes: 110 additions & 0 deletions material_maker/panels/graph_edit/highlights_overlay.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
class_name HighlightsOverlay
extends Control


class AnimatedConnection extends Line2D:
var connection : Dictionary

@onready var graph : MMGraphEdit = owner
@export var line_material : ShaderMaterial

var active_connections : Array[Dictionary]
var is_updating_connections : bool = false

func _ready() -> void:
graph.child_order_changed.connect(_move_above_connections.call_deferred)
graph.get_node("_connection_layer").draw.connect(queue_redraw)
graph.get_node("_connection_layer").child_order_changed.connect(update_connections)
graph.connection_drag_started.connect(update_connections.bind(1).unbind(3))
graph.node_selected.connect(update_connections.unbind(1))
graph.node_deselected.connect(update_connections.unbind(1))
graph.gui_input.connect(_graph_gui_input)

func _draw() -> void:
if get_children().is_empty():
return

for line : AnimatedConnection in get_children():
var conn : Dictionary = line.connection
var positions : Dictionary[String, Vector2] = get_connection_positions(conn)
if positions.is_empty():
continue

line.visible = get_viewport_rect().intersects(
Rect2(positions.from, positions.to - positions.from).abs())

line.points = graph._get_connection_line(positions.from, positions.to)
line.width = graph.connection_lines_thickness

func _move_above_connections() -> void:
graph.move_child(self, graph.get_node("_connection_layer").get_index() + 1)

func _graph_gui_input(e : InputEvent) -> void:
if e is InputEventKey:
update_connections(true)

func update_connections(should_hide_when_updating : bool = false) -> void:
if is_updating_connections:
return
is_updating_connections = true

if should_hide_when_updating:
hide()

while Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
await get_tree().process_frame

active_connections.clear()
for c in graph.get_connection_list():
if (graph.get_node(NodePath(c.from_node)).selected
or graph.get_node(NodePath(c.to_node)).selected):
active_connections.append(c)
await get_tree().process_frame
create_animated_connections()

# Remove inactive/invalid animated conections
if get_children().size():
for anim_line : AnimatedConnection in get_children():
if (anim_line.connection not in active_connections
or get_connection_positions(anim_line.connection).is_empty()):
remove_child(anim_line)
anim_line.free()

queue_redraw()
is_updating_connections = false
show.call_deferred()

func create_animated_connections() -> void:
if active_connections.size():
for active_connection in active_connections:
var positions : Dictionary[String, Vector2] = get_connection_positions(active_connection)
if positions.is_empty():
continue

var has_existing_connection : bool = false
for c in get_children():
if c.connection == active_connection:
has_existing_connection = true
break

if not has_existing_connection:
var ac : AnimatedConnection = AnimatedConnection.new()
ac.connection = active_connection
ac.texture_mode = Line2D.LINE_TEXTURE_TILE
ac.material = line_material
ac.points = graph._get_connection_line(positions.from, positions.to)
ac.width = graph.connection_lines_thickness
add_child(ac)

func get_connection_positions(from_connection : Dictionary) -> Dictionary[String, Vector2]:
var c : Dictionary = from_connection
var positions : Dictionary[String, Vector2]
if graph.has_node(NodePath(c.from_node)) and graph.has_node(NodePath(c.to_node)):
var from_node : MMGraphNodeMinimal = graph.get_node(NodePath(c.from_node))
var to_node : MMGraphNodeMinimal = graph.get_node(NodePath(c.to_node))
if from_node and to_node:
var from_pos : Vector2 = from_node.get_output_port_position(c.from_port)
var to_pos : Vector2 = to_node.get_input_port_position(c.to_port)
positions.from = from_pos * graph.zoom + from_node.position
positions.to = to_pos * graph.zoom + to_node.position
return positions
1 change: 1 addition & 0 deletions material_maker/panels/graph_edit/highlights_overlay.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dlah77kjy12l6