godot-plateformer/addons/reedscene/reedscene.gd

120 lines
2.8 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-03 23:21:04 +08:00
const AUTOLOAD_REED_SCENE_NAME: StringName = &"ReedSceneRegistry"
const AUTOLOAD_REED_SCENE_PATH := "res://addons/reedscene/scene/SceneRegistry.gd"
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()
# ======================================================
# Inspector Plugins
# ======================================================
func _register_inspectors() -> void:
# Inspector 1ActManager
2026-01-01 16:33:32 +08:00
var act_inspector := preload(
"res://addons/reedscene/act/ActManagerInspector.gd"
).new()
2026-01-03 23:21:04 +08:00
2026-01-01 16:33:32 +08:00
add_inspector_plugin(act_inspector)
inspector_plugins.append(act_inspector)
2026-01-03 23:21:04 +08:00
# Inspector 2ReedSceneID
2026-01-01 16:33:32 +08:00
var scene_id_inspector := preload(
"res://addons/reedscene/scene/ReedSceneIDInspector.gd"
).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-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
# ======================================================
# Autoload
# ======================================================
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
)
func _remove_autoload() -> void:
var key := "autoload/%s" % AUTOLOAD_REED_SCENE_NAME
if ProjectSettings.has_setting(key):
remove_autoload_singleton(AUTOLOAD_REED_SCENE_NAME)
# ======================================================
# Main Screen
# ======================================================
2026-01-01 16:33:32 +08:00
func _load_mainscreen() -> void:
2026-01-03 23:21:04 +08:00
main_screen = preload(
"res://addons/reedscene/dock/SceneIDMainPanel.tscn"
).instantiate()
2026-01-01 16:33:32 +08:00
EditorInterface.get_editor_main_screen().add_child(main_screen)
main_screen.visible = false
2026-01-03 23:21:04 +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"
)