Cleanups to the export dialog.

This commit is contained in:
Relintai 2020-11-29 22:43:32 +01:00
parent ab4be495b6
commit 3d40d58205
3 changed files with 32 additions and 431 deletions

View File

@ -3,9 +3,6 @@ extends Node
var DrawGD : Node = null
enum ExportTab { FRAME = 0, SPRITESHEET = 1, ANIMATION = 2 }
var current_tab : int = ExportTab.FRAME
# Frame options
var frame_number := 0
@ -50,13 +47,7 @@ var export_progress := 0.0
func external_export() -> void:
match current_tab:
ExportTab.FRAME:
process_frame()
ExportTab.SPRITESHEET:
process_spritesheet()
ExportTab.ANIMATION:
process_animation()
process_frame()
export_processed_images(true, DrawGD.export_dialog)
@ -68,67 +59,6 @@ func process_frame() -> void:
blend_layers(image, frame)
processed_images.append(image)
func process_spritesheet() -> void:
processed_images.clear()
# Range of frames determined by tags
var frames := []
if frame_current_tag > 0:
var frame_start = DrawGD.current_project.animation_tags[frame_current_tag - 1].from
var frame_end = DrawGD.current_project.animation_tags[frame_current_tag - 1].to
frames = DrawGD.current_project.frames.slice(frame_start-1, frame_end-1, 1, true)
else:
frames = DrawGD.current_project.frames
# Then store the size of frames for other functions
number_of_frames = frames.size()
# If rows mode selected calculate columns count and vice versa
var spritesheet_columns = lines_count if orientation == Orientation.ROWS else frames_divided_by_spritesheet_lines()
var spritesheet_rows = lines_count if orientation == Orientation.COLUMNS else frames_divided_by_spritesheet_lines()
var width = DrawGD.current_project.size.x * spritesheet_columns
var height = DrawGD.current_project.size.y * spritesheet_rows
var whole_image := Image.new()
whole_image.create(width, height, false, Image.FORMAT_RGBA8)
var origin := Vector2.ZERO
var hh := 0
var vv := 0
for frame in frames:
if orientation == Orientation.ROWS:
if vv < spritesheet_columns:
origin.x = DrawGD.current_project.size.x * vv
vv += 1
else:
hh += 1
origin.x = 0
vv = 1
origin.y = DrawGD.current_project.size.y * hh
else:
if hh < spritesheet_rows:
origin.y = DrawGD.current_project.size.y * hh
hh += 1
else:
vv += 1
origin.y = 0
hh = 1
origin.x = DrawGD.current_project.size.x * vv
blend_layers(whole_image, frame, origin)
processed_images.append(whole_image)
func process_animation() -> void:
processed_images.clear()
for frame in DrawGD.current_project.frames:
var image := Image.new()
image.create(DrawGD.current_project.size.x, DrawGD.current_project.size.y, false, Image.FORMAT_RGBA8)
blend_layers(image, frame)
processed_images.append(image)
func export_processed_images(ignore_overwrites: bool, export_dialog: AcceptDialog ) -> bool:
# Stop export if directory path or file name are not valid
var dir = Directory.new()
@ -140,7 +70,7 @@ func export_processed_images(ignore_overwrites: bool, export_dialog: AcceptDialo
var export_paths = []
for i in range(processed_images.size()):
stop_export = false
var multiple_files := true if (current_tab == ExportTab.ANIMATION and animation_type == AnimationType.MULTIPLE_FILES) else false
var multiple_files := false
var export_path = create_export_path(multiple_files, i + 1)
# If user want to create new directory for each animation tag then check if directories exist and create them if not
if multiple_files and new_dir_for_each_frame_tag:
@ -161,28 +91,23 @@ func export_processed_images(ignore_overwrites: bool, export_dialog: AcceptDialo
# User decided to stop export
return
export_paths.append(export_path)
# Only get one export path if single file animated image is exported
if current_tab == ExportTab.ANIMATION and animation_type == AnimationType.ANIMATED:
break
# if current_tab == ExportTab.ANIMATION and animation_type == AnimationType.ANIMATED:
# break
# Scale images that are to export
scale_processed_images()
if current_tab == ExportTab.ANIMATION and animation_type == AnimationType.ANIMATED:
pass
else:
for i in range(processed_images.size()):
var err = processed_images[i].save_png(export_paths[i])
if err != OK:
OS.alert("Can't save file. Error code: %s" % err)
for i in range(processed_images.size()):
var err = processed_images[i].save_png(export_paths[i])
if err != OK:
OS.alert("Can't save file. Error code: %s" % err)
# Store settings for quick export and when the dialog is opened again
was_exported = true
DrawGD.file_menu.get_popup().set_item_text(5, tr("Export") + " %s" % (file_name + file_format_string(file_format)))
# Only show when not exporting gif - gif export finishes in thread
if not (current_tab == ExportTab.ANIMATION and animation_type == AnimationType.ANIMATED):
DrawGD.notification_label("File(s) exported")
return true
func increase_export_progress(export_dialog: Node) -> void:

View File

@ -10,7 +10,6 @@ signal resume_export_function()
var animated_preview_current_frame := 0
var animated_preview_frames = []
onready var tabs = $VBoxContainer/Tabs
onready var popups = $Popups
onready var file_exists_alert_popup = $Popups/FileExistsAlert
onready var path_validation_alert_popup = $Popups/PathValidationAlert
@ -20,22 +19,6 @@ onready var export_progress_bar = $Popups/ExportProgressBar/MarginContainer/Prog
onready var animation_options_multiple_animations_directories = $VBoxContainer/AnimationOptions/MultipleAnimationsDirectories
onready var previews = $VBoxContainer/PreviewPanel/PreviewScroll/Previews
onready var frame_timer = $FrameTimer
onready var frame_options = $VBoxContainer/FrameOptions
onready var frame_options_frame_number = $VBoxContainer/FrameOptions/FrameNumber/FrameNumber
onready var spritesheet_options = $VBoxContainer/SpritesheetOptions
onready var spritesheet_options_frames = $VBoxContainer/SpritesheetOptions/Frames/Frames
onready var spritesheet_options_orientation = $VBoxContainer/SpritesheetOptions/Orientation/Orientation
onready var spritesheet_options_lines_count = $VBoxContainer/SpritesheetOptions/Orientation/LinesCount
onready var spritesheet_options_lines_count_label = $VBoxContainer/SpritesheetOptions/Orientation/LinesCountLabel
onready var animation_options = $VBoxContainer/AnimationOptions
onready var animation_options_animation_type = $VBoxContainer/AnimationOptions/AnimationType
onready var animation_options_animation_options = $VBoxContainer/AnimationOptions/AnimatedOptions
onready var animation_options_direction = $VBoxContainer/AnimationOptions/AnimatedOptions/Direction
onready var options_resize = $VBoxContainer/Options/Resize
onready var options_interpolation = $VBoxContainer/Options/Interpolation
@ -46,10 +29,17 @@ onready var file_file_format = $VBoxContainer/File/FileFormat
var DrawGD : Node = null
func _ready() -> void:
tabs.add_tab("Frame")
tabs.add_tab("Spritesheet")
tabs.add_tab("Animation")
func _enter_tree() -> void:
var n : Node = get_parent()
while n:
if n.name == "DrawGDSingleton":
DrawGD = n
break
n = n.get_parent()
export_progress_popup = get_node("Popups/ExportProgressBar")
file_exists_alert_popup = get_node("Popups/FileExistsAlert")
if OS.get_name() == "Windows":
add_button("Cancel", true, "cancel")
file_exists_alert_popup.add_button("Cancel Export", true, "cancel")
@ -62,46 +52,10 @@ func _ready() -> void:
func show_tab() -> void:
frame_options.hide()
spritesheet_options.hide()
animation_options.hide()
Export.file_format = Export.FileFormat.PNG
file_file_format.selected = Export.FileFormat.PNG
match Export.current_tab:
Export.ExportTab.FRAME:
Export.file_format = Export.FileFormat.PNG
file_file_format.selected = Export.FileFormat.PNG
frame_timer.stop()
if not Export.was_exported:
Export.frame_number = DrawGD.current_project.current_frame + 1
frame_options_frame_number.max_value = DrawGD.current_project.frames.size() + 1
var prev_frame_number = frame_options_frame_number.value
frame_options_frame_number.value = Export.frame_number
if prev_frame_number == Export.frame_number:
Export.process_frame()
frame_options.show()
Export.ExportTab.SPRITESHEET:
create_frame_tag_list()
Export.file_format = Export.FileFormat.PNG
if not Export.was_exported:
Export.orientation = Export.Orientation.ROWS
Export.lines_count = int(ceil(sqrt(Export.number_of_frames)))
Export.process_spritesheet()
file_file_format.selected = Export.FileFormat.PNG
spritesheet_options_frames.select(Export.frame_current_tag)
frame_timer.stop()
spritesheet_options_orientation.selected = Export.orientation
spritesheet_options_lines_count.max_value = Export.number_of_frames
spritesheet_options_lines_count.value = Export.lines_count
spritesheet_options_lines_count_label.text = "Columns:"
spritesheet_options.show()
Export.ExportTab.ANIMATION:
set_file_format_selector()
Export.process_animation()
animation_options_animation_type.selected = Export.animation_type
animation_options_direction.selected = Export.direction
animation_options.show()
set_preview()
tabs.current_tab = Export.current_tab
func set_preview() -> void:
@ -153,7 +107,6 @@ func add_animated_preview() -> void:
container.add_child(preview)
previews.add_child(container)
frame_timer.start()
func create_preview_container() -> VBoxContainer:
@ -177,34 +130,6 @@ func remove_previews() -> void:
for child in previews.get_children():
child.free()
func set_file_format_selector() -> void:
animation_options_multiple_animations_directories.visible = false
match Export.animation_type:
Export.AnimationType.MULTIPLE_FILES:
Export.file_format = Export.FileFormat.PNG
file_file_format.selected = Export.FileFormat.PNG
frame_timer.stop()
animation_options_animation_options.hide()
animation_options_multiple_animations_directories.pressed = Export.new_dir_for_each_frame_tag
animation_options_multiple_animations_directories.visible = true
Export.AnimationType.ANIMATED:
Export.file_format = Export.FileFormat.GIF
file_file_format.selected = Export.FileFormat.GIF
frame_timer.wait_time = DrawGD.animation_timer.wait_time
animation_options_animation_options.show()
func create_frame_tag_list() -> void:
# Clear existing tag list from entry if it exists
spritesheet_options_frames.clear()
spritesheet_options_frames.add_item("All Frames", 0) # Re-add removed 'All Frames' item
# Repopulate list with current tag list
for item in DrawGD.current_project.animation_tags:
spritesheet_options_frames.add_item(item.name)
func open_path_validation_alert_popup() -> void:
path_validation_alert_popup.popup_centered()
@ -243,8 +168,8 @@ func _on_ExportDialog_about_to_show() -> void:
file_file_format.selected = Export.file_format
show_tab()
for child in popups.get_children(): # Set the theme for the popups
child.theme = DrawGD.control.theme
# for child in popups.get_children(): # Set the theme for the popups
# child.theme = DrawGD.control.theme
Export.file_exists_alert = tr("File %s already exists. Overwrite?") # Update translation
@ -263,41 +188,6 @@ func _on_Frame_value_changed(value: float) -> void:
set_preview()
func _on_Orientation_item_selected(id : int) -> void:
Export.orientation = id
if Export.orientation == Export.Orientation.ROWS:
spritesheet_options_lines_count_label.text = "Columns:"
else:
spritesheet_options_lines_count_label.text = "Rows:"
spritesheet_options_lines_count.value = Export.frames_divided_by_spritesheet_lines()
Export.process_spritesheet()
set_preview()
func _on_LinesCount_value_changed(value : float) -> void:
Export.lines_count = value
Export.process_spritesheet()
set_preview()
func _on_AnimationType_item_selected(id : int) -> void:
Export.animation_type = id
set_file_format_selector()
set_preview()
func _on_Direction_item_selected(id : int) -> void:
Export.direction = id
match id:
Export.AnimationDirection.FORWARD:
animated_preview_current_frame = 0
Export.AnimationDirection.BACKWARDS:
animated_preview_current_frame = Export.processed_images.size() - 1
Export.AnimationDirection.PING_PONG:
animated_preview_current_frame = 0
pingpong_direction = Export.AnimationDirection.FORWARD
func _on_Resize_value_changed(value : float) -> void:
Export.resize = value
@ -357,54 +247,5 @@ func _on_FileExistsAlert_custom_action(action : String) -> void:
file_exists_alert_popup.hide()
var pingpong_direction = Export.AnimationDirection.FORWARD
func _on_FrameTimer_timeout() -> void:
$VBoxContainer/PreviewPanel/PreviewScroll/Previews/PreviewContainer/Preview.texture = animated_preview_frames[animated_preview_current_frame]
match Export.direction:
Export.AnimationDirection.FORWARD:
if animated_preview_current_frame == animated_preview_frames.size() - 1:
animated_preview_current_frame = 0
else:
animated_preview_current_frame += 1
Export.AnimationDirection.BACKWARDS:
if animated_preview_current_frame == 0:
animated_preview_current_frame = Export.processed_images.size() - 1
else:
animated_preview_current_frame -= 1
Export.AnimationDirection.PING_PONG:
match pingpong_direction:
Export.AnimationDirection.FORWARD:
if animated_preview_current_frame == animated_preview_frames.size() - 1:
pingpong_direction = Export.AnimationDirection.BACKWARDS
animated_preview_current_frame -= 1
if animated_preview_current_frame <= 0:
animated_preview_current_frame = 0
else:
animated_preview_current_frame += 1
Export.AnimationDirection.BACKWARDS:
if animated_preview_current_frame == 0:
animated_preview_current_frame += 1
if animated_preview_current_frame >= animated_preview_frames.size() - 1:
animated_preview_current_frame = 0
pingpong_direction = Export.AnimationDirection.FORWARD
else:
animated_preview_current_frame -= 1
func _on_ExportDialog_popup_hide() -> void:
frame_timer.stop()
func _on_MultipleAnimationsDirectories_toggled(button_pressed : bool) -> void:
Export.new_dir_for_each_frame_tag = button_pressed
func _on_Frames_item_selected(id : int) -> void:
Export.frame_current_tag = id
Export.process_spritesheet()
set_preview()
spritesheet_options_lines_count.max_value = Export.number_of_frames
spritesheet_options_lines_count.value = Export.lines_count

View File

@ -3,8 +3,8 @@
[ext_resource path="res://addons/draw_gd/src/UI/Dialogs/ExportDialog.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
[node name="ExportDialog" type="AcceptDialog"]
visible = true
margin_right = 532.0
margin_bottom = 530.0
rect_min_size = Vector2( 456, 530 )
@ -27,26 +27,15 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Tabs" type="Tabs" parent="VBoxContainer"]
margin_right = 516.0
margin_bottom = 24.0
size_flags_vertical = 0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
margin_top = 28.0
margin_right = 516.0
margin_bottom = 32.0
[node name="PreviewLabel" type="Label" parent="VBoxContainer"]
margin_top = 36.0
margin_right = 516.0
margin_bottom = 50.0
margin_bottom = 14.0
text = "Preview:"
[node name="PreviewPanel" type="Panel" parent="VBoxContainer"]
margin_top = 54.0
margin_top = 18.0
margin_right = 516.0
margin_bottom = 278.0
margin_bottom = 386.0
size_flags_horizontal = 3
size_flags_vertical = 3
@ -67,158 +56,11 @@ __meta__ = {
[node name="Previews" type="GridContainer" parent="VBoxContainer/PreviewPanel/PreviewScroll"]
margin_right = 516.0
margin_bottom = 224.0
margin_bottom = 368.0
size_flags_horizontal = 3
size_flags_vertical = 3
columns = 3
[node name="FrameOptions" type="VBoxContainer" parent="VBoxContainer"]
visible = false
margin_top = 278.0
margin_right = 516.0
margin_bottom = 302.0
[node name="FrameNumber" type="HBoxContainer" parent="VBoxContainer/FrameOptions"]
margin_right = 516.0
margin_bottom = 24.0
[node name="FrameNumberLabel" type="Label" parent="VBoxContainer/FrameOptions/FrameNumber"]
margin_top = 5.0
margin_right = 44.0
margin_bottom = 19.0
text = "Frame:"
[node name="FrameNumber" type="SpinBox" parent="VBoxContainer/FrameOptions/FrameNumber"]
margin_left = 48.0
margin_right = 516.0
margin_bottom = 24.0
rect_min_size = Vector2( 100, 0 )
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
min_value = 1.0
page = 1.0
value = 1.0
rounded = true
align = 2
[node name="SpritesheetOptions" type="VBoxContainer" parent="VBoxContainer"]
margin_top = 282.0
margin_right = 516.0
margin_bottom = 330.0
[node name="Frames" type="HBoxContainer" parent="VBoxContainer/SpritesheetOptions"]
margin_right = 516.0
margin_bottom = 20.0
[node name="FramesLabel" type="Label" parent="VBoxContainer/SpritesheetOptions/Frames"]
margin_top = 3.0
margin_right = 51.0
margin_bottom = 17.0
text = "Frames:"
[node name="Frames" type="OptionButton" parent="VBoxContainer/SpritesheetOptions/Frames"]
margin_left = 55.0
margin_right = 516.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
text = "All Frames"
items = [ "All Frames", null, false, 0, null ]
selected = 0
[node name="Orientation" type="HBoxContainer" parent="VBoxContainer/SpritesheetOptions"]
margin_top = 24.0
margin_right = 516.0
margin_bottom = 48.0
alignment = 1
[node name="OrientationLabel" type="Label" parent="VBoxContainer/SpritesheetOptions/Orientation"]
margin_top = 5.0
margin_right = 77.0
margin_bottom = 19.0
text = "Orientation:"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Orientation" type="OptionButton" parent="VBoxContainer/SpritesheetOptions/Orientation"]
margin_left = 81.0
margin_right = 264.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
text = "Rows"
items = [ "Rows", null, false, 0, null, "Columns", null, false, 1, null ]
selected = 0
[node name="LinesCountLabel" type="Label" parent="VBoxContainer/SpritesheetOptions/Orientation"]
margin_left = 268.0
margin_top = 5.0
margin_right = 328.0
margin_bottom = 19.0
text = "Columns:"
[node name="LinesCount" type="SpinBox" parent="VBoxContainer/SpritesheetOptions/Orientation"]
margin_left = 332.0
margin_right = 516.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
min_value = 1.0
max_value = 1000.0
value = 1.0
align = 2
[node name="AnimationOptions" type="VBoxContainer" parent="VBoxContainer"]
margin_top = 334.0
margin_right = 516.0
margin_bottom = 386.0
[node name="AnimationType" type="OptionButton" parent="VBoxContainer/AnimationOptions"]
margin_right = 516.0
margin_bottom = 24.0
rect_min_size = Vector2( 0, 24 )
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
text = "All frames as multiple files"
items = [ "All frames as multiple files", null, false, 0, null, "All frames as a single file animation", null, false, 1, null ]
selected = 0
[node name="MultipleAnimationsDirectories" type="CheckBox" parent="VBoxContainer/AnimationOptions"]
visible = false
margin_top = 28.0
margin_right = 516.0
margin_bottom = 52.0
hint_tooltip = "Creates multiple files but every file is stored in different directory that corresponds to its frame tag"
mouse_default_cursor_shape = 2
text = "Create new directory for each frame tag"
[node name="AnimatedOptions" type="HBoxContainer" parent="VBoxContainer/AnimationOptions"]
margin_top = 28.0
margin_right = 516.0
margin_bottom = 52.0
rect_min_size = Vector2( 0, 24 )
[node name="DirectionLabel" type="Label" parent="VBoxContainer/AnimationOptions/AnimatedOptions"]
margin_top = 5.0
margin_right = 63.0
margin_bottom = 19.0
text = "Direction:"
[node name="Direction" type="OptionButton" parent="VBoxContainer/AnimationOptions/AnimatedOptions"]
margin_left = 67.0
margin_right = 516.0
margin_bottom = 24.0
rect_min_size = Vector2( 100, 0 )
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
text = "Forward"
items = [ "Forward", null, false, 0, null, "Backwards", null, false, 1, null, "Ping-Pong", null, false, 2, null ]
selected = 0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HSeparator2" type="HSeparator" parent="VBoxContainer"]
margin_top = 390.0
margin_right = 516.0
@ -346,8 +188,8 @@ window_title = "Open a Directory"
resizable = true
mode = 2
access = 2
current_dir = "/Users"
current_path = "/Users/"
current_dir = "/home/relintai/Projects/draw_gd"
current_path = "/home/relintai/Projects/draw_gd/"
[node name="PathValidationAlert" type="AcceptDialog" parent="Popups"]
margin_left = 8.0
@ -412,18 +254,11 @@ __meta__ = {
__meta__ = {
"_editor_description_": "Timer to advance animation frames in animation preview."
}
[connection signal="about_to_show" from="." to="." method="_on_ExportDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_ExportDialog_confirmed"]
[connection signal="custom_action" from="." to="." method="_on_ExportDialog_custom_action"]
[connection signal="popup_hide" from="." to="." method="_on_ExportDialog_popup_hide"]
[connection signal="tab_clicked" from="VBoxContainer/Tabs" to="." method="_on_Tabs_tab_clicked"]
[connection signal="value_changed" from="VBoxContainer/FrameOptions/FrameNumber/FrameNumber" to="." method="_on_Frame_value_changed"]
[connection signal="item_selected" from="VBoxContainer/SpritesheetOptions/Frames/Frames" to="." method="_on_Frames_item_selected"]
[connection signal="item_selected" from="VBoxContainer/SpritesheetOptions/Orientation/Orientation" to="." method="_on_Orientation_item_selected"]
[connection signal="value_changed" from="VBoxContainer/SpritesheetOptions/Orientation/LinesCount" to="." method="_on_LinesCount_value_changed"]
[connection signal="item_selected" from="VBoxContainer/AnimationOptions/AnimationType" to="." method="_on_AnimationType_item_selected"]
[connection signal="toggled" from="VBoxContainer/AnimationOptions/MultipleAnimationsDirectories" to="." method="_on_MultipleAnimationsDirectories_toggled"]
[connection signal="item_selected" from="VBoxContainer/AnimationOptions/AnimatedOptions/Direction" to="." method="_on_Direction_item_selected"]
[connection signal="value_changed" from="VBoxContainer/Options/Resize" to="." method="_on_Resize_value_changed"]
[connection signal="item_selected" from="VBoxContainer/Options/Interpolation" to="." method="_on_Interpolation_item_selected"]
[connection signal="text_changed" from="VBoxContainer/Path/PathLineEdit" to="." method="_on_PathLineEdit_text_changed"]