Files
autgame/games/juggleboard/scripts/ui/game_hud.gd
T

139 lines
4.6 KiB
GDScript

class_name JuggleBoardHud
extends CanvasLayer
## HUD del JuggleBoard: costruzione e aggiornamenti visuali.
signal options_requested
const DISPLAY_FONT := preload("res://shared/assets/fonts/NotoSerifDisplay-CondensedExtraBold.ttf")
const CARTOUCHE_SCRIPT := preload("res://games/juggleboard/scripts/ui/hud_cartouche.gd")
const TARGET_SCRIPT := preload("res://games/juggleboard/scripts/components/target_dot.gd")
const HEARTS_SCRIPT := preload("res://games/juggleboard/scripts/ui/hearts_display.gd")
var target_dot: Node2D
var score_label: Label
var combo_label: Label
var help_label: Label
var milestone_label: Label
var flash: ColorRect
var hearts: Node2D
func _ready() -> void:
_build()
func _build() -> void:
var ink := Color("#5b2f19")
var cartouche: Node2D = CARTOUCHE_SCRIPT.new()
add_child(cartouche)
var target_label := _make_label("BERSAGLIO", Vector2(94, 44), Vector2(270, 54), 34, ink)
target_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
target_dot = TARGET_SCRIPT.new()
target_dot.position = Vector2(430, 78)
add_child(target_dot)
help_label = _make_label(
"Tocca la pallina corrispondente al bersaglio per lanciarla!",
Vector2(JuggleBoardConfig.VIEW.x / 2 - 350, 154), Vector2(700, 30), 17, ink
)
help_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
score_label = _make_label("", Vector2(925, 34), Vector2(245, 48), 36, ink)
score_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
combo_label = _make_label("", Vector2(925, 80), Vector2(245, 34), 21, ink)
combo_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
hearts = HEARTS_SCRIPT.new()
hearts.position = Vector2(121, 99)
hearts.visible = false
add_child(hearts)
var options_button := Button.new()
options_button.text = "Opzioni"
options_button.position = Vector2(580, 49)
options_button.size = Vector2(120, 57)
options_button.add_theme_font_override("font", DISPLAY_FONT)
options_button.add_theme_font_size_override("font_size", 25)
options_button.add_theme_color_override("font_color", ink)
options_button.add_theme_color_override("font_hover_color", Color("#7b421f"))
var option_style := _button_style(Color("#ddb983"))
options_button.add_theme_stylebox_override("normal", option_style)
var option_hover := _button_style(Color("#ebcb96"))
options_button.add_theme_stylebox_override("hover", option_hover)
options_button.add_theme_stylebox_override("pressed", option_style)
options_button.pressed.connect(func(): options_requested.emit())
add_child(options_button)
milestone_label = _make_label("", Vector2(0, 160), Vector2(JuggleBoardConfig.VIEW.x, 120), 56, Color(0.8, 0.55, 0.1))
milestone_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
milestone_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
milestone_label.visible = false
flash = ColorRect.new()
flash.color = Color(1, 1, 0.7)
flash.position = Vector2.ZERO
flash.size = JuggleBoardConfig.VIEW
flash.mouse_filter = Control.MOUSE_FILTER_IGNORE
flash.modulate.a = 0.0
flash.visible = false
add_child(flash)
func reset(score: int, combo: float, lives: int, survival: bool) -> void:
set_score(score, combo)
hearts.set_lives(lives)
hearts.visible = survival
help_label.visible = true
func set_score(score: int, combo: float) -> void:
score_label.text = "PUNTI %d" % score
combo_label.text = "Combo x%d" % int(combo)
func set_target(color: Color, shown: bool = true) -> void:
if shown:
target_dot.set_color(color)
target_dot.visible = shown
func celebrate(amount: int) -> void:
milestone_label.text = "%d PUNTI!" % amount
milestone_label.visible = true
milestone_label.modulate.a = 1.0
milestone_label.scale = Vector2(0.6, 0.6)
flash.visible = true
flash.modulate.a = 0.18
var tween := create_tween()
tween.set_parallel(true)
tween.tween_property(milestone_label, "scale", Vector2(1.3, 1.3), 0.4).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)
tween.tween_property(milestone_label, "modulate:a", 0.0, 0.8).set_delay(0.6)
tween.tween_property(flash, "modulate:a", 0.0, 0.4)
tween.chain().tween_callback(func():
milestone_label.visible = false
flash.visible = false
)
func _make_label(text: String, position: Vector2, size: Vector2, font_size: int, color: Color) -> Label:
var label := Label.new()
label.text = text
label.position = position
label.size = size
label.add_theme_font_override("font", DISPLAY_FONT)
label.add_theme_font_size_override("font_size", font_size)
label.add_theme_color_override("font_color", color)
add_child(label)
return label
func _button_style(color: Color) -> StyleBoxFlat:
var style := StyleBoxFlat.new()
style.bg_color = color
style.border_color = Color("#9b6738")
style.set_border_width_all(3)
style.set_corner_radius_all(9)
return style