Skip to content

Commit b8cdac0

Browse files
Merge pull request #31 from nhillen/master
An update to get this working in 4.3
2 parents b4b97bf + c2f81cb commit b8cdac0

File tree

4 files changed

+60
-75
lines changed

4 files changed

+60
-75
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[plugin]
22

33
name="Godot Plugin Refresher"
4-
description="A toolbar addition to facilitate toggling off/on a selected plugin."
4+
description="A toolbar addition to facilitate toggling off/on a selected plugin. Updated for Godot 4.3"
55
author="willnationsdev"
6-
version="1.0"
6+
version="1.2"
77
script="plugin_refresher_plugin.gd"

addons/godot-plugin-refresher/plugin_refresher.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
tool
1+
@tool
22
extends HBoxContainer
33

44
signal request_refresh_plugin(p_name)
55
signal confirm_refresh_plugin(p_name)
66

7-
onready var options = $OptionButton
7+
@onready var options = $OptionButton
88

99
func _ready():
1010
if get_tree().edited_scene_root == self:
1111
return # This is the scene opened in the editor!
12-
$RefreshButton.icon = get_icon("Reload", "EditorIcons")
12+
$RefreshButton.icon = EditorInterface.get_editor_theme().get_icon("Reload", "EditorIcons")
1313

1414

1515
func update_items(p_plugins):
@@ -27,7 +27,7 @@ func update_items(p_plugins):
2727
func select_plugin(p_name):
2828
if not options:
2929
return
30-
if p_name == null or p_name.empty():
30+
if p_name == null or p_name.is_empty():
3131
return
3232

3333
for idx in options.get_item_count():
@@ -42,7 +42,7 @@ func _on_RefreshButton_pressed():
4242
return # nothing selected
4343

4444
var plugin = options.get_item_metadata(options.selected)
45-
if not plugin or plugin.empty():
45+
if not plugin or plugin.is_empty():
4646
return
4747
emit_signal("request_refresh_plugin", plugin)
4848

addons/godot-plugin-refresher/plugin_refresher.tscn

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
1-
[gd_scene load_steps=2 format=2]
1+
[gd_scene load_steps=2 format=3 uid="uid://dnladpgp5dwts"]
22

3-
[ext_resource path="res://addons/godot-plugin-refresher/plugin_refresher.gd" type="Script" id=1]
3+
[ext_resource type="Script" path="res://addons/godot-plugin-refresher/plugin_refresher.gd" id="1"]
44

55
[node name="HBoxContainer" type="HBoxContainer"]
6-
margin_right = 40.0
7-
margin_bottom = 40.0
8-
script = ExtResource( 1 )
9-
__meta__ = {
10-
"_edit_use_anchors_": false
11-
}
6+
script = ExtResource("1")
127

138
[node name="VSeparator" type="VSeparator" parent="."]
14-
margin_right = 4.0
15-
margin_bottom = 40.0
9+
layout_mode = 2
1610

1711
[node name="OptionButton" type="OptionButton" parent="."]
18-
margin_left = 8.0
19-
margin_right = 158.0
20-
margin_bottom = 40.0
21-
rect_min_size = Vector2( 150, 0 )
12+
layout_mode = 2
2213

23-
[node name="RefreshButton" type="ToolButton" parent="."]
24-
margin_left = 162.0
25-
margin_right = 174.0
26-
margin_bottom = 40.0
14+
[node name="RefreshButton" type="Button" parent="."]
15+
layout_mode = 2
2716

2817
[node name="ConfirmationDialog" type="ConfirmationDialog" parent="."]
29-
margin_right = 278.0
30-
margin_bottom = 110.0
31-
rect_min_size = Vector2( 300, 70 )
32-
window_title = "Plugin Refresher"
3318
dialog_autowrap = true
3419

3520
[connection signal="pressed" from="RefreshButton" to="." method="_on_RefreshButton_pressed"]

addons/godot-plugin-refresher/plugin_refresher_plugin.gd

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tool
1+
@tool
22
extends EditorPlugin
33

44
const ADDONS_PATH = "res://addons/"
@@ -11,15 +11,15 @@ var plugin_config = ConfigFile.new()
1111
var refresher
1212

1313
func _enter_tree():
14-
refresher = preload("plugin_refresher.tscn").instance()
14+
refresher = preload("plugin_refresher.tscn").instantiate()
1515
add_control_to_container(CONTAINER_TOOLBAR, refresher)
1616

1717
# Watch whether any plugin is changed, added or removed on the filesystem
1818
var efs = get_editor_interface().get_resource_filesystem()
19-
efs.connect("filesystem_changed", self, "_on_filesystem_changed")
19+
efs.filesystem_changed.connect(_on_filesystem_changed)
2020

