ui.gd 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. extends Control
  2. @export var combatants_node: Node
  3. @export var info_scene: PackedScene
  4. func initialize():
  5. for combatant in combatants_node.get_children():
  6. var health = combatant.get_node("Health")
  7. var info = info_scene.instantiate()
  8. var health_info = info.get_node("VBoxContainer/HealthContainer/Health")
  9. health_info.value = health.life
  10. health_info.max_value = health.max_life
  11. info.get_node("VBoxContainer/NameContainer/Name").text = combatant.name
  12. health.connect("health_changed", Callable(health_info, "set_value"))
  13. $Combatants.add_child(info)
  14. $Buttons/GridContainer/Attack.grab_focus()
  15. func _on_Attack_button_up():
  16. if not combatants_node.get_node("Player").active:
  17. return
  18. combatants_node.get_node("Player").attack(combatants_node.get_node("Opponent"))
  19. func _on_Defend_button_up():
  20. if not combatants_node.get_node("Player").active:
  21. return
  22. combatants_node.get_node("Player").defend()
  23. func _on_Flee_button_up():
  24. if not combatants_node.get_node("Player").active:
  25. return
  26. combatants_node.get_node("Player").flee()
  27. var loser = combatants_node.get_node("Player")
  28. var winner = combatants_node.get_node("Opponent")
  29. get_parent().finish_combat(winner, loser)