TowerDefense/UI/gui_button.gd
2025-09-03 18:42:28 +02:00

38 lines
859 B
GDScript

@tool
extends Button
class_name GuiButton
enum TYPE { BASIC, TOWER }
var type : TYPE = TYPE.BASIC
var towerType : Tower.TYPE :
set(value):
towerType = value
if towerType != Tower.TYPE.NONE:
type = TYPE.TOWER
toggle_mode = true
$EnergyBar.visible = true
EventBus.energy_has_changed.connect(towerChanged)
EventBus.tower_builded.connect(towerChanged)
EventBus.tower_selected.connect(func(type): set_pressed_no_signal(type == towerType))
@export var texture : Texture2D :
set(value):
texture = value
$TextureRect.texture = texture
func buttonToggled(state : bool) -> void:
if type == TYPE.TOWER:
EventBus.tower_selected.emit(towerType if state else Tower.TYPE.NONE)
func towerChanged(tower : Tower) -> void :
if tower.tower_type == towerType:
$EnergyBar.value = tower.energy
$EnergyBar.max_value = tower.max_energy