Now the editor loads and created nodes from MMNodes, and also implemented MMNode and graphnode creating logic for the add button/dialog.

This commit is contained in:
Relintai 2021-10-04 11:55:47 +02:00
parent 1374df2b59
commit 537d44bc63
3 changed files with 59 additions and 3 deletions

View File

@ -1,13 +1,63 @@
tool tool
extends MarginContainer 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" 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(): func _on_AddButton_pressed():
get_node(add_popup_path).popup_centered() get_node(add_popup_path).popup_centered()
func _on_AddPopup_ok_pressed(script_path : String): func _on_AddPopup_ok_pressed(script_path : String):
#print(script_path) if !_material:
pass 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)

View File

@ -1,3 +1,7 @@
tool tool
extends GraphNode extends GraphNode
var _node : MMNode = null
func set_node(node : MMNode) -> void:
_node = node

View File

@ -36,7 +36,9 @@ func handles(object):
func edit(object): func edit(object):
#if editor_scene: #if editor_scene:
# make_bottom_panel_item_visible(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): func make_visible(visible):
if tool_button: if tool_button: