diff --git a/addons/kenyoni/plugin_reloader/internal/reloader.gd b/addons/kenyoni/plugin_reloader/internal/reloader.gd new file mode 100644 index 0000000..e79df1f --- /dev/null +++ b/addons/kenyoni/plugin_reloader/internal/reloader.gd @@ -0,0 +1,55 @@ +@tool +extends MarginContainer + +@export var _reload_button: Button +@export var _option_button: OptionButton + +var _last_selection: String = "" + +func _ready() -> void: + if Engine.is_editor_hint(): + self._reload_button.icon = self.get_theme_icon(&"Reload", &"EditorIcons") + + self._option_button.item_selected.connect(func(idx: int) -> void: + self._last_selection = self._option_button.get_item_metadata(idx) + ) + self._reload_button.pressed.connect(self._on_reload_pressed) + + EditorInterface.get_resource_filesystem().filesystem_changed.connect(self._reload_plugins) + self._reload_plugins() + +func _reload_plugins() -> void: + self._option_button.clear() + for dir: String in DirAccess.get_directories_at("res://addons/"): + self._add_plugin(dir) + + # subfolder + for sub_dir: String in DirAccess.get_directories_at("res://addons/" + dir): + self._add_plugin(dir + "/" + sub_dir) + if self._last_selection == "": + self._last_selection = self._option_button.get_item_metadata(0) + + +func _add_plugin(plugin_id: String) -> void: + # ignore the current plugin + if plugin_id == "kenyoni/plugin_reloader": + return + + var cfg_path: String = "res://addons/" + plugin_id + "/plugin.cfg" + if !FileAccess.file_exists(cfg_path): + return + + var plugin_cfg: ConfigFile = ConfigFile.new() + plugin_cfg.load(cfg_path) + var plugin_name: String = plugin_cfg.get_value("plugin", "name", plugin_id) + self._option_button.add_item(plugin_name) + self._option_button.set_item_metadata(self._option_button.get_item_count() - 1, plugin_id) + self._option_button.set_item_tooltip(self._option_button.get_item_count() - 1, "res://addons/" + plugin_id + "/") + if plugin_id == self._last_selection: + self._option_button.select(self._option_button.get_item_count() - 1) + +func _on_reload_pressed() -> void: + var cfg_path: String = "res://addons/" + self._last_selection + "/plugin.cfg" + if EditorInterface.is_plugin_enabled(cfg_path): + EditorInterface.set_plugin_enabled(cfg_path, false) + EditorInterface.set_plugin_enabled(cfg_path, true) diff --git a/addons/kenyoni/plugin_reloader/internal/reloader.tscn b/addons/kenyoni/plugin_reloader/internal/reloader.tscn new file mode 100644 index 0000000..33d93d9 --- /dev/null +++ b/addons/kenyoni/plugin_reloader/internal/reloader.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=2 format=3 uid="uid://dryoyuj4vl0l5"] + +[ext_resource type="Script" path="res://addons/kenyoni/plugin_reloader/internal/reloader.gd" id="1_kd7gg"] + +[node name="Reloader" type="MarginContainer" node_paths=PackedStringArray("_reload_button", "_option_button")] +offset_right = 939.0 +offset_bottom = 187.0 +script = ExtResource("1_kd7gg") +_reload_button = NodePath("HBoxContainer/reload_button") +_option_button = NodePath("HBoxContainer/OptionButton") + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +layout_mode = 2 + +[node name="reload_button" type="Button" parent="HBoxContainer"] +layout_mode = 2 + +[node name="OptionButton" type="OptionButton" parent="HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 diff --git a/addons/kenyoni/plugin_reloader/plugin.cfg b/addons/kenyoni/plugin_reloader/plugin.cfg new file mode 100644 index 0000000..00e95d3 --- /dev/null +++ b/addons/kenyoni/plugin_reloader/plugin.cfg @@ -0,0 +1,19 @@ +[plugin] + +name="Plugin Reloader" +description="Quickly reload plugins from the editor." +author="Kenyoni Software" +version="0.1.0" +script="plugin.gd" +license="MIT" +repository="https://github.com/kenyoni-software/godot-addons" +keywords=[ + "tool" +] +classifiers=[ + "Development Status :: 5 - Production/Stable", + "License :: OSI Approved :: MIT License" +] + +[plugin.dependencies] +godot="==4.3" diff --git a/addons/kenyoni/plugin_reloader/plugin.gd b/addons/kenyoni/plugin_reloader/plugin.gd new file mode 100644 index 0000000..94fe541 --- /dev/null +++ b/addons/kenyoni/plugin_reloader/plugin.gd @@ -0,0 +1,20 @@ +@tool +extends EditorPlugin + +const ReloaderScene: PackedScene = preload("res://addons/kenyoni/plugin_reloader/internal/reloader.tscn") +const Reloader := preload("res://addons/kenyoni/plugin_reloader/internal/reloader.gd") + +var _reloader: Reloader + +func _get_plugin_name() -> String: + return "Plugin Reloader" + +func _enter_tree() -> void: + self._reloader = ReloaderScene.instantiate() + self.add_control_to_container(CustomControlContainer.CONTAINER_TOOLBAR, self._reloader) + # move before editor run bar + self._reloader.get_parent().move_child(self._reloader, self._reloader.get_parent().find_child("@EditorRunBar@*", true, false).get_index()) + +func _exit_tree() -> void: + self.remove_control_from_container(CustomControlContainer.CONTAINER_TOOLBAR, self._reloader) + self._reloader.queue_free() diff --git a/project.godot b/project.godot index dbcfda0..9fcbc86 100644 --- a/project.godot +++ b/project.godot @@ -29,7 +29,7 @@ gdscript/warnings/unsafe_call_argument=1 [editor_plugins] -enabled=PackedStringArray("res://addons/aspect_ratio_resize_container/plugin.cfg", "res://addons/custom_theme_overrides/plugin.cfg", "res://addons/explore-editor-theme/plugin.cfg", "res://addons/git_sha_project_setting/plugin.cfg", "res://addons/glogging/plugin.cfg", "res://addons/hide_private_properties/plugin.cfg", "res://addons/icon_explorer/plugin.cfg", "res://addons/icons_patcher/plugin.cfg", "res://addons/licenses/plugin.cfg", "res://addons/qr_code/plugin.cfg", "res://addons/texture_button_colored/plugin.cfg") +enabled=PackedStringArray("res://addons/aspect_ratio_resize_container/plugin.cfg", "res://addons/custom_theme_overrides/plugin.cfg", "res://addons/explore-editor-theme/plugin.cfg", "res://addons/git_sha_project_setting/plugin.cfg", "res://addons/glogging/plugin.cfg", "res://addons/hide_private_properties/plugin.cfg", "res://addons/icon_explorer/plugin.cfg", "res://addons/icons_patcher/plugin.cfg", "res://addons/kenyoni/plugin_reloader/plugin.cfg", "res://addons/licenses/plugin.cfg", "res://addons/qr_code/plugin.cfg", "res://addons/texture_button_colored/plugin.cfg") [plugins]