1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-20 12:33:14 +00:00

Sync import options (#624)

* sync import options (1/2)

* sync import options (2/2)

* resolve format check

* a minor improvement +

some code formatting

* some more formatting

* Some  more formatting

...the checks becoming a pain...

* again you guessed it!

CODE FORMATTING

* used checkbutton instead of simple button

* formatting
This commit is contained in:
Variable 2022-02-25 19:08:11 +05:00 committed by GitHub
parent 8e126c3bab
commit 906123bab1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 159 additions and 56 deletions

View file

@ -4,6 +4,7 @@ var current_save_paths := [] # Array of strings
# Stores a filename of a backup file in user:// until user saves manually
var backup_save_paths := [] # Array of strings
var preview_dialog_tscn = preload("res://src/UI/Dialogs/PreviewDialog.tscn")
var preview_dialogs := [] # Array of preview dialogs
onready var autosave_timer: Timer
@ -63,6 +64,7 @@ func handle_loading_files(files: PoolStringArray) -> void:
func handle_loading_image(file: String, image: Image) -> void:
var preview_dialog: ConfirmationDialog = preview_dialog_tscn.instance()
preview_dialogs.append(preview_dialog)
preview_dialog.path = file
preview_dialog.image = image
Global.control.add_child(preview_dialog)

View file

@ -19,22 +19,29 @@ var current_import_option: int = ImageImportOptions.NEW_TAB
var spritesheet_horizontal := 1
var spritesheet_vertical := 1
var brush_type: int = BrushTypes.FILE
var opened_once = false
var is_master: bool = false
var hiding: bool = false
onready var texture_rect: TextureRect = $VBoxContainer/CenterContainer/TextureRect
onready var image_size_label: Label = $VBoxContainer/SizeContainer/ImageSizeLabel
onready var frame_size_label: Label = $VBoxContainer/SizeContainer/FrameSizeLabel
onready var spritesheet_tab_options = $VBoxContainer/HBoxContainer/SpritesheetTabOptions
onready var spritesheet_layer_options = $VBoxContainer/HBoxContainer/SpritesheetLayerOptions
onready var spritesheet_lay_opt = $VBoxContainer/HBoxContainer/SpritesheetLayerOptions
onready var new_frame_options = $VBoxContainer/HBoxContainer/NewFrameOptions
onready var replace_frame_options = $VBoxContainer/HBoxContainer/ReplaceFrameOptions
onready var new_layer_options = $VBoxContainer/HBoxContainer/NewLayerOptions
onready var new_brush_options = $VBoxContainer/HBoxContainer/NewBrushOptions
onready var new_brush_name = $VBoxContainer/HBoxContainer/NewBrushOptions/BrushName
onready var import_options: OptionButton = $VBoxContainer/HBoxContainer/ImportOption
onready var apply_all: CheckBox = $VBoxContainer/ApplyAll
func _on_PreviewDialog_about_to_show() -> void:
var import_options: OptionButton = get_node("VBoxContainer/HBoxContainer/ImportOption")
if opened_once:
return
opened_once = true
# # order as in ImageImportOptions enum
import_options.add_item("New tab")
import_options.add_item("Spritesheet (new tab)")
@ -69,74 +76,160 @@ func _on_PreviewDialog_about_to_show() -> void:
+ "×"
+ str(image.get_size().y)
)
if OpenSave.preview_dialogs.size() > 1:
apply_all.visible = true
func _on_PreviewDialog_popup_hide() -> void:
queue_free()
if hiding: # if the popup is hiding because of master
return
elif is_master: # if the master is closed then close others too
for child in Global.control.get_children():
if "PreviewDialog" in child.name:
OpenSave.preview_dialogs.erase(child)
child.queue_free()
else: # dialogs being closed separately
OpenSave.preview_dialogs.erase(self)
queue_free()
# Call Global.dialog_open() only if it's the only preview dialog opened
for child in Global.control.get_children():
if child != self and "PreviewDialog" in child.name:
return
if OpenSave.preview_dialogs.size() != 0:
return
Global.dialog_open(false)
func _on_PreviewDialog_confirmed() -> void:
if current_import_option == ImageImportOptions.NEW_TAB:
OpenSave.open_image_as_new_tab(path, image)
if is_master: # if the master is confirmed then confirm others too
is_master = false
synchronize()
for child in Global.control.get_children():
if "PreviewDialog" in child.name:
child.emit_signal("confirmed")
else:
if current_import_option == ImageImportOptions.NEW_TAB:
OpenSave.open_image_as_new_tab(path, image)
elif current_import_option == ImageImportOptions.SPRITESHEET_TAB:
OpenSave.open_image_as_spritesheet_tab(
path, image, spritesheet_horizontal, spritesheet_vertical
)
elif current_import_option == ImageImportOptions.SPRITESHEET_TAB:
OpenSave.open_image_as_spritesheet_tab(
path, image, spritesheet_horizontal, spritesheet_vertical
)
elif current_import_option == ImageImportOptions.SPRITESHEET_LAYER:
var frame_index: int = spritesheet_layer_options.get_node("AtFrameSpinbox").value - 1
OpenSave.open_image_as_spritesheet_layer(
path,
image,
path.get_basename().get_file(),
spritesheet_horizontal,
spritesheet_vertical,
frame_index
)
elif current_import_option == ImageImportOptions.SPRITESHEET_LAYER:
var frame_index: int = spritesheet_lay_opt.get_node("AtFrameSpinbox").value - 1
OpenSave.open_image_as_spritesheet_layer(
path,
image,
path.get_basename().get_file(),
spritesheet_horizontal,
spritesheet_vertical,
frame_index
)
elif current_import_option == ImageImportOptions.NEW_FRAME:
var layer_index: int = new_frame_options.get_node("AtLayerSpinbox").value
OpenSave.open_image_as_new_frame(image, layer_index)
elif current_import_option == ImageImportOptions.NEW_FRAME:
var layer_index: int = new_frame_options.get_node("AtLayerSpinbox").value
OpenSave.open_image_as_new_frame(image, layer_index)
elif current_import_option == ImageImportOptions.REPLACE_FRAME:
var layer_index: int = replace_frame_options.get_node("AtLayerSpinbox").value
var frame_index: int = replace_frame_options.get_node("AtFrameSpinbox").value - 1
OpenSave.open_image_at_frame(image, layer_index, frame_index)
elif current_import_option == ImageImportOptions.REPLACE_FRAME:
var layer_index: int = replace_frame_options.get_node("AtLayerSpinbox").value
var frame_index: int = replace_frame_options.get_node("AtFrameSpinbox").value - 1
OpenSave.open_image_at_frame(image, layer_index, frame_index)
elif current_import_option == ImageImportOptions.NEW_LAYER:
var frame_index: int = new_layer_options.get_node("AtFrameSpinbox").value - 1
OpenSave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index)
elif current_import_option == ImageImportOptions.NEW_LAYER:
var frame_index: int = new_layer_options.get_node("AtFrameSpinbox").value - 1
OpenSave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index)
elif current_import_option == ImageImportOptions.PALETTE:
Palettes.import_palette_from_path(path)
elif current_import_option == ImageImportOptions.PALETTE:
Palettes.import_palette_from_path(path)
elif current_import_option == ImageImportOptions.BRUSH:
add_brush()
elif current_import_option == ImageImportOptions.BRUSH:
add_brush()
elif current_import_option == ImageImportOptions.PATTERN:
var file_name_ext: String = path.get_file()
file_name_ext = file_name_replace(file_name_ext, "Patterns")
var file_name: String = file_name_ext.get_basename()
image.convert(Image.FORMAT_RGBA8)
Global.patterns_popup.add(image, file_name)
elif current_import_option == ImageImportOptions.PATTERN:
var file_name_ext: String = path.get_file()
file_name_ext = file_name_replace(file_name_ext, "Patterns")
var file_name: String = file_name_ext.get_basename()
image.convert(Image.FORMAT_RGBA8)
Global.patterns_popup.add(image, file_name)
# Copy the image file into the "pixelorama/Patterns" directory
var location := "Patterns".plus_file(file_name_ext)
var dir = Directory.new()
dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location))
# Copy the image file into the "pixelorama/Patterns" directory
var location := "Patterns".plus_file(file_name_ext)
var dir = Directory.new()
dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location))
func _on_ApplyAll_toggled(pressed) -> void:
is_master = pressed
# below 4 (and the last) line is needed for correct popup placement
var old_rect = get_rect()
disconnect("popup_hide", self, "_on_PreviewDialog_popup_hide")
hide()
connect("popup_hide", self, "_on_PreviewDialog_popup_hide")
for child in Global.control.get_children():
if child != self and "PreviewDialog" in child.name:
child.hiding = pressed
if pressed:
child.hide()
synchronize()
else:
child.popup_centered()
popup(old_rect) # needed for correct popup_order
func synchronize() -> void:
for child in Global.control.get_children():
if child != self and "PreviewDialog" in child.name:
var dialog = child
#sync modes
var id = current_import_option
dialog.import_options.select(id)
dialog.import_options.emit_signal("item_selected", id)
#sync properties (if any)
if (
id == ImageImportOptions.SPRITESHEET_TAB
or id == ImageImportOptions.SPRITESHEET_LAYER
):
dialog.spritesheet_tab_options.get_node("HorizontalFrames").value = min(
spritesheet_tab_options.get_node("HorizontalFrames").value, image.get_size().x
)
dialog.spritesheet_tab_options.get_node("VerticalFrames").value = min(
spritesheet_tab_options.get_node("VerticalFrames").value, image.get_size().y
)
if id == ImageImportOptions.SPRITESHEET_LAYER:
dialog.spritesheet_lay_opt.get_node("AtFrameSpinbox").value = (spritesheet_lay_opt.get_node(
"AtFrameSpinbox"
).value)
elif id == ImageImportOptions.NEW_FRAME:
dialog.new_frame_options.get_node("AtLayerSpinbox").value = (new_frame_options.get_node(
"AtLayerSpinbox"
).value)
elif id == ImageImportOptions.REPLACE_FRAME:
dialog.replace_frame_options.get_node("AtLayerSpinbox").value = (replace_frame_options.get_node(
"AtLayerSpinbox"
).value)
dialog.replace_frame_options.get_node("AtFrameSpinbox").value = (replace_frame_options.get_node(
"AtFrameSpinbox"
).value)
elif id == ImageImportOptions.NEW_LAYER:
dialog.new_layer_options.get_node("AtFrameSpinbox").value = (new_layer_options.get_node(
"AtFrameSpinbox"
).value)
elif id == ImageImportOptions.BRUSH:
var type = new_brush_options.get_node("BrushTypeOption").selected
dialog.new_brush_options.get_node("BrushTypeOption").select(type)
dialog.new_brush_options.get_node("BrushTypeOption").emit_signal(
"item_selected", type
)
func _on_ImportOption_item_selected(id: int) -> void:
current_import_option = id
frame_size_label.visible = false
spritesheet_tab_options.visible = false
spritesheet_layer_options.visible = false
spritesheet_lay_opt.visible = false
new_frame_options.visible = false
replace_frame_options.visible = false
new_layer_options.visible = false
@ -155,10 +248,10 @@ func _on_ImportOption_item_selected(id: int) -> void:
elif id == ImageImportOptions.SPRITESHEET_LAYER:
frame_size_label.visible = true
spritesheet_tab_options.visible = true
spritesheet_layer_options.visible = true
spritesheet_lay_opt.visible = true
texture_rect.get_child(0).visible = true
texture_rect.get_child(1).visible = true
rect_size.x = spritesheet_layer_options.rect_size.x
rect_size.x = spritesheet_lay_opt.rect_size.x
elif id == ImageImportOptions.NEW_FRAME:
new_frame_options.visible = true

