36 lines
1.0 KiB
GDScript
36 lines
1.0 KiB
GDScript
## Dynamically displays all currencies from the LevelGameState catalogue as CurrencyTile widgets.
|
|
class_name CurrencyPanel
|
|
extends PanelContainer
|
|
|
|
const CURRENCY_TILE_SCENE: PackedScene = preload("res://currency_tile.tscn")
|
|
|
|
@onready var _tiles_container: VBoxContainer = $CurrencyTiles
|
|
|
|
var _game_state: LevelGameState
|
|
|
|
func _ready() -> void:
|
|
_game_state = find_parent("LevelGameState")
|
|
if _game_state == null:
|
|
push_error("CurrencyPanel: No LevelGameState found in parent hierarchy")
|
|
return
|
|
_build_currency_tiles()
|
|
_game_state.ready.connect(_on_game_state_ready)
|
|
|
|
func _build_currency_tiles() -> void:
|
|
for child in _tiles_container.get_children():
|
|
child.queue_free()
|
|
|
|
if _game_state.currency_catalogue == null:
|
|
return
|
|
|
|
for currency in _game_state.currency_catalogue.currencies:
|
|
if currency == null:
|
|
continue
|
|
var tile: CurrencyTile = CURRENCY_TILE_SCENE.instantiate()
|
|
tile.currency = currency
|
|
tile.game_state = _game_state
|
|
_tiles_container.add_child(tile)
|
|
|
|
func _on_game_state_ready() -> void:
|
|
pass
|