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

Added Line2D nodes to cut the spritesheet preview

This helps in previewing how each spritesheet frame will look when it will be imported in Pixelorama. Note that this does not work well with non-square images at the moment.
This commit is contained in:
OverloadedOrama 2020-06-16 18:30:01 +03:00
parent 13613703fc
commit 8142647a69
2 changed files with 33 additions and 1 deletions

View file

@ -9,13 +9,14 @@ var current_import_option : int = ImageImportOptions.NEW_TAB
var spritesheet_horizontal := 1
var spritesheet_vertical := 1
onready var texture_rect : TextureRect = $VBoxContainer/CenterContainer/TextureRect
onready var spritesheet_options = $VBoxContainer/HBoxContainer/SpritesheetOptions
func _on_PreviewDialog_about_to_show() -> void:
var img_texture := ImageTexture.new()
img_texture.create_from_image(image)
get_node("VBoxContainer/CenterContainer/TextureRect").texture = img_texture
texture_rect.texture = img_texture
func _on_PreviewDialog_popup_hide() -> void:
@ -33,13 +34,39 @@ func _on_ImportOption_item_selected(id : int) -> void:
current_import_option = id
if id == ImageImportOptions.SPRITESHEET:
spritesheet_options.visible = true
texture_rect.get_child(0).visible = true
texture_rect.get_child(1).visible = true
else:
spritesheet_options.visible = false
texture_rect.get_child(0).visible = false
texture_rect.get_child(1).visible = false
func _on_HorizontalFrames_value_changed(value) -> void:
spritesheet_horizontal = value
for child in texture_rect.get_node("HorizLines").get_children():
child.queue_free()
if value > 1:
var line_distance = texture_rect.rect_size.x / value
for i in range(1, value):
var line_2d := Line2D.new()
line_2d.width = 1
line_2d.position = Vector2.ZERO
line_2d.add_point(Vector2(i * line_distance, 0))
line_2d.add_point(Vector2(i * line_distance, texture_rect.rect_size.x))
texture_rect.get_node("HorizLines").add_child(line_2d)
func _on_VerticalFrames_value_changed(value) -> void:
spritesheet_vertical = value
for child in texture_rect.get_node("VerticalLines").get_children():
child.queue_free()
if value > 1:
var line_distance = texture_rect.rect_size.y / value
for i in range(1, value):
var line_2d := Line2D.new()
line_2d.width = 1
line_2d.position = Vector2.ZERO
line_2d.add_point(Vector2(0, i * line_distance))
line_2d.add_point(Vector2(texture_rect.rect_size.y, i * line_distance))
texture_rect.get_node("VerticalLines").add_child(line_2d)

View file

@ -42,6 +42,10 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="HorizLines" type="Control" parent="VBoxContainer/CenterContainer/TextureRect"]
[node name="VerticalLines" type="Control" parent="VBoxContainer/CenterContainer/TextureRect"]
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 304.0
margin_right = 534.0
@ -57,6 +61,7 @@ text = "Import as:"
margin_left = 70.0
margin_right = 151.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
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