mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Added more options for creating palette from sprite
Creating palettes from sprites has been enhanced - you can now choose if you want to get colors from the selection, current cel, entire frame or all frames, and if you want the colors to have an alpha component.
This commit is contained in:
parent
fbbdcdaa57
commit
3be5f27c5c
|
@ -11,6 +11,7 @@ Laurenz Reinthaler (Schweini07)
|
||||||
### Added
|
### Added
|
||||||
- A new purple theme.
|
- A new purple theme.
|
||||||
- Buttons for moving the current frame left or right. ([#344](https://github.com/Orama-Interactive/Pixelorama/pull/344))
|
- Buttons for moving the current frame left or right. ([#344](https://github.com/Orama-Interactive/Pixelorama/pull/344))
|
||||||
|
- Creating palettes from sprites has been enhanced - you can now choose if you want to get colors from the selection, current cel, entire frame or all frames, and if you want the colors to have an alpha component.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Guides now move with a step of 0.5 pixels. That makes it possible to have guides (and symmetry guides) to be in the middle of pixels.
|
- Guides now move with a step of 0.5 pixels. That makes it possible to have guides (and symmetry guides) to be in the middle of pixels.
|
||||||
|
|
|
@ -1245,6 +1245,15 @@ msgstr ""
|
||||||
msgid "Edit Palette"
|
msgid "Edit Palette"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Create colors with alpha component"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Get colors only from selection"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Get colors from"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
msgid "Patrons:"
|
msgid "Patrons:"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
extends GridContainer
|
extends GridContainer
|
||||||
|
|
||||||
|
|
||||||
|
enum {CEL, FRAME, ALL_FRAMES}
|
||||||
|
|
||||||
const palette_button = preload("res://src/Palette/PaletteButton.tscn")
|
const palette_button = preload("res://src/Palette/PaletteButton.tscn")
|
||||||
|
|
||||||
var current_palette = "Default"
|
var current_palette = "Default"
|
||||||
var from_palette : Palette
|
var from_palette : Palette
|
||||||
|
|
||||||
|
onready var palette_from_sprite_dialog = $"../../../../PaletteFromSpriteDialog"
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_load_palettes()
|
_load_palettes()
|
||||||
|
@ -117,7 +122,8 @@ func add_palette_menu_id_pressed(id : int) -> void:
|
||||||
1: # Import Palette
|
1: # Import Palette
|
||||||
on_import_palette()
|
on_import_palette()
|
||||||
2: # Create Palette From Current Sprite
|
2: # Create Palette From Current Sprite
|
||||||
create_palette_from_sprite()
|
palette_from_sprite_dialog.popup_centered()
|
||||||
|
Global.dialog_open(true)
|
||||||
|
|
||||||
|
|
||||||
func create_new_palette(name : String, _from_palette : Palette) -> String: # Returns empty string, else error string
|
func create_new_palette(name : String, _from_palette : Palette) -> String: # Returns empty string, else error string
|
||||||
|
@ -188,15 +194,48 @@ func create_palette_from_sprite() -> void:
|
||||||
Global.error_dialog.set_text(result)
|
Global.error_dialog.set_text(result)
|
||||||
Global.error_dialog.popup_centered()
|
Global.error_dialog.popup_centered()
|
||||||
Global.dialog_open(true)
|
Global.dialog_open(true)
|
||||||
else:
|
return
|
||||||
var current_cel : Cel = current_project.frames[current_project.current_frame].cels[current_project.current_layer]
|
|
||||||
var cel_image : Image = current_cel.image
|
var alpha_checkbox : CheckBox = palette_from_sprite_dialog.get_node("VBoxContainer/AlphaCheckBox")
|
||||||
|
var selection_checkbox : CheckBox = palette_from_sprite_dialog.get_node("VBoxContainer/SelectionCheckBox")
|
||||||
|
var colors_from_optionbutton : OptionButton = palette_from_sprite_dialog.get_node("VBoxContainer/HBoxContainer/ColorsFromOptionButton")
|
||||||
|
|
||||||
var palette : Palette = Global.palettes[current_palette]
|
var palette : Palette = Global.palettes[current_palette]
|
||||||
for x in cel_image.get_size().x:
|
var pixels := []
|
||||||
for y in cel_image.get_size().y:
|
|
||||||
var color : Color = cel_image.get_pixel(x, y)
|
if selection_checkbox.pressed:
|
||||||
if color.a > 0 and !palette.has_color(color):
|
pixels = current_project.selected_pixels.duplicate()
|
||||||
|
else:
|
||||||
|
for x in current_project.size.x:
|
||||||
|
for y in current_project.size.y:
|
||||||
|
pixels.append(Vector2(x, y))
|
||||||
|
|
||||||
|
var cels := []
|
||||||
|
match colors_from_optionbutton.selected:
|
||||||
|
CEL:
|
||||||
|
cels.append(current_project.frames[current_project.current_frame].cels[current_project.current_layer])
|
||||||
|
FRAME:
|
||||||
|
for cel in current_project.frames[current_project.current_frame].cels:
|
||||||
|
cels.append(cel)
|
||||||
|
ALL_FRAMES:
|
||||||
|
for frame in current_project.frames:
|
||||||
|
for cel in frame.cels:
|
||||||
|
cels.append(cel)
|
||||||
|
|
||||||
|
for cel in cels:
|
||||||
|
var cel_image := Image.new()
|
||||||
|
cel_image.copy_from(cel.image)
|
||||||
|
cel_image.lock()
|
||||||
|
if cel_image.is_invisible():
|
||||||
|
continue
|
||||||
|
for i in pixels:
|
||||||
|
var color : Color = cel_image.get_pixelv(i)
|
||||||
|
if color.a > 0:
|
||||||
|
if !alpha_checkbox.pressed:
|
||||||
|
color.a = 1
|
||||||
|
if !palette.has_color(color):
|
||||||
palette.add_color(color)
|
palette.add_color(color)
|
||||||
|
cel_image.unlock()
|
||||||
|
|
||||||
save_palette(current_palette, current_palette + ".json")
|
save_palette(current_palette, current_palette + ".json")
|
||||||
_display_palette(palette)
|
_display_palette(palette)
|
||||||
|
@ -373,3 +412,11 @@ func _on_NewPaletteDialog_popup_hide() -> void:
|
||||||
|
|
||||||
func _on_RemovePalette_pressed() -> void:
|
func _on_RemovePalette_pressed() -> void:
|
||||||
remove_palette(current_palette)
|
remove_palette(current_palette)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_PaletteFromSpriteDialog_confirmed() -> void:
|
||||||
|
create_palette_from_sprite()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_PaletteFromSpriteDialog_popup_hide() -> void:
|
||||||
|
Global.dialog_open(false)
|
||||||
|
|
|
@ -190,6 +190,60 @@ margin_left = 7.0
|
||||||
margin_top = 7.0
|
margin_top = 7.0
|
||||||
margin_right = 607.0
|
margin_right = 607.0
|
||||||
margin_bottom = 577.0
|
margin_bottom = 577.0
|
||||||
|
|
||||||
|
[node name="PaletteFromSpriteDialog" type="ConfirmationDialog" parent="."]
|
||||||
|
margin_left = 7.0
|
||||||
|
margin_top = 7.0
|
||||||
|
margin_right = 281.0
|
||||||
|
margin_bottom = 127.0
|
||||||
|
window_title = "Create Palette From Current Sprite"
|
||||||
|
resizable = true
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="PaletteFromSpriteDialog"]
|
||||||
|
margin_left = 8.0
|
||||||
|
margin_top = 8.0
|
||||||
|
margin_right = 266.0
|
||||||
|
margin_bottom = 84.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="AlphaCheckBox" type="CheckBox" parent="PaletteFromSpriteDialog/VBoxContainer"]
|
||||||
|
margin_right = 258.0
|
||||||
|
margin_bottom = 24.0
|
||||||
|
mouse_default_cursor_shape = 2
|
||||||
|
pressed = true
|
||||||
|
text = "Create colors with alpha component"
|
||||||
|
|
||||||
|
[node name="SelectionCheckBox" type="CheckBox" parent="PaletteFromSpriteDialog/VBoxContainer"]
|
||||||
|
margin_top = 28.0
|
||||||
|
margin_right = 258.0
|
||||||
|
margin_bottom = 52.0
|
||||||
|
mouse_default_cursor_shape = 2
|
||||||
|
text = "Get colors only from selection"
|
||||||
|
|
||||||
|
[node name="HBoxContainer" type="HBoxContainer" parent="PaletteFromSpriteDialog/VBoxContainer"]
|
||||||
|
margin_top = 56.0
|
||||||
|
margin_right = 258.0
|
||||||
|
margin_bottom = 76.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="PaletteFromSpriteDialog/VBoxContainer/HBoxContainer"]
|
||||||
|
margin_top = 3.0
|
||||||
|
margin_right = 104.0
|
||||||
|
margin_bottom = 17.0
|
||||||
|
text = "Get colors from:"
|
||||||
|
|
||||||
|
[node name="ColorsFromOptionButton" type="OptionButton" parent="PaletteFromSpriteDialog/VBoxContainer/HBoxContainer"]
|
||||||
|
margin_left = 108.0
|
||||||
|
margin_right = 207.0
|
||||||
|
margin_bottom = 20.0
|
||||||
|
mouse_default_cursor_shape = 2
|
||||||
|
text = "Current cel"
|
||||||
|
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All frames", null, false, 2, null ]
|
||||||
|
selected = 0
|
||||||
[connection signal="pressed" from="PaletteVBoxContainer/CenterContainer/PaletteButtons/AddPalette" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_AddPalette_pressed"]
|
[connection signal="pressed" from="PaletteVBoxContainer/CenterContainer/PaletteButtons/AddPalette" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_AddPalette_pressed"]
|
||||||
[connection signal="pressed" from="PaletteVBoxContainer/CenterContainer/PaletteButtons/EditPalette" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_edit_palette"]
|
[connection signal="pressed" from="PaletteVBoxContainer/CenterContainer/PaletteButtons/EditPalette" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_edit_palette"]
|
||||||
[connection signal="pressed" from="PaletteVBoxContainer/CenterContainer/PaletteButtons/RemovePalette" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_RemovePalette_pressed"]
|
[connection signal="pressed" from="PaletteVBoxContainer/CenterContainer/PaletteButtons/RemovePalette" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_RemovePalette_pressed"]
|
||||||
|
@ -198,3 +252,5 @@ margin_bottom = 577.0
|
||||||
[connection signal="popup_hide" from="NewPaletteDialog" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_NewPaletteDialog_popup_hide"]
|
[connection signal="popup_hide" from="NewPaletteDialog" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_NewPaletteDialog_popup_hide"]
|
||||||
[connection signal="file_selected" from="PaletteImportFileDialog" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_palette_import_file_selected"]
|
[connection signal="file_selected" from="PaletteImportFileDialog" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_palette_import_file_selected"]
|
||||||
[connection signal="popup_hide" from="PaletteImportFileDialog" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_NewPaletteDialog_popup_hide"]
|
[connection signal="popup_hide" from="PaletteImportFileDialog" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_NewPaletteDialog_popup_hide"]
|
||||||
|
[connection signal="confirmed" from="PaletteFromSpriteDialog" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_PaletteFromSpriteDialog_confirmed"]
|
||||||
|
[connection signal="popup_hide" from="PaletteFromSpriteDialog" to="PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_PaletteFromSpriteDialog_popup_hide"]
|
||||||
|
|
Loading…
Reference in a new issue