diff --git a/addons/material_maker/engine/gen_switch.gd b/addons/material_maker/engine/gen_switch.gd index 8b91ddd..5a48ab5 100644 --- a/addons/material_maker/engine/gen_switch.gd +++ b/addons/material_maker/engine/gen_switch.gd @@ -45,6 +45,32 @@ func get_output_defs() -> Array: return rv 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) emit_signal("parameter_changed", "__update_all__", null) diff --git a/addons/material_maker/nodes/switch.gd b/addons/material_maker/nodes/switch.gd index 4009b8f..47c477d 100644 --- a/addons/material_maker/nodes/switch.gd +++ b/addons/material_maker/nodes/switch.gd @@ -26,9 +26,9 @@ func update_node() -> void: remove.free() var lines_list = [] if generator.editable: - lines_list.push_back( { name="outputs", min=1, max=5 } ) - lines_list.push_back( { name="choices", min=2, max=5 } ) - lines_list.push_back( { name="source", min=0, max=generator.parameters.choices-1 } ) + lines_list.push_back( { name="outputs", tooltip="Outputs count", min=1, max=5 } ) + lines_list.push_back( { name="choices", tooltip="Choices count", min=2, max=5 } ) + lines_list.push_back( { name="source", tooltip="Current choice", min=0, max=generator.parameters.choices-1 } ) for l in lines_list: var sizer = HBoxContainer.new() var input_label = Label.new() @@ -40,6 +40,8 @@ func update_node() -> void: control.max_value = l.max control.step = 1 control.rect_min_size.x = 75 + if l.has("tooltip"): + control.hint_tooltip = l.tooltip sizer.add_child(control) control.connect("value_changed", self, "_on_value_changed", [ l.name ]) controls[l.name] = control