Enough changes to launch a basic game!

* Add an action to autoclose the dialog for setting keybindings after 5 seconds, thus allowing capturing keys to attach to actions.
 * Remove "Hello, world." from global script and move it into player.
 * Add commands to speak coordinates, headings, and to stop speech.
 * Add Quit command.
 * Announce new screen on change.
 * Other minor cleanups.
This commit is contained in:
Nolan Darilek 2019-09-05 09:01:20 -05:00
parent 8acbab94df
commit 744e2727db
5 changed files with 75 additions and 29 deletions

View File

@ -6,4 +6,3 @@ var tts
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
tts = TTS.new() tts = TTS.new()
tts.speak("Hello, world.", true)

View File

@ -16,6 +16,10 @@ func augment_tree(node):
augment_tree(child) augment_tree(child)
func set_initial_screen_focus(screen): func set_initial_screen_focus(screen):
tts.speak(screen, true)
var control = find_focusable_control(get_tree().root)
if control.get_focus_owner() != null:
return
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)
if not focus: if not focus:
@ -34,6 +38,12 @@ func find_focusable_control(node):
func set_initial_scene_focus(scene): func set_initial_scene_focus(scene):
print("Set focus in scene") print("Set focus in scene")
self.augment_tree(get_tree().root)
var focus = find_focusable_control(get_tree().root)
if not focus:
return
focus.grab_click_focus()
focus.grab_focus()
func _enter_tree(): func _enter_tree():
tts = TTS.new() tts = TTS.new()

View File

