diff --git a/Main.tscn b/Main.tscn index 566386f2c..951fe610d 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=88 format=2] +[gd_scene load_steps=89 format=2] [ext_resource path="res://Themes & Styles/Dark Theme/Dark Theme.tres" type="Theme" id=1] [ext_resource path="res://Scripts/Main.gd" type="Script" id=2] @@ -60,11 +60,12 @@ [ext_resource path="res://Prefabs/BrushButton.tscn" type="PackedScene" id=58] [ext_resource path="res://Assets/Graphics/Canvas_split.png" type="Texture" id=59] [ext_resource path="res://Assets/Graphics/Canvas_unsplit.png" type="Texture" id=60] -[ext_resource path="res://Prefabs/PreferencesDialog.tscn" type="PackedScene" id=61] -[ext_resource path="res://Scripts/AboutDialog.gd" type="Script" id=62] -[ext_resource path="res://Prefabs/EditPalettePopup.tscn" type="PackedScene" id=63] -[ext_resource path="res://Prefabs/NewPaletteDialog.tscn" type="PackedScene" id=64] -[ext_resource path="res://Prefabs/PaletteImportFileDialog.tscn" type="PackedScene" id=65] +[ext_resource path="res://Prefabs/Dialogs/ImportSprites.tscn" type="PackedScene" id=61] +[ext_resource path="res://Prefabs/Dialogs/PreferencesDialog.tscn" type="PackedScene" id=62] +[ext_resource path="res://Scripts/Dialogs/AboutDialog.gd" type="Script" id=63] +[ext_resource path="res://Prefabs/EditPalettePopup.tscn" type="PackedScene" id=64] +[ext_resource path="res://Prefabs/NewPaletteDialog.tscn" type="PackedScene" id=65] +[ext_resource path="res://Prefabs/PaletteImportFileDialog.tscn" type="PackedScene" id=66] [sub_resource type="InputEventKey" id=1] scancode = 88 @@ -1729,16 +1730,7 @@ filters = PoolStringArray( "*.pxo ; Pixelorama Project" ) current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama" current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/" -[node name="ImportSprites" type="FileDialog" parent="."] -margin_right = 515.0 -margin_bottom = 348.0 -window_title = "Open File(s)" -resizable = true -mode = 1 -access = 2 -filters = PoolStringArray( "*.bmp ; BMP Image", "*.hdr ; Radiance HDR Image", "*.jpg,*.jpeg ; JPEG Image", "*.png ; PNG Image", "*.svg ; SVG Image", "*.tga ; TGA Image", "*.webp ; WebP Image" ) -current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama" -current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/" +[node name="ImportSprites" parent="." instance=ExtResource( 61 )] [node name="ExportSprites" type="FileDialog" parent="."] anchor_left = 0.5 @@ -1825,7 +1817,7 @@ text = "Nearest" items = [ "Nearest", null, false, 0, null, "Bilinear", null, false, 1, null, "Cubic", null, false, 2, null, "Trilinear", null, false, 3, null, "Lanczos", null, true, 4, null ] selected = 0 -[node name="PreferencesDialog" parent="." instance=ExtResource( 61 )] +[node name="PreferencesDialog" parent="." instance=ExtResource( 62 )] [node name="OutlineDialog" type="ConfirmationDialog" parent="."] editor/display_folded = true @@ -1885,7 +1877,7 @@ editor/display_folded = true margin_right = 284.0 margin_bottom = 186.0 window_title = "About Pixelorama" -script = ExtResource( 62 ) +script = ExtResource( 63 ) [node name="AboutUI" type="VBoxContainer" parent="AboutDialog"] margin_left = 8.0 @@ -1956,12 +1948,12 @@ margin_bottom = 60.0 window_title = "Error!" dialog_text = "This is an error message!" -[node name="EditPalettePopup" parent="." instance=ExtResource( 63 )] +[node name="EditPalettePopup" parent="." instance=ExtResource( 64 )] visible = false -[node name="NewPaletteDialog" parent="." instance=ExtResource( 64 )] +[node name="NewPaletteDialog" parent="." instance=ExtResource( 65 )] -[node name="PaletteImportFileDialog" parent="." instance=ExtResource( 65 )] +[node name="PaletteImportFileDialog" parent="." instance=ExtResource( 66 )] filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library" ) current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama" current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/" @@ -2043,8 +2035,7 @@ visible = false [connection signal="popup_hide" from="OpenSprite" to="." method="_on_ImportSprites_popup_hide"] [connection signal="file_selected" from="SaveSprite" to="." method="_on_SaveSprite_file_selected"] [connection signal="popup_hide" from="SaveSprite" to="." method="_can_draw_true"] -[connection signal="files_selected" from="ImportSprites" to="." method="_on_ImportSprites_files_selected"] -[connection signal="popup_hide" from="ImportSprites" to="." method="_on_ImportSprites_popup_hide"] +[connection signal="popup_hide" from="ImportSprites" to="." method="_can_draw_true"] [connection signal="file_selected" from="ExportSprites" to="." method="_on_ExportSprites_file_selected"] [connection signal="popup_hide" from="ExportSprites" to="." method="_can_draw_true"] [connection signal="confirmed" from="ScaleImage" to="." method="_on_ScaleImage_confirmed"] diff --git a/Prefabs/Dialogs/ImportSprites.tscn b/Prefabs/Dialogs/ImportSprites.tscn new file mode 100644 index 000000000..4a6c19f99 --- /dev/null +++ b/Prefabs/Dialogs/ImportSprites.tscn @@ -0,0 +1,68 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Scripts/Dialogs/ImportSprites.gd" type="Script" id=1] + +[node name="ImportSprites" type="FileDialog"] +editor/display_folded = true +margin_right = 515.0 +margin_bottom = 348.0 +window_title = "Open File(s)" +resizable = true +mode = 1 +access = 2 +filters = PoolStringArray( "*.bmp ; BMP Image", "*.hdr ; Radiance HDR Image", "*.jpg,*.jpeg ; JPEG Image", "*.png ; PNG Image", "*.svg ; SVG Image", "*.tga ; TGA Image", "*.webp ; WebP Image" ) +current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama" +current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/" +script = ExtResource( 1 ) + +[node name="HBoxContainer2" type="HBoxContainer" parent="."] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="ImportAsNewFrame" type="CheckBox" parent="HBoxContainer2"] +margin_right = 130.0 +margin_bottom = 40.0 +text = "IMPORT_FILE_LABEL" + +[node name="ImportSpritesheet" type="CheckBox" parent="HBoxContainer2"] +margin_left = 134.0 +margin_right = 268.0 +margin_bottom = 40.0 +text = "Import as spritesheet" + +[node name="Spritesheet" type="HBoxContainer" parent="."] +visible = false +margin_right = 306.0 +margin_bottom = 17.0 + +[node name="Label" type="Label" parent="Spritesheet"] +margin_top = 1.0 +margin_right = 101.0 +margin_bottom = 16.0 +text = "Horizontal frames:" + +[node name="HorizontalFrames" type="SpinBox" parent="Spritesheet"] +margin_left = 105.0 +margin_right = 159.0 +margin_bottom = 17.0 +min_value = 1.0 +value = 1.0 + +[node name="Label2" type="Label" parent="Spritesheet"] +margin_left = 163.0 +margin_top = 1.0 +margin_right = 248.0 +margin_bottom = 16.0 +text = "Vertical frames:" + +[node name="VerticalFrames" type="SpinBox" parent="Spritesheet"] +margin_left = 252.0 +margin_right = 306.0 +margin_bottom = 17.0 +min_value = 1.0 +value = 1.0 +[connection signal="files_selected" from="." to="." method="_on_ImportSprites_files_selected"] +[connection signal="pressed" from="HBoxContainer2/ImportAsNewFrame" to="." method="_on_ImportAsNewFrame_pressed"] +[connection signal="pressed" from="HBoxContainer2/ImportSpritesheet" to="." method="_on_ImportSpritesheet_pressed"] +[connection signal="value_changed" from="Spritesheet/HorizontalFrames" to="." method="_on_HorizontalFrames_value_changed"] +[connection signal="value_changed" from="Spritesheet/VerticalFrames" to="." method="_on_VerticalFrames_value_changed"] diff --git a/Prefabs/PreferencesDialog.tscn b/Prefabs/Dialogs/PreferencesDialog.tscn similarity index 98% rename from Prefabs/PreferencesDialog.tscn rename to Prefabs/Dialogs/PreferencesDialog.tscn index 594046d88..8eed0f596 100644 --- a/Prefabs/PreferencesDialog.tscn +++ b/Prefabs/Dialogs/PreferencesDialog.tscn @@ -1,9 +1,10 @@ [gd_scene load_steps=4 format=2] -[ext_resource path="res://Scripts/PreferencesDialog.gd" type="Script" id=1] +[ext_resource path="res://Scripts/Dialogs/PreferencesDialog.gd" type="Script" id=1] [ext_resource path="res://Assets/Fonts/Roboto-Regular.tres" type="DynamicFont" id=2] [ext_resource path="res://Assets/Fonts/NotoSansCJKtc-Regular.tres" type="DynamicFont" id=3] + [node name="PreferencesDialog" type="AcceptDialog"] margin_right = 200.0 margin_bottom = 70.0 diff --git a/Scripts/AboutDialog.gd b/Scripts/Dialogs/AboutDialog.gd similarity index 100% rename from Scripts/AboutDialog.gd rename to Scripts/Dialogs/AboutDialog.gd diff --git a/Scripts/Dialogs/ImportSprites.gd b/Scripts/Dialogs/ImportSprites.gd new file mode 100644 index 000000000..de20070bc --- /dev/null +++ b/Scripts/Dialogs/ImportSprites.gd @@ -0,0 +1,112 @@ +extends FileDialog + +var new_frame := false +var import_spritesheet := false +var spritesheet_horizontal := 1 +var spritesheet_vertical := 1 + +func _ready(): + var children := [] + for i in range(get_child_count()): + if i > 7: + children.append(get_child(i)) + + for child in children: + remove_child(child) + get_vbox().add_child(child) + +func _on_ImportAsNewFrame_pressed() -> void: + new_frame = !new_frame + +func _on_ImportSpritesheet_pressed() -> void: + import_spritesheet = !import_spritesheet + var spritesheet_container = Global.find_node_by_name(self, "Spritesheet") + spritesheet_container.visible = import_spritesheet + +func _on_HorizontalFrames_value_changed(value) -> void: + spritesheet_horizontal = value + +func _on_VerticalFrames_value_changed(value) -> void: + spritesheet_vertical = value + +func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void: + Global.control.opensprite_file_selected = true + if !new_frame: # If we're not adding a new frame, delete the previous + Global.control.clear_canvases() + + var first_path : String = paths[0] + var i: int = Global.canvases.size() + + if !import_spritesheet: + # Find the biggest image and let it handle the camera zoom options + var max_size : Vector2 + var biggest_canvas : Canvas + for path in paths: + var image := Image.new() + var err := image.load(path) + if err != OK: #An error occured + OS.alert("Can't load file") + continue + + var canvas : Canvas = load("res://Prefabs/Canvas.tscn").instance() + canvas.size = image.get_size() + image.convert(Image.FORMAT_RGBA8) + image.lock() + var tex := ImageTexture.new() + tex.create_from_image(image, 0) + # Store [Image, ImageTexture, Layer Name, Visibity boolean, Opacity] + canvas.layers.append([image, tex, "Layer 0", true, 1]) + canvas.frame = i + Global.canvases.append(canvas) + Global.canvas_parent.add_child(canvas) + canvas.visible = false + if path == paths[0]: #If it's the first file + max_size = canvas.size + biggest_canvas = canvas + else: + if canvas.size > max_size: + biggest_canvas = canvas + + i += 1 + + biggest_canvas.camera_zoom() + + else: + var image := Image.new() + var err := image.load(first_path) + if err != OK: #An error occured + OS.alert("Can't load file") + return + + spritesheet_horizontal = min(spritesheet_horizontal, image.get_size().x) + spritesheet_vertical = min(spritesheet_vertical, image.get_size().y) + var frame_width := image.get_size().x / spritesheet_horizontal + var frame_height := image.get_size().y / spritesheet_vertical + for yy in range(spritesheet_vertical): + for xx in range(spritesheet_horizontal): + var canvas : Canvas = load("res://Prefabs/Canvas.tscn").instance() + var cropped_image := Image.new() + cropped_image = image.get_rect(Rect2(frame_width * xx, frame_height * yy, frame_width, frame_height)) + canvas.size = cropped_image.get_size() + image.convert(Image.FORMAT_RGBA8) + cropped_image.lock() + var tex := ImageTexture.new() + tex.create_from_image(cropped_image, 0) + # Store [Image, ImageTexture, Layer Name, Visibity boolean, Opacity] + canvas.layers.append([cropped_image, tex, "Layer 0", true, 1]) + canvas.frame = i + Global.canvases.append(canvas) + Global.canvas_parent.add_child(canvas) + canvas.visible = false + + i += 1 + + Global.canvases[Global.canvases.size() - 1].camera_zoom() + + Global.current_frame = i - 1 + Global.canvas = Global.canvases[Global.canvases.size() - 1] + Global.canvas.visible = true + + Global.undo_redo.clear_history(false) + OS.set_window_title(first_path.get_file() + " (imported) - Pixelorama") + diff --git a/Scripts/PreferencesDialog.gd b/Scripts/Dialogs/PreferencesDialog.gd similarity index 100% rename from Scripts/PreferencesDialog.gd rename to Scripts/Dialogs/PreferencesDialog.gd diff --git a/Scripts/Global.gd b/Scripts/Global.gd index b8c9fd77e..f2a7d40de 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -145,6 +145,8 @@ var help_menu : MenuButton var cursor_position_label : Label var zoom_level_label : Label +var import_sprites_dialog : FileDialog + var left_color_picker : ColorPickerButton var right_color_picker : ColorPickerButton @@ -257,6 +259,8 @@ func _ready() -> void: cursor_position_label = find_node_by_name(root, "CursorPosition") zoom_level_label = find_node_by_name(root, "ZoomLevel") + import_sprites_dialog = find_node_by_name(root, "ImportSprites") + left_tool_options_container = find_node_by_name(root, "LeftToolOptions") right_tool_options_container = find_node_by_name(root, "RightToolOptions") diff --git a/Scripts/Main.gd b/Scripts/Main.gd index 8d6b371f9..3e6d2bc07 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -6,7 +6,6 @@ var opensprite_file_selected := false var file_menu : PopupMenu var view_menu : PopupMenu var tools := [] -var import_as_new_frame : CheckBox var export_all_frames : CheckBox var export_as_single_file : CheckBox var export_vertical_spritesheet : CheckBox @@ -156,11 +155,6 @@ func _ready() -> void: Global.left_color_picker.get_picker().move_child(Global.left_color_picker.get_picker().get_child(0), 1) Global.right_color_picker.get_picker().move_child(Global.right_color_picker.get_picker().get_child(0), 1) - # Options for Import - import_as_new_frame = CheckBox.new() - import_as_new_frame.text = tr("IMPORT_FILE_LABEL") - $ImportSprites.get_vbox().add_child(import_as_new_frame) - # Options for Export var export_project_hbox := HBoxContainer.new() export_all_frames = CheckBox.new() @@ -169,6 +163,7 @@ func _ready() -> void: export_as_single_file.text = tr("EXPORT_FRAMES_ASFILE_LABEL") export_vertical_spritesheet = CheckBox.new() export_vertical_spritesheet.text = tr("EXPORT_VERTICAL_SPRITESHEET_LABEL") + $ExportSprites.get_vbox().add_child(export_project_hbox) export_project_hbox.add_child(export_all_frames) export_project_hbox.add_child(export_as_single_file) @@ -529,52 +524,6 @@ func _on_SaveSprite_file_selected(path) -> void: file.close() Global.notification_label("File saved") -func _on_ImportSprites_files_selected(paths) -> void: - if !import_as_new_frame.pressed: #If we're not adding a new frame, delete the previous - clear_canvases() - - #Find the biggest image and let it handle the camera zoom options - var max_size : Vector2 - var biggest_canvas : Canvas - var i: int = Global.canvases.size() - for path in paths: - var image := Image.new() - var err := image.load(path) - if err != OK: #An error occured - OS.alert("Can't load file") - continue - - opensprite_file_selected = true - var canvas : Canvas = load("res://Prefabs/Canvas.tscn").instance() - canvas.size = image.get_size() - image.convert(Image.FORMAT_RGBA8) - image.lock() - var tex := ImageTexture.new() - tex.create_from_image(image, 0) - #Store [Image, ImageTexture, Layer Name, Visibity boolean, Opacity] - canvas.layers.append([image, tex, "Layer 0", true, 1]) - canvas.frame = i - Global.canvases.append(canvas) - Global.canvas_parent.add_child(canvas) - canvas.visible = false - if path == paths[0]: #If it's the first file - max_size = canvas.size - biggest_canvas = canvas - else: - if canvas.size > max_size: - biggest_canvas = canvas - - i += 1 - Global.current_frame = i - 1 - Global.canvas = Global.canvases[Global.canvases.size() - 1] - Global.canvas.visible = true - biggest_canvas.camera_zoom() - - Global.undo_redo.clear_history(false) - - var first_path : String = paths[0] - OS.set_window_title(first_path.get_file() + " (imported) - Pixelorama") - func clear_canvases() -> void: for child in Global.vbox_layer_container.get_children(): if child is PanelContainer: @@ -845,8 +794,8 @@ func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_le else: t[0].texture_normal = load("res://Assets/Graphics/%s Themes/Tools/%s.png" % [Global.theme_type, tool_name]) - Global.left_cursor_tool_texture.create_from_image(load("res://Assets/Graphics/Tool Cursors/%s_Cursor.png" % Global.current_left_tool)) - Global.right_cursor_tool_texture.create_from_image(load("res://Assets/Graphics/Tool Cursors/%s_Cursor.png" % Global.current_right_tool)) + Global.left_cursor_tool_texture.create_from_image(load("res://Assets/Graphics/Tool Cursors/%s_Cursor.png" % Global.current_left_tool), 0) + Global.right_cursor_tool_texture.create_from_image(load("res://Assets/Graphics/Tool Cursors/%s_Cursor.png" % Global.current_right_tool), 0) func _on_LeftIndicatorCheckbox_toggled(button_pressed) -> void: Global.left_square_indicator_visible = button_pressed