Reformat.

This commit is contained in:
Nolan Darilek 2020-05-19 12:03:59 -05:00
parent 6279f1a3c9
commit 9e2e99349c
3 changed files with 811 additions and 687 deletions

View File

@ -6,12 +6,14 @@ var position_in_children = 0
var column_in_row = 0
func get_siblings():
var parent = node.get_parent()
if parent:
return parent.get_children()
return null
func click(item := node, button_index = BUTTON_LEFT):
print_debug("Click")
var click = InputEventMouseButton.new()
@ -25,6 +27,7 @@ func click(item := node, button_index = BUTTON_LEFT):
click.pressed = false
node.get_tree().input_event(click)
func guess_label():
var tokens = PoolStringArray([])
var to_check = node
@ -33,7 +36,10 @@ func guess_label():
return
if to_check.is_class("EditorProperty") and to_check.label:
tokens.append(to_check.label)
if (to_check.is_class("EditorProperty") or to_check.is_class("EditorInspectorCategory")) and to_check.get_tooltip_text():
if (
(to_check.is_class("EditorProperty") or to_check.is_class("EditorInspectorCategory"))
and to_check.get_tooltip_text()
):
tokens.append(to_check.get_tooltip_text())
var label = tokens.join(": ")
if label:
@ -43,19 +49,23 @@ func guess_label():
return child
to_check = to_check.get_parent()
func _accept_dialog_speak():
if node.dialog_text != "":
TTS.speak("dialog: %s" % node.dialog_text)
func accept_dialog_focused():
_accept_dialog_speak()
if node.get_parent() and node.get_parent().is_class("ProjectSettingsEditor"):
yield(node.get_tree().create_timer(5), "timeout")
node.get_ok().emit_signal("pressed")
func _accept_dialog_about_to_show():
_accept_dialog_speak()
func checkbox_focused():
var tokens = PoolStringArray([])
if node.pressed:
@ -65,6 +75,7 @@ func checkbox_focused():
tokens.append(" checkbox")
TTS.speak(tokens.join(" "), false)
func checkbox_toggled(checked):
if node.has_focus():
if checked:
@ -72,8 +83,10 @@ func checkbox_toggled(checked):
else:
TTS.speak("unchecked", true)
var spoke_hint_tooltip
func button_focused():
var tokens = PoolStringArray([])
if node.text:
@ -86,6 +99,7 @@ func button_focused():
tokens.append("disabled")
TTS.speak(tokens.join(": "), false)
func texturebutton_focused():
var texture = node.texture_normal
print_debug(texture.resource_name)
@ -95,6 +109,7 @@ func texturebutton_focused():
print_debug(rid.get_id())
TTS.speak("button", false)
func item_list_item_focused(idx):
var tokens = PoolStringArray([])
var text = node.get_item_text(idx)
@ -106,6 +121,7 @@ func item_list_item_focused(idx):
tokens.append("%s of %s" % [idx + 1, node.get_item_count()])
TTS.speak(tokens.join(": "))
func item_list_focused():
var count = node.get_item_count()
var selected = node.get_selected_items()
@ -121,15 +137,19 @@ func item_list_focused():
position_in_children = selected
item_list_item_focused(selected)
func item_list_item_selected(index):
item_list_item_focused(index)
func item_list_multi_selected(index, selected):
TTS.speak("Multiselect", false)
func item_list_nothing_selected():
TTS.speak("Nothing selected", true)
func item_list_input(event):
if event.is_action_pressed("ui_right") or event.is_action_pressed("ui_left"):
return node.accept_event()
@ -159,12 +179,14 @@ func item_list_input(event):
node.emit_signal("item_list_item_selected", position_in_children)
item_list_item_focused(position_in_children)
func label_focused():
var text = node.text
if text == "":
text = "blank"
TTS.speak(text, false)
func line_edit_focused():
var text = "blank"
if node.secret:
@ -178,10 +200,12 @@ func line_edit_focused():
type = "text"
TTS.speak("%s: %s" % [text, type], false)
var old_text = ""
var old_pos
func line_edit_text_changed(text):
if text == null or old_text == null:
return
@ -196,6 +220,7 @@ func line_edit_text_changed(text):
TTS.speak(old_text.substr(i, 1))
return
func line_edit_input(event):
var pos = node.caret_position
if old_pos != null and old_pos != pos:
@ -210,6 +235,7 @@ func line_edit_input(event):
old_pos = pos
old_text = node.text
func menu_button_focused():
var tokens = PoolStringArray([])
if node.text:
@ -220,9 +246,11 @@ func menu_button_focused():
tokens.append("menu")
TTS.speak(tokens.join(": "), false)
func popup_menu_focused():
TTS.speak("menu", false)
func popup_menu_item_id_focused(index):
print_debug("item id focus %s" % index)
var tokens = PoolStringArray([])
@ -256,6 +284,7 @@ func popup_menu_item_id_focused(index):
tokens.append(str(index + 1) + " of " + str(node.get_item_count()))
TTS.speak(tokens.join(": "), true)
func popup_menu_item_id_pressed(index):
if node.is_item_checkable(index):
if node.is_item_checked(index):
@ -263,6 +292,7 @@ func popup_menu_item_id_pressed(index):
else:
TTS.speak("unchecked", true)
func range_focused():
var tokens = PoolStringArray([])
tokens.append(str(node.value))
@ -278,10 +308,12 @@ func range_focused():
tokens.append("maximum %s" % node.max_value)
TTS.speak(tokens.join(": "), false)
func range_value_changed(value):
if node.has_focus():
TTS.speak("%s" % value, true)
func text_edit_focus():
var tokens = PoolStringArray([])
if node.text:
@ -294,9 +326,11 @@ func text_edit_focus():
tokens.append("edit text")
TTS.speak(tokens.join(": "), false)
func text_edit_input(event):
pass
func tree_item_render():
var focused_tree_item = node.get_selected()
var tokens = PoolStringArray([])
@ -312,10 +346,12 @@ func tree_item_render():
tokens.append("selected")
TTS.speak(tokens.join(": "), true)
func tree_item_deselect_all(item: TreeItem):
for i in range(node.columns):
item.deselect(i)
func tree_deselect_all_but(target: TreeItem, tree: Tree):
var cur = tree.get_root()
while cur != null:
@ -323,10 +359,12 @@ func tree_deselect_all_but(target: TreeItem, tree: Tree):
tree_item_deselect_all(cur)
cur = tree.get_next_selected(cur)
var prev_selected_cell
var button_index
func tree_item_selected():
button_index = null
var cell = node.get_selected()
@ -350,7 +388,13 @@ func tree_item_selected():
var button_count = cell.get_button_count(i)
if button_count != 0:
button_index = 0
tokens.append(str(button_count) + " " + TTS.singular_or_plural(button_count, "button", "buttons"))
tokens.append(
(
str(button_count)
+ " "
+ TTS.singular_or_plural(button_count, "button", "buttons")
)
)
if cell.has_method("get_button_tooltip"):
var button_tooltip = cell.get_button_tooltip(i, button_index)
if button_tooltip:
@ -360,12 +404,14 @@ func tree_item_selected():
tokens.append("Use Home and End to switch focus.")
TTS.speak(tokens.join(": "), true)
func tree_item_multi_selected(item, column, selected):
if selected:
TTS.speak("selected", true)
else:
TTS.speak("unselected", true)
func tree_input(event):
var item = node.get_selected()
var column
@ -380,7 +426,10 @@ func tree_input(event):
area = node.get_item_area_rect(item, column)
else:
area = node.get_item_area_rect(item)
var position = Vector2(node.rect_global_position.x + area.position.x + area.size.x / 2, node.rect_global_position.y + area.position.y + area.size.y / 2)
var position = Vector2(
node.rect_global_position.x + area.position.x + area.size.x / 2,
node.rect_global_position.y + area.position.y + area.size.y / 2
)
node.get_tree().root.warp_mouse(position)
if item and column and button_index != null:
if event.is_action_pressed("ui_accept"):
@ -406,12 +455,14 @@ func tree_input(event):
tokens.append("button")
TTS.speak(tokens.join(": "), true)
func tree_focused():
if node.get_selected():
tree_item_render()
else:
TTS.speak("tree", true)
func tree_item_collapsed(item):
if node.has_focus():
if item.collapsed:
@ -419,33 +470,42 @@ func tree_item_collapsed(item):
else:
TTS.speak("expanded", true)
func progress_bar_focused():
var percentage = int(node.ratio * 100)
TTS.speak("%s percent" % percentage, false)
TTS.speak("progress bar", false)
var last_percentage_spoken
var last_percentage_spoken_at = 0
func progress_bar_value_changed(value):
var percentage = node.value / (node.max_value - node.min_value) * 100
percentage = int(percentage)
if percentage != last_percentage_spoken and OS.get_ticks_msec() - last_percentage_spoken_at >= 10000:
if (
percentage != last_percentage_spoken
and OS.get_ticks_msec() - last_percentage_spoken_at >= 10000
):
TTS.speak("%s percent" % percentage)
last_percentage_spoken_at = OS.get_ticks_msec()
last_percentage_spoken = percentage
func tab_container_focused():
var text = node.get_tab_title(node.current_tab)
text += ": tab: " + str(node.current_tab + 1) + " of " + str(node.get_tab_count())
TTS.speak(text, false)
func tab_container_tab_changed(tab):
if node.has_focus():
TTS.stop()
tab_container_focused()
func tab_container_input(event):
var new_tab = node.current_tab
if event.is_action_pressed("ui_right"):
@ -461,6 +521,7 @@ func tab_container_input(event):
if node.current_tab != new_tab:
node.current_tab = new_tab
func focused():
print_debug("Focus: %s" % node)
TTS.stop()
@ -510,13 +571,16 @@ func focused():
TTS.speak(node.hint_tooltip, false)
spoke_hint_tooltip = false
var timer
func unfocused():
print_debug("Unfocused")
position_in_children = 0
timer = node.get_tree().create_timer(1)
func click_focused():
if node.has_focus():
return
@ -524,8 +588,14 @@ func click_focused():
print_debug("Grabbing focus: %s" % node)
node.grab_focus()
func gui_input(event):
if event is InputEventKey and Input.is_action_just_pressed("ui_accept") and event.control and event.alt:
if (
event is InputEventKey
and Input.is_action_just_pressed("ui_accept")
and event.control
and event.alt
):
TTS.speak("click", false)
click()
elif event is InputEventKey and event.pressed and not event.echo and event.scancode == KEY_MENU:
@ -540,12 +610,18 @@ func gui_input(event):
elif node is TextEdit:
return text_edit_input(event)
elif node is Tree:
if event.is_action_pressed("ui_up") or event.is_action_pressed("ui_down") or event.is_action_pressed("ui_left") or event.is_action_pressed("ui_right"):
if (
event.is_action_pressed("ui_up")
or event.is_action_pressed("ui_down")
or event.is_action_pressed("ui_left")
or event.is_action_pressed("ui_right")
):
node.accept_event()
return tree_input(event)
elif node.is_class("EditorInspectorSection"):
return editor_inspector_section_input(event)
func is_in_bar():
var parent = node.get_parent()
if parent and parent is Container:
@ -555,6 +631,7 @@ func is_in_bar():
return true
return false
func is_focusable(node):
if node.is_class("SceneTreeEditor"):
return false
@ -578,10 +655,17 @@ func is_focusable(node):
return true
if node is Label and node.get_parent() and node.get_parent() is AcceptDialog:
return false
if node is Container or node is Separator or node is ScrollBar or node is Popup or node.get_class() == "Control":
if (
node is Container
or node is Separator
or node is ScrollBar
or node is Popup
or node.get_class() == "Control"
):
return false
return true
func editor_inspector_section_focused():
var child = node.get_children()[0]
var expanded = child.is_visible_in_tree()
@ -592,6 +676,7 @@ func editor_inspector_section_focused():
tokens.append("collapsed")
TTS.speak(tokens.join(": "), false)
func editor_inspector_section_input(event):
if event.is_action_pressed("ui_accept"):
click()
@ -602,6 +687,7 @@ func editor_inspector_section_input(event):
else:
TTS.speak("collapsed", true)
func _init(node):
if node.is_in_group("accessible"):
return
@ -647,12 +733,14 @@ func _init(node):
node.connect("item_selected", self, "tree_item_selected")
node.connect("tree_exiting", self, "queue_free", [], Object.CONNECT_DEFERRED)
func _process(delta):
if timer and timer.time_left <= 0:
if node.is_inside_tree() and not node.get_focus_owner():
node.get_tree().root.warp_mouse(node.rect_global_position)
timer = null
func free():
if timer:
timer.unreference()

