Skip to content

Commit cae8f4b

Browse files
committed
duplicate frame with nodes attached
1 parent 0170918 commit cae8f4b

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

addons/material_maker/engine/nodes/gen_comment.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var size : Vector2 = Vector2(350, 200)
1111
var title : String = "Comment"
1212
var autoshrink : bool = false
1313

14+
var attached : PackedStringArray
15+
1416
var color = null
1517

1618
func _ready() -> void:
@@ -39,6 +41,7 @@ func _serialize(data : Dictionary) -> Dictionary:
3941
data.text = text
4042
data.size = { x=size.x, y=size.y }
4143
data.autoshrink = MMType.serialize_value(autoshrink)
44+
data.attached = attached
4245
return data
4346

4447
func _deserialize(data : Dictionary) -> void:
@@ -52,3 +55,5 @@ func _deserialize(data : Dictionary) -> void:
5255
color = MMType.deserialize_value(data.color)
5356
if data.has("autoshrink"):
5457
autoshrink = MMType.deserialize_value(data.autoshrink)
58+
if data.has("attached"):
59+
attached = data.attached

material_maker/nodes/comment/comment.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,4 @@ func _on_resize_end(_new_size : Vector2) -> void:
273273
is_resizing = false
274274
redo_action = { type="resize_comment", node=generator.get_hier_name(), size=size }
275275
get_parent().undoredo.add("Resize comment", [undo_action], [redo_action], true)
276-
generator.size = size
276+
generator.size = _new_size

material_maker/panels/graph_edit/graph_edit.gd

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,14 +902,34 @@ func do_paste(data) -> void:
902902
var node_position = scroll_offset+0.5*size
903903
if Rect2(Vector2(0, 0), size).has_point(get_local_mouse_position()):
904904
node_position = offset_from_global_position(get_global_mouse_position())
905+
906+
# Mapping from original to duplicated node(names)
907+
var dupe_map : Dictionary[String, String]
908+
905909
for c in get_children():
906910
if c is GraphElement:
907911
c.selected = false
912+
913+
var i := 0
914+
for n in data.nodes.map(func(d): return d.name):
915+
dupe_map["node_"+n] = ""
916+
908917
var new_nodes = await create_nodes(data, node_position)
909918
if new_nodes != null:
910919
for c in new_nodes:
911920
c.selected = true
912921

922+
dupe_map[dupe_map.keys()[i]] = c.name
923+
i += 1
924+
925+
# Attach duplicated nodes to frames
926+
for old_node in dupe_map.keys():
927+
if get_node(old_node) is MMGraphComment:
928+
var new_frame = dupe_map[old_node]
929+
for attached_node in get_attached_nodes_of_frame(old_node):
930+
if dupe_map.has(attached_node):
931+
attach_graph_element_to_frame(dupe_map[attached_node], new_frame)
932+
913933
func paste() -> void:
914934
var data : String = DisplayServer.clipboard_get().strip_edges()
915935
var parsed_data = await mm_globals.parse_paste_data(data)
@@ -1764,3 +1784,6 @@ func detach_nodes() -> void:
17641784

17651785
for n in get_selected_nodes():
17661786
detach_graph_element_from_frame(n.name)
1787+
1788+
func _on_frame_rect_changed(frame: GraphFrame, new_rect: Rect2) -> void:
1789+
frame.generator.size = new_rect.size

material_maker/panels/graph_edit/graph_edit.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ script = ExtResource("3")
9191
[connection signal="copy_nodes_request" from="." to="." method="copy"]
9292
[connection signal="disconnection_request" from="." to="." method="on_disconnect_node"]
9393
[connection signal="duplicate_nodes_request" from="." to="." method="duplicate_selected"]
94+
[connection signal="frame_rect_changed" from="." to="." method="_on_frame_rect_changed"]
9495
[connection signal="graph_elements_linked_to_frame_request" from="." to="." method="_on_graph_elements_linked_to_frame_request"]
9596
[connection signal="node_deselected" from="." to="." method="_on_GraphEdit_node_unselected"]
9697
[connection signal="node_selected" from="." to="." method="_on_GraphEdit_node_selected"]

0 commit comments

Comments
 (0)