-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99175c7
commit f70e9ce
Showing
17 changed files
with
1,155 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[plugin] | ||
|
||
name="Godot Plugin Refresher" | ||
description="A toolbar addition to facilitate toggling off/on a selected plugin." | ||
author="willnationsdev" | ||
version="1.0" | ||
script="plugin_refresher_plugin.gd" |
59 changes: 59 additions & 0 deletions
59
mono/2.5d/addons/godot-plugin-refresher/plugin_refresher.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
tool | ||
extends HBoxContainer | ||
|
||
const ADDONS_PATH = "res://addons/" | ||
const PLUGIN_PATH = "godot-plugin-refresher" | ||
|
||
signal request_refresh_plugin(p_name) | ||
signal confirm_refresh_plugin(p_name) | ||
|
||
onready var options = $OptionButton | ||
|
||
func _ready(): | ||
$RefreshButton.icon = get_icon('Reload', 'EditorIcons') | ||
reload_items() | ||
|
||
func reload_items(): | ||
if not options: | ||
return | ||
var dir = Directory.new() | ||
dir.change_dir(ADDONS_PATH) | ||
dir.list_dir_begin(true, true) | ||
var file = dir.get_next() | ||
options.clear() | ||
while file: | ||
if dir.dir_exists(ADDONS_PATH.plus_file(file)) and file != PLUGIN_PATH: | ||
options.add_item(file) | ||
file = dir.get_next() | ||
|
||
func select_plugin(p_name): | ||
if not options: | ||
return | ||
if p_name == null or p_name.empty(): | ||
return | ||
|
||
for idx in options.get_item_count(): | ||
var plugin = options.get_item_text(idx) | ||
if plugin == p_name: | ||
options.selected = options.get_item_id(idx) | ||
break | ||
|
||
func _on_RefreshButton_pressed(): | ||
if options.selected == -1: | ||
return # nothing selected | ||
|
||
var plugin = options.get_item_text(options.selected) | ||
if not plugin or plugin.empty(): | ||
return | ||
emit_signal("request_refresh_plugin", plugin) | ||
|
||
func show_warning(p_name): | ||
$ConfirmationDialog.dialog_text = """ | ||
Plugin `%s` is currently disabled.\n | ||
Do you want to enable it now? | ||
""" % [p_name] | ||
$ConfirmationDialog.popup_centered() | ||
|
||
func _on_ConfirmationDialog_confirmed(): | ||
var plugin = options.get_item_text(options.selected) | ||
emit_signal('confirm_refresh_plugin', plugin) |
54 changes: 54 additions & 0 deletions
54
mono/2.5d/addons/godot-plugin-refresher/plugin_refresher.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://addons/godot-plugin-refresher/plugin_refresher.gd" type="Script" id=1] | ||
|
||
[sub_resource type="Image" id=3] | ||
data = { | ||
"data": PoolByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), | ||
"format": "LumAlpha8", | ||
"height": 16, | ||
"mipmaps": false, | ||
"width": 16 | ||
} | ||
|
||
[sub_resource type="ImageTexture" id=2] | ||
flags = 4 | ||
flags = 4 | ||
image = SubResource( 3 ) | ||
size = Vector2( 16, 16 ) | ||
|
||
[node name="PluginRefresher" type="HBoxContainer"] | ||
margin_right = 40.0 | ||
margin_bottom = 40.0 | ||
script = ExtResource( 1 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="VSeparator" type="VSeparator" parent="."] | ||
margin_right = 4.0 | ||
margin_bottom = 40.0 | ||
|
||
[node name="OptionButton" type="OptionButton" parent="."] | ||
margin_left = 8.0 | ||
margin_right = 158.0 | ||
margin_bottom = 40.0 | ||
rect_min_size = Vector2( 150, 0 ) | ||
text = "node25d" | ||
items = [ "node25d", null, false, 0, null ] | ||
selected = 0 | ||
|
||
[node name="RefreshButton" type="ToolButton" parent="."] | ||
margin_left = 162.0 | ||
margin_right = 190.0 | ||
margin_bottom = 40.0 | ||
icon = SubResource( 2 ) | ||
|
||
[node name="ConfirmationDialog" type="ConfirmationDialog" parent="."] | ||
margin_right = 278.0 | ||
margin_bottom = 110.0 | ||
rect_min_size = Vector2( 300, 70 ) | ||
window_title = "Plugin Refresher" | ||
dialog_autowrap = true | ||
[connection signal="pressed" from="RefreshButton" to="." method="_on_RefreshButton_pressed"] | ||
[connection signal="confirmed" from="ConfirmationDialog" to="." method="_on_ConfirmationDialog_confirmed"] |
97 changes: 97 additions & 0 deletions
97
mono/2.5d/addons/godot-plugin-refresher/plugin_refresher_plugin.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
tool | ||
extends EditorPlugin | ||
|
||
const PLUGIN_CONFIG_DIR = 'plugins/plugin_refresher' | ||
const PLUGIN_CONFIG = 'settings.cfg' | ||
const SETTINGS = 'settings' | ||
const SETTING_RECENT = 'recently_used' | ||
|
||
var plugin_config = ConfigFile.new() | ||
|
||
const PluginRefresherScene = preload("plugin_refresher.tscn") | ||
|
||
var refresher | ||
|
||
func _enter_tree(): | ||
refresher = PluginRefresherScene.instance() | ||
add_control_to_container(CONTAINER_TOOLBAR, refresher) | ||
|
||
# Watch whether any plugin is changed, added or removed on the filesystem | ||
var efs = get_editor_interface().get_resource_filesystem() | ||
efs.connect("filesystem_changed", self, "_on_filesystem_changed") | ||
|
||
refresher.connect("request_refresh_plugin", self, "_on_request_refresh_plugin") | ||
refresher.connect("confirm_refresh_plugin", self, "_on_confirm_refresh_plugin") | ||
|
||
_load_settings() | ||
|
||
|
||
func _exit_tree(): | ||
remove_control_from_container(CONTAINER_TOOLBAR, refresher) | ||
refresher.free() | ||
|
||
|
||
func _load_settings(): | ||
var path = get_config_path() | ||
|
||
var fs = Directory.new() | ||
if not fs.file_exists(path): | ||
# Create new if running for the first time | ||
var config = ConfigFile.new() | ||
fs.make_dir_recursive(path.get_base_dir()) | ||
config.save(path) | ||
else: | ||
plugin_config.load(path) | ||
|
||
|
||
func _save_settings(): | ||
plugin_config.save(get_config_path()) | ||
|
||
|
||
func get_config_path(): | ||
var dir = get_editor_interface().get_editor_settings().get_project_settings_dir() | ||
var home = dir.plus_file(PLUGIN_CONFIG_DIR) | ||
var path = home.plus_file(PLUGIN_CONFIG) | ||
|
||
return path | ||
|
||
|
||
func _on_filesystem_changed(): | ||
if refresher: | ||
refresher.reload_items() | ||
refresher.select_plugin(get_recent_plugin()) | ||
|
||
|
||
func get_recent_plugin(): | ||
if not plugin_config.has_section_key(SETTINGS, SETTING_RECENT): | ||
return null # not saved yet | ||
|
||
var recent = plugin_config.get_value(SETTINGS, SETTING_RECENT) | ||
return recent | ||
|
||
|
||
func _on_request_refresh_plugin(p_name): | ||
assert(not p_name.empty()) | ||
|
||
var disabled = not get_editor_interface().is_plugin_enabled(p_name) | ||
if disabled: | ||
refresher.show_warning(p_name) | ||
else: | ||
refresh_plugin(p_name) | ||
|
||
|
||
func _on_confirm_refresh_plugin(p_name): | ||
refresh_plugin(p_name) | ||
|
||
|
||
func refresh_plugin(p_name): | ||
print("Refreshing plugin: ", p_name) | ||
|
||
var enabled = get_editor_interface().is_plugin_enabled(p_name) | ||
if enabled: # can only disable an active plugin | ||
get_editor_interface().set_plugin_enabled(p_name, false) | ||
|
||
get_editor_interface().set_plugin_enabled(p_name, true) | ||
|
||
plugin_config.set_value(SETTINGS, SETTING_RECENT, p_name) | ||
_save_settings() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.