123456789101112131415161718192021222324252627282930 |
- class_name StackableControl extends Control
- @export
- var _initial_scene: PackedScene
- var _current_ref: Node
- var _stacked_ref: Array[Node] = []
- func _ready() -> void:
- to_prefab(_initial_scene)
- func to(node: Node, push_prev: bool = false) -> void:
- if push_prev:
- _stacked_ref.push_back(_current_ref)
- if _current_ref != null:
- remove_child(_current_ref)
- _current_ref = null
- if node != null:
- add_child(node)
- _current_ref = node
- func to_prefab(prefab: PackedScene, push_prev: bool = false) -> void:
- if prefab != null:
- to(prefab.instantiate(), push_prev)
- func pop() -> void:
- to(_stacked_ref.pop_back(), false)
- func clear_stacked() -> void:
- _stacked_ref.clear()
|