2019-12-14 18:18:45 -05:00
|
|
|
extends GridContainer
|
|
|
|
|
2020-05-01 22:17:05 +03:00
|
|
|
const palette_button = preload("res://src/Palette/PaletteButton.tscn")
|
2019-12-14 18:18:45 -05:00
|
|
|
|
2019-12-14 22:11:32 -05:00
|
|
|
var current_palette = "Default"
|
2019-12-20 15:22:52 -05:00
|
|
|
var from_palette : Palette
|
2019-12-14 22:11:32 -05:00
|
|
|
|
2020-04-25 00:42:02 +03:00
|
|
|
|
2019-12-15 03:15:01 +02:00
|
|
|
func _ready() -> void:
|
2019-12-14 22:11:32 -05:00
|
|
|
_load_palettes()
|
2019-12-15 13:44:53 +02:00
|
|
|
|
2019-12-30 20:03:22 +02:00
|
|
|
# Select default palette "Default"
|
2019-12-14 22:11:32 -05:00
|
|
|
on_palette_select(current_palette)
|
|
|
|
|
2020-05-03 03:13:08 +03:00
|
|
|
var add_palette_menu : PopupMenu = Global.add_palette_button.get_node("PopupMenu")
|
2019-12-31 03:44:27 +02:00
|
|
|
add_palette_menu.connect("id_pressed", self, "add_palette_menu_id_pressed")
|
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-14 22:19:17 -05:00
|
|
|
func _clear_swatches() -> void:
|
2019-12-14 22:11:32 -05:00
|
|
|
for child in get_children():
|
2020-09-07 19:02:10 +05:30
|
|
|
if child is BaseButton and child.text != "Dummy":
|
2019-12-14 22:11:32 -05:00
|
|
|
child.disconnect("pressed", self, "on_color_select")
|
|
|
|
child.queue_free()
|
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-15 00:06:04 -05:00
|
|
|
func on_palette_select(palette_name : String) -> void:
|
2019-12-14 22:11:32 -05:00
|
|
|
_clear_swatches()
|
2019-12-30 20:29:46 +02:00
|
|
|
if Global.palettes.has(palette_name): # Palette exists in memory
|
2019-12-16 10:14:16 -05:00
|
|
|
current_palette = palette_name
|
2019-12-20 15:22:52 -05:00
|
|
|
var palette : Palette = Global.palettes[palette_name]
|
2019-12-16 10:48:23 -05:00
|
|
|
_display_palette(palette)
|
2019-12-14 22:11:32 -05:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-17 19:49:20 -05:00
|
|
|
func on_new_empty_palette() -> void:
|
|
|
|
Global.new_palette_dialog.window_title = "Create a new empty palette?"
|
|
|
|
Global.new_palette_name_line_edit.text = "Custom_Palette"
|
2019-12-20 15:22:52 -05:00
|
|
|
from_palette = null
|
2019-12-17 19:49:20 -05:00
|
|
|
Global.new_palette_dialog.popup_centered()
|
2020-05-08 18:37:45 +03:00
|
|
|
Global.dialog_open(true)
|
2019-12-17 19:49:20 -05:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-17 19:49:20 -05:00
|
|
|
func on_import_palette() -> void:
|
2020-07-01 04:48:18 +03:00
|
|
|
if OS.get_name() == "HTML5":
|
|
|
|
Html5FileExchange.load_palette()
|
|
|
|
else:
|
|
|
|
Global.palette_import_file_dialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
2019-12-18 09:43:11 -05:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-31 14:40:44 +02:00
|
|
|
func on_palette_import_file_selected(path : String) -> void:
|
2019-12-20 15:22:52 -05:00
|
|
|
var palette : Palette = null
|
|
|
|
if path.to_lower().ends_with("json"):
|
|
|
|
palette = Palette.new().load_from_file(path)
|
|
|
|
elif path.to_lower().ends_with("gpl"):
|
2020-07-01 04:48:18 +03:00
|
|
|
var file = File.new()
|
|
|
|
if file.file_exists(path):
|
|
|
|
file.open(path, File.READ)
|
|
|
|
var text = file.get_as_text()
|
|
|
|
file.close()
|
|
|
|
palette = Import.import_gpl(path, text)
|
2020-08-26 05:36:03 -04:00
|
|
|
elif path.to_lower().ends_with("pal"):
|
|
|
|
var file = File.new()
|
|
|
|
if file.file_exists(path):
|
|
|
|
file.open(path, File.READ)
|
|
|
|
var text = file.get_as_text()
|
|
|
|
file.close()
|
|
|
|
palette = Import.import_pal_palette(path, text)
|
2020-06-17 17:15:51 +03:00
|
|
|
elif path.to_lower().ends_with("png") or path.to_lower().ends_with("bmp") or path.to_lower().ends_with("hdr") or path.to_lower().ends_with("jpg") or path.to_lower().ends_with("svg") or path.to_lower().ends_with("tga") or path.to_lower().ends_with("webp"):
|
2020-06-30 22:29:24 +03:00
|
|
|
var image := Image.new()
|
|
|
|
var err := image.load(path)
|
|
|
|
if !err:
|
|
|
|
import_image_palette(path, image)
|
|
|
|
return
|
2019-12-22 20:50:37 +02:00
|
|
|
|
2020-06-30 22:29:24 +03:00
|
|
|
attempt_to_import_palette(palette)
|
|
|
|
|
|
|
|
|
|
|
|
func import_image_palette(path : String, image : Image) -> void:
|
|
|
|
var palette : Palette = null
|
|
|
|
palette = Import.import_png_palette(path, image)
|
|
|
|
attempt_to_import_palette(palette)
|
|
|
|
|
|
|
|
|
|
|
|
func attempt_to_import_palette(palette : Palette) -> void:
|
2019-12-20 15:22:52 -05:00
|
|
|
if palette:
|
2020-06-24 20:02:03 +03:00
|
|
|
palette.name = palette_name_replace(palette.name)
|
|
|
|
Global.palettes[palette.name] = palette
|
|
|
|
Global.palette_option_button.add_item(palette.name)
|
|
|
|
var index: int = Global.palette_option_button.get_item_count() - 1
|
|
|
|
Global.palette_option_button.set_item_metadata(index, palette.name)
|
|
|
|
Global.palette_option_button.select(index)
|
|
|
|
on_palette_select(palette.name)
|
|
|
|
save_palette(palette.name, palette.name + ".json")
|
2019-12-20 15:22:52 -05:00
|
|
|
else:
|
|
|
|
Global.error_dialog.set_text("Invalid Palette file!")
|
|
|
|
Global.error_dialog.popup_centered()
|
2020-05-08 18:37:45 +03:00
|
|
|
Global.dialog_open(true)
|
2019-12-17 19:49:20 -05:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-31 03:44:27 +02:00
|
|
|
func _on_AddPalette_pressed() -> void:
|
2020-05-03 03:13:08 +03:00
|
|
|
Global.add_palette_button.get_node("PopupMenu").popup(Rect2(Global.add_palette_button.rect_global_position, Vector2.ONE))
|
2019-12-16 20:23:18 -05:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-16 20:23:18 -05:00
|
|
|
func on_new_palette_confirmed() -> void:
|
|
|
|
var new_palette_name : String = Global.new_palette_name_line_edit.text
|
|
|
|
var result : String = create_new_palette(new_palette_name, from_palette)
|
|
|
|
if not result.empty():
|
2019-12-30 20:03:22 +02:00
|
|
|
Global.error_dialog.set_text(result)
|
2019-12-16 20:23:18 -05:00
|
|
|
Global.error_dialog.popup_centered()
|
2020-05-08 18:37:45 +03:00
|
|
|
Global.dialog_open(true)
|
2019-12-16 20:23:18 -05:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-31 14:40:44 +02:00
|
|
|
func add_palette_menu_id_pressed(id : int) -> void:
|
2019-12-31 03:44:27 +02:00
|
|
|
match id:
|
2020-06-24 20:02:03 +03:00
|
|
|
0: # New Empty Palette
|
|
|
|
on_new_empty_palette()
|
|
|
|
1: # Import Palette
|
|
|
|
on_import_palette()
|
2020-06-24 20:22:44 +03:00
|
|
|
2: # Create Palette From Current Sprite
|
|
|
|
create_palette_from_sprite()
|
2019-12-31 03:44:27 +02:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-24 04:08:16 +02:00
|
|
|
func create_new_palette(name : String, _from_palette : Palette) -> String: # Returns empty string, else error string
|
2019-12-20 15:22:52 -05:00
|
|
|
var new_palette : Palette = Palette.new()
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-16 20:23:18 -05:00
|
|
|
# Check if new name is valid
|
|
|
|
if name.empty():
|
2020-01-08 17:31:56 +02:00
|
|
|
return tr("Error: Palette must have a valid name.")
|
2020-06-24 20:02:03 +03:00
|
|
|
|
|
|
|
name = palette_name_replace(name)
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-16 20:23:18 -05:00
|
|
|
new_palette.name = name
|
|
|
|
# Check if source palette has data
|
2019-12-24 04:08:16 +02:00
|
|
|
if _from_palette:
|
|
|
|
new_palette = _from_palette.duplicate()
|
2019-12-16 20:23:18 -05:00
|
|
|
new_palette.name = name
|
|
|
|
new_palette.editable = true
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-16 20:23:18 -05:00
|
|
|
# Add palette to Global and options
|
|
|
|
Global.palettes[name] = new_palette
|
|
|
|
Global.palette_option_button.add_item(name)
|
2019-12-31 01:24:56 +02:00
|
|
|
var index : int = Global.palette_option_button.get_item_count() - 1
|
2019-12-16 20:23:18 -05:00
|
|
|
Global.palette_option_button.set_item_metadata(index, name)
|
|
|
|
Global.palette_option_button.select(index)
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-16 20:23:18 -05:00
|
|
|
save_palette(name, name + ".json")
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-16 20:23:18 -05:00
|
|
|
on_palette_select(name)
|
|
|
|
return ""
|
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2020-06-24 20:02:03 +03:00
|
|
|
# Checks if the palette name already exists
|
|
|
|
# If it does, add a number to its name, for example
|
|
|
|
# "Palette_Name" will become "Palette_Name (2)", "Palette_Name (3)", etc.
|
|
|
|
func palette_name_replace(name : String) -> String:
|
|
|
|
var i := 1
|
|
|
|
var temp_name := name
|
|
|
|
while Global.palettes.has(temp_name):
|
|
|
|
i += 1
|
|
|
|
temp_name = name + " (%s)" % i
|
|
|
|
name = temp_name
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
2019-12-31 03:44:27 +02:00
|
|
|
func on_edit_palette() -> void:
|
2020-01-12 02:22:37 +02:00
|
|
|
var palette : Palette = Global.palettes[current_palette]
|
2019-12-31 03:44:27 +02:00
|
|
|
|
|
|
|
var create_new_palette := true # Create new palette by default
|
|
|
|
if palette.editable:
|
|
|
|
create_new_palette = false # Edit if already a custom palette
|
|
|
|
|
|
|
|
if create_new_palette:
|
|
|
|
from_palette = Global.palettes[current_palette]
|
|
|
|
Global.new_palette_dialog.window_title = "Create a new custom palette from existing default?"
|
|
|
|
Global.new_palette_name_line_edit.text = "Custom_" + current_palette
|
|
|
|
Global.new_palette_dialog.popup_centered()
|
2020-05-08 18:37:45 +03:00
|
|
|
Global.dialog_open(true)
|
2019-12-31 03:44:27 +02:00
|
|
|
else:
|
|
|
|
from_palette = null
|
|
|
|
Global.edit_palette_popup.open(current_palette)
|
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2020-06-24 20:22:44 +03:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2019-12-31 03:44:27 +02:00
|
|
|
func _on_PaletteOptionButton_item_selected(ID : int) -> void:
|
|
|
|
var palette_name = Global.palette_option_button.get_item_metadata(ID)
|
2020-05-19 23:35:48 +02:00
|
|
|
if palette_name != null:
|
|
|
|
on_palette_select(palette_name)
|
2019-12-31 03:44:27 +02:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-20 15:22:52 -05:00
|
|
|
func _display_palette(palette : Palette) -> void:
|
2019-12-15 03:15:01 +02:00
|
|
|
var index := 0
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-16 10:48:23 -05:00
|
|
|
for color_data in palette.colors:
|
2019-12-20 15:22:52 -05:00
|
|
|
var color = color_data.color
|
2019-12-14 18:18:45 -05:00
|
|
|
var new_button = palette_button.instance()
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-14 18:18:45 -05:00
|
|
|
new_button.get_child(0).modulate = color
|
2019-12-20 15:22:52 -05:00
|
|
|
new_button.hint_tooltip = "#" + color_data.data.to_upper() + " " + color_data.name
|
2019-12-14 22:11:32 -05:00
|
|
|
new_button.connect("pressed", self, "on_color_select", [index])
|
2020-09-07 19:02:10 +05:30
|
|
|
new_button.group = $DummyBtn.group
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-14 18:18:45 -05:00
|
|
|
add_child(new_button)
|
|
|
|
index += 1
|
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-14 22:19:17 -05:00
|
|
|
func on_color_select(index : int) -> void:
|
2019-12-20 15:22:52 -05:00
|
|
|
var color : Color = Global.palettes[current_palette].get_color(index)
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-26 02:01:04 +02:00
|
|
|
if Input.is_action_just_pressed("left_mouse"):
|
2020-07-09 20:22:17 +08:00
|
|
|
Tools.assign_color(color, BUTTON_LEFT)
|
2019-12-26 02:01:04 +02:00
|
|
|
elif Input.is_action_just_pressed("right_mouse"):
|
2020-07-09 20:22:17 +08:00
|
|
|
Tools.assign_color(color, BUTTON_RIGHT)
|
2019-12-14 18:18:45 -05:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2019-12-14 22:19:17 -05:00
|
|
|
func _load_palettes() -> void:
|
2020-04-11 07:58:58 +01:00
|
|
|
Global.directory_module.ensure_xdg_user_dirs_exist()
|
|
|
|
var search_locations = Global.directory_module.get_palette_search_path_in_order()
|
|
|
|
var priority_ordered_files := get_palette_priority_file_map(search_locations)
|
2020-04-13 01:40:26 +03:00
|
|
|
|
2020-04-11 07:58:58 +01:00
|
|
|
# Iterate backwards, so any palettes defined in default files
|
|
|
|
# get overwritten by those of the same name in user files
|
|
|
|
search_locations.invert()
|
|
|
|
priority_ordered_files.invert()
|
|
|
|
for i in range(len(search_locations)):
|
|
|
|
var base_directory : String = search_locations[i]
|
|
|
|
var palette_files : Array = priority_ordered_files[i]
|
|
|
|
for file_name in palette_files:
|
|
|
|
var palette : Palette = Palette.new().load_from_file(base_directory.plus_file(file_name))
|
|
|
|
if palette:
|
|
|
|
Global.palettes[palette.name] = palette
|
|
|
|
Global.palette_option_button.add_item(palette.name)
|
|
|
|
var index: int = Global.palette_option_button.get_item_count() - 1
|
|
|
|
Global.palette_option_button.set_item_metadata(index, palette.name)
|
|
|
|
if palette.name == "Default":
|
2020-05-19 23:35:48 +02:00
|
|
|
# You need these two lines because when you remove a palette
|
|
|
|
# Then this just won't work and _on_PaletteOptionButton_item_selected
|
|
|
|
# method won't fire.
|
Bring refactoring changes to master (#253)
* Refactoring image_menu_id_pressed method in Main.gd (#243)
* Refactoring image_menu_id_pressed method in Main.gd
I've moved the code from each "match" case into a seperate method to make it more readable.
Co-authored-by: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com>
* Refactoring Main.gd. Mostly cutting big methods into smaller ones. (#244)
* Refactoring Main.gd. Mostly cutting big methods into smaller one.
- Reduced size of _ready method in Main.gd
- Moved code from certain parts of old _ready method into seperate methods
- Fixed the translation bug related to CurrentFrame node in TopMenuContainer scene. The CurrentFrame node wasn't updating the language when I was changing language. I've also changed the translation file for this.
- Fixed Global.palette_option_button.selected related warning. Because of some unknown reasons, git didn't push completed line there.
- Moved code from file_menu_id_pressed and view_menu_id_pressed method in Main.gd to separate methods to make it more readable.
* Removed window_title changes from Main.tscn
Co-authored-by: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com>
* Fixed TextureRect images of the circle brushes in BrushesPopup
They all had the pixel brush image in their TextureRect
* Split code from PreferencesDialog.gd to HandleLanguages.gd
Also moved PreferencesDialog script & scene to src/Preferences. More Preferences code splitting will follow.
* Split theme related code from PreferencesDialog into HandleThemes.gd
* Moved shortcuts code from PreferencesDialog
* Created DrawingAlgos.gd and moved a lot of drawing code there
Moved code from Global.gd and Canvas.gd to DrawingAlgos.gd. Will also move the fill_gaps and draw_brush methods of Canvas.gd next. Maybe even refactor the inside of them a bit to make them easier to read.
* Connected "files_dropped" signal to a method
This lets the user drag and drop files into Pixelorama, while it runs, to open them. This doesn't work properly and will crash when it can't open the files. It will get merged into master soon.
* Renamed handle_running_pixelorama_with_arguments() to handle_loading_files()
handle_loading_files() is also used for _on_files_dropped()
* Moved draw_brush() and fill_gaps() from Canvas.gd to DrawingAlgos.gd
draw_brush() is currently very ugly and probably needs inside refactoring
* Removed coord clamping from fill_gaps()
This should make line making behave as expected when the mouse is outside of canvas boundaries
* Drawing is no longer limited by the canvas boundaries
his means that, if you have a brush largen than 1px, you can draw on the edges of the canvas. All pixels that are being drawn outside of the canvas will still have no effect.
* Use enums instead of strings for tools
This could be a slight increase in performance
* Fixed line making with Shift and don't let color picker pick colors outside of canvas
* Changed Global node variables to arrays for left/right
Instead of having 2 variables for left & right nodes, use an array instead. This will help with better looking code, automation and less repetitive code, as seen in ToolButtons.gd. Move related refactoring will follow.
* More Global left/right variables became Arrays
Global.update_left_custom_brush() and its right counterpart have also now become Global.update_custom_brush(mouse_button : int)
* Use Global.Mouse_Button instead of strings for comparison
This should be a slight increase in performance
* Refactoring perferences dialog (#251)
* Added ItemList to themes
* Language and theme checkboxes are now radio buttons
* Even more Global left/right variables became arrays
ColorAndToolOptions has now the same code for left and right tool options, with more similar refactoring coming soon to places like Canvas and DrawingAlgos
* Refactored Canvas.gd
* Refactored DrawingAlgos.draw_brush(), made draw_pixel() method
This also fixes alpha blending and lighting/darkening issues when drawing pixels with mirroring.
* Remove draw_pixel(), use draw_pixel_blended() instead
* Ignore warnings
I don't know what else to do about them, they seem trivial anyway
* Use enum instead of strings for Global.theme_type
Another potential small performance boost when changing themes.
* Use a new Layer class to handle layer information
This replaces the old Global.layers nested array mess, and makes the code easier to read and to understand.
* Fixed linked cel crash and layer naming
* Created a new Cel class, to handle cel information
Like the Layer class, it is used in place of Canvas.layers nested array mess. It hasn't been tested thoroughly yet, so there may be crashes.
* Fixed issue where if you moved a frame to the start (move left), it was invisible
* Added AnimationTag class
Replaces nested Global.animation_tags arrays. Also replaced array.duplicate(true) with looping through the array and creating a new class for each array element, because duplicate(true) does not create new classes, unfortunately, which was causing issues with undo/redo.
Co-authored-by: Igor Santarek <jegor377@gmail.com>
Co-authored-by: Kinwailo <lokinwai@gmail.com>
2020-06-02 20:00:18 +03:00
|
|
|
Global.palette_option_button.selected = index
|
2020-05-19 23:35:48 +02:00
|
|
|
on_palette_select("Default")
|
2020-04-11 07:58:58 +01:00
|
|
|
Global.palette_option_button.select(index)
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-30 20:03:22 +02:00
|
|
|
if not "Default" in Global.palettes && Global.palettes.size() > 0:
|
2020-04-11 08:37:53 +01:00
|
|
|
Global.palette_container._on_PaletteOptionButton_item_selected(0)
|
2019-12-30 20:03:22 +02:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2020-04-11 07:58:58 +01:00
|
|
|
# Get the palette files in a single directory.
|
|
|
|
# if it does not exist, return []
|
|
|
|
func get_palette_files(path : String ) -> Array:
|
2019-12-16 20:23:18 -05:00
|
|
|
var dir := Directory.new()
|
|
|
|
var results = []
|
2020-04-13 01:40:26 +03:00
|
|
|
|
2020-04-11 07:58:58 +01:00
|
|
|
if not dir.dir_exists(path):
|
|
|
|
return []
|
2019-12-17 04:22:39 +02:00
|
|
|
|
2019-12-16 20:23:18 -05:00
|
|
|
dir.open(path)
|
|
|
|
dir.list_dir_begin()
|
2019-12-15 13:44:53 +02:00
|
|
|
|
2019-12-16 20:23:18 -05:00
|
|
|
while true:
|
|
|
|
var file_name = dir.get_next()
|
|
|
|
if file_name == "":
|
|
|
|
break
|
2020-04-11 07:58:58 +01:00
|
|
|
elif (not file_name.begins_with(".")) && file_name.to_lower().ends_with("json") && not dir.current_is_dir():
|
2019-12-16 20:23:18 -05:00
|
|
|
results.append(file_name)
|
|
|
|
|
|
|
|
dir.list_dir_end()
|
|
|
|
return results
|
2019-12-14 22:11:32 -05:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2020-04-11 07:58:58 +01:00
|
|
|
# This returns an array of arrays, with priorities.
|
|
|
|
# In particular, it takes an array of paths to look for
|
|
|
|
# arrays in, in order of file and palette override priority
|
|
|
|
# such that the files in the first directory override the
|
|
|
|
# second, third, etc. ^.^
|
|
|
|
# It returns an array of arrays, where each output array
|
|
|
|
# corresponds to the given input array at the same index, and
|
|
|
|
# contains the (relative to the given directory) palette files
|
|
|
|
# to load, excluding all ones already existing in higher-priority
|
|
|
|
# directories. nya
|
2020-04-13 01:40:26 +03:00
|
|
|
# in particular, this also means you can run backwards on the result
|
2020-04-11 07:58:58 +01:00
|
|
|
# so that palettes with the given palette name in the higher priority
|
|
|
|
# directories override those set in lower priority directories :)
|
|
|
|
func get_palette_priority_file_map(looking_paths: Array) -> Array:
|
|
|
|
var final_list := []
|
|
|
|
# Holds pattern files already found
|
|
|
|
var working_file_set : Dictionary = {}
|
|
|
|
for search_directory in looking_paths:
|
|
|
|
var to_add_files := []
|
|
|
|
var files = get_palette_files(search_directory)
|
|
|
|
# files to check
|
|
|
|
for maybe_to_add in files:
|
|
|
|
if not maybe_to_add in working_file_set:
|
|
|
|
to_add_files.append(maybe_to_add)
|
|
|
|
working_file_set[maybe_to_add] = true
|
2020-04-13 01:40:26 +03:00
|
|
|
|
2020-04-11 07:58:58 +01:00
|
|
|
final_list.append(to_add_files)
|
|
|
|
return final_list
|
2020-04-13 01:40:26 +03:00
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2020-04-11 07:58:58 +01:00
|
|
|
# Locate the highest priority palette by the given relative filename
|
2020-04-13 01:40:26 +03:00
|
|
|
# If none is found in the directories, then do nothing and return
|
2020-04-11 07:58:58 +01:00
|
|
|
# null
|
|
|
|
func get_best_palette_file_location(looking_paths: Array, fname: String): # -> String:
|
|
|
|
var priority_fmap : Array = get_palette_priority_file_map(looking_paths)
|
|
|
|
for i in range(len(looking_paths)):
|
|
|
|
var base_path : String = looking_paths[i]
|
|
|
|
var the_files : Array = priority_fmap[i]
|
|
|
|
if the_files.has(fname):
|
|
|
|
return base_path.plus_file(fname)
|
2020-04-13 01:40:26 +03:00
|
|
|
|
2020-04-11 07:58:58 +01:00
|
|
|
return null
|
|
|
|
|
2020-05-01 20:47:10 +03:00
|
|
|
|
2020-05-19 23:35:48 +02:00
|
|
|
func remove_palette(palette_name : String) -> void:
|
|
|
|
# Don't allow user to remove palette if there is no one left
|
|
|
|
if Global.palettes.size() < 2:
|
2020-05-20 01:31:38 +03:00
|
|
|
Global.error_dialog.set_text("You can't remove more palettes!")
|
|
|
|
Global.error_dialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
2020-05-19 23:35:48 +02:00
|
|
|
return
|
|
|
|
# Don't allow user to try to remove not existing palettes
|
|
|
|
if not palette_name in Global.palettes:
|
2020-05-20 01:31:38 +03:00
|
|
|
Global.error_dialog.set_text("Cannot remove the palette, because it doesn't exist!")
|
|
|
|
Global.error_dialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
2020-05-19 23:35:48 +02:00
|
|
|
return
|
|
|
|
Global.directory_module.ensure_xdg_user_dirs_exist()
|
|
|
|
var palette = Global.palettes[palette_name]
|
|
|
|
var result = palette.remove_file()
|
|
|
|
# Inform user if pallete hasn't been removed from disk because of an error
|
|
|
|
if result != OK:
|
2020-05-20 01:31:38 +03:00
|
|
|
Global.error_dialog.set_text(tr("An error occured while removing the palette! Error code: %s") % str(result))
|
|
|
|
Global.error_dialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
2020-05-19 23:35:48 +02:00
|
|
|
# Remove palette in the program anyway, because if you don't do it
|
|
|
|
# then Pixelorama will crash
|
|
|
|
Global.palettes.erase(palette_name)
|
|
|
|
Global.palette_option_button.clear()
|
|
|
|
current_palette = "Default"
|
|
|
|
_load_palettes()
|
|
|
|
|
|
|
|
|
2019-12-16 20:23:18 -05:00
|
|
|
func save_palette(palette_name : String, filename : String) -> void:
|
2020-04-11 07:58:58 +01:00
|
|
|
Global.directory_module.ensure_xdg_user_dirs_exist()
|
2019-12-20 15:22:52 -05:00
|
|
|
var palette = Global.palettes[palette_name]
|
2020-04-11 07:58:58 +01:00
|
|
|
var palettes_write_path: String = Global.directory_module.get_palette_write_path()
|
|
|
|
palette.save_to_file(palettes_write_path.plus_file(filename))
|
2020-04-07 18:13:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
func _on_NewPaletteDialog_popup_hide() -> void:
|
2020-05-08 18:37:45 +03:00
|
|
|
Global.dialog_open(false)
|
2020-05-19 23:35:48 +02:00
|
|
|
|
|
|
|
|
2020-05-20 01:02:25 +03:00
|
|
|
func _on_RemovePalette_pressed() -> void:
|
2020-05-19 23:35:48 +02:00
|
|
|
remove_palette(current_palette)
|