class_name HUD extends CanvasLayer @onready var time: Label = %Time @onready var money: Label = %Money @onready var income: Label = %Income @onready var spawn_box: Control = %SpawnBox @onready var team_top: PanelContainer = %TeamTop @onready var team_bottom: PanelContainer = %TeamBottom @onready var lives_top: Label = %LivesTop @onready var lives_bottom: Label = %LivesBottom func _ready(): Client.player.money_changed.connect(func(): money.text = "Money: " + str(Client.player.money) ) Client.player.income_changed.connect(func(): income.text = "Income: " + str(Client.player.income) ) Client.current_stage.lives_changed.connect(func(): lives_top.text = "Lives: %02d" % Client.current_stage.teams.top.lives lives_bottom.text = "Lives: %02d" % Client.current_stage.teams.bottom.lives ) Client.stage_state_changed.connect(func(state: State): if state is StateBuild: %TowerConfigurationsContainer.visible = true else: %TowerConfigurationsContainer.visible = false ) # TODO: fix multi select %SelectionContainer.visible = false %SelectionData.get_child(0).queue_free() %MultiSelectionContainer.visible = false Client.placed_tower.connect(func(tower: Tower): tower.selected.connect(func(): var hud_data = tower.get_hud() hud_data.name = tower.name var groups = {"md5:1": [], "md5_2": []} var selected_group = "md5" # TODO: build groups from current component configurations matches. md5 of property values? # TODO: do in tower.gd at select? if Tower.selected_towers.size() == 1: %SelectionContainer.visible = true %MultiSelectionContainer.visible = false %SelectionData.add_child(hud_data) %MultiSelectionList.add_child(hud_data.duplicate()) elif Tower.selected_towers.size() > 1: %SelectionContainer.visible = false %MultiSelectionContainer.visible = true %MultiSelectionList.add_child(hud_data) ) tower.deselected.connect(func(): if Tower.selected_towers.size() == 0: %SelectionContainer.visible = false %MultiSelectionContainer.visible = false for child in %SelectionData.get_children(): child.queue_free() for child in %MultiSelectionList.get_children(): child.queue_free() elif Tower.selected_towers.size() == 1: %MultiSelectionContainer.visible = false %SelectionContainer.visible = true elif Tower.selected_towers.size() > 1: # only remove deselected tower from list %MultiSelectionList.get_node(NodePath(tower.name)).queue_free() ) ) func _input(event: InputEvent): if event.is_action_pressed("spawn_box_toggle"): spawn_box.visible = not spawn_box.visible if event.is_action_pressed("players_list_toggle"): team_top.visible = not team_top.visible team_bottom.visible = not team_bottom.visible func _on_build_mode_button_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): if Client.state is StateDefault: get_tree().current_scene.get_node("StateManager").set_state("StateBuild") elif Client.state is StateBuild: get_tree().current_scene.get_node("StateManager").set_state("StateDefault") func _on_spawner_box_button_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): spawn_box.visible = not spawn_box.visible func _on_player_list_button_gui_input(event: InputEvent) -> void: if event.is_action_pressed("select"): team_top.visible = not team_top.visible team_bottom.visible = not team_bottom.visible