2018-09-08 12:25:28 +02:00
|
|
|
tool
|
2019-09-24 22:25:46 +02:00
|
|
|
extends MMGraphNodeGeneric
|
|
|
|
class_name MMGraphNodeRemote
|
2018-09-08 12:25:28 +02:00
|
|
|
|
2019-09-26 22:32:49 +02:00
|
|
|
var links = {}
|
|
|
|
|
|
|
|
onready var grid = $Controls
|
|
|
|
|
2019-09-24 22:25:46 +02:00
|
|
|
func add_control(text, control):
|
2019-09-26 22:32:49 +02:00
|
|
|
var index = grid.get_child_count() / 4
|
2019-09-24 22:25:46 +02:00
|
|
|
var label = preload("res://addons/material_maker/widgets/linked_widgets/editable_label.tscn").instance()
|
|
|
|
label.set_text(text)
|
2019-09-26 22:32:49 +02:00
|
|
|
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 ])
|
2019-09-24 22:25:46 +02:00
|
|
|
var button = Button.new()
|
2019-10-06 14:07:49 +02:00
|
|
|
button.icon = preload("res://addons/material_maker/icons/link.tres")
|
2019-09-26 22:32:49 +02:00
|
|
|
grid.add_child(button)
|
2019-09-24 22:25:46 +02:00
|
|
|
button.connect("pressed", self, "_on_Link_pressed", [ index ])
|
|
|
|
button = Button.new()
|
2019-10-06 14:07:49 +02:00
|
|
|
button.icon = preload("res://addons/material_maker/icons/remove.tres")
|
2019-09-26 22:32:49 +02:00
|
|
|
grid.add_child(button)
|
2019-09-24 22:25:46 +02:00
|
|
|
button.connect("pressed", generator, "remove_parameter", [ index ])
|
2019-09-20 20:43:57 +02:00
|
|
|
|
|
|
|
func update_node():
|
2019-09-24 22:25:46 +02:00
|
|
|
var i : int = 0
|
2019-09-26 22:32:49 +02:00
|
|
|
for c in grid.get_children():
|
2019-09-24 22:25:46 +02:00
|
|
|
c.queue_free()
|
|
|
|
yield(get_tree(), "idle_frame")
|
2019-09-29 10:07:32 +02:00
|
|
|
title = generator.get_type_name()
|
2019-09-24 22:25:46 +02:00
|
|
|
controls = {}
|
|
|
|
for p in generator.get_parameter_defs():
|
|
|
|
var control = create_parameter_control(p)
|
|
|
|
if control != null:
|
|
|
|
control.name = p.name
|
|
|
|
controls[control.name] = control
|
|
|
|
add_control(generator.widgets[i].label, control)
|
2019-09-25 08:04:36 +02:00
|
|
|
if generator.widgets[i].type == "config_control":
|
|
|
|
var current = null
|
|
|
|
if control.get_item_count() > 0:
|
|
|
|
control.selected = generator.parameters["param"+str(i)]
|
|
|
|
current = control.get_item_text(control.selected)
|
|
|
|
control.add_separator()
|
|
|
|
control.add_item("<add configuration>")
|
|
|
|
if current != null:
|
|
|
|
control.add_separator()
|
|
|
|
control.add_item("<update "+current+">")
|
|
|
|
control.add_item("<remove "+current+">")
|
2019-09-24 22:25:46 +02:00
|
|
|
i += 1
|
|
|
|
rect_size = Vector2(0, 0)
|
|
|
|
initialize_properties()
|
2018-09-08 12:25:28 +02:00
|
|
|
|
2019-09-25 08:04:36 +02:00
|
|
|
func _on_value_changed(new_value, variable):
|
|
|
|
var param_index = variable.trim_prefix("param").to_int()
|
|
|
|
var widget = generator.widgets[param_index]
|
2019-09-25 23:29:06 +02:00
|
|
|
if widget.type == "config_control":
|
|
|
|
var configuration_count = widget.configurations.size()
|
2019-09-26 22:32:49 +02:00
|
|
|
var control = grid.get_child(param_index*4+1)
|
2019-09-25 23:29:06 +02:00
|
|
|
if new_value < configuration_count:
|
|
|
|
._on_value_changed(new_value, variable)
|
|
|
|
var current = control.get_item_text(new_value)
|
|
|
|
control.set_item_text(configuration_count+3, "<update "+current+">")
|
|
|
|
control.set_item_text(configuration_count+4, "<remove "+current+">")
|
|
|
|
else:
|
|
|
|
var current = control.get_item_text(generator.parameters[variable])
|
|
|
|
var command = new_value - widget.configurations.size()
|
|
|
|
match command:
|
|
|
|
1:
|
|
|
|
var dialog = preload("res://addons/material_maker/widgets/line_dialog.tscn").instance()
|
|
|
|
add_child(dialog)
|
|
|
|
dialog.set_texts("Configuration", "Enter a name for the new configuration")
|
|
|
|
dialog.connect("ok", self, "do_add_configuration", [ param_index ])
|
|
|
|
dialog.popup_centered()
|
|
|
|
3:
|
|
|
|
generator.update_configuration(param_index, current)
|
|
|
|
4:
|
|
|
|
generator.parameters[variable] = 0
|
|
|
|
generator.remove_configuration(param_index, current)
|
|
|
|
_:
|
|
|
|
print(command)
|
2019-09-25 08:04:36 +02:00
|
|
|
else:
|
|
|
|
._on_value_changed(new_value, variable)
|
|
|
|
|
2019-09-25 23:29:06 +02:00
|
|
|
func do_add_configuration(config_name, param_index):
|
|
|
|
generator.add_configuration(param_index, config_name)
|
|
|
|
|
2018-09-08 12:25:28 +02:00
|
|
|
func _on_AddLink_pressed():
|
2019-09-24 22:25:46 +02:00
|
|
|
var widget = Control.new()
|
|
|
|
add_control("Unnamed", widget)
|
|
|
|
var link = MMNodeLink.new(get_parent())
|
|
|
|
link.pick(widget, generator, generator.create_linked_control("Unnamed"), true)
|
2018-09-08 12:25:28 +02:00
|
|
|
|
|
|
|
func _on_AddConfig_pressed():
|
2019-09-24 22:25:46 +02:00
|
|
|
var widget = Control.new()
|
|
|
|
add_control("Unnamed", widget)
|
|
|
|
var link = MMNodeLink.new(get_parent())
|
|
|
|
link.pick(widget, generator, generator.create_config_control("Unnamed"), true)
|
|
|
|
|
|
|
|
func _on_Link_pressed(index):
|
|
|
|
var link = MMNodeLink.new(get_parent())
|
2019-09-26 22:32:49 +02:00
|
|
|
link.pick(grid.get_child(index*4+1), generator, index)
|
2018-09-08 12:25:28 +02:00
|
|
|
|
|
|
|
func _on_Remote_resize_request(new_minsize):
|
|
|
|
rect_size = new_minsize
|
|
|
|
|
|
|
|
func _on_HBoxContainer_minimum_size_changed():
|
|
|
|
print("_on_HBoxContainer_minimum_size_changed "+str($HBoxContainer.rect_min_size))
|
|
|
|
|
2019-09-24 22:25:46 +02:00
|
|
|
func on_parameter_changed(p, v):
|
|
|
|
if p == "":
|
|
|
|
update_node()
|
|
|
|
else:
|
2019-09-26 22:32:49 +02:00
|
|
|
.on_parameter_changed(p, v)
|
|
|
|
|
|
|
|
func on_enter_widget(widget):
|
|
|
|
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)
|