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

69 lines
2.2 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 request_focus(new_focus: Node, reclaim_focus: bool = false) -> bool:
assert(is_instance_valid(new_focus))
if lock_focus or get_tree().paused:
push_warning(new_focus.name, " attempted to get focus while tree was paused or fokus had been locked.")
return false
if not focus_list.size() == 0: _pass_focus_of(focus_list[0])
if reclaim_focus:
if focus_list.has(new_focus):
while not focus_list[0] == new_focus: focus_list.pop_front()
return true
else:
focus_list.push_front(new_focus)
push_warning(new_focus.name, " attempted to reclaim focus it did not previousely have.")
return true
else:
focus_list.append(new_focus)
return true
func assign_focus_to(focusable: Node) -> bool:
if "focus_forward" in focusable:
assign_focus_to(focusable.focus_forward)
if "has_focus" in focusable:
if not focus_list.size() == 0:
_pass_focus_of(focus_list[0])
focusable.has_focus = true
return true
else: return false
func pass_focus_to_unkown(from: Node):
pass
func drop_own_focus(node: Node):
if focus_list[0] == node:
focus_list.pop_front().has_focus = false
assert(focus_list.size() == 0)
focus_list[0].has_focus = true
else:
push_warning(node.name + " attempted to drop focus while not owning it.")
func clear_focus_stack_and_focus_on(focus: Node):
assert(is_instance_valid(focus))
if focus_list.size() > 0: focus_list[0].has_focus = false
focus_list = [focus]
focus.has_focus = true
func _pass_focus_of(previous_focus: Node):
previous_focus.has_focus = false
func focus_cleared(from: Node):
if from == focus_list[0]:
push_warning(from.name, " cleared focus without validating!")