From 9a659609942efe07da38497a9f710cfbeda31d1c Mon Sep 17 00:00:00 2001 From: CheetoHead Date: Wed, 18 Dec 2019 09:43:11 -0500 Subject: [PATCH] Import palette file dialog added --- Assets/Graphics/Palette/new_swatch_button.png | Bin 0 -> 146 bytes .../Palette/new_swatch_button.png.import | 34 ++++++++ .../Palette/new_swatch_button_hover.png | Bin 0 -> 156 bytes .../new_swatch_button_hover.png.import | 34 ++++++++ .../Graphics/Palette/remove_swatch_button.png | Bin 0 -> 125 bytes .../Palette/remove_swatch_button.png.import | 34 ++++++++ .../Palette/remove_swatch_button_hover.png | Bin 0 -> 130 bytes .../remove_swatch_button_hover.png.import | 34 ++++++++ Main.tscn | 7 +- Prefabs/EditPalettePopup.tscn | 77 +++++++++--------- Prefabs/NewPaletteDialog.tscn | 12 +-- Prefabs/PaletteImportFileDialog.tscn | 13 +++ Scripts/EditPalettePopup.gd | 4 +- Scripts/Global.gd | 2 + Scripts/Main.gd | 4 + Scripts/PaletteContainer.gd | 34 +++++++- 16 files changed, 242 insertions(+), 47 deletions(-) create mode 100644 Assets/Graphics/Palette/new_swatch_button.png create mode 100644 Assets/Graphics/Palette/new_swatch_button.png.import create mode 100644 Assets/Graphics/Palette/new_swatch_button_hover.png create mode 100644 Assets/Graphics/Palette/new_swatch_button_hover.png.import create mode 100644 Assets/Graphics/Palette/remove_swatch_button.png create mode 100644 Assets/Graphics/Palette/remove_swatch_button.png.import create mode 100644 Assets/Graphics/Palette/remove_swatch_button_hover.png create mode 100644 Assets/Graphics/Palette/remove_swatch_button_hover.png.import create mode 100644 Prefabs/PaletteImportFileDialog.tscn diff --git a/Assets/Graphics/Palette/new_swatch_button.png b/Assets/Graphics/Palette/new_swatch_button.png new file mode 100644 index 0000000000000000000000000000000000000000..af798ea40ec91162866cc3891abcaa8b29752f47 GIT binary patch literal 146 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE;Aq^FBxh(&L5Nxn)VRG5cIG$$7xj)7zWc(c8OpUgMGm!3+gAD;2X3i3uMc9o4A0wOc^CVW-qx t(;EjK^iMgM|A0ehpM<2uifC2_h8xc%R4;|G3j-}-@O1TaS?83{1OV1{FV+A6 literal 0 HcmV?d00001 diff --git a/Assets/Graphics/Palette/new_swatch_button.png.import b/Assets/Graphics/Palette/new_swatch_button.png.import new file mode 100644 index 000000000..a1ab228fd --- /dev/null +++ b/Assets/Graphics/Palette/new_swatch_button.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/new_swatch_button.png-37e4c5ebd7346f6c29db555ec99ae1f5.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Palette/new_swatch_button.png" +dest_files=[ "res://.import/new_swatch_button.png-37e4c5ebd7346f6c29db555ec99ae1f5.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 diff --git a/Assets/Graphics/Palette/new_swatch_button_hover.png b/Assets/Graphics/Palette/new_swatch_button_hover.png new file mode 100644 index 0000000000000000000000000000000000000000..7eadde1c5f130d9eb1ffcfcaca9b0e9eecf75880 GIT binary patch literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE;AvZsq?Ehe%Gtj1vuw2j8cHfYh(&L5Nxn)VRG5cIG$+>c1Vv+*)E{B{P9Zxo$xIGfB{-xr5&!z-2vo|;P@bFw&%f#?< XD!<@|2X7t&&13L%^>bP0l+XkKhN&eN literal 0 HcmV?d00001 diff --git a/Assets/Graphics/Palette/remove_swatch_button.png.import b/Assets/Graphics/Palette/remove_swatch_button.png.import new file mode 100644 index 000000000..9fb159fa3 --- /dev/null +++ b/Assets/Graphics/Palette/remove_swatch_button.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/remove_swatch_button.png-e55ca10e4a33e81efd86e89e399c8786.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Palette/remove_swatch_button.png" +dest_files=[ "res://.import/remove_swatch_button.png-e55ca10e4a33e81efd86e89e399c8786.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=false +svg/scale=1.0 diff --git a/Assets/Graphics/Palette/remove_swatch_button_hover.png b/Assets/Graphics/Palette/remove_swatch_button_hover.png new file mode 100644 index 0000000000000000000000000000000000000000..e8f27d98291a09dbf0a2a9e648da8ca0bad2f781 GIT binary patch literal 130 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE;=r>Bc!h(&L5N void: pass # Replace with function body. func _on_EditPaletteColorNameLineEdit_text_changed(new_text) -> void: - if current_swatch > 0 && current_swatch < working_palette.colors.size(): + if current_swatch >= 0 && current_swatch < working_palette.colors.size(): working_palette.colors[current_swatch].name = new_text _refresh_hint_tooltip(current_swatch) pass func _on_EditPaletteColorPicker_color_changed(color) -> void: - if current_swatch > 0 && current_swatch < working_palette.colors.size(): + if current_swatch >= 0 && current_swatch < working_palette.colors.size(): palette_grid.get_child(current_swatch).get_child(0).modulate = color working_palette.colors[current_swatch].data = color.to_html(true) _refresh_hint_tooltip(current_swatch) diff --git a/Scripts/Global.gd b/Scripts/Global.gd index 06272f1b4..662622d7e 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -190,6 +190,7 @@ var palette_container : GridContainer var edit_palette_popup : WindowDialog var new_palette_dialog : ConfirmationDialog var new_palette_name_line_edit : LineEdit +var palette_import_file_dialog : FileDialog var error_dialog : AcceptDialog @@ -283,6 +284,7 @@ func _ready() -> void: edit_palette_popup = find_node_by_name(root, "EditPalettePopup") new_palette_dialog = find_node_by_name(root, "NewPaletteDialog") new_palette_name_line_edit = find_node_by_name(new_palette_dialog, "NewPaletteNameLineEdit") + palette_import_file_dialog = find_node_by_name(root, "PaletteImportFileDialog") error_dialog = find_node_by_name(root, "ErrorDialog") diff --git a/Scripts/Main.gd b/Scripts/Main.gd index bc42878bc..7b379a33f 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -1079,3 +1079,7 @@ func add_palette_menu_id_pressed(id) -> void: func _on_NewPaletteDialog_confirmed() -> void: Global.palette_container.on_new_palette_confirmed() pass + +func _on_PaletteImportFileDialog_file_selected(path) -> void: + Global.palette_container.on_palette_import_file_selected(path) + pass diff --git a/Scripts/PaletteContainer.gd b/Scripts/PaletteContainer.gd index 80997fd98..eb87a529c 100644 --- a/Scripts/PaletteContainer.gd +++ b/Scripts/PaletteContainer.gd @@ -1,6 +1,6 @@ extends GridContainer -var palette_button = preload("res://Prefabs/PaletteButton.tscn"); +const palette_button = preload("res://Prefabs/PaletteButton.tscn"); var current_palette = "Default" var from_palette : = {} @@ -42,6 +42,38 @@ func on_new_empty_palette() -> void: pass func on_import_palette() -> void: + Global.palette_import_file_dialog.popup_centered() + pass + +func on_palette_import_file_selected(path) -> void: + var file := File.new() + + file.open(path, File.READ) + var text = file.get_as_text() + var result_json = JSON.parse(text) + var result = {} + var palette_name = null # Default error condition + + if result_json.error != OK: # If parse has errors + print("Error: ", result_json.error) + print("Error Line: ", result_json.error_line) + print("Error String: ", result_json.error_string) + else: # If parse OK + var data = result_json.result + if data.has("name"): #If data is 'valid' palette file + palette_name = data.name + if not Global.palettes.has(palette_name): + Global.palettes[palette_name] = data + Global.palette_option_button.add_item(palette_name) + var index := 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") + else: + Global.error_dialog.set_text("Palette named '" + palette_name + "' already exists"); + Global.error_dialog.popup_centered() + file.close() pass func on_edit_palette() -> void: