mirror of
https://github.com/lightsoutgames/godot-accessibility.git
synced 2024-11-24 12:55:56 +00:00
Reformat.
This commit is contained in:
parent
6279f1a3c9
commit
9e2e99349c
108
Accessible.gd
108
Accessible.gd
|
@ -6,12 +6,14 @@ var position_in_children = 0
|
||||||
|
|
||||||
var column_in_row = 0
|
var column_in_row = 0
|
||||||
|
|
||||||
|
|
||||||
func get_siblings():
|
func get_siblings():
|
||||||
var parent = node.get_parent()
|
var parent = node.get_parent()
|
||||||
if parent:
|
if parent:
|
||||||
return parent.get_children()
|
return parent.get_children()
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
||||||
func click(item := node, button_index = BUTTON_LEFT):
|
func click(item := node, button_index = BUTTON_LEFT):
|
||||||
print_debug("Click")
|
print_debug("Click")
|
||||||
var click = InputEventMouseButton.new()
|
var click = InputEventMouseButton.new()
|
||||||
|
@ -25,6 +27,7 @@ func click(item := node, button_index = BUTTON_LEFT):
|
||||||
click.pressed = false
|
click.pressed = false
|
||||||
node.get_tree().input_event(click)
|
node.get_tree().input_event(click)
|
||||||
|
|
||||||
|
|
||||||
func guess_label():
|
func guess_label():
|
||||||
var tokens = PoolStringArray([])
|
var tokens = PoolStringArray([])
|
||||||
var to_check = node
|
var to_check = node
|
||||||
|
@ -33,7 +36,10 @@ func guess_label():
|
||||||
return
|
return
|
||||||
if to_check.is_class("EditorProperty") and to_check.label:
|
if to_check.is_class("EditorProperty") and to_check.label:
|
||||||
tokens.append(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())
|
tokens.append(to_check.get_tooltip_text())
|
||||||
var label = tokens.join(": ")
|
var label = tokens.join(": ")
|
||||||
if label:
|
if label:
|
||||||
|
@ -43,19 +49,23 @@ func guess_label():
|
||||||
return child
|
return child
|
||||||
to_check = to_check.get_parent()
|
to_check = to_check.get_parent()
|
||||||
|
|
||||||
|
|
||||||
func _accept_dialog_speak():
|
func _accept_dialog_speak():
|
||||||
if node.dialog_text != "":
|
if node.dialog_text != "":
|
||||||
TTS.speak("dialog: %s" % node.dialog_text)
|
TTS.speak("dialog: %s" % node.dialog_text)
|
||||||
|
|
||||||
|
|
||||||
func accept_dialog_focused():
|
func accept_dialog_focused():
|
||||||
_accept_dialog_speak()
|
_accept_dialog_speak()
|
||||||
if node.get_parent() and node.get_parent().is_class("ProjectSettingsEditor"):
|
if node.get_parent() and node.get_parent().is_class("ProjectSettingsEditor"):
|
||||||
yield(node.get_tree().create_timer(5), "timeout")
|
yield(node.get_tree().create_timer(5), "timeout")
|
||||||
node.get_ok().emit_signal("pressed")
|
node.get_ok().emit_signal("pressed")
|
||||||
|
|
||||||
|
|
||||||
func _accept_dialog_about_to_show():
|
func _accept_dialog_about_to_show():
|
||||||
_accept_dialog_speak()
|
_accept_dialog_speak()
|
||||||
|
|
||||||
|
|
||||||
func checkbox_focused():
|
func checkbox_focused():
|
||||||
var tokens = PoolStringArray([])
|
var tokens = PoolStringArray([])
|
||||||
if node.pressed:
|
if node.pressed:
|
||||||
|
@ -65,6 +75,7 @@ func checkbox_focused():
|
||||||
tokens.append(" checkbox")
|
tokens.append(" checkbox")
|
||||||
TTS.speak(tokens.join(" "), false)
|
TTS.speak(tokens.join(" "), false)
|
||||||
|
|
||||||
|
|
||||||
func checkbox_toggled(checked):
|
func checkbox_toggled(checked):
|
||||||
if node.has_focus():
|
if node.has_focus():
|
||||||
if checked:
|
if checked:
|
||||||
|
@ -72,8 +83,10 @@ func checkbox_toggled(checked):
|
||||||
else:
|
else:
|
||||||
TTS.speak("unchecked", true)
|
TTS.speak("unchecked", true)
|
||||||
|
|
||||||
|
|
||||||
var spoke_hint_tooltip
|
var spoke_hint_tooltip
|
||||||
|
|
||||||
|
|
||||||
func button_focused():
|
func button_focused():
|
||||||
var tokens = PoolStringArray([])
|
var tokens = PoolStringArray([])
|
||||||
if node.text:
|
if node.text:
|
||||||
|
@ -86,6 +99,7 @@ func button_focused():
|
||||||
tokens.append("disabled")
|
tokens.append("disabled")
|
||||||
TTS.speak(tokens.join(": "), false)
|
TTS.speak(tokens.join(": "), false)
|
||||||
|
|
||||||
|
|
||||||
func texturebutton_focused():
|
func texturebutton_focused():
|
||||||
var texture = node.texture_normal
|
var texture = node.texture_normal
|
||||||
print_debug(texture.resource_name)
|
print_debug(texture.resource_name)
|
||||||
|
@ -95,6 +109,7 @@ func texturebutton_focused():
|
||||||
print_debug(rid.get_id())
|
print_debug(rid.get_id())
|
||||||
TTS.speak("button", false)
|
TTS.speak("button", false)
|
||||||
|
|
||||||
|
|
||||||
func item_list_item_focused(idx):
|
func item_list_item_focused(idx):
|
||||||
var tokens = PoolStringArray([])
|
var tokens = PoolStringArray([])
|
||||||
var text = node.get_item_text(idx)
|
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()])
|
tokens.append("%s of %s" % [idx + 1, node.get_item_count()])
|
||||||
TTS.speak(tokens.join(": "))
|
TTS.speak(tokens.join(": "))
|
||||||
|
|
||||||
|
|
||||||
func item_list_focused():
|
func item_list_focused():
|
||||||
var count = node.get_item_count()
|
var count = node.get_item_count()
|
||||||
var selected = node.get_selected_items()
|
var selected = node.get_selected_items()
|
||||||
|
@ -121,15 +137,19 @@ func item_list_focused():
|
||||||
position_in_children = selected
|
position_in_children = selected
|
||||||
item_list_item_focused(selected)
|
item_list_item_focused(selected)
|
||||||
|
|
||||||
|
|
||||||
func item_list_item_selected(index):
|
func item_list_item_selected(index):
|
||||||
item_list_item_focused(index)
|
item_list_item_focused(index)
|
||||||
|
|
||||||
|
|
||||||
func item_list_multi_selected(index, selected):
|
func item_list_multi_selected(index, selected):
|
||||||
TTS.speak("Multiselect", false)
|
TTS.speak("Multiselect", false)
|
||||||
|
|
||||||
|
|
||||||
func item_list_nothing_selected():
|
func item_list_nothing_selected():
|
||||||
TTS.speak("Nothing selected", true)
|
TTS.speak("Nothing selected", true)
|
||||||
|
|
||||||
|
|
||||||
func item_list_input(event):
|
func item_list_input(event):
|
||||||
if event.is_action_pressed("ui_right") or event.is_action_pressed("ui_left"):
|
if event.is_action_pressed("ui_right") or event.is_action_pressed("ui_left"):
|
||||||
return node.accept_event()
|
return node.accept_event()
|
||||||
|
@ -142,7 +162,7 @@ func item_list_input(event):
|
||||||
position_in_children -= 1
|
position_in_children -= 1
|
||||||
elif event.is_action_pressed("ui_down"):
|
elif event.is_action_pressed("ui_down"):
|
||||||
node.accept_event()
|
node.accept_event()
|
||||||
if position_in_children >= node.get_item_count()-1:
|
if position_in_children >= node.get_item_count() - 1:
|
||||||
return
|
return
|
||||||
position_in_children += 1
|
position_in_children += 1
|
||||||
elif event.is_action_pressed("ui_home"):
|
elif event.is_action_pressed("ui_home"):
|
||||||
|
@ -150,7 +170,7 @@ func item_list_input(event):
|
||||||
position_in_children = 0
|
position_in_children = 0
|
||||||
elif event.is_action_pressed("ui_end"):
|
elif event.is_action_pressed("ui_end"):
|
||||||
node.accept_event()
|
node.accept_event()
|
||||||
position_in_children = node.get_item_count()-1
|
position_in_children = node.get_item_count() - 1
|
||||||
if old_pos != position_in_children:
|
if old_pos != position_in_children:
|
||||||
if position_in_children >= node.get_item_count():
|
if position_in_children >= node.get_item_count():
|
||||||
position_in_children = 0
|
position_in_children = 0
|
||||||
|
@ -159,12 +179,14 @@ func item_list_input(event):
|
||||||
node.emit_signal("item_list_item_selected", position_in_children)
|
node.emit_signal("item_list_item_selected", position_in_children)
|
||||||
item_list_item_focused(position_in_children)
|
item_list_item_focused(position_in_children)
|
||||||
|
|
||||||
|
|
||||||
func label_focused():
|
func label_focused():
|
||||||
var text = node.text
|
var text = node.text
|
||||||
if text == "":
|
if text == "":
|
||||||
text = "blank"
|
text = "blank"
|
||||||
TTS.speak(text, false)
|
TTS.speak(text, false)
|
||||||
|
|
||||||
|
|
||||||
func line_edit_focused():
|
func line_edit_focused():
|
||||||
var text = "blank"
|
var text = "blank"
|
||||||
if node.secret:
|
if node.secret:
|
||||||
|
@ -178,10 +200,12 @@ func line_edit_focused():
|
||||||
type = "text"
|
type = "text"
|
||||||
TTS.speak("%s: %s" % [text, type], false)
|
TTS.speak("%s: %s" % [text, type], false)
|
||||||
|
|
||||||
|
|
||||||
var old_text = ""
|
var old_text = ""
|
||||||
|
|
||||||
var old_pos
|
var old_pos
|
||||||
|
|
||||||
|
|
||||||
func line_edit_text_changed(text):
|
func line_edit_text_changed(text):
|
||||||
if text == null or old_text == null:
|
if text == null or old_text == null:
|
||||||
return
|
return
|
||||||
|
@ -196,12 +220,13 @@ func line_edit_text_changed(text):
|
||||||
TTS.speak(old_text.substr(i, 1))
|
TTS.speak(old_text.substr(i, 1))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
func line_edit_input(event):
|
func line_edit_input(event):
|
||||||
var pos = node.caret_position
|
var pos = node.caret_position
|
||||||
if old_pos != null and old_pos != pos:
|
if old_pos != null and old_pos != pos:
|
||||||
var text = node.text
|
var text = node.text
|
||||||
if old_text == text:
|
if old_text == text:
|
||||||
if pos > len(text)-1:
|
if pos > len(text) - 1:
|
||||||
TTS.speak("blank", true)
|
TTS.speak("blank", true)
|
||||||
else:
|
else:
|
||||||
TTS.speak(text[pos], true)
|
TTS.speak(text[pos], true)
|
||||||
|
@ -210,6 +235,7 @@ func line_edit_input(event):
|
||||||
old_pos = pos
|
old_pos = pos
|
||||||
old_text = node.text
|
old_text = node.text
|
||||||
|
|
||||||
|
|
||||||
func menu_button_focused():
|
func menu_button_focused():
|
||||||
var tokens = PoolStringArray([])
|
var tokens = PoolStringArray([])
|
||||||
if node.text:
|
if node.text:
|
||||||
|
@ -220,9 +246,11 @@ func menu_button_focused():
|
||||||
tokens.append("menu")
|
tokens.append("menu")
|
||||||
TTS.speak(tokens.join(": "), false)
|
TTS.speak(tokens.join(": "), false)
|
||||||
|
|
||||||
|
|
||||||
func popup_menu_focused():
|
func popup_menu_focused():
|
||||||
TTS.speak("menu", false)
|
TTS.speak("menu", false)
|
||||||
|
|
||||||
|
|
||||||
func popup_menu_item_id_focused(index):
|
func popup_menu_item_id_focused(index):
|
||||||
print_debug("item id focus %s" % index)
|
print_debug("item id focus %s" % index)
|
||||||
var tokens = PoolStringArray([])
|
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()))
|
tokens.append(str(index + 1) + " of " + str(node.get_item_count()))
|
||||||
TTS.speak(tokens.join(": "), true)
|
TTS.speak(tokens.join(": "), true)
|
||||||
|
|
||||||
|
|
||||||
func popup_menu_item_id_pressed(index):
|
func popup_menu_item_id_pressed(index):
|
||||||
if node.is_item_checkable(index):
|
if node.is_item_checkable(index):
|
||||||
if node.is_item_checked(index):
|
if node.is_item_checked(index):
|
||||||
|
@ -263,6 +292,7 @@ func popup_menu_item_id_pressed(index):
|
||||||
else:
|
else:
|
||||||
TTS.speak("unchecked", true)
|
TTS.speak("unchecked", true)
|
||||||
|
|
||||||
|
|
||||||
func range_focused():
|
func range_focused():
|
||||||
var tokens = PoolStringArray([])
|
var tokens = PoolStringArray([])
|
||||||
tokens.append(str(node.value))
|
tokens.append(str(node.value))
|
||||||
|
@ -278,10 +308,12 @@ func range_focused():
|
||||||
tokens.append("maximum %s" % node.max_value)
|
tokens.append("maximum %s" % node.max_value)
|
||||||
TTS.speak(tokens.join(": "), false)
|
TTS.speak(tokens.join(": "), false)
|
||||||
|
|
||||||
|
|
||||||
func range_value_changed(value):
|
func range_value_changed(value):
|
||||||
if node.has_focus():
|
if node.has_focus():
|
||||||
TTS.speak("%s" % value, true)
|
TTS.speak("%s" % value, true)
|
||||||
|
|
||||||
|
|
||||||
func text_edit_focus():
|
func text_edit_focus():
|
||||||
var tokens = PoolStringArray([])
|
var tokens = PoolStringArray([])
|
||||||
if node.text:
|
if node.text:
|
||||||
|
@ -294,9 +326,11 @@ func text_edit_focus():
|
||||||
tokens.append("edit text")
|
tokens.append("edit text")
|
||||||
TTS.speak(tokens.join(": "), false)
|
TTS.speak(tokens.join(": "), false)
|
||||||
|
|
||||||
|
|
||||||
func text_edit_input(event):
|
func text_edit_input(event):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func tree_item_render():
|
func tree_item_render():
|
||||||
var focused_tree_item = node.get_selected()
|
var focused_tree_item = node.get_selected()
|
||||||
var tokens = PoolStringArray([])
|
var tokens = PoolStringArray([])
|
||||||
|
@ -312,10 +346,12 @@ func tree_item_render():
|
||||||
tokens.append("selected")
|
tokens.append("selected")
|
||||||
TTS.speak(tokens.join(": "), true)
|
TTS.speak(tokens.join(": "), true)
|
||||||
|
|
||||||
|
|
||||||
func tree_item_deselect_all(item: TreeItem):
|
func tree_item_deselect_all(item: TreeItem):
|
||||||
for i in range(node.columns):
|
for i in range(node.columns):
|
||||||
item.deselect(i)
|
item.deselect(i)
|
||||||
|
|
||||||
|
|
||||||
func tree_deselect_all_but(target: TreeItem, tree: Tree):
|
func tree_deselect_all_but(target: TreeItem, tree: Tree):
|
||||||
var cur = tree.get_root()
|
var cur = tree.get_root()
|
||||||
while cur != null:
|
while cur != null:
|
||||||
|
@ -323,10 +359,12 @@ func tree_deselect_all_but(target: TreeItem, tree: Tree):
|
||||||
tree_item_deselect_all(cur)
|
tree_item_deselect_all(cur)
|
||||||
cur = tree.get_next_selected(cur)
|
cur = tree.get_next_selected(cur)
|
||||||
|
|
||||||
|
|
||||||
var prev_selected_cell
|
var prev_selected_cell
|
||||||
|
|
||||||
var button_index
|
var button_index
|
||||||
|
|
||||||
|
|
||||||
func tree_item_selected():
|
func tree_item_selected():
|
||||||
button_index = null
|
button_index = null
|
||||||
var cell = node.get_selected()
|
var cell = node.get_selected()
|
||||||
|
@ -350,7 +388,13 @@ func tree_item_selected():
|
||||||
var button_count = cell.get_button_count(i)
|
var button_count = cell.get_button_count(i)
|
||||||
if button_count != 0:
|
if button_count != 0:
|
||||||
button_index = 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"):
|
if cell.has_method("get_button_tooltip"):
|
||||||
var button_tooltip = cell.get_button_tooltip(i, button_index)
|
var button_tooltip = cell.get_button_tooltip(i, button_index)
|
||||||
if button_tooltip:
|
if button_tooltip:
|
||||||
|
@ -360,12 +404,14 @@ func tree_item_selected():
|
||||||
tokens.append("Use Home and End to switch focus.")
|
tokens.append("Use Home and End to switch focus.")
|
||||||
TTS.speak(tokens.join(": "), true)
|
TTS.speak(tokens.join(": "), true)
|
||||||
|
|
||||||
|
|
||||||
func tree_item_multi_selected(item, column, selected):
|
func tree_item_multi_selected(item, column, selected):
|
||||||
if selected:
|
if selected:
|
||||||
TTS.speak("selected", true)
|
TTS.speak("selected", true)
|
||||||
else:
|
else:
|
||||||
TTS.speak("unselected", true)
|
TTS.speak("unselected", true)
|
||||||
|
|
||||||
|
|
||||||
func tree_input(event):
|
func tree_input(event):
|
||||||
var item = node.get_selected()
|
var item = node.get_selected()
|
||||||
var column
|
var column
|
||||||
|
@ -380,7 +426,10 @@ func tree_input(event):
|
||||||
area = node.get_item_area_rect(item, column)
|
area = node.get_item_area_rect(item, column)
|
||||||
else:
|
else:
|
||||||
area = node.get_item_area_rect(item)
|
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)
|
node.get_tree().root.warp_mouse(position)
|
||||||
if item and column and button_index != null:
|
if item and column and button_index != null:
|
||||||
if event.is_action_pressed("ui_accept"):
|
if event.is_action_pressed("ui_accept"):
|
||||||
|
@ -406,12 +455,14 @@ func tree_input(event):
|
||||||
tokens.append("button")
|
tokens.append("button")
|
||||||
TTS.speak(tokens.join(": "), true)
|
TTS.speak(tokens.join(": "), true)
|
||||||
|
|
||||||
|
|
||||||
func tree_focused():
|
func tree_focused():
|
||||||
if node.get_selected():
|
if node.get_selected():
|
||||||
tree_item_render()
|
tree_item_render()
|
||||||
else:
|
else:
|
||||||
TTS.speak("tree", true)
|
TTS.speak("tree", true)
|
||||||
|
|
||||||
|
|
||||||
func tree_item_collapsed(item):
|
func tree_item_collapsed(item):
|
||||||
if node.has_focus():
|
if node.has_focus():
|
||||||
if item.collapsed:
|
if item.collapsed:
|
||||||
|
@ -419,33 +470,42 @@ func tree_item_collapsed(item):
|
||||||
else:
|
else:
|
||||||
TTS.speak("expanded", true)
|
TTS.speak("expanded", true)
|
||||||
|
|
||||||
|
|
||||||
func progress_bar_focused():
|
func progress_bar_focused():
|
||||||
var percentage = int(node.ratio * 100)
|
var percentage = int(node.ratio * 100)
|
||||||
TTS.speak("%s percent" % percentage, false)
|
TTS.speak("%s percent" % percentage, false)
|
||||||
TTS.speak("progress bar", false)
|
TTS.speak("progress bar", false)
|
||||||
|
|
||||||
|
|
||||||
var last_percentage_spoken
|
var last_percentage_spoken
|
||||||
|
|
||||||
var last_percentage_spoken_at = 0
|
var last_percentage_spoken_at = 0
|
||||||
|
|
||||||
|
|
||||||
func progress_bar_value_changed(value):
|
func progress_bar_value_changed(value):
|
||||||
var percentage = node.value / (node.max_value - node.min_value) * 100
|
var percentage = node.value / (node.max_value - node.min_value) * 100
|
||||||
percentage = int(percentage)
|
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)
|
TTS.speak("%s percent" % percentage)
|
||||||
last_percentage_spoken_at = OS.get_ticks_msec()
|
last_percentage_spoken_at = OS.get_ticks_msec()
|
||||||
last_percentage_spoken = percentage
|
last_percentage_spoken = percentage
|
||||||
|
|
||||||
|
|
||||||
func tab_container_focused():
|
func tab_container_focused():
|
||||||
var text = node.get_tab_title(node.current_tab)
|
var text = node.get_tab_title(node.current_tab)
|
||||||
text += ": tab: " + str(node.current_tab + 1) + " of " + str(node.get_tab_count())
|
text += ": tab: " + str(node.current_tab + 1) + " of " + str(node.get_tab_count())
|
||||||
TTS.speak(text, false)
|
TTS.speak(text, false)
|
||||||
|
|
||||||
|
|
||||||
func tab_container_tab_changed(tab):
|
func tab_container_tab_changed(tab):
|
||||||
if node.has_focus():
|
if node.has_focus():
|
||||||
TTS.stop()
|
TTS.stop()
|
||||||
tab_container_focused()
|
tab_container_focused()
|
||||||
|
|
||||||
|
|
||||||
func tab_container_input(event):
|
func tab_container_input(event):
|
||||||
var new_tab = node.current_tab
|
var new_tab = node.current_tab
|
||||||
if event.is_action_pressed("ui_right"):
|
if event.is_action_pressed("ui_right"):
|
||||||
|
@ -461,6 +521,7 @@ func tab_container_input(event):
|
||||||
if node.current_tab != new_tab:
|
if node.current_tab != new_tab:
|
||||||
node.current_tab = new_tab
|
node.current_tab = new_tab
|
||||||
|
|
||||||
|
|
||||||
func focused():
|
func focused():
|
||||||
print_debug("Focus: %s" % node)
|
print_debug("Focus: %s" % node)
|
||||||
TTS.stop()
|
TTS.stop()
|
||||||
|
@ -510,13 +571,16 @@ func focused():
|
||||||
TTS.speak(node.hint_tooltip, false)
|
TTS.speak(node.hint_tooltip, false)
|
||||||
spoke_hint_tooltip = false
|
spoke_hint_tooltip = false
|
||||||
|
|
||||||
|
|
||||||
var timer
|
var timer
|
||||||
|
|
||||||
|
|
||||||
func unfocused():
|
func unfocused():
|
||||||
print_debug("Unfocused")
|
print_debug("Unfocused")
|
||||||
position_in_children = 0
|
position_in_children = 0
|
||||||
timer = node.get_tree().create_timer(1)
|
timer = node.get_tree().create_timer(1)
|
||||||
|
|
||||||
|
|
||||||
func click_focused():
|
func click_focused():
|
||||||
if node.has_focus():
|
if node.has_focus():
|
||||||
return
|
return
|
||||||
|
@ -524,8 +588,14 @@ func click_focused():
|
||||||
print_debug("Grabbing focus: %s" % node)
|
print_debug("Grabbing focus: %s" % node)
|
||||||
node.grab_focus()
|
node.grab_focus()
|
||||||
|
|
||||||
|
|
||||||
func gui_input(event):
|
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)
|
TTS.speak("click", false)
|
||||||
click()
|
click()
|
||||||
elif event is InputEventKey and event.pressed and not event.echo and event.scancode == KEY_MENU:
|
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:
|
elif node is TextEdit:
|
||||||
return text_edit_input(event)
|
return text_edit_input(event)
|
||||||
elif node is Tree:
|
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()
|
node.accept_event()
|
||||||
return tree_input(event)
|
return tree_input(event)
|
||||||
elif node.is_class("EditorInspectorSection"):
|
elif node.is_class("EditorInspectorSection"):
|
||||||
return editor_inspector_section_input(event)
|
return editor_inspector_section_input(event)
|
||||||
|
|
||||||
|
|
||||||
func is_in_bar():
|
func is_in_bar():
|
||||||
var parent = node.get_parent()
|
var parent = node.get_parent()
|
||||||
if parent and parent is Container:
|
if parent and parent is Container:
|
||||||
|
@ -555,6 +631,7 @@ func is_in_bar():
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
func is_focusable(node):
|
func is_focusable(node):
|
||||||
if node.is_class("SceneTreeEditor"):
|
if node.is_class("SceneTreeEditor"):
|
||||||
return false
|
return false
|
||||||
|
@ -578,10 +655,17 @@ func is_focusable(node):
|
||||||
return true
|
return true
|
||||||
if node is Label and node.get_parent() and node.get_parent() is AcceptDialog:
|
if node is Label and node.get_parent() and node.get_parent() is AcceptDialog:
|
||||||
return false
|
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 false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
func editor_inspector_section_focused():
|
func editor_inspector_section_focused():
|
||||||
var child = node.get_children()[0]
|
var child = node.get_children()[0]
|
||||||
var expanded = child.is_visible_in_tree()
|
var expanded = child.is_visible_in_tree()
|
||||||
|
@ -592,6 +676,7 @@ func editor_inspector_section_focused():
|
||||||
tokens.append("collapsed")
|
tokens.append("collapsed")
|
||||||
TTS.speak(tokens.join(": "), false)
|
TTS.speak(tokens.join(": "), false)
|
||||||
|
|
||||||
|
|
||||||
func editor_inspector_section_input(event):
|
func editor_inspector_section_input(event):
|
||||||
if event.is_action_pressed("ui_accept"):
|
if event.is_action_pressed("ui_accept"):
|
||||||
click()
|
click()
|
||||||
|
@ -602,6 +687,7 @@ func editor_inspector_section_input(event):
|
||||||
else:
|
else:
|
||||||
TTS.speak("collapsed", true)
|
TTS.speak("collapsed", true)
|
||||||
|
|
||||||
|
|
||||||
func _init(node):
|
func _init(node):
|
||||||
if node.is_in_group("accessible"):
|
if node.is_in_group("accessible"):
|
||||||
return
|
return
|
||||||
|
@ -647,12 +733,14 @@ func _init(node):
|
||||||
node.connect("item_selected", self, "tree_item_selected")
|
node.connect("item_selected", self, "tree_item_selected")
|
||||||
node.connect("tree_exiting", self, "queue_free", [], Object.CONNECT_DEFERRED)
|
node.connect("tree_exiting", self, "queue_free", [], Object.CONNECT_DEFERRED)
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if timer and timer.time_left <= 0:
|
if timer and timer.time_left <= 0:
|
||||||
if node.is_inside_tree() and not node.get_focus_owner():
|
if node.is_inside_tree() and not node.get_focus_owner():
|
||||||
node.get_tree().root.warp_mouse(node.rect_global_position)
|
node.get_tree().root.warp_mouse(node.rect_global_position)
|
||||||
timer = null
|
timer = null
|
||||||
|
|
||||||
|
|
||||||
func free():
|
func free():
|
||||||
if timer:
|
if timer:
|
||||||
timer.unreference()
|
timer.unreference()
|
||||||
|
|
|
@ -5,13 +5,16 @@ var ScreenReader = preload("ScreenReader.gd")
|
||||||
|
|
||||||
var screen_reader
|
var screen_reader
|
||||||
|
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
var editor_accessibility_enabled = true
|
var editor_accessibility_enabled = true
|
||||||
var rate = 50
|
var rate = 50
|
||||||
var config = ConfigFile.new()
|
var config = ConfigFile.new()
|
||||||
var err = config.load("res://.godot-accessibility-editor-settings.ini")
|
var err = config.load("res://.godot-accessibility-editor-settings.ini")
|
||||||
if not err:
|
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)
|
rate = config.get_value("speech", "rate", 50)
|
||||||
add_autoload_singleton("TTS", "res://addons/godot-tts/TTS.gd")
|
add_autoload_singleton("TTS", "res://addons/godot-tts/TTS.gd")
|
||||||
if editor_accessibility_enabled:
|
if editor_accessibility_enabled:
|
||||||
|
@ -22,5 +25,6 @@ func _enter_tree():
|
||||||
call_deferred("connect", "main_screen_changed", screen_reader, "set_initial_screen_focus")
|
call_deferred("connect", "main_screen_changed", screen_reader, "set_initial_screen_focus")
|
||||||
add_custom_type("ScreenReader", "Node", preload("ScreenReader.gd"), null)
|
add_custom_type("ScreenReader", "Node", preload("ScreenReader.gd"), null)
|
||||||
|
|
||||||
|
|
||||||
func _exit_tree():
|
func _exit_tree():
|
||||||
remove_custom_type("ScreenReader")
|
remove_custom_type("ScreenReader")
|
||||||
|
|
|
@ -21,6 +21,7 @@ export var explore_by_touch_interval = 200
|
||||||
|
|
||||||
var focus_restore_timer
|
var focus_restore_timer
|
||||||
|
|
||||||
|
|
||||||
func _set_enabled(v):
|
func _set_enabled(v):
|
||||||
if enabled:
|
if enabled:
|
||||||
augment_tree(get_tree().root)
|
augment_tree(get_tree().root)
|
||||||
|
@ -28,18 +29,23 @@ func _set_enabled(v):
|
||||||
pass
|
pass
|
||||||
enabled = v
|
enabled = v
|
||||||
|
|
||||||
|
|
||||||
func _get_enabled():
|
func _get_enabled():
|
||||||
return enabled
|
return enabled
|
||||||
|
|
||||||
|
|
||||||
func focused(node):
|
func focused(node):
|
||||||
focus_restore_timer = null
|
focus_restore_timer = null
|
||||||
|
|
||||||
|
|
||||||
func click_focused(node):
|
func click_focused(node):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func unfocused(node):
|
func unfocused(node):
|
||||||
focus_restore_timer = get_tree().create_timer(0.2)
|
focus_restore_timer = get_tree().create_timer(0.2)
|
||||||
|
|
||||||
|
|
||||||
func augment_node(node):
|
func augment_node(node):
|
||||||
if not enabled:
|
if not enabled:
|
||||||
return
|
return
|
||||||
|
@ -54,6 +60,7 @@ func augment_node(node):
|
||||||
if not node.is_connected("mouse_exited", self, "unfocused"):
|
if not node.is_connected("mouse_exited", self, "unfocused"):
|
||||||
node.connect("mouse_exited", self, "unfocused", [node])
|
node.connect("mouse_exited", self, "unfocused", [node])
|
||||||
|
|
||||||
|
|
||||||
func augment_tree(node):
|
func augment_tree(node):
|
||||||
if not enabled:
|
if not enabled:
|
||||||
return
|
return
|
||||||
|
@ -63,6 +70,7 @@ func augment_tree(node):
|
||||||
for child in node.get_children():
|
for child in node.get_children():
|
||||||
augment_tree(child)
|
augment_tree(child)
|
||||||
|
|
||||||
|
|
||||||
func set_initial_screen_focus(screen):
|
func set_initial_screen_focus(screen):
|
||||||
TTS.speak("%s: screen" % screen, false)
|
TTS.speak("%s: screen" % screen, false)
|
||||||
var control = find_focusable_control(get_tree().root)
|
var control = find_focusable_control(get_tree().root)
|
||||||
|
@ -75,8 +83,13 @@ func set_initial_screen_focus(screen):
|
||||||
focus.grab_click_focus()
|
focus.grab_click_focus()
|
||||||
focus.grab_focus()
|
focus.grab_focus()
|
||||||
|
|
||||||
|
|
||||||
func find_focusable_control(node):
|
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
|
return node
|
||||||
for child in node.get_children():
|
for child in node.get_children():
|
||||||
var result = find_focusable_control(child)
|
var result = find_focusable_control(child)
|
||||||
|
@ -84,6 +97,7 @@ func find_focusable_control(node):
|
||||||
return result
|
return result
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
||||||
func set_initial_scene_focus(scene):
|
func set_initial_scene_focus(scene):
|
||||||
self.augment_tree(get_tree().root)
|
self.augment_tree(get_tree().root)
|
||||||
var focus = find_focusable_control(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_click_focus()
|
||||||
focus.grab_focus()
|
focus.grab_focus()
|
||||||
|
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
if enabled:
|
if enabled:
|
||||||
augment_tree(get_tree().root)
|
augment_tree(get_tree().root)
|
||||||
|
@ -101,6 +116,7 @@ func _enter_tree():
|
||||||
connect("swipe_up", self, "swipe_up")
|
connect("swipe_up", self, "swipe_up")
|
||||||
connect("swipe_down", self, "swipe_down")
|
connect("swipe_down", self, "swipe_down")
|
||||||
|
|
||||||
|
|
||||||
func press_and_release(action):
|
func press_and_release(action):
|
||||||
var event = InputEventAction.new()
|
var event = InputEventAction.new()
|
||||||
event.action = action
|
event.action = action
|
||||||
|
@ -109,6 +125,7 @@ func press_and_release(action):
|
||||||
event.pressed = false
|
event.pressed = false
|
||||||
get_tree().input_event(event)
|
get_tree().input_event(event)
|
||||||
|
|
||||||
|
|
||||||
func _ui_focus_next():
|
func _ui_focus_next():
|
||||||
for event in InputMap.get_action_list("ui_focus_next"):
|
for event in InputMap.get_action_list("ui_focus_next"):
|
||||||
if event is InputEventKey:
|
if event is InputEventKey:
|
||||||
|
@ -120,6 +137,7 @@ func _ui_focus_next():
|
||||||
get_tree().input_event(event)
|
get_tree().input_event(event)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
func _ui_focus_prev():
|
func _ui_focus_prev():
|
||||||
for event in InputMap.get_action_list("ui_focus_prev"):
|
for event in InputMap.get_action_list("ui_focus_prev"):
|
||||||
if event is InputEventKey:
|
if event is InputEventKey:
|
||||||
|
@ -131,18 +149,23 @@ func _ui_focus_prev():
|
||||||
get_tree().input_event(event)
|
get_tree().input_event(event)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
func swipe_right():
|
func swipe_right():
|
||||||
_ui_focus_next()
|
_ui_focus_next()
|
||||||
|
|
||||||
|
|
||||||
func swipe_left():
|
func swipe_left():
|
||||||
_ui_focus_prev()
|
_ui_focus_prev()
|
||||||
|
|
||||||
|
|
||||||
func swipe_up():
|
func swipe_up():
|
||||||
TTS.speak("Swipe up")
|
TTS.speak("Swipe up")
|
||||||
|
|
||||||
|
|
||||||
func swipe_down():
|
func swipe_down():
|
||||||
TTS.speak("Swipe down")
|
TTS.speak("Swipe down")
|
||||||
|
|
||||||
|
|
||||||
var touch_index = null
|
var touch_index = null
|
||||||
|
|
||||||
var touch_position = null
|
var touch_position = null
|
||||||
|
@ -155,6 +178,7 @@ var explore_by_touch = false
|
||||||
|
|
||||||
var tap_count = 0
|
var tap_count = 0
|
||||||
|
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
if not enabled:
|
if not enabled:
|
||||||
return
|
return
|
||||||
|
@ -190,16 +214,24 @@ func _input(event):
|
||||||
elif event is InputEventScreenDrag:
|
elif event is InputEventScreenDrag:
|
||||||
if touch_index and event.index != touch_index:
|
if touch_index and event.index != touch_index:
|
||||||
return
|
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
|
explore_by_touch = true
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
if event.device == -1 and not explore_by_touch:
|
if event.device == -1 and not explore_by_touch:
|
||||||
get_tree().set_input_as_handled()
|
get_tree().set_input_as_handled()
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if not enabled:
|
if not enabled:
|
||||||
return
|
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
|
touch_stop_time = null
|
||||||
if tap_count == 2:
|
if tap_count == 2:
|
||||||
press_and_release("ui_accept")
|
press_and_release("ui_accept")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user