2020-04-26 15:47:21 +02:00
|
|
|
tool
|
|
|
|
extends Control
|
|
|
|
|
2022-01-26 19:37:46 +01:00
|
|
|
const DataManagerAddonSettings = preload("res://addons/data_manager/resources/data_manager_addon_settings.gd")
|
|
|
|
|
2020-04-26 15:47:21 +02:00
|
|
|
signal inspect_data
|
|
|
|
|
|
|
|
export(PackedScene) var resource_scene : PackedScene
|
|
|
|
export(PackedScene) var folder_entry_button_scene : PackedScene
|
2022-01-26 18:04:30 +01:00
|
|
|
export(String) var base_folder : String = "res://"
|
2020-04-26 15:47:21 +02:00
|
|
|
export(NodePath) var main_container : NodePath
|
|
|
|
export(NodePath) var folder_entry_container_path : NodePath
|
|
|
|
|
|
|
|
var _main_container : Node
|
|
|
|
var _resource_scene : Node
|
|
|
|
var _folder_entry_container : Node
|
|
|
|
|
2022-01-26 18:04:30 +01:00
|
|
|
var _modules : Array = Array()
|
2022-01-26 19:37:46 +01:00
|
|
|
var _settings : DataManagerAddonSettings = null
|
|
|
|
|
|
|
|
var _initialized : bool = false
|
|
|
|
var _plugin : EditorPlugin = null
|
|
|
|
|
|
|
|
func _enter_tree():
|
2022-01-26 19:40:36 +01:00
|
|
|
if !is_connected("visibility_changed", self, "on_visibility_changed"):
|
|
|
|
connect("visibility_changed", self, "on_visibility_changed")
|
2020-04-26 15:47:21 +02:00
|
|
|
|
2022-01-26 19:37:46 +01:00
|
|
|
func on_visibility_changed():
|
|
|
|
if _plugin && is_visible_in_tree() && !_initialized:
|
|
|
|
_initialized = true
|
|
|
|
load_data()
|
|
|
|
|
|
|
|
func load_data():
|
2020-04-26 15:47:21 +02:00
|
|
|
var dir : Directory = Directory.new()
|
|
|
|
|
2022-01-26 19:37:46 +01:00
|
|
|
_settings = _plugin.settings
|
|
|
|
|
2020-04-26 15:47:21 +02:00
|
|
|
_main_container = get_node(main_container)
|
|
|
|
|
|
|
|
_resource_scene = resource_scene.instance()
|
|
|
|
_main_container.add_child(_resource_scene)
|
|
|
|
_resource_scene.owner = _main_container
|
|
|
|
_resource_scene.connect("inspect_data", self, "inspect_data")
|
|
|
|
|
|
|
|
_folder_entry_container = get_node(folder_entry_container_path)
|
|
|
|
|
|
|
|
for ch in _folder_entry_container.get_children():
|
|
|
|
ch.queue_free()
|
|
|
|
|
|
|
|
var index = 0
|
2022-01-26 19:37:46 +01:00
|
|
|
for f in _settings.folders:
|
|
|
|
if f.header != "":
|
2020-04-26 15:47:21 +02:00
|
|
|
var h : Label = Label.new()
|
|
|
|
|
|
|
|
_folder_entry_container.add_child(h)
|
|
|
|
h.owner = _folder_entry_container
|
|
|
|
|
2022-01-26 19:37:46 +01:00
|
|
|
h.text = f.header
|
2020-04-26 15:47:21 +02:00
|
|
|
|
|
|
|
var fe : Node = folder_entry_button_scene.instance()
|
|
|
|
|
|
|
|
_folder_entry_container.add_child(fe)
|
|
|
|
fe.owner = _folder_entry_container
|
|
|
|
|
2022-01-26 19:37:46 +01:00
|
|
|
fe.text = f.name
|
2020-04-26 15:47:21 +02:00
|
|
|
fe.tab = index
|
|
|
|
|
|
|
|
fe.set_main_panel(self)
|
|
|
|
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
set_tab(0)
|
|
|
|
|
2022-01-26 18:04:30 +01:00
|
|
|
|
|
|
|
func initialize_modules() -> void:
|
|
|
|
_modules.clear()
|
|
|
|
|
|
|
|
load_modules_at("res://")
|
|
|
|
|
|
|
|
_modules.sort_custom(ModulePathSorter, "sort_ascending")
|
|
|
|
|
|
|
|
for module in _modules:
|
|
|
|
if module.has_method("load_module"):
|
|
|
|
module.load_module()
|
|
|
|
|
|
|
|
func load_modules_at(path : String) -> void:
|
|
|
|
var dir = Directory.new()
|
|
|
|
if dir.open(path) == OK:
|
|
|
|
dir.list_dir_begin()
|
|
|
|
var file_name = dir.get_next()
|
|
|
|
while file_name != "":
|
|
|
|
if file_name == "." or file_name == "..":
|
|
|
|
file_name = dir.get_next()
|
|
|
|
continue
|
|
|
|
|
|
|
|
if dir.current_is_dir():
|
|
|
|
if path == "res://":
|
|
|
|
load_modules_at(path + file_name)
|
|
|
|
else:
|
|
|
|
load_modules_at(path + "/" + file_name)
|
|
|
|
else:
|
|
|
|
if file_name == "game_module.tres":
|
|
|
|
var res : Resource = null
|
|
|
|
|
|
|
|
if path == "res://":
|
|
|
|
res = ResourceLoader.load(path + file_name)
|
|
|
|
else:
|
|
|
|
res = ResourceLoader.load(path + "/" + file_name)
|
|
|
|
|
|
|
|
if res.enabled:
|
|
|
|
_modules.append(res)
|
|
|
|
|
|
|
|
file_name = dir.get_next()
|
|
|
|
else:
|
|
|
|
print("An error occurred when trying to access the path: " + path)
|
|
|
|
|
|
|
|
|
|
|
|
class ModulePathSorter:
|
|
|
|
static func sort_ascending(a, b):
|
|
|
|
if a.resource_path < b.resource_path:
|
|
|
|
return true
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
2020-04-26 15:47:21 +02:00
|
|
|
func set_tab(tab_index : int) -> void:
|
|
|
|
hide_all()
|
|
|
|
|
|
|
|
_resource_scene.show()
|
2022-01-26 19:37:46 +01:00
|
|
|
_resource_scene.set_resource_type(_settings.folder_get_folder(tab_index), _settings.folder_get_type(tab_index))
|
2020-04-26 15:47:21 +02:00
|
|
|
|
|
|
|
func hide_all() -> void:
|
|
|
|
_resource_scene.hide()
|
|
|
|
|
|
|
|
func inspect_data(var data : Resource) -> void:
|
|
|
|
emit_signal("inspect_data", data)
|
2022-01-26 19:37:46 +01:00
|
|
|
|
|
|
|
func set_plugin(plugin : EditorPlugin) -> void:
|
|
|
|
_plugin = plugin
|