@ -30,6 +30,19 @@ func left_click(item := node):
click.pressed = false click.pressed = false
node.get_tree().input_event(click) node.get_tree().input_event(click)
func close_key_event_dialog():
node.get_ok().emit_signal("pressed")
var dialog_close_timer = Timer.new()
func accept_dialog_focus():
if not dialog_close_timer.is_connected("timeout", self, "close_key_event_dialog"):
dialog_close_timer.connect("timeout", self, "close_key_event_dialog")
dialog_close_timer.one_shot = true
dialog_close_timer.start(5)
if dialog_close_timer.get_parent() == null:
node.add_child(dialog_close_timer)
func button_focus(): func button_focus():
var text var text
if node.text: if node.text:
@ -40,7 +53,6 @@ func button_focus():
tts.speak("button", false) tts.speak("button", false)
func texturebutton_focus(): func texturebutton_focus():
print(node.texture_normal.get_data().get_rid().get_id())
tts.speak("button", false) tts.speak("button", false)
func item_list_focus(): func item_list_focus():
@ -59,22 +71,22 @@ func item_list_nothing_selected():
tts.speak("Nothing selected", false) tts.speak("Nothing selected", false)
func item_list_input(event): func item_list_input(event):
if event.is_echo() or not event.pressed:
return
var old_pos = position_in_children var old_pos = position_in_children
if event.scancode == KEY_UP: if event.is_action_pressed("ui_up"):
node.get_tree().set_input_as_handled() node.accept_event()
if position_in_children == 0: if position_in_children == 0:
return return
position_in_children -= 1 position_in_children -= 1
elif event.scancode == KEY_DOWN: elif event.is_action_pressed("ui_down"):
node.get_tree().set_input_as_handled() 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.scancode == KEY_HOME: elif event.is_action_pressed("ui_home"):
node.accept_event()
position_in_children = 0 position_in_children = 0
elif event.scancode == KEY_END: elif event.is_action_pressed("ui_end"):
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:
var text = node.get_item_text(position_in_children) var text = node.get_item_text(position_in_children)
@ -131,17 +143,14 @@ func popup_menu_item_id_focus(id):
var item = node.get_item_text(id) var item = node.get_item_text(id)
var submenu = node.get_item_submenu(id) var submenu = node.get_item_submenu(id)
var tooltip = node.get_item_tooltip(position_in_children) var tooltip = node.get_item_tooltip(position_in_children)
print("Tooltip: %s" % tooltip)
var disabled = node.is_item_disabled(id) var disabled = node.is_item_disabled(id)
if item and tooltip: if item and tooltip:
item += ": " item += ": "
item += tooltip item += tooltip
elif tooltip: elif tooltip:
print("Got tooltip only")
item = tooltip item = tooltip
var shortcut = node.get_item_shortcut(position_in_children) var shortcut = node.get_item_shortcut(position_in_children)
if shortcut != null and shortcut.get_as_text() != "None": if shortcut != null and shortcut.get_as_text() != "None":
print("Got shortcut: %s" % shortcut.get_as_text())
item += ": "+shortcut.get_as_text() item += ": "+shortcut.get_as_text()
if item == "": if item == "":
item = "Unlabelled" item = "Unlabelled"
@ -175,7 +184,6 @@ func tree_item_selected():
button_index = null button_index = null
var cell = node.get_selected() var cell = node.get_selected()
if cell != prev_selected_cell: if cell != prev_selected_cell:
print("New cell")
tree_item_render() tree_item_render()
prev_selected_cell = cell prev_selected_cell = cell
else: else:
@ -209,25 +217,24 @@ func tree_item_multi_select(item, column, selected):
tts.speak("unselected", true) tts.speak("unselected", true)
func tree_input(event): func tree_input(event):
if not event.is_pressed() or event.is_echo():
return
var item = node.get_selected() var item = node.get_selected()
var column var column
if item: if item:
for i in range(node.columns): for i in range(node.columns):
if item.is_selected(i): if item.is_selected(i):
column = i column = i
break
if item and column and button_index != null: if item and column and button_index != null:
if event.is_action_pressed("ui_select"): if event.is_action_pressed("ui_accept"):
node.accept_event() node.accept_event()
return node.emit_signal("button_pressed", item, column, button_index + 1) return node.emit_signal("button_pressed", item, column, button_index + 1)
var new_button_index = button_index var new_button_index = button_index
if event.scancode == KEY_HOME: if event.is_action_pressed("ui_home"):
node.accept_event() node.accept_event()
new_button_index += 1 new_button_index += 1
if new_button_index >= item.get_button_count(column): if new_button_index >= item.get_button_count(column):
new_button_index = 0 new_button_index = 0
elif event.scancode == KEY_END: elif event.is_action_pressed("ui_end"):
node.accept_event() node.accept_event()
new_button_index -= 1 new_button_index -= 1
if new_button_index < 0: if new_button_index < 0:
@ -260,12 +267,12 @@ func tab_container_focus():
tts.speak(text, false) tts.speak(text, false)
func tab_container_input(event): func tab_container_input(event):
if event.is_echo() or not event.pressed:
return
var new_tab = node.current_tab var new_tab = node.current_tab
if event.scancode == KEY_RIGHT: if event.is_action_pressed("ui_right"):
node.accept_event()
new_tab += 1 new_tab += 1
elif event.scancode == KEY_LEFT: elif event.is_action_pressed("ui_left"):
node.accept_event()
new_tab -= 1 new_tab -= 1
if new_tab < 0: if new_tab < 0:
new_tab = node.get_tab_count() - 1 new_tab = node.get_tab_count() - 1
@ -284,6 +291,8 @@ func focused():
tts.speak(parent.label, false) tts.speak(parent.label, false)
if node is MenuButton: if node is MenuButton:
menu_button_focus() menu_button_focus()
elif node is AcceptDialog:
accept_dialog_focus()
elif node is Button: elif node is Button:
button_focus() button_focus()
elif node.get_class() == "EditorInspectorSection": elif node.get_class() == "EditorInspectorSection":
@ -353,9 +362,7 @@ func editor_inspector_section_focus():
tts.speak("editor inspector section", true) tts.speak("editor inspector section", true)
func editor_inspector_section_input(event): func editor_inspector_section_input(event):
if event.is_echo(): if event.is_action_pressed("ui_accept"):
return
if event.is_action_pressed("ui_select"):
left_click() left_click()
func _init(tts, node): func _init(tts, node):

View File

@ -6,8 +6,15 @@ extends Area2D
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. Globals.tts.speak("Hello, world.", true)
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta): func _process(delta):
# pass if Input.is_action_just_pressed("speak_coordinates"):
Globals.tts.speak("%s, %s" % [position.x, position.y], true)
elif Input.is_action_just_pressed("speak_heading"):
Globals.tts.speak("%s degrees" % global_rotation_degrees, true)
elif Input.is_action_pressed("quit"):
get_tree().quit()
elif Input.is_action_pressed("stop_speech"):
Globals.tts.stop()

View File

@ -24,3 +24,26 @@ Globals="*res://Globals.gd"
[editor_plugins] [editor_plugins]
enabled=[ "accessibility" ] enabled=[ "accessibility" ]
[input]
speak_coordinates={
"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":67,"unicode":0,"echo":false,"script":null)
]
}
speak_heading={
"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":72,"unicode":0,"echo":false,"script":null)
]
}
stop_speech={
"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":16777238,"unicode":0,"echo":false,"script":null)
]
}
quit={
"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)
]
}