diff --git a/addons/block_code/blocks/math/vector3_multiply.tres b/addons/block_code/blocks/math/vector3_multiply.tres new file mode 100644 index 00000000..7ec43ac8 --- /dev/null +++ b/addons/block_code/blocks/math/vector3_multiply.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bff7cwmpisihj"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_52jwf"] + +[resource] +script = ExtResource("1_52jwf") +name = &"vector3_multiply" +target_node_class = "" +description = "Multiplies a Vector3 with a number. Use this, for example, to get a point some distance away along an angle." +category = "Math" +type = 3 +variant_type = 9 +display_template = "multiply {vector: VECTOR3} by {number: FLOAT}" +code_template = "{vector} * {number}" +defaults = { +"number": 1.0, +"vector": Vector3(1, 1, 1) +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/vector3_x.tres b/addons/block_code/blocks/math/vector3_x.tres new file mode 100644 index 00000000..3a4f4c76 --- /dev/null +++ b/addons/block_code/blocks/math/vector3_x.tres @@ -0,0 +1,19 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cehtd3jqu5es2"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_p3bft"] + +[resource] +script = ExtResource("1_p3bft") +name = &"vector3_x" +target_node_class = "" +description = "Gives the x of a [i]Vector3[/i]" +category = "Math" +type = 3 +variant_type = 3 +display_template = "x of {vector3: VECTOR3}" +code_template = "{vector3}.x" +defaults = { +"vector3": Vector3(0, 0, 0) +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/vector3_y.tres b/addons/block_code/blocks/math/vector3_y.tres new file mode 100644 index 00000000..31702319 --- /dev/null +++ b/addons/block_code/blocks/math/vector3_y.tres @@ -0,0 +1,19 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cehtd3jqu5es2"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_p3bft"] + +[resource] +script = ExtResource("1_p3bft") +name = &"vector3_y" +target_node_class = "" +description = "Gives the y of a [i]Vector3[/i]" +category = "Math" +type = 3 +variant_type = 3 +display_template = "y of {vector3: VECTOR3}" +code_template = "{vector3}.y" +defaults = { +"vector3": Vector3(0, 0, 0) +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/vector3_z.tres b/addons/block_code/blocks/math/vector3_z.tres new file mode 100644 index 00000000..b1b29b84 --- /dev/null +++ b/addons/block_code/blocks/math/vector3_z.tres @@ -0,0 +1,19 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cehtd3jqu5es2"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_p3bft"] + +[resource] +script = ExtResource("1_p3bft") +name = &"vector3_z" +target_node_class = "" +description = "Gives the z of a [i]Vector3[/i]" +category = "Math" +type = 3 +variant_type = 3 +display_template = "z of {vector3: VECTOR3}" +code_template = "{vector3}.z" +defaults = { +"vector3": Vector3(0, 0, 0) +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/variables/vector3.tres b/addons/block_code/blocks/variables/vector3.tres new file mode 100644 index 00000000..ac239691 --- /dev/null +++ b/addons/block_code/blocks/variables/vector3.tres @@ -0,0 +1,21 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ddj24k1fp0s82"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_ilw3v"] + +[resource] +script = ExtResource("1_ilw3v") +name = &"vector3" +target_node_class = "" +description = "" +category = "Math" +type = 3 +variant_type = 9 +display_template = "vector3 x: {x: FLOAT} y: {y: FLOAT}: z: {z: FLOAT}" +code_template = "Vector3({x}, {y}, {z})" +defaults = { +"x": 0.0, +"y": 0.0, +"z": 0.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/code_generation/block_ast.gd b/addons/block_code/code_generation/block_ast.gd index a90657e2..865e3047 100644 --- a/addons/block_code/code_generation/block_ast.gd +++ b/addons/block_code/code_generation/block_ast.gd @@ -131,6 +131,8 @@ static func raw_input_to_code_string(input) -> String: return "'%s'" % input.c_escape() TYPE_VECTOR2: return "Vector2%s" % str(input) + TYPE_VECTOR3: + return "Vector3%s" % str(input) TYPE_COLOR: return "Color%s" % str(input) _: diff --git a/addons/block_code/code_generation/blocks_catalog.gd b/addons/block_code/code_generation/blocks_catalog.gd index 04aebdb2..2009112f 100644 --- a/addons/block_code/code_generation/blocks_catalog.gd +++ b/addons/block_code/code_generation/blocks_catalog.gd @@ -12,6 +12,7 @@ const _FALLBACK_SET_FOR_TYPE = { TYPE_INT: 0, TYPE_FLOAT: 0.0, TYPE_VECTOR2: Vector2(0, 0), + TYPE_VECTOR3: Vector3(0, 0, 0), TYPE_COLOR: Color.DARK_ORANGE, } @@ -20,6 +21,7 @@ const _FALLBACK_CHANGE_FOR_TYPE = { TYPE_INT: 1, TYPE_FLOAT: 1.0, TYPE_VECTOR2: Vector2(1, 1), + TYPE_VECTOR3: Vector3(1, 1, 1), TYPE_COLOR: Color.DARK_ORANGE, } @@ -45,6 +47,27 @@ const _SETTINGS_FOR_CLASS_PROPERTY = { "default_change": Vector2(0.1, 0.1), }, }, + "Node3D": + { + "position": + { + "category": "Transform | Position", + "default_set": Vector3(0, 0, 0), + "default_change": Vector3(0.1, 0.1, 0.1), + }, + "rotation": + { + "category": "Transform | Rotation", + "default_set": Vector3(0, 0, 0), + "default_change": Vector3(0.1, 0.1, 0.1), + }, + "scale": + { + "category": "Transform | Scale", + "default_set": Vector3(1, 1, 1), + "default_change": Vector3(0.1, 0.1, 0.1), + } + }, "CanvasItem": { "modulate": @@ -280,13 +303,13 @@ static func get_variable_getter_block_definition(variable: VariableDefinition) - static func get_variable_setter_block_definition(variable: VariableDefinition) -> BlockDefinition: - var type_string: String = Types.VARIANT_TYPE_TO_STRING[variable.var_type] + var _type_string: String = Types.VARIANT_TYPE_TO_STRING[variable.var_type] var block_def := BlockDefinition.new() block_def.name = "set_var_%s" % variable.var_name block_def.category = "Variables" block_def.type = Types.BlockType.STATEMENT - block_def.display_template = "Set %s to {value: %s}" % [variable.var_name, type_string] + block_def.display_template = "Set %s to {value: %s}" % [variable.var_name, _type_string] block_def.code_template = "%s = {value}" % variable.var_name return block_def diff --git a/addons/block_code/types/types.gd b/addons/block_code/types/types.gd index 4a7de445..e1768560 100644 --- a/addons/block_code/types/types.gd +++ b/addons/block_code/types/types.gd @@ -14,6 +14,7 @@ const VARIANT_TYPE_TO_STRING: Dictionary = { TYPE_FLOAT: "FLOAT", TYPE_BOOL: "BOOL", TYPE_VECTOR2: "VECTOR2", + TYPE_VECTOR3: "VECTOR3", TYPE_COLOR: "COLOR", TYPE_NODE_PATH: "NODE_PATH", TYPE_OBJECT: "OBJECT", @@ -27,6 +28,7 @@ const STRING_TO_VARIANT_TYPE: Dictionary = { "FLOAT": TYPE_FLOAT, "BOOL": TYPE_BOOL, "VECTOR2": TYPE_VECTOR2, + "VECTOR3": TYPE_VECTOR3, "COLOR": TYPE_COLOR, "NODE_PATH": TYPE_NODE_PATH, "OBJECT": TYPE_OBJECT, @@ -42,6 +44,8 @@ const cast_relationships = [ [TYPE_COLOR, TYPE_STRING, "str(%s)"], [TYPE_VECTOR2, TYPE_STRING, "str(%s)"], [TYPE_VECTOR2, TYPE_BOOL, "%s"], + [TYPE_VECTOR3, TYPE_STRING, "str(%s)"], + [TYPE_VECTOR3, TYPE_BOOL, "%s"], ] # Directed graph, edges are CastGraphEdge diff --git a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd index 4c9d9d41..46de1795 100644 --- a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd +++ b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd @@ -37,6 +37,11 @@ var _drag_start: Vector2 = Vector2.INF @onready var _vector2_input := %Vector2Input @onready var _x_line_edit := %XLineEdit @onready var _y_line_edit := %YLineEdit +# Vector3 +@onready var _vector3_input := %Vector3Input +@onready var _v3_x_line_edit := %V3XLineEdit +@onready var _v3_y_line_edit := %V3YLineEdit +@onready var _v3_z_line_edit := %V3ZLineEdit # Bool @onready var _bool_input := %BoolInput @onready var _bool_input_option := %BoolInputOption @@ -46,6 +51,9 @@ var _drag_start: Vector2 = Vector2.INF _line_edit: "", _x_line_edit: "", _y_line_edit: "", + _v3_x_line_edit: "", + _v3_y_line_edit: "", + _v3_z_line_edit: "", } @@ -73,6 +81,10 @@ func set_raw_input(raw_input: Variant): # Rounding because floats are doubles by default but Vector2s have single components _x_line_edit.text = ("%.4f" % raw_input.x).rstrip("0").rstrip(".") if raw_input != null else "" _y_line_edit.text = ("%.4f" % raw_input.y).rstrip("0").rstrip(".") if raw_input != null else "" + TYPE_VECTOR3: + _v3_x_line_edit.text = ("%.4f" % raw_input.x).rstrip("0").rstrip(".") if raw_input != null else "" + _v3_y_line_edit.text = ("%.4f" % raw_input.y).rstrip("0").rstrip(".") if raw_input != null else "" + _v3_z_line_edit.text = ("%.4f" % raw_input.z).rstrip("0").rstrip(".") if raw_input != null else "" TYPE_BOOL: _bool_input_option.select(1 if raw_input else 0) TYPE_NIL: @@ -83,6 +95,9 @@ func set_raw_input(raw_input: Variant): _last_submitted_text[_line_edit] = _line_edit.text _last_submitted_text[_x_line_edit] = _x_line_edit.text _last_submitted_text[_y_line_edit] = _y_line_edit.text + _last_submitted_text[_v3_x_line_edit] = _v3_x_line_edit.text + _last_submitted_text[_v3_y_line_edit] = _v3_y_line_edit.text + _last_submitted_text[_v3_z_line_edit] = _v3_z_line_edit.text ## Gets the value, which could be one of a variety of types depending on @@ -102,6 +117,8 @@ func get_raw_input() -> Variant: return _color_input.color TYPE_VECTOR2: return Vector2(float(_x_line_edit.text), float(_y_line_edit.text)) + TYPE_VECTOR3: + return Vector3(float(_v3_x_line_edit.text), float(_v3_y_line_edit.text), float(_v3_z_line_edit.text)) TYPE_BOOL: return bool(_bool_input_option.selected) TYPE_INT: @@ -203,6 +220,30 @@ func _on_y_line_edit_focus_exited(): _validate_and_submit_edit_text(_y_line_edit, TYPE_FLOAT) +func _on_v3_x_line_edit_text_submitted(_new_text): + _validate_and_submit_edit_text(_v3_x_line_edit, TYPE_FLOAT) + + +func _on_v3_x_line_edit_focus_exited(): + _validate_and_submit_edit_text(_v3_x_line_edit, TYPE_FLOAT) + + +func _on_v3_y_line_edit_text_submitted(_new_text): + _validate_and_submit_edit_text(_v3_y_line_edit, TYPE_FLOAT) + + +func _on_v3_y_line_edit_focus_exited(): + _validate_and_submit_edit_text(_v3_y_line_edit, TYPE_FLOAT) + + +func _on_v3_z_line_edit_text_submitted(_new_text): + _validate_and_submit_edit_text(_v3_z_line_edit, TYPE_FLOAT) + + +func _on_v3_z_line_edit_focus_exited(): + _validate_and_submit_edit_text(_v3_z_line_edit, TYPE_FLOAT) + + func _update_visible_input(): if snap_point.has_snapped_block(): _switch_input(null) @@ -214,6 +255,8 @@ func _update_visible_input(): _switch_input(_color_input) TYPE_VECTOR2: _switch_input(_vector2_input) + TYPE_VECTOR3: + _switch_input(_vector3_input) TYPE_BOOL: _switch_input(_bool_input) _: diff --git a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn index c4949f7b..7add975d 100644 --- a/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn +++ b/addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn @@ -39,6 +39,7 @@ script = ExtResource("1_rgmxn") unique_name_in_owner = true layout_mode = 2 script = ExtResource("2_68spp") +color = Color(1, 1, 1, 1) block_type = 3 [node name="InputSwitcher" type="MarginContainer" parent="."] @@ -220,7 +221,6 @@ action_mode = 1 selected = 0 item_count = 2 popup/item_0/text = "false" -popup/item_0/id = 0 popup/item_1/text = "true" popup/item_1/id = 1 @@ -228,6 +228,130 @@ popup/item_1/id = 1 layout_mode = 1 drag_outside = true +[node name="Vector3Input" type="MarginContainer" parent="InputSwitcher"] +unique_name_in_owner = true +visible = false +layout_mode = 2 +theme_override_constants/margin_left = 8 +theme_override_constants/margin_top = 4 +theme_override_constants/margin_right = 8 +theme_override_constants/margin_bottom = 4 + +[node name="HBoxContainer" type="HBoxContainer" parent="InputSwitcher/Vector3Input"] +layout_mode = 2 + +[node name="Control" type="Control" parent="InputSwitcher/Vector3Input/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="V3XLineEdit" type="LineEdit" parent="InputSwitcher/Vector3Input/HBoxContainer"] +unique_name_in_owner = true +auto_translate_mode = 2 +layout_mode = 2 +mouse_filter = 1 +theme_override_colors/font_placeholder_color = Color(0.76662, 0.76662, 0.76662, 1) +theme_override_colors/font_uneditable_color = Color(0.117647, 0.117647, 0.117647, 1) +theme_override_colors/font_color = Color(0.118581, 0.118581, 0.118581, 1) +theme_override_constants/minimum_character_width = 0 +theme_override_styles/focus = SubResource("StyleBoxEmpty_afyv2") +theme_override_styles/read_only = SubResource("StyleBoxEmpty_3r4mt") +theme_override_styles/normal = SubResource("StyleBoxEmpty_6oowp") +placeholder_text = "x" +alignment = 1 +expand_to_text_length = true + +[node name="DragDropArea" parent="InputSwitcher/Vector3Input/HBoxContainer/V3XLineEdit" instance=ExtResource("2_05gck")] +layout_mode = 1 +drag_outside = true + +[node name="Control3" type="Control" parent="InputSwitcher/Vector3Input/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="CenterContainer" type="MarginContainer" parent="InputSwitcher/Vector3Input/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="ColorRect" type="ColorRect" parent="InputSwitcher/Vector3Input/HBoxContainer/CenterContainer"] +custom_minimum_size = Vector2(2, 0) +layout_mode = 2 +size_flags_horizontal = 4 +color = Color(0.804743, 0.804743, 0.804743, 1) + +[node name="DragDropArea" parent="InputSwitcher/Vector3Input/HBoxContainer/CenterContainer/ColorRect" instance=ExtResource("2_05gck")] +layout_mode = 1 +drag_outside = true + +[node name="Control4" type="Control" parent="InputSwitcher/Vector3Input/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="V3YLineEdit" type="LineEdit" parent="InputSwitcher/Vector3Input/HBoxContainer"] +unique_name_in_owner = true +auto_translate_mode = 2 +layout_mode = 2 +mouse_filter = 1 +theme_override_colors/font_placeholder_color = Color(0.76662, 0.76662, 0.76662, 1) +theme_override_colors/font_uneditable_color = Color(0.117647, 0.117647, 0.117647, 1) +theme_override_colors/font_color = Color(0.118581, 0.118581, 0.118581, 1) +theme_override_constants/minimum_character_width = 0 +theme_override_styles/focus = SubResource("StyleBoxEmpty_afyv2") +theme_override_styles/read_only = SubResource("StyleBoxEmpty_3r4mt") +theme_override_styles/normal = SubResource("StyleBoxEmpty_6oowp") +placeholder_text = "y" +alignment = 1 +expand_to_text_length = true + +[node name="DragDropArea" parent="InputSwitcher/Vector3Input/HBoxContainer/V3YLineEdit" instance=ExtResource("2_05gck")] +layout_mode = 1 +drag_outside = true + +[node name="Control2" type="Control" parent="InputSwitcher/Vector3Input/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="CenterContainer2" type="MarginContainer" parent="InputSwitcher/Vector3Input/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="ColorRect" type="ColorRect" parent="InputSwitcher/Vector3Input/HBoxContainer/CenterContainer2"] +custom_minimum_size = Vector2(2, 0) +layout_mode = 2 +size_flags_horizontal = 4 +color = Color(0.804743, 0.804743, 0.804743, 1) + +[node name="DragDropArea" parent="InputSwitcher/Vector3Input/HBoxContainer/CenterContainer2/ColorRect" instance=ExtResource("2_05gck")] +layout_mode = 1 +drag_outside = true + +[node name="Control5" type="Control" parent="InputSwitcher/Vector3Input/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="V3ZLineEdit" type="LineEdit" parent="InputSwitcher/Vector3Input/HBoxContainer"] +unique_name_in_owner = true +auto_translate_mode = 2 +layout_mode = 2 +mouse_filter = 1 +theme_override_colors/font_placeholder_color = Color(0.76662, 0.76662, 0.76662, 1) +theme_override_colors/font_uneditable_color = Color(0.117647, 0.117647, 0.117647, 1) +theme_override_colors/font_color = Color(0.118581, 0.118581, 0.118581, 1) +theme_override_constants/minimum_character_width = 0 +theme_override_styles/focus = SubResource("StyleBoxEmpty_afyv2") +theme_override_styles/read_only = SubResource("StyleBoxEmpty_3r4mt") +theme_override_styles/normal = SubResource("StyleBoxEmpty_6oowp") +placeholder_text = "z" +alignment = 1 +expand_to_text_length = true + +[node name="DragDropArea" parent="InputSwitcher/Vector3Input/HBoxContainer/V3ZLineEdit" instance=ExtResource("2_05gck")] +layout_mode = 1 +drag_outside = true + +[node name="Control6" type="Control" parent="InputSwitcher/Vector3Input/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + [node name="SnapPoint" parent="." instance=ExtResource("2_6esp3")] unique_name_in_owner = true layout_mode = 2 @@ -250,4 +374,15 @@ variant_type = 4 [connection signal="drag_started" from="InputSwitcher/Vector2Input/HBoxContainer/YLineEdit/DragDropArea" to="." method="_on_drag_drop_area_drag_started"] [connection signal="item_selected" from="InputSwitcher/BoolInput/BoolInputOption" to="." method="_on_option_input_item_selected"] [connection signal="drag_started" from="InputSwitcher/BoolInput/BoolInputOption/DragDropArea" to="." method="_on_drag_drop_area_drag_started"] +[connection signal="focus_exited" from="InputSwitcher/Vector3Input/HBoxContainer/V3XLineEdit" to="." method="_on_v3_x_line_edit_focus_exited"] +[connection signal="text_submitted" from="InputSwitcher/Vector3Input/HBoxContainer/V3XLineEdit" to="." method="_on_v3_x_line_edit_text_submitted"] +[connection signal="drag_started" from="InputSwitcher/Vector3Input/HBoxContainer/V3XLineEdit/DragDropArea" to="." method="_on_drag_drop_area_drag_started"] +[connection signal="drag_started" from="InputSwitcher/Vector3Input/HBoxContainer/CenterContainer/ColorRect/DragDropArea" to="." method="_on_drag_drop_area_drag_started"] +[connection signal="focus_exited" from="InputSwitcher/Vector3Input/HBoxContainer/V3YLineEdit" to="." method="_on_v3_y_line_edit_focus_exited"] +[connection signal="text_submitted" from="InputSwitcher/Vector3Input/HBoxContainer/V3YLineEdit" to="." method="_on_v3_y_line_edit_text_submitted"] +[connection signal="drag_started" from="InputSwitcher/Vector3Input/HBoxContainer/V3YLineEdit/DragDropArea" to="." method="_on_drag_drop_area_drag_started"] +[connection signal="drag_started" from="InputSwitcher/Vector3Input/HBoxContainer/CenterContainer2/ColorRect/DragDropArea" to="." method="_on_drag_drop_area_drag_started"] +[connection signal="focus_exited" from="InputSwitcher/Vector3Input/HBoxContainer/V3ZLineEdit" to="." method="_on_v3_z_line_edit_focus_exited"] +[connection signal="text_submitted" from="InputSwitcher/Vector3Input/HBoxContainer/V3ZLineEdit" to="." method="_on_v3_z_line_edit_text_submitted"] +[connection signal="drag_started" from="InputSwitcher/Vector3Input/HBoxContainer/V3ZLineEdit/DragDropArea" to="." method="_on_drag_drop_area_drag_started"] [connection signal="snapped_block_changed" from="SnapPoint" to="." method="_on_snap_point_snapped_block_changed"]