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
|
2022-01-26 20:21:35 +01:00
|
|
|
export(NodePath) var module_entry_container_path : NodePath
|
2020-04-26 15:47:21 +02:00
|
|
|
export(NodePath) var folder_entry_container_path : NodePath
|
|
|
|
|
|
|
|
var _main_container : Node
|
|
|
|
var _resource_scene : Node
|
2022-01-26 20:21:35 +01:00
|
|
|
var _module_entry_container : Node
|
2020-04-26 15:47:21 +02:00
|
|
|
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")
|
|
|
|
|
2022-01-26 20:21:35 +01:00
|
|
|
_module_entry_container = get_node(module_entry_container_path)
|
|
|
|
load_modules()
|
|
|
|
|
|
|
|
for m in _modules:
|
|
|
|
var label_str : String = m.resource_name
|
|
|
|
|
|
|
|
if label_str == "":
|
|
|
|
label_str = m.resource_path
|
|
|
|
label_str = label_str.replace("res://", "")
|
|
|
|
label_str = label_str.replace("/game_module.tres", "")
|
|
|
|
label_str = label_str.replace("game_module.tres", "")
|
|
|
|
|
|
|
|
var b : Button = Button.new()
|
|
|
|
b.toggle_mode = true
|
|
|
|
b.text = label_str
|
|
|
|
b.set_h_size_flags(SIZE_EXPAND_FILL)
|
|
|
|
b.connect("toggled", self, "on_module_entry_button_toggled", [ m ])
|
|
|
|
_module_entry_container.add_child(b)
|
|
|
|
|
2020-04-26 15:47:21 +02:00
|
|
|
_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 20:21:35 +01:00
|
|
|
func on_module_entry_button_toggled(on : bool, module) -> void:
|
|
|
|
pass
|
2022-01-26 18:04:30 +01:00
|
|
|
|
2022-01-26 20:21:35 +01:00
|
|
|
func load_modules() -> void:
|
2022-01-26 18:04:30 +01:00
|
|
|
_modules.clear()
|
|
|
|
load_modules_at("res://")
|
|
|
|
_modules.sort_custom(ModulePathSorter, "sort_ascending")
|
|
|
|
|
|
|
|
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
|