Updated switch to update connections when changing the number of choices/outputs and added tooltips

This commit is contained in:
RodZill4 2019-10-27 14:48:35 +01:00
parent f07e4475a2
commit 46d0e0f5cd
2 changed files with 31 additions and 3 deletions

View File

@ -45,6 +45,32 @@ func get_output_defs() -> Array:
return rv return rv
func set_parameter(p, v) -> void: func set_parameter(p, v) -> void:
if p == "outputs" or p == "choices":
var parent = get_parent()
if parent != null:
var connected_inputs : Array = parent.get_connected_inputs(self)
var connected_outputs : Array = parent.get_connected_outputs(self)
var inputs_changes : Dictionary = {}
var outputs_changes : Dictionary = {}
if p == "outputs":
for i in connected_inputs:
var input = int(i) % int(parameters.outputs)
var choice = int(i) / int(parameters.outputs)
if input >= v:
inputs_changes[i] = -1
else:
inputs_changes[i] = input + v * choice
for i in connected_outputs:
if i >= v:
outputs_changes[i] = -1
else:
for i in connected_inputs:
var input = int(i) % int(parameters.outputs)
var choice = int(i) / int(parameters.outputs)
if choice >= v:
inputs_changes[i] = -1
parent.reconnect_inputs(self, inputs_changes)
parent.reconnect_outputs(self, outputs_changes)
.set_parameter(p, v) .set_parameter(p, v)
emit_signal("parameter_changed", "__update_all__", null) emit_signal("parameter_changed", "__update_all__", null)

View File

@ -26,9 +26,9 @@ func update_node() -> void:
remove.free() remove.free()
var lines_list = [] var lines_list = []
if generator.editable: if generator.editable:
lines_list.push_back( { name="outputs", min=1, max=5 } ) lines_list.push_back( { name="outputs", tooltip="Outputs count", min=1, max=5 } )
lines_list.push_back( { name="choices", min=2, max=5 } ) lines_list.push_back( { name="choices", tooltip="Choices count", min=2, max=5 } )
lines_list.push_back( { name="source", min=0, max=generator.parameters.choices-1 } ) lines_list.push_back( { name="source", tooltip="Current choice", min=0, max=generator.parameters.choices-1 } )
for l in lines_list: for l in lines_list:
var sizer = HBoxContainer.new() var sizer = HBoxContainer.new()
var input_label = Label.new() var input_label = Label.new()
@ -40,6 +40,8 @@ func update_node() -> void:
control.max_value = l.max control.max_value = l.max
control.step = 1 control.step = 1
control.rect_min_size.x = 75 control.rect_min_size.x = 75
if l.has("tooltip"):
control.hint_tooltip = l.tooltip
sizer.add_child(control) sizer.add_child(control)
control.connect("value_changed", self, "_on_value_changed", [ l.name ]) control.connect("value_changed", self, "_on_value_changed", [ l.name ])
controls[l.name] = control controls[l.name] = control