From eb47d24df387ecd4f2b553c896c799d40a4b599d Mon Sep 17 00:00:00 2001 From: Igor Santarek Date: Tue, 19 May 2020 23:35:48 +0200 Subject: [PATCH] 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> --- Translations/Translations.pot | 12 +++ addons/godot-gifexporter | 2 +- .../dark_themes/palette/remove_palette.png | Bin 0 -> 279 bytes .../palette/remove_palette.png.import | 34 ++++++++ .../light_themes/palette/remove_palette.png | Bin 0 -> 262 bytes .../palette/remove_palette.png.import | 34 ++++++++ src/Main.tscn | 81 ++++++++++++++---- src/Palette/Palette.gd | 9 ++ src/Palette/PaletteContainer.gd | 36 +++++++- .../Dialogs/CantRemoveMorePalettesDialog.tscn | 5 ++ src/UI/Dialogs/PaletteDoesntExistDialog.tscn | 5 ++ src/UI/Dialogs/PaletteRemoveErrorDialog.tscn | 7 ++ 12 files changed, 205 insertions(+), 20 deletions(-) create mode 100644 assets/graphics/dark_themes/palette/remove_palette.png create mode 100644 assets/graphics/dark_themes/palette/remove_palette.png.import create mode 100644 assets/graphics/light_themes/palette/remove_palette.png create mode 100644 assets/graphics/light_themes/palette/remove_palette.png.import create mode 100644 src/UI/Dialogs/CantRemoveMorePalettesDialog.tscn create mode 100644 src/UI/Dialogs/PaletteDoesntExistDialog.tscn create mode 100644 src/UI/Dialogs/PaletteRemoveErrorDialog.tscn diff --git a/Translations/Translations.pot b/Translations/Translations.pot index 5e3eb9249..1f781f433 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -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 "" diff --git a/addons/godot-gifexporter b/addons/godot-gifexporter index ba0f832b3..eb7be4f9a 160000 --- a/addons/godot-gifexporter +++ b/addons/godot-gifexporter @@ -1 +1 @@ -Subproject commit ba0f832b3d208678a2c0b8e935f7b365e9b49739 +Subproject commit eb7be4f9a9dded53f2ce8a24ecba001da368ca5c diff --git a/assets/graphics/dark_themes/palette/remove_palette.png b/assets/graphics/dark_themes/palette/remove_palette.png new file mode 100644 index 0000000000000000000000000000000000000000..8512b88af44dea7d9be58b0ba03172a277ecf4e9 GIT binary patch literal 279 zcmV+y0qFjTP)Px#(Md!>R7i=vRY?xSAPfuq5Q*n-`Am@CcI3uOx zda-U`R(xdA3`*fr$}=8ge9h~{w9$+7#I+ELX%laWpF(PRH1P{K?I^L+1BsN9bF)ny zp|{ps6D&R}uKCY<@IM1x^OYW;weHLPZ{es!`dYBKM>pX}yw-a0dd(T|ppC?thY%Xh z-^(S^;zUGPx#z)3_wR7i=vRZAAcAP565>e)DHXXQK^`AIvIT|^TBKTHAUoL3ZI5E1rbZlEfj znQVhvSVZ(V3YsxAx)Dztg`yam3`_hewAP3wz5zx@jZP0>4s*4s8N9W_nqcv&IP#zO z;C}{K^OGJ#Yx&LdZ{bmi@L90 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) diff --git a/src/Palette/PaletteContainer.gd b/src/Palette/PaletteContainer.gd index 381935b5d..70df729ef 100644 --- a/src/Palette/PaletteContainer.gd +++ b/src/Palette/PaletteContainer.gd @@ -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: @@ -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) diff --git a/src/UI/Dialogs/CantRemoveMorePalettesDialog.tscn b/src/UI/Dialogs/CantRemoveMorePalettesDialog.tscn new file mode 100644 index 000000000..a83ba9c06 --- /dev/null +++ b/src/UI/Dialogs/CantRemoveMorePalettesDialog.tscn @@ -0,0 +1,5 @@ +[gd_scene format=2] + +[node name="CantRemoveMorePalettesDialog" type="AcceptDialog"] +window_title = "Alarm!" +dialog_text = "You can't remove more palettes!" diff --git a/src/UI/Dialogs/PaletteDoesntExistDialog.tscn b/src/UI/Dialogs/PaletteDoesntExistDialog.tscn new file mode 100644 index 000000000..360b41a47 --- /dev/null +++ b/src/UI/Dialogs/PaletteDoesntExistDialog.tscn @@ -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!" diff --git a/src/UI/Dialogs/PaletteRemoveErrorDialog.tscn b/src/UI/Dialogs/PaletteRemoveErrorDialog.tscn new file mode 100644 index 000000000..cb8cf9412 --- /dev/null +++ b/src/UI/Dialogs/PaletteRemoveErrorDialog.tscn @@ -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"