View File

@ -5,13 +5,16 @@ var ScreenReader = preload("ScreenReader.gd")
var screen_reader
func _enter_tree():
var editor_accessibility_enabled = true
var rate = 50
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)
editor_accessibility_enabled = config.get_value(
"global", "editor_accessibility_enabled", true
)
rate = config.get_value("speech", "rate", 50)
add_autoload_singleton("TTS", "res://addons/godot-tts/TTS.gd")
if editor_accessibility_enabled:
@ -22,5 +25,6 @@ func _enter_tree():
call_deferred("connect", "main_screen_changed", screen_reader, "set_initial_screen_focus")
add_custom_type("ScreenReader", "Node", preload("ScreenReader.gd"), null)
func _exit_tree():
remove_custom_type("ScreenReader")

View File

@ -21,6 +21,7 @@ export var explore_by_touch_interval = 200
var focus_restore_timer
func _set_enabled(v):
if enabled:
augment_tree(get_tree().root)
@ -28,18 +29,23 @@ func _set_enabled(v):
pass
enabled = v
func _get_enabled():
return enabled
func focused(node):
focus_restore_timer = null
func click_focused(node):
pass
func unfocused(node):
focus_restore_timer = get_tree().create_timer(0.2)
func augment_node(node):
if not enabled:
return
@ -54,6 +60,7 @@ func augment_node(node):
if not node.is_connected("mouse_exited", self, "unfocused"):
node.connect("mouse_exited", self, "unfocused", [node])
func augment_tree(node):
if not enabled:
return
@ -63,6 +70,7 @@ func augment_tree(node):
for child in node.get_children():
augment_tree(child)
func set_initial_screen_focus(screen):
TTS.speak("%s: screen" % screen, false)
var control = find_focusable_control(get_tree().root)
@ -75,8 +83,13 @@ func set_initial_screen_focus(screen):
focus.grab_click_focus()
focus.grab_focus()
func find_focusable_control(node):
if node is Control and node.is_visible_in_tree() and (node.focus_mode == Control.FOCUS_CLICK or node.focus_mode == Control.FOCUS_ALL):
if (
node is Control
and node.is_visible_in_tree()
and (node.focus_mode == Control.FOCUS_CLICK or node.focus_mode == Control.FOCUS_ALL)
):
return node
for child in node.get_children():
var result = find_focusable_control(child)
@ -84,6 +97,7 @@ func find_focusable_control(node):
return result
return null
func set_initial_scene_focus(scene):
self.augment_tree(get_tree().root)
var focus = find_focusable_control(get_tree().root)
@ -92,6 +106,7 @@ func set_initial_scene_focus(scene):
focus.grab_click_focus()
focus.grab_focus()
func _enter_tree():
if enabled:
augment_tree(get_tree().root)
@ -101,6 +116,7 @@ func _enter_tree():
connect("swipe_up", self, "swipe_up")
connect("swipe_down", self, "swipe_down")
func press_and_release(action):
var event = InputEventAction.new()
event.action = action
@ -109,6 +125,7 @@ func press_and_release(action):
event.pressed = false
get_tree().input_event(event)
func _ui_focus_next():
for event in InputMap.get_action_list("ui_focus_next"):
if event is InputEventKey:
@ -120,6 +137,7 @@ func _ui_focus_next():
get_tree().input_event(event)
return
func _ui_focus_prev():
for event in InputMap.get_action_list("ui_focus_prev"):
if event is InputEventKey:
@ -131,18 +149,23 @@ func _ui_focus_prev():
get_tree().input_event(event)
return
func swipe_right():
_ui_focus_next()
func swipe_left():
_ui_focus_prev()
func swipe_up():
TTS.speak("Swipe up")
func swipe_down():
TTS.speak("Swipe down")
var touch_index = null
var touch_position = null
@ -155,6 +178,7 @@ var explore_by_touch = false
var tap_count = 0
func _input(event):
if not enabled:
return
@ -190,16 +214,24 @@ func _input(event):
elif event is InputEventScreenDrag:
if touch_index and event.index != touch_index:
return
if not explore_by_touch and OS.get_ticks_msec() - touch_start_time >= explore_by_touch_interval:
if (
not explore_by_touch
and OS.get_ticks_msec() - touch_start_time >= explore_by_touch_interval
):
explore_by_touch = true
if event is InputEventMouseButton:
if event.device == -1 and not explore_by_touch:
get_tree().set_input_as_handled()
func _process(delta):
if not enabled:
return
if touch_stop_time and OS.get_ticks_msec() - touch_stop_time >= tap_execute_interval and tap_count != 0:
if (
touch_stop_time
and OS.get_ticks_msec() - touch_stop_time >= tap_execute_interval
and tap_count != 0
):
touch_stop_time = null
if tap_count == 2:
press_and_release("ui_accept")