44 lines
1.1 KiB
GDScript
44 lines
1.1 KiB
GDScript
@tool
|
|
extends Button
|
|
class_name GuiButton
|
|
|
|
|
|
enum TYPE { BASIC, TOWER, UPGRADE }
|
|
|
|
|
|
var type : TYPE = TYPE.BASIC
|
|
|
|
|
|
var towerType : Tower.TYPE :
|
|
set(value):
|
|
towerType = value
|
|
if towerType != Tower.TYPE.NONE:
|
|
type = TYPE.TOWER
|
|
toggle_mode = true
|
|
add_theme_stylebox_override("pressed", GameStyleBoxFlat.createWithColor(GameColor.COLOR.SELECTED))
|
|
EventBus.tower_changed.connect(towerChanged)
|
|
EventBus.tower_selected.connect(func(_type): set_pressed_no_signal(_type == towerType))
|
|
if type == TYPE.UPGRADE:
|
|
EventBus.tower_upgraded.connect(upgradeTower)
|
|
|
|
|
|
func upgradeTower(_towerType : Tower.TYPE, upgrade : TowerUpgrade) -> void:
|
|
pass
|
|
|
|
|
|
@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.type == towerType:
|
|
$EnergyBar.value = tower.energy
|
|
$EnergyBar.max_value = tower.max_energy
|
|
$EnergyBar.visible = tower.builded
|