searching siblings to find a node that will take focus

This commit is contained in:
betalars 2023-07-01 01:14:25 +02:00
parent 5b41242439
commit af82bcc9b9
1 changed files with 8 additions and 1 deletions

View File

@ -12,6 +12,11 @@ var allow_skipping: bool = false
var focus_list:Array = []
var lock_focus: bool = false
func _ready():
for child in get_parent().get_children():
if "has_focus" in child:
pass_focus_to(child)
# Intented for use when me wants focus for itself, can reclaim focus, thus dropping the stack that focused.
func request_focus_for(me: Object, reclaim: bool = false) -> bool:
if reclaim:
@ -47,7 +52,9 @@ func pass_focus_to(target:Object) -> bool:
elif !is_instance_valid(target):
push_error("Focus instance not valid")
elif !"has_focus" in target:
push_error(target, " has no has focus method")
push_error(target, " has no has focus method.")
if focus_list.front() == target:
push_warning(target, " is already target. Abort passing focus.")
else:
if not focus_list.front() == null: focus_list.front().has_focus = false
target.has_focus = true