Skip to content

Commit

Permalink
Workaround for leaked instances.
Browse files Browse the repository at this point in the history
While godotengine/godot#55648 is solved and
merged, I ended making all inspectors in a single file.

Is not a good idea, is hard to mantain, but that's what I do for now.
  • Loading branch information
AnidemDex committed Dec 6, 2021
1 parent a45b298 commit 8d8c803
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 135 deletions.
127 changes: 0 additions & 127 deletions addons/textalog/events/dialog/text_inspector.gd

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,111 @@
# All inspectors must be in a single script due to
# https://github.com/godotengine/godot/issues/55648
# May be splited in 3.5+

extends EditorInspectorPlugin

class DisplayNameProperty extends EditorProperty:
var line_edit:LineEdit
var updating:bool

func _init() -> void:
line_edit = LineEdit.new()
line_edit.connect("text_changed", self, "_on_text_changed")
line_edit.connect("text_entered", self, "_on_text_entered")

add_child(line_edit)
set_bottom_editor(line_edit)

add_focusable(line_edit)

updating = false


func update_property() -> void:
var actual_value:String = str(get_edited_object()[get_edited_property()])

updating = true
if line_edit.text != actual_value:
line_edit.text = actual_value

line_edit.editable = !read_only
updating = false


func _on_text_entered(new_text:String) -> void:
if updating:
return

if line_edit.has_focus():
line_edit.release_focus()
_on_text_changed(new_text)


func _on_text_changed(new_text:String) -> void:
if updating:
return

emit_changed(get_edited_property(), new_text, "", true)


class TextProperty extends EditorProperty:
var vb:VBoxContainer
var text:TextEdit
var big_text:TextEdit
var big_text_dialog:AcceptDialog

func _text_changed() -> void:
emit_changed(get_edited_property(), text.text, "", true)


func _init() -> void:
vb = VBoxContainer.new()

text = TextEdit.new()
text.wrap_enabled = true
text.size_flags_vertical = SIZE_EXPAND_FILL
text.connect("text_changed", self, "_text_changed")
add_focusable(text)

var hb := HBoxContainer.new()
# TODO: Add buttons to get shortcuts to bbcode tags
var help_btn := LinkButton.new()
help_btn.text = "More information"
help_btn.underline = LinkButton.UNDERLINE_MODE_ON_HOVER
help_btn.size_flags_horizontal = SIZE_SHRINK_END | SIZE_EXPAND
help_btn.connect("pressed", self, "_on_HelpButton_pressed")

hb.add_child(help_btn)

vb.add_child(hb)
vb.add_child(text)

add_child(vb)
set_bottom_editor(vb)


func update_property() -> void:
var actual_value:String = get_edited_object()[get_edited_property()]
if (text.text != actual_value):
text.text = actual_value


func _notification(what: int) -> void:
match what:
NOTIFICATION_ENTER_TREE, NOTIFICATION_THEME_CHANGED:
var font = get_font("font","Label")
text.rect_min_size = Vector2(0, font.get_height() * 6)


func set_disabled(value:bool) -> void:
read_only = value
text.readonly = read_only


func _on_HelpButton_pressed() -> void:
OS.shell_open("https://docs.godotengine.org/en/stable/tutorials/gui/bbcode_in_richtextlabel.html")


class OptionProperty extends EditorProperty:
var selector:BaseButton
var remover:BaseButton
Expand Down Expand Up @@ -104,12 +210,24 @@ var plugin_script:EditorPlugin
var editor_inspector:EditorInspector
var editor_gui:Control

var ObjClass = load("res://addons/textalog/events/dialog/choice.gd")
var TextClass = load("res://addons/textalog/events/dialog/text.gd")
var ChoiceClass = load("res://addons/textalog/events/dialog/choice.gd")

func can_handle(object: Object) -> bool:
return object is ObjClass

if object is TextClass:
return true

if object is ChoiceClass:
return true

return false


func parse_begin(object: Object) -> void:
if not(object is ChoiceClass):
return

var custom_category := InspectorTools.InspectorCategory.new()
custom_category.label = "OptionTool"
custom_category.icon = editor_gui.get_icon("Tools", "EditorIcons")
Expand All @@ -121,14 +239,34 @@ func parse_begin(object: Object) -> void:
custom_control.edited_object = object
custom_control.undo_redo = plugin_script.get_undo_redo()
add_custom_control(custom_control)



func parse_property(object: Object, type: int, path: String, hint: int, hint_text: String, usage: int) -> bool:
if path.begins_with("options/"):
var option_property = OptionProperty.new()
option_property.undo_redo = plugin_script.get_undo_redo()
add_property_editor(path, option_property)
if object is TextClass:
if type == TYPE_ARRAY and path == "audio_sounds":
if object.get("audio_same_as_character"):
return true

return true
if path == "display_name":
var property_node := DisplayNameProperty.new()
add_property_editor(path, property_node)
return true

if path == "text":
var property_node := TextProperty.new()
if object.get("translation_key"):
property_node.set_disabled(true)
add_property_editor(path, property_node)
return true


if object is ChoiceClass:
if path.begins_with("options/"):
var option_property = OptionProperty.new()
option_property.undo_redo = plugin_script.get_undo_redo()
add_property_editor(path, option_property)

return true

return false

0 comments on commit 8d8c803

Please sign in to comment.