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

Update the ratio of the AspectRatioContainer in the Import Preview dialog, plus some code cleaning

This commit is contained in:
Emmanouil Papadeas 2024-05-23 01:29:16 +03:00
parent 46ce9aef01
commit dc94f76d6a
2 changed files with 71 additions and 68 deletions

View file

@ -30,33 +30,34 @@ var hiding := false
## keeps track of which custom export to show when it's import option is selected ## keeps track of which custom export to show when it's import option is selected
## Contains ids as keys and custion import option scenes as values ## Contains ids as keys and custion import option scenes as values
var custom_importers = {} var custom_importers := {}
## A [TextureRect] containing the preview image ## A [TextureRect] containing the preview image
@onready var texture_rect: TextureRect = %TextureRect @onready var texture_rect := %TextureRect as TextureRect
@onready var aspect_ratio_container := texture_rect.get_parent() as AspectRatioContainer
## The [OptionButton] containing import options ## The [OptionButton] containing import options
@onready var import_option_button: OptionButton = %ImportOption @onready var import_option_button := %ImportOption as OptionButton
## A [CheckBox] for enabling apply all system. ## A [CheckBox] for enabling apply all system.
@onready var apply_all: CheckBox = $VBoxContainer/VBoxContainer/ApplyAll @onready var apply_all := $VBoxContainer/VBoxContainer/ApplyAll as CheckBox
## Label showing size of original image. ## Label showing size of original image.
@onready var image_size_label: Label = $VBoxContainer/VBoxContainer/SizeContainer/ImageSizeLabel @onready var image_size_label := $VBoxContainer/VBoxContainer/SizeContainer/ImageSizeLabel as Label
## Label for showing size of image after import. ## Label for showing size of image after import.
@onready var frame_size_label: Label = $VBoxContainer/VBoxContainer/SizeContainer/FrameSizeLabel @onready var frame_size_label := $VBoxContainer/VBoxContainer/SizeContainer/FrameSizeLabel as Label
## Container for all types of advanced settings like [member spritesheet_options], ## Container for all types of advanced settings like [member spritesheet_options],
## [member new_brush_options] etc... ## [member new_brush_options] etc...
@onready var import_options: VBoxContainer = %ImportOptions @onready var import_options := %ImportOptions as VBoxContainer
# Below are some common settings grouped into categories and are made visible/invisible # Below are some common settings grouped into categories and are made visible/invisible
# depending on what your import option requires. # depending on what your import option requires.
## container of spritesheet related import options ## container of spritesheet related import options
@onready var spritesheet_options = %ImportOptions/SpritesheetOptions @onready var spritesheet_options := %ImportOptions/SpritesheetOptions as VBoxContainer
## container of frame related import options ## container of frame related import options
@onready var at_frame_option = %ImportOptions/AtFrame @onready var at_frame_option := %ImportOptions/AtFrame as HBoxContainer
## container of layer related import options ## container of layer related import options
@onready var at_layer_option = %ImportOptions/AtLayer @onready var at_layer_option := %ImportOptions/AtLayer as GridContainer
## container of brush related import options ## container of brush related import options
@onready var new_brush_options = %ImportOptions/NewBrushOptions @onready var new_brush_options := %ImportOptions/NewBrushOptions as HBoxContainer
func _on_ImportPreviewDialog_about_to_show() -> void: func _on_ImportPreviewDialog_about_to_show() -> void:
@ -88,11 +89,12 @@ func _on_ImportPreviewDialog_about_to_show() -> void:
var img_texture := ImageTexture.create_from_image(image) var img_texture := ImageTexture.create_from_image(image)
texture_rect.texture = img_texture texture_rect.texture = img_texture
aspect_ratio_container.ratio = float(image.get_width()) / image.get_height()
# set max values of spritesheet options # set max values of spritesheet options
var h_frames = spritesheet_options.find_child("HorizontalFrames") var h_frames := spritesheet_options.find_child("HorizontalFrames") as SpinBox
var v_frames = spritesheet_options.find_child("VerticalFrames") var v_frames := spritesheet_options.find_child("VerticalFrames") as SpinBox
h_frames.max_value = min(h_frames.max_value, image.get_size().x) h_frames.max_value = mini(h_frames.max_value, image.get_size().x)
v_frames.max_value = min(v_frames.max_value, image.get_size().y) v_frames.max_value = mini(v_frames.max_value, image.get_size().y)
# set labels # set labels
image_size_label.text = ( image_size_label.text = (
tr("Image Size") + ": " + str(image.get_size().x) + "×" + str(image.get_size().y) tr("Image Size") + ": " + str(image.get_size().x) + "×" + str(image.get_size().y)
@ -110,7 +112,7 @@ func _on_visibility_changed() -> void:
if hiding: # if the popup is hiding because of main if hiding: # if the popup is hiding because of main
return return
elif is_main: # if the main dialog is closed then close others too elif is_main: # if the main dialog is closed then close others too
for child in Global.control.get_children(): for child in get_parent().get_children():
if child is ImportPreviewDialog: if child is ImportPreviewDialog:
OpenSave.preview_dialogs.erase(child) OpenSave.preview_dialogs.erase(child)
child.queue_free() child.queue_free()
@ -127,7 +129,7 @@ func _on_ImportPreviewDialog_confirmed() -> void:
if is_main: # if the main dialog is confirmed then confirm others too if is_main: # if the main dialog is confirmed then confirm others too
is_main = false is_main = false
synchronize() synchronize()
for child in Global.control.get_children(): for child in get_parent().get_children():
if child is ImportPreviewDialog: if child is ImportPreviewDialog:
child.confirmed.emit() child.confirmed.emit()
else: else:
@ -220,7 +222,7 @@ func _on_ApplyAll_toggled(pressed: bool) -> void:
visibility_changed.disconnect(_on_visibility_changed) visibility_changed.disconnect(_on_visibility_changed)
hide() hide()
visibility_changed.connect(_on_visibility_changed) visibility_changed.connect(_on_visibility_changed)
for child in Global.control.get_children(): for child in get_parent().get_children():
if child != self and child is ImportPreviewDialog: if child != self and child is ImportPreviewDialog:
child.hiding = pressed child.hiding = pressed
if pressed: if pressed:
@ -232,55 +234,53 @@ func _on_ApplyAll_toggled(pressed: bool) -> void:
func synchronize() -> void: func synchronize() -> void:
for child in Global.control.get_children(): var at_frame_spinbox := at_frame_option.get_node("AtFrameSpinbox") as SpinBox
if child != self and child is ImportPreviewDialog: var at_layer_option_button := at_layer_option.get_node("AtLayerOption") as OptionButton
var dialog := child as ImportPreviewDialog for child in get_parent().get_children():
#sync modes if child == self or not child is ImportPreviewDialog:
var id := current_import_option continue
dialog.import_option_button.select(id) var dialog := child as ImportPreviewDialog
dialog.import_option_button.item_selected.emit(id) # Sync modes
var id := current_import_option
dialog.import_option_button.select(id)
dialog.import_option_button.item_selected.emit(id)
# Nodes
var d_at_frame_spinbox := dialog.at_frame_option.get_node("AtFrameSpinbox") as SpinBox
var d_at_layer_option_button := (
dialog.at_layer_option.get_node("AtLayerOption") as OptionButton
)
# Sync properties (if any)
if id == ImageImportOptions.SPRITESHEET_TAB or id == ImageImportOptions.SPRITESHEET_LAYER:
var h_frames := spritesheet_options.find_child("HorizontalFrames") as SpinBox
var v_frames := spritesheet_options.find_child("VerticalFrames") as SpinBox
var d_h_frames := dialog.spritesheet_options.find_child("HorizontalFrames") as SpinBox
var d_v_frames := dialog.spritesheet_options.find_child("VerticalFrames") as SpinBox
d_h_frames.value = mini(h_frames.value, image.get_size().x)
d_v_frames.value = mini(v_frames.value, image.get_size().y)
if id == ImageImportOptions.SPRITESHEET_LAYER:
d_at_frame_spinbox.value = at_frame_spinbox.value
#sync properties (if any) elif id == ImageImportOptions.NEW_FRAME:
if ( d_at_layer_option_button.selected = at_layer_option_button.selected
id == ImageImportOptions.SPRITESHEET_TAB
or id == ImageImportOptions.SPRITESHEET_LAYER
):
var h_frames = spritesheet_options.find_child("HorizontalFrames")
var v_frames = spritesheet_options.find_child("VerticalFrames")
var d_h_frames = dialog.spritesheet_options.find_child("HorizontalFrames")
var d_v_frames = dialog.spritesheet_options.find_child("VerticalFrames")
d_h_frames.value = min(h_frames.value, image.get_size().x)
d_v_frames.value = min(v_frames.value, image.get_size().y)
if id == ImageImportOptions.SPRITESHEET_LAYER:
dialog.at_frame_option.get_node("AtFrameSpinbox").value = (
at_frame_option.get_node("AtFrameSpinbox").value
)
elif id == ImageImportOptions.NEW_FRAME: elif id == ImageImportOptions.REPLACE_CEL:
dialog.at_layer_option.get_node("AtLayerOption").selected = ( d_at_layer_option_button.selected = at_layer_option_button.selected
at_layer_option.get_node("AtLayerOption").selected d_at_frame_spinbox.value = at_frame_spinbox.value
)
elif id == ImageImportOptions.REPLACE_CEL: elif id == ImageImportOptions.NEW_LAYER:
dialog.at_layer_option.get_node("AtLayerOption").selected = ( d_at_frame_spinbox.value = at_frame_spinbox.value
at_layer_option.get_node("AtLayerOption").selected
)
dialog.at_frame_option.get_node("AtFrameSpinbox").value = (
at_frame_option.get_node("AtFrameSpinbox").value
)
elif id == ImageImportOptions.NEW_LAYER: elif id == ImageImportOptions.BRUSH:
dialog.at_frame_option.get_node("AtFrameSpinbox").value = ( var brush_type_option := new_brush_options.get_node("BrushTypeOption") as OptionButton
at_frame_option.get_node("AtFrameSpinbox").value var d_brush_type_option := (
) dialog.new_brush_options.get_node("BrushTypeOption") as OptionButton
)
elif id == ImageImportOptions.BRUSH: var type := brush_type_option.selected
var type = new_brush_options.get_node("BrushTypeOption").selected d_brush_type_option.select(type)
dialog.new_brush_options.get_node("BrushTypeOption").select(type) d_brush_type_option.item_selected.emit(type)
dialog.new_brush_options.get_node("BrushTypeOption").item_selected.emit(type)
func _hide_all_options(): func _hide_all_options() -> void:
# reset some options # reset some options
smart_slice = false smart_slice = false
apply_all.disabled = false apply_all.disabled = false
@ -442,9 +442,9 @@ func _on_BrushTypeOption_item_selected(index: BrushTypes) -> void:
func add_brush() -> void: func add_brush() -> void:
image.convert(Image.FORMAT_RGBA8) image.convert(Image.FORMAT_RGBA8)
if brush_type == BrushTypes.FILE: if brush_type == BrushTypes.FILE:
var file_name_ext: String = path.get_file() var file_name_ext := path.get_file()
file_name_ext = file_name_replace(file_name_ext, "Brushes") file_name_ext = file_name_replace(file_name_ext, "Brushes")
var file_name: String = file_name_ext.get_basename() var file_name := file_name_ext.get_basename()
Brushes.add_file_brush([image], file_name) Brushes.add_file_brush([image], file_name)
@ -454,12 +454,13 @@ func add_brush() -> void:
dir.copy(path, Global.home_data_directory.path_join(location)) dir.copy(path, Global.home_data_directory.path_join(location))
elif brush_type == BrushTypes.PROJECT: elif brush_type == BrushTypes.PROJECT:
var file_name: String = path.get_file().get_basename() var file_name := path.get_file().get_basename()
Global.current_project.brushes.append(image) Global.current_project.brushes.append(image)
Brushes.add_project_brush(image, file_name) Brushes.add_project_brush(image, file_name)
elif brush_type == BrushTypes.RANDOM: elif brush_type == BrushTypes.RANDOM:
var brush_name = new_brush_options.get_node("BrushName/BrushNameLineEdit").text.to_lower() var brush_name_edit := new_brush_options.get_node("BrushName/BrushNameLineEdit") as LineEdit
var brush_name := brush_name_edit.text.to_lower()
if !brush_name.is_valid_filename(): if !brush_name.is_valid_filename():
return return
var dir := DirAccess.open(Global.home_data_directory.path_join("Brushes")) var dir := DirAccess.open(Global.home_data_directory.path_join("Brushes"))
@ -478,7 +479,7 @@ func add_brush() -> void:
var file_ext := path.get_file().get_extension() var file_ext := path.get_file().get_extension()
var index := random_brushes.size() + 1 var index := random_brushes.size() + 1
var file_name = "~" + brush_name + str(index) + "." + file_ext var file_name := "~" + brush_name + str(index) + "." + file_ext
var location := "Brushes".path_join(brush_name).path_join(file_name) var location := "Brushes".path_join(brush_name).path_join(file_name)
dir.copy(path, Global.home_data_directory.path_join(location)) dir.copy(path, Global.home_data_directory.path_join(location))

View file

@ -9,7 +9,7 @@
[node name="ImportPreviewDialog" type="ConfirmationDialog"] [node name="ImportPreviewDialog" type="ConfirmationDialog"]
canvas_item_default_texture_filter = 0 canvas_item_default_texture_filter = 0
position = Vector2i(0, 36) position = Vector2i(0, 36)
size = Vector2i(316, 446) size = Vector2i(316, 451)
script = ExtResource("1_r16hn") script = ExtResource("1_r16hn")
[node name="VBoxContainer" type="VBoxContainer" parent="."] [node name="VBoxContainer" type="VBoxContainer" parent="."]
@ -62,6 +62,7 @@ layout_mode = 2
[node name="ApplyAll" type="CheckBox" parent="VBoxContainer/VBoxContainer"] [node name="ApplyAll" type="CheckBox" parent="VBoxContainer/VBoxContainer"]
visible = false visible = false
layout_mode = 2 layout_mode = 2
mouse_default_cursor_shape = 2
text = "Apply to all" text = "Apply to all"
[node name="SizeContainer" type="HBoxContainer" parent="VBoxContainer/VBoxContainer"] [node name="SizeContainer" type="HBoxContainer" parent="VBoxContainer/VBoxContainer"]
@ -80,7 +81,7 @@ text = "Frame size: 64×64"
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/VBoxContainer"] [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
[node name="Label" type="Label" parent="VBoxContainer/VBoxContainer/HBoxContainer"] [node name="ImportAsLabel" type="Label" parent="VBoxContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 0 size_flags_vertical = 0
text = "Import as:" text = "Import as:"
@ -88,6 +89,7 @@ text = "Import as:"
[node name="ImportOption" type="OptionButton" parent="VBoxContainer/VBoxContainer/HBoxContainer"] [node name="ImportOption" type="OptionButton" parent="VBoxContainer/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 0 size_flags_vertical = 0
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2