2019-09-24 14:01:37 +00:00
|
|
|
tool
|
|
|
|
extends EditorPlugin
|
|
|
|
|
|
|
|
var ScreenReader = preload("ScreenReader.gd")
|
|
|
|
|
|
|
|
var screen_reader
|
|
|
|
|
2020-05-19 17:03:59 +00:00
|
|
|
|
2020-06-16 23:03:13 +00:00
|
|
|
func set_initial_screen_focus(screen):
|
|
|
|
if not screen_reader.enabled:
|
|
|
|
return
|
|
|
|
TTS.speak("%s: screen" % screen, false)
|
|
|
|
var control = screen_reader.find_focusable_control(get_tree().root)
|
|
|
|
if control.get_focus_owner() != null:
|
|
|
|
return
|
|
|
|
screen_reader.augment_tree(get_tree().root)
|
|
|
|
var focus = screen_reader.find_focusable_control(get_tree().root)
|
|
|
|
if not focus:
|
|
|
|
return
|
|
|
|
focus.grab_click_focus()
|
|
|
|
focus.grab_focus()
|
|
|
|
|
|
|
|
|
2019-09-24 14:01:37 +00:00
|
|
|
func _enter_tree():
|
2020-05-19 17:03:59 +00:00
|
|
|
var editor_accessibility_enabled = true
|
2020-09-02 14:19:43 +00:00
|
|
|
add_autoload_singleton("TTS", "res://addons/godot-tts/TTS.gd")
|
|
|
|
var rate = TTS.normal_rate
|
2020-05-19 17:03:59 +00:00
|
|
|
var config = ConfigFile.new()
|
|
|
|
var err = config.load("res://.godot-accessibility-editor-settings.ini")
|
|
|
|
if not err:
|
|
|
|
editor_accessibility_enabled = config.get_value(
|
|
|
|
"global", "editor_accessibility_enabled", true
|
|
|
|
)
|
|
|
|
rate = config.get_value("speech", "rate", 50)
|
|
|
|
if editor_accessibility_enabled:
|
2020-05-28 18:13:06 +00:00
|
|
|
TTS.call_deferred("_set_rate", rate)
|
2020-05-19 17:03:59 +00:00
|
|
|
screen_reader = ScreenReader.new()
|
2020-05-28 18:13:06 +00:00
|
|
|
screen_reader.enable_focus_mode = true
|
2020-05-19 17:03:59 +00:00
|
|
|
get_tree().root.call_deferred("add_child", screen_reader)
|
|
|
|
add_custom_type("ScreenReader", "Node", preload("ScreenReader.gd"), null)
|
|
|
|
|
2019-09-24 14:20:45 +00:00
|
|
|
|
|
|
|
func _exit_tree():
|
2020-05-19 17:03:59 +00:00
|
|
|
remove_custom_type("ScreenReader")
|
2020-06-10 16:45:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
var _focus_loss_interval = 0
|
|
|
|
|
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
if not screen_reader.enabled:
|
|
|
|
return
|
2020-06-16 23:03:13 +00:00
|
|
|
var focus = screen_reader.find_focusable_control(get_tree().root)
|
2020-06-10 16:45:32 +00:00
|
|
|
focus = focus.get_focus_owner()
|
|
|
|
if focus:
|
|
|
|
_focus_loss_interval = 0
|
|
|
|
else:
|
|
|
|
_focus_loss_interval += delta
|
|
|
|
if _focus_loss_interval >= 0.2:
|
|
|
|
_focus_loss_interval = 0
|
2020-06-16 23:03:13 +00:00
|
|
|
focus = screen_reader.find_focusable_control(get_tree().root)
|
2020-06-10 16:45:32 +00:00
|
|
|
focus.grab_focus()
|
|
|
|
focus.grab_click_focus()
|