From 5ce061d7938821efade11e91b2b7c75e3881940d Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 24 Jun 2020 20:22:44 +0300 Subject: [PATCH] Palettes can now be created from the colors of the selected sprite --- CHANGELOG.md | 1 + Translations/Translations.pot | 3 +++ src/Palette/PaletteContainer.gd | 24 ++++++++++++++++++++++++ src/Palette/PalettePanelContainer.tscn | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7e1589ab..675e5ec06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Darshan Phaldesai (luiq54), Igor Santarek (jegor377), rob-a-bolton, Kinwailo - You can now drag & drop files into the program while it's running to open them. You can open .pxo files, image files and palette (json and gpl) files this way. - You can now draw on the tiling mode previews! ([#65](https://github.com/Orama-Interactive/Pixelorama/issues/65)) - Added Resize Canvas option to Image menu. +- Palettes can now be created from the colors of the selected sprite. - You can now preview how the frames of the spritesheet you are importing will look. - You can now import image files as layers. Their size will be cropped to the project's size. - You can import image files as brushes, patterns and palettes. diff --git a/Translations/Translations.pot b/Translations/Translations.pot index b074ecee3..b416e79a2 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -1014,6 +1014,9 @@ msgstr "" msgid "Import Palette" msgstr "" +msgid "Create Palette From Current Sprite" +msgstr "" + msgid "Palette Name:" msgstr "" diff --git a/src/Palette/PaletteContainer.gd b/src/Palette/PaletteContainer.gd index 59567dcc9..9f10dad46 100644 --- a/src/Palette/PaletteContainer.gd +++ b/src/Palette/PaletteContainer.gd @@ -87,6 +87,8 @@ func add_palette_menu_id_pressed(id : int) -> void: on_new_empty_palette() 1: # Import Palette on_import_palette() + 2: # Create Palette From Current Sprite + create_palette_from_sprite() func create_new_palette(name : String, _from_palette : Palette) -> String: # Returns empty string, else error string @@ -149,6 +151,28 @@ func on_edit_palette() -> void: Global.edit_palette_popup.open(current_palette) +func create_palette_from_sprite() -> void: + var current_project : Project = Global.current_project + var new_palette_name : String = current_project.name + var result : String = create_new_palette(new_palette_name, null) + if not result.empty(): + Global.error_dialog.set_text(result) + Global.error_dialog.popup_centered() + Global.dialog_open(true) + else: + var current_cel : Cel = current_project.frames[current_project.current_frame].cels[current_project.current_layer] + var cel_image : Image = current_cel.image + var palette : Palette = Global.palettes[current_palette] + for x in cel_image.get_size().x: + for y in cel_image.get_size().y: + var color : Color = cel_image.get_pixel(x, y) + if color.a > 0 and !palette.has_color(color): + palette.add_color(color) + + save_palette(current_palette, current_palette + ".json") + _display_palette(palette) + + func _on_PaletteOptionButton_item_selected(ID : int) -> void: var palette_name = Global.palette_option_button.get_item_metadata(ID) if palette_name != null: diff --git a/src/Palette/PalettePanelContainer.tscn b/src/Palette/PalettePanelContainer.tscn index 66f9b8b07..0f86c59ac 100644 --- a/src/Palette/PalettePanelContainer.tscn +++ b/src/Palette/PalettePanelContainer.tscn @@ -58,7 +58,7 @@ mouse_default_cursor_shape = 2 [node name="PopupMenu" type="PopupMenu" parent="PaletteVBoxContainer/CenterContainer/PaletteButtons/AddPalette"] margin_right = 115.0 margin_bottom = 54.0 -items = [ "New Empty Palette", null, 0, false, false, 0, 0, null, "", false, "Import Palette", null, 0, false, false, 1, 0, null, "", false ] +items = [ "New Empty Palette", null, 0, false, false, 0, 0, null, "", false, "Import Palette", null, 0, false, false, 1, 0, null, "", false, "Create Palette From Current Sprite", null, 0, false, false, 2, 0, null, "", false ] __meta__ = { "_edit_use_anchors_": false }