diff --git a/src/UI/Dialogs/PreviewDialog.gd b/src/UI/Dialogs/PreviewDialog.gd index 2770a1270..27944f8d7 100644 --- a/src/UI/Dialogs/PreviewDialog.gd +++ b/src/UI/Dialogs/PreviewDialog.gd @@ -9,6 +9,7 @@ var image : Image var current_import_option : int = ImageImportOptions.NEW_TAB var spritesheet_horizontal := 1 var spritesheet_vertical := 1 +var brush_type : int = BrushTypes.FILE onready var texture_rect : TextureRect = $VBoxContainer/CenterContainer/TextureRect onready var image_size_label : Label = $VBoxContainer/SizeContainer/ImageSizeLabel @@ -17,6 +18,7 @@ onready var spritesheet_options = $VBoxContainer/HBoxContainer/SpritesheetOption onready var new_frame_options = $VBoxContainer/HBoxContainer/NewFrameOptions onready var new_layer_options = $VBoxContainer/HBoxContainer/NewLayerOptions onready var new_brush_options = $VBoxContainer/HBoxContainer/NewBrushOptions +onready var new_brush_name = $VBoxContainer/HBoxContainer/NewBrushOptions/BrushName func _on_PreviewDialog_about_to_show() -> void: @@ -57,8 +59,7 @@ func _on_PreviewDialog_confirmed() -> void: Global.palette_container.import_image_palette(path, image) elif current_import_option == ImageImportOptions.BRUSH: - var brush_type_option : int = new_brush_options.get_node("BrushTypeOption").selected - add_brush(brush_type_option) + add_brush() elif current_import_option == ImageImportOptions.PATTERN: var file_name_ext : String = path.get_file() @@ -155,9 +156,16 @@ func spritesheet_frame_value_changed(value : int, vertical : bool) -> void: frame_size_label.text = tr("Frame Size") + ": " + str(frame_width) + "×" + str(frame_height) -func add_brush(type : int) -> void: +func _on_BrushTypeOption_item_selected(index : int) -> void: + brush_type = index + new_brush_name.visible = false + if brush_type == BrushTypes.RANDOM: + new_brush_name.visible = true + + +func add_brush() -> void: image.convert(Image.FORMAT_RGBA8) - if type == BrushTypes.FILE: + if brush_type == BrushTypes.FILE: var file_name_ext : String = path.get_file() file_name_ext = file_name_replace(file_name_ext, "Brushes") var file_name : String = file_name_ext.get_basename() @@ -169,11 +177,37 @@ func add_brush(type : int) -> void: var dir = Directory.new() dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location)) - elif type == BrushTypes.PROJECT: + elif brush_type == BrushTypes.PROJECT: var file_name : String = path.get_file().get_basename() Global.current_project.brushes.append(image) Brushes.add_project_brush(image, file_name) + elif brush_type == BrushTypes.RANDOM: + var brush_name = new_brush_name.get_node("BrushNameLineEdit").text.to_lower() + if !brush_name.is_valid_filename(): + return + var dir := Directory.new() + dir.open(Global.directory_module.xdg_data_home.plus_file("Brushes")) + if !dir.dir_exists(brush_name): + dir.make_dir(brush_name) + + dir.open(Global.directory_module.xdg_data_home.plus_file("Brushes").plus_file(brush_name)) + var random_brushes := [] + dir.list_dir_begin() + var curr_file := dir.get_next() + while curr_file != "": + print(curr_file) + if curr_file.begins_with("%") and brush_name in curr_file: + random_brushes.append(curr_file) + curr_file = dir.get_next() + dir.list_dir_end() + + var file_ext : String = path.get_file().get_extension() + var index : int = random_brushes.size() + 1 + var file_name = "%" + brush_name + str(index) + "." + file_ext + var location := "Brushes".plus_file(brush_name).plus_file(file_name) + dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location)) + # Checks if the file already exists # If it does, add a number to its name, for example diff --git a/src/UI/Dialogs/PreviewDialog.tscn b/src/UI/Dialogs/PreviewDialog.tscn index 27296d0c3..e90821664 100644 --- a/src/UI/Dialogs/PreviewDialog.tscn +++ b/src/UI/Dialogs/PreviewDialog.tscn @@ -26,15 +26,15 @@ __meta__ = { } [node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"] -margin_right = 706.0 +margin_right = 534.0 margin_bottom = 300.0 __meta__ = { "_edit_use_anchors_": false } [node name="TextureRect" type="TextureRect" parent="VBoxContainer/CenterContainer"] -margin_left = 203.0 -margin_right = 503.0 +margin_left = 117.0 +margin_right = 417.0 margin_bottom = 300.0 rect_min_size = Vector2( 300, 300 ) expand = true @@ -49,7 +49,7 @@ __meta__ = { [node name="SizeContainer" type="HBoxContainer" parent="VBoxContainer"] margin_top = 304.0 -margin_right = 706.0 +margin_right = 534.0 margin_bottom = 318.0 custom_constants/separation = 32 @@ -67,7 +67,7 @@ text = "Frame size: 64×64" [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] margin_top = 322.0 -margin_right = 706.0 +margin_right = 534.0 margin_bottom = 342.0 [node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"] @@ -163,26 +163,44 @@ value = 1.0 [node name="NewBrushOptions" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"] visible = false margin_left = 155.0 -margin_right = 324.0 -margin_bottom = 20.0 +margin_right = 471.0 +margin_bottom = 24.0 [node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/NewBrushOptions"] -margin_top = 3.0 +margin_top = 5.0 margin_right = 73.0 -margin_bottom = 17.0 +margin_bottom = 19.0 text = "Brush type:" [node name="BrushTypeOption" type="OptionButton" parent="VBoxContainer/HBoxContainer/NewBrushOptions"] margin_left = 77.0 margin_right = 169.0 -margin_bottom = 20.0 +margin_bottom = 24.0 mouse_default_cursor_shape = 2 text = "File brush" -items = [ "File brush", null, false, 0, null, "Project brush", null, false, 1, null, "Random brush", null, true, 2, null ] +items = [ "File brush", null, false, 0, null, "Project brush", null, false, 1, null, "Random brush", null, false, 2, null ] selected = 0 + +[node name="BrushName" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/NewBrushOptions"] +visible = false +margin_left = 173.0 +margin_right = 316.0 +margin_bottom = 24.0 + +[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/NewBrushOptions/BrushName"] +margin_top = 5.0 +margin_right = 81.0 +margin_bottom = 19.0 +text = "Brush name:" + +[node name="BrushNameLineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer/NewBrushOptions/BrushName"] +margin_left = 85.0 +margin_right = 143.0 +margin_bottom = 24.0 [connection signal="about_to_show" from="." to="." method="_on_PreviewDialog_about_to_show"] [connection signal="confirmed" from="." to="." method="_on_PreviewDialog_confirmed"] [connection signal="popup_hide" from="." to="." method="_on_PreviewDialog_popup_hide"] [connection signal="item_selected" from="VBoxContainer/HBoxContainer/ImportOption" to="." method="_on_ImportOption_item_selected"] [connection signal="value_changed" from="VBoxContainer/HBoxContainer/SpritesheetOptions/HorizontalFrames" to="." method="_on_HorizontalFrames_value_changed"] [connection signal="value_changed" from="VBoxContainer/HBoxContainer/SpritesheetOptions/VerticalFrames" to="." method="_on_VerticalFrames_value_changed"] +[connection signal="item_selected" from="VBoxContainer/HBoxContainer/NewBrushOptions/BrushTypeOption" to="." method="_on_BrushTypeOption_item_selected"]