21-
refresher.connect("request_refresh_plugin", self, "_on_request_refresh_plugin")
22-
refresher.connect("confirm_refresh_plugin", self, "_on_confirm_refresh_plugin")
21+
refresher.request_refresh_plugin.connect(_on_request_refresh_plugin)
22+
refresher.confirm_refresh_plugin.connect(_on_confirm_refresh_plugin)
2323

2424
_reload_plugins_list()
2525
_load_settings()
@@ -35,63 +35,63 @@ func _reload_plugins_list():
3535
var plugins = {}
3636
var origins = {}
3737

38-
var dir = Directory.new()
39-
dir.open(ADDONS_PATH)
40-
dir.list_dir_begin(true, true)
41-
var file = dir.get_next()
42-
while file:
43-
var addon_dir = ADDONS_PATH.plus_file(file)
44-
if dir.dir_exists(addon_dir) and file != refresher_dir:
45-
var display_name = file
46-
var plugin_config_path = addon_dir.plus_file("plugin.cfg")
47-
if not dir.file_exists(plugin_config_path):
48-
file = dir.get_next()
49-
continue # not a plugin
50-
var plugin_cfg = ConfigFile.new()
51-
plugin_cfg.load(plugin_config_path)
52-
display_name = plugin_cfg.get_value("plugin", "name", file)
53-
if not display_name in origins:
54-
origins[display_name] = [file]
55-
else:
56-
origins[display_name].append(file)
57-
plugins[file] = display_name
58-
file = dir.get_next()
59-
60-
# Specify the exact plugin name in parenthesis in case of naming collisions.
61-
for display_name in origins:
62-
var plugin_names = origins[display_name]
63-
if plugin_names.size() > 1:
64-
for n in plugin_names:
65-
plugins[n] = "%s (%s)" % [display_name, n]
66-
67-
refresher.update_items(plugins)
68-
38+
var dir = DirAccess.open(ADDONS_PATH)
39+
if dir:
40+
dir.list_dir_begin()
41+
var file_name = dir.get_next()
42+
while file_name != "":
43+
44+
var addon_dir = ADDONS_PATH.path_join(file_name)
45+
if dir.dir_exists(addon_dir) and file_name != refresher_dir:
46+
var display_name = file_name
47+
48+
var plugin_config_path = addon_dir.path_join("plugin.cfg")
49+
if not dir.file_exists(plugin_config_path):
50+
file_name = dir.get_next()
51+
continue # not a plugin
52+
var plugin_cfg = ConfigFile.new()
53+
plugin_cfg.load(plugin_config_path)
54+
display_name = plugin_cfg.get_value("plugin", "name", file_name)
55+
if not display_name in origins:
56+
origins[display_name] = [file_name]
57+
else:
58+
origins[display_name].append(file_name)
59+
plugins[file_name] = display_name
60+
file_name = dir.get_next()
61+
62+
# Specify the exact plugin name in parenthesis in case of naming collisions.
63+
for display_name in origins:
64+
var plugin_names = origins[display_name]
65+
if plugin_names.size() > 1:
66+
for n in plugin_names:
67+
plugins[n] = "%s (%s)" % [display_name, n]
68+
69+
refresher.update_items(plugins)
6970

7071
func _load_settings():
7172
var path = get_config_path()
7273

73-
var fs = Directory.new()
74-
if not fs.file_exists(path):
74+
if not FileAccess.file_exists(path):
7575
# Create new if running for the first time
7676
var config = ConfigFile.new()
77-
fs.make_dir_recursive(path.get_base_dir())
77+
DirAccess.make_dir_recursive_absolute(path.get_base_dir())
7878
config.save(path)
7979
else:
8080
plugin_config.load(path)
8181

82-
8382
func _save_settings():
8483
plugin_config.save(get_config_path())
8584

8685

87-
func get_config_path():
88-
var dir = get_editor_interface().get_editor_settings().get_project_settings_dir()
89-
var home = dir.plus_file(PLUGIN_CONFIG_DIR)
90-
var path = home.plus_file(PLUGIN_CONFIG)
86+
func get_config_path() -> String:
87+
var editor_paths = EditorInterface.get_editor_paths()
88+
var dir = editor_paths.get_project_settings_dir()
89+
90+
var home = dir.path_join(PLUGIN_CONFIG_DIR)
91+
var path = home.path_join(PLUGIN_CONFIG)
9192

9293
return path
9394

94-
9595
func _on_filesystem_changed():
9696
if refresher:
9797
_reload_plugins_list()
@@ -107,7 +107,7 @@ func get_recent_plugin():
107107

108108

109109
func _on_request_refresh_plugin(p_name):
110-
assert(not p_name.empty())
110+
assert(not p_name.is_empty())
111111

112112
var disabled = not get_editor_interface().is_plugin_enabled(p_name)
113113
if disabled:

0 commit comments

Comments
 (0)