diff --git a/addons/GDQuest_GDScript_formatter/editor/greeter.gd b/addons/GDQuest_GDScript_formatter/editor/greeter.gd new file mode 100644 index 0000000..d64259e --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/editor/greeter.gd @@ -0,0 +1,121 @@ +@tool +class_name Greeter +extends Window + +signal action_pressed(action: String) +signal setting_changed(setting: String, value: Variant) + +@onready var _addon_version_label: Label = $Container/Layout/Versions/Addon/Layout/Meta/Value +@onready var _formatter_version_label: Label = $Container/Layout/Versions/Formatter/Layout/Meta/Value +@onready var _heading_label: Label = $Container/Layout/Heading/Description + +@onready var _docs_button: Button = $Container/Layout/SplitPanel/Resources/Items/Docs/HBoxContainer/DocsButton +@onready var _issues_button: Button = $Container/Layout/SplitPanel/Resources/Items/Issues/HBoxContainer/IssuesButton +@onready var _formatter_install_button: Button = $Container/Layout/Versions/Formatter/Layout/Actions/InstallButton +@onready var _formatter_uninstall_button: Button = $Container/Layout/Versions/Formatter/Layout/Actions/UninstallButton +@onready var _addon_install_button: Button = $Container/Layout/Versions/Addon/Layout/InstallButton +@onready var _format_on_save_toggle: CheckButton = $Container/Layout/SplitPanel/QuickSettings/Items/FormatOnSave/Toggle +@onready var _lint_on_save_toggle: CheckButton = $Container/Layout/SplitPanel/QuickSettings/Items/LintOnSave/Toggle + +var _addon_version: String = "-" +var _formatter_version: String = "-" +var _setting_states: Dictionary = { } + + +func _ready() -> void: + _addon_version_label.text = _addon_version + _formatter_version_label.text = _formatter_version + + close_requested.connect(_handle_close) + + _docs_button.button_down.connect(_handle_docs_press) + _issues_button.button_down.connect(_handle_issues_press) + _formatter_install_button.button_down.connect(_handle_formatter_install) + _formatter_uninstall_button.button_down.connect(_handle_formatter_uninstall) + _addon_install_button.button_down.connect(_handle_addon_press) + _format_on_save_toggle.toggled.connect(_handle_format_on_save_toggle) + _lint_on_save_toggle.toggled.connect(_handle_lint_on_save_toggle) + + _update_tagline() + _update_setting_ui() + + +func set_addon_version(version: String) -> void: + _addon_version = version + + if is_node_ready(): + _addon_version_label.text = _addon_version + + +func set_formatter_version(version: String) -> void: + _formatter_version = version + _formatter_uninstall_button.disabled = _formatter_version == "-" + + if is_node_ready(): + _formatter_version_label.text = _formatter_version + + +func set_setting_state(setting: String, value: Variant) -> void: + _setting_states.set(setting, value) + + if is_node_ready(): + _update_setting_ui() + + +func _update_tagline() -> void: + var godot_version = Engine.get_version_info() + var version_major = str(godot_version.major) + + _heading_label.text = _heading_label.text.replace("", version_major) + + +func _update_setting_ui() -> void: + if _setting_states.has("format_on_save"): + var state = _setting_states.get("format_on_save") + + _format_on_save_toggle.button_pressed = state == true + + if _setting_states.has("lint_on_save"): + var state = _setting_states.get("lint_on_save") + + _lint_on_save_toggle.button_pressed = state == true + + +func _handle_close() -> void: + close_requested.disconnect(_handle_close) + + _docs_button.button_down.disconnect(_handle_docs_press) + _issues_button.button_down.disconnect(_handle_issues_press) + _formatter_install_button.button_down.disconnect(_handle_formatter_install) + _formatter_uninstall_button.button_down.disconnect(_handle_formatter_uninstall) + _addon_install_button.button_down.disconnect(_handle_addon_press) + + hide() + + +func _handle_docs_press() -> void: + action_pressed.emit("help") + + +func _handle_issues_press() -> void: + action_pressed.emit("report_issue") + + +func _handle_formatter_install() -> void: + action_pressed.emit("install_update") + + +func _handle_formatter_uninstall() -> void: + action_pressed.emit("uninstall") + + +func _handle_addon_press() -> void: + action_pressed.emit("update_addon") + + +func _handle_format_on_save_toggle(state: bool) -> void: + setting_changed.emit("format_on_save", state) + + +func _handle_lint_on_save_toggle(state: bool) -> void: + setting_changed.emit("lint_on_save", state) diff --git a/addons/GDQuest_GDScript_formatter/editor/greeter.gd.uid b/addons/GDQuest_GDScript_formatter/editor/greeter.gd.uid new file mode 100644 index 0000000..386254a --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/editor/greeter.gd.uid @@ -0,0 +1 @@ +uid://chtdytdwey3un diff --git a/addons/GDQuest_GDScript_formatter/editor/greeter.tscn b/addons/GDQuest_GDScript_formatter/editor/greeter.tscn new file mode 100644 index 0000000..9ec7223 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/editor/greeter.tscn @@ -0,0 +1,400 @@ +[gd_scene format=3 uid="uid://2ffo6diluqkm"] + +[ext_resource type="Script" uid="uid://chtdytdwey3un" path="res://addons/GDQuest_GDScript_formatter/editor/greeter.gd" id="1_cku6i"] +[ext_resource type="Texture2D" uid="uid://cp5vhsg54dmt5" path="res://addons/GDQuest_GDScript_formatter/images/gdquest_logo.svg" id="1_hq2xi"] +[ext_resource type="Texture2D" uid="uid://pfs8d8babvcu" path="res://addons/GDQuest_GDScript_formatter/images/icons/download.svg" id="3_cku6i"] +[ext_resource type="Texture2D" uid="uid://bgwq4as8xi47j" path="res://addons/GDQuest_GDScript_formatter/images/icons/resources.svg" id="4_2dn7m"] +[ext_resource type="Texture2D" uid="uid://ctpras52nelx3" path="res://addons/GDQuest_GDScript_formatter/images/icons/link.svg" id="4_yrmdb"] +[ext_resource type="Texture2D" uid="uid://c25vn7jgshggh" path="res://addons/GDQuest_GDScript_formatter/images/icons/trash.svg" id="5_cx1jr"] +[ext_resource type="Texture2D" uid="uid://dp30pekmsn6tt" path="res://addons/GDQuest_GDScript_formatter/images/icons/settings.svg" id="5_lrwqi"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2dn7m"] +content_margin_left = 16.0 +content_margin_top = 16.0 +content_margin_right = 16.0 +content_margin_bottom = 16.0 +bg_color = Color(0.105882354, 0.105882354, 0.105882354, 1) + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_cku6i"] +content_margin_left = 4.0 +content_margin_top = 4.0 +content_margin_right = 12.0 +content_margin_bottom = 4.0 +bg_color = Color(0.13333334, 0.13333334, 0.13333334, 1) +corner_radius_top_left = 8 +corner_radius_bottom_left = 8 + +[sub_resource type="SystemFont" id="SystemFont_cx1jr"] +font_names = PackedStringArray("Monospace") +font_weight = 600 +subpixel_positioning = 0 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hq2xi"] +content_margin_left = 4.0 +content_margin_top = 4.0 +content_margin_right = 12.0 +content_margin_bottom = 4.0 +bg_color = Color(0.13333334, 0.13333334, 0.13333334, 1) +corner_radius_top_right = 8 +corner_radius_bottom_right = 8 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0pdmk"] +content_margin_left = 8.0 +content_margin_top = 8.0 +content_margin_right = 8.0 +content_margin_bottom = 8.0 +bg_color = Color(0.13333334, 0.13333334, 0.13333334, 1) +corner_radius_top_left = 8 +corner_radius_top_right = 8 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ciixy"] +content_margin_left = 8.0 +content_margin_top = 8.0 +content_margin_right = 8.0 +content_margin_bottom = 8.0 +bg_color = Color(0.13333334, 0.13333334, 0.13333334, 1) +corner_radius_bottom_right = 8 +corner_radius_bottom_left = 8 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yrmdb"] +content_margin_left = 8.0 +content_margin_top = 8.0 +content_margin_right = 8.0 +content_margin_bottom = 8.0 +bg_color = Color(0.13333334, 0.13333334, 0.13333334, 1) +corner_radius_top_left = 8 +corner_radius_top_right = 8 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_cx1jr"] +content_margin_left = 8.0 +content_margin_top = 8.0 +content_margin_right = 8.0 +content_margin_bottom = 8.0 +bg_color = Color(0.13333334, 0.13333334, 0.13333334, 1) +corner_radius_bottom_right = 8 +corner_radius_bottom_left = 8 + +[node name="Window" type="Window" unique_id=447471143] +oversampling_override = 1.0 +title = "GDScript Formatter" +initial_position = 1 +size = Vector2i(500, 339) +visible = false +wrap_controls = true +unresizable = true +minimize_disabled = true +maximize_disabled = true +keep_title_visible = true +script = ExtResource("1_cku6i") + +[node name="Container" type="PanelContainer" parent="." unique_id=1537388181] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme_override_styles/panel = SubResource("StyleBoxFlat_2dn7m") +metadata/_edit_use_anchors_ = true + +[node name="Layout" type="VBoxContainer" parent="Container" unique_id=508597381] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme_override_constants/separation = 16 + +[node name="Heading" type="VBoxContainer" parent="Container/Layout" unique_id=1777254668] +layout_mode = 2 +theme_override_constants/separation = 8 + +[node name="Branding" type="CenterContainer" parent="Container/Layout/Heading" unique_id=373074182] +layout_mode = 2 + +[node name="Logo" type="TextureRect" parent="Container/Layout/Heading/Branding" unique_id=859651745] +layout_mode = 2 +texture = ExtResource("1_hq2xi") +stretch_mode = 4 + +[node name="Description" type="Label" parent="Container/Layout/Heading" unique_id=1391782465] +layout_mode = 2 +size_flags_vertical = 0 +theme_override_font_sizes/font_size = 14 +text = "A faster code formatter for GDScript and Godot 4" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Versions" type="HBoxContainer" parent="Container/Layout" unique_id=215688731] +layout_mode = 2 +size_flags_vertical = 0 +accessibility_name = "Versions" +accessibility_description = "Addon and formatter versions" +theme_override_constants/separation = 1 +accessibility_region = true + +[node name="Addon" type="PanelContainer" parent="Container/Layout/Versions" unique_id=1266364516] +layout_mode = 2 +size_flags_horizontal = 3 +accessibility_name = "Addon version" +accessibility_described_by_nodes = Array[NodePath]([NodePath("Layout/Meta/Value")]) +accessibility_labeled_by_nodes = Array[NodePath]([NodePath("Layout/Meta/Title")]) +theme_override_styles/panel = SubResource("StyleBoxFlat_cku6i") +accessibility_region = true + +[node name="Layout" type="HBoxContainer" parent="Container/Layout/Versions/Addon" unique_id=1478601450] +layout_mode = 2 +theme_override_constants/separation = 16 + +[node name="Meta" type="VBoxContainer" parent="Container/Layout/Versions/Addon/Layout" unique_id=764178420] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 4 +theme_override_constants/separation = -4 + +[node name="Title" type="Label" parent="Container/Layout/Versions/Addon/Layout/Meta" unique_id=1563506712] +layout_mode = 2 +size_flags_vertical = 0 +text = "Addon version" + +[node name="Value" type="Label" parent="Container/Layout/Versions/Addon/Layout/Meta" unique_id=1344464055] +layout_mode = 2 +size_flags_vertical = 0 +accessibility_live = 1 +accessibility_labeled_by_nodes = Array[NodePath]([NodePath("../Title")]) +theme_override_fonts/font = SubResource("SystemFont_cx1jr") +theme_override_font_sizes/font_size = 16 +text = "-" + +[node name="InstallButton" type="Button" parent="Container/Layout/Versions/Addon/Layout" unique_id=1381876748] +layout_mode = 2 +size_flags_vertical = 4 +tooltip_text = "Download the latest version +from GitHub" +theme_override_constants/icon_max_width = 16 +icon = ExtResource("4_yrmdb") +icon_alignment = 1 + +[node name="Formatter" type="PanelContainer" parent="Container/Layout/Versions" unique_id=1351105920] +layout_mode = 2 +size_flags_horizontal = 3 +accessibility_name = "Formatter version" +accessibility_described_by_nodes = Array[NodePath]([NodePath("Layout/Meta/Value")]) +accessibility_labeled_by_nodes = Array[NodePath]([NodePath("Layout/Meta/Title")]) +theme_override_styles/panel = SubResource("StyleBoxFlat_hq2xi") +accessibility_region = true + +[node name="Layout" type="HBoxContainer" parent="Container/Layout/Versions/Formatter" unique_id=185289625] +layout_mode = 2 +theme_override_constants/separation = 16 + +[node name="Meta" type="VBoxContainer" parent="Container/Layout/Versions/Formatter/Layout" unique_id=1585824214] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 4 +theme_override_constants/separation = -4 + +[node name="Title" type="Label" parent="Container/Layout/Versions/Formatter/Layout/Meta" unique_id=265656052] +layout_mode = 2 +size_flags_vertical = 3 +text = "Formatter version" + +[node name="Value" type="Label" parent="Container/Layout/Versions/Formatter/Layout/Meta" unique_id=1786751365] +layout_mode = 2 +size_flags_vertical = 2 +accessibility_live = 1 +accessibility_labeled_by_nodes = Array[NodePath]([NodePath("../Title")]) +theme_override_fonts/font = SubResource("SystemFont_cx1jr") +theme_override_font_sizes/font_size = 16 +text = "-" + +[node name="Actions" type="HBoxContainer" parent="Container/Layout/Versions/Formatter/Layout" unique_id=568154137] +layout_mode = 2 +size_flags_vertical = 4 + +[node name="InstallButton" type="Button" parent="Container/Layout/Versions/Formatter/Layout/Actions" unique_id=1459022472] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +tooltip_text = "Installs or updates +the formatter" +theme_override_constants/icon_max_width = 16 +icon = ExtResource("3_cku6i") +icon_alignment = 1 + +[node name="UninstallButton" type="Button" parent="Container/Layout/Versions/Formatter/Layout/Actions" unique_id=1828822505] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +tooltip_text = "Removes the formatter +from your system" +theme_override_constants/icon_max_width = 16 +disabled = true +icon = ExtResource("5_cx1jr") +icon_alignment = 1 + +[node name="SplitPanel" type="HBoxContainer" parent="Container/Layout" unique_id=1617836975] +layout_mode = 2 +theme_override_constants/separation = 8 + +[node name="QuickSettings" type="VBoxContainer" parent="Container/Layout/SplitPanel" unique_id=255097673] +layout_mode = 2 +size_flags_horizontal = 3 +accessibility_name = "Resources" +theme_override_constants/separation = 4 +accessibility_region = true + +[node name="Heading" type="HBoxContainer" parent="Container/Layout/SplitPanel/QuickSettings" unique_id=627743144] +layout_mode = 2 +size_flags_vertical = 0 +tooltip_text = "Quick access to the most +commonly used settings. + +Need more? Find them +under your Editor Settings." +theme_override_constants/separation = 0 + +[node name="TextureRect" type="TextureRect" parent="Container/Layout/SplitPanel/QuickSettings/Heading" unique_id=1095513836] +custom_maximum_size = Vector2(18, 18) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +texture = ExtResource("5_lrwqi") + +[node name="Label" type="Label" parent="Container/Layout/SplitPanel/QuickSettings/Heading" unique_id=2032064637] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 0 +theme_type_variation = &"HeaderSmall" +text = "Quick settings" + +[node name="Items" type="VBoxContainer" parent="Container/Layout/SplitPanel/QuickSettings" unique_id=1814396095] +layout_mode = 2 +theme_override_constants/separation = 1 + +[node name="FormatOnSave" type="PanelContainer" parent="Container/Layout/SplitPanel/QuickSettings/Items" unique_id=839105562] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +accessibility_name = "Format on save" +accessibility_labeled_by_nodes = Array[NodePath]([NodePath("")]) +theme_override_styles/panel = SubResource("StyleBoxFlat_0pdmk") +accessibility_region = true + +[node name="Toggle" type="CheckButton" parent="Container/Layout/SplitPanel/QuickSettings/Items/FormatOnSave" unique_id=762096402] +layout_mode = 2 +tooltip_text = "Formats your code +when the file is saved" +text = "Format on save" +flat = true + +[node name="LintOnSave" type="PanelContainer" parent="Container/Layout/SplitPanel/QuickSettings/Items" unique_id=1685232789] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +accessibility_name = "Lint on save" +accessibility_labeled_by_nodes = Array[NodePath]([NodePath("")]) +theme_override_styles/panel = SubResource("StyleBoxFlat_ciixy") +accessibility_region = true + +[node name="Toggle" type="CheckButton" parent="Container/Layout/SplitPanel/QuickSettings/Items/LintOnSave" unique_id=693952472] +layout_mode = 2 +tooltip_text = "Checks your code +for common mistakes when +the file is saved" +text = "Lint on save" +flat = true + +[node name="Resources" type="VBoxContainer" parent="Container/Layout/SplitPanel" unique_id=308460711] +layout_mode = 2 +size_flags_horizontal = 3 +accessibility_name = "Resources" +theme_override_constants/separation = 4 +accessibility_region = true + +[node name="Heading" type="HBoxContainer" parent="Container/Layout/SplitPanel/Resources" unique_id=2131034157] +layout_mode = 2 +size_flags_vertical = 0 +theme_override_constants/separation = 0 + +[node name="TextureRect" type="TextureRect" parent="Container/Layout/SplitPanel/Resources/Heading" unique_id=213876480] +custom_maximum_size = Vector2(18, 18) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +texture = ExtResource("4_2dn7m") + +[node name="Label" type="Label" parent="Container/Layout/SplitPanel/Resources/Heading" unique_id=326050371] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 0 +theme_type_variation = &"HeaderSmall" +text = "Resources" + +[node name="Items" type="VBoxContainer" parent="Container/Layout/SplitPanel/Resources" unique_id=528407113] +layout_mode = 2 +theme_override_constants/separation = 1 + +[node name="Docs" type="PanelContainer" parent="Container/Layout/SplitPanel/Resources/Items" unique_id=1617879850] +layout_mode = 2 +size_flags_horizontal = 3 +accessibility_name = "Documentation" +accessibility_labeled_by_nodes = Array[NodePath]([NodePath("HBoxContainer/Meta/Title")]) +theme_override_styles/panel = SubResource("StyleBoxFlat_yrmdb") +accessibility_region = true + +[node name="HBoxContainer" type="HBoxContainer" parent="Container/Layout/SplitPanel/Resources/Items/Docs" unique_id=730529116] +layout_mode = 2 +size_flags_vertical = 0 +theme_override_constants/separation = 16 + +[node name="Meta" type="VBoxContainer" parent="Container/Layout/SplitPanel/Resources/Items/Docs/HBoxContainer" unique_id=491611772] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 4 +theme_override_constants/separation = 0 + +[node name="Title" type="Label" parent="Container/Layout/SplitPanel/Resources/Items/Docs/HBoxContainer/Meta" unique_id=292956704] +layout_mode = 2 +size_flags_vertical = 3 +text = "Documentation" + +[node name="DocsButton" type="Button" parent="Container/Layout/SplitPanel/Resources/Items/Docs/HBoxContainer" unique_id=1379633793] +layout_mode = 2 +size_flags_vertical = 4 +tooltip_text = "View documentation" +theme_override_constants/icon_max_width = 16 +icon = ExtResource("4_yrmdb") +icon_alignment = 1 + +[node name="Issues" type="PanelContainer" parent="Container/Layout/SplitPanel/Resources/Items" unique_id=828435889] +layout_mode = 2 +size_flags_horizontal = 3 +accessibility_name = "Issue tracker" +accessibility_labeled_by_nodes = Array[NodePath]([NodePath("HBoxContainer/Meta/Title")]) +theme_override_styles/panel = SubResource("StyleBoxFlat_cx1jr") +accessibility_region = true + +[node name="HBoxContainer" type="HBoxContainer" parent="Container/Layout/SplitPanel/Resources/Items/Issues" unique_id=1959402616] +layout_mode = 2 +size_flags_vertical = 4 +theme_override_constants/separation = 16 + +[node name="Meta" type="VBoxContainer" parent="Container/Layout/SplitPanel/Resources/Items/Issues/HBoxContainer" unique_id=820974620] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 4 +theme_override_constants/separation = 0 + +[node name="Title" type="Label" parent="Container/Layout/SplitPanel/Resources/Items/Issues/HBoxContainer/Meta" unique_id=669708178] +layout_mode = 2 +size_flags_vertical = 2 +text = "Issue tracker" + +[node name="IssuesButton" type="Button" parent="Container/Layout/SplitPanel/Resources/Items/Issues/HBoxContainer" unique_id=225001517] +layout_mode = 2 +size_flags_vertical = 4 +tooltip_text = "Report an issue" +accessibility_name = "Report an issue" +theme_override_constants/icon_max_width = 16 +icon = ExtResource("4_yrmdb") +icon_alignment = 1 diff --git a/addons/GDQuest_GDScript_formatter/images/gdquest_logo.svg b/addons/GDQuest_GDScript_formatter/images/gdquest_logo.svg new file mode 100644 index 0000000..6e5d120 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/gdquest_logo.svg @@ -0,0 +1,27 @@ + + \ No newline at end of file diff --git a/addons/GDQuest_GDScript_formatter/images/gdquest_logo.svg.import b/addons/GDQuest_GDScript_formatter/images/gdquest_logo.svg.import new file mode 100644 index 0000000..490c95c --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/gdquest_logo.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cp5vhsg54dmt5" +path="res://.godot/imported/gdquest_logo.svg-3d69df92bc1269a9cd56d21bfb4e3dfd.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/GDQuest_GDScript_formatter/images/gdquest_logo.svg" +dest_files=["res://.godot/imported/gdquest_logo.svg-3d69df92bc1269a9cd56d21bfb4e3dfd.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/addons/GDQuest_GDScript_formatter/images/icons/download.svg b/addons/GDQuest_GDScript_formatter/images/icons/download.svg new file mode 100644 index 0000000..66d6681 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/download.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/addons/GDQuest_GDScript_formatter/images/icons/download.svg.import b/addons/GDQuest_GDScript_formatter/images/icons/download.svg.import new file mode 100644 index 0000000..ef30e79 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/download.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://pfs8d8babvcu" +path="res://.godot/imported/download.svg-d338a54db5cab704099d1a1b2a18a684.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/GDQuest_GDScript_formatter/images/icons/download.svg" +dest_files=["res://.godot/imported/download.svg-d338a54db5cab704099d1a1b2a18a684.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/addons/GDQuest_GDScript_formatter/images/icons/link.svg b/addons/GDQuest_GDScript_formatter/images/icons/link.svg new file mode 100644 index 0000000..10da18e --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/link.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/addons/GDQuest_GDScript_formatter/images/icons/link.svg.import b/addons/GDQuest_GDScript_formatter/images/icons/link.svg.import new file mode 100644 index 0000000..56bab93 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/link.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ctpras52nelx3" +path="res://.godot/imported/link.svg-b137df11cbc30e911fb0835645149fef.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/GDQuest_GDScript_formatter/images/icons/link.svg" +dest_files=["res://.godot/imported/link.svg-b137df11cbc30e911fb0835645149fef.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/addons/GDQuest_GDScript_formatter/images/icons/resources.svg b/addons/GDQuest_GDScript_formatter/images/icons/resources.svg new file mode 100644 index 0000000..3ca9445 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/resources.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/addons/GDQuest_GDScript_formatter/images/icons/resources.svg.import b/addons/GDQuest_GDScript_formatter/images/icons/resources.svg.import new file mode 100644 index 0000000..7107fb9 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/resources.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bgwq4as8xi47j" +path="res://.godot/imported/resources.svg-c9d73a79fde4a2d7e788a9b272643ba4.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/GDQuest_GDScript_formatter/images/icons/resources.svg" +dest_files=["res://.godot/imported/resources.svg-c9d73a79fde4a2d7e788a9b272643ba4.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/addons/GDQuest_GDScript_formatter/images/icons/settings.svg b/addons/GDQuest_GDScript_formatter/images/icons/settings.svg new file mode 100644 index 0000000..c840125 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/settings.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/addons/GDQuest_GDScript_formatter/images/icons/settings.svg.import b/addons/GDQuest_GDScript_formatter/images/icons/settings.svg.import new file mode 100644 index 0000000..91cd46c --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/settings.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dp30pekmsn6tt" +path="res://.godot/imported/settings.svg-62cf3e99083bed9344103ef46d33eb2a.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/GDQuest_GDScript_formatter/images/icons/settings.svg" +dest_files=["res://.godot/imported/settings.svg-62cf3e99083bed9344103ef46d33eb2a.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/addons/GDQuest_GDScript_formatter/images/icons/trash.svg b/addons/GDQuest_GDScript_formatter/images/icons/trash.svg new file mode 100644 index 0000000..a0052a0 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/trash.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/addons/GDQuest_GDScript_formatter/images/icons/trash.svg.import b/addons/GDQuest_GDScript_formatter/images/icons/trash.svg.import new file mode 100644 index 0000000..9fdd4d0 --- /dev/null +++ b/addons/GDQuest_GDScript_formatter/images/icons/trash.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c25vn7jgshggh" +path="res://.godot/imported/trash.svg-a9a6e3eec301ddf3c41ade5e7d043c57.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/GDQuest_GDScript_formatter/images/icons/trash.svg" +dest_files=["res://.godot/imported/trash.svg-a9a6e3eec301ddf3c41ade5e7d043c57.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/addons/GDQuest_GDScript_formatter/plugin.gd b/addons/GDQuest_GDScript_formatter/plugin.gd index 24ae21d..3e01c85 100644 --- a/addons/GDQuest_GDScript_formatter/plugin.gd +++ b/addons/GDQuest_GDScript_formatter/plugin.gd @@ -10,6 +10,7 @@ extends EditorPlugin const FormatterInstaller = preload("install_and_update.gd") const FormatterMenu = preload("menu.gd") +const GreeterPanel = preload("editor/greeter.tscn") const EDITOR_SETTINGS_CATEGORY = "gdquest_gdscript_formatter/" const SETTING_FORMAT_ON_SAVE = "format_on_save" @@ -57,6 +58,12 @@ const COMMAND_PALETTE_INSTALL_UPDATE = "Install or Update Formatter" const COMMAND_PALETTE_UNINSTALL = "Uninstall Formatter" const COMMAND_PALETTE_REPORT_ISSUE = "Report Issue" +# Quick settings that are shown in the greeter +const QUICK_SETTINGS = [ + SETTING_FORMAT_ON_SAVE, + SETTING_LINT_ON_SAVE +] + var DEFAULT_SETTINGS = { SETTING_FORMAT_ON_SAVE: false, SETTING_USE_SPACES: false, @@ -69,6 +76,7 @@ var DEFAULT_SETTINGS = { SETTING_IGNORED_DIRECTORIES: PackedStringArray(["addons/"]), } + ## Which gutter lint icons are shown in. ## By default, gutter 0 is for breakpoints and 1 is for things like overrides. const GUTTER_LINT_ICON_INDEX = 2 @@ -78,17 +86,21 @@ var connection_list: Array[Resource] = [] var installer: FormatterInstaller = null var formatter_cache_dir: String var menu: FormatterMenu = null +var greeter_panel: Greeter = null var _has_uninstall_command := false var _has_formatter_command := false var _has_format_command := false var _has_lint_command := false var _already_warned_about_reorder_on_save := false +var _setting_updated_via_greeter := false # Used to auto detect changes to the project's .editorconfig file. var _editorconfig_last_modified_time := -1 # Editorconfig allows setting rules per path glob. We track globs for the format # on save rule here so users can enable it selectively for specific folders. var _editorconfig_format_on_save_rules: Array[Dictionary] = [] +# Used to detect the formatter +const FORMATTER_BINARY_NAME = "gdscript-formatter" func _init() -> void: migrate_format_mode_setting() @@ -167,6 +179,10 @@ func migrate_format_mode_setting() -> void: version = 2 +func _enable_plugin() -> void: + _show_greeter() + + func _enter_tree() -> void: formatter_cache_dir = EditorInterface.get_editor_paths().get_cache_dir().path_join("gdquest") installer = FormatterInstaller.new(formatter_cache_dir) @@ -182,6 +198,9 @@ func _enter_tree() -> void: return add_format_command() add_lint_command() + + _update_formatter_version() + # After installing the formatter we can add the menu option to show the uninstall command if is_instance_valid(menu): menu.update_menu(true), @@ -190,7 +209,10 @@ func _enter_tree() -> void: func _on_installation_failed (error_message: String) -> void: push_error("Formatter installation failed: ", error_message), ) - + + greeter_panel = GreeterPanel.instantiate() as Greeter + add_child(greeter_panel) + _has_formatter_command = has_command(get_editor_setting(SETTING_FORMATTER_PATH)) add_format_command() add_lint_command() @@ -207,6 +229,34 @@ func _enter_tree() -> void: resource_saved.connect(_on_resource_saved) +func _show_greeter() -> void: + if not greeter_panel: + return + + _update_addon_version() + _update_formatter_version() + + greeter_panel.popup_centered() + greeter_panel.action_pressed.connect(_on_menu_item_selected) + greeter_panel.setting_changed.connect(_handle_greeter_setting_change) + + _apply_greeter_defaults() + +func _handle_greeter_setting_change(setting: String, value: Variant) -> void: + _setting_updated_via_greeter = true + + set_editor_setting(setting, value) + +func _apply_greeter_defaults() -> void: + if not greeter_panel: + return + + for setting in QUICK_SETTINGS: + var state = get_editor_setting(setting) + + greeter_panel.set_setting_state(setting, state) + + func _exit_tree() -> void: resource_saved.disconnect(_on_resource_saved) @@ -218,6 +268,10 @@ func _exit_tree() -> void: installer.queue_free() installer = null + + greeter_panel.action_pressed.disconnect(_on_menu_item_selected) + greeter_panel.setting_changed.disconnect(_handle_greeter_setting_change) + greeter_panel.queue_free() if is_instance_valid(menu): menu.menu_item_selected.disconnect(_on_menu_item_selected) @@ -226,6 +280,15 @@ func _exit_tree() -> void: menu = null +func _notification(what: int) -> void: + var has_settings_changed = what == EditorSettings.NOTIFICATION_EDITOR_SETTINGS_CHANGED + + if has_settings_changed and not _setting_updated_via_greeter: + _apply_greeter_defaults() + + _setting_updated_via_greeter = false + + func _shortcut_input(event: InputEvent) -> void: var shortcut := get_editor_setting(SETTING_SHORTCUT) as Shortcut if not is_instance_valid(shortcut): @@ -501,6 +564,85 @@ func has_command(command: String) -> bool: var exit_code := OS.execute(command, ["--version"], output, true) return exit_code == OK +func _get_binary_path() -> String: + var binary_name := FORMATTER_BINARY_NAME + + if OS.get_name().to_lower().contains("windows"): + binary_name = binary_name + ".exe" + + return formatter_cache_dir.path_join(binary_name) + +func _parse_formatter_version(version: Array) -> String: + var version_raw: String = "" + + for index in version.size(): + version_raw += version[index] + + if version_raw.begins_with(FORMATTER_BINARY_NAME): + version_raw = version_raw.trim_prefix(FORMATTER_BINARY_NAME) + + return version_raw.strip_edges() + +func get_formatter_version(): + var binary_path = _get_binary_path() + + if not FileAccess.file_exists(binary_path): + return + + var version_stdout: Array = [] + var exit_code = OS.execute(binary_path, ["--version"], version_stdout) + + if not exit_code == OK: + return + + return _parse_formatter_version(version_stdout) + + +func _update_formatter_version() -> void: + if not greeter_panel: + return + + var formatter_version = get_formatter_version() + + if not formatter_version: + return + + greeter_panel.set_formatter_version(formatter_version) + + +func _reset_formatter_version() -> void: + if not greeter_panel: + return + + greeter_panel.set_formatter_version("-") + + +func get_addon_version(): + var menu = FormatterMenu.new() + print(menu.get_path()) + + var plugin_config = ConfigFile.new() + var config_loaded = plugin_config.load(get_script().resource_path.get_base_dir() + "/plugin.cfg") + + if not config_loaded == OK: + push_error("Unable to load plugin config") + + return + + return plugin_config.get_value("plugin", "version") + + +func _update_addon_version() -> void: + if not greeter_panel: + return + + var addon_version = get_addon_version() + + if not addon_version: + return + + greeter_panel.set_addon_version(addon_version) + func is_formatter_available() -> bool: if _has_formatter_command: @@ -510,18 +652,12 @@ func is_formatter_available() -> bool: func is_formatter_installed_locally() -> bool: - var binary_name := "gdscript-formatter" - if OS.get_name().to_lower().contains("windows"): - binary_name = "gdscript-formatter.exe" - var binary_path := formatter_cache_dir.path_join(binary_name) + var binary_path = _get_binary_path() return FileAccess.file_exists(binary_path) func uninstall_formatter() -> void: - var binary_name := "gdscript-formatter" - if OS.get_name().to_lower().contains("windows"): - binary_name = "gdscript-formatter.exe" - var binary_path := formatter_cache_dir.path_join(binary_name) + var binary_path = _get_binary_path() if FileAccess.file_exists(binary_path): DirAccess.remove_absolute(binary_path) @@ -534,6 +670,7 @@ func uninstall_formatter() -> void: add_format_command() remove_uninstall_command() add_uninstall_command() + _reset_formatter_version() if is_instance_valid(menu): menu.update_menu(false) else: @@ -569,6 +706,10 @@ func show_help() -> void: OS.shell_open("https://www.gdquest.com/library/gdscript_formatter/") +func update_addon() -> void: + OS.shell_open("https://github.com/GDQuest/GDScript-formatter/releases") + + func _on_menu_item_selected(command: String) -> void: match command: "format_script": @@ -585,6 +726,8 @@ func _on_menu_item_selected(command: String) -> void: report_issue() "help": show_help() + "update_addon": + update_addon() _: push_warning("Unsupported command sent from the menu: " + command)