Skip to content
Draft
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
Binary file added material_maker/icons/cross.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions material_maker/icons/cross.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://c6ahvommwwa8t"
path="res://.godot/imported/cross.png-84a7013f3d6c2a917d839be20cc31c25.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://material_maker/icons/cross.png"
dest_files=["res://.godot/imported/cross.png-84a7013f3d6c2a917d839be20cc31c25.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
137 changes: 103 additions & 34 deletions material_maker/panels/graph_edit/graph_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ enum ConnectionStyle {DIRECT, BEZIER, ROUNDED, MANHATTAN, DIAGONAL}
var connection_line_style : int = ConnectionStyle.BEZIER

@onready var drag_cut_cursor = preload("res://material_maker/icons/knife.png")
var connections_to_cut : Array[Dictionary]
var drag_cut_line : PackedVector2Array
var valid_drag_cut_entry: bool = false
const CURSOR_HOT_SPOT : Vector2 = Vector2(1.02, 17.34)
@onready var drag_reroute_cursor = preload("res://material_maker/icons/cross.png")
const DRAG_CUT_CURSOR_HOT_SPOT : Vector2 = Vector2(1.02, 17.34)

var drag_line : PackedVector2Array
enum DragLineGesture {CUT, REROUTE, NONE}
var drag_line_mode : int = DragLineGesture.NONE

var lasso_points : PackedVector2Array

Expand All @@ -76,7 +78,7 @@ func _ready() -> void:
for t in range(41):
add_valid_connection_type(t, 42)
add_valid_connection_type(42, t)
node_popup.about_to_popup.connect(func(): valid_drag_cut_entry = false)
node_popup.about_to_popup.connect(func(): drag_line_mode = DragLineGesture.NONE)

func _exit_tree():
remove_crash_recovery_file()
Expand Down Expand Up @@ -168,22 +170,45 @@ func _gui_input(event) -> void:
accept_event()
node_popup.position = Vector2i(get_screen_transform()*get_local_mouse_position())
node_popup.show_popup()
elif event.is_action_released("ui_cut_drag"):
var conns : Array[Dictionary]
for p in len(drag_cut_line) - 1:
var rect : Rect2
rect.position = drag_cut_line[p]
rect.end = drag_cut_line[p + 1]
conns = get_connections_intersecting_with_rect(rect.abs())
if conns.size():
connections_to_cut.append_array(conns)
if connections_to_cut.size():
on_cut_connections(connections_to_cut)
connections_to_cut.clear()
Input.set_custom_mouse_cursor(null)
drag_cut_line.clear()
conns.clear()
queue_redraw()
elif event.is_action_released("ui_cut_drag") or event.is_action_released("ui_reroute_drag"):
match drag_line_mode:
DragLineGesture.CUT:
var connections_to_cut : Array[Dictionary]
var links : Array[Dictionary]
for p in len(drag_line) - 1:
var rect : Rect2
rect.position = drag_line[p]
rect.end = drag_line[p + 1]
links = get_connections_intersecting_with_rect(rect.abs())
if links.size():
connections_to_cut.append_array(links)
if connections_to_cut.size():
on_cut_connections(connections_to_cut)
connections_to_cut.clear()
Input.set_custom_mouse_cursor(null)
drag_line.clear()
links.clear()
queue_redraw()
DragLineGesture.REROUTE:
if drag_line.size() >= 2:
var drag_reroute_line := Curve2D.new()
for p : Vector2 in drag_line:
drag_reroute_line.add_point(p)
var points := drag_reroute_line.tessellate_even_length(5, connection_lines_thickness)
var target_connections : Array[Dictionary]
for p : Vector2 in points:
var link := get_closest_connection_at_point(p, connection_lines_thickness)
if not link.is_empty() and target_connections.find_custom(func(d):
return (d.from_node == link.from_node and d.from_port == link.from_port
and d.to_node == link.to_node and d.to_port == link.to_port)) == -1:
link.position = p
target_connections.append(link)
if target_connections.size():
on_reroute_connections(target_connections)
target_connections.clear()
Input.set_custom_mouse_cursor(null)
drag_line.clear()
queue_redraw()
elif event.is_action_released("ui_lasso_select", true):
for node in get_children():
if node is GraphElement:
Expand Down Expand Up @@ -224,8 +249,10 @@ func _gui_input(event) -> void:
event.control = true
do_zoom(1.0/1.1)
elif event.button_index == MOUSE_BUTTON_RIGHT and event.is_pressed():
valid_drag_cut_entry = true
if event.is_command_or_control_pressed() and event.shift_pressed:
drag_line_mode = DragLineGesture.CUT
if event.shift_pressed:
add_reroute_under_mouse()
elif event.ctrl_pressed:
create_portals()
elif event.shift_pressed:
add_reroute_under_mouse()
Expand Down Expand Up @@ -326,15 +353,24 @@ func _gui_input(event) -> void:
if rect.has_point(get_global_mouse_position()):
mm_globals.set_tip_text("Space/#RMB: Nodes menu, Arrow keys: Pan, Mouse wheel: Zoom", 3)

if ((event.button_mask & MOUSE_BUTTON_MASK_RIGHT) != 0 and valid_drag_cut_entry
and event.relative.length() > 1.0):
if event.ctrl_pressed:
Input.set_custom_mouse_cursor(
drag_cut_cursor, Input.CURSOR_ARROW, CURSOR_HOT_SPOT)
drag_cut_line.append(get_local_mouse_position())
# drag line gesture (cut/reroute)
if (event.button_mask & MOUSE_BUTTON_MASK_RIGHT) != 0 and event.relative.length() > 1.0:
if drag_line_mode != DragLineGesture.NONE:
drag_line.append(get_local_mouse_position())
queue_redraw()
elif drag_cut_line.size():
drag_cut_line.append(get_local_mouse_position())
if event.ctrl_pressed:
drag_line_mode = DragLineGesture.CUT
Input.set_custom_mouse_cursor(drag_cut_cursor,
Input.CURSOR_ARROW, DRAG_CUT_CURSOR_HOT_SPOT)
elif event.shift_pressed:
drag_line_mode = DragLineGesture.REROUTE
Input.set_custom_mouse_cursor(drag_reroute_cursor,
Input.CURSOR_ARROW, drag_reroute_cursor.get_size() * 0.5)
else:
drag_line_mode = DragLineGesture.NONE
Input.set_custom_mouse_cursor(null)
if drag_line.size():
drag_line.clear()
queue_redraw()

# lasso selection
Expand All @@ -355,8 +391,8 @@ func get_padded_node_rect(graph_node:GraphNode) -> Rect2:
return Rect2(rect.position, rect.size)

func _draw() -> void:
if drag_cut_line.size() > 1:
draw_polyline(drag_cut_line, get_theme_color("connection_knife", "GraphEdit"), 1.0)
if drag_line.size() > 1:
draw_polyline(drag_line, get_theme_color("line_gesture", "GraphEdit"), 1.0)
if lasso_points.size() > 1:
draw_polyline(lasso_points + PackedVector2Array([lasso_points[0]]),
get_theme_color("lasso_stroke", "GraphEdit"), 1.0)
Expand Down Expand Up @@ -479,6 +515,40 @@ func do_disconnect_node(from : String, from_slot : int, to : String, to_slot : i
return true
return false

func on_reroute_connections(target_connections : Array[Dictionary]) -> void:
var prev : Dictionary = generator.serialize()
var grouped_connections : Dictionary[String, Array]

# group connections by their source node/port
for link : Dictionary in target_connections:
var key := "%s_%d" % [link.from_node, link.from_port]
if not grouped_connections.has(key):
grouped_connections[key] = []
grouped_connections[key].append(link)

for group : String in grouped_connections:
# find connection group center
var group_rect := Rect2(grouped_connections[group][0].position, Vector2.ZERO)
for group_link : Dictionary in grouped_connections[group]:
group_rect = group_rect.expand(group_link.position)
var group_center := (group_rect.abs().get_center() + scroll_offset) / zoom

# create reroute node
var reroute : Array = await do_create_nodes({nodes=[{name ="reroute", type="reroute",
node_position={x=group_center.x, y=group_center.y}}], connections=[]})
var group_reroute : GraphNode = reroute[0]
group_reroute.position_offset -= group_reroute.size * 0.5

# reroute connections
for link : Dictionary in grouped_connections[group]:
do_disconnect_node(link.from_node, link.from_port, link.to_node, link.to_port)
do_connect_node(link.from_node, link.from_port, group_reroute.name, 0)
do_connect_node(group_reroute.name, 0, link.to_node, link.to_port)

# undo/redo
var next : Dictionary = generator.serialize()
undoredo_create_step("Reroute multiple connections", generator.get_hier_name(), prev, next)

func on_cut_connections(connections_to_be_cut : Array):
var generator_hier_name : String = generator.get_hier_name()
var conns : Array = []
Expand All @@ -495,7 +565,6 @@ func on_cut_connections(connections_to_be_cut : Array):
]
undoredo.add("Cut node connections", undo_actions, redo_actions)


func on_disconnect_node(from : String, from_slot : int, to : String, to_slot : int) -> void:
var from_gen = get_node(from).generator
var to_gen = get_node(to).generator
Expand Down
2 changes: 1 addition & 1 deletion material_maker/theme/classic_base.tres
Original file line number Diff line number Diff line change
Expand Up @@ -981,10 +981,10 @@ CodeEdit/colors/symbol_color = Color(1, 1, 1, 1)
CodeEdit/colors/type_color = Color(1, 1, 0.878431, 1)
CodeEdit/styles/normal = SubResource("StyleBoxFlat_meah8")
FileDialog/styles/panel = SubResource("StyleBoxFlat_7b2nb")
GraphEdit/colors/connection_knife = Color(1, 1, 1, 1)
GraphEdit/colors/grid_major = Color(0.321569, 0.337255, 0.384314, 1)
GraphEdit/colors/grid_minor = Color(0.321569, 0.337255, 0.384314, 1)
GraphEdit/colors/lasso_stroke = Color(1, 1, 1, 1)
GraphEdit/colors/line_gesture = Color(1, 1, 1, 1)
GraphEdit/constants/port_hotzone_inner_extent = 8
GraphEdit/constants/port_hotzone_outer_extent = 50
GraphEdit/icons/grid_toggle = SubResource("AtlasTexture_m1w7u")
Expand Down
2 changes: 1 addition & 1 deletion material_maker/theme/default dark.tres
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ metadata/_custom_type_script = "uid://3ga2k3abkk0d"

[sub_resource type="Resource" id="Resource_0m7hk"]
script = ExtResource("4_0efyb")
name = "GraphEditConnectionKnife"
name = "GraphEditLineGesture"
orig = Color(0.99215686, 0.9843137, 1, 1)
target = Color(1, 1, 1, 1)
metadata/_custom_type_script = "uid://3ga2k3abkk0d"
Expand Down
2 changes: 1 addition & 1 deletion material_maker/theme/default light.tres
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ metadata/_custom_type_script = "uid://3ga2k3abkk0d"

[sub_resource type="Resource" id="Resource_qqxbn"]
script = ExtResource("4_rhf2q")
name = "GraphEditConnectionKnife"
name = "GraphEditLineGesture"
orig = Color(0.99215686, 0.9843137, 1, 1)
target = Color(1, 1, 1, 1)
metadata/_custom_type_script = "uid://3ga2k3abkk0d"
Expand Down
2 changes: 1 addition & 1 deletion material_maker/theme/default.tres
Original file line number Diff line number Diff line change
Expand Up @@ -1252,10 +1252,10 @@ FileDialog/colors/file_disabled_color = Color(0.301961, 0.305882, 0.309804, 1)
FileDialog/colors/file_icon_color = Color(0.698039, 0.698039, 0.698039, 1)
FileDialog/colors/folder_icon_color = Color(0.698039, 0.698039, 0.698039, 1)
FileDialog/styles/panel = SubResource("StyleBoxFlat_ck0hb")
GraphEdit/colors/connection_knife = Color(0.99215686, 0.9843137, 1, 1)
GraphEdit/colors/grid_major = Color(0.137255, 0.141176, 0.152941, 1)
GraphEdit/colors/grid_minor = Color(0.137255, 0.141176, 0.152941, 1)
GraphEdit/colors/lasso_stroke = Color(0.9882353, 0.9882353, 0.9882353, 1)
GraphEdit/colors/line_gesture = Color(0.9882353, 0.9882353, 0.9882353, 1)
GraphEdit/constants/port_hotzone_inner_extent = 8
GraphEdit/constants/port_hotzone_outer_extent = 50
GraphEdit/icons/grid_toggle = SubResource("AtlasTexture_m1w7u")
Expand Down
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ left_click={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(80, 13),"global_position":Vector2(89, 61),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
ui_reroute_drag={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(812, 27),"global_position":Vector2(828, 108),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}

[locale]

Expand Down