godot-plateformer/addons/reedscene/reedscene.gd

120 lines
2.8 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@tool
extends EditorPlugin
var inspector_plugins: Array[EditorInspectorPlugin] = []
const AUTOLOAD_REED_SCENE_NAME: StringName = &"ReedSceneRegistry"
const AUTOLOAD_REED_SCENE_PATH := "res://addons/reedscene/scene/SceneRegistry.gd"
var main_screen: Control
# ======================================================
# 生命周期
# ======================================================
func _enter_tree() -> void:
_load_mainscreen()
_ensure_autoload()
_register_inspectors()
func _exit_tree() -> void:
_unload_mainscreen()
_remove_autoload()
_unregister_inspectors()
# ======================================================
# Inspector Plugins
# ======================================================
func _register_inspectors() -> void:
# Inspector 1ActManager
var act_inspector := preload(
"res://addons/reedscene/act/ActManagerInspector.gd"
).new()
add_inspector_plugin(act_inspector)
inspector_plugins.append(act_inspector)
# Inspector 2ReedSceneID
var scene_id_inspector := preload(
"res://addons/reedscene/scene/ReedSceneIDInspector.gd"
).new()
add_inspector_plugin(scene_id_inspector)
inspector_plugins.append(scene_id_inspector)
func _unregister_inspectors() -> void:
for plugin in inspector_plugins:
remove_inspector_plugin(plugin)
inspector_plugins.clear()
# ======================================================
# 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
# ======================================================
func _load_mainscreen() -> void:
main_screen = preload(
"res://addons/reedscene/dock/SceneIDMainPanel.tscn"
).instantiate()
EditorInterface.get_editor_main_screen().add_child(main_screen)
main_screen.visible = false
func _unload_mainscreen() -> void:
if main_screen:
main_screen.queue_free()
main_screen = null
func _has_main_screen() -> bool:
return true
func _make_visible(visible: bool) -> void:
if not main_screen:
return
main_screen.visible = visible
if visible and main_screen.has_method("on_activated"):
main_screen.on_activated()
# ======================================================
# Meta
# ======================================================
func _get_plugin_name() -> String:
return "Reed Scene"
func _get_plugin_icon() -> Texture2D:
return EditorInterface.get_editor_theme().get_icon(
"Node",
"EditorIcons"
)