diff --git a/Assets/Graphics/Palette/swatch_drag_preview.png b/Assets/Graphics/Palette/swatch_drag_preview.png new file mode 100644 index 000000000..401e48029 Binary files /dev/null and b/Assets/Graphics/Palette/swatch_drag_preview.png differ diff --git a/Assets/Graphics/Palette/swatch_drag_preview.png.import b/Assets/Graphics/Palette/swatch_drag_preview.png.import new file mode 100644 index 000000000..a44fda04f --- /dev/null +++ b/Assets/Graphics/Palette/swatch_drag_preview.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/swatch_drag_preview.png-4e3b034338643b2d9a5d7daa883dd850.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Graphics/Palette/swatch_drag_preview.png" +dest_files=[ "res://.import/swatch_drag_preview.png-4e3b034338643b2d9a5d7daa883dd850.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 11f3fcda8..9af7c1b2b 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=61 format=2] +[gd_scene load_steps=62 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] @@ -43,6 +43,7 @@ [ext_resource path="res://Assets/Graphics/Canvas_split.png" type="Texture" id=41] [ext_resource path="res://Assets/Graphics/Canvas_unsplit.png" type="Texture" id=42] [ext_resource path="res://Scripts/AboutDialog.gd" type="Script" id=43] +[ext_resource path="res://Scripts/EditPalettePopup.gd" type="Script" id=44] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.223529, 0.223529, 0.243137, 1 ) @@ -133,6 +134,7 @@ anchor_bottom = 1.0 custom_constants/separation = 0 [node name="MenuContainer" type="Panel" parent="MenuAndUI"] +editor/display_folded = true margin_right = 1152.0 margin_bottom = 28.0 rect_min_size = Vector2( 0, 28 ) @@ -208,7 +210,6 @@ size_flags_vertical = 3 custom_constants/separation = 0 [node name="ToolPanel" type="Panel" parent="MenuAndUI/UI"] -editor/display_folded = true margin_right = 224.0 margin_bottom = 620.0 rect_min_size = Vector2( 224, 0 ) @@ -336,7 +337,6 @@ button_mask = 3 texture_normal = ExtResource( 8 ) [node name="ColorAndToolOptions" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools"] -editor/display_folded = true margin_top = 159.0 margin_right = 208.0 margin_bottom = 612.0 @@ -345,7 +345,6 @@ custom_constants/separation = 8 alignment = 1 [node name="ColorPickersCenter" type="CenterContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ColorAndToolOptions"] -editor/display_folded = true margin_top = 35.0 margin_right = 208.0 margin_bottom = 67.0 @@ -366,7 +365,6 @@ size_flags_vertical = 0 flat = true [node name="ColorButtonsCenter" type="CenterContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ColorAndToolOptions/ColorPickersCenter/ColorPickersHorizontal"] -editor/display_folded = true margin_left = 68.0 margin_right = 85.0 margin_bottom = 32.0 @@ -772,6 +770,7 @@ mouse_default_cursor_shape = 2 text = "Vertical" [node name="CanvasAndTimeline" type="VBoxContainer" parent="MenuAndUI/UI"] +editor/display_folded = true margin_left = 224.0 margin_right = 928.0 margin_bottom = 620.0 @@ -1285,7 +1284,9 @@ texture_disabled = ExtResource( 31 ) margin_left = 72.0 margin_right = 187.0 margin_bottom = 32.0 +grow_horizontal = 0 size_flags_horizontal = 3 +clip_text = true [node name="EditPalette" type="Button" parent="MenuAndUI/UI/LayerPanel/LayersAndMisc/PaletteVBoxContainer/PaletteButtons"] margin_left = 191.0 @@ -1381,7 +1382,7 @@ text = "Image Size" [node name="OptionsContainer" type="GridContainer" parent="CreateNewImage/VBoxContainer"] margin_top = 19.0 margin_right = 184.0 -margin_bottom = 98.0 +margin_bottom = 90.0 columns = 2 [node name="WidthLabel" type="Label" parent="CreateNewImage/VBoxContainer/OptionsContainer"] @@ -1391,8 +1392,8 @@ margin_bottom = 20.0 text = "Width:" [node name="WidthValue" type="SpinBox" parent="CreateNewImage/VBoxContainer/OptionsContainer"] -margin_left = 79.0 -margin_right = 143.0 +margin_left = 75.0 +margin_right = 139.0 margin_bottom = 25.0 min_value = 1.0 max_value = 16384.0 @@ -1400,32 +1401,32 @@ value = 64.0 suffix = "px" [node name="Height" type="Label" parent="CreateNewImage/VBoxContainer/OptionsContainer"] -margin_top = 34.0 +margin_top = 30.0 margin_right = 75.0 -margin_bottom = 49.0 +margin_bottom = 45.0 text = "Height:" [node name="HeightValue" type="SpinBox" parent="CreateNewImage/VBoxContainer/OptionsContainer"] -margin_left = 79.0 -margin_top = 29.0 -margin_right = 143.0 -margin_bottom = 54.0 +margin_left = 75.0 +margin_top = 25.0 +margin_right = 139.0 +margin_bottom = 50.0 min_value = 1.0 max_value = 16384.0 value = 64.0 suffix = "px" [node name="FillColorLabel" type="Label" parent="CreateNewImage/VBoxContainer/OptionsContainer"] -margin_top = 61.0 +margin_top = 53.0 margin_right = 75.0 -margin_bottom = 76.0 +margin_bottom = 68.0 text = "Fill with color:" [node name="FillColor" type="ColorPickerButton" parent="CreateNewImage/VBoxContainer/OptionsContainer"] -margin_left = 79.0 -margin_top = 58.0 -margin_right = 143.0 -margin_bottom = 79.0 +margin_left = 75.0 +margin_top = 50.0 +margin_right = 139.0 +margin_bottom = 71.0 rect_min_size = Vector2( 64, 20 ) color = Color( 0, 0, 0, 0 ) @@ -1503,7 +1504,7 @@ text = "Image Size" editor/display_folded = true margin_top = 19.0 margin_right = 184.0 -margin_bottom = 98.0 +margin_bottom = 90.0 columns = 2 [node name="WidthLabel" type="Label" parent="ScaleImage/VBoxContainer/OptionsContainer"] @@ -1513,8 +1514,8 @@ margin_bottom = 20.0 text = "Width:" [node name="WidthValue" type="SpinBox" parent="ScaleImage/VBoxContainer/OptionsContainer"] -margin_left = 76.0 -margin_right = 159.0 +margin_left = 72.0 +margin_right = 155.0 margin_bottom = 25.0 min_value = 1.0 max_value = 16384.0 @@ -1522,32 +1523,32 @@ value = 64.0 suffix = "px" [node name="Height" type="Label" parent="ScaleImage/VBoxContainer/OptionsContainer"] -margin_top = 34.0 +margin_top = 30.0 margin_right = 72.0 -margin_bottom = 49.0 +margin_bottom = 45.0 text = "Height:" [node name="HeightValue" type="SpinBox" parent="ScaleImage/VBoxContainer/OptionsContainer"] -margin_left = 76.0 -margin_top = 29.0 -margin_right = 159.0 -margin_bottom = 54.0 +margin_left = 72.0 +margin_top = 25.0 +margin_right = 155.0 +margin_bottom = 50.0 min_value = 1.0 max_value = 16384.0 value = 64.0 suffix = "px" [node name="InterpolationLabel" type="Label" parent="ScaleImage/VBoxContainer/OptionsContainer"] -margin_top = 61.0 +margin_top = 53.0 margin_right = 72.0 -margin_bottom = 76.0 +margin_bottom = 68.0 text = "Interpolation:" [node name="InterpolationType" type="OptionButton" parent="ScaleImage/VBoxContainer/OptionsContainer"] -margin_left = 76.0 -margin_top = 58.0 -margin_right = 159.0 -margin_bottom = 79.0 +margin_left = 72.0 +margin_top = 50.0 +margin_right = 155.0 +margin_bottom = 71.0 text = "Nearest" items = [ "Nearest", null, false, 0, null, "Bilinear", null, false, 1, null, "Cubic", null, false, 2, null, "Trilinear", null, false, 3, null, "Lanczos", null, true, 4, null ] selected = 0 @@ -1568,7 +1569,7 @@ margin_right = 92.0 margin_bottom = 33.0 [node name="OptionsContainer" type="GridContainer" parent="PreferencesDialog/VBoxContainer"] -margin_right = 184.0 +margin_right = 195.0 margin_bottom = 21.0 columns = 2 @@ -1579,8 +1580,8 @@ margin_bottom = 18.0 text = "Language:" [node name="LanguageOption" type="OptionButton" parent="PreferencesDialog/VBoxContainer/OptionsContainer"] -margin_left = 61.0 -margin_right = 142.0 +margin_left = 57.0 +margin_right = 195.0 margin_bottom = 21.0 text = "System Language" items = [ "System Language", null, false, 0, null, "German [de]", null, false, 1, null, "Greek [el]", null, false, 2, null, "English [en]", null, false, 3, null, "French [fr]", null, false, 4, null ] @@ -1588,14 +1589,14 @@ selected = 0 [node name="GridOptionsLabel" type="Label" parent="PreferencesDialog/VBoxContainer"] margin_top = 25.0 -margin_right = 184.0 +margin_right = 195.0 margin_bottom = 40.0 text = "Grid options" [node name="GridOptions" type="GridContainer" parent="PreferencesDialog/VBoxContainer"] margin_top = 44.0 -margin_right = 184.0 -margin_bottom = 123.0 +margin_right = 195.0 +margin_bottom = 115.0 columns = 2 [node name="WidthLabel" type="Label" parent="PreferencesDialog/VBoxContainer/GridOptions"] @@ -1605,8 +1606,8 @@ margin_bottom = 20.0 text = "Width:" [node name="GridWidthValue" type="SpinBox" parent="PreferencesDialog/VBoxContainer/GridOptions"] -margin_left = 43.0 -margin_right = 107.0 +margin_left = 39.0 +margin_right = 103.0 margin_bottom = 25.0 min_value = 1.0 max_value = 16384.0 @@ -1614,32 +1615,32 @@ value = 1.0 suffix = "px" [node name="Height" type="Label" parent="PreferencesDialog/VBoxContainer/GridOptions"] -margin_top = 34.0 +margin_top = 30.0 margin_right = 39.0 -margin_bottom = 49.0 +margin_bottom = 45.0 text = "Height:" [node name="GridHeightValue" type="SpinBox" parent="PreferencesDialog/VBoxContainer/GridOptions"] -margin_left = 43.0 -margin_top = 29.0 -margin_right = 107.0 -margin_bottom = 54.0 +margin_left = 39.0 +margin_top = 25.0 +margin_right = 103.0 +margin_bottom = 50.0 min_value = 1.0 max_value = 16384.0 value = 1.0 suffix = "px" [node name="GridColorLabel" type="Label" parent="PreferencesDialog/VBoxContainer/GridOptions"] -margin_top = 61.0 +margin_top = 53.0 margin_right = 39.0 -margin_bottom = 76.0 +margin_bottom = 68.0 text = "Color:" [node name="GridColor" type="ColorPickerButton" parent="PreferencesDialog/VBoxContainer/GridOptions"] -margin_left = 43.0 -margin_top = 58.0 -margin_right = 107.0 -margin_bottom = 79.0 +margin_left = 39.0 +margin_top = 50.0 +margin_right = 103.0 +margin_bottom = 71.0 rect_min_size = Vector2( 64, 20 ) [node name="AboutDialog" type="AcceptDialog" parent="."] @@ -1665,15 +1666,15 @@ align = 1 [node name="MadeBy" type="Label" parent="AboutDialog/AboutUI"] margin_top = 37.0 margin_right = 268.0 -margin_bottom = 70.0 +margin_bottom = 52.0 text = "MADEBY_LABEL" align = 1 [node name="Links" type="CenterContainer" parent="AboutDialog/AboutUI"] editor/display_folded = true -margin_top = 74.0 +margin_top = 56.0 margin_right = 268.0 -margin_bottom = 95.0 +margin_bottom = 77.0 [node name="LinkButtons" type="HBoxContainer" parent="AboutDialog/AboutUI/Links"] editor/display_folded = true @@ -1699,9 +1700,9 @@ margin_bottom = 21.0 text = "Donate" [node name="Copyright" type="Label" parent="AboutDialog/AboutUI"] -margin_top = 99.0 +margin_top = 81.0 margin_right = 268.0 -margin_bottom = 132.0 +margin_bottom = 114.0 text = " Copyright 2019 - Orama Interactive" align = 1 @@ -1712,6 +1713,143 @@ margin_bottom = 70.0 resizable = true dialog_text = "QUIT_LABEL" +[node name="ErrorDialog" type="AcceptDialog" parent="."] +margin_right = 76.0 +margin_bottom = 60.0 +window_title = "Error!" +dialog_text = "This is an error message!" + +[node name="EditPalettePopup" type="WindowDialog" parent="."] +visible = true +margin_right = 600.0 +margin_bottom = 550.0 +rect_min_size = Vector2( 600, 550 ) +window_title = "Edit Palette" +script = ExtResource( 44 ) + +[node name="VBoxContainer" type="VBoxContainer" parent="EditPalettePopup"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_left = 10.0 +margin_top = 10.0 +margin_right = -10.0 +margin_bottom = -10.0 +size_flags_horizontal = 3 + +[node name="HBoxContainer" type="HBoxContainer" parent="EditPalettePopup/VBoxContainer"] +margin_right = 580.0 +margin_bottom = 476.0 +size_flags_vertical = 3 + +[node name="EditPaletteColorPicker" type="ColorPicker" parent="EditPalettePopup/VBoxContainer/HBoxContainer"] +margin_right = 290.0 +margin_bottom = 476.0 + +[node name="Panel" type="Panel" parent="EditPalettePopup/VBoxContainer/HBoxContainer"] +margin_left = 294.0 +margin_right = 540.0 +margin_bottom = 476.0 +size_flags_horizontal = 3 + +[node name="EditPaletteGridContainer" type="GridContainer" parent="EditPalettePopup/VBoxContainer/HBoxContainer/Panel"] +anchor_right = 1.0 +anchor_bottom = 1.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +columns = 8 + +[node name="VBoxContainer" type="VBoxContainer" parent="EditPalettePopup/VBoxContainer/HBoxContainer"] +margin_left = 544.0 +margin_right = 580.0 +margin_bottom = 476.0 + +[node name="AddSwatchButton" type="TextureButton" parent="EditPalettePopup/VBoxContainer/HBoxContainer/VBoxContainer"] +margin_right = 36.0 +margin_bottom = 36.0 +texture_normal = ExtResource( 28 ) + +[node name="RemoveSwatchButton" type="TextureButton" parent="EditPalettePopup/VBoxContainer/HBoxContainer/VBoxContainer"] +margin_top = 40.0 +margin_right = 36.0 +margin_bottom = 72.0 +texture_normal = ExtResource( 30 ) + +[node name="HBoxContainer3" type="HBoxContainer" parent="EditPalettePopup/VBoxContainer"] +margin_top = 480.0 +margin_right = 580.0 +margin_bottom = 505.0 + +[node name="Label" type="Label" parent="EditPalettePopup/VBoxContainer/HBoxContainer3"] +margin_top = 5.0 +margin_right = 68.0 +margin_bottom = 20.0 +text = "Color Name:" + +[node name="EditPaletteColorNameLineEdit" type="LineEdit" parent="EditPalettePopup/VBoxContainer/HBoxContainer3"] +margin_left = 72.0 +margin_right = 580.0 +margin_bottom = 25.0 +size_flags_horizontal = 3 + +[node name="HBoxContainer2" type="HBoxContainer" parent="EditPalettePopup/VBoxContainer"] +margin_top = 509.0 +margin_right = 580.0 +margin_bottom = 530.0 +size_flags_horizontal = 3 + +[node name="SpacerControl" type="Control" parent="EditPalettePopup/VBoxContainer/HBoxContainer2"] +margin_right = 159.0 +margin_bottom = 21.0 +size_flags_horizontal = 3 + +[node name="EditPaletteSaveButton" type="Button" parent="EditPalettePopup/VBoxContainer/HBoxContainer2"] +margin_left = 163.0 +margin_right = 201.0 +margin_bottom = 21.0 +text = "Save" + +[node name="SpacerControl2" type="Control" parent="EditPalettePopup/VBoxContainer/HBoxContainer2"] +margin_left = 205.0 +margin_right = 364.0 +margin_bottom = 21.0 +size_flags_horizontal = 3 + +[node name="EditPaletteCancelButton" type="Button" parent="EditPalettePopup/VBoxContainer/HBoxContainer2"] +margin_left = 368.0 +margin_right = 417.0 +margin_bottom = 21.0 +text = "Cancel" + +[node name="SpacerControl3" type="Control" parent="EditPalettePopup/VBoxContainer/HBoxContainer2"] +margin_left = 421.0 +margin_right = 580.0 +margin_bottom = 21.0 +size_flags_horizontal = 3 + +[node name="NewPaletteDialog" type="ConfirmationDialog" parent="."] +margin_right = 200.0 +margin_bottom = 70.0 +window_title = "Create a new custom palette from existing default?" + +[node name="HBoxContainer2" type="HBoxContainer" parent="NewPaletteDialog"] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 315.0 +margin_bottom = 33.0 + +[node name="Label" type="Label" parent="NewPaletteDialog/HBoxContainer2"] +margin_top = 5.0 +margin_right = 77.0 +margin_bottom = 20.0 +text = "Palette Name:" + +[node name="NewPaletteNameLineEdit" type="LineEdit" parent="NewPaletteDialog/HBoxContainer2"] +margin_left = 81.0 +margin_right = 192.0 +margin_bottom = 25.0 +size_flags_horizontal = 3 +expand_to_text_length = true + [node name="AnimationTimer" type="Timer" parent="."] [node name="LeftCursor" type="Sprite" parent="."] @@ -1770,7 +1908,9 @@ visible = false [connection signal="pressed" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/LayerVBoxContainer/CenterLayerButtons/LayerButtons/CloneLayer" to="." method="add_layer" binds= [ false ]] [connection signal="pressed" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/LayerVBoxContainer/CenterLayerButtons/LayerButtons/MergeDownLayer" to="." method="_on_MergeLayer_pressed"] [connection signal="pressed" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/PaletteVBoxContainer/PaletteButtons/AddPalette" to="." method="_on_AddPalette_pressed"] +[connection signal="pressed" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/PaletteVBoxContainer/PaletteButtons/RemovePalette" to="." method="_on_RemovePalette_pressed"] [connection signal="item_selected" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/PaletteVBoxContainer/PaletteButtons/PaletteOptionButton" to="." method="_on_PaletteOptionButton_item_selected"] +[connection signal="pressed" from="MenuAndUI/UI/LayerPanel/LayersAndMisc/PaletteVBoxContainer/PaletteButtons/EditPalette" to="." method="_on_EditPalette_pressed"] [connection signal="toggled" from="SplitScreenButton" to="." method="_on_SplitScreenButton_toggled"] [connection signal="confirmed" from="CreateNewImage" to="." method="_on_CreateNewImage_confirmed"] [connection signal="popup_hide" from="CreateNewImage" to="." method="_can_draw_true"] @@ -1795,4 +1935,11 @@ visible = false [connection signal="pressed" from="AboutDialog/AboutUI/Links/LinkButtons/Donate" to="AboutDialog" method="_on_Donate_pressed"] [connection signal="confirmed" from="QuitDialog" to="." method="_on_QuitDialog_confirmed"] [connection signal="popup_hide" from="QuitDialog" to="." method="_can_draw_true"] +[connection signal="color_changed" from="EditPalettePopup/VBoxContainer/HBoxContainer/EditPaletteColorPicker" to="EditPalettePopup" method="_on_EditPaletteColorPicker_color_changed"] +[connection signal="pressed" from="EditPalettePopup/VBoxContainer/HBoxContainer/VBoxContainer/AddSwatchButton" to="EditPalettePopup" method="_on_AddSwatchButton_pressed"] +[connection signal="pressed" from="EditPalettePopup/VBoxContainer/HBoxContainer/VBoxContainer/RemoveSwatchButton" to="EditPalettePopup" method="_on_RemoveSwatchButton_pressed"] +[connection signal="text_changed" from="EditPalettePopup/VBoxContainer/HBoxContainer3/EditPaletteColorNameLineEdit" to="EditPalettePopup" method="_on_EditPaletteColorNameLineEdit_text_changed"] +[connection signal="pressed" from="EditPalettePopup/VBoxContainer/HBoxContainer2/EditPaletteSaveButton" to="EditPalettePopup" method="_on_EditPaletteSaveButton_pressed"] +[connection signal="pressed" from="EditPalettePopup/VBoxContainer/HBoxContainer2/EditPaletteCancelButton" to="EditPalettePopup" method="_on_EditPaletteCancelButton_pressed"] +[connection signal="confirmed" from="NewPaletteDialog" to="." method="_on_NewPaletteDialog_confirmed"] [connection signal="timeout" from="AnimationTimer" to="." method="_on_AnimationTimer_timeout"] diff --git a/Prefabs/PaletteButton.tscn b/Prefabs/PaletteButton.tscn index 81c6fc731..fc1c63245 100644 --- a/Prefabs/PaletteButton.tscn +++ b/Prefabs/PaletteButton.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_hover.tres" type="StyleBox" id=1] [ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_pressedr.tres" type="StyleBox" id=2] -[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_normal.tres" type="StyleBox" id=3] -[ext_resource path="res://Assets/Graphics/Palette/palette_button_fill.png" type="Texture" id=4] +[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_focus.tres" type="StyleBox" id=3] +[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_normal.tres" type="StyleBox" id=4] +[ext_resource path="res://Scripts/PaletteButton.gd" type="Script" id=5] +[ext_resource path="res://Assets/Graphics/Palette/palette_button_fill.png" type="Texture" id=6] [sub_resource type="ImageTexture" id=1] @@ -14,9 +16,11 @@ rect_min_size = Vector2( 26, 26 ) hint_tooltip = "Color Name" custom_styles/hover = ExtResource( 1 ) custom_styles/pressed = ExtResource( 2 ) -custom_styles/normal = ExtResource( 3 ) +custom_styles/focus = ExtResource( 3 ) +custom_styles/normal = ExtResource( 4 ) button_mask = 3 icon = SubResource( 1 ) +script = ExtResource( 5 ) [node name="NinePatchRect" type="NinePatchRect" parent="."] anchor_right = 1.0 @@ -27,7 +31,7 @@ margin_right = -1.0 margin_bottom = -1.0 size_flags_horizontal = 3 size_flags_vertical = 3 -texture = ExtResource( 4 ) +texture = ExtResource( 6 ) patch_margin_left = 2 patch_margin_top = 2 patch_margin_right = 2 diff --git a/Scripts/EditPalettePopup.gd b/Scripts/EditPalettePopup.gd new file mode 100644 index 000000000..d48cad0e9 --- /dev/null +++ b/Scripts/EditPalettePopup.gd @@ -0,0 +1,131 @@ +extends WindowDialog + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +onready var palette_grid = $VBoxContainer/HBoxContainer/Panel/EditPaletteGridContainer +onready var color_name_edit = $VBoxContainer/HBoxContainer3/EditPaletteColorNameLineEdit +onready var color_picker = $VBoxContainer/HBoxContainer/EditPaletteColorPicker + +var palette_button = preload("res://Prefabs/PaletteButton.tscn"); + +var current_palette : String +var current_swatch := -1 +var working_palette : Dictionary + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func open(palette : String) -> void: + current_palette = palette + if Global.palettes.has(palette): + working_palette = Global.palettes[palette].duplicate() + + _display_palette() + + self.popup_centered() + pass + +func _display_palette() -> void: + _clear_swatches() + var index := 0 + + for color_data in working_palette.colors: + var color = Color(color_data.data) + var new_button = palette_button.instance() + + new_button.color = color + new_button.get_child(0).modulate = color + new_button.hint_tooltip = color_data.data.to_upper() + " " + color_data.name + new_button.draggable = true + new_button.index = index + new_button.connect("on_drop_data", self, "on_move_swatch") + new_button.connect("pressed", self, "on_swatch_select", [index]) + + palette_grid.add_child(new_button) + index += 1 + +func _clear_swatches() -> void: + for child in palette_grid.get_children(): + if child is BaseButton: + child.disconnect("on_drop_data", self, "on_move_swatch") + child.queue_free() + +func on_swatch_select(index : int) -> void: + current_swatch = index + color_name_edit.text = working_palette.colors[index].name + color_picker.color = working_palette.colors[index].data + pass + +func on_move_swatch(from : int, to : int) -> void: + var color_to_move = working_palette.colors[from] + working_palette.colors.remove(from) + working_palette.colors.insert(to, color_to_move) + + palette_grid.move_child(palette_grid.get_child(from), to) + + # Re-index swatches with new order + var index := 0 + for child in palette_grid.get_children(): + child.index = index + index += 1 + pass + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass + +func _on_AddSwatchButton_pressed() -> void: + var color = Color.white + var color_data = {} + color_data.data = color.to_html(true) + color_data.name = "no name" + working_palette.colors.push_back(color_data) + var new_button = palette_button.instance() + + new_button.color = color + new_button.get_child(0).modulate = color + new_button.hint_tooltip = color_data.data.to_upper() + " " + color_data.name + new_button.draggable = true + var index : int = palette_grid.get_child_count() + new_button.index = index + new_button.connect("on_drop_data", self, "on_move_swatch") + new_button.connect("pressed", self, "on_swatch_select", [index]) + + palette_grid.add_child(new_button) + pass # Replace with function body. + +func _on_RemoveSwatchButton_pressed() -> void: + working_palette.colors.remove(current_swatch) + palette_grid.remove_child(palette_grid.get_child(current_swatch)) + pass # Replace with function body. + +func _on_EditPaletteSaveButton_pressed() -> void: + Global.palettes[current_palette] = working_palette + Global.palette_container.on_palette_select(current_palette) + Global.palette_container.save_palette(current_palette, working_palette.name + ".json") + self.hide() + pass # Replace with function body. + +func _on_EditPaletteCancelButton_pressed() -> void: + self.hide() + pass # Replace with function body. + +func _on_EditPaletteColorNameLineEdit_text_changed(new_text) -> void: + 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(): + 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) + pass + +func _refresh_hint_tooltip(index : int): + palette_grid.get_child(current_swatch).hint_tooltip = working_palette.colors[current_swatch].data.to_upper() + " " + working_palette.colors[current_swatch].name + pass diff --git a/Scripts/Global.gd b/Scripts/Global.gd index 6d2fa37bf..2e626c392 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -187,6 +187,11 @@ var remove_palette_button : TextureButton var palette_option_button : OptionButton var edit_palette_button : BaseButton var palette_container : GridContainer +var edit_palette_popup : WindowDialog +var new_palette_dialog : ConfirmationDialog +var new_palette_name_line_edit : LineEdit + +var error_dialog : AcceptDialog func _ready() -> void: undo_redo = UndoRedo.new() @@ -275,6 +280,11 @@ func _ready() -> void: palette_option_button = find_node_by_name(root, "PaletteOptionButton") edit_palette_button = find_node_by_name(root, "EditPalette") palette_container = find_node_by_name(root, "PaletteContainer") + 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") + + error_dialog = find_node_by_name(root, "ErrorDialog") #Thanks to https://godotengine.org/qa/17524/how-to-find-an-instanced-scene-by-its-name func find_node_by_name(root, node_name) -> Node: diff --git a/Scripts/Main.gd b/Scripts/Main.gd index d6676e46a..b87ef4d3c 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -1047,3 +1047,16 @@ func _exit_tree() -> void: func _on_PaletteOptionButton_item_selected(ID) -> void: var palette_name = Global.palette_option_button.get_item_metadata(ID) Global.palette_container.on_palette_select(palette_name) + +func _on_EditPalette_pressed() -> void: + Global.palette_container.on_edit_palette() + pass + +func _on_RemovePalette_pressed() -> void: + Global.palette_container.remove_current_palette() + pass + +func _on_NewPaletteDialog_confirmed() -> void: + Global.palette_container.on_new_palette_confirmed() + pass + diff --git a/Scripts/PaletteButton.gd b/Scripts/PaletteButton.gd new file mode 100644 index 000000000..492bda68a --- /dev/null +++ b/Scripts/PaletteButton.gd @@ -0,0 +1,39 @@ +extends Button + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +signal on_drop_data + +export var index := 0; +export var color : Color = Color.white +export var draggable := false + +var drag_preview_texture = preload("res://Assets/Graphics/Palette/swatch_drag_preview.png") + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func get_drag_data(position): + var data = null; + if(draggable): + #print(String(get_instance_id()) + ": Drag Start"); + data = {source_index = index}; + var drag_icon = TextureRect.new(); + drag_icon.texture = drag_preview_texture; + drag_icon.modulate = color + set_drag_preview(drag_icon); + return data; + +func can_drop_data(position, data): + return true; + +func drop_data(position, data): + emit_signal("on_drop_data", data.source_index, index); + pass; + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/Scripts/PaletteContainer.gd b/Scripts/PaletteContainer.gd index 3019cdd12..7759f8ce9 100644 --- a/Scripts/PaletteContainer.gd +++ b/Scripts/PaletteContainer.gd @@ -3,6 +3,7 @@ extends GridContainer var palette_button = preload("res://Prefabs/PaletteButton.tscn"); var current_palette = "Default" +var from_palette : = {} # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -24,8 +25,8 @@ func on_palette_select(palette_name : String) -> void: var palette : Dictionary = Global.palettes[palette_name] Global.remove_palette_button.disabled = true # Cannot remove by default - if(palette.has("editable")): - if(palette.editable): + if palette.has("editable"): + if palette.editable: Global.remove_palette_button.disabled = false # Can remove if custom palette _display_palette(palette) @@ -33,6 +34,62 @@ func on_palette_select(palette_name : String) -> void: current_palette = "Default" _display_palette(Global.palettes["Default"]) +func on_edit_palette() -> void: + var palette : Dictionary = Global.palettes[current_palette] + + var create_new_palette := true # Create new palette by default + if palette.has("editable"): + if palette.editable: + create_new_palette = false # Edit if already a custom palette + + if create_new_palette: + from_palette = Global.palettes[current_palette] + Global.new_palette_name_line_edit.text = "Custom_" + current_palette + Global.new_palette_dialog.popup_centered() + else: + from_palette = {} + Global.edit_palette_popup.open(current_palette) + +func on_new_palette_confirmed() -> void: + var new_palette_name : String = Global.new_palette_name_line_edit.text + var result : String = create_new_palette(new_palette_name, from_palette) + if not result.empty(): + Global.error_dialog.set_text(result); + Global.error_dialog.popup_centered() + +func create_new_palette(name : String, from_palette : Dictionary = {}) -> String: # Returns empty string, else error string + var new_palette : Dictionary = {} + + # Check if new name is valid + if name.empty(): + return "Error: Palette must have a valid name." + if Global.palettes.has(name): + return "Error: Palette '" + name + "' already exists!" + + new_palette.name = name + + # Check if source palette has data + if from_palette.has("name"): + new_palette = from_palette.duplicate() + new_palette.name = name + new_palette.editable = true + else: + new_palette.colors = [] + new_palette.comments = "" + new_palette.editable = true + + # Add palette to Global and options + Global.palettes[name] = new_palette + Global.palette_option_button.add_item(name) + var index := Global.palette_option_button.get_item_count() - 1 + Global.palette_option_button.set_item_metadata(index, name) + Global.palette_option_button.select(index) + + save_palette(name, name + ".json") + + on_palette_select(name) + return "" + func _display_palette(palette : Dictionary) -> void: var index := 0 @@ -58,29 +115,17 @@ func on_color_select(index : int) -> void: Global.update_right_custom_brush() func _load_palettes() -> void: - var files := [] - var dir := Directory.new() if not dir.dir_exists("user://palettes"): dir.make_dir("user://palettes"); - dir.make_dir("user://palettes/custom"); + dir.make_dir("user://custom/palettes") dir.copy("res://Assets/Graphics/Palette/default_palette.json","user://palettes/default_palette.json"); dir.copy("res://Assets/Graphics/Palette/bubblegum16.json","user://palettes/bubblegum16.json"); - dir.open("user://palettes") - dir.list_dir_begin() + var palette_files : Array = get_palette_files("user://palettes") - while true: - var file_name = dir.get_next() - if file_name == "": - break - elif not file_name.begins_with(".") && file_name.to_lower().ends_with("json"): - files.append(file_name) - - dir.list_dir_end() - - for file_name in files: + for file_name in palette_files: var result : String = load_palette("user://palettes/" + file_name) if result: Global.palette_option_button.add_item(result) @@ -88,9 +133,34 @@ func _load_palettes() -> void: Global.palette_option_button.set_item_metadata(index, result) if result == "Default": Global.palette_option_button.select(index) + + dir.open("user://palettes/custom") + var custom_palette_files : Array = get_palette_files("user://palettes/custom") + + for file_name in custom_palette_files: + var result : String = load_palette("user://palettes/custom/" + file_name) + if result: + Global.palette_option_button.add_item(result) + var index := Global.palette_option_button.get_item_count() - 1 + Global.palette_option_button.set_item_metadata(index, result) - for item in Global.palette_option_button.items: - print(item) +func get_palette_files(path : String) -> Array: + var dir := Directory.new() + var results = [] + + dir.open(path) + dir.list_dir_begin() + + while true: + var file_name = dir.get_next() + if file_name == "": + break + elif not file_name.begins_with(".") && file_name.to_lower().ends_with("json"): + results.append(file_name) + + dir.list_dir_end() + + return results func load_palette(path : String) -> String: # Open file for reading @@ -117,11 +187,28 @@ func load_palette(path : String) -> String: return palette_name -func _save_palette(palette : Dictionary, name : String, path : String) -> void: +func remove_current_palette() -> void: + if Global.palettes[current_palette].has("editable"): + if Global.palettes[current_palette].editable: + _delete_palette_file(current_palette + ".json") + Global.palettes.erase(current_palette) + var selected_index := Global.palette_option_button.selected + Global.palette_option_button.remove_item(selected_index) + if(selected_index - 1 >= 0): + Global.palette_option_button.select(selected_index - 1) + on_palette_select(Global.palette_option_button.get_item_metadata(selected_index - 1)) + pass + +func _delete_palette_file(file_name : String) -> void: + var dir = Directory.new() + dir.remove("user://palettes/custom/" + file_name) + +func save_palette(palette_name : String, filename : String) -> void: + var palette_data = Global.palettes[palette_name] # Open file for writing var file := File.new() - file.open(path, File.WRITE) + file.open("user://palettes/custom/" + filename, File.WRITE) # Write palette data to file - file.store_string(JSON.print(palette)) + file.store_string(JSON.print(palette_data)) file.close() diff --git a/Themes & Styles/StyleBoxes/palette_stylebox_focus.tres b/Themes & Styles/StyleBoxes/palette_stylebox_focus.tres new file mode 100644 index 000000000..b734ad9a2 --- /dev/null +++ b/Themes & Styles/StyleBoxes/palette_stylebox_focus.tres @@ -0,0 +1,11 @@ +[gd_resource type="StyleBoxTexture" load_steps=2 format=2] + +[ext_resource path="res://Assets/Graphics/Palette/palette_button.png" type="Texture" id=1] + +[resource] +texture = ExtResource( 1 ) +region_rect = Rect2( 0, 0, 8, 8 ) +margin_left = 2.0 +margin_right = 2.0 +margin_top = 2.0 +margin_bottom = 2.0