From ac4a5c39b6928333faeff8d0eff90d086d7fb407 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Thu, 19 Sep 2019 07:56:32 +0200 Subject: [PATCH] Added support for hierrachical navigation --- addons/material_maker/engine/gen_graph.gd | 3 ++ addons/material_maker/engine/gen_shader.gd | 8 +++++ addons/material_maker/graph_edit.gd | 40 +++++++++++++++------- addons/material_maker/graph_edit.tscn | 10 ++++++ addons/material_maker/nodes/generic.gd | 8 ++--- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index 8fb9859..e036c5f 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -105,3 +105,6 @@ func _serialize(data): data.nodes.append(c.serialize()) data.connections = connections return data + +func edit(node): + node.get_parent().call_deferred("update_view", self) \ No newline at end of file diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index 4fe0902..a50a2d4 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -213,3 +213,11 @@ func get_globals(): func _serialize(data): data.shader_model = shader_model return data + +func edit(node): + if shader_model != null: + var edit_window = load("res://addons/material_maker/widgets/node_editor/node_editor.tscn").instance() + node.get_parent().add_child(edit_window) + edit_window.set_model_data(shader_model) + edit_window.connect("node_changed", node, "update_generator") + edit_window.popup_centered() diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index 89b2cc8..72d93c1 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -8,6 +8,7 @@ var renderer = null var save_path = null setget set_save_path var need_save = false +var top_generator = null var generator = null signal save_path_changed @@ -86,15 +87,24 @@ func set_save_path(path): update_tab_title() emit_signal("save_path_changed", self, path) -func clear_material(): +func clear_view(): clear_connections() for c in get_children(): if c is GraphNode: remove_child(c) c.free() - if generator != null: - remove_child(generator) - generator.free() + +func update_view(g): + clear_view() + generator = g + update_graph(generator.get_children(), generator.connections) + $ButtonUp.visible = generator != top_generator + +func clear_material(): + if top_generator != null: + remove_child(top_generator) + top_generator.free() + top_generator = null generator = null send_changed_signal() @@ -115,10 +125,10 @@ func update_graph(generators, connections): func new_material(): clear_material() var loader = MMGenLoader.new() - generator = loader.create_gen({nodes=[{name="Material", type="material"}], connections=[]}) - if generator != null: - add_child(generator) - update_graph(generator.get_children(), generator.connections) + top_generator = loader.create_gen({nodes=[{name="Material", type="material"}], connections=[]}) + if top_generator != null: + add_child(top_generator) + update_view(top_generator) set_save_path(null) set_need_save(false) center_view() @@ -145,16 +155,16 @@ func create_nodes(data, position : Vector2 = Vector2(0, 0)): func load_file(filename): clear_material() - generator = MMGenLoader.load_gen(filename) - if generator != null: - add_child(generator) - update_graph(generator.get_children(), generator.connections) + top_generator = MMGenLoader.load_gen(filename) + if top_generator != null: + add_child(top_generator) + update_view(top_generator) set_save_path(filename) set_need_save(false) center_view() func save_file(filename): - var data = generator.serialize() + var data = top_generator.serialize() var file = File.new() if file.open(filename, File.WRITE) == OK: file.store_string(to_json(data)) @@ -258,3 +268,7 @@ func drop_data(position, data): Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) create_nodes(data, offset_from_global_position(get_global_transform().xform(position))) return true + +func on_ButtonUp_pressed(): + if generator != top_generator && generator.get_parent() is MMGenGraph: + call_deferred("update_view", generator.get_parent()) diff --git a/addons/material_maker/graph_edit.tscn b/addons/material_maker/graph_edit.tscn index 2b611c3..ad08ee3 100644 --- a/addons/material_maker/graph_edit.tscn +++ b/addons/material_maker/graph_edit.tscn @@ -13,6 +13,16 @@ script = ExtResource( 1 ) [node name="Timer" type="Timer" parent="."] wait_time = 0.2 one_shot = true + +[node name="ButtonUp" type="Button" parent="."] +anchor_left = 1.0 +anchor_right = 1.0 +margin_left = -44.0 +margin_top = 4.0 +margin_right = -14.0 +margin_bottom = 24.0 +text = "Up" [connection signal="connection_request" from="." to="." method="connect_node"] [connection signal="disconnection_request" from="." to="." method="disconnect_node"] [connection signal="timeout" from="Timer" to="." method="do_send_changed_signal"] +[connection signal="pressed" from="ButtonUp" to="." method="on_ButtonUp_pressed"] diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index fc83735..c16c2b9 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -206,12 +206,8 @@ func update_node(): edit_buttons.connect_buttons(self, "edit_generator", "load_generator", "save_generator") func edit_generator(): - var edit_window = load("res://addons/material_maker/widgets/node_editor/node_editor.tscn").instance() - get_parent().add_child(edit_window) - if generator.shader_model != null: - edit_window.set_model_data(generator.shader_model) - edit_window.connect("node_changed", self, "update_generator") - edit_window.popup_centered() + if generator.has_method("edit"): + generator.edit(self) func update_generator(shader_model): generator.set_shader_model(shader_model)