diff --git a/game/addons/mat_maker_gd/editor/MatMakerGDEditor.gd b/game/addons/mat_maker_gd/editor/MatMakerGDEditor.gd index 65820ba6..666c195d 100644 --- a/game/addons/mat_maker_gd/editor/MatMakerGDEditor.gd +++ b/game/addons/mat_maker_gd/editor/MatMakerGDEditor.gd @@ -1,13 +1,63 @@ tool extends MarginContainer +var MMGraphNode = preload("res://addons/mat_maker_gd/editor/mm_graph_node.gd") + +export(NodePath) var graph_edit_path : NodePath = "VBoxContainer/GraphEdit" export(NodePath) var add_popup_path : NodePath = "Popups/AddPopup" +var _graph_edit : GraphEdit = null +var _material : MMMateial + +func _enter_tree(): + ensure_objs() + +func ensure_objs() -> void: + if !_graph_edit: + _graph_edit = get_node(graph_edit_path) + +func recreate() -> void: + ensure_objs() + + for c in _graph_edit.get_children(): + if c is GraphNode: + _graph_edit.remove_child(c) + c.queue_free() + + if !_material: + return + + for n in _material.nodes: + var gn : GraphNode = MMGraphNode.new() + gn.set_node(n) + _graph_edit.add_child(gn) + + #connect them + +func set_mmmaterial(object : MMMateial): + _material = object + + recreate() func _on_AddButton_pressed(): get_node(add_popup_path).popup_centered() func _on_AddPopup_ok_pressed(script_path : String): - #print(script_path) - pass + if !_material: + return + + ensure_objs() + + var sc = load(script_path) + var nnode : MMNode = sc.new() + + if !nnode: + print("_on_AddPopup_ok_pressed: Error !nnode! script: " + script_path) + return + + _material.nodes.append(nnode) + + var gn : GraphNode = MMGraphNode.new() + gn.set_node(nnode) + _graph_edit.add_child(gn) diff --git a/game/addons/mat_maker_gd/editor/mm_graph_node.gd b/game/addons/mat_maker_gd/editor/mm_graph_node.gd index 92c4740d..4b33e7cc 100644 --- a/game/addons/mat_maker_gd/editor/mm_graph_node.gd +++ b/game/addons/mat_maker_gd/editor/mm_graph_node.gd @@ -1,3 +1,7 @@ tool extends GraphNode +var _node : MMNode = null + +func set_node(node : MMNode) -> void: + _node = node diff --git a/game/addons/mat_maker_gd/plugin.gd b/game/addons/mat_maker_gd/plugin.gd index ac20050d..1fa5cf26 100644 --- a/game/addons/mat_maker_gd/plugin.gd +++ b/game/addons/mat_maker_gd/plugin.gd @@ -36,7 +36,9 @@ func handles(object): func edit(object): #if editor_scene: # make_bottom_panel_item_visible(editor_scene) - pass + + if object is MMMateial: + editor_scene.set_mmmaterial(object as MMMateial) func make_visible(visible): if tool_button: