TowerDefense/UI/gui_button.gd

40 lines
958 B
GDScript3
Raw Normal View History

@tool
extends Button
class_name GuiButton
2025-09-03 18:39:58 +02:00
enum TYPE { BASIC, TOWER }
var type : TYPE = TYPE.BASIC
var towerType : Tower.TYPE :
set(value):
towerType = value
if towerType != Tower.TYPE.NONE:
2025-09-03 18:39:58 +02:00
type = TYPE.TOWER
toggle_mode = true
$EnergyBar.visible = true
2025-09-03 20:52:14 +02:00
add_theme_stylebox_override("pressed", GameStyleBoxFlat.createWithColor(Game.COLOR.SELECTED))
EventBus.energy_has_changed.connect(towerChanged)
EventBus.tower_builded.connect(towerChanged)
2025-09-03 20:52:14 +02:00
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:
2025-09-03 18:39:58 +02:00
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