diff --git a/Assets/Graphics/Palette/new_swatch_button.png b/Assets/Graphics/Palette/new_swatch_button.png new file mode 100644 index 000000000..af798ea40 Binary files /dev/null and b/Assets/Graphics/Palette/new_swatch_button.png differ 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 000000000..7eadde1c5 Binary files /dev/null and b/Assets/Graphics/Palette/new_swatch_button_hover.png differ diff --git a/Assets/Graphics/Palette/new_swatch_button_hover.png.import b/Assets/Graphics/Palette/new_swatch_button_hover.png.import new file mode 100644 index 000000000..8762882ea --- /dev/null +++ b/Assets/Graphics/Palette/new_swatch_button_hover.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/new_swatch_button_hover.png-5a3842ea128669b8a5845c570dfb34de.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Palette/new_swatch_button_hover.png" +dest_files=[ "res://.import/new_swatch_button_hover.png-5a3842ea128669b8a5845c570dfb34de.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/remove_swatch_button.png b/Assets/Graphics/Palette/remove_swatch_button.png new file mode 100644 index 000000000..6eac7ee70 Binary files /dev/null and b/Assets/Graphics/Palette/remove_swatch_button.png differ 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 000000000..e8f27d982 Binary files /dev/null and b/Assets/Graphics/Palette/remove_swatch_button_hover.png differ diff --git a/Assets/Graphics/Palette/remove_swatch_button_hover.png.import b/Assets/Graphics/Palette/remove_swatch_button_hover.png.import new file mode 100644 index 000000000..90c7e6797 --- /dev/null +++ b/Assets/Graphics/Palette/remove_swatch_button_hover.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/remove_swatch_button_hover.png-3d8cfbbb669e326875ae170abbd7ecbf.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Palette/remove_swatch_button_hover.png" +dest_files=[ "res://.import/remove_swatch_button_hover.png-3d8cfbbb669e326875ae170abbd7ecbf.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/Main.tscn b/Main.tscn index ac67824db..00994fa8c 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=63 format=2] +[gd_scene load_steps=64 format=2] [ext_resource path="res://Themes & Styles/Main Theme.tres" type="Theme" id=1] [ext_resource path="res://Scripts/Main.gd" type="Script" id=2] @@ -45,6 +45,7 @@ [ext_resource path="res://Scripts/AboutDialog.gd" type="Script" id=43] [ext_resource path="res://Prefabs/EditPalettePopup.tscn" type="PackedScene" id=44] [ext_resource path="res://Prefabs/NewPaletteDialog.tscn" type="PackedScene" id=45] +[ext_resource path="res://Prefabs/PaletteImportFileDialog.tscn" type="PackedScene" id=46] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.223529, 0.223529, 0.243137, 1 ) @@ -1723,9 +1724,12 @@ window_title = "Error!" dialog_text = "This is an error message!" [node name="EditPalettePopup" parent="." instance=ExtResource( 44 )] +visible = false [node name="NewPaletteDialog" parent="." instance=ExtResource( 45 )] +[node name="PaletteImportFileDialog" parent="." instance=ExtResource( 46 )] + [node name="AnimationTimer" type="Timer" parent="."] [node name="LeftCursor" type="Sprite" parent="."] @@ -1811,4 +1815,5 @@ visible = false [connection signal="confirmed" from="QuitDialog" to="." method="_on_QuitDialog_confirmed"] [connection signal="popup_hide" from="QuitDialog" to="." method="_can_draw_true"] [connection signal="confirmed" from="NewPaletteDialog" to="." method="_on_NewPaletteDialog_confirmed"] +[connection signal="file_selected" from="PaletteImportFileDialog" to="." method="_on_PaletteImportFileDialog_file_selected"] [connection signal="timeout" from="AnimationTimer" to="." method="_on_AnimationTimer_timeout"] diff --git a/Prefabs/EditPalettePopup.tscn b/Prefabs/EditPalettePopup.tscn index fe7fc70d7..84d4746a7 100644 --- a/Prefabs/EditPalettePopup.tscn +++ b/Prefabs/EditPalettePopup.tscn @@ -1,10 +1,13 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://Scripts/EditPalettePopup.gd" type="Script" id=1] -[ext_resource path="res://Assets/Graphics/Timeline/New_Frame.png" type="Texture" id=2] -[ext_resource path="res://Assets/Graphics/Layers/delete_layer.png" type="Texture" id=3] +[ext_resource path="res://Assets/Graphics/Palette/new_swatch_button.png" type="Texture" id=2] +[ext_resource path="res://Assets/Graphics/Palette/new_swatch_button_hover.png" type="Texture" id=3] +[ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button.png" type="Texture" id=4] +[ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button_hover.png" type="Texture" id=5] [node name="EditPalettePopup" type="WindowDialog"] +visible = true margin_right = 600.0 margin_bottom = 550.0 rect_min_size = Vector2( 600, 550 ) @@ -22,19 +25,17 @@ size_flags_horizontal = 3 [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] margin_right = 580.0 -margin_bottom = 482.0 +margin_bottom = 478.0 size_flags_vertical = 3 [node name="EditPaletteColorPicker" type="ColorPicker" parent="VBoxContainer/HBoxContainer"] -margin_left = 4.0 -margin_top = 4.0 -margin_right = 4.0 -margin_bottom = 4.0 +margin_right = 290.0 +margin_bottom = 478.0 [node name="Panel" type="Panel" parent="VBoxContainer/HBoxContainer"] margin_left = 294.0 -margin_right = 540.0 -margin_bottom = 482.0 +margin_right = 556.0 +margin_bottom = 478.0 size_flags_horizontal = 3 [node name="EditPaletteGridContainer" type="GridContainer" parent="VBoxContainer/HBoxContainer/Panel"] @@ -45,71 +46,73 @@ size_flags_vertical = 3 columns = 8 [node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer"] -margin_left = 544.0 +margin_left = 560.0 margin_right = 580.0 -margin_bottom = 482.0 +margin_bottom = 478.0 [node name="AddSwatchButton" type="TextureButton" parent="VBoxContainer/HBoxContainer/VBoxContainer"] -margin_right = 36.0 -margin_bottom = 36.0 +margin_right = 20.0 +margin_bottom = 20.0 texture_normal = ExtResource( 2 ) +texture_hover = ExtResource( 3 ) [node name="RemoveSwatchButton" type="TextureButton" parent="VBoxContainer/HBoxContainer/VBoxContainer"] -margin_top = 40.0 -margin_right = 36.0 -margin_bottom = 72.0 -texture_normal = ExtResource( 3 ) +margin_top = 24.0 +margin_right = 20.0 +margin_bottom = 44.0 +texture_normal = ExtResource( 4 ) +texture_hover = ExtResource( 5 ) [node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"] -margin_top = 486.0 +margin_top = 482.0 margin_right = 580.0 -margin_bottom = 503.0 +margin_bottom = 506.0 [node name="Label" type="Label" parent="VBoxContainer/HBoxContainer3"] -margin_top = 1.0 -margin_right = 68.0 -margin_bottom = 16.0 +margin_top = 5.0 +margin_right = 79.0 +margin_bottom = 19.0 text = "Color Name:" [node name="EditPaletteColorNameLineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer3"] -margin_left = 72.0 +margin_left = 83.0 margin_right = 580.0 -margin_bottom = 17.0 +margin_bottom = 24.0 size_flags_horizontal = 3 [node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"] -margin_top = 507.0 +margin_top = 510.0 margin_right = 580.0 margin_bottom = 530.0 size_flags_horizontal = 3 [node name="SpacerControl" type="Control" parent="VBoxContainer/HBoxContainer2"] -margin_right = 159.0 -margin_bottom = 23.0 +margin_right = 156.0 +margin_bottom = 20.0 size_flags_horizontal = 3 [node name="EditPaletteSaveButton" type="Button" parent="VBoxContainer/HBoxContainer2"] -margin_left = 163.0 +margin_left = 160.0 margin_right = 201.0 -margin_bottom = 23.0 +margin_bottom = 20.0 text = "Save" [node name="SpacerControl2" type="Control" parent="VBoxContainer/HBoxContainer2"] margin_left = 205.0 -margin_right = 364.0 -margin_bottom = 23.0 +margin_right = 361.0 +margin_bottom = 20.0 size_flags_horizontal = 3 [node name="EditPaletteCancelButton" type="Button" parent="VBoxContainer/HBoxContainer2"] -margin_left = 368.0 -margin_right = 417.0 -margin_bottom = 23.0 +margin_left = 365.0 +margin_right = 419.0 +margin_bottom = 20.0 text = "Cancel" [node name="SpacerControl3" type="Control" parent="VBoxContainer/HBoxContainer2"] -margin_left = 421.0 +margin_left = 423.0 margin_right = 580.0 -margin_bottom = 23.0 +margin_bottom = 20.0 size_flags_horizontal = 3 [connection signal="color_changed" from="VBoxContainer/HBoxContainer/EditPaletteColorPicker" to="." method="_on_EditPaletteColorPicker_color_changed"] [connection signal="pressed" from="VBoxContainer/HBoxContainer/VBoxContainer/AddSwatchButton" to="." method="_on_AddSwatchButton_pressed"] diff --git a/Prefabs/NewPaletteDialog.tscn b/Prefabs/NewPaletteDialog.tscn index f56d49835..2d6296f0f 100644 --- a/Prefabs/NewPaletteDialog.tscn +++ b/Prefabs/NewPaletteDialog.tscn @@ -12,14 +12,14 @@ margin_right = 365.0 margin_bottom = 34.0 [node name="Label" type="Label" parent="HBoxContainer2"] -margin_top = 4.0 -margin_right = 77.0 -margin_bottom = 19.0 +margin_top = 6.0 +margin_right = 91.0 +margin_bottom = 20.0 text = "Palette Name:" [node name="NewPaletteNameLineEdit" type="LineEdit" parent="HBoxContainer2"] -margin_left = 81.0 -margin_right = 307.0 -margin_bottom = 23.0 +margin_left = 95.0 +margin_right = 357.0 +margin_bottom = 26.0 size_flags_horizontal = 3 expand_to_text_length = true diff --git a/Prefabs/PaletteImportFileDialog.tscn b/Prefabs/PaletteImportFileDialog.tscn new file mode 100644 index 000000000..8058cb414 --- /dev/null +++ b/Prefabs/PaletteImportFileDialog.tscn @@ -0,0 +1,13 @@ +[gd_scene format=2] + +[node name="PaletteImportFileDialog" type="FileDialog"] +anchor_right = 1.0 +anchor_bottom = 1.0 +rect_min_size = Vector2( 500, 300 ) +window_title = "Open a File" +resizable = true +mode = 0 +access = 2 +filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library" ) +current_dir = "D:/GitHub/Pixelorama" +current_path = "D:/GitHub/Pixelorama/" diff --git a/Scripts/EditPalettePopup.gd b/Scripts/EditPalettePopup.gd index ba6d7d354..3b75fe658 100644 --- a/Scripts/EditPalettePopup.gd +++ b/Scripts/EditPalettePopup.gd @@ -103,13 +103,13 @@ func _on_EditPaletteCancelButton_pressed() -> 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: