Store list of Accessibles and clean up manually.

This commit is contained in:
Nolan Darilek 2019-12-22 21:01:47 -06:00
parent dfe0c8179e
commit 606766e0e8

View File

@ -3,6 +3,8 @@ extends Node
var Accessible = preload("Accessible.gd") var Accessible = preload("Accessible.gd")
var accessibles = []
var focus_restore_timer = Timer.new() var focus_restore_timer = Timer.new()
func focused(node): func focused(node):
@ -24,7 +26,7 @@ func unfocused(node):
func augment_node(node): func augment_node(node):
if node is Control: if node is Control:
var accessible = Accessible.new(node) var accessible = Accessible.new(node)
add_child(accessible) accessibles.append(accessible)
if not node.is_connected("focus_entered", self, "focused"): if not node.is_connected("focus_entered", self, "focused"):
node.connect("focus_entered", self, "focused", [node]) node.connect("focus_entered", self, "focused", [node])
if not node.is_connected("mouse_entered", self, "click_focused"): if not node.is_connected("mouse_entered", self, "click_focused"):
@ -73,3 +75,7 @@ func _enter_tree():
focus_restore_timer.connect("timeout", self, "restore_focus") focus_restore_timer.connect("timeout", self, "restore_focus")
add_child(focus_restore_timer) add_child(focus_restore_timer)
get_tree().connect("node_added", self, "augment_tree") get_tree().connect("node_added", self, "augment_tree")
func _exit_tree():
for accessible in accessibles:
accessible.free()