1
Fork 0
mirror of https://github.com/Steffo99/nanogolf.git synced 2024-11-22 08:04:21 +00:00
algodist-steffo-nanogolf/scenes/game_hud.gd

56 lines
1.8 KiB
GDScript3
Raw Normal View History

2024-03-16 04:25:23 +00:00
extends Control
class_name GameHUD
@export var strokes_label: Label
@export var scores_panel: PanelContainer
@export var scores_container: Control
const score_scene = preload("res://scenes/player_score_label.tscn")
func _on_level_completed(_level: GolfLevel) -> void:
strokes_label.text = "0"
for child in scores_container.get_children():
child.queue_free()
scores_panel.hide()
func _on_playernode_name_changed(old: String, new: String, playernode: PlayerNode) -> void:
var instance = get_node_or_null("PlayerScoreLabel__%s" % old)
if instance != null:
instance.from_score(playernode)
instance.name = "PlayerScoreLabel__%s" % new
2024-03-16 04:55:02 +00:00
func _on_playernode_color_changed(_old: Color, _new: Color, playernode: PlayerNode) -> void:
2024-03-16 04:25:23 +00:00
var instance = get_node_or_null("PlayerScoreLabel__%s" % playernode.player_name)
if instance != null:
instance.from_score(playernode)
2024-03-16 04:55:02 +00:00
func _on_playernode_possessed(_old: int, _new: int, playernode: PlayerNode) -> void:
2024-03-16 04:25:23 +00:00
var instance = get_node_or_null("PlayerScoreLabel__%s" % playernode.player_name)
if instance != null:
instance.from_score(playernode)
func _on_playernode_score_reported(strokes: int, playernode: PlayerNode) -> void:
var score_instance = score_scene.instantiate()
score_instance.from_score(strokes, playernode)
score_instance.name = "PlayerScoreLabel__%s" % playernode.player_name
scores_container.add_child(score_instance)
scores_panel.show()
2024-03-16 04:55:02 +00:00
func _on_playernode_scores_changed(_old: Array, _new: Array, _playernode: PlayerNode) -> void:
2024-03-16 04:25:23 +00:00
pass
2024-03-16 04:55:02 +00:00
func _on_local_player_spawned(ball: GolfBall, _level: GolfLevel) -> void:
ball.putt_controller.putt.connect(_on_putt.bind(ball))
func _on_putt(_putt_vector: Vector2, ball: GolfBall) -> void:
strokes_label.text = "%d" % ball.strokes
2024-03-16 04:25:23 +00:00
func _on_strokes_changed(strokes: int) -> void:
strokes_label.text = "%s" % strokes