View file

@ -3,8 +3,8 @@
[ext_resource path="res://src/UI/Dialogs/PreviewDialog.gd" type="Script" id=1]
[node name="PreviewDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 70.0
margin_right = 550.0
margin_bottom = 410.0
rect_min_size = Vector2( 550, 70 )
popup_exclusive = true
window_title = "Import Options"
@ -51,10 +51,17 @@ __meta__ = {
[node name="VerticalLines" type="Control" parent="VBoxContainer/CenterContainer/TextureRect"]
[node name="SizeContainer" type="HBoxContainer" parent="VBoxContainer"]
[node name="ApplyAll" type="CheckBox" parent="VBoxContainer"]
visible = false
margin_top = 304.0
margin_right = 534.0
margin_bottom = 318.0
margin_bottom = 324.0
text = "Apply to all ?"
[node name="SizeContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 328.0
margin_right = 534.0
margin_bottom = 342.0
custom_constants/separation = 32
[node name="ImageSizeLabel" type="Label" parent="VBoxContainer/SizeContainer"]
@ -70,9 +77,9 @@ margin_bottom = 14.0
text = "Frame size: 64×64"
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 322.0
margin_top = 346.0
margin_right = 534.0
margin_bottom = 342.0
margin_bottom = 366.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
margin_top = 3.0
@ -257,6 +264,7 @@ margin_bottom = 24.0
[connection signal="about_to_show" from="." to="." method="_on_PreviewDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_PreviewDialog_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_PreviewDialog_popup_hide"]
[connection signal="toggled" from="VBoxContainer/ApplyAll" to="." method="_on_ApplyAll_toggled"]
[connection signal="item_selected" from="VBoxContainer/HBoxContainer/ImportOption" to="." method="_on_ImportOption_item_selected"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/SpritesheetTabOptions/HorizontalFrames" to="." method="_on_HorizontalFrames_value_changed"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/SpritesheetTabOptions/VerticalFrames" to="." method="_on_VerticalFrames_value_changed"]