1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Importing spritesheets is possible again

This commit is contained in:
OverloadedOrama 2020-06-16 17:59:56 +03:00
parent 181230cb3f
commit 13613703fc
5 changed files with 156 additions and 24 deletions

View file

@ -64,12 +64,6 @@ msgstr ""
msgid "Import" msgid "Import"
msgstr "" msgstr ""
msgid "Import..."
msgstr ""
msgid "Import PNG..."
msgstr ""
msgid "Export" msgid "Export"
msgstr "" msgstr ""
@ -145,10 +139,28 @@ msgstr ""
msgid "Open File(s)" msgid "Open File(s)"
msgstr "" msgstr ""
msgid "Import as new frame" msgid "Import as:"
msgstr "" msgstr ""
msgid "Import as a spritesheet" msgid "New tab"
msgstr ""
msgid "Spritesheet (new tab)"
msgstr ""
msgid "New frame"
msgstr ""
msgid "New layer"
msgstr ""
msgid "New palette"
msgstr ""
msgid "Horizontal frames:"
msgstr ""
msgid "Vertical frames:"
msgstr "" msgstr ""
msgid "Save Sprite as .pxo" msgid "Save Sprite as .pxo"

View file

@ -1,5 +1,6 @@
extends Node extends Node
var current_save_paths := [] # Array of strings var current_save_paths := [] # Array of strings
# Stores a filename of a backup file in user:// until user saves manually # Stores a filename of a backup file in user:// until user saves manually
var backup_save_paths := [] # Array of strings var backup_save_paths := [] # Array of strings
@ -303,10 +304,8 @@ func save_pxo_file(path : String, autosave : bool, project : Project = Global.cu
file.close() file.close()
func open_image_file(path : String, image : Image) -> void: func open_image_as_new_tab(path : String, image : Image) -> void:
var project := Global.current_project var project = Project.new([], path.get_file())
project = Project.new([], path.get_file())
project.layers.append(Layer.new()) project.layers.append(Layer.new())
Global.projects.append(project) Global.projects.append(project)
project.size = image.get_size() project.size = image.get_size()
@ -317,6 +316,40 @@ func open_image_file(path : String, image : Image) -> void:
frame.cels.append(Cel.new(image, 1)) frame.cels.append(Cel.new(image, 1))
project.frames.append(frame) project.frames.append(frame)
set_new_tab(project, path)
func open_image_as_spritesheet(path : String, image : Image, horizontal : int, vertical : int) -> void:
var project = Project.new([], path.get_file())
project.layers.append(Layer.new())
Global.projects.append(project)
horizontal = min(horizontal, image.get_size().x)
vertical = min(vertical, image.get_size().y)
var frame_width := image.get_size().x / horizontal
var frame_height := image.get_size().y / vertical
for yy in range(vertical):
for xx in range(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))
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)
set_new_tab(project, path)
func set_new_tab(project : Project, path : String) -> void:
Global.tabs.current_tab = Global.tabs.get_tab_count() - 1 Global.tabs.current_tab = Global.tabs.get_tab_count() - 1
Global.canvas.camera_zoom() Global.canvas.camera_zoom()

View file

