2019-10-21 23:58:14 +02:00
|
|
|
extends MMGraphNodeBase
|
2019-09-24 22:25:46 +02:00
|
|
|
class_name MMGraphNodeGeneric
|
2019-08-12 15:58:42 +02:00
|
|
|
|
2019-09-22 22:17:26 +02:00
|
|
|
var controls = {}
|
2019-09-26 22:32:49 +02:00
|
|
|
var ignore_parameter_change = ""
|
2019-10-05 11:04:50 +02:00
|
|
|
var output_count = 0
|
|
|
|
|
|
|
|
var preview : TextureRect
|
|
|
|
var preview_index : int = -1
|
|
|
|
var preview_position : int
|
|
|
|
var preview_size : int
|
2019-10-05 19:50:44 +02:00
|
|
|
var preview_timer : Timer = null
|
2019-08-13 13:38:11 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func set_generator(g) -> void:
|
2019-10-21 23:58:14 +02:00
|
|
|
.set_generator(g)
|
2019-09-22 22:17:26 +02:00
|
|
|
generator.connect("parameter_changed", self, "on_parameter_changed")
|
2020-01-03 16:03:53 +01:00
|
|
|
update_node()
|
2019-08-12 15:58:42 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func on_parameter_changed(p, v) -> void:
|
2019-09-26 22:32:49 +02:00
|
|
|
if ignore_parameter_change == p:
|
2019-09-24 22:25:46 +02:00
|
|
|
return
|
2019-10-20 00:59:51 +02:00
|
|
|
if p == "__update_all__":
|
2020-01-03 16:03:53 +01:00
|
|
|
update_node()
|
2019-10-20 00:59:51 +02:00
|
|
|
elif controls.has(p):
|
2019-10-09 20:39:08 +02:00
|
|
|
var o = controls[p]
|
2019-11-05 22:28:55 +01:00
|
|
|
if o is MMFloatEdit:
|
2019-10-09 20:39:08 +02:00
|
|
|
o.value = v
|
2019-11-14 08:47:21 +01:00
|
|
|
elif o is HSlider:
|
|
|
|
o.value = v
|
2019-11-05 22:28:55 +01:00
|
|
|
elif o is LineEdit:
|
|
|
|
o.text = v
|
2019-10-21 23:58:14 +02:00
|
|
|
elif o is SizeOptionButton:
|
|
|
|
o.size_value = v
|
2019-10-09 20:39:08 +02:00
|
|
|
elif o is OptionButton:
|
|
|
|
o.selected = v
|
|
|
|
elif o is CheckBox:
|
|
|
|
o.pressed = v
|
|
|
|
elif o is ColorPickerButton:
|
|
|
|
o.color = MMType.deserialize_value(v)
|
|
|
|
elif o is MMGradientEditor:
|
|
|
|
var gradient : MMGradient = MMGradient.new()
|
|
|
|
gradient.deserialize(v)
|
|
|
|
o.value = gradient
|
|
|
|
else:
|
|
|
|
print("unsupported widget "+str(o))
|
2019-09-24 22:25:46 +02:00
|
|
|
update_shaders()
|
2019-09-22 22:17:26 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func initialize_properties() -> void:
|
2019-09-22 22:17:26 +02:00
|
|
|
var parameter_names = []
|
|
|
|
for p in generator.get_parameter_defs():
|
|
|
|
parameter_names.push_back(p.name)
|
|
|
|
for c in controls:
|
|
|
|
if parameter_names.find(c) == -1:
|
2019-08-15 11:53:21 +02:00
|
|
|
continue
|
2019-09-22 22:17:26 +02:00
|
|
|
var o = controls[c]
|
2019-09-29 10:07:32 +02:00
|
|
|
if generator.parameters.has(c):
|
|
|
|
on_parameter_changed(c, generator.parameters[c])
|
2019-11-05 22:28:55 +01:00
|
|
|
if o is MMFloatEdit:
|
2019-08-13 13:38:11 +02:00
|
|
|
o.connect("value_changed", self, "_on_value_changed", [ o.name ])
|
2019-11-05 22:28:55 +01:00
|
|
|
elif o is LineEdit:
|
|
|
|
o.connect("text_changed", self, "_on_text_changed", [ o.name ])
|
2019-10-21 23:58:14 +02:00
|
|
|
elif o is SizeOptionButton:
|
|
|
|
o.connect("size_value_changed", self, "_on_value_changed", [ o.name ])
|
2019-08-13 13:38:11 +02:00
|
|
|
elif o is OptionButton:
|
|
|
|
o.connect("item_selected", self, "_on_value_changed", [ o.name ])
|
|
|
|
elif o is CheckBox:
|
|
|
|
o.connect("toggled", self, "_on_value_changed", [ o.name ])
|
|
|
|
elif o is ColorPickerButton:
|
|
|
|
o.connect("color_changed", self, "_on_color_changed", [ o.name ])
|
2020-01-27 08:17:18 +01:00
|
|
|
elif o is Control and o.filename == "res://material_maker/widgets/gradient_editor.tscn":
|
2019-08-13 13:38:11 +02:00
|
|
|
o.connect("updated", self, "_on_gradient_changed", [ o.name ])
|
|
|
|
else:
|
|
|
|
print("unsupported widget "+str(o))
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func update_shaders() -> void:
|
2019-08-13 13:38:11 +02:00
|
|
|
get_parent().send_changed_signal()
|
2019-10-05 11:04:50 +02:00
|
|
|
update_preview()
|
2019-08-13 13:38:11 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_text_changed(new_text, variable) -> void:
|
2019-09-26 22:32:49 +02:00
|
|
|
ignore_parameter_change = variable
|
2019-11-02 08:43:54 +01:00
|
|
|
generator.set_parameter(variable, new_text)
|
2019-09-26 22:32:49 +02:00
|
|
|
ignore_parameter_change = ""
|
2019-08-13 13:38:11 +02:00
|
|
|
update_shaders()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_value_changed(new_value, variable) -> void:
|
2019-09-26 22:32:49 +02:00
|
|
|
ignore_parameter_change = variable
|
2019-09-14 09:14:27 +02:00
|
|
|
generator.set_parameter(variable, new_value)
|
2019-09-26 22:32:49 +02:00
|
|
|
ignore_parameter_change = ""
|
2019-08-13 13:38:11 +02:00
|
|
|
update_shaders()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_color_changed(new_color, variable) -> void:
|
2019-09-26 22:32:49 +02:00
|
|
|
ignore_parameter_change = variable
|
2019-09-14 09:14:27 +02:00
|
|
|
generator.set_parameter(variable, new_color)
|
2019-09-26 22:32:49 +02:00
|
|
|
ignore_parameter_change = ""
|
2019-08-13 13:38:11 +02:00
|
|
|
update_shaders()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_gradient_changed(new_gradient, variable) -> void:
|
2019-09-26 22:32:49 +02:00
|
|
|
ignore_parameter_change = variable
|
|
|
|
generator.set_parameter(variable, MMType.serialize_value(new_gradient))
|
|
|
|
ignore_parameter_change = ""
|
2019-08-13 13:38:11 +02:00
|
|
|
update_shaders()
|
2019-08-12 15:58:42 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func create_parameter_control(p : Dictionary) -> Control:
|
2019-09-24 22:25:46 +02:00
|
|
|
var control = null
|
|
|
|
if p.type == "float":
|
2020-01-25 15:20:08 +01:00
|
|
|
control = preload("res://material_maker/widgets/float_edit.tscn").instance()
|
2019-09-24 22:25:46 +02:00
|
|
|
control.min_value = p.min
|
|
|
|
control.max_value = p.max
|
|
|
|
control.step = 0.005 if !p.has("step") else p.step
|
|
|
|
if p.has("default"):
|
|
|
|
control.value = p.default
|
|
|
|
control.rect_min_size.x = 80
|
|
|
|
elif p.type == "size":
|
2019-10-21 23:58:14 +02:00
|
|
|
control = SizeOptionButton.new()
|
|
|
|
control.min_size = p.first
|
|
|
|
control.max_size = p.last
|
|
|
|
control.size_value = p.first if !p.has("default") else p.default
|
2019-09-24 22:25:46 +02:00
|
|
|
elif p.type == "enum":
|
|
|
|
control = OptionButton.new()
|
|
|
|
for i in range(p.values.size()):
|
|
|
|
var value = p.values[i]
|
|
|
|
control.add_item(value.name)
|
|
|
|
control.selected = 0 if !p.has("default") else p.default
|
|
|
|
elif p.type == "boolean":
|
|
|
|
control = CheckBox.new()
|
|
|
|
elif p.type == "color":
|
|
|
|
control = ColorPickerButton.new()
|
2019-11-27 07:45:58 +01:00
|
|
|
control.rect_min_size.x = 40
|
2019-09-24 22:25:46 +02:00
|
|
|
elif p.type == "gradient":
|
2020-01-25 15:20:08 +01:00
|
|
|
control = preload("res://material_maker/widgets/gradient_editor.tscn").instance()
|
2019-11-02 08:43:54 +01:00
|
|
|
elif p.type == "string":
|
|
|
|
control = LineEdit.new()
|
2019-09-24 22:25:46 +02:00
|
|
|
return control
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func save_preview_widget() -> void:
|
2019-12-25 10:36:45 +01:00
|
|
|
if preview != null and preview.get_parent() == self:
|
2019-10-07 20:41:57 +02:00
|
|
|
remove_child(preview)
|
2019-10-05 19:50:44 +02:00
|
|
|
if preview_timer != null:
|
|
|
|
preview_timer.stop()
|
|
|
|
remove_child(preview_timer)
|
2019-10-20 00:59:51 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func restore_preview_widget() -> void:
|
2019-10-20 00:59:51 +02:00
|
|
|
if preview == null:
|
|
|
|
preview = TextureRect.new()
|
|
|
|
preview.visible = false
|
|
|
|
preview_position = get_child_count()
|
|
|
|
if preview.visible:
|
|
|
|
add_child(preview)
|
|
|
|
update_preview()
|
|
|
|
set_slot(preview_position, false, 0, Color(0.0, 0.0, 0.0), false, 0, Color(0.0, 0.0, 0.0))
|
|
|
|
# Preview timer
|
|
|
|
if preview_timer == null:
|
|
|
|
preview_timer = Timer.new()
|
|
|
|
preview_timer.one_shot = true
|
|
|
|
preview_timer.connect("timeout", self, "do_update_preview")
|
|
|
|
add_child(preview_timer)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func update_node() -> void:
|
2019-10-20 00:59:51 +02:00
|
|
|
# Clean node
|
|
|
|
var custom_node_buttons = null
|
2020-01-03 16:03:53 +01:00
|
|
|
clear_all_slots()
|
2019-10-20 00:59:51 +02:00
|
|
|
save_preview_widget()
|
2019-08-12 15:58:42 +02:00
|
|
|
for c in get_children():
|
2019-10-05 22:24:00 +02:00
|
|
|
remove_child(c)
|
|
|
|
c.free()
|
2019-09-09 22:00:18 +02:00
|
|
|
rect_size = Vector2(0, 0)
|
2019-10-19 01:30:25 +02:00
|
|
|
# Show or hide the close button
|
|
|
|
show_close = generator.can_be_deleted()
|
2019-08-12 15:58:42 +02:00
|
|
|
# Rebuild node
|
2019-08-17 17:35:48 +02:00
|
|
|
title = generator.get_type_name()
|
2019-09-10 22:51:49 +02:00
|
|
|
# Inputs
|
|
|
|
var inputs = generator.get_input_defs()
|
|
|
|
for i in range(inputs.size()):
|
|
|
|
var input = inputs[i]
|
|
|
|
var enable_left = false
|
|
|
|
var color_left = Color(0.5, 0.5, 0.5)
|
2019-12-22 23:27:02 +01:00
|
|
|
var type_left = 0
|
2019-09-10 22:51:49 +02:00
|
|
|
if typeof(input) == TYPE_DICTIONARY:
|
2019-12-15 12:41:00 +01:00
|
|
|
enable_left = true
|
2020-02-05 06:36:49 +01:00
|
|
|
if mm_io_types.types.has(input.type):
|
|
|
|
color_left = mm_io_types.types[input.type].color
|
|
|
|
type_left = mm_io_types.types[input.type].slot_type
|
2019-12-22 23:27:02 +01:00
|
|
|
set_slot(i, enable_left, type_left, color_left, false, 0, Color())
|
2019-09-10 22:51:49 +02:00
|
|
|
var hsizer : HBoxContainer = HBoxContainer.new()
|
|
|
|
hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
2019-10-05 11:04:50 +02:00
|
|
|
if input.has("label") and input.label != "":
|
|
|
|
var label : Label = Label.new()
|
|
|
|
label.text = input.label
|
|
|
|
hsizer.add_child(label)
|
|
|
|
else:
|
|
|
|
var control : Control = Control.new()
|
|
|
|
control.rect_min_size.y = 16
|
|
|
|
hsizer.add_child(control)
|
2019-09-10 22:51:49 +02:00
|
|
|
add_child(hsizer)
|
|
|
|
var input_names_width : int = 0
|
|
|
|
for c in get_children():
|
|
|
|
var width = c.get_child(0).rect_size.x
|
|
|
|
if width > input_names_width:
|
|
|
|
input_names_width = width
|
|
|
|
if input_names_width > 0:
|
|
|
|
input_names_width += 3
|
|
|
|
for c in get_children():
|
|
|
|
c.get_child(0).rect_min_size.x = input_names_width
|
2019-08-17 17:35:48 +02:00
|
|
|
# Parameters
|
2019-09-22 22:17:26 +02:00
|
|
|
controls = {}
|
2019-09-10 22:51:49 +02:00
|
|
|
var index = -1
|
2019-09-11 23:13:10 +02:00
|
|
|
var regex = RegEx.new()
|
|
|
|
regex.compile("^(\\d+):(.*)")
|
2019-08-17 17:35:48 +02:00
|
|
|
for p in generator.get_parameter_defs():
|
|
|
|
if !p.has("name") or !p.has("type"):
|
|
|
|
continue
|
2019-09-24 22:25:46 +02:00
|
|
|
var control = create_parameter_control(p)
|
2019-08-17 17:35:48 +02:00
|
|
|
if control != null:
|
|
|
|
var label = p.name
|
|
|
|
control.name = label
|
2019-09-22 22:17:26 +02:00
|
|
|
controls[control.name] = control
|
2019-08-17 17:35:48 +02:00
|
|
|
if p.has("label"):
|
|
|
|
label = p.label
|
2019-09-11 23:13:10 +02:00
|
|
|
var result = regex.search(label)
|
|
|
|
if result:
|
|
|
|
index = result.get_string(1).to_int()-1
|
|
|
|
label = result.get_string(2)
|
|
|
|
else:
|
2019-09-10 22:51:49 +02:00
|
|
|
index += 1
|
|
|
|
var hsizer : HBoxContainer
|
2019-09-11 23:13:10 +02:00
|
|
|
while index >= get_child_count():
|
2019-09-10 22:51:49 +02:00
|
|
|
hsizer = HBoxContainer.new()
|
|
|
|
hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
|
|
|
var empty_control : Control = Control.new()
|
|
|
|
empty_control.rect_min_size.x = input_names_width
|
|
|
|
hsizer.add_child(empty_control)
|
|
|
|
add_child(hsizer)
|
2019-09-11 23:13:10 +02:00
|
|
|
hsizer = get_child(index)
|
|
|
|
if label != "":
|
2019-08-17 17:35:48 +02:00
|
|
|
var label_widget = Label.new()
|
|
|
|
label_widget.text = label
|
|
|
|
label_widget.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
2019-09-10 22:51:49 +02:00
|
|
|
hsizer.add_child(label_widget)
|
2019-08-17 17:35:48 +02:00
|
|
|
control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
2019-12-15 12:41:00 +01:00
|
|
|
if hsizer != null:
|
|
|
|
hsizer.add_child(control)
|
2019-08-17 17:35:48 +02:00
|
|
|
initialize_properties()
|
2019-08-18 16:28:50 +02:00
|
|
|
# Outputs
|
|
|
|
var outputs = generator.get_output_defs()
|
2019-10-05 11:04:50 +02:00
|
|
|
var button_width = 0
|
|
|
|
output_count = outputs.size()
|
|
|
|
for i in range(output_count):
|
2019-08-18 16:28:50 +02:00
|
|
|
var output = outputs[i]
|
2019-12-22 23:27:02 +01:00
|
|
|
var enable_right : bool = true
|
|
|
|
var color_right : Color = Color(0.5, 0.5, 0.5)
|
|
|
|
var type_right : int = 0
|
2019-09-11 07:53:06 +02:00
|
|
|
assert(typeof(output) == TYPE_DICTIONARY)
|
|
|
|
assert(output.has("type"))
|
|
|
|
enable_right = true
|
2020-02-05 06:36:49 +01:00
|
|
|
if mm_io_types.types.has(output.type):
|
|
|
|
color_right = mm_io_types.types[output.type].color
|
|
|
|
type_right = mm_io_types.types[output.type].slot_type
|
2019-12-22 23:27:02 +01:00
|
|
|
set_slot(i, is_slot_enabled_left(i), get_slot_type_left(i), get_slot_color_left(i), enable_right, type_right, color_right)
|
2019-10-05 11:04:50 +02:00
|
|
|
var hsizer : HBoxContainer
|
|
|
|
while i >= get_child_count():
|
|
|
|
hsizer = HBoxContainer.new()
|
|
|
|
hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
|
|
|
add_child(hsizer)
|
|
|
|
hsizer = get_child(i)
|
|
|
|
var has_filler = false
|
|
|
|
for c in hsizer.get_children():
|
|
|
|
if c.size_flags_horizontal & SIZE_EXPAND != 0:
|
|
|
|
has_filler = true
|
|
|
|
break
|
|
|
|
if !has_filler:
|
|
|
|
var empty_control : Control = Control.new()
|
|
|
|
empty_control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
|
|
|
|
hsizer.add_child(empty_control)
|
2020-01-25 15:20:08 +01:00
|
|
|
var button = preload("res://material_maker/widgets/preview_button.tscn").instance()
|
2019-10-05 11:04:50 +02:00
|
|
|
button.size_flags_horizontal = SIZE_SHRINK_END
|
|
|
|
button.size_flags_vertical = SIZE_SHRINK_CENTER
|
2019-10-05 19:50:44 +02:00
|
|
|
if i == preview_index:
|
|
|
|
button.pressed = true
|
2019-10-05 11:04:50 +02:00
|
|
|
hsizer.add_child(button)
|
|
|
|
button.connect("toggled", self, "on_preview_button", [ i ])
|
|
|
|
button_width = button.rect_size.x
|
|
|
|
if !outputs.empty():
|
|
|
|
for i in range(output_count, get_child_count()):
|
|
|
|
var hsizer : HBoxContainer = get_child(i)
|
|
|
|
var empty_control : Control = Control.new()
|
|
|
|
empty_control.rect_min_size.x = button_width
|
|
|
|
hsizer.add_child(empty_control)
|
|
|
|
# Edit buttons
|
2019-10-20 00:59:51 +02:00
|
|
|
if generator.is_editable():
|
2020-01-25 15:20:08 +01:00
|
|
|
var edit_buttons = preload("res://material_maker/nodes/edit_buttons.tscn").instance()
|
2019-09-09 22:00:18 +02:00
|
|
|
add_child(edit_buttons)
|
|
|
|
edit_buttons.connect_buttons(self, "edit_generator", "load_generator", "save_generator")
|
2019-10-20 00:59:51 +02:00
|
|
|
set_slot(edit_buttons.get_index(), false, 0, Color(0.0, 0.0, 0.0), false, 0, Color(0.0, 0.0, 0.0))
|
|
|
|
# Preview
|
|
|
|
restore_preview_widget()
|
2019-09-09 22:00:18 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func edit_generator() -> void:
|
2019-09-19 07:56:32 +02:00
|
|
|
if generator.has_method("edit"):
|
|
|
|
generator.edit(self)
|
2019-09-09 22:00:18 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func update_generator(shader_model) -> void:
|
2019-09-11 23:13:10 +02:00
|
|
|
generator.set_shader_model(shader_model)
|
2019-09-09 22:00:18 +02:00
|
|
|
update_node()
|
2019-09-26 22:32:49 +02:00
|
|
|
update_shaders()
|
2019-09-09 22:00:18 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func load_generator() -> void:
|
2019-09-09 22:00:18 +02:00
|
|
|
var dialog = FileDialog.new()
|
|
|
|
add_child(dialog)
|
|
|
|
dialog.rect_min_size = Vector2(500, 500)
|
|
|
|
dialog.access = FileDialog.ACCESS_FILESYSTEM
|
|
|
|
dialog.mode = FileDialog.MODE_OPEN_FILE
|
|
|
|
dialog.add_filter("*.mmg,*.mmn;Material Maker Generator")
|
|
|
|
dialog.connect("file_selected", self, "do_load_generator")
|
|
|
|
dialog.popup_centered()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func do_load_generator(file_name : String) -> void:
|
2019-09-09 22:00:18 +02:00
|
|
|
var new_generator = null
|
|
|
|
if file_name.ends_with(".mmn"):
|
|
|
|
var file = File.new()
|
|
|
|
if file.open(file_name, File.READ) == OK:
|
|
|
|
new_generator = MMGenShader.new()
|
|
|
|
new_generator.set_shader_model(parse_json(file.get_as_text()))
|
|
|
|
file.close()
|
|
|
|
else:
|
2020-01-28 11:47:29 +01:00
|
|
|
new_generator = mm_loader.load_gen(file_name)
|
2019-09-09 22:00:18 +02:00
|
|
|
if new_generator != null:
|
2020-01-28 11:47:29 +01:00
|
|
|
var gen_name = mm_loader.generator_name_from_path(file_name)
|
2019-10-07 20:41:57 +02:00
|
|
|
if gen_name != "":
|
2019-10-12 07:10:25 +02:00
|
|
|
new_generator.model = gen_name
|
2019-09-09 22:00:18 +02:00
|
|
|
var parent_generator = generator.get_parent()
|
|
|
|
parent_generator.replace_generator(generator, new_generator)
|
|
|
|
generator = new_generator
|
2020-01-03 16:03:53 +01:00
|
|
|
update_node()
|
2019-09-09 22:00:18 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func save_generator() -> void:
|
2019-09-09 22:00:18 +02:00
|
|
|
var dialog = FileDialog.new()
|
|
|
|
add_child(dialog)
|
|
|
|
dialog.rect_min_size = Vector2(500, 500)
|
|
|
|
dialog.access = FileDialog.ACCESS_FILESYSTEM
|
|
|
|
dialog.mode = FileDialog.MODE_SAVE_FILE
|
|
|
|
dialog.add_filter("*.mmg;Material Maker Generator")
|
|
|
|
dialog.connect("file_selected", self, "do_save_generator")
|
|
|
|
dialog.popup_centered()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func do_save_generator(file_name : String) -> void:
|
2019-09-09 22:00:18 +02:00
|
|
|
var file = File.new()
|
|
|
|
if file.open(file_name, File.WRITE) == OK:
|
2019-09-10 22:51:49 +02:00
|
|
|
var data = generator.serialize()
|
|
|
|
data.name = file_name.get_file().get_basename()
|
|
|
|
data.node_position = { x=0, y=0 }
|
2019-10-27 14:36:16 +01:00
|
|
|
file.store_string(JSON.print(data, "\t", true))
|
2019-09-09 22:00:18 +02:00
|
|
|
file.close()
|
2019-10-05 11:04:50 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func update_preview_buttons(index : int) -> void:
|
2019-10-20 00:59:51 +02:00
|
|
|
for i in range(output_count):
|
|
|
|
if i != index:
|
|
|
|
var line = get_child(i)
|
|
|
|
line.get_child(line.get_child_count()-1).pressed = false
|
|
|
|
|
2020-01-28 23:11:27 +01:00
|
|
|
var processing_button = false
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func on_preview_button(pressed : bool, index : int) -> void:
|
2020-01-28 23:11:27 +01:00
|
|
|
if processing_button:
|
|
|
|
return
|
|
|
|
processing_button = true
|
2019-10-05 11:04:50 +02:00
|
|
|
if pressed:
|
|
|
|
preview_index = index
|
|
|
|
var width
|
|
|
|
if preview.visible:
|
2019-10-20 00:59:51 +02:00
|
|
|
update_preview_buttons(index)
|
2019-10-05 11:04:50 +02:00
|
|
|
update_preview()
|
|
|
|
else:
|
|
|
|
var status = update_preview(get_child(0).rect_size.x)
|
|
|
|
while status is GDScriptFunctionState:
|
|
|
|
status = yield(status, "completed")
|
|
|
|
else:
|
|
|
|
preview_index = -1
|
|
|
|
preview.visible = false
|
|
|
|
remove_child(preview)
|
|
|
|
rect_size = Vector2(0, 0)
|
2020-01-28 23:11:27 +01:00
|
|
|
processing_button = false
|
2019-10-05 11:04:50 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func update_preview(size : int = 0) -> void:
|
2019-10-05 11:04:50 +02:00
|
|
|
if preview_index == -1:
|
|
|
|
return
|
|
|
|
if size != 0:
|
|
|
|
preview_size = size
|
|
|
|
preview_timer.start(0.2)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func do_update_preview() -> void:
|
2019-12-15 12:41:00 +01:00
|
|
|
var result = generator.render(preview_index, preview_size, true)
|
2019-10-05 11:04:50 +02:00
|
|
|
while result is GDScriptFunctionState:
|
|
|
|
result = yield(result, "completed")
|
|
|
|
if preview.texture == null:
|
|
|
|
preview.texture = ImageTexture.new()
|
|
|
|
result.copy_to_texture(preview.texture)
|
|
|
|
result.release()
|
|
|
|
if !preview.visible:
|
|
|
|
add_child(preview)
|
|
|
|
move_child(preview, preview_position)
|
|
|
|
preview.visible = true
|