2018-10-09 07:24:44 +02:00
|
|
|
tool
|
2018-10-02 07:46:20 +02:00
|
|
|
extends WindowDialog
|
|
|
|
|
2018-10-09 07:24:44 +02:00
|
|
|
var model_data = null
|
2018-10-02 07:46:20 +02:00
|
|
|
|
2019-10-26 13:51:15 +02:00
|
|
|
onready var parameter_list : VBoxContainer = $Sizer/Tabs/General/Parameters/Sizer
|
|
|
|
onready var input_list : VBoxContainer = $Sizer/Tabs/General/Inputs/Sizer
|
|
|
|
onready var output_list : VBoxContainer = $Sizer/Tabs/Outputs/Outputs/Sizer
|
|
|
|
|
2019-10-10 07:42:38 +02:00
|
|
|
onready var main_code_editor : TextEdit = $"Sizer/Tabs/Main Code"
|
|
|
|
onready var instance_functions_editor : TextEdit = $"Sizer/Tabs/Instance Functions"
|
|
|
|
onready var global_functions_editor : TextEdit = $"Sizer/Tabs/Global Functions"
|
2019-10-07 20:41:57 +02:00
|
|
|
|
2018-10-09 07:24:44 +02:00
|
|
|
const ParameterEditor = preload("res://addons/material_maker/widgets/node_editor/parameter.tscn")
|
|
|
|
const InputEditor = preload("res://addons/material_maker/widgets/node_editor/input.tscn")
|
|
|
|
const OutputEditor = preload("res://addons/material_maker/widgets/node_editor/output.tscn")
|
2018-10-02 07:46:20 +02:00
|
|
|
|
2018-10-09 07:24:44 +02:00
|
|
|
signal node_changed
|
2018-10-02 07:46:20 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _ready() -> void:
|
2019-10-10 07:42:38 +02:00
|
|
|
main_code_editor.add_color_region("//", "", Color(0, 0.5, 0), true)
|
|
|
|
instance_functions_editor.add_color_region("//", "", Color(0, 0.5, 0), true)
|
|
|
|
global_functions_editor.add_color_region("//", "", Color(0, 0.5, 0), true)
|
2019-10-07 20:41:57 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func add_item(parent, scene) -> Node:
|
2018-10-09 07:24:44 +02:00
|
|
|
var object = scene.instance()
|
|
|
|
parent.add_child(object)
|
|
|
|
parent.move_child(object, parent.get_child_count()-2)
|
|
|
|
return object
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func set_model_data(data) -> void:
|
2018-10-09 07:24:44 +02:00
|
|
|
if data.has("name"):
|
|
|
|
$Sizer/Tabs/General/Name/Name.text = data.name
|
|
|
|
if data.has("parameters"):
|
|
|
|
for p in data.parameters:
|
2019-10-26 13:51:15 +02:00
|
|
|
add_item(parameter_list, ParameterEditor).set_model_data(p)
|
|
|
|
parameter_list.update_up_down_buttons()
|
2018-11-11 19:18:26 +01:00
|
|
|
if data.has("inputs"):
|
|
|
|
for i in data.inputs:
|
2019-10-26 13:51:15 +02:00
|
|
|
add_item(input_list, InputEditor).set_model_data(i)
|
|
|
|
input_list.update_up_down_buttons()
|
2018-10-09 07:24:44 +02:00
|
|
|
if data.has("outputs"):
|
|
|
|
for o in data.outputs:
|
2019-10-26 13:51:15 +02:00
|
|
|
add_item(output_list, OutputEditor).set_model_data(o)
|
|
|
|
output_list.update_up_down_buttons()
|
2018-10-09 07:24:44 +02:00
|
|
|
if data.has("global"):
|
2019-10-10 07:42:38 +02:00
|
|
|
global_functions_editor.text = data.global
|
2018-10-09 07:24:44 +02:00
|
|
|
if data.has("instance"):
|
2019-10-10 07:42:38 +02:00
|
|
|
instance_functions_editor.text = data.instance
|
|
|
|
if data.has("code"):
|
|
|
|
main_code_editor.text = data.code
|
2018-10-09 07:24:44 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_model_data() -> Dictionary:
|
2018-10-09 07:24:44 +02:00
|
|
|
var data = {
|
|
|
|
name=$Sizer/Tabs/General/Name/Name.text,
|
2019-10-10 07:42:38 +02:00
|
|
|
global=global_functions_editor.text,
|
|
|
|
instance=instance_functions_editor.text,
|
|
|
|
code=main_code_editor.text
|
2018-10-09 07:24:44 +02:00
|
|
|
}
|
|
|
|
data.parameters = []
|
2019-10-26 13:51:15 +02:00
|
|
|
for p in parameter_list.get_children():
|
2018-10-09 07:24:44 +02:00
|
|
|
if p.has_method("get_model_data"):
|
|
|
|
data.parameters.append(p.get_model_data())
|
2018-11-11 19:18:26 +01:00
|
|
|
data.inputs = []
|
2019-10-26 13:51:15 +02:00
|
|
|
for i in input_list.get_children():
|
2018-11-11 19:18:26 +01:00
|
|
|
if i.has_method("get_model_data"):
|
|
|
|
data.inputs.append(i.get_model_data())
|
2018-10-09 07:24:44 +02:00
|
|
|
data.outputs = []
|
2019-10-26 13:51:15 +02:00
|
|
|
for o in output_list.get_children():
|
2018-10-09 07:24:44 +02:00
|
|
|
if o.has_method("get_model_data"):
|
|
|
|
data.outputs.append(o.get_model_data())
|
|
|
|
return data
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_AddParameter_pressed() -> void:
|
2019-10-26 13:51:15 +02:00
|
|
|
add_item(parameter_list, ParameterEditor)
|
|
|
|
parameter_list.update_up_down_buttons()
|
2018-10-09 07:24:44 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_AddInput_pressed() -> void:
|
2019-10-26 13:51:15 +02:00
|
|
|
add_item(input_list, InputEditor)
|
|
|
|
input_list.update_up_down_buttons()
|
2018-10-09 07:24:44 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_AddOutput_pressed() -> void:
|
2019-10-26 13:51:15 +02:00
|
|
|
add_item(output_list, OutputEditor)
|
|
|
|
output_list.update_up_down_buttons()
|
2018-10-09 07:24:44 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_Apply_pressed() -> void:
|
2018-11-20 07:46:51 +01:00
|
|
|
emit_signal("node_changed", get_model_data())
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_OK_pressed() -> void:
|
2018-10-09 07:24:44 +02:00
|
|
|
emit_signal("node_changed", get_model_data())
|
|
|
|
queue_free()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_Cancel_pressed() -> void:
|
2018-10-09 07:24:44 +02:00
|
|
|
queue_free()
|