From 051f3df147763eed66d4c8647846be2eb4fae8eb Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 29 Jul 2020 03:16:02 +0300 Subject: [PATCH] Buttons to reset preferences to default Similar functionality with Godot's default buttons. The buttons currently aren't visible with the gold & light themes. --- CHANGELOG.md | 2 + Translations/Translations.pot | 3 + .../graphics/dark_themes/misc/icon_reload.png | Bin 0 -> 234 bytes .../dark_themes/misc/icon_reload.png.import | 34 ++++++ src/Autoload/Global.gd | 2 +- src/Preferences/PreferencesDialog.gd | 85 ++++++++++----- src/Preferences/PreferencesDialog.tscn | 97 ++++++++++-------- src/Preferences/RestoreDefaultButton.gd | 15 +++ src/Preferences/RestoreDefaultButton.tscn | 18 ++++ 9 files changed, 185 insertions(+), 71 deletions(-) create mode 100644 assets/graphics/dark_themes/misc/icon_reload.png create mode 100644 assets/graphics/dark_themes/misc/icon_reload.png.import create mode 100644 src/Preferences/RestoreDefaultButton.gd create mode 100644 src/Preferences/RestoreDefaultButton.tscn diff --git a/CHANGELOG.md b/CHANGELOG.md index 7356e399f..5f34d1933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Darshan Phaldesai (luiq54), Igor Santarek (jegor377), rob-a-bolton, Kinwailo - You can now preview how the frames of the spritesheet you are importing will look. - You can now import image files as layers. Their size will be cropped to the project's size. - You can import image files as brushes, patterns and palettes. +- Buttons have been added in Preferences to restore each setting to its default state. - Added "Copy", "Paste" and "Delete" options in the Edit menu. ([#281](https://github.com/Orama-Interactive/Pixelorama/pull/281)) - Selection region and size are now being shown when making a selection on the top, next to the position label. ([#281](https://github.com/Orama-Interactive/Pixelorama/pull/281)) - Added color overwrite option for the Pencil tool. ([#282](https://github.com/Orama-Interactive/Pixelorama/pull/282)) @@ -39,6 +40,7 @@ Darshan Phaldesai (luiq54), Igor Santarek (jegor377), rob-a-bolton, Kinwailo - Pixelorama now remembers the selected colors, tools and their options when it's closed and re-opened. ([#281](https://github.com/Orama-Interactive/Pixelorama/pull/281)) - Drawing brushes with mirror also mirrors the images of the brushes themselves. ([#281](https://github.com/Orama-Interactive/Pixelorama/pull/281)) - When making a new palette or importing one and its name already exists, Pixelorama will add a number to its name. For example, "Palette_Name" would become "Palette_Name (2)", "Palette_Name (3)", etc. +- Re-organized preferences dialog. - The "create new image" dialog now remembers the last created canvas size. The default image settings are being used only when Pixelorama first launches. ([#178](https://github.com/Orama-Interactive/Pixelorama/issues/178)) - Language and theme checkboxes are now radio buttons. - The Blue theme has more similar margins and seperations with the rest of the themes. diff --git a/Translations/Translations.pot b/Translations/Translations.pot index 08cd1617a..3abe16df6 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -359,6 +359,9 @@ msgstr "" msgid "On" msgstr "" +msgid "Restore default value" +msgstr "" + msgid "Smooth Zoom" msgstr "" diff --git a/assets/graphics/dark_themes/misc/icon_reload.png b/assets/graphics/dark_themes/misc/icon_reload.png new file mode 100644 index 0000000000000000000000000000000000000000..bec5f3f4f982aec6ee693b72171772c1329d9a3e GIT binary patch literal 234 zcmVkeSjV$l-!b}0tp@G;0b9J z_gGFq!oygKwlUE;*eC6STNE>WJ-bC+5>=N3Hc%n_}4*K1v0FY0M(BYmN!T void: @@ -43,46 +44,64 @@ func _ready() -> void: for pref in preferences: var node = right_side.get_node(pref[1]) + var node_position = node.get_index() + + var restore_default_button : BaseButton = restore_default_button_scene.instance() + restore_default_button.setting_name = pref[0] + restore_default_button.value_type = pref[2] + restore_default_button.default_value = pref[3] + restore_default_button.node = node + node.get_parent().add_child(restore_default_button) + node.get_parent().move_child(restore_default_button, node_position) match pref[2]: "pressed": - node.connect("toggled", self, "_on_Preference_toggled", [pref[0]]) + node.connect("toggled", self, "_on_Preference_toggled", [pref[0], pref[3], restore_default_button]) "value": - node.connect("value_changed", self, "_on_Preference_value_changed", [pref[0]]) + node.connect("value_changed", self, "_on_Preference_value_changed", [pref[0], pref[3], restore_default_button]) "color": node.get_picker().presets_visible = false - node.connect("color_changed", self, "_on_Preference_color_changed", [pref[0]]) + node.connect("color_changed", self, "_on_Preference_color_changed", [pref[0], pref[3], restore_default_button]) "selected": - node.connect("item_selected", self, "_on_Preference_item_selected", [pref[0]]) + node.connect("item_selected", self, "_on_Preference_item_selected", [pref[0], pref[3], restore_default_button]) if Global.config_cache.has_section_key("preferences", pref[0]): var value = Global.config_cache.get_value("preferences", pref[0]) Global.set(pref[0], value) node.set(pref[2], value) + # This is needed because color_changed doesn't fire if the color changes in code + if pref[2] == "color": + preference_update(pref[0]) + disable_restore_default_button(restore_default_button, Global.get(pref[0]).is_equal_approx(pref[3])) -func _on_Preference_toggled(button_pressed : bool, prop : String) -> void: + +func _on_Preference_toggled(button_pressed : bool, prop : String, default_value, restore_default_button : BaseButton) -> void: Global.set(prop, button_pressed) Global.config_cache.set_value("preferences", prop, button_pressed) preference_update(prop) + disable_restore_default_button(restore_default_button, Global.get(prop) == default_value) -func _on_Preference_value_changed(value : float, prop : String) -> void: +func _on_Preference_value_changed(value : float, prop : String, default_value, restore_default_button : BaseButton) -> void: Global.set(prop, value) Global.config_cache.set_value("preferences", prop, value) preference_update(prop) + disable_restore_default_button(restore_default_button, Global.get(prop) == default_value) -func _on_Preference_color_changed(color : Color, prop : String) -> void: +func _on_Preference_color_changed(color : Color, prop : String, default_value, restore_default_button : BaseButton) -> void: Global.set(prop, color) Global.config_cache.set_value("preferences", prop, color) preference_update(prop) + disable_restore_default_button(restore_default_button, Global.get(prop).is_equal_approx(default_value)) -func _on_Preference_item_selected(id : int, prop : String) -> void: +func _on_Preference_item_selected(id : int, prop : String, default_value, restore_default_button : BaseButton) -> void: Global.set(prop, id) Global.config_cache.set_value("preferences", prop, id) preference_update(prop) + disable_restore_default_button(restore_default_button, Global.get(prop) == default_value) func preference_update(prop : String) -> void: @@ -108,6 +127,16 @@ func preference_update(prop : String) -> void: Global.config_cache.save("user://cache.ini") +func disable_restore_default_button(button : BaseButton, disable : bool) -> void: + button.disabled = disable + if disable: + button.mouse_default_cursor_shape = Control.CURSOR_ARROW + button.hint_tooltip = "" + else: + button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND + button.hint_tooltip = "Restore default value" + + func _on_PreferencesDialog_about_to_show(changed_language := false) -> void: if OS.get_name() != "HTML5": list.add_item(" " + tr("Startup")) diff --git a/src/Preferences/PreferencesDialog.tscn b/src/Preferences/PreferencesDialog.tscn index 04189c6f2..bf1cf19e9 100644 --- a/src/Preferences/PreferencesDialog.tscn +++ b/src/Preferences/PreferencesDialog.tscn @@ -285,23 +285,34 @@ text = "Light" [node name="Canvas" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] visible = false -margin_top = 184.0 +margin_top = 28.0 margin_right = 498.0 -margin_bottom = 484.0 +margin_bottom = 280.0 [node name="ZoomLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas"] margin_right = 498.0 margin_bottom = 14.0 text = "Zoom" -[node name="SmoothZoom" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas"] +[node name="ZoomOptions" type="HBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas"] margin_top = 18.0 margin_right = 498.0 margin_bottom = 42.0 + +[node name="Label" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/ZoomOptions"] +margin_top = 5.0 +margin_right = 90.0 +margin_bottom = 19.0 +text = "Smooth Zoom" + +[node name="SmoothZoom" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/ZoomOptions"] +margin_left = 94.0 +margin_right = 141.0 +margin_bottom = 24.0 hint_tooltip = "Adds a smoother transition when zooming in or out" mouse_default_cursor_shape = 2 pressed = true -text = "Smooth Zoom" +text = "On" [node name="HSeparator" type="HSeparator" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas"] margin_top = 46.0 @@ -320,7 +331,7 @@ margin_right = 498.0 margin_bottom = 92.0 custom_constants/vseparation = 4 custom_constants/hseparation = 4 -columns = 2 +columns = 3 [node name="GuideColorLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GuideOptions"] margin_top = 3.0 @@ -354,10 +365,10 @@ text = "Grid" [node name="GridOptions" type="GridContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas"] margin_top = 122.0 margin_right = 498.0 -margin_bottom = 198.0 +margin_bottom = 174.0 custom_constants/vseparation = 4 custom_constants/hseparation = 4 -columns = 2 +columns = 3 [node name="WidthLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"] margin_top = 5.0 @@ -382,17 +393,17 @@ align = 2 suffix = "px" [node name="Height" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"] -margin_top = 33.0 -margin_right = 110.0 -margin_bottom = 47.0 +margin_left = 192.0 +margin_top = 5.0 +margin_right = 267.0 +margin_bottom = 19.0 hint_tooltip = "Sets how far apart are horizontal lines of the grid" mouse_filter = 0 text = "Grid height:" [node name="GridHeightValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"] -margin_left = 114.0 margin_top = 28.0 -margin_right = 188.0 +margin_right = 110.0 margin_bottom = 52.0 hint_tooltip = "Sets how far apart are horizontal lines of the grid" mouse_default_cursor_shape = 2 @@ -404,40 +415,41 @@ align = 2 suffix = "px" [node name="GridColorLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"] -margin_top = 59.0 -margin_right = 110.0 -margin_bottom = 73.0 +margin_left = 114.0 +margin_top = 33.0 +margin_right = 188.0 +margin_bottom = 47.0 hint_tooltip = "A color of the grid" mouse_filter = 0 text = "Grid color:" [node name="GridColor" type="ColorPickerButton" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/GridOptions"] -margin_left = 114.0 -margin_top = 56.0 -margin_right = 188.0 -margin_bottom = 76.0 +margin_left = 192.0 +margin_top = 28.0 +margin_right = 267.0 +margin_bottom = 52.0 rect_min_size = Vector2( 64, 20 ) hint_tooltip = "A color of the grid" mouse_default_cursor_shape = 2 [node name="HSeparator3" type="HSeparator" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas"] -margin_top = 202.0 +margin_top = 178.0 margin_right = 498.0 -margin_bottom = 206.0 +margin_bottom = 182.0 [node name="TransparencyLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas"] -margin_top = 210.0 +margin_top = 186.0 margin_right = 498.0 -margin_bottom = 224.0 +margin_bottom = 200.0 text = "Transparency" [node name="CheckerOptions" type="GridContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas"] -margin_top = 228.0 +margin_top = 204.0 margin_right = 498.0 -margin_bottom = 300.0 +margin_bottom = 252.0 custom_constants/vseparation = 4 custom_constants/hseparation = 4 -columns = 2 +columns = 3 [node name="SizeLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] margin_top = 5.0 @@ -450,7 +462,7 @@ text = "Checker size:" [node name="CheckerSizeValue" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] margin_left = 114.0 -margin_right = 188.0 +margin_right = 217.0 margin_bottom = 24.0 hint_tooltip = "Size of the transparent checker background" mouse_default_cursor_shape = 2 @@ -462,17 +474,17 @@ align = 2 suffix = "px" [node name="CheckerColor1Label" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] -margin_top = 31.0 -margin_right = 110.0 -margin_bottom = 45.0 +margin_left = 221.0 +margin_top = 5.0 +margin_right = 324.0 +margin_bottom = 19.0 hint_tooltip = "First color of the transparent checker background" mouse_filter = 0 text = "Checker color 1:" [node name="CheckerColor1" type="ColorPickerButton" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] -margin_left = 114.0 margin_top = 28.0 -margin_right = 188.0 +margin_right = 110.0 margin_bottom = 48.0 rect_min_size = Vector2( 64, 20 ) hint_tooltip = "First color of the transparent checker background" @@ -480,18 +492,19 @@ mouse_default_cursor_shape = 2 color = Color( 0.470588, 0.470588, 0.470588, 1 ) [node name="CheckerColor2Label" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] -margin_top = 55.0 -margin_right = 110.0 -margin_bottom = 69.0 +margin_left = 114.0 +margin_top = 31.0 +margin_right = 217.0 +margin_bottom = 45.0 hint_tooltip = "Second color of the transparent checker background" mouse_filter = 0 text = "Checker color 2:" [node name="CheckerColor2" type="ColorPickerButton" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas/CheckerOptions"] -margin_left = 114.0 -margin_top = 52.0 -margin_right = 188.0 -margin_bottom = 72.0 +margin_left = 221.0 +margin_top = 28.0 +margin_right = 324.0 +margin_bottom = 48.0 rect_min_size = Vector2( 64, 20 ) hint_tooltip = "Second color of the transparent checker background" mouse_default_cursor_shape = 2 @@ -508,7 +521,7 @@ margin_right = 506.0 margin_bottom = 76.0 custom_constants/vseparation = 4 custom_constants/hseparation = 4 -columns = 2 +columns = 3 [node name="DefaultWidthLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Image/ImageOptions"] margin_top = 5.0 @@ -829,7 +842,7 @@ margin_bottom = 254.0 margin_top = 18.0 margin_right = 498.0 margin_bottom = 70.0 -columns = 2 +columns = 3 [node name="Label" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Backup/AutosaveContainer"] margin_top = 5.0 @@ -885,7 +898,7 @@ margin_right = 498.0 margin_bottom = 126.0 custom_constants/vseparation = 4 custom_constants/hseparation = 4 -columns = 2 +columns = 3 [node name="Label" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Indicators/IndicatorsContainer"] margin_top = 5.0 diff --git a/src/Preferences/RestoreDefaultButton.gd b/src/Preferences/RestoreDefaultButton.gd new file mode 100644 index 000000000..f9d9e727d --- /dev/null +++ b/src/Preferences/RestoreDefaultButton.gd @@ -0,0 +1,15 @@ +extends TextureButton + + +var setting_name : String +var value_type : String +var default_value +var node : Node + + +func _on_RestoreDefaultButton_pressed() -> void: + Global.set(setting_name, default_value) + Global.config_cache.set_value("preferences", setting_name, default_value) + Global.preferences_dialog.preference_update(setting_name) + Global.preferences_dialog.disable_restore_default_button(self, true) + node.set(value_type, default_value) diff --git a/src/Preferences/RestoreDefaultButton.tscn b/src/Preferences/RestoreDefaultButton.tscn new file mode 100644 index 000000000..a9cbedad2 --- /dev/null +++ b/src/Preferences/RestoreDefaultButton.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://assets/graphics/dark_themes/misc/icon_reload.png" type="Texture" id=1] +[ext_resource path="res://src/Preferences/RestoreDefaultButton.gd" type="Script" id=2] + +[sub_resource type="ImageTexture" id=1] + +[node name="RestoreDefaultButton" type="TextureButton"] +margin_right = 16.0 +margin_bottom = 16.0 +disabled = true +texture_normal = ExtResource( 1 ) +texture_disabled = SubResource( 1 ) +script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} +[connection signal="pressed" from="." to="." method="_on_RestoreDefaultButton_pressed"]