mirror of
https://github.com/Relintai/material-maker.git
synced 2024-12-23 21:16:54 +01:00
Added support for hierrachical navigation
This commit is contained in:
parent
07273fdd04
commit
ac4a5c39b6
@ -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)
|
@ -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()
|
||||
|
@ -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())
|
||||
|
@ -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"]
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user