Implemented int and float slots.

This commit is contained in:
Relintai 2021-10-04 14:58:15 +02:00
parent 634d28b713
commit ef784088b4
3 changed files with 78 additions and 1 deletions

View File

@ -26,6 +26,42 @@ func add_slot_label(input_type : int, output_type : int, getter : String, setter
add_slot(input_type, output_type, getter, setter, l)
func add_slot_int(input_type : int, output_type : int, getter : String, setter : String, slot_name : String) -> void:
var bc : VBoxContainer = VBoxContainer.new()
if slot_name != "":
var l : Label = Label.new()
l.text = slot_name
bc.add_child(l)
var sb : SpinBox = SpinBox.new()
sb.rounded = true
bc.add_child(sb)
var slot_idx : int = add_slot(input_type, output_type, getter, setter, bc)
sb.value = _node.call(getter)
sb.connect("value_changed", self, "on_int_spinbox_value_changed", [ slot_idx ])
func add_slot_float(input_type : int, output_type : int, getter : String, setter : String, slot_name : String) -> void:
var bc : VBoxContainer = VBoxContainer.new()
if slot_name != "":
var l : Label = Label.new()
l.text = slot_name
bc.add_child(l)
var sb : SpinBox = SpinBox.new()
bc.add_child(sb)
var slot_idx : int = add_slot(input_type, output_type, getter, setter, bc)
sb.rounded = false
sb.step = 0
sb.value = _node.call(getter)
sb.connect("value_changed", self, "on_float_spinbox_value_changed", [ slot_idx ])
func add_slot(input_type : int, output_type : int, getter : String, setter : String, control : Control) -> int:
add_child(control)
var slot_idx : int = get_child_count() - 1
@ -88,3 +124,9 @@ func on_node_changed():
#_node.recalculate_image(_material)
propagate_node_change()
func on_int_spinbox_value_changed(val : float, slot_idx) -> void:
_node.call(properties[slot_idx][4], int(val))
func on_float_spinbox_value_changed(val : float, slot_idx) -> void:
_node.call(properties[slot_idx][4], val)

View File

@ -50,7 +50,7 @@ func gen() -> void:
image.unlock()
tex.create_from_image(image)
texture = tex
#texture = tex
var p_o7136_amplitude = 0.500000000;
var p_o7136_frequency = 2.000000000;

View File

@ -15,4 +15,39 @@ func get_value_for(uv : Vector2, slot_idx : int, pseed : int) -> Color:
func register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_texture(SlotTypes.SLOT_TYPE_NONE, SlotTypes.SLOT_TYPE_IMAGE, "recalculate_image", "")
mm_graph_node.add_slot_int(SlotTypes.SLOT_TYPE_NONE, SlotTypes.SLOT_TYPE_NONE, "get_iterations", "set_iterations", "iterations")
mm_graph_node.add_slot_float(SlotTypes.SLOT_TYPE_NONE, SlotTypes.SLOT_TYPE_NONE, "get_persistence", "set_persistence", "persistence")
mm_graph_node.add_slot_float(SlotTypes.SLOT_TYPE_NONE, SlotTypes.SLOT_TYPE_NONE, "get_scale_x", "set_scale_x", "scale")
mm_graph_node.add_slot_float(SlotTypes.SLOT_TYPE_NONE, SlotTypes.SLOT_TYPE_NONE, "get_scale_y", "set_scale_y", "")
func get_iterations() -> int:
return iterations
func set_iterations(val : int) -> void:
iterations = val
emit_changed()
func get_persistence() -> float:
return persistence
func set_persistence(val : float) -> void:
persistence = val
emit_changed()
func get_scale_x() -> float:
return scale.x
func set_scale_x(val : float) -> void:
scale.x = val
emit_changed()
func get_scale_y() -> float:
return scale.y
func set_scale_y(val : float) -> void:
scale.y = val
emit_changed()