prompt_container.gd 939 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. class_name PromptContainer
  2. extends Control
  3. ## Free itself when every prompt has been used
  4. var _nb_prompts: int
  5. func _ready() -> void:
  6. _nb_prompts = 0
  7. for child in get_children():
  8. if child is InputPrompt:
  9. child.pressed.connect(child.queue_free)
  10. if child is InputPrompt or child is PromptContainer:
  11. child.tree_exited.connect(_on_child_exited_tree)
  12. _nb_prompts += 1
  13. func switch(enable: bool) -> void:
  14. if enable:
  15. enable()
  16. else:
  17. disable()
  18. # Show and process
  19. func enable() -> void:
  20. set_visible(true)
  21. set_process_mode(Node.PROCESS_MODE_PAUSABLE)
  22. # Hide and stop processing
  23. func disable() -> void:
  24. set_visible(false)
  25. set_process_mode(Node.PROCESS_MODE_DISABLED)
  26. func remove_if_no_more_prompt():
  27. _nb_prompts -= 1
  28. print(_nb_prompts, " remaining prompts")
  29. if _nb_prompts <= 0:
  30. # Only label remaining
  31. print("Destruction !")
  32. queue_free()
  33. func _on_child_exited_tree() -> void:
  34. remove_if_no_more_prompt()