mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-22 05:23:14 +00:00
Changed Export PNG settings, moved code from Main.gd to ExportSprites.gd
And made ExportSprites.tscn a scene of its own
This commit is contained in:
parent
04fe708560
commit
67631ac648
7 changed files with 162 additions and 144 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -2,8 +2,5 @@
|
||||||
.import/
|
.import/
|
||||||
export_presets.cfg
|
export_presets.cfg
|
||||||
|
|
||||||
# Imported translations
|
Translations/Update Translations.bat
|
||||||
# Godot imports them automatically when editing the project for the first time.
|
|
||||||
*.translation
|
|
||||||
|
|
||||||
Scripts/Old/
|
Scripts/Old/
|
||||||
|
|
41
Main.tscn
41
Main.tscn
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=89 format=2]
|
[gd_scene load_steps=90 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Themes & Styles/Dark Theme/Dark Theme.tres" type="Theme" id=1]
|
[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]
|
[ext_resource path="res://Scripts/Main.gd" type="Script" id=2]
|
||||||
|
@ -61,11 +61,12 @@
|
||||||
[ext_resource path="res://Assets/Graphics/Canvas_split.png" type="Texture" id=59]
|
[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://Assets/Graphics/Canvas_unsplit.png" type="Texture" id=60]
|
||||||
[ext_resource path="res://Prefabs/Dialogs/ImportSprites.tscn" type="PackedScene" id=61]
|
[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://Prefabs/Dialogs/ExportSprites.tscn" type="PackedScene" id=62]
|
||||||
[ext_resource path="res://Scripts/Dialogs/AboutDialog.gd" type="Script" id=63]
|
[ext_resource path="res://Prefabs/Dialogs/PreferencesDialog.tscn" type="PackedScene" id=63]
|
||||||
[ext_resource path="res://Prefabs/EditPalettePopup.tscn" type="PackedScene" id=64]
|
[ext_resource path="res://Scripts/Dialogs/AboutDialog.gd" type="Script" id=64]
|
||||||
[ext_resource path="res://Prefabs/NewPaletteDialog.tscn" type="PackedScene" id=65]
|
[ext_resource path="res://Prefabs/EditPalettePopup.tscn" type="PackedScene" id=65]
|
||||||
[ext_resource path="res://Prefabs/PaletteImportFileDialog.tscn" type="PackedScene" id=66]
|
[ext_resource path="res://Prefabs/NewPaletteDialog.tscn" type="PackedScene" id=66]
|
||||||
|
[ext_resource path="res://Prefabs/PaletteImportFileDialog.tscn" type="PackedScene" id=67]
|
||||||
|
|
||||||
[sub_resource type="InputEventKey" id=1]
|
[sub_resource type="InputEventKey" id=1]
|
||||||
scancode = 88
|
scancode = 88
|
||||||
|
@ -778,6 +779,7 @@ size_flags_vertical = 1
|
||||||
min_value = 1.0
|
min_value = 1.0
|
||||||
value = 1.0
|
value = 1.0
|
||||||
allow_greater = true
|
allow_greater = true
|
||||||
|
ticks_on_borders = true
|
||||||
|
|
||||||
[node name="RightBrushSizeEdit" type="SpinBox" parent="MenuAndUI/UI/ToolPanel/Tools/ColorAndToolOptions/RightToolOptions/RightBrushSize"]
|
[node name="RightBrushSizeEdit" type="SpinBox" parent="MenuAndUI/UI/ToolPanel/Tools/ColorAndToolOptions/RightToolOptions/RightBrushSize"]
|
||||||
margin_left = 154.0
|
margin_left = 154.0
|
||||||
|
@ -1732,21 +1734,7 @@ current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρι
|
||||||
|
|
||||||
[node name="ImportSprites" parent="." instance=ExtResource( 61 )]
|
[node name="ImportSprites" parent="." instance=ExtResource( 61 )]
|
||||||
|
|
||||||
[node name="ExportSprites" type="FileDialog" parent="."]
|
[node name="ExportSprites" parent="." instance=ExtResource( 62 )]
|
||||||
anchor_left = 0.5
|
|
||||||
anchor_top = 0.5
|
|
||||||
anchor_right = 0.5
|
|
||||||
anchor_bottom = 0.5
|
|
||||||
margin_left = -512.0
|
|
||||||
margin_top = -300.0
|
|
||||||
margin_right = 3.0
|
|
||||||
margin_bottom = 48.0
|
|
||||||
window_title = "Export Sprite"
|
|
||||||
resizable = true
|
|
||||||
access = 2
|
|
||||||
filters = PoolStringArray( "*.png ; PNG 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="ScaleImage" type="ConfirmationDialog" parent="."]
|
[node name="ScaleImage" type="ConfirmationDialog" parent="."]
|
||||||
editor/display_folded = true
|
editor/display_folded = true
|
||||||
|
@ -1817,7 +1805,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 ]
|
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
|
selected = 0
|
||||||
|
|
||||||
[node name="PreferencesDialog" parent="." instance=ExtResource( 62 )]
|
[node name="PreferencesDialog" parent="." instance=ExtResource( 63 )]
|
||||||
|
|
||||||
[node name="OutlineDialog" type="ConfirmationDialog" parent="."]
|
[node name="OutlineDialog" type="ConfirmationDialog" parent="."]
|
||||||
editor/display_folded = true
|
editor/display_folded = true
|
||||||
|
@ -1877,7 +1865,7 @@ editor/display_folded = true
|
||||||
margin_right = 284.0
|
margin_right = 284.0
|
||||||
margin_bottom = 186.0
|
margin_bottom = 186.0
|
||||||
window_title = "About Pixelorama"
|
window_title = "About Pixelorama"
|
||||||
script = ExtResource( 63 )
|
script = ExtResource( 64 )
|
||||||
|
|
||||||
[node name="AboutUI" type="VBoxContainer" parent="AboutDialog"]
|
[node name="AboutUI" type="VBoxContainer" parent="AboutDialog"]
|
||||||
margin_left = 8.0
|
margin_left = 8.0
|
||||||
|
@ -1948,12 +1936,12 @@ margin_bottom = 60.0
|
||||||
window_title = "Error!"
|
window_title = "Error!"
|
||||||
dialog_text = "This is an error message!"
|
dialog_text = "This is an error message!"
|
||||||
|
|
||||||
[node name="EditPalettePopup" parent="." instance=ExtResource( 64 )]
|
[node name="EditPalettePopup" parent="." instance=ExtResource( 65 )]
|
||||||
visible = false
|
visible = false
|
||||||
|
|
||||||
[node name="NewPaletteDialog" parent="." instance=ExtResource( 65 )]
|
[node name="NewPaletteDialog" parent="." instance=ExtResource( 66 )]
|
||||||
|
|
||||||
[node name="PaletteImportFileDialog" parent="." instance=ExtResource( 66 )]
|
[node name="PaletteImportFileDialog" parent="." instance=ExtResource( 67 )]
|
||||||
filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library" )
|
filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library" )
|
||||||
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
||||||
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
||||||
|
@ -2036,7 +2024,6 @@ visible = false
|
||||||
[connection signal="file_selected" from="SaveSprite" to="." method="_on_SaveSprite_file_selected"]
|
[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="popup_hide" from="SaveSprite" to="." method="_can_draw_true"]
|
||||||
[connection signal="popup_hide" from="ImportSprites" to="." method="_can_draw_true"]
|
[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="popup_hide" from="ExportSprites" to="." method="_can_draw_true"]
|
||||||
[connection signal="confirmed" from="ScaleImage" to="." method="_on_ScaleImage_confirmed"]
|
[connection signal="confirmed" from="ScaleImage" to="." method="_on_ScaleImage_confirmed"]
|
||||||
[connection signal="popup_hide" from="ScaleImage" to="." method="_can_draw_true"]
|
[connection signal="popup_hide" from="ScaleImage" to="." method="_can_draw_true"]
|
||||||
|
|
28
Prefabs/Dialogs/ExportSprites.tscn
Normal file
28
Prefabs/Dialogs/ExportSprites.tscn
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Scripts/Dialogs/ExportSprites.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="ExportSprites" type="FileDialog"]
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
margin_left = -512.0
|
||||||
|
margin_top = -300.0
|
||||||
|
margin_right = 3.0
|
||||||
|
margin_bottom = 48.0
|
||||||
|
resizable = true
|
||||||
|
access = 2
|
||||||
|
filters = PoolStringArray( "*.png ; PNG 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="ExportOption" type="OptionButton" parent="."]
|
||||||
|
margin_right = 41.0
|
||||||
|
margin_bottom = 20.0
|
||||||
|
text = "Export current frame"
|
||||||
|
items = [ "Export current frame", null, false, 0, null, "Export all frames as multiple files", null, false, 1, null, "Export all frames as a horizontal spritesheet (single file)", null, false, 2, null, "Export all frames as a vertical spritesheet (single file)", null, false, 3, null ]
|
||||||
|
selected = 0
|
||||||
|
[connection signal="file_selected" from="." to="." method="_on_ExportSprites_file_selected"]
|
||||||
|
[connection signal="item_selected" from="ExportOption" to="." method="_on_ExportOption_item_selected"]
|
|
@ -3,7 +3,6 @@
|
||||||
[ext_resource path="res://Scripts/Dialogs/ImportSprites.gd" type="Script" id=1]
|
[ext_resource path="res://Scripts/Dialogs/ImportSprites.gd" type="Script" id=1]
|
||||||
|
|
||||||
[node name="ImportSprites" type="FileDialog"]
|
[node name="ImportSprites" type="FileDialog"]
|
||||||
editor/display_folded = true
|
|
||||||
margin_right = 515.0
|
margin_right = 515.0
|
||||||
margin_bottom = 348.0
|
margin_bottom = 348.0
|
||||||
window_title = "Open File(s)"
|
window_title = "Open File(s)"
|
||||||
|
@ -16,8 +15,10 @@ current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρι
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="HBoxContainer2" type="HBoxContainer" parent="."]
|
[node name="HBoxContainer2" type="HBoxContainer" parent="."]
|
||||||
margin_right = 40.0
|
margin_left = 8.0
|
||||||
margin_bottom = 40.0
|
margin_top = 8.0
|
||||||
|
margin_right = 507.0
|
||||||
|
margin_bottom = 312.0
|
||||||
|
|
||||||
[node name="ImportAsNewFrame" type="CheckBox" parent="HBoxContainer2"]
|
[node name="ImportAsNewFrame" type="CheckBox" parent="HBoxContainer2"]
|
||||||
margin_right = 130.0
|
margin_right = 130.0
|
||||||
|
@ -32,8 +33,10 @@ text = "Import as spritesheet"
|
||||||
|
|
||||||
[node name="Spritesheet" type="HBoxContainer" parent="."]
|
[node name="Spritesheet" type="HBoxContainer" parent="."]
|
||||||
visible = false
|
visible = false
|
||||||
margin_right = 306.0
|
margin_left = 8.0
|
||||||
margin_bottom = 17.0
|
margin_top = 8.0
|
||||||
|
margin_right = 507.0
|
||||||
|
margin_bottom = 312.0
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="Spritesheet"]
|
[node name="Label" type="Label" parent="Spritesheet"]
|
||||||
margin_top = 1.0
|
margin_top = 1.0
|
||||||
|
|
104
Scripts/Dialogs/ExportSprites.gd
Normal file
104
Scripts/Dialogs/ExportSprites.gd
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
extends FileDialog
|
||||||
|
|
||||||
|
var current_export_path := ""
|
||||||
|
var export_option := 0
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
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_ExportOption_item_selected(ID : int) -> void:
|
||||||
|
export_option = ID
|
||||||
|
|
||||||
|
func _on_ExportSprites_file_selected(path : String) -> void:
|
||||||
|
current_export_path = path
|
||||||
|
Global.file_menu.get_popup().set_item_text(5, tr("Export") + " %s" % path.get_file())
|
||||||
|
export_project()
|
||||||
|
|
||||||
|
func export_project() -> void:
|
||||||
|
if export_option == 0: # Export current frame
|
||||||
|
save_sprite(Global.canvas, current_export_path)
|
||||||
|
elif export_option == 1: # Export all frames as multiple files
|
||||||
|
var i := 1
|
||||||
|
for canvas in Global.canvases:
|
||||||
|
var path := "%s_%s" % [current_export_path, str(i)]
|
||||||
|
path = path.replace(".png", "")
|
||||||
|
path = "%s.png" % path
|
||||||
|
save_sprite(canvas, path)
|
||||||
|
i += 1
|
||||||
|
else: # Export all frames as a spritesheet (single file)
|
||||||
|
save_spritesheet(export_option == 2)
|
||||||
|
|
||||||
|
Global.notification_label("File exported")
|
||||||
|
|
||||||
|
func save_sprite(canvas : Canvas, path : String) -> void:
|
||||||
|
var whole_image := Image.new()
|
||||||
|
whole_image.create(canvas.size.x, canvas.size.y, false, Image.FORMAT_RGBA8)
|
||||||
|
whole_image.lock()
|
||||||
|
for layer in canvas.layers:
|
||||||
|
var img : Image = layer[0]
|
||||||
|
img.lock()
|
||||||
|
if layer[4] < 1: # If we have layer transparency
|
||||||
|
for xx in img.get_size().x:
|
||||||
|
for yy in img.get_size().y:
|
||||||
|
var pixel_color := img.get_pixel(xx, yy)
|
||||||
|
var alpha : float = pixel_color.a * layer[4]
|
||||||
|
img.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
||||||
|
|
||||||
|
canvas.blend_rect(whole_image, img, Rect2(canvas.position, canvas.size), Vector2.ZERO)
|
||||||
|
layer[0].lock()
|
||||||
|
var err = whole_image.save_png(path)
|
||||||
|
if err != OK:
|
||||||
|
OS.alert("Can't save file")
|
||||||
|
|
||||||
|
func save_spritesheet(horizontal : bool) -> void:
|
||||||
|
var width
|
||||||
|
var height
|
||||||
|
if horizontal: # Horizontal spritesheet
|
||||||
|
width = 0
|
||||||
|
height = Global.canvas.size.y
|
||||||
|
for canvas in Global.canvases:
|
||||||
|
width += canvas.size.x
|
||||||
|
if canvas.size.y > height:
|
||||||
|
height = canvas.size.y
|
||||||
|
else: # Vertical spritesheet
|
||||||
|
width = Global.canvas.size.x
|
||||||
|
height = 0
|
||||||
|
for canvas in Global.canvases:
|
||||||
|
height += canvas.size.y
|
||||||
|
if canvas.size.x > width:
|
||||||
|
width = canvas.size.x
|
||||||
|
|
||||||
|
var whole_image := Image.new()
|
||||||
|
whole_image.create(width, height, false, Image.FORMAT_RGBA8)
|
||||||
|
whole_image.lock()
|
||||||
|
var dst := Vector2.ZERO
|
||||||
|
for canvas in Global.canvases:
|
||||||
|
for layer in canvas.layers:
|
||||||
|
var img : Image = layer[0]
|
||||||
|
img.lock()
|
||||||
|
if layer[4] < 1: # If we have layer transparency
|
||||||
|
for xx in img.get_size().x:
|
||||||
|
for yy in img.get_size().y:
|
||||||
|
var pixel_color := img.get_pixel(xx, yy)
|
||||||
|
var alpha : float = pixel_color.a * layer[4]
|
||||||
|
img.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
||||||
|
|
||||||
|
canvas.blend_rect(whole_image, img, Rect2(canvas.position, canvas.size), dst)
|
||||||
|
layer[0].lock()
|
||||||
|
|
||||||
|
if horizontal:
|
||||||
|
dst += Vector2(canvas.size.x, 0)
|
||||||
|
else:
|
||||||
|
dst += Vector2(0, canvas.size.y)
|
||||||
|
|
||||||
|
var err = whole_image.save_png(current_export_path)
|
||||||
|
if err != OK:
|
||||||
|
OS.alert("Can't save file")
|
||||||
|
|
|
@ -5,7 +5,7 @@ var import_spritesheet := false
|
||||||
var spritesheet_horizontal := 1
|
var spritesheet_horizontal := 1
|
||||||
var spritesheet_vertical := 1
|
var spritesheet_vertical := 1
|
||||||
|
|
||||||
func _ready():
|
func _ready() -> void:
|
||||||
var children := []
|
var children := []
|
||||||
for i in range(get_child_count()):
|
for i in range(get_child_count()):
|
||||||
if i > 7:
|
if i > 7:
|
||||||
|
@ -44,7 +44,7 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
|
||||||
for path in paths:
|
for path in paths:
|
||||||
var image := Image.new()
|
var image := Image.new()
|
||||||
var err := image.load(path)
|
var err := image.load(path)
|
||||||
if err != OK: #An error occured
|
if err != OK: # An error occured
|
||||||
OS.alert("Can't load file")
|
OS.alert("Can't load file")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
|
||||||
else:
|
else:
|
||||||
var image := Image.new()
|
var image := Image.new()
|
||||||
var err := image.load(first_path)
|
var err := image.load(first_path)
|
||||||
if err != OK: #An error occured
|
if err != OK: # An error occured
|
||||||
OS.alert("Can't load file")
|
OS.alert("Can't load file")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
109
Scripts/Main.gd
109
Scripts/Main.gd
|
@ -1,14 +1,11 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
var current_save_path := ""
|
var current_save_path := ""
|
||||||
var current_export_path := ""
|
|
||||||
var opensprite_file_selected := false
|
var opensprite_file_selected := false
|
||||||
var file_menu : PopupMenu
|
var file_menu : PopupMenu
|
||||||
var view_menu : PopupMenu
|
var view_menu : PopupMenu
|
||||||
var tools := []
|
var tools := []
|
||||||
var export_all_frames : CheckBox
|
|
||||||
var export_as_single_file : CheckBox
|
|
||||||
var export_vertical_spritesheet : CheckBox
|
|
||||||
var redone := false
|
var redone := false
|
||||||
var fps := 6.0
|
var fps := 6.0
|
||||||
var animation_loop := 0 # 0 is no loop, 1 is cycle loop, 2 is ping-pong loop
|
var animation_loop := 0 # 0 is no loop, 1 is cycle loop, 2 is ping-pong loop
|
||||||
|
@ -155,20 +152,6 @@ func _ready() -> void:
|
||||||
Global.left_color_picker.get_picker().move_child(Global.left_color_picker.get_picker().get_child(0), 1)
|
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)
|
Global.right_color_picker.get_picker().move_child(Global.right_color_picker.get_picker().get_child(0), 1)
|
||||||
|
|
||||||
# Options for Export
|
|
||||||
var export_project_hbox := HBoxContainer.new()
|
|
||||||
export_all_frames = CheckBox.new()
|
|
||||||
export_all_frames.text = tr("EXPORT_ALLFRAMES_LABEL")
|
|
||||||
export_as_single_file = CheckBox.new()
|
|
||||||
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)
|
|
||||||
export_project_hbox.add_child(export_vertical_spritesheet)
|
|
||||||
|
|
||||||
Import.import_brushes("Brushes")
|
Import.import_brushes("Brushes")
|
||||||
|
|
||||||
func _input(event : InputEvent) -> void:
|
func _input(event : InputEvent) -> void:
|
||||||
|
@ -219,11 +202,11 @@ func file_menu_id_pressed(id : int) -> void:
|
||||||
Global.can_draw = false
|
Global.can_draw = false
|
||||||
opensprite_file_selected = false
|
opensprite_file_selected = false
|
||||||
5: # Export
|
5: # Export
|
||||||
if current_export_path == "":
|
if $ExportSprites.current_export_path == "":
|
||||||
$ExportSprites.popup_centered()
|
$ExportSprites.popup_centered()
|
||||||
Global.can_draw = false
|
Global.can_draw = false
|
||||||
else:
|
else:
|
||||||
export_project()
|
$ExportSprites.export_project()
|
||||||
6: # Export as
|
6: # Export as
|
||||||
$ExportSprites.popup_centered()
|
$ExportSprites.popup_centered()
|
||||||
Global.can_draw = false
|
Global.can_draw = false
|
||||||
|
@ -535,93 +518,9 @@ func clear_canvases() -> void:
|
||||||
child.queue_free()
|
child.queue_free()
|
||||||
Global.canvases.clear()
|
Global.canvases.clear()
|
||||||
current_save_path = ""
|
current_save_path = ""
|
||||||
current_export_path = ""
|
$ExportSprites.current_export_path = ""
|
||||||
file_menu.set_item_text(5, "Export PNG...")
|
file_menu.set_item_text(5, "Export PNG...")
|
||||||
|
|
||||||
func _on_ExportSprites_file_selected(path : String) -> void:
|
|
||||||
current_export_path = path
|
|
||||||
file_menu.set_item_text(5, tr("Export") + " %s" % path.get_file())
|
|
||||||
export_project()
|
|
||||||
|
|
||||||
func export_project() -> void:
|
|
||||||
if export_all_frames.pressed:
|
|
||||||
if !export_as_single_file.pressed:
|
|
||||||
var i := 1
|
|
||||||
for canvas in Global.canvases:
|
|
||||||
var path := "%s_%s" % [current_export_path, str(i)]
|
|
||||||
path = path.replace(".png", "")
|
|
||||||
path = "%s.png" % path
|
|
||||||
save_sprite(canvas, path)
|
|
||||||
i += 1
|
|
||||||
else:
|
|
||||||
save_spritesheet()
|
|
||||||
else:
|
|
||||||
save_sprite(Global.canvas, current_export_path)
|
|
||||||
Global.notification_label("File exported")
|
|
||||||
|
|
||||||
func save_sprite(canvas : Canvas, path : String) -> void:
|
|
||||||
var whole_image := Image.new()
|
|
||||||
whole_image.create(canvas.size.x, canvas.size.y, false, Image.FORMAT_RGBA8)
|
|
||||||
whole_image.lock()
|
|
||||||
for layer in canvas.layers:
|
|
||||||
var img : Image = layer[0]
|
|
||||||
img.lock()
|
|
||||||
if layer[4] < 1: # If we have layer transparency
|
|
||||||
for xx in img.get_size().x:
|
|
||||||
for yy in img.get_size().y:
|
|
||||||
var pixel_color := img.get_pixel(xx, yy)
|
|
||||||
var alpha : float = pixel_color.a * layer[4]
|
|
||||||
img.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
|
||||||
|
|
||||||
canvas.blend_rect(whole_image, img, Rect2(canvas.position, canvas.size), Vector2.ZERO)
|
|
||||||
layer[0].lock()
|
|
||||||
var err = whole_image.save_png(path)
|
|
||||||
if err != OK:
|
|
||||||
OS.alert("Can't save file")
|
|
||||||
|
|
||||||
func save_spritesheet() -> void:
|
|
||||||
var width
|
|
||||||
var height
|
|
||||||
if export_vertical_spritesheet.pressed: #Vertical spritesheet
|
|
||||||
width = Global.canvas.size.x
|
|
||||||
height = 0
|
|
||||||
for canvas in Global.canvases:
|
|
||||||
height += canvas.size.y
|
|
||||||
if canvas.size.x > width:
|
|
||||||
width = canvas.size.x
|
|
||||||
else: #Horizontal spritesheet
|
|
||||||
width = 0
|
|
||||||
height = Global.canvas.size.y
|
|
||||||
for canvas in Global.canvases:
|
|
||||||
width += canvas.size.x
|
|
||||||
if canvas.size.y > height:
|
|
||||||
height = canvas.size.y
|
|
||||||
var whole_image := Image.new()
|
|
||||||
whole_image.create(width, height, false, Image.FORMAT_RGBA8)
|
|
||||||
whole_image.lock()
|
|
||||||
var dst := Vector2.ZERO
|
|
||||||
for canvas in Global.canvases:
|
|
||||||
for layer in canvas.layers:
|
|
||||||
var img : Image = layer[0]
|
|
||||||
img.lock()
|
|
||||||
if layer[4] < 1: # If we have layer transparency
|
|
||||||
for xx in img.get_size().x:
|
|
||||||
for yy in img.get_size().y:
|
|
||||||
var pixel_color := img.get_pixel(xx, yy)
|
|
||||||
var alpha : float = pixel_color.a * layer[4]
|
|
||||||
img.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
|
||||||
|
|
||||||
canvas.blend_rect(whole_image, img, Rect2(canvas.position, canvas.size), dst)
|
|
||||||
layer[0].lock()
|
|
||||||
|
|
||||||
if export_vertical_spritesheet.pressed:
|
|
||||||
dst += Vector2(0, canvas.size.y)
|
|
||||||
else:
|
|
||||||
dst += Vector2(canvas.size.x, 0)
|
|
||||||
|
|
||||||
var err = whole_image.save_png(current_export_path)
|
|
||||||
if err != OK:
|
|
||||||
OS.alert("Can't save file")
|
|
||||||
|
|
||||||
func _on_ScaleImage_confirmed() -> void:
|
func _on_ScaleImage_confirmed() -> void:
|
||||||
var width : int = $ScaleImage/VBoxContainer/OptionsContainer/WidthValue.value
|
var width : int = $ScaleImage/VBoxContainer/OptionsContainer/WidthValue.value
|
||||||
|
|
Loading…
Add table
Reference in a new issue