Skip to content

Commit

Permalink
New remove current palette feature (#239)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jegor377 and OverloadedOrama authored May 19, 2020
1 parent c879633 commit eb47d24
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 20 deletions.
12 changes: 12 additions & 0 deletions Translations/Translations.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
2 changes: 1 addition & 1 deletion addons/godot-gifexporter
Submodule godot-gifexporter updated 1 files
+1 −1 plugin.gd
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions assets/graphics/dark_themes/palette/remove_palette.png.import
Original file line number Diff line number Diff line change
@@ -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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions assets/graphics/light_themes/palette/remove_palette.png.import
Original file line number Diff line number Diff line change
@@ -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
81 changes: 63 additions & 18 deletions src/Main.tscn

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/Palette/Palette.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
36 changes: 35 additions & 1 deletion src/Palette/PaletteContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func on_edit_palette() -> void:

func _on_PaletteOptionButton_item_selected(ID : int) -> void:
var palette_name = Global.palette_option_button.get_item_metadata(ID)
on_palette_select(palette_name)
if palette_name != null:
on_palette_select(palette_name)


func _display_palette(palette : Palette) -> void:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Expand All @@ -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)
5 changes: 5 additions & 0 deletions src/UI/Dialogs/CantRemoveMorePalettesDialog.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[gd_scene format=2]

[node name="CantRemoveMorePalettesDialog" type="AcceptDialog"]
window_title = "Alarm!"
dialog_text = "You can't remove more palettes!"
5 changes: 5 additions & 0 deletions src/UI/Dialogs/PaletteDoesntExistDialog.tscn
Original file line number Diff line number Diff line change
@@ -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!"
7 changes: 7 additions & 0 deletions src/UI/Dialogs/PaletteRemoveErrorDialog.tscn
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit eb47d24

Please sign in to comment.