diff --git a/addons/material_maker/widgets/node_editor/input.gd b/addons/material_maker/widgets/node_editor/input.gd index 99289d0..301f98d 100644 --- a/addons/material_maker/widgets/node_editor/input.gd +++ b/addons/material_maker/widgets/node_editor/input.gd @@ -1,6 +1,13 @@ tool extends HBoxContainer +func update_up_down_button() -> void: + var parent = get_parent() + if parent == null: + return + $Up.disabled = (get_index() == 0) + $Down.disabled = (get_index() == get_parent().get_child_count()-2) + func set_model_data(data) -> void: $Name.text = data.name $Label.text = data.label @@ -23,4 +30,15 @@ func get_model_data() -> Dictionary: return data func _on_Delete_pressed() -> void: + var p = get_parent() + p.remove_child(self) + p.update_up_down_buttons() queue_free() + +func _on_Up_pressed() -> void: + get_parent().move_child(self, get_index() - 1) + get_parent().update_up_down_buttons() + +func _on_Down_pressed() -> void: + get_parent().move_child(self, get_index() + 1) + get_parent().update_up_down_buttons() diff --git a/addons/material_maker/widgets/node_editor/input.tscn b/addons/material_maker/widgets/node_editor/input.tscn index 0f6b2fd..a56a889 100644 --- a/addons/material_maker/widgets/node_editor/input.tscn +++ b/addons/material_maker/widgets/node_editor/input.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://addons/material_maker/widgets/node_editor/input.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=2] @@ -8,6 +8,16 @@ flags = 4 atlas = ExtResource( 2 ) region = Rect2( 0, 16, 16, 16 ) +[sub_resource type="AtlasTexture" id=2] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 18, 48, 12, 16 ) + +[sub_resource type="AtlasTexture" id=3] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 34, 48, 12, 16 ) + [node name="Parameter" type="HBoxContainer"] margin_right = 201.0 margin_bottom = 24.0 @@ -19,25 +29,39 @@ margin_bottom = 24.0 icon = SubResource( 1 ) flat = true -[node name="Name" type="LineEdit" parent="."] +[node name="Up" type="Button" parent="."] margin_left = 32.0 -margin_right = 102.0 +margin_right = 56.0 +margin_bottom = 24.0 +icon = SubResource( 2 ) +flat = true + +[node name="Down" type="Button" parent="."] +margin_left = 60.0 +margin_right = 84.0 +margin_bottom = 24.0 +icon = SubResource( 3 ) +flat = true + +[node name="Name" type="LineEdit" parent="."] +margin_left = 88.0 +margin_right = 158.0 margin_bottom = 24.0 rect_min_size = Vector2( 70, 0 ) hint_tooltip = "Input name" text = "name" [node name="Label" type="LineEdit" parent="."] -margin_left = 106.0 -margin_right = 176.0 +margin_left = 162.0 +margin_right = 232.0 margin_bottom = 24.0 rect_min_size = Vector2( 70, 0 ) hint_tooltip = "Input Label" text = "Label" [node name="Type" type="OptionButton" parent="."] -margin_left = 180.0 -margin_right = 284.0 +margin_left = 236.0 +margin_right = 340.0 margin_bottom = 24.0 rect_min_size = Vector2( 102, 0 ) hint_tooltip = "Input flag" @@ -46,11 +70,13 @@ items = [ "GreyScale", null, false, 0, null, "Color", null, false, 1, null, "RGB selected = 0 [node name="Default" type="LineEdit" parent="."] -margin_left = 288.0 -margin_right = 358.0 +margin_left = 344.0 +margin_right = 414.0 margin_bottom = 24.0 rect_min_size = Vector2( 70, 0 ) hint_tooltip = "Default value" size_flags_horizontal = 3 text = "0.0" [connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"] +[connection signal="pressed" from="Up" to="." method="_on_Up_pressed"] +[connection signal="pressed" from="Down" to="." method="_on_Down_pressed"] diff --git a/addons/material_maker/widgets/node_editor/node_editor.gd b/addons/material_maker/widgets/node_editor/node_editor.gd index 1afb005..b9f256a 100644 --- a/addons/material_maker/widgets/node_editor/node_editor.gd +++ b/addons/material_maker/widgets/node_editor/node_editor.gd @@ -3,6 +3,10 @@ extends WindowDialog var model_data = null +onready var parameter_list : VBoxContainer = $Sizer/Tabs/General/Parameters/Sizer +onready var input_list : VBoxContainer = $Sizer/Tabs/General/Inputs/Sizer +onready var output_list : VBoxContainer = $Sizer/Tabs/Outputs/Outputs/Sizer + onready var main_code_editor : TextEdit = $"Sizer/Tabs/Main Code" onready var instance_functions_editor : TextEdit = $"Sizer/Tabs/Instance Functions" onready var global_functions_editor : TextEdit = $"Sizer/Tabs/Global Functions" @@ -29,13 +33,16 @@ func set_model_data(data) -> void: $Sizer/Tabs/General/Name/Name.text = data.name if data.has("parameters"): for p in data.parameters: - add_item($Sizer/Tabs/General/Parameters/Sizer, ParameterEditor).set_model_data(p) + add_item(parameter_list, ParameterEditor).set_model_data(p) + parameter_list.update_up_down_buttons() if data.has("inputs"): for i in data.inputs: - add_item($Sizer/Tabs/General/Inputs/Sizer, InputEditor).set_model_data(i) + add_item(input_list, InputEditor).set_model_data(i) + input_list.update_up_down_buttons() if data.has("outputs"): for o in data.outputs: - add_item($Sizer/Tabs/Outputs/Outputs/Sizer, OutputEditor).set_model_data(o) + add_item(output_list, OutputEditor).set_model_data(o) + output_list.update_up_down_buttons() if data.has("global"): global_functions_editor.text = data.global if data.has("instance"): @@ -51,27 +58,30 @@ func get_model_data() -> Dictionary: code=main_code_editor.text } data.parameters = [] - for p in $Sizer/Tabs/General/Parameters/Sizer.get_children(): + for p in parameter_list.get_children(): if p.has_method("get_model_data"): data.parameters.append(p.get_model_data()) data.inputs = [] - for i in $Sizer/Tabs/General/Inputs/Sizer.get_children(): + for i in input_list.get_children(): if i.has_method("get_model_data"): data.inputs.append(i.get_model_data()) data.outputs = [] - for o in $Sizer/Tabs/Outputs/Outputs/Sizer.get_children(): + for o in output_list.get_children(): if o.has_method("get_model_data"): data.outputs.append(o.get_model_data()) return data func _on_AddParameter_pressed() -> void: - add_item($Sizer/Tabs/General/Parameters/Sizer, ParameterEditor) + add_item(parameter_list, ParameterEditor) + parameter_list.update_up_down_buttons() func _on_AddInput_pressed() -> void: - add_item($Sizer/Tabs/General/Inputs/Sizer, InputEditor) + add_item(input_list, InputEditor) + input_list.update_up_down_buttons() func _on_AddOutput_pressed() -> void: - add_item($Sizer/Tabs/Outputs/Outputs/Sizer, OutputEditor) + add_item(output_list, OutputEditor) + output_list.update_up_down_buttons() func _on_Apply_pressed() -> void: emit_signal("node_changed", get_model_data()) diff --git a/addons/material_maker/widgets/node_editor/node_editor.tscn b/addons/material_maker/widgets/node_editor/node_editor.tscn index feb1678..e12e89b 100644 --- a/addons/material_maker/widgets/node_editor/node_editor.tscn +++ b/addons/material_maker/widgets/node_editor/node_editor.tscn @@ -1,11 +1,12 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://addons/material_maker/widgets/node_editor/node_editor.gd" type="Script" id=1] -[ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=2] +[ext_resource path="res://addons/material_maker/widgets/node_editor/node_editor_item_list.gd" type="Script" id=2] +[ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=3] [sub_resource type="AtlasTexture" id=1] flags = 4 -atlas = ExtResource( 2 ) +atlas = ExtResource( 3 ) region = Rect2( 48, 0, 16, 16 ) [sub_resource type="DynamicFontData" id=2] @@ -16,7 +17,7 @@ size = 12 font_data = SubResource( 2 ) [node name="NodeEditor" type="WindowDialog"] -margin_right = 833.0 +margin_right = 896.0 margin_bottom = 398.0 popup_exclusive = true window_title = "Node Editor" @@ -29,7 +30,7 @@ size_flags_horizontal = 3 size_flags_vertical = 3 [node name="Tabs" type="TabContainer" parent="Sizer"] -margin_right = 833.0 +margin_right = 896.0 margin_bottom = 374.0 size_flags_horizontal = 3 size_flags_vertical = 3 @@ -44,7 +45,7 @@ margin_right = -4.0 margin_bottom = -4.0 [node name="Name" type="HBoxContainer" parent="Sizer/Tabs/General"] -margin_right = 825.0 +margin_right = 888.0 margin_bottom = 24.0 size_flags_horizontal = 3 @@ -56,28 +57,29 @@ text = "Name:" [node name="Name" type="LineEdit" parent="Sizer/Tabs/General/Name"] margin_left = 46.0 -margin_right = 825.0 +margin_right = 888.0 margin_bottom = 24.0 size_flags_horizontal = 3 [node name="LabelParameters" type="Label" parent="Sizer/Tabs/General"] margin_top = 28.0 -margin_right = 825.0 +margin_right = 888.0 margin_bottom = 42.0 text = "Parameters:" [node name="Parameters" type="ScrollContainer" parent="Sizer/Tabs/General"] margin_top = 46.0 -margin_right = 825.0 +margin_right = 888.0 margin_bottom = 181.0 size_flags_horizontal = 3 size_flags_vertical = 3 scroll_horizontal_enabled = false [node name="Sizer" type="VBoxContainer" parent="Sizer/Tabs/General/Parameters"] -margin_right = 825.0 +margin_right = 888.0 margin_bottom = 22.0 size_flags_horizontal = 3 +script = ExtResource( 2 ) [node name="AddParameter" type="Button" parent="Sizer/Tabs/General/Parameters/Sizer"] margin_right = 28.0 @@ -88,22 +90,23 @@ flat = true [node name="LabelInputs" type="Label" parent="Sizer/Tabs/General"] margin_top = 185.0 -margin_right = 825.0 +margin_right = 888.0 margin_bottom = 199.0 text = "Inputs:" [node name="Inputs" type="ScrollContainer" parent="Sizer/Tabs/General"] margin_top = 203.0 -margin_right = 825.0 +margin_right = 888.0 margin_bottom = 338.0 size_flags_horizontal = 3 size_flags_vertical = 3 scroll_horizontal_enabled = false [node name="Sizer" type="VBoxContainer" parent="Sizer/Tabs/General/Inputs"] -margin_right = 825.0 +margin_right = 888.0 margin_bottom = 22.0 size_flags_horizontal = 3 +script = ExtResource( 2 ) [node name="AddInput" type="Button" parent="Sizer/Tabs/General/Inputs/Sizer"] margin_right = 28.0 @@ -138,6 +141,7 @@ scroll_horizontal_enabled = false margin_right = 825.0 margin_bottom = 22.0 size_flags_horizontal = 3 +script = ExtResource( 2 ) [node name="AddOutput" type="Button" parent="Sizer/Tabs/Outputs/Outputs/Sizer"] margin_right = 28.0 @@ -187,9 +191,9 @@ syntax_highlighting = true show_line_numbers = true [node name="HBoxContainer" type="HBoxContainer" parent="Sizer"] -margin_left = 307.0 +margin_left = 339.0 margin_top = 378.0 -margin_right = 525.0 +margin_right = 557.0 margin_bottom = 398.0 size_flags_horizontal = 4 diff --git a/addons/material_maker/widgets/node_editor/node_editor_item_list.gd b/addons/material_maker/widgets/node_editor/node_editor_item_list.gd new file mode 100644 index 0000000..79ce49b --- /dev/null +++ b/addons/material_maker/widgets/node_editor/node_editor_item_list.gd @@ -0,0 +1,7 @@ +tool +extends VBoxContainer + +func update_up_down_buttons() -> void: + for c in get_children(): + if ! (c is Button): + c.update_up_down_button() diff --git a/addons/material_maker/widgets/node_editor/output.gd b/addons/material_maker/widgets/node_editor/output.gd index ebeae0c..ca9d8c0 100644 --- a/addons/material_maker/widgets/node_editor/output.gd +++ b/addons/material_maker/widgets/node_editor/output.gd @@ -1,6 +1,13 @@ tool extends HBoxContainer +func update_up_down_button() -> void: + var parent = get_parent() + if parent == null: + return + $Up.disabled = (get_index() == 0) + $Down.disabled = (get_index() == get_parent().get_child_count()-2) + func set_model_data(data) -> void: if data.has("rgb"): $Type.selected = 1 @@ -21,4 +28,15 @@ func get_model_data() -> Dictionary: return { f=$Value.text } func _on_Delete_pressed() -> void: + var p = get_parent() + p.remove_child(self) + p.update_up_down_buttons() queue_free() + +func _on_Up_pressed() -> void: + get_parent().move_child(self, get_index() - 1) + get_parent().update_up_down_buttons() + +func _on_Down_pressed() -> void: + get_parent().move_child(self, get_index() + 1) + get_parent().update_up_down_buttons() diff --git a/addons/material_maker/widgets/node_editor/output.tscn b/addons/material_maker/widgets/node_editor/output.tscn index 1410dcd..bd1d127 100644 --- a/addons/material_maker/widgets/node_editor/output.tscn +++ b/addons/material_maker/widgets/node_editor/output.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://addons/material_maker/widgets/node_editor/output.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=2] @@ -8,12 +8,22 @@ flags = 4 atlas = ExtResource( 2 ) region = Rect2( 0, 16, 16, 16 ) -[sub_resource type="DynamicFontData" id=2] +[sub_resource type="AtlasTexture" id=2] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 18, 48, 12, 16 ) + +[sub_resource type="AtlasTexture" id=3] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 34, 48, 12, 16 ) + +[sub_resource type="DynamicFontData" id=4] font_path = "res://addons/material_maker/fonts/hack.ttf" -[sub_resource type="DynamicFont" id=3] +[sub_resource type="DynamicFont" id=5] size = 12 -font_data = SubResource( 2 ) +font_data = SubResource( 4 ) [node name="Output" type="HBoxContainer"] margin_right = 251.0 @@ -27,9 +37,23 @@ margin_bottom = 25.0 icon = SubResource( 1 ) flat = true -[node name="Type" type="OptionButton" parent="."] +[node name="Up" type="Button" parent="."] margin_left = 32.0 -margin_right = 136.0 +margin_right = 56.0 +margin_bottom = 25.0 +icon = SubResource( 2 ) +flat = true + +[node name="Down" type="Button" parent="."] +margin_left = 60.0 +margin_right = 84.0 +margin_bottom = 25.0 +icon = SubResource( 3 ) +flat = true + +[node name="Type" type="OptionButton" parent="."] +margin_left = 88.0 +margin_right = 192.0 margin_bottom = 25.0 rect_min_size = Vector2( 102, 0 ) hint_tooltip = "Input flag" @@ -38,12 +62,14 @@ items = [ "GreyScale", null, false, 0, null, "Color", null, false, 1, null, "RGB selected = 0 [node name="Value" type="LineEdit" parent="."] -margin_left = 140.0 -margin_right = 251.0 +margin_left = 196.0 +margin_right = 290.0 margin_bottom = 25.0 hint_tooltip = "Default value" size_flags_horizontal = 3 -custom_fonts/font = SubResource( 3 ) +custom_fonts/font = SubResource( 5 ) text = "0.0" context_menu_enabled = false [connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"] +[connection signal="pressed" from="Up" to="." method="_on_Up_pressed"] +[connection signal="pressed" from="Down" to="." method="_on_Down_pressed"] diff --git a/addons/material_maker/widgets/node_editor/parameter.gd b/addons/material_maker/widgets/node_editor/parameter.gd index d5c5910..f6aab20 100644 --- a/addons/material_maker/widgets/node_editor/parameter.gd +++ b/addons/material_maker/widgets/node_editor/parameter.gd @@ -7,6 +7,13 @@ func _ready() -> void: $Type.add_item(t.name) _on_Type_item_selected($Type.selected) +func update_up_down_button() -> void: + var parent = get_parent() + if parent == null: + return + $Up.disabled = (get_index() == 0) + $Down.disabled = (get_index() == get_parent().get_child_count()-2) + func set_model_data(data) -> void: if data.has("name"): $Name.text = data.name @@ -28,8 +35,19 @@ func get_model_data() -> Dictionary: return data func _on_Delete_pressed() -> void: + var p = get_parent() + p.remove_child(self) + p.update_up_down_buttons() queue_free() +func _on_Up_pressed() -> void: + get_parent().move_child(self, get_index() - 1) + get_parent().update_up_down_buttons() + +func _on_Down_pressed() -> void: + get_parent().move_child(self, get_index() + 1) + get_parent().update_up_down_buttons() + func _on_Type_item_selected(ID) -> void: for t in $Types.get_children(): t.visible = false diff --git a/addons/material_maker/widgets/node_editor/parameter.tscn b/addons/material_maker/widgets/node_editor/parameter.tscn index 43b3a8a..907a1a8 100644 --- a/addons/material_maker/widgets/node_editor/parameter.tscn +++ b/addons/material_maker/widgets/node_editor/parameter.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=12 format=2] [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/icons/icons.svg" type="Texture" id=2] @@ -14,6 +14,16 @@ flags = 4 atlas = ExtResource( 2 ) region = Rect2( 0, 16, 16, 16 ) +[sub_resource type="AtlasTexture" id=2] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 18, 48, 12, 16 ) + +[sub_resource type="AtlasTexture" id=3] +flags = 4 +atlas = ExtResource( 2 ) +region = Rect2( 34, 48, 12, 16 ) + [node name="Parameter" type="HBoxContainer"] margin_right = 201.0 margin_bottom = 24.0 @@ -25,31 +35,45 @@ margin_bottom = 24.0 icon = SubResource( 1 ) flat = true -[node name="Name" type="LineEdit" parent="."] +[node name="Up" type="Button" parent="."] margin_left = 32.0 -margin_right = 102.0 +margin_right = 56.0 +margin_bottom = 24.0 +icon = SubResource( 2 ) +flat = true + +[node name="Down" type="Button" parent="."] +margin_left = 60.0 +margin_right = 84.0 +margin_bottom = 24.0 +icon = SubResource( 3 ) +flat = true + +[node name="Name" type="LineEdit" parent="."] +margin_left = 88.0 +margin_right = 158.0 margin_bottom = 24.0 rect_min_size = Vector2( 70, 0 ) text = "name" [node name="Label" type="LineEdit" parent="."] -margin_left = 106.0 -margin_right = 176.0 +margin_left = 162.0 +margin_right = 232.0 margin_bottom = 24.0 rect_min_size = Vector2( 70, 0 ) text = "Label" [node name="Type" type="OptionButton" parent="."] -margin_left = 180.0 -margin_right = 249.0 +margin_left = 236.0 +margin_right = 305.0 margin_bottom = 24.0 text = "float" items = [ "float", null, false, -1, null, "size", null, false, -1, null, "enum", null, false, -1, null, "boolean", null, false, -1, null, "color", null, false, -1, null, "gradient", null, false, -1, null ] selected = 0 [node name="Types" type="HBoxContainer" parent="."] -margin_left = 253.0 -margin_right = 800.0 +margin_left = 309.0 +margin_right = 856.0 margin_bottom = 24.0 [node name="float" parent="Types" instance=ExtResource( 3 )] @@ -79,4 +103,6 @@ margin_left = 551.0 margin_right = 725.0 margin_bottom = 30.0 [connection signal="pressed" from="Delete" to="." method="_on_Delete_pressed"] +[connection signal="pressed" from="Up" to="." method="_on_Up_pressed"] +[connection signal="pressed" from="Down" to="." method="_on_Down_pressed"] [connection signal="item_selected" from="Type" to="." method="_on_Type_item_selected"] diff --git a/addons/material_maker/widgets/node_editor/parameter_boolean.tscn b/addons/material_maker/widgets/node_editor/parameter_boolean.tscn index a7b0855..361ecae 100644 --- a/addons/material_maker/widgets/node_editor/parameter_boolean.tscn +++ b/addons/material_maker/widgets/node_editor/parameter_boolean.tscn @@ -3,44 +3,12 @@ [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_boolean.gd" type="Script" id=1] [node name="boolean" type="HBoxContainer"] - visible = false -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 margin_right = 74.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -mouse_filter = 1 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -alignment = 0 script = ExtResource( 1 ) -[node name="Default" type="CheckBox" parent="." index="0"] - -anchor_left = 0.0 -anchor_top = 0.0 -anchor_right = 0.0 -anchor_bottom = 0.0 +[node name="Default" type="CheckBox" parent="."] margin_right = 74.0 margin_bottom = 24.0 -rect_pivot_offset = Vector2( 0, 0 ) -rect_clip_content = false -focus_mode = 2 -mouse_filter = 0 -mouse_default_cursor_shape = 0 -size_flags_horizontal = 1 -size_flags_vertical = 1 -toggle_mode = true -enabled_focus_mode = 2 -shortcut = null -group = null text = "Default" -flat = false -align = 0 - -