1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Removed ImportSprites dialog

This commit is contained in:
OverloadedOrama 2020-06-19 23:07:56 +03:00
parent 1acb1f6b7f
commit 597fdbc0c0
2 changed files with 0 additions and 195 deletions

View file

@ -1,119 +0,0 @@
extends FileDialog
var new_frame := false
var import_spritesheet := false
var spritesheet_horizontal := 1
var spritesheet_vertical := 1
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_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
var project := Global.current_project
var first_path : String = paths[0]
var i := 0
if new_frame:
i = project.frames.size()
for path in paths:
var image := Image.new()
var err := image.load(path)
if err != OK: # An error occured
var file_name : String = path.get_file()
Global.error_dialog.set_text(tr("Can't load file '%s'.\nError code: %s") % [file_name, str(err)])
Global.error_dialog.popup_centered()
Global.dialog_open(true)
continue
if !new_frame: # If we're not adding a new frame, delete the previous
project = Project.new([], path.get_file())
project.layers.append(Layer.new())
Global.projects.append(project)
if !import_spritesheet:
if !new_frame:
project.size = image.get_size()
var frame := Frame.new()
image.convert(Image.FORMAT_RGBA8)
image.lock()
frame.cels.append(Cel.new(image, 1))
for _i in range(1, project.layers.size()):
var empty_sprite := Image.new()
empty_sprite.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)
empty_sprite.fill(Color(0, 0, 0, 0))
empty_sprite.lock()
frame.cels.append(Cel.new(empty_sprite, 1))
project.frames.append(frame)
i += 1
else:
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 frame := Frame.new()
var cropped_image := Image.new()
cropped_image = image.get_rect(Rect2(frame_width * xx, frame_height * yy, frame_width, frame_height))
if !new_frame:
project.size = cropped_image.get_size()
cropped_image.convert(Image.FORMAT_RGBA8)
cropped_image.lock()
frame.cels.append(Cel.new(cropped_image, 1))
for _i in range(1, project.layers.size()):
var empty_sprite := Image.new()
empty_sprite.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)
empty_sprite.fill(Color(0, 0, 0, 0))
empty_sprite.lock()
frame.cels.append(Cel.new(empty_sprite, 1))
project.frames.append(frame)
i += 1
Global.tabs.current_tab = Global.tabs.get_tab_count() - 1
Global.canvas.camera_zoom()
if new_frame:
project.frames = project.frames # Just to call Global.frames_changed
project.current_frame = i - 1
Global.window_title = first_path.get_file() + " (" + tr("imported") + ") - Pixelorama " + Global.current_version
if project.has_changed:
Global.window_title = Global.window_title + "(*)"
var file_name := first_path.get_basename().get_file()
var directory_path := first_path.get_basename().replace(file_name, "")
Global.export_dialog.directory_path = directory_path
Global.export_dialog.file_name = file_name

View file

@ -1,76 +0,0 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UI/Dialogs/ImportSprites.gd" type="Script" id=1]
[node name="ImportSprites" type="FileDialog"]
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"
current_path = "C:/Users/"
script = ExtResource( 1 )
[node name="HBoxContainer2" type="HBoxContainer" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 507.0
margin_bottom = 312.0
[node name="ImportAsNewFrame" type="CheckBox" parent="HBoxContainer2"]
margin_right = 161.0
margin_bottom = 304.0
mouse_default_cursor_shape = 2
disabled = true
text = "Import as new frame"
[node name="ImportSpritesheet" type="CheckBox" parent="HBoxContainer2"]
margin_left = 165.0
margin_right = 343.0
margin_bottom = 304.0
mouse_default_cursor_shape = 2
text = "Import as a spritesheet"
[node name="Spritesheet" type="HBoxContainer" parent="."]
visible = false
margin_left = 8.0
margin_top = 8.0
margin_right = 507.0
margin_bottom = 312.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
mouse_default_cursor_shape = 2
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
mouse_default_cursor_shape = 2
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"]