Add prestige graph
This commit is contained in:
85
core/prestige/prestige_buff_graph_panel.gd
Normal file
85
core/prestige/prestige_buff_graph_panel.gd
Normal file
@@ -0,0 +1,85 @@
|
||||
## Separate-screen panel displaying the prestige buff graph.
|
||||
## Tiles are placed manually in the scene editor — each PrestigeBuffGraphTile has its PrestigeBuffNode
|
||||
## resource assigned directly. The panel manages the prestige currency balance display and
|
||||
## delegates connection-line drawing to a PrestigeBuffConnectionOverlay child.
|
||||
class_name PrestigeBuffGraphPanel
|
||||
extends PanelContainer
|
||||
|
||||
@onready var _balance_label: Label = $MarginContainer/VBoxContainer/BalanceLabel
|
||||
@onready var _tiles_area: Control = $MarginContainer/VBoxContainer/TilesArea
|
||||
@onready var _close_button: Button = $MarginContainer/VBoxContainer/Header/CloseButton
|
||||
@onready var _connection_overlay: PrestigeBuffConnectionOverlay = $MarginContainer/VBoxContainer/TilesArea/ConnectionOverlay
|
||||
|
||||
var _game_state: LevelGameState
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_game_state = find_parent("LevelGameState")
|
||||
if _game_state == null:
|
||||
push_error("PrestigeBuffGraphPanel: Could not find LevelGameState parent")
|
||||
return
|
||||
|
||||
_game_state.currency_changed.connect(_on_currency_changed)
|
||||
_close_button.pressed.connect(_on_close_pressed)
|
||||
|
||||
visibility_changed.connect(_on_visibility_changed)
|
||||
_refresh_balance()
|
||||
|
||||
|
||||
## Rebuilds the connection overlay by scanning all PrestigeBuffGraphTile children and matching parent_ids.
|
||||
func _refresh_connections() -> void:
|
||||
if _connection_overlay == null:
|
||||
return
|
||||
|
||||
var tiles_by_id: Dictionary = {}
|
||||
var all_tiles: Array[PrestigeBuffGraphTile] = []
|
||||
_collect_tiles(_tiles_area, all_tiles)
|
||||
|
||||
for tile in all_tiles:
|
||||
var node_id: StringName = tile.get_node_id()
|
||||
if node_id != &"":
|
||||
tiles_by_id[node_id] = tile
|
||||
|
||||
var connections: Array = []
|
||||
for tile in all_tiles:
|
||||
if tile.prestige_buff == null:
|
||||
continue
|
||||
for parent_id in tile.prestige_buff.parent_ids:
|
||||
var parent_tile: PrestigeBuffGraphTile = tiles_by_id.get(parent_id, null)
|
||||
if parent_tile:
|
||||
connections.append([parent_tile, tile])
|
||||
|
||||
_connection_overlay.set_connections(connections)
|
||||
|
||||
|
||||
## Recursively collects all PrestigeBuffGraphTile nodes from a container.
|
||||
func _collect_tiles(from: Node, out_tiles: Array[PrestigeBuffGraphTile]) -> void:
|
||||
for child in from.get_children():
|
||||
if child is PrestigeBuffGraphTile:
|
||||
out_tiles.append(child)
|
||||
elif child is Container:
|
||||
_collect_tiles(child, out_tiles)
|
||||
|
||||
func _refresh_balance() -> void:
|
||||
if _game_state == null:
|
||||
_balance_label.text = "Prestige Currency: 0"
|
||||
return
|
||||
|
||||
var currency_id: StringName = _game_state.get_prestige_currency_id()
|
||||
var balance: BigNumber = _game_state.get_currency_amount_by_id(currency_id)
|
||||
_balance_label.text = "Prestige Currency: %s" % balance.to_string_suffix(2)
|
||||
|
||||
func _on_currency_changed(currency_id: StringName, _new_amount: BigNumber) -> void:
|
||||
if currency_id == _game_state.get_prestige_currency_id():
|
||||
_refresh_balance()
|
||||
|
||||
func _on_close_pressed() -> void:
|
||||
hide()
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if visible:
|
||||
_refresh_balance()
|
||||
_refresh_connections()
|
||||
|
||||
func _on_prestige_buff_toggle_pressed() -> void:
|
||||
show()
|
||||
Reference in New Issue
Block a user