Better accessible handling for Tree. Also, fix casing error in script.

This commit is contained in:
Nolan Darilek 2019-09-03 15:57:32 -05:00
parent cf8ede147d
commit 8ebdb5ee57
4 changed files with 60 additions and 96 deletions

View File

@ -6,6 +6,8 @@ var node
var position_in_children = 0
var column_in_row = 0
func item_or_items(count):
if count == 1:
return "item"
@ -37,9 +39,9 @@ func item_list_nothing_selected():
tts.speak("Nothing selected", false)
func input_item_list(event):
var old_pos = position_in_children
if event.echo or not event.pressed:
return
var old_pos = position_in_children
if event.scancode == KEY_UP:
node.get_tree().set_input_as_handled()
if position_in_children == 0:
@ -132,18 +134,18 @@ func focus_popup_menu_item(id):
tts.speak(item, true)
func render_tree_item():
var item = node.get_selected()
var result = ""
for i in range(node.columns):
result += item.get_text(i) + ": "
if item.collapsed:
result += "collapsed "
else:
result += "expanded "
result += focused_tree_item.get_text(i) + ": "
if focused_tree_item.get_children():
if focused_tree_item.collapsed:
result += "collapsed "
else:
result += "expanded "
result += "tree item"
if item.is_selected(0):
if focused_tree_item.is_selected(0):
result += ": selected"
return result
tts.speak(result, true)
func focus_tab_container():
var text = node.get_tab_title(node.current_tab)
@ -169,20 +171,64 @@ func input_tab_container(event):
func focus_tree():
if node.get_selected():
tts.speak(render_tree_item(), true)
render_tree_item()
else:
tts.speak("tree", true)
func collapse_tree_item(item):
if node.has_focus():
tts.speak("collapsed", true)
if item.collapsed:
tts.speak("collapsed", true)
else:
tts.speak("expanded", true)
var focused_tree_item
func input_tree(event):
pass
if event.echo or not event.pressed:
return
if not focused_tree_item:
focused_tree_item = node.get_root()
if event.scancode == KEY_UP:
node.accept_event()
focused_tree_item = focused_tree_item.get_prev_visible()
if not focused_tree_item:
focused_tree_item = node.get_root()
if node.select_mode == Tree.SELECT_SINGLE:
if node.columns == 1 and focused_tree_item.is_selectable(0):
# focused_tree_item.select(0)
pass
render_tree_item()
elif event.scancode == KEY_DOWN:
node.accept_event()
focused_tree_item = focused_tree_item.get_next_visible()
if not focused_tree_item:
focused_tree_item = node.get_root()
if node.select_mode == Tree.SELECT_SINGLE:
if node.columns == 1 and focused_tree_item.is_selectable(0):
# focused_tree_item.select(0)
pass
render_tree_item()
elif event.scancode == KEY_PLUS:
node.accept_event()
focused_tree_item.collapsed = false
elif event.scancode == KEY_MINUS:
node.accept_event()
focused_tree_item.collapsed = true
elif event.scancode == KEY_SPACE:
print("Got it")
node.accept_event()
tts.speak("Select", true)
func select_tree_item():
if node.has_focus():
tts.speak(render_tree_item(), true)
render_tree_item()
func multi_select_tree_item(item, column, selected):
if selected:
tts.speak("selected", true)
else:
tts.speak("unselected", true)
func focused():
print("Focus: %s" % node)
@ -251,4 +297,5 @@ func _init(tts, node):
elif node is Tree:
node.connect("item_collapsed", self, "collapse_tree_item")
node.connect("item_selected", self, "select_tree_item")
node.connect("multi_selected", self, "multi_select_tree_item")
node.connect("tree_exiting", self, "free")

View File

@ -3,5 +3,4 @@
[ext_resource path="res://player.gd" type="Script" id=1]
[node name="Player" type="Area2D"]
position = Vector2( 2, 3 )
script = ExtResource( 1 )

View File

@ -24,85 +24,3 @@ Globals="*res://Globals.gd"
[editor_plugins]
enabled=[ "accessibility" ]
[input]
ui_accept={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777222,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
]
}
ui_select={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":3,"pressure":0.0,"pressed":false,"script":null)
]
}
ui_cancel={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777217,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
]
}
ui_focus_next={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777218,"unicode":0,"echo":false,"script":null)
]
}
ui_focus_prev={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777218,"unicode":0,"echo":false,"script":null)
]
}
ui_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
]
}
ui_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
]
}
ui_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
]
}
ui_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
]
}
ui_page_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777235,"unicode":0,"echo":false,"script":null)
]
}
ui_page_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777236,"unicode":0,"echo":false,"script":null)
]
}
ui_home={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777229,"unicode":0,"echo":false,"script":null)
]
}
ui_end={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777230,"unicode":0,"echo":false,"script":null)
]
}
default_environment=false
[input map]
custom_font=false