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 bed98701..a4d3d5fd 100644 --- a/game/addons/mat_maker_gd/editor/mm_graph_node.gd +++ b/game/addons/mat_maker_gd/editor/mm_graph_node.gd @@ -49,6 +49,29 @@ func add_slot_int(input_type : int, output_type : int, getter : String, setter : return slot_idx +func add_slot_int_universal(input_property : MMNodeUniversalProperty, output_type : int, slot_name : String, prange : Vector2 = Vector2(-1000, 1000)) -> int: + var bc : VBoxContainer = VBoxContainer.new() + + var l : Label = Label.new() + l.text = slot_name + bc.add_child(l) + + var sb : SpinBox = SpinBox.new() + sb.rounded = true + sb.min_value = prange.x + sb.max_value = prange.y + bc.add_child(sb) + + var slot_idx : int = add_slot(MMNode.SlotTypes.SLOT_TYPE_UNIVERSAL, output_type, "", "", bc) + + sb.value = _node.call(input_property.get_default_value()) + + sb.connect("value_changed", self, "on_int_universal_spinbox_value_changed", [ slot_idx ]) + + properties[slot_idx].append(input_property) + + return slot_idx + func add_slot_float(input_type : int, output_type : int, getter : String, setter : String, slot_name : String, step : float = 0.1, prange : Vector2 = Vector2(-1000, 1000)) -> int: var bc : VBoxContainer = VBoxContainer.new() @@ -69,7 +92,30 @@ func add_slot_float(input_type : int, output_type : int, getter : String, setter sb.connect("value_changed", self, "on_float_spinbox_value_changed", [ slot_idx ]) return slot_idx + +func add_slot_float_universal(input_property : MMNodeUniversalProperty, output_type : int, slot_name : String, step : float = 0.1, prange : Vector2 = Vector2(-1000, 1000)) -> int: + var bc : VBoxContainer = VBoxContainer.new() + 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(MMNode.SlotTypes.SLOT_TYPE_UNIVERSAL, output_type, "", "", bc) + sb.rounded = false + sb.step = step + sb.min_value = prange.x + sb.max_value = prange.y + sb.value = _node.call(input_property.get_default_value()) + + properties[slot_idx].append(input_property) + + sb.connect("value_changed", self, "on_float_universal_spinbox_value_changed", [ slot_idx ]) + + return slot_idx + func add_slot_vector2(input_type : int, output_type : int, getter : String, setter : String, slot_name : String, step : float = 0.1, prange : Vector2 = Vector2(-1000, 1000)) -> int: var bc : VBoxContainer = VBoxContainer.new() @@ -103,6 +149,41 @@ func add_slot_vector2(input_type : int, output_type : int, getter : String, sett return slot_idx +func add_slot_vector2_universal(input_property : MMNodeUniversalProperty, output_type : int, slot_name : String, step : float = 0.1, prange : Vector2 = Vector2(-1000, 1000)) -> int: + 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(MMNode.SlotTypes.SLOT_TYPE_UNIVERSAL, output_type, "", "", bc) + sbx.rounded = false + sby.rounded = false + sbx.step = step + sby.step = step + sbx.min_value = prange.x + sbx.max_value = prange.y + sby.min_value = prange.x + sby.max_value = prange.y + + var val : Vector2 = _node.call(input_property.get_default_value()) + + sbx.value = val.x + sby.value = val.y + + properties[slot_idx].append(input_property) + + sbx.connect("value_changed", self, "on_vector2_universal_spinbox_value_changed", [ slot_idx, sbx, sby ]) + sby.connect("value_changed", self, "on_vector2_universal_spinbox_value_changed", [ slot_idx, sbx, sby ]) + + return 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 @@ -180,3 +261,14 @@ func on_vector2_spinbox_value_changed(val : float, slot_idx, spinbox_x, spinbox_ _node.call(properties[slot_idx][4], vv) +func on_int_universal_spinbox_value_changed(val : float, slot_idx) -> void: + properties[slot_idx][7].set_default_value(int(val)) + +func on_float_universal_spinbox_value_changed(val : float, slot_idx) -> void: + properties[slot_idx][7].set_default_value(val) + +func on_vector2_universal_spinbox_value_changed(val : float, slot_idx, spinbox_x, spinbox_y) -> void: + var vv : Vector2 = Vector2(spinbox_x.value, spinbox_y.value) + + properties[slot_idx][7].set_default_value(vv) + diff --git a/game/addons/mat_maker_gd/nodes/mm_node_universal_property.gd b/game/addons/mat_maker_gd/nodes/mm_node_universal_property.gd new file mode 100644 index 00000000..0665a6c0 --- /dev/null +++ b/game/addons/mat_maker_gd/nodes/mm_node_universal_property.gd @@ -0,0 +1,67 @@ +tool +class_name MMNodeUniversalProperty +extends Resource + +enum MMNodeUniversalPropertyDefaultType { + DEFAULT_TYPE_INT = 0, + DEFAULT_TYPE_FLOAT = 1, + DEFAULT_TYPE_VECTOR2 = 2, + DEFAULT_TYPE_VECTOR3 = 3, + DEFAULT_TYPE_COLOR = 4, +} + +export(int, "Int,Float,Vector2,Vector3,Color") var default_type : int + +export(int) var default_int : int +export(float) var default_float : float +export(Vector2) var default_vector2 : Vector2 +export(Vector3) var default_vector3 : Vector3 +export(Color) var default_color : Color + +export(Resource) var obj : Resource +export(String) var getter : String +export(Array) var params : Array + +func get_value(): + if !obj: + if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT: + return default_int + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT: + return default_float + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2: + return default_vector2 + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3: + return default_vector3 + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR: + return default_color + + return null + + if params.size() == 0: + return obj.call(getter) + else: + return obj.call(getter, params) + +func get_default_value(): + if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT: + return default_int + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT: + return default_float + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2: + return default_vector2 + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3: + return default_vector3 + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR: + return default_color + +func set_default_value(val): + if default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_INT: + default_int = val + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT: + default_float = val + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR2: + default_vector2 = val + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_VECTOR3: + default_vector3 = val + elif default_type == MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_COLOR: + default_color = val diff --git a/game/addons/mat_maker_gd/plugin.gd b/game/addons/mat_maker_gd/plugin.gd index 1fa5cf26..c3b47e16 100644 --- a/game/addons/mat_maker_gd/plugin.gd +++ b/game/addons/mat_maker_gd/plugin.gd @@ -3,6 +3,7 @@ extends EditorPlugin var MMNode = preload("res://addons/mat_maker_gd/nodes/mm_node.gd") var MMMaterial = preload("res://addons/mat_maker_gd/nodes/mm_material.gd") +var MMNodeUniversalProperty = preload("res://addons/mat_maker_gd/nodes/mm_node_universal_property.gd") var editor_packed_scene = preload("res://addons/mat_maker_gd/editor/MatMakerGDEditor.tscn") var editor_scene = null @@ -12,6 +13,7 @@ var tool_button : ToolButton = null func _enter_tree(): add_custom_type("MMNode", "Resource", MMNode, null) add_custom_type("MMMaterial", "Resource", MMMaterial, null) + add_custom_type("MMNodeUniversalProperty", "Resource", MMNodeUniversalProperty, null) editor_scene = editor_packed_scene.instance() @@ -21,6 +23,7 @@ func _enter_tree(): func _exit_tree(): remove_custom_type("MMNode") remove_custom_type("MMMaterial") + remove_custom_type("MMNodeUniversalProperty") remove_control_from_bottom_panel(editor_scene) diff --git a/game/project.godot b/game/project.godot index 051719a7..090a9584 100644 --- a/game/project.godot +++ b/game/project.godot @@ -154,6 +154,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/mat_maker_gd/nodes/mm_node.gd" }, { +"base": "Resource", +"class": "MMNodeUniversalProperty", +"language": "GDScript", +"path": "res://addons/mat_maker_gd/nodes/mm_node_universal_property.gd" +}, { "base": "Node", "class": "Main", "language": "GDScript", @@ -259,6 +264,7 @@ _global_script_class_icons={ "LayeredTextureMaker": "", "MMMateial": "", "MMNode": "", +"MMNodeUniversalProperty": "", "Main": "", "MainTPlanetGenerator": "", "ManaResource": "",