diff --git a/addons/material_maker/engine/gen_remote.gd b/addons/material_maker/engine/gen_remote.gd index 42cf317..92e5fc7 100644 --- a/addons/material_maker/engine/gen_remote.gd +++ b/addons/material_maker/engine/gen_remote.gd @@ -66,7 +66,11 @@ func set_parameter(p, v): var configurations = widget.configurations.keys() configurations.sort() for w in widget.configurations[configurations[v]]: - parent.get_node(w.node).set_parameter(w.widget, w.value) + var node = parent.get_node(w.node) + if node != null: + print(w.value) + print(MMType.deserialize_value(w.value)) + node.set_parameter(w.widget, MMType.deserialize_value(w.value)) else: # incorrect configuration index print("error: incorrect config control parameter value") @@ -126,10 +130,11 @@ func update_configuration(index, config_name): var parent = get_parent() for w in widget.linked_widgets: var g = parent.get_node(w.node) - var value = g.parameters[w.widget] - if typeof(value) == TYPE_ARRAY or typeof(value) == TYPE_DICTIONARY: - value = value.duplicate() - c.push_back({ node=w.node, widget=w.widget, value=value }) + if g != null: + print(g.parameters[w.widget]) + var value = MMType.serialize_value(g.parameters[w.widget]) + print(value) + c.push_back({ node=w.node, widget=w.widget, value=value }) widget.configurations[config_name] = c emit_signal("parameter_changed", "", null) diff --git a/addons/material_maker/engine/loader.gd b/addons/material_maker/engine/loader.gd index f7842a1..bcd576f 100644 --- a/addons/material_maker/engine/loader.gd +++ b/addons/material_maker/engine/loader.gd @@ -51,7 +51,7 @@ static func create_gen(data) -> MMGenBase: generator.set_shader_model(data.model_data) elif data.has("widgets"): generator = MMGenRemote.new() - generator.set_widgets(data.widgets) + generator.set_widgets(data.widgets.duplicate(true)) elif data.has("type"): if data.type == "material": generator = MMGenMaterial.new() diff --git a/addons/material_maker/library/base.json b/addons/material_maker/library/base.json index 08bd7b8..730621a 100644 --- a/addons/material_maker/library/base.json +++ b/addons/material_maker/library/base.json @@ -259,6 +259,7 @@ }, { "tree_item":"Miscellaneous/Remote", - "type":"remote" + "type":"remote", + "widgets":[] } ]} \ No newline at end of file diff --git a/addons/material_maker/nodes/generic.gd b/addons/material_maker/nodes/generic.gd index 1b4481b..332c03a 100644 --- a/addons/material_maker/nodes/generic.gd +++ b/addons/material_maker/nodes/generic.gd @@ -5,7 +5,7 @@ class_name MMGraphNodeGeneric var generator = null setget set_generator var controls = {} -var ignore_parameter_change = false +var ignore_parameter_change = "" func set_generator(g): generator = g @@ -19,7 +19,7 @@ func on_offset_changed(): generator.position = offset func on_parameter_changed(p, v): - if ignore_parameter_change: + if ignore_parameter_change == p: return var o = controls[p] if o is LineEdit: @@ -34,7 +34,7 @@ func on_parameter_changed(p, v): o.pressed = v elif o is ColorPickerButton: o.color = MMType.deserialize_value(v) - elif o is Control and o.filename == "res://addons/material_maker/widgets/gradient_editor.tscn": + elif o is MMGradientEditor: var gradient : MMGradient = MMGradient.new() gradient.deserialize(v) o.value = gradient @@ -72,27 +72,27 @@ func update_shaders(): get_parent().send_changed_signal() func _on_text_changed(new_text, variable): - ignore_parameter_change = true + ignore_parameter_change = variable generator.set_parameter(variable, float(new_text)) - ignore_parameter_change = false + ignore_parameter_change = "" update_shaders() func _on_value_changed(new_value, variable): - ignore_parameter_change = true + ignore_parameter_change = variable generator.set_parameter(variable, new_value) - ignore_parameter_change = false + ignore_parameter_change = "" update_shaders() func _on_color_changed(new_color, variable): - ignore_parameter_change = true + ignore_parameter_change = variable generator.set_parameter(variable, new_color) - ignore_parameter_change = false + ignore_parameter_change = "" update_shaders() func _on_gradient_changed(new_gradient, variable): - ignore_parameter_change = true - generator.set_parameter(variable, new_gradient) - ignore_parameter_change = false + ignore_parameter_change = variable + generator.set_parameter(variable, MMType.serialize_value(new_gradient)) + ignore_parameter_change = "" update_shaders() func create_parameter_control(p : Dictionary): @@ -240,6 +240,7 @@ func edit_generator(): func update_generator(shader_model): generator.set_shader_model(shader_model) update_node() + update_shaders() func load_generator(): var dialog = FileDialog.new() diff --git a/addons/material_maker/nodes/remote.gd b/addons/material_maker/nodes/remote.gd index 332e48e..a85609a 100644 --- a/addons/material_maker/nodes/remote.gd +++ b/addons/material_maker/nodes/remote.gd @@ -2,24 +2,30 @@ tool extends MMGraphNodeGeneric class_name MMGraphNodeRemote +var links = {} + +onready var grid = $Controls + func add_control(text, control): - var index = $Controls.get_child_count() / 4 + var index = grid.get_child_count() / 4 var label = preload("res://addons/material_maker/widgets/linked_widgets/editable_label.tscn").instance() label.set_text(text) - $Controls.add_child(label) - $Controls.add_child(control) + grid.add_child(label) + grid.add_child(control) + control.connect("mouse_entered", self, "on_enter_widget", [ control ]) + control.connect("mouse_exited", self, "on_exit_widget", [ control ]) var button = Button.new() button.icon = preload("res://addons/material_maker/icons/link.png") - $Controls.add_child(button) + grid.add_child(button) button.connect("pressed", self, "_on_Link_pressed", [ index ]) button = Button.new() button.icon = preload("res://addons/material_maker/icons/remove.png") - $Controls.add_child(button) + grid.add_child(button) button.connect("pressed", generator, "remove_parameter", [ index ]) func update_node(): var i : int = 0 - for c in $Controls.get_children(): + for c in grid.get_children(): c.queue_free() yield(get_tree(), "idle_frame") controls = {} @@ -49,7 +55,7 @@ func _on_value_changed(new_value, variable): var widget = generator.widgets[param_index] if widget.type == "config_control": var configuration_count = widget.configurations.size() - var control = $Controls.get_child(param_index*4+1) + var control = grid.get_child(param_index*4+1) if new_value < configuration_count: ._on_value_changed(new_value, variable) var current = control.get_item_text(new_value) @@ -92,7 +98,7 @@ func _on_AddConfig_pressed(): func _on_Link_pressed(index): var link = MMNodeLink.new(get_parent()) - link.pick($Controls.get_child(index*4+1), generator, index) + link.pick(grid.get_child(index*4+1), generator, index) func _on_Remote_resize_request(new_minsize): print("_on_Remote_resize_request") @@ -102,7 +108,32 @@ func _on_HBoxContainer_minimum_size_changed(): print("_on_HBoxContainer_minimum_size_changed "+str($HBoxContainer.rect_min_size)) func on_parameter_changed(p, v): + print("remote.parameter_changed "+str(p)+" "+str(v)) if p == "": update_node() else: - .on_parameter_changed(p, v) \ No newline at end of file + .on_parameter_changed(p, v) + +func on_enter_widget(widget): + print("enter_widget "+widget.name) + var param_index = widget.name.trim_prefix("param").to_int() + var w = generator.widgets[param_index] + var new_links = [] + for l in w.linked_widgets: + var graph_node = get_parent().get_node("node_"+l.node) + if graph_node != null: + var control = graph_node.controls[l.widget] + if control != null: + var link = MMNodeLink.new(get_parent()) + link.show_link(widget, control) + new_links.push_back(link) + # free existing links if any + on_exit_widget(widget) + # store new links + links[widget] = new_links + +func on_exit_widget(widget): + if links.has(widget): + for l in links[widget]: + l.queue_free() + links.erase(widget) diff --git a/addons/material_maker/nodes/remote.tscn b/addons/material_maker/nodes/remote.tscn index 941f019..c0219f8 100644 --- a/addons/material_maker/nodes/remote.tscn +++ b/addons/material_maker/nodes/remote.tscn @@ -53,5 +53,7 @@ margin_right = 60.0 margin_bottom = 22.0 hint_tooltip = "Add configurations" icon = ExtResource( 3 ) +[connection signal="close_request" from="." to="." method="on_close_request"] +[connection signal="offset_changed" from="." to="." method="on_offset_changed"] [connection signal="pressed" from="HBoxContainer/AddLink" to="." method="_on_AddLink_pressed"] [connection signal="pressed" from="HBoxContainer/AddConfig" to="." method="_on_AddConfig_pressed"] diff --git a/addons/material_maker/types/gradient.gd b/addons/material_maker/types/gradient.gd index c56a6d4..ddbb1ec 100644 --- a/addons/material_maker/types/gradient.gd +++ b/addons/material_maker/types/gradient.gd @@ -100,3 +100,5 @@ func deserialize(v): clear() for p in v.points: add_point(p.v, p.c) + else: + print("Cannot deserialize gradient") diff --git a/addons/material_maker/widgets/gradient_editor.gd b/addons/material_maker/widgets/gradient_editor.gd index e79453a..66a343f 100644 --- a/addons/material_maker/widgets/gradient_editor.gd +++ b/addons/material_maker/widgets/gradient_editor.gd @@ -1,5 +1,6 @@ tool extends Control +class_name MMGradientEditor class GradientCursor: extends ColorRect @@ -50,9 +51,10 @@ func _ready(): set_value(MMGradient.new()) func set_value(v): + print("GradientEditor.set_value") value = v for c in get_children(): - if c != $Gradient && c != $Background: + if c != $Gradient and c != $Background: remove_child(c) c.free() for p in value.points: diff --git a/addons/material_maker/widgets/gradient_editor.tscn b/addons/material_maker/widgets/gradient_editor.tscn index ee0fe5d..01e47ec 100644 --- a/addons/material_maker/widgets/gradient_editor.tscn +++ b/addons/material_maker/widgets/gradient_editor.tscn @@ -2,21 +2,17 @@ [ext_resource path="res://addons/material_maker/widgets/gradient_editor.gd" type="Script" id=1] -[sub_resource type="Shader" id=3] - +[sub_resource type="Shader" id=1] code = "shader_type canvas_item; void fragment() { COLOR = vec4(vec3(2.0*fract(0.5*(floor(10.0*UV.x)+floor(2.0*UV.y)))), 1.0); }" -[sub_resource type="ShaderMaterial" id=4] - -render_priority = 0 -shader = SubResource( 3 ) - -[sub_resource type="Shader" id=1] +[sub_resource type="ShaderMaterial" id=2] +shader = SubResource( 1 ) +[sub_resource type="Shader" id=3] code = "shader_type canvas_item; vec4 gradient(float x) { if (x < 0.000000000) { @@ -28,113 +24,42 @@ vec4 gradient(float x) { } void fragment() { COLOR = gradient(UV.x); }" -[sub_resource type="ShaderMaterial" id=2] - -render_priority = 0 -shader = SubResource( 1 ) +[sub_resource type="ShaderMaterial" id=4] +shader = SubResource( 3 ) [sub_resource type="Theme" id=5] - [node name="Control" type="Control"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_right = 120.0 margin_bottom = 30.0 rect_min_size = Vector2( 120, 30 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 script = ExtResource( 1 ) -_sections_unfolded = [ "Rect" ] - -[node name="Background" type="ColorRect" parent="." index="0"] - -material = SubResource( 4 ) -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 -margin_right = 120.0 -margin_bottom = 20.0 -rect_min_size = Vector2( 120, 20 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -color = Color( 1, 1, 1, 1 ) -_sections_unfolded = [ "Material", "Rect" ] - -[node name="Gradient" type="ColorRect" parent="." index="1"] +[node name="Background" type="ColorRect" parent="."] material = SubResource( 2 ) -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_right = 120.0 margin_bottom = 20.0 rect_min_size = Vector2( 120, 20 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 +mouse_filter = 2 + +[node name="Gradient" type="ColorRect" parent="."] +material = SubResource( 4 ) +margin_right = 120.0 +margin_bottom = 20.0 +rect_min_size = Vector2( 120, 20 ) +mouse_filter = 2 theme = SubResource( 5 ) -color = Color( 1, 1, 1, 1 ) -_sections_unfolded = [ "Material", "Theme" ] -[node name="Popup" type="Popup" parent="Gradient" index="0"] - -visible = false -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Popup" type="Popup" parent="Gradient"] margin_left = 47.0 margin_top = 33.0 margin_right = 353.0 margin_bottom = 475.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -popup_exclusive = false -[node name="ColorPicker" type="ColorPicker" parent="Gradient/Popup" index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="ColorPicker" type="ColorPicker" parent="Gradient/Popup"] margin_left = 4.0 margin_top = 4.0 margin_right = 4.0 margin_bottom = 4.0 rect_scale = Vector2( 0.75, 0.75 ) -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 1 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -alignment = 0 -color = Color( 1, 1, 1, 1 ) -edit_alpha = true -raw_mode = false -_sections_unfolded = [ "Rect" ] - [connection signal="popup_hide" from="Gradient/Popup" to="." method="_on_Popup_popup_hide"] - - diff --git a/addons/material_maker/widgets/linked_widgets/link.gd b/addons/material_maker/widgets/linked_widgets/link.gd index 7d3df28..5e4bf5c 100644 --- a/addons/material_maker/widgets/linked_widgets/link.gd +++ b/addons/material_maker/widgets/linked_widgets/link.gd @@ -46,8 +46,8 @@ func find_control(gp): return null func _draw(): - draw_rect(Rect2(rect_position, rect_size), Color(1.0, 0.0, 0.0, 0.2)) - draw_rect(Rect2(rect_position, rect_size), Color(1.0, 1.0, 0.0), false) + #draw_rect(Rect2(rect_position, rect_size), Color(1.0, 0.0, 0.0, 0.2)) + #draw_rect(Rect2(rect_position, rect_size), Color(1.0, 1.0, 0.0), false) var start = get_global_transform().xform_inv(source.get_global_transform().xform(0.5*source.rect_size)) var color = Color(1, 0.5, 0.5, 0.5) var rect diff --git a/project.godot b/project.godot index e488d5a..ae19cfd 100644 --- a/project.godot +++ b/project.godot @@ -84,6 +84,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/material_maker/types/gradient.gd" }, { +"base": "Control", +"class": "MMGradientEditor", +"language": "GDScript", +"path": "res://addons/material_maker/widgets/gradient_editor.gd" +}, { "base": "GraphNode", "class": "MMGraphNodeGeneric", "language": "GDScript", @@ -120,6 +125,7 @@ _global_script_class_icons={ "MMGenSwitch": "", "MMGenTexture": "", "MMGradient": "", +"MMGradientEditor": "", "MMGraphNodeGeneric": "", "MMGraphNodeRemote": "", "MMNodeLink": "",