diff --git a/addons/dialogic/plugin.cfg b/addons/dialogic/plugin.cfg index 6400c6430..e3e18980a 100644 --- a/addons/dialogic/plugin.cfg +++ b/addons/dialogic/plugin.cfg @@ -5,4 +5,5 @@ description="Create dialogs, characters and scenes to display conversations in y https://github.com/dialogic-godot/dialogic" author="Jowan Spooner, Emi, Cake and more!" version="2.0-Alpha-19 WIP (Godot 4.3+)" +godot_version="4.5" script="plugin.gd" diff --git a/addons/dialogic/plugin.gd b/addons/dialogic/plugin.gd index 75df7e64b..cec98c93e 100644 --- a/addons/dialogic/plugin.gd +++ b/addons/dialogic/plugin.gd @@ -19,52 +19,46 @@ func _init() -> void: #region ACTIVATION & EDITOR SETUP ################################################################################ -## Activation & Editor Setup -func _enable_plugin() -> void: - add_autoload_singleton(PLUGIN_NAME, PLUGIN_HANDLER_PATH) - add_dialogic_default_action() - - -func _disable_plugin() -> void: - remove_autoload_singleton(PLUGIN_NAME) - - +## Called when the plugin is activated in the editor. +## Sets up the main editor interface and inspector plugin. func _enter_tree() -> void: + # Add default input action for Dialogic + add_dialogic_default_action() + + # Setup main editor view + # Use call_deferred to ensure editor_main_screen is ready in Godot 4.5+ editor_view = MainPanel.instantiate() editor_view.plugin_reference = self editor_view.hide() - get_editor_interface().get_editor_main_screen().add_child(editor_view) + call_deferred("_add_main_panel_to_editor", editor_view) _make_visible(false) - + + # Setup inspector plugin inspector_plugin = load("res://addons/dialogic/Editor/Inspector/inspector_plugin.gd").new() add_inspector_plugin(inspector_plugin) - # Auto-update the singleton path for alpha users - # TODO remove at some point during beta or later - if not ProjectSettings.has_setting("autoload/"+PLUGIN_NAME) or not "Core" in ProjectSettings.get_setting("autoload/"+PLUGIN_NAME, ""): - if ProjectSettings.has_setting("autoload/"+PLUGIN_NAME): - remove_autoload_singleton(PLUGIN_NAME) - add_autoload_singleton(PLUGIN_NAME, PLUGIN_HANDLER_PATH) + +## Helper function to safely add main panel to editor interface +## Deferred to ensure editor_main_screen is ready in Godot 4.5+ +func _add_main_panel_to_editor(panel: Control) -> void: + var main_screen := get_editor_interface().get_editor_main_screen() + if main_screen: + main_screen.add_child(panel) +## Called when the plugin is deactivated in the editor. +## Cleans up the editor interface. func _exit_tree() -> void: if editor_view: - remove_control_from_bottom_panel(editor_view) + if editor_view.get_parent(): + editor_view.get_parent().remove_child(editor_view) editor_view.queue_free() - + if inspector_plugin: remove_inspector_plugin(inspector_plugin) #endregion - -#region PLUGIN_INFO -################################################################################ - -func _has_main_screen() -> bool: - return true - - func _get_plugin_name() -> String: return PLUGIN_NAME