1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

New remove current palette feature (#239)

* New remove current palette feature

This commit adds new feature to Pixelorama that will allow user to remove the current selected palette.

* Fixed grammar and added focus_mode = 0 on the remove palette button

Co-authored-by: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com>
This commit is contained in:
Igor Santarek 2020-05-19 23:35:48 +02:00 committed by GitHub
parent c879633f4b
commit eb47d24df3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 205 additions and 20 deletions

View file

@ -1149,3 +1149,15 @@ msgstr ""
msgid "Backup reloaded"
msgstr ""
msgid "Remove currently selected palette"
msgstr ""
msgid "You can't remove more palettes!"
msgstr ""
msgid "Cannot remove the palette, because it doesn't exist!"
msgstr ""
msgid "An error occured while removing the palette! Error code: %s"
msgstr ""

@ -1 +1 @@
Subproject commit ba0f832b3d208678a2c0b8e935f7b365e9b49739
Subproject commit eb7be4f9a9dded53f2ce8a24ecba001da368ca5c

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/remove_palette.png-7e8aecee96680faa3c0f5a841f893394.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/dark_themes/palette/remove_palette.png"
dest_files=[ "res://.import/remove_palette.png-7e8aecee96680faa3c0f5a841f893394.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/remove_palette.png-d2a7982e1ea82bf8f92fd57b586aab4e.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/light_themes/palette/remove_palette.png"
dest_files=[ "res://.import/remove_palette.png-d2a7982e1ea82bf8f92fd57b586aab4e.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

File diff suppressed because one or more lines are too long

View file

@ -3,6 +3,8 @@ extends Reference
var name : String = "Custom_Palette"
# Its purpose is to store pallete source path to enable removing it in the future.
var source_path : String
var colors : Array = []
var comments : String = ""
var editable : bool = true
@ -93,6 +95,7 @@ func save_to_file(path : String) -> void:
file.open(path, File.WRITE)
file.store_string(_serialize())
file.close()
source_path = path
func duplicate(): # -> Palette
@ -155,7 +158,13 @@ func load_from_file(path : String): # -> Palette
var text : String = file.get_as_text()
result = deserialize(text)
result.source_path = path
file.close()
return result
func remove_file() -> int:
var dir = Directory.new()
return dir.remove(source_path)

View file

@ -142,6 +142,7 @@ func on_edit_palette() -> void:
func _on_PaletteOptionButton_item_selected(ID : int) -> void:
var palette_name = Global.palette_option_button.get_item_metadata(ID)
if palette_name != null:
on_palette_select(palette_name)
@ -191,6 +192,11 @@ func _load_palettes() -> void:
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":
# 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.
Global.palette_option_button.selected
on_palette_select("Default")
Global.palette_option_button.select(index)
if not "Default" in Global.palettes && Global.palettes.size() > 0:
@ -264,6 +270,30 @@ func get_best_palette_file_location(looking_paths: Array, fname: String): # ->
return null
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:
get_node('/root/Control/CantRemoveMorePalettesDialog').popup_centered()
return
# Don't allow user to try to remove not existing palettes
if not palette_name in Global.palettes:
get_node('/root/Control/PaletteDoesntExistDialog').popup_centered()
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:
get_node('/root/Control/PaletteRemoveErrorDialog').dialog_text %= str(result)
get_node('/root/Control/PaletteRemoveErrorDialog').popup_centered()
# 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()
func save_palette(palette_name : String, filename : String) -> void:
Global.directory_module.ensure_xdg_user_dirs_exist()
var palette = Global.palettes[palette_name]
@ -273,3 +303,7 @@ func save_palette(palette_name : String, filename : String) -> void:
func _on_NewPaletteDialog_popup_hide() -> void:
Global.dialog_open(false)
func _on_RemovePalette_pressed():
remove_palette(current_palette)

View file

@ -0,0 +1,5 @@
[gd_scene format=2]
[node name="CantRemoveMorePalettesDialog" type="AcceptDialog"]
window_title = "Alarm!"
dialog_text = "You can't remove more palettes!"

View file

@ -0,0 +1,5 @@
[gd_scene format=2]
[node name="PaletteDoesntExistDialog" type="AcceptDialog"]
window_title = "Alarm!"
dialog_text = "Cannot remove the palette, because it doesn't exist!"

View file

@ -0,0 +1,7 @@
[gd_scene format=2]
[node name="PaletteRemoveErrorDialog" type="AcceptDialog"]
margin_right = 90.0
margin_bottom = 58.0
window_title = "Alarm!"
dialog_text = "An error occured while removing the palette! Error code: %s"