fixing up handling of locked focus in global state

This commit is contained in:
betalars 2023-08-01 10:49:42 +02:00
parent ee9ab8bc68
commit 7434426af6
1 changed files with 8 additions and 6 deletions

View File

@ -24,6 +24,7 @@ func _ready():
# Intented for use when an actor wants focus for itself, can reclaim focus, thus dropping the stack that focused.
func take_stage(actor: Object, reclaim: bool = false) -> bool:
if lock_focus: return false
if reclaim:
stage_list.front().has_stage = false
if stage_list.has(actor):
@ -36,11 +37,11 @@ func take_stage(actor: Object, reclaim: bool = false) -> bool:
# Element no longer wants focus, if Element itself is also dropped, this option can be chosen aswell.
func leave_stage(actor:Object, dropObject: bool = false) -> bool:
if lock_focus or get_tree().paused:
push_error(actor, " wanted to drop focus while it was locked or tree is paused.")
if get_tree().paused:
push_error(actor, " wanted to drop focus while tree is paused.")
if not dropObject: actor.has_stage = false
lock_focus = false
stage_list.erase(actor)
if stage_list != []:
@ -53,10 +54,10 @@ func leave_stage(actor:Object, dropObject: bool = false) -> bool:
func get_current_actor(): return stage_list.front()
# Used to put a new target on top of the Focus Stack.
func pass_stage_to(target:Object) -> bool:
func pass_stage_to(target:Object, force = false) -> bool:
if "pass_to_actor" in target:
pass_stage_to(target.pass_to_actor)
if lock_focus or get_tree().paused:
if (lock_focus or get_tree().paused) and not force:
push_error(target, " requested focus while it was locked or tree is paused.")
elif !is_instance_valid(target):
push_error("Focus instance not valid")
@ -77,13 +78,14 @@ func pass_stage_to(target:Object) -> bool:
# Currently focused element loses focus, but remains in stack.
func free_focus():
if lock_focus: return false
if stage_list.size() > 0: stage_list.front().has_stage = false
func transition_stage_to(thief: Object):
if stage_list.size() > 0:
if stage_list.front().has_stage:
stage_list.pop_front().has_stage = false
return pass_stage_to(thief)
return pass_stage_to(thief, true)
func queue_for_stage(target: Object, index: int = 1):
stage_list.insert(index, target)