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

Compare commits

...

2 commits

Author SHA1 Message Date
Emmanouil Papadeas 85ac0897a9 Remove unused method parameter in Palettes' copy_palette() 2024-02-05 00:17:56 +02:00
Emmanouil Papadeas fb948c33b4 Add a "Create a new palette" option on the sort palette button
Enabled by default, every time you sort a palette it creates a copy of the original palette and it sorts that, instead of sorting the original palette directly. This reduces the risk of destructive change, as the palette system does not have undo/redo support. If disabled, sorting affects the original palette directly, without creating a new one.
2024-02-05 00:16:22 +02:00
2 changed files with 32 additions and 12 deletions

View file

@ -3,7 +3,7 @@ extends Node
signal palette_selected(palette_name: String)
signal new_palette_imported
enum SortOptions { REVERSE, HUE, SATURATION, VALUE, RED, GREEN, BLUE, ALPHA }
enum SortOptions { NEW_PALETTE, REVERSE, HUE, SATURATION, VALUE, RED, GREEN, BLUE, ALPHA }
## Presets for creating a new palette
enum NewPalettePresetType {
EMPTY = 0, FROM_CURRENT_PALETTE = 1, FROM_CURRENT_SPRITE = 2, FROM_CURRENT_SELECTION = 3
@ -71,6 +71,14 @@ func _save_palette(palette: Palette = current_palette) -> void:
Global.notification_label("Failed to save palette")
func copy_palette() -> void:
var new_palette_name := current_palette.name
while does_palette_exist(new_palette_name):
new_palette_name += " copy"
var comment := current_palette.comment
_create_new_palette_from_current_palette(new_palette_name, comment)
func create_new_palette(
preset: int,
palette_name: String,
@ -242,6 +250,8 @@ func current_palette_delete_color(index: int) -> void:
func current_palette_sort_colors(id: SortOptions) -> void:
if id == SortOptions.NEW_PALETTE:
return
if id == SortOptions.REVERSE:
current_palette.reverse_colors()
else:

View file

@ -14,6 +14,7 @@ var edited_swatch_color := Color.TRANSPARENT
@onready var add_color_button := $"%AddColor"
@onready var delete_color_button := $"%DeleteColor"
@onready var sort_button := %Sort as MenuButton
@onready var sort_button_popup := sort_button.get_popup()
@onready var edit_palette_dialog := $"%EditPaletteDialog"
@onready var create_palette_dialog := $"%CreatePaletteDialog"
@ -23,20 +24,22 @@ var edited_swatch_color := Color.TRANSPARENT
func _ready() -> void:
sort_button.get_popup().add_item("Reverse colors", Palettes.SortOptions.REVERSE)
sort_button.get_popup().add_separator()
sort_button.get_popup().add_item("Sort by hue", Palettes.SortOptions.HUE)
sort_button.get_popup().add_item("Sort by saturation", Palettes.SortOptions.SATURATION)
sort_button.get_popup().add_item("Sort by value", Palettes.SortOptions.VALUE)
sort_button.get_popup().add_separator()
sort_button.get_popup().add_item("Sort by red", Palettes.SortOptions.RED)
sort_button.get_popup().add_item("Sort by green", Palettes.SortOptions.GREEN)
sort_button.get_popup().add_item("Sort by blue", Palettes.SortOptions.BLUE)
sort_button.get_popup().add_item("Sort by alpha", Palettes.SortOptions.ALPHA)
sort_button_popup.add_check_item("Create a new palette", Palettes.SortOptions.NEW_PALETTE)
sort_button_popup.set_item_checked(Palettes.SortOptions.NEW_PALETTE, true)
sort_button_popup.add_item("Reverse colors", Palettes.SortOptions.REVERSE)
sort_button_popup.add_separator()
sort_button_popup.add_item("Sort by hue", Palettes.SortOptions.HUE)
sort_button_popup.add_item("Sort by saturation", Palettes.SortOptions.SATURATION)
sort_button_popup.add_item("Sort by value", Palettes.SortOptions.VALUE)
sort_button_popup.add_separator()
sort_button_popup.add_item("Sort by red", Palettes.SortOptions.RED)
sort_button_popup.add_item("Sort by green", Palettes.SortOptions.GREEN)
sort_button_popup.add_item("Sort by blue", Palettes.SortOptions.BLUE)
sort_button_popup.add_item("Sort by alpha", Palettes.SortOptions.ALPHA)
Palettes.palette_selected.connect(select_palette)
Palettes.new_palette_imported.connect(setup_palettes_selector)
Tools.color_changed.connect(_color_changed)
sort_button.get_popup().id_pressed.connect(sort_pressed)
sort_button_popup.id_pressed.connect(sort_pressed)
setup_palettes_selector()
redraw_current_palette()
@ -152,6 +155,13 @@ func _on_DeleteColor_gui_input(event: InputEvent) -> void:
func sort_pressed(id: Palettes.SortOptions) -> void:
var new_palette := sort_button_popup.is_item_checked(Palettes.SortOptions.NEW_PALETTE)
if id == Palettes.SortOptions.NEW_PALETTE:
sort_button_popup.set_item_checked(Palettes.SortOptions.NEW_PALETTE, not new_palette)
return
if new_palette:
Palettes.copy_palette()
setup_palettes_selector()
Palettes.current_palette_sort_colors(id)
redraw_current_palette()