From b55487d6df0ea80126ba6f6ebe9278e0b0a03812 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 4 Oct 2021 18:29:11 +0200 Subject: [PATCH] Added a vector2 slot to MMGraphNode. --- .../mat_maker_gd/editor/mm_graph_node.gd | 47 +++++++++++++++---- .../addons/mat_maker_gd/nodes/noise/perlin.gd | 19 ++------ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/game/addons/mat_maker_gd/editor/mm_graph_node.gd b/game/addons/mat_maker_gd/editor/mm_graph_node.gd index a433c04e..8764a7e9 100644 --- a/game/addons/mat_maker_gd/editor/mm_graph_node.gd +++ b/game/addons/mat_maker_gd/editor/mm_graph_node.gd @@ -29,10 +29,9 @@ func add_slot_label(input_type : int, output_type : int, getter : String, setter 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 l : Label = Label.new() + l.text = slot_name + bc.add_child(l) var sb : SpinBox = SpinBox.new() sb.rounded = true @@ -47,10 +46,9 @@ func add_slot_int(input_type : int, output_type : int, getter : String, setter : func add_slot_float(input_type : int, output_type : int, getter : String, setter : String, slot_name : String, step : float = 0.1) -> void: var bc : VBoxContainer = VBoxContainer.new() - if slot_name != "": - var l : Label = Label.new() - l.text = slot_name - bc.add_child(l) + var l : Label = Label.new() + l.text = slot_name + bc.add_child(l) var sb : SpinBox = SpinBox.new() bc.add_child(sb) @@ -61,6 +59,33 @@ func add_slot_float(input_type : int, output_type : int, getter : String, setter sb.value = _node.call(getter) sb.connect("value_changed", self, "on_float_spinbox_value_changed", [ slot_idx ]) + +func add_slot_vector2(input_type : int, output_type : int, getter : String, setter : String, slot_name : String, step : float = 0.1) -> void: + var bc : VBoxContainer = VBoxContainer.new() + + var l : Label = Label.new() + l.text = slot_name + bc.add_child(l) + + var sbx : SpinBox = SpinBox.new() + bc.add_child(sbx) + + var sby : SpinBox = SpinBox.new() + bc.add_child(sby) + + var slot_idx : int = add_slot(input_type, output_type, getter, setter, bc) + sbx.rounded = false + sby.rounded = false + sbx.step = step + sby.step = step + + var val : Vector2 = _node.call(getter) + + sbx.value = val.x + sby.value = val.y + + sbx.connect("value_changed", self, "on_vector2_spinbox_value_changed", [ slot_idx, sbx, sby ]) + sby.connect("value_changed", self, "on_vector2_spinbox_value_changed", [ slot_idx, sbx, sby ]) func add_slot(input_type : int, output_type : int, getter : String, setter : String, control : Control) -> int: add_child(control) @@ -130,3 +155,9 @@ func on_int_spinbox_value_changed(val : float, slot_idx) -> void: func on_float_spinbox_value_changed(val : float, slot_idx) -> void: _node.call(properties[slot_idx][4], val) + +func on_vector2_spinbox_value_changed(val : float, slot_idx, spinbox_x, spinbox_y) -> void: + var vv : Vector2 = Vector2(spinbox_x.value, spinbox_y.value) + + _node.call(properties[slot_idx][4], vv) + diff --git a/game/addons/mat_maker_gd/nodes/noise/perlin.gd b/game/addons/mat_maker_gd/nodes/noise/perlin.gd index 54abd7cd..6340a56b 100644 --- a/game/addons/mat_maker_gd/nodes/noise/perlin.gd +++ b/game/addons/mat_maker_gd/nodes/noise/perlin.gd @@ -17,8 +17,7 @@ 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", "") + mm_graph_node.add_slot_vector2(SlotTypes.SLOT_TYPE_NONE, SlotTypes.SLOT_TYPE_NONE, "get_scale", "set_scale", "scale") func get_iterations() -> int: return iterations @@ -36,18 +35,10 @@ func set_persistence(val : float) -> void: emit_changed() -func get_scale_x() -> float: - return scale.x +func get_scale() -> Vector2: + return scale -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 +func set_scale(val : Vector2) -> void: + scale = val emit_changed()