TowerDefense/UI/gui.gd

59 lines
1.8 KiB
GDScript3
Raw Normal View History

2025-08-29 20:07:36 +02:00
@tool
2025-08-26 19:26:36 +02:00
extends Control
const BUTTON_QTY = 4
2025-08-29 20:07:36 +02:00
const guiButton : PackedScene = preload("res://UI/gui_button.tscn")
2025-08-29 20:07:36 +02:00
@onready var buttonContainer = %ButtonContainer
2025-09-03 20:52:14 +02:00
@onready var cubeIntegrity = %CubeIntegrity
2025-08-27 13:27:32 +02:00
2025-08-30 00:46:34 +02:00
2025-08-27 13:27:32 +02:00
func _ready() -> void:
2025-08-29 20:07:36 +02:00
addTowerButtonNodes()
EventBus.team_in_rest_changed.connect(func(count): %LabelTowerInCube.text = "Zzz : %d" % count)
EventBus.team_in_action_changed.connect(func(count): %LabelTowerOnTerrain.text = " In action : %d" % count)
Game.allowed_tower_has_change.connect(addTowerButtonNodes)
Game.cube_integrity_changed.connect(func(): cubeIntegrity.value = Game.healthPercentage)
Game.money_changed.connect(func(): %LabelMoney.text = "%d" % Game.money)
%NextWaveBtn.pressed.connect(EventBus.lauch_next_wave.emit)
2025-08-29 20:07:36 +02:00
2025-08-26 19:26:36 +02:00
func _on_button_cube_pressed() -> void:
pass # Replace with function body.
2025-08-27 13:27:32 +02:00
2025-09-03 20:52:14 +02:00
func quitLevel() -> void:
2025-08-27 13:27:32 +02:00
Transition.goto("res://UI/start_menu.tscn")
2025-09-03 20:52:14 +02:00
func quitGame() -> void:
2025-08-27 13:27:32 +02:00
get_tree().quit()
2025-08-29 20:07:36 +02:00
2025-08-30 00:46:34 +02:00
2025-08-29 20:07:36 +02:00
func addTowerButtonNodes() -> void:
for node in buttonContainer.get_children():
if node.has_meta("dynamicButton"):
node.queue_free()
for towerType : int in Tower.TYPE.values() :
if towerType && (Engine.is_editor_hint() || Game.allowedTowers.has(towerType)):
createTowerButton(towerType)
for i in BUTTON_QTY - (buttonContainer.get_children().size() % BUTTON_QTY):
createTowerButton(Tower.TYPE.NONE)
func createTowerButton(towerType : Tower.TYPE) -> void:
var btn : GuiButton = guiButton.instantiate()
btn.set_meta("dynamicButton", true)
if towerType:
var tower : PackedScene = Game.towerPackedScenes.get(towerType)
btn.towerType = towerType
btn.tooltip_text = str(EnhancedResource.getPackedSceneProperty(tower, "name"))
btn.texture = EnhancedResource.getPackedSceneProperty(tower, "icone")
else:
btn.disabled = true
buttonContainer.add_child(btn)