This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
Jessist/addons/dialogue_manager/plugin.gd

71 lines
1.8 KiB
GDScript3
Raw Permalink Normal View History

2022-06-18 13:05:48 +02:00
tool
extends EditorPlugin
const DialogueResource = preload("res://addons/dialogue_manager/dialogue_resource.gd")
const DialogueExportPlugin = preload("res://addons/dialogue_manager/editor_export_plugin.gd")
const MainView = preload("res://addons/dialogue_manager/views/main_view.tscn")
var export_plugin = DialogueExportPlugin.new()
var main_view
func _enter_tree() -> void:
add_autoload_singleton("DialogueManager", "res://addons/dialogue_manager/dialogue_manager.gd")
add_custom_type("DialogueLabel", "RichTextLabel", preload("res://addons/dialogue_manager/dialogue_label.gd"), get_plugin_icon())
if Engine.editor_hint:
add_export_plugin(export_plugin)
main_view = MainView.instance()
get_editor_interface().get_editor_viewport().add_child(main_view)
main_view.plugin = self
make_visible(false)
func _exit_tree() -> void:
remove_custom_type("DialogueLabel")
remove_autoload_singleton("DialogueManager")
if is_instance_valid(main_view):
main_view.queue_free()
if export_plugin:
remove_export_plugin(export_plugin)
func has_main_screen() -> bool:
return true
func make_visible(next_visible: bool) -> void:
if is_instance_valid(main_view):
main_view.visible = next_visible
func get_plugin_name() -> String:
return "Dialogue"
func get_plugin_icon() -> Texture:
var scale = get_editor_interface().get_editor_scale()
var base_color = get_editor_interface().get_editor_settings().get_setting("interface/theme/base_color")
var theme = "light" if base_color.v > 0.5 else "dark"
return load("res://addons/dialogue_manager/assets/icons/icon_%s_%d.svg" % [theme, scale]) as Texture
func handles(object) -> bool:
return object is DialogueResource
func edit(object) -> void:
if is_instance_valid(main_view):
main_view.open_resource(object)
func apply_changes() -> void:
if is_instance_valid(main_view):
main_view.apply_changes()