@ -51,12 +51,8 @@ __meta__ = {
[node name="CreateNewImage" parent="." instance=ExtResource( 28 )] [node name="CreateNewImage" parent="." instance=ExtResource( 28 )]
[node name="OpenSprite" parent="." instance=ExtResource( 12 )] [node name="OpenSprite" parent="." instance=ExtResource( 12 )]
current_dir = "/Users"
current_path = "/Users/"
[node name="SaveSprite" parent="." instance=ExtResource( 11 )] [node name="SaveSprite" parent="." instance=ExtResource( 11 )]
current_dir = "/Users"
current_path = "/Users/"
[node name="ExportDialog" parent="." instance=ExtResource( 39 )] [node name="ExportDialog" parent="." instance=ExtResource( 39 )]

View file

@ -1,14 +1,21 @@
extends ConfirmationDialog extends ConfirmationDialog
enum ImageImportOptions {NEW_TAB, SPRITESHEET, NEW_FRAME, NEW_LAYER, PALETTE}
var path : String var path : String
var image : Image var image : Image
var current_import_option : int = ImageImportOptions.NEW_TAB
var spritesheet_horizontal := 1
var spritesheet_vertical := 1
onready var spritesheet_options = $VBoxContainer/HBoxContainer/SpritesheetOptions
func _on_PreviewDialog_about_to_show() -> void: func _on_PreviewDialog_about_to_show() -> void:
var img_texture := ImageTexture.new() var img_texture := ImageTexture.new()
img_texture.create_from_image(image) img_texture.create_from_image(image)
get_node("CenterContainer/TextureRect").texture = img_texture get_node("VBoxContainer/CenterContainer/TextureRect").texture = img_texture
func _on_PreviewDialog_popup_hide() -> void: func _on_PreviewDialog_popup_hide() -> void:
@ -16,4 +23,23 @@ func _on_PreviewDialog_popup_hide() -> void:
func _on_PreviewDialog_confirmed() -> void: func _on_PreviewDialog_confirmed() -> void:
OpenSave.open_image_file(path, image) if current_import_option == ImageImportOptions.NEW_TAB:
OpenSave.open_image_as_new_tab(path, image)
elif current_import_option == ImageImportOptions.SPRITESHEET:
OpenSave.open_image_as_spritesheet(path, image, spritesheet_horizontal, spritesheet_vertical)
func _on_ImportOption_item_selected(id : int) -> void:
current_import_option = id
if id == ImageImportOptions.SPRITESHEET:
spritesheet_options.visible = true
else:
spritesheet_options.visible = false
func _on_HorizontalFrames_value_changed(value) -> void:
spritesheet_horizontal = value
func _on_VerticalFrames_value_changed(value) -> void:
spritesheet_vertical = value

View file

@ -5,7 +5,7 @@
[node name="PreviewDialog" type="ConfirmationDialog"] [node name="PreviewDialog" type="ConfirmationDialog"]
margin_right = 200.0 margin_right = 200.0
margin_bottom = 70.0 margin_bottom = 70.0
rect_min_size = Vector2( 400, 70 ) rect_min_size = Vector2( 550, 70 )
popup_exclusive = true popup_exclusive = true
resizable = true resizable = true
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -13,19 +13,27 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="CenterContainer" type="CenterContainer" parent="."] [node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0 margin_left = 8.0
margin_top = 8.0 margin_top = 8.0
margin_right = -8.0 margin_right = -8.0
margin_bottom = 308.0 margin_bottom = -36.0
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="TextureRect" type="TextureRect" parent="CenterContainer"] [node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"]
margin_left = 42.0 margin_right = 534.0
margin_right = 342.0 margin_bottom = 300.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/CenterContainer"]
margin_left = 117.0
margin_right = 417.0
margin_bottom = 300.0 margin_bottom = 300.0
rect_min_size = Vector2( 300, 300 ) rect_min_size = Vector2( 300, 300 )
expand = true expand = true
@ -33,6 +41,63 @@ stretch_mode = 6
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 304.0
margin_right = 534.0
margin_bottom = 324.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
margin_top = 3.0
margin_right = 66.0
margin_bottom = 17.0
text = "Import as:"
[node name="ImportOption" type="OptionButton" parent="VBoxContainer/HBoxContainer"]
margin_left = 70.0
margin_right = 151.0
margin_bottom = 20.0
text = "New tab"
items = [ "New tab", null, false, 0, null, "Spritesheet (new tab)", null, false, 1, null, "New frame", null, true, 2, null, "New layer", null, true, 3, null, "New palette", null, true, 4, null ]
selected = 0
[node name="SpritesheetOptions" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"]
visible = false
margin_left = 155.0
margin_right = 533.0
margin_bottom = 24.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/SpritesheetOptions"]
margin_top = 5.0
margin_right = 118.0
margin_bottom = 19.0
text = "Horizontal frames:"
[node name="HorizontalFrames" type="SpinBox" parent="VBoxContainer/HBoxContainer/SpritesheetOptions"]
margin_left = 122.0
margin_right = 196.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 1.0
value = 1.0
[node name="Label2" type="Label" parent="VBoxContainer/HBoxContainer/SpritesheetOptions"]
margin_left = 200.0
margin_top = 5.0
margin_right = 300.0
margin_bottom = 19.0
text = "Vertical frames:"
[node name="VerticalFrames" type="SpinBox" parent="VBoxContainer/HBoxContainer/SpritesheetOptions"]
margin_left = 304.0
margin_right = 378.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 1.0
value = 1.0
[connection signal="about_to_show" from="." to="." method="_on_PreviewDialog_about_to_show"] [connection signal="about_to_show" from="." to="." method="_on_PreviewDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_PreviewDialog_confirmed"] [connection signal="confirmed" from="." to="." method="_on_PreviewDialog_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_PreviewDialog_popup_hide"] [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"]