godot-plateformer/addons/reedscene/reedscene.gd

130 lines
3.1 KiB
GDScript3
Raw Normal View History

2025-12-29 11:54:31 +08:00
@tool
extends EditorPlugin
2025-12-31 13:07:31 +08:00
2026-01-01 16:33:32 +08:00
var inspector_plugins: Array[EditorInspectorPlugin] = []
2026-01-04 21:21:01 +08:00
## Autoload的SceneRegistery的Name
const AUTOLOAD_REED_SCENE_NAME : StringName = &"ReedSceneRegistry"
## Autoload的SceneRegistery的PATH
2026-01-03 23:21:04 +08:00
const AUTOLOAD_REED_SCENE_PATH := "res://addons/reedscene/scene/SceneRegistry.gd"
2026-01-01 16:33:32 +08:00
2026-01-04 21:21:01 +08:00
## Act的Inspector輔助面板
const ACT_INSPECTOR_SCENE_PATH := "res://addons/reedscene/act/ActManagerInspector.gd"
## ID的Inspector輔助面板
const ID_INSEPCTOR_SCENE_PATH := "res://addons/reedscene/scene/ReedSceneIDInspector.gd"
## SceneID注冊查詢面板的位置
const SCENE_ID_MAIN_PANEL_PATH := "res://addons/reedscene/dock/SceneIDMainPanel.tscn"
## 配置Json的地址
const CONFIG_JSON_PATH:= "res://addons/reedscene/plugin_config.json"
2026-01-01 16:33:32 +08:00
var main_screen: Control
2025-12-31 13:07:31 +08:00
2026-01-03 23:21:04 +08:00
# ======================================================
# 生命周期
# ======================================================
2025-12-31 13:07:31 +08:00
func _enter_tree() -> void:
2026-01-01 16:33:32 +08:00
_load_mainscreen()
2026-01-03 23:21:04 +08:00
_ensure_autoload()
_register_inspectors()
func _exit_tree() -> void:
_unload_mainscreen()
_remove_autoload()
_unregister_inspectors()
2026-01-04 21:21:01 +08:00
## 注冊Inspector
2026-01-03 23:21:04 +08:00
func _register_inspectors() -> void:
2026-01-05 15:28:43 +08:00
#TODO: 临时禁用Act的Inspector后续如果有需求再迭代。
2026-01-03 23:21:04 +08:00
# Inspector 1ActManager
2026-01-05 15:28:43 +08:00
#var act_inspector := preload(
#ACT_INSPECTOR_SCENE_PATH
#).new()
#
#add_inspector_plugin(act_inspector)
#inspector_plugins.append(act_inspector)
2026-01-01 16:33:32 +08:00
2026-01-03 23:21:04 +08:00
# Inspector 2ReedSceneID
2026-01-01 16:33:32 +08:00
var scene_id_inspector := preload(
2026-01-04 21:21:01 +08:00
ID_INSEPCTOR_SCENE_PATH
2026-01-01 16:33:32 +08:00
).new()
2026-01-03 23:21:04 +08:00
2026-01-01 16:33:32 +08:00
add_inspector_plugin(scene_id_inspector)
inspector_plugins.append(scene_id_inspector)
2025-12-31 13:07:31 +08:00
2026-01-04 21:21:01 +08:00
## 注銷Inspector
2026-01-03 23:21:04 +08:00
func _unregister_inspectors() -> void:
2026-01-01 16:33:32 +08:00
for plugin in inspector_plugins:
remove_inspector_plugin(plugin)
inspector_plugins.clear()
2026-01-03 23:21:04 +08:00
2026-01-04 21:21:01 +08:00
## 注冊Autoload
2026-01-03 23:21:04 +08:00
func _ensure_autoload() -> void:
var key := "autoload/%s" % AUTOLOAD_REED_SCENE_NAME
if not ProjectSettings.has_setting(key):
add_autoload_singleton(
AUTOLOAD_REED_SCENE_NAME,
AUTOLOAD_REED_SCENE_PATH
)
2026-01-04 21:21:01 +08:00
## 注銷Autoload
2026-01-03 23:21:04 +08:00
func _remove_autoload() -> void:
var key := "autoload/%s" % AUTOLOAD_REED_SCENE_NAME
if ProjectSettings.has_setting(key):
remove_autoload_singleton(AUTOLOAD_REED_SCENE_NAME)
2026-01-04 21:21:01 +08:00
## 加載插件編輯面板
2026-01-01 16:33:32 +08:00
func _load_mainscreen() -> void:
2026-01-03 23:21:04 +08:00
main_screen = preload(
2026-01-04 21:21:01 +08:00
SCENE_ID_MAIN_PANEL_PATH
2026-01-03 23:21:04 +08:00
).instantiate()
2026-01-01 16:33:32 +08:00
EditorInterface.get_editor_main_screen().add_child(main_screen)
main_screen.visible = false
2026-01-04 21:21:01 +08:00
## 注銷插件編輯面板
2026-01-01 16:33:32 +08:00
func _unload_mainscreen() -> void:
if main_screen:
main_screen.queue_free()
main_screen = null
2026-01-03 23:21:04 +08:00
2026-01-01 16:33:32 +08:00
func _has_main_screen() -> bool:
return true
2026-01-03 23:21:04 +08:00
2026-01-01 16:33:32 +08:00
func _make_visible(visible: bool) -> void:
2026-01-03 23:21:04 +08:00
if not main_screen:
return
2026-01-02 18:37:09 +08:00
main_screen.visible = visible
2026-01-03 23:21:04 +08:00
if visible and main_screen.has_method("on_activated"):
main_screen.on_activated()
# ======================================================
# Meta
# ======================================================
2026-01-01 16:33:32 +08:00
func _get_plugin_name() -> String:
return "Reed Scene"
2026-01-03 23:21:04 +08:00
2026-01-01 16:33:32 +08:00
func _get_plugin_icon() -> Texture2D:
2026-01-03 23:21:04 +08:00
return EditorInterface.get_editor_theme().get_icon(
"Node",
"EditorIcons"
)
2026-01-04 21:21:01 +08:00
## 通過Json獲取到Plugin的基本配置
func _get_config_data() -> Dictionary:
return {}