Skip to content

Commit

Permalink
fix switching wiht other editor modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremi360 committed Oct 21, 2021
1 parent b95608e commit bb5a09f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 20 deletions.
72 changes: 53 additions & 19 deletions addons/advanced-text-label/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ func _enter_tree():

markup_text_editor = preload("MarkupTextEditor/MarkupTextEditor.tscn")
markup_text_editor = markup_text_editor.instance()
markup_text_editor.visible = false
markup_text_editor.size_flags_horizontal = Control.SIZE_EXPAND_FILL
markup_text_editor.size_flags_vertical = Control.SIZE_EXPAND_FILL
editor_parent = get_editor_interface().get_editor_viewport()
editor_parent.add_child(markup_text_editor)
markup_text_editor.size_flags_horizontal = Control.SIZE_EXPAND_FILL
markup_text_editor.size_flags_vertical = Control.SIZE_EXPAND_FILL
markup_text_editor.visible = false

markup_text_editor_button.text = "Markup Text Editor"
markup_text_editor_button.icon = preload("MarkupTextEditor/MarkupTextEditor.svg")
Expand All @@ -31,33 +31,67 @@ func _enter_tree():
button_parent = markup_text_editor_button.get_parent()
button_parent.remove_child(markup_text_editor_button)
button_parent = button_parent.get_child(2)
button_parent.add_child(markup_text_editor_button)

for b in button_parent.get_children():
b.connect("pressed", self, "_on_toggle", [false])

markup_text_editor_button.connect("toggled", self, "_on_toggle")
button_parent.add_child(markup_text_editor_button)
var args := [false, b]
if b == markup_text_editor_button:
args[0] = true

b.connect("pressed", self, "_on_toggle", args)

func _exit_tree():
remove_inspector_plugin(atl_inspector)
markup_text_editor.queue_free()
markup_text_editor_button.queue_free()

func hide_current_editor():
for ch in editor_parent.get_children():
if ch.visible:
ch.visible = false
return
for editor in editor_parent.get_children():
if editor.has_method("show"):
if editor.visible:
editor.visible = false
break

func unpressed_current_button():
for ch in button_parent.get_children():
if ch.pressed:
ch.pressed = false
for b in button_parent.get_children():
if b.pressed:
b.pressed = false
return

func _on_toggle(toggled:bool):
func show_editor(button: ToolButton):
for editor in editor_parent.get_children():
if editor is Control:
match button.text:
"2D":
if editor.get_class() == "CanvasItemEditor":
editor.show()
return

"3D":
if editor.get_class() == "SpatialEditor":
editor.show()
return

"Script":
if editor.get_class() == "ScriptEditor":
editor.show()
return

"AssetLib":
if editor.get_class() == "AssetLibraryEditor":
editor.show()
return
_:
continue

func _on_toggle(toggled:bool, button:ToolButton):
if toggled:
hide_current_editor()
unpressed_current_button()

markup_text_editor.visible = toggled

else:
button.pressed = true
show_editor(button)

markup_text_editor_button.pressed = toggled
markup_text_editor.visible = toggled


2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ config/icon="res://icon.png"

[editor_plugins]

enabled=PoolStringArray( "res://addons/advanced-text-label/plugin.cfg", "res://addons/emojis-for-godot/plugin.cfg", "res://addons/zylann.editor_debugger/plugin.cfg" )
enabled=PoolStringArray( "res://addons/advanced-text-label/plugin.cfg", "res://addons/emojis-for-godot/plugin.cfg" )

[physics]

Expand Down

0 comments on commit bb5a09f

Please sign in to comment.