Add currency panel
This commit is contained in:
35
core/currency/currency_panel.gd
Normal file
35
core/currency/currency_panel.gd
Normal file
@@ -0,0 +1,35 @@
|
||||
## 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
|
||||
1
core/currency/currency_panel.gd.uid
Normal file
1
core/currency/currency_panel.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://blfou5xiynxqf
|
||||
Reference in New Issue
Block a user