This commit is contained in:
Nolan Darilek 2019-09-13 09:32:51 -05:00
commit 40cb92d39b

View File

@ -20,12 +20,14 @@ func singular_or_plural(count, singular, plural):
else: else:
return plural return plural
func left_click(item := node): func click(item := node, button_index = BUTTON_LEFT):
var click = InputEventMouseButton.new() var click = InputEventMouseButton.new()
click.button_index = BUTTON_LEFT click.button_index = button_index
click.pressed = true click.pressed = true
if item is Node: if item is Node:
click.position = item.rect_global_position click.position = item.rect_global_position
else:
click.position = node.get_tree().root.get_mouse_position()
node.get_tree().input_event(click) node.get_tree().input_event(click)
click.pressed = false click.pressed = false
node.get_tree().input_event(click) node.get_tree().input_event(click)
@ -51,13 +53,13 @@ func accept_dialog_focus():
node.add_child(dialog_close_timer) node.add_child(dialog_close_timer)
func checkbox_focus(): func checkbox_focus():
var text var tokens = PoolStringArray([])
if node.pressed: if node.pressed:
text = "checked" tokens.append("checked")
else: else:
text = "unchecked" tokens.append("unchecked")
text += " checkbox" tokens.append(" checkbox")
tts.speak(text, false) tts.speak(tokens.join(" "), false)
func checkbox_toggled(checked): func checkbox_toggled(checked):
if checked: if checked:
@ -65,14 +67,17 @@ func checkbox_toggled(checked):
else: else:
tts.speak("unchecked", true) tts.speak("unchecked", true)
var spoke_hint_tooltip
func button_focus(): func button_focus():
var text var tokens = PoolStringArray([])
if node.text: if node.text:
text = node.text tokens.append(node.text)
if text: elif node.hint_tooltip:
tts.speak("%s: button" % text, false) spoke_hint_tooltip = true
else: tokens.append(node.hint_tooltip)
tts.speak("button", false) tokens.append("button")
tts.speak(tokens.join(": "), false)
func texturebutton_focus(): func texturebutton_focus():
tts.speak("button", false) tts.speak("button", false)
@ -84,13 +89,13 @@ func item_list_focus():
tts.speak(selected, false) tts.speak(selected, false)
func item_list_item_selected(index): func item_list_item_selected(index):
tts.speak("Selected", false) tts.speak("Selected", true)
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", false) tts.speak("Nothing selected", true)
func item_list_input(event): func item_list_input(event):
var old_pos = position_in_children var old_pos = position_in_children
@ -154,49 +159,62 @@ func check_caret_moved():
old_pos = pos old_pos = pos
func menu_button_focus(): func menu_button_focus():
tts.speak(node.text + ": menu", false) var tokens = PoolStringArray([])
if node.text:
tokens.append(node.text)
if node.hint_tooltip:
tokens.append(node.hint_tooltip)
spoke_hint_tooltip = true
tokens.append("menu")
tts.speak(tokens.join(": "), false)
func popup_menu_focus(): func popup_menu_focus():
tts.speak("menu", false) tts.speak("menu", false)
func popup_menu_item_id_focus(id): func popup_menu_item_id_focus(id):
print("id: %s" % id) var tokens = PoolStringArray([])
print("count: %s" % node.get_item_count()) var index = node.get_item_index(id)
var item = node.get_item_text(id) print("id: %s, index: %s" % [id, index])
var submenu = node.get_item_submenu(id) if index == -1:
var tooltip = node.get_item_tooltip(position_in_children) index = id
var disabled = node.is_item_disabled(id) var item = node.get_item_text(index)
if item and tooltip: if item:
item += ": " tokens.append(item)
item += tooltip var submenu = node.get_item_submenu(index)
elif tooltip:
item = tooltip
var shortcut = node.get_item_shortcut(position_in_children)
if shortcut != null and shortcut.get_as_text() != "None":
item += ": "+shortcut.get_as_text()
if item == "":
item = "Unlabelled"
if submenu: if submenu:
item += ": menu" tokens.append(submenu)
tokens.append("menu")
var tooltip = node.get_item_tooltip(index)
if tooltip:
tokens.append(tooltip)
var disabled = node.is_item_disabled(index)
if disabled: if disabled:
item += ": disabled" tokens.append("disabled")
item += ": " + str(id + 1) + " of " + str(node.get_item_count()) var shortcut = node.get_item_shortcut(index)
tts.speak(item, true) if shortcut:
var name = shortcut.resource_name
if name:
tokens.append(name)
var text = shortcut.get_as_text()
if text != "None":
tokens.append(text)
tokens.append(str(id + 1) + " of " + str(node.get_item_count()))
tts.speak(tokens.join(": "), true)
func tree_item_render(): func tree_item_render():
var focused_tree_item = node.get_selected() var focused_tree_item = node.get_selected()
var result = "" var tokens = PoolStringArray([])
for i in range(node.columns): for i in range(node.columns):
result += focused_tree_item.get_text(i) + ": " tokens.append(focused_tree_item.get_text(i))
if focused_tree_item.get_children(): if focused_tree_item.get_children():
if focused_tree_item.collapsed: if focused_tree_item.collapsed:
result += "collapsed " tokens.append("collapsed")
else: else:
result += "expanded " tokens.append("expanded")
result += "tree item" tokens.append("tree item")
if focused_tree_item.is_selected(0): if focused_tree_item.is_selected(0):
result += ": selected" tokens.append("selected")
tts.speak(result, true) tts.speak(tokens.join(": "), true)
var prev_selected_cell var prev_selected_cell
@ -209,28 +227,26 @@ func tree_item_selected():
tree_item_render() tree_item_render()
prev_selected_cell = cell prev_selected_cell = cell
else: else:
var text = "" var tokens = PoolStringArray([])
for i in range(node.columns): for i in range(node.columns):
if cell.is_selected(i): if cell.is_selected(i):
var title = node.get_column_title(i) var title = node.get_column_title(i)
if title: if title:
text += title + ": " tokens.append(title)
var column_text = cell.get_text(i) var column_text = cell.get_text(i)
if column_text: if column_text:
text += column_text + ", " tokens.append(column_text)
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
text += str(button_count) + " " + singular_or_plural(button_count, "button", "buttons") + ", " tokens.append(str(button_count) + " " + singular_or_plural(button_count, "button", "buttons"))
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:
text += button_tooltip + ": button, " tokens.append(button_tooltip)
tokens.append("button")
if button_count > 1: if button_count > 1:
text += "Use Home and End to switch focus, " tokens.append("Use Home and End to switch focus.")
if text != "": tts.speak(tokens.join(": "), true)
tts.speak(text, true)
else:
tts.speak("blank", true)
func tree_item_multi_select(item, column, selected): func tree_item_multi_select(item, column, selected):
if selected: if selected:
@ -246,6 +262,14 @@ func tree_input(event):
if item.is_selected(i): if item.is_selected(i):
column = i column = i
break break
if item and event is InputEventKey and event.pressed and not event.echo:
var area
if column:
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, node.rect_global_position.y + area.position.y)
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"):
node.accept_event() node.accept_event()
@ -263,12 +287,12 @@ func tree_input(event):
new_button_index = item.get_button_count(column) - 1 new_button_index = item.get_button_count(column) - 1
if new_button_index != button_index: if new_button_index != button_index:
button_index = new_button_index button_index = new_button_index
var tokens = PoolStringArray([])
var tooltip = item.get_button_tooltip(column, button_index) var tooltip = item.get_button_tooltip(column, button_index)
var text = ""
if tooltip: if tooltip:
text += tooltip + ": " tokens.append(tooltip)
text += "button" tokens.append("button")
tts.speak(text, true) tts.speak(tokens.join(": "), true)
func tree_focus(): func tree_focus():
if node.get_selected(): if node.get_selected():
@ -309,6 +333,7 @@ func tab_container_input(event):
func focused(): func focused():
print("Focus: %s" % node) print("Focus: %s" % node)
node.get_tree().root.warp_mouse(node.rect_global_position)
tts.stop() tts.stop()
var label = guess_label() var label = guess_label()
if label: if label:
@ -339,14 +364,22 @@ func focused():
tree_focus() tree_focus()
else: else:
print("No handler") print("No handler")
if node.hint_tooltip: if node.hint_tooltip and not spoke_hint_tooltip:
tts.speak(node.hint_tooltip, false) tts.speak(node.hint_tooltip, false)
spoke_hint_tooltip = false
func unfocused(): func unfocused():
print("Unfocused") print("Unfocused")
position_in_children = 0 position_in_children = 0
func click_focused():
if node.has_focus():
return
node.grab_focus()
func gui_input(event): func gui_input(event):
if event is InputEventKey and event.pressed and not event.echo and event.scancode == KEY_MENU:
return click(null, BUTTON_RIGHT)
if node is TabContainer: if node is TabContainer:
return tab_container_input(event) return tab_container_input(event)
elif node is ItemList: elif node is ItemList:
@ -387,15 +420,16 @@ func is_focusable(node):
func editor_inspector_section_focus(): func editor_inspector_section_focus():
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()
tts.speak("editor inspector section:", true) var tokens = PoolStringArray(["editor inspector section"])
if expanded: if expanded:
tts.speak("expanded", false) tokens.append("expanded")
else: else:
tts.speak("collapsed", false) tokens.append("collapsed")
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"):
left_click() click()
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()
if expanded: if expanded:
@ -412,7 +446,7 @@ func _init(tts, node):
if is_focusable(node): if is_focusable(node):
node.set_focus_mode(Control.FOCUS_ALL) node.set_focus_mode(Control.FOCUS_ALL)
node.connect("focus_entered", self, "focused") node.connect("focus_entered", self, "focused")
node.connect("mouse_entered", self, "focused") node.connect("mouse_entered", self, "click_focused")
node.connect("focus_exited", self, "unfocused") node.connect("focus_exited", self, "unfocused")
node.connect("mouse_exited", self, "unfocused") node.connect("mouse_exited", self, "unfocused")
node.connect("gui_input", self, "gui_input") node.connect("gui_input", self, "gui_input")