From af82bcc9b93bc874c689293f3f6b80999152a553 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 1 Jul 2023 01:14:25 +0200 Subject: [PATCH] searching siblings to find a node that will take focus --- src/singletons/global_state.gd | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/singletons/global_state.gd b/src/singletons/global_state.gd index 16ff66f..326b7f3 100644 --- a/src/singletons/global_state.gd +++ b/src/singletons/global_state.gd @@ -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