Skip to content

Commit

Permalink
Update inspector plugins
Browse files Browse the repository at this point in the history
Fix #1
  • Loading branch information
AnidemDex committed May 8, 2021
1 parent 9d3589c commit b42abee
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
4 changes: 0 additions & 4 deletions addons/dialog_plugin/Editor/EditorMainNode.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ func _ready() -> void:
instance_editor_scene()


func _draw() -> void:
if visible:
instance_editor_scene()

func scan_resources() -> void:
DialogDB.Timelines.get_database().scan_resources_folder()
DialogDB.Characters.get_database().scan_resources_folder()
Expand Down
4 changes: 4 additions & 0 deletions addons/dialog_plugin/Editor/EditorView.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ func _on_ToolBar_timeline_selected(timeline) -> void:
_editor_view = TimelineEditorScene.instance()
_editor_view.base_resource = timeline
$ViewContainer.add_child(_editor_view)

func _exit_tree() -> void:
if _editor_view and is_instance_valid(_editor_view):
_editor_view.free()
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
tool
#tool
extends EditorInspectorPlugin

const BaseMetaEditorScene = preload("res://addons/dialog_plugin/Other/translation_service/editor_node/base_meta_editor.tscn")
const TextMetaEditorScene = preload("res://addons/dialog_plugin/Other/translation_service/editor_node/text_node/text_meta_editor.tscn")
var BaseMetaEditorScene = load("res://addons/dialog_plugin/Other/translation_service/editor_node/base_meta_editor.tscn")
var TextMetaEditorScene = load("res://addons/dialog_plugin/Other/translation_service/editor_node/text_node/text_meta_editor.tscn")

var modified_object = null
var _control = null

func parse_begin(object: Object) -> void:
if object is Control:
modified_object = object


func can_handle(object: Object) -> bool:
if object is Control:
return true
return false


func parse_end() -> void:
if modified_object:
var _control
if _control and is_instance_valid(_control):
print("Control existed before calling parse end")
_control.free()
_control = null

if "text" in modified_object:
_control = TextMetaEditorScene.instance()
pass
else:
_control = BaseMetaEditorScene.instance()
pass
_control.BaseNode = modified_object
add_custom_control(_control)

Expand All @@ -30,4 +39,7 @@ func _notification(what:int) -> void:
if what == NOTIFICATION_PREDELETE:
if modified_object:
modified_object = null
if _control and is_instance_valid(_control):
_control.free()
_control = null

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ static func get_editor_locale() -> String:
var _locale = "en"

if Engine.editor_hint:
_locale = EditorPlugin.new().get_editor_interface().get_editor_settings().get_setting("interface/editor/editor_language")
var _editor_plugin = EditorPlugin.new()
_locale = _editor_plugin.get_editor_interface().get_editor_settings().get_setting("interface/editor/editor_language")
_editor_plugin.free()
else:
# Just if someone try to get the editor locale in game for some reason
_locale = TranslationServer.get_locale()
Expand Down
34 changes: 25 additions & 9 deletions addons/dialog_plugin/plugin_script.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tool
extends EditorPlugin

const PLUGIN_NAME = "Dialog Editor"
const DialogResources = preload("res://addons/dialog_plugin/Core/DialogResources.gd")
const EditorView_Scene = preload("res://addons/dialog_plugin/Editor/EditorMainNode.tscn")
const Dialog_i18n = preload("res://addons/dialog_plugin/Core/Dialog_i18n.gd")
Expand All @@ -15,11 +16,10 @@ func _enter_tree() -> void:
DialogResources.verify_resource_directories()
_add_editor_translations()

_editor_view = EditorView_Scene.instance()
var _err = connect("main_screen_changed", self, "_on_main_screen_changed")

# _add_editor_inspector_plugins()

get_editor_interface().get_editor_viewport().add_child(_editor_view)
_add_editor_inspector_plugins()

make_visible(false)

Expand All @@ -31,10 +31,7 @@ func _ready() -> void:


func _exit_tree() -> void:
if _editor_view:
_editor_view.queue_free()
_editor_view = null

_remove_main_editor()
_remove_editor_inspector_plugins()
_remove_editor_translations()

Expand All @@ -45,7 +42,7 @@ func has_main_screen() -> bool:


func get_plugin_name() -> String:
return "Dialog Editor"
return PLUGIN_NAME


# Copied
Expand Down Expand Up @@ -73,6 +70,8 @@ func _remove_editor_inspector_plugins() -> void:
remove_inspector_plugin(_parts_inspector)
if _translation_inspector:
remove_inspector_plugin(_translation_inspector)
# For some reason that i don't know, i have to force an unreference to this object
_translation_inspector.unreference()

_parts_inspector = null
_translation_inspector = null
Expand All @@ -85,5 +84,22 @@ func _add_editor_translations() -> void:

func _remove_editor_translations() -> void:
Dialog_i18n.remove_editor_translations()
_editor_view = null


func _add_main_editor() -> void:
_editor_view = EditorView_Scene.instance()
get_editor_interface().get_editor_viewport().add_child(_editor_view)
pass


func _remove_main_editor() -> void:
if _editor_view and is_instance_valid(_editor_view):
_editor_view.free()
_editor_view = null


func _on_main_screen_changed(screen_name:String) -> void:
if screen_name == PLUGIN_NAME:
_add_main_editor()
else:
_remove_main_editor()

0 comments on commit b42abee

Please sign in to comment.