frame-of-mind/src/singletons/global_state.gd

74 lines
2.5 KiB
GDScript

extends Node
var screen_reader:bool = false
var disable_rendering: bool = false
var simplified_navigation:bool = false
var enable_subtitles: bool = false
var reduce_motion: bool = false
var show_content_notes: bool = false
var provide_summaries: bool = false
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:
focus_list.front().has_focus = false
if focus_list.has(me):
while focus_list.pop_front() != me: break
me.has_focus = true
return me.has_focus
push_warning(me, " wanted to reclaim focus, but was not on list.")
return pass_focus_to(me)
# Element no longer wants focus, if Element itself is also dropped, this option can be chosen aswell.
func drop_focus(of:Object, dropObject: bool = false) -> bool:
if lock_focus or get_tree().paused:
push_error(of, " wanted to drop focus while it was locked or tree is paused.")
if not dropObject: of.has_focus = false
focus_list.erase(of)
focus_list.front().has_focus = true
return false
func get_current_focus(): return focus_list.front()
# Used to put a new target on top of the Focus Stack.
func pass_focus_to(target:Object) -> bool:
if "focus_forward" in target:
pass_focus_to(target.focus_forward)
if lock_focus or get_tree().paused:
push_error(target, " requested focus while it was locked or tree is paused.")
elif !is_instance_valid(target):
push_error("Focus instance not valid")
elif !"has_focus" in target:
push_error(target, " has no has focus method.")
if focus_list.size() > 0:
if focus_list.front() == target:
push_warning(target, " is already target. Abort passing focus.")
else:
if not focus_list.size() == 0: focus_list.front().has_focus = false
target.has_focus = true
if target.has_focus:
focus_list.push_front(target)
assert(focus_list.size() < 100)
return true
return false
# Currently focused element loses focus, but remains in stack.
func free_focus():
if not focus_list.front() == null: focus_list.front().has_focus = false
func queue_for_focus(target: Object, index: int):
focus_list.insert(index, target)