mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Exporting palettes to png files is now possible
This commit is contained in:
parent
87f7780af5
commit
ed1b5168f9
|
@ -10,6 +10,9 @@ Fayez Akhtar ([@Variable-ind](https://github.com/Variable-ind))
|
|||
|
||||
Built using Godot 3.5.2
|
||||
|
||||
### Added
|
||||
- Exporting palettes to png files is now possible.
|
||||
|
||||
### Changed
|
||||
- When quitting, multiple save confirmation dialogs now appear, each for every project that has changes.
|
||||
- Loop through frames when clicking on go to previous/next frame buttons on the timeline.
|
||||
|
|
|
@ -3,7 +3,9 @@ extends ConfirmationDialog
|
|||
# Emitted when user confirms their changes
|
||||
signal saved(name, comment, width, height)
|
||||
signal deleted
|
||||
signal exported(path)
|
||||
|
||||
const EXPORT_ACTION := "export"
|
||||
const DELETE_ACTION := "delete"
|
||||
const BIN_ACTION := "trash"
|
||||
|
||||
|
@ -22,11 +24,13 @@ onready var path_input := $VBoxContainer/PaletteMetadata/Path
|
|||
onready var size_reduced_warning := $VBoxContainer/SizeReducedWarning
|
||||
onready var already_exists_warning := $VBoxContainer/AlreadyExistsWarning
|
||||
onready var delete_confirmation := $DeleteConfirmation
|
||||
onready var export_file_dialog: FileDialog = $ExportFileDialog
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# Add delete button to edit palette dialog
|
||||
# Add delete and export buttons to edit palette dialog
|
||||
add_button(tr("Delete"), false, DELETE_ACTION)
|
||||
add_button(tr("Export"), false, EXPORT_ACTION)
|
||||
delete_confirmation.get_ok().text = tr("Delete Permanently")
|
||||
delete_confirmation.add_button(tr("Move to Trash"), false, BIN_ACTION)
|
||||
|
||||
|
@ -83,6 +87,8 @@ func _on_EditPaletteDialog_confirmed() -> void:
|
|||
func _on_EditPaletteDialog_custom_action(action: String) -> void:
|
||||
if action == DELETE_ACTION:
|
||||
delete_confirmation.popup_centered()
|
||||
elif action == EXPORT_ACTION:
|
||||
export_file_dialog.popup_centered()
|
||||
|
||||
|
||||
func _on_delete_confirmation_confirmed() -> void:
|
||||
|
@ -117,3 +123,7 @@ func _on_Name_text_changed(new_name):
|
|||
# Disable ok button on empty name
|
||||
if new_name == "":
|
||||
get_ok().disabled = true
|
||||
|
||||
|
||||
func _on_ExportFileDialog_file_selected(path: String) -> void:
|
||||
emit_signal("exported", path)
|
||||
|
|
|
@ -140,8 +140,10 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="DeleteConfirmation" type="ConfirmationDialog" parent="."]
|
||||
margin_right = 170.0
|
||||
margin_bottom = 60.0
|
||||
margin_left = 8.0
|
||||
margin_top = 8.0
|
||||
margin_right = 551.0
|
||||
margin_bottom = 499.0
|
||||
rect_min_size = Vector2( 170, 59.5 )
|
||||
|
||||
[node name="Label2" type="Label" parent="DeleteConfirmation"]
|
||||
|
@ -155,6 +157,14 @@ text = "Delete Palette?"
|
|||
align = 1
|
||||
valign = 1
|
||||
|
||||
[node name="ExportFileDialog" type="FileDialog" parent="."]
|
||||
margin_left = 8.0
|
||||
margin_top = 8.0
|
||||
margin_right = 551.0
|
||||
margin_bottom = 499.0
|
||||
access = 2
|
||||
filters = PoolStringArray( "*.png ; PNG Image" )
|
||||
|
||||
[connection signal="confirmed" from="." to="." method="_on_EditPaletteDialog_confirmed"]
|
||||
[connection signal="custom_action" from="." to="." method="_on_EditPaletteDialog_custom_action"]
|
||||
[connection signal="popup_hide" from="." to="." method="_on_EditPaletteDialog_popup_hide"]
|
||||
|
@ -163,3 +173,4 @@ valign = 1
|
|||
[connection signal="value_changed" from="VBoxContainer/PaletteMetadata/Height" to="." method="_on_size_value_changed"]
|
||||
[connection signal="confirmed" from="DeleteConfirmation" to="." method="_on_delete_confirmation_confirmed"]
|
||||
[connection signal="custom_action" from="DeleteConfirmation" to="." method="_on_delete_confirmation_custom_action"]
|
||||
[connection signal="file_selected" from="ExportFileDialog" to="." method="_on_ExportFileDialog_file_selected"]
|
||||
|
|
|
@ -205,3 +205,14 @@ static func strip_unvalid_characters(string_to_strip: String) -> String:
|
|||
var regex := RegEx.new()
|
||||
regex.compile("[^a-zA-Z0-9_]+")
|
||||
return regex.sub(string_to_strip, "", true)
|
||||
|
||||
|
||||
func convert_to_image() -> Image:
|
||||
var image := Image.new()
|
||||
image.create(colors_max, 1, false, Image.FORMAT_RGBA8)
|
||||
image.lock()
|
||||
for i in colors_max:
|
||||
if colors.has(i):
|
||||
image.set_pixel(i, 0, colors[i].color)
|
||||
image.unlock()
|
||||
return image
|
||||
|
|
|
@ -223,3 +223,11 @@ func _color_changed(_color: Color, button: int) -> void:
|
|||
Palettes.right_selected_color = -1
|
||||
|
||||
palette_grid.unselect_swatch(button, swatch_to_unselect)
|
||||
|
||||
|
||||
func _on_EditPaletteDialog_exported(path: String) -> void:
|
||||
var extension := path.get_extension()
|
||||
match extension:
|
||||
"png":
|
||||
var image: Image = Palettes.current_palette.convert_to_image()
|
||||
image.save_png(path)
|
||||
|
|
|
@ -221,6 +221,7 @@ margin_bottom = 111.0
|
|||
[connection signal="value_changed" from="PaletteVBoxContainer/SwatchesContainer/PaletteScroll/HBoxContainer/VBoxContainer/HScrollBar" to="PaletteVBoxContainer/SwatchesContainer/PaletteScroll" method="_on_HSlider_value_changed"]
|
||||
[connection signal="value_changed" from="PaletteVBoxContainer/SwatchesContainer/PaletteScroll/HBoxContainer/MarginContainer/VScrollBar" to="PaletteVBoxContainer/SwatchesContainer/PaletteScroll" method="_on_VSlider_value_changed"]
|
||||
[connection signal="deleted" from="EditPaletteDialog" to="." method="_on_EditPaletteDialog_deleted"]
|
||||
[connection signal="exported" from="EditPaletteDialog" to="." method="_on_EditPaletteDialog_exported"]
|
||||
[connection signal="saved" from="EditPaletteDialog" to="." method="_on_EditPaletteDialog_saved"]
|
||||
[connection signal="saved" from="CreatePaletteDialog" to="." method="_on_CreatePaletteDialog_saved"]
|
||||
[connection signal="color_changed" from="HiddenColorPickerButton" to="." method="_on_ColorPicker_color_changed"]
|
||||
|
|
Loading…
Reference in a new issue