diff --git a/game/addons/mat_maker_gd/editor/MatMakerGDEditor.gd b/game/addons/mat_maker_gd/editor/MatMakerGDEditor.gd index 5f033327..b61f6585 100644 --- a/game/addons/mat_maker_gd/editor/MatMakerGDEditor.gd +++ b/game/addons/mat_maker_gd/editor/MatMakerGDEditor.gd @@ -18,6 +18,30 @@ func _enter_tree(): func ensure_objs() -> void: if !_graph_edit: _graph_edit = get_node(graph_edit_path) + + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_INT, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR3, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL) + + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_INT) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR3) + + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL) + + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_INT, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_INT) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_FLOAT) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR2) + _graph_edit.add_valid_connection_type(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR3, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_VECTOR3) + + _graph_edit.connect("connection_request", self, "on_graph_edit_connection_request") + _graph_edit.connect("disconnection_request", self, "on_graph_edit_disconnection_request") + func recreate() -> void: ensure_objs() @@ -44,6 +68,20 @@ func set_mmmaterial(object : MMMateial): _material = object recreate() + +func on_graph_edit_connection_request(from: String, from_slot: int, to: String, to_slot: int): + var from_node : GraphNode = _graph_edit.get_node(from) + var to_node : GraphNode = _graph_edit.get_node(to) + + if from_node.connect_slot(from_slot, to_node, to_slot): + _graph_edit.connect_node(from, from_slot, to, to_slot) + +func on_graph_edit_disconnection_request(from: String, from_slot: int, to: String, to_slot: int): + var from_node : GraphNode = _graph_edit.get_node(from) + var to_node : GraphNode = _graph_edit.get_node(to) + + if from_node.disconnect_slot(from_slot, to_node, to_slot): + _graph_edit.disconnect_node(from, from_slot, to, to_slot) func _on_AddButton_pressed(): get_node(add_popup_path).popup_centered() diff --git a/game/addons/mat_maker_gd/editor/MatMakerGDEditor.tscn b/game/addons/mat_maker_gd/editor/MatMakerGDEditor.tscn index bb576bbc..720d385a 100644 --- a/game/addons/mat_maker_gd/editor/MatMakerGDEditor.tscn +++ b/game/addons/mat_maker_gd/editor/MatMakerGDEditor.tscn @@ -40,6 +40,7 @@ margin_right = 1024.0 margin_bottom = 600.0 size_flags_horizontal = 3 size_flags_vertical = 3 +right_disconnects = true scroll_offset = Vector2( 0, -20 ) [node name="Popups" type="Control" parent="."] 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 3220cf77..500080a0 100644 --- a/game/addons/mat_maker_gd/editor/mm_graph_node.gd +++ b/game/addons/mat_maker_gd/editor/mm_graph_node.gd @@ -277,6 +277,54 @@ func add_slot(input_type : int, output_type : int, getter : String, setter : Str return slot_idx +func connect_slot(slot_idx : int, to_node : Node, to_slot_idx : int) -> bool: + var from_property_index : int = -1 + var to_property_index : int = -1 + + for i in range(properties.size()): + if properties[i][2] != -1: + from_property_index += 1 + + if from_property_index == slot_idx: + from_property_index = i + break + + for i in range(to_node.properties.size()): + if to_node.properties[i][1] != -1: + to_property_index += 1 + + if to_property_index == to_slot_idx: + to_property_index = i + break + + to_node.properties[to_property_index][6].set_input_property(properties[from_property_index][6]) + + return true + +func disconnect_slot(slot_idx : int, to_node : Node, to_slot_idx : int) -> bool: + var from_property_index : int = -1 + var to_property_index : int = -1 + + for i in range(properties.size()): + if properties[i][2] != -1: + from_property_index += 1 + + if from_property_index == slot_idx: + from_property_index = i + break + + for i in range(to_node.properties.size()): + if to_node.properties[i][1] != -1: + to_property_index += 1 + + if to_property_index == to_slot_idx: + to_property_index = i + break + + to_node.properties[to_property_index][6].set_input_property(null) + + return true + func get_property_control(slot_idx : int) -> Node: return properties[slot_idx][5] diff --git a/game/addons/mat_maker_gd/new_resource.tres b/game/addons/mat_maker_gd/new_resource.tres index 98d43e5b..e85452a2 100644 --- a/game/addons/mat_maker_gd/new_resource.tres +++ b/game/addons/mat_maker_gd/new_resource.tres @@ -1,10 +1,11 @@ -[gd_resource type="Resource" load_steps=11 format=2] +[gd_resource type="Resource" load_steps=15 format=2] [ext_resource path="res://addons/mat_maker_gd/nodes/mm_material.gd" type="Script" id=1] [ext_resource path="res://addons/mat_maker_gd/nodes/noise/perlin.gd" type="Script" id=2] [ext_resource path="res://addons/mat_maker_gd/nodes/noise/noise.gd" type="Script" id=3] [ext_resource path="res://addons/mat_maker_gd/nodes/simple/shape.gd" type="Script" id=4] [ext_resource path="res://addons/mat_maker_gd/nodes/mm_node_universal_property.gd" type="Script" id=5] +[ext_resource path="res://addons/mat_maker_gd/nodes/other/output_image.gd" type="Script" id=6] [sub_resource type="Resource" id=1] script = ExtResource( 2 ) @@ -29,24 +30,50 @@ default_vector2 = Vector2( 0, 0 ) default_vector3 = Vector3( 0, 0, 0 ) default_color = Color( 0, 0, 0, 1 ) +[sub_resource type="Resource" id=7] +script = ExtResource( 5 ) +default_type = 5 +default_int = 0 +default_float = 0.0 +default_vector2 = Vector2( 0, 0 ) +default_vector3 = Vector3( 0, 0, 0 ) +default_color = Color( 0, 0, 0, 1 ) + [sub_resource type="Resource" id=4] script = ExtResource( 5 ) default_type = 1 default_int = 0 -default_float = 1.05 +default_float = 0.55 default_vector2 = Vector2( 0, 0 ) default_vector3 = Vector3( 0, 0, 0 ) default_color = Color( 0, 0, 0, 1 ) [sub_resource type="Resource" id=5] script = ExtResource( 4 ) -graph_position = Vector2( -340, -360 ) -shape_type = 1 -sides = 4 +graph_position = Vector2( -360, -340 ) +image = SubResource( 7 ) +shape_type = 2 +sides = 6 radius = SubResource( 4 ) edge = SubResource( 3 ) +[sub_resource type="Resource" id=8] +script = ExtResource( 5 ) +default_type = 5 +default_int = 0 +default_float = 0.0 +default_vector2 = Vector2( 0, 0 ) +default_vector3 = Vector3( 0, 0, 0 ) +default_color = Color( 0, 0, 0, 1 ) +input_property = SubResource( 7 ) + +[sub_resource type="Resource" id=6] +script = ExtResource( 6 ) +graph_position = Vector2( -20, -340 ) +image = SubResource( 8 ) +postfix = "-test" + [resource] script = ExtResource( 1 ) image_size = Vector2( 128, 128 ) -nodes = [ SubResource( 1 ), SubResource( 2 ), SubResource( 5 ) ] +nodes = [ SubResource( 1 ), SubResource( 2 ), SubResource( 5 ), SubResource( 6 ) ] diff --git a/game/addons/mat_maker_gd/nodes/mm_node.gd b/game/addons/mat_maker_gd/nodes/mm_node.gd index 43dc0918..a2968254 100644 --- a/game/addons/mat_maker_gd/nodes/mm_node.gd +++ b/game/addons/mat_maker_gd/nodes/mm_node.gd @@ -118,3 +118,4 @@ func set_dirty(val : bool) -> void: func on_input_property_changed() -> void: set_dirty(true) + emit_changed() 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 index eb2787a1..ae82c2fb 100644 --- a/game/addons/mat_maker_gd/nodes/mm_node_universal_property.gd +++ b/game/addons/mat_maker_gd/nodes/mm_node_universal_property.gd @@ -47,7 +47,7 @@ var owner func _init(): if input_property: - input_property.connect("changed", self, "on_input_property_cahnged") + input_property.connect("changed", self, "on_input_property_changed") func get_value(uv : Vector2): if !input_property: @@ -110,6 +110,9 @@ func set_default_value(val): emit_changed() func get_active_image() -> Image: + if input_property: + return input_property.get_active_image() + if override_image: return override_image @@ -120,11 +123,14 @@ func set_input_property(val : MMNodeUniversalProperty) -> void: return if input_property: - input_property.disconnect("changed", self, "on_input_property_cahnged") + input_property.disconnect("changed", self, "on_input_property_changed") input_property = val - input_property.connect("changed", self, "on_input_property_cahnged") - -func on_input_property_cahnged() -> void: + if input_property: + input_property.connect("changed", self, "on_input_property_changed") + + emit_changed() + +func on_input_property_changed() -> void: emit_changed() diff --git a/game/addons/mat_maker_gd/nodes/other/output_image.gd b/game/addons/mat_maker_gd/nodes/other/output_image.gd index 41a01c84..7bba0ad7 100644 --- a/game/addons/mat_maker_gd/nodes/other/output_image.gd +++ b/game/addons/mat_maker_gd/nodes/other/output_image.gd @@ -1,9 +1,9 @@ tool extends MMNode -var image : Resource +export(Resource) var image : Resource -var postfix : String = "" +export(String) var postfix : String = "" func _init_properties(): image = MMNodeUniversalProperty.new() @@ -18,6 +18,9 @@ func _register_methods(mm_graph_node) -> void: mm_graph_node.add_slot_line_edit(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_postfix", "set_postfix", "postfix") func _render(material) -> void: + if !image: + return + var img : Image = image.get_active_image() if !img: diff --git a/game/addons/mat_maker_gd/nodes/simple/shape.gd b/game/addons/mat_maker_gd/nodes/simple/shape.gd index 127477d6..d827bc3f 100644 --- a/game/addons/mat_maker_gd/nodes/simple/shape.gd +++ b/game/addons/mat_maker_gd/nodes/simple/shape.gd @@ -11,7 +11,7 @@ enum ShapeType { SHAPE_TYPE_RAYS = 4, } -var image : Resource +export(Resource) var image : Resource export(int, "Circle,Polygon,Star,Curved Star,Rays") var shape_type : int = 0 export(int) var sides : int = 6 export(Resource) var radius : Resource @@ -21,7 +21,8 @@ func _init_properties(): if !image: image = MMNodeUniversalProperty.new() image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE - image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE + + image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE if !radius: radius = MMNodeUniversalProperty.new()