From 8142647a694b3764a43208f79d5b3852eceb5c40 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 16 Jun 2020 18:30:01 +0300 Subject: [PATCH] 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. --- src/UI/Dialogs/PreviewDialog.gd | 29 ++++++++++++++++++++++++++++- src/UI/Dialogs/PreviewDialog.tscn | 5 +++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/UI/Dialogs/PreviewDialog.gd b/src/UI/Dialogs/PreviewDialog.gd index 997d00f34..22a69438f 100644 --- a/src/UI/Dialogs/PreviewDialog.gd +++ b/src/UI/Dialogs/PreviewDialog.gd @@ -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) diff --git a/src/UI/Dialogs/PreviewDialog.tscn b/src/UI/Dialogs/PreviewDialog.tscn index a97f34331..8ebde6a1a 100644 --- a/src/UI/Dialogs/PreviewDialog.tscn +++ b/src/UI/Dialogs/PreviewDialog.tscn @@ -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