diff --git a/Translations/Translations.pot b/Translations/Translations.pot index da94d7c2a..1d66dffde 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -684,6 +684,19 @@ msgstr "" msgid "Gradient Map" msgstr "" +msgid "Divide into equal parts" +msgstr "" + +msgid "Parts:" +msgstr "" + +msgid "Add point at the end" +msgstr "" + +msgid "If this is enabled, the last point gets added at the end of the gradient.\n" +"Disable this if you wish to convert the gradient to have constant interpolation, so that it will take into account the last color." +msgstr "" + msgid "Linear" msgstr "" diff --git a/src/UI/Nodes/GradientEdit.gd b/src/UI/Nodes/GradientEdit.gd index 3d276546f..fd6e2146f 100644 --- a/src/UI/Nodes/GradientEdit.gd +++ b/src/UI/Nodes/GradientEdit.gd @@ -14,6 +14,9 @@ onready var texture_rect: TextureRect = $TextureRect onready var texture: Texture = $TextureRect.texture onready var gradient: Gradient = texture.gradient onready var color_picker: ColorPicker = $Popup.get_node("ColorPicker") +onready var divide_dialog: ConfirmationDialog = $DivideConfirmationDialog +onready var number_of_parts_spin_box: SpinBox = $"%NumberOfPartsSpinBox" +onready var add_point_end_check_box: CheckBox = $"%AddPointEndCheckBox" class GradientCursor: @@ -97,10 +100,10 @@ class GradientCursor: func _ready() -> void: - create_cursors() + _create_cursors() -func create_cursors() -> void: +func _create_cursors() -> void: for c in texture_rect.get_children(): if c is GradientCursor: texture_rect.remove_child(c) @@ -167,8 +170,30 @@ func _on_GradientEdit_resized() -> void: if not gradient: return x_offset = rect_size.x - GradientCursor.WIDTH - create_cursors() + _create_cursors() func _on_InterpolationOptionButton_item_selected(index: int) -> void: gradient.interpolation_mode = index + + +func _on_DivideButton_pressed() -> void: + divide_dialog.popup_centered() + + +func _on_DivideConfirmationDialog_confirmed() -> void: + var add_point_to_end := add_point_end_check_box.pressed + var parts := number_of_parts_spin_box.value + var colors := [] + var end_point = 1 if add_point_to_end else 0 + parts -= end_point + + if not add_point_to_end: + # Move the final color one part behind, useful for it to be in constant interpolation + gradient.add_point((parts - 1) / parts, gradient.interpolate(1)) + for i in parts + end_point: + colors.append(gradient.interpolate(i / parts)) + gradient.offsets = [] + for i in parts + end_point: + gradient.add_point(i / parts, colors[i]) + _create_cursors() diff --git a/src/UI/Nodes/GradientEdit.tscn b/src/UI/Nodes/GradientEdit.tscn index 0ff13cd7f..ac6e56bab 100644 --- a/src/UI/Nodes/GradientEdit.tscn +++ b/src/UI/Nodes/GradientEdit.tscn @@ -14,7 +14,7 @@ script = ExtResource( 1 ) [node name="TextureRect" type="TextureRect" parent="."] margin_right = 1280.0 -margin_bottom = 696.0 +margin_bottom = 672.0 rect_min_size = Vector2( 0, 30 ) size_flags_vertical = 3 texture = SubResource( 2 ) @@ -41,9 +41,9 @@ margin_right = 312.0 margin_bottom = 466.0 [node name="InterpolationContainer" type="HBoxContainer" parent="."] -margin_top = 700.0 +margin_top = 676.0 margin_right = 1280.0 -margin_bottom = 720.0 +margin_bottom = 696.0 [node name="Label" type="Label" parent="InterpolationContainer"] margin_top = 3.0 @@ -61,6 +61,60 @@ text = "Linear" items = [ "Linear", null, false, 0, null, "Constant", null, false, 1, null, "Cubic", null, false, 2, null ] selected = 0 +[node name="DivideButton" type="Button" parent="."] +margin_top = 700.0 +margin_right = 1280.0 +margin_bottom = 720.0 +mouse_default_cursor_shape = 2 +text = "Divide into equal parts" + +[node name="DivideConfirmationDialog" type="ConfirmationDialog" parent="."] +margin_top = 650.0 +margin_right = 200.0 +margin_bottom = 746.0 +resizable = true + +[node name="VBoxContainer" type="VBoxContainer" parent="DivideConfirmationDialog"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 8.0 +margin_top = 8.0 +margin_right = -8.0 +margin_bottom = -36.0 + +[node name="HBoxContainer" type="HBoxContainer" parent="DivideConfirmationDialog/VBoxContainer"] +margin_right = 1280.0 +margin_bottom = 24.0 + +[node name="Label" type="Label" parent="DivideConfirmationDialog/VBoxContainer/HBoxContainer"] +margin_top = 5.0 +margin_right = 36.0 +margin_bottom = 19.0 +text = "Parts:" + +[node name="NumberOfPartsSpinBox" type="SpinBox" parent="DivideConfirmationDialog/VBoxContainer/HBoxContainer"] +unique_name_in_owner = true +margin_left = 40.0 +margin_right = 1280.0 +margin_bottom = 24.0 +mouse_default_cursor_shape = 2 +size_flags_horizontal = 3 +min_value = 2.0 +value = 3.0 +allow_greater = true + +[node name="AddPointEndCheckBox" type="CheckBox" parent="DivideConfirmationDialog/VBoxContainer"] +unique_name_in_owner = true +margin_top = 28.0 +margin_right = 1280.0 +margin_bottom = 52.0 +hint_tooltip = "If this is enabled, the last point gets added at the end of the gradient. +Disable this if you wish to convert the gradient to have constant interpolation, so that it will take into account the last color." +mouse_default_cursor_shape = 2 +text = "Add point at the end" + [connection signal="resized" from="." to="." method="_on_GradientEdit_resized"] [connection signal="color_changed" from="Popup/ColorPicker" to="." method="_on_ColorPicker_color_changed"] [connection signal="item_selected" from="InterpolationContainer/InterpolationOptionButton" to="." method="_on_InterpolationOptionButton_item_selected"] +[connection signal="pressed" from="DivideButton" to="." method="_on_DivideButton_pressed"] +[connection signal="confirmed" from="DivideConfirmationDialog" to="." method="_on_DivideConfirmationDialog_confirmed"]