plant_button_root.gd 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. extends Control
  2. @export_multiline var description = ""
  3. @export var icon: Texture
  4. @export var plant: PackedScene
  5. @export var hotkey: int
  6. var t_cost: int = -1
  7. var shown: bool = false
  8. func _input(ev):
  9. var b = $MarginContainer/Button
  10. if ev is InputEventKey and ev.keycode == hotkey and !ev.pressed and !b.disabled:
  11. b._on_pressed()
  12. func _ready():
  13. var p = plant.instantiate()
  14. description += "\n[color=#88FFFF]Root strength: " + str(p.max_hp) + "[/color]"
  15. description += "\n[color=#FF8888]Base damage: " + str(p.attack_damage) + "[/color]"
  16. description += "\n[color=#88FF88]Fire rate: " + str(p.attack_rate) + "s [/color]"
  17. description += "\n[color=#FFFF88]Cost: " + str(p.cost) + "[/color]"
  18. description += "[/font]"
  19. t_cost = p.cost
  20. find_child("Label").set_text("[center][font_size=18]???[/font_size][/center]")
  21. find_child("Button").set_button_icon(icon)
  22. updoot(19)
  23. func updoot(money: int):
  24. if t_cost >= 0 and money >= t_cost:
  25. set_modulate(Color(1.0, 1.0, 1.0, 1.0))
  26. $MarginContainer/Button.set_disabled(false)
  27. else:
  28. set_modulate(Color(0.4, 0.4, 0.4, 1.0))
  29. $MarginContainer/Button.set_disabled(true)
  30. if t_cost >= 0 and shown == false and money >= t_cost - 10:
  31. find_child("Label").set_text(description)
  32. shown = true