58 lines
1.8 KiB
GDScript
58 lines
1.8 KiB
GDScript
@tool
|
|
extends Control
|
|
|
|
const BUTTON_QTY = 4
|
|
|
|
const guiButton : PackedScene = preload("res://UI/gui_button.tscn")
|
|
|
|
@onready var buttonContainer = %ButtonContainer
|
|
@onready var cubeIntegrity = %CubeIntegrity
|
|
|
|
|
|
func _ready() -> void:
|
|
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)
|
|
|
|
|
|
func _on_button_cube_pressed() -> void:
|
|
pass # Replace with function body.
|
|
|
|
|
|
func quitLevel() -> void:
|
|
Transition.goto("res://UI/start_menu.tscn")
|
|
|
|
|
|
func quitGame() -> void:
|
|
get_tree().quit()
|
|
|
|
|
|
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)
|