ui.gd 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. extends Control
  2. @export var combatants_node: Node
  3. @export var info_scene: PackedScene
  4. func initialize() -> void:
  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.health_changed.connect(health_info.set_value)
  13. $Combatants.add_child(info)
  14. $Buttons/GridContainer/Attack.grab_focus()
  15. func _on_Attack_button_up() -> void:
  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() -> void:
  20. if not combatants_node.get_node("Player").active:
  21. return
  22. combatants_node.get_node("Player").defend()
  23. func _on_Flee_button_up() -> void:
  24. if not combatants_node.get_node("Player").active:
  25. return
  26. combatants_node.get_node("Player").flee()
  27. var loser: Combatant = combatants_node.get_node("Player")
  28. var winner: Combatant = combatants_node.get_node("Opponent")
  29. get_parent().finish_combat(winner, loser)