Release v0.2: refine menus and JuggleBoard
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
class_name JuggleBoardHud
|
||||
extends CanvasLayer
|
||||
## HUD del JuggleBoard: costruzione e aggiornamenti visuali.
|
||||
## HUD P2B: bersaglio e cartigli sul pannello laterale illustrato.
|
||||
|
||||
signal options_requested
|
||||
signal back_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")
|
||||
const BACK_BUTTON_ART := preload("res://menus/assets/common/pulsante_indietro.png")
|
||||
|
||||
var target_dot: Node2D
|
||||
var score_label: Label
|
||||
@@ -16,6 +17,7 @@ var help_label: Label
|
||||
var milestone_label: Label
|
||||
var flash: ColorRect
|
||||
var hearts: Node2D
|
||||
var back_button: TextureButton
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -23,56 +25,41 @@ func _ready() -> void:
|
||||
|
||||
|
||||
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
|
||||
var ink := Color("#251b17")
|
||||
|
||||
# Node2D ha pivot locale (0, 0); target_dot disegna l'asset simmetricamente
|
||||
# intorno a quel pivot, quindi si usa il centro misurato della cornice P2B.
|
||||
target_dot = TARGET_SCRIPT.new()
|
||||
target_dot.position = Vector2(430, 78)
|
||||
target_dot.position = JuggleBoardConfig.TARGET_CENTER
|
||||
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
|
||||
back_button = _make_back_button()
|
||||
add_child(back_button)
|
||||
|
||||
score_label = _make_label("", Vector2(925, 34), Vector2(245, 48), 36, ink)
|
||||
score_label = _make_label("", Vector2(112, 520), Vector2(220, 45), 25, ink)
|
||||
score_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
combo_label = _make_label("", Vector2(925, 80), Vector2(245, 34), 21, ink)
|
||||
score_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
combo_label = _make_label("", Vector2(112, 606), Vector2(220, 45), 24, ink)
|
||||
combo_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
combo_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
|
||||
hearts = HEARTS_SCRIPT.new()
|
||||
hearts.position = Vector2(121, 99)
|
||||
hearts.position = Vector2(84, 655)
|
||||
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)
|
||||
# Le opzioni restano accessibili da Esc per non introdurre elementi estranei
|
||||
# al mockup P2B; il lock adulto e la persistenza delle impostazioni non cambiano.
|
||||
help_label = _make_label("", Vector2.ZERO, Vector2.ZERO, 1, ink)
|
||||
help_label.visible = false
|
||||
|
||||
milestone_label = _make_label("", Vector2(0, 160), Vector2(JuggleBoardConfig.VIEW.x, 120), 56, Color(0.8, 0.55, 0.1))
|
||||
milestone_label = _make_label("", Vector2(350, 20), Vector2(820, 80), 46, Color("#9e5420"))
|
||||
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.color = Color(1, 0.95, 0.72)
|
||||
flash.position = Vector2.ZERO
|
||||
flash.size = JuggleBoardConfig.VIEW
|
||||
flash.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
@@ -81,16 +68,41 @@ func _build() -> void:
|
||||
add_child(flash)
|
||||
|
||||
|
||||
func _make_back_button() -> TextureButton:
|
||||
var button := TextureButton.new()
|
||||
button.texture_normal = BACK_BUTTON_ART
|
||||
button.texture_hover = BACK_BUTTON_ART
|
||||
button.texture_pressed = BACK_BUTTON_ART
|
||||
button.ignore_texture_size = true
|
||||
button.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
||||
button.tooltip_text = "Torna al menu Juggle"
|
||||
# Margine sicuro relativo, uguale al bordo utile dei controlli nei menu.
|
||||
# Ancore coincidenti: gli offset definiscono soltanto la dimensione del tasto.
|
||||
button.set_anchors_preset(Control.PRESET_TOP_LEFT)
|
||||
button.anchor_left = 0.03
|
||||
button.anchor_top = 0.06
|
||||
button.anchor_right = 0.03
|
||||
button.anchor_bottom = 0.06
|
||||
button.offset_left = 0.0
|
||||
button.offset_top = 0.0
|
||||
button.offset_right = 76.0
|
||||
button.offset_bottom = 64.0
|
||||
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
button.mouse_entered.connect(func(): button.modulate = Color(1.10, 1.10, 1.10, 1.0))
|
||||
button.mouse_exited.connect(func(): button.modulate = Color.WHITE)
|
||||
button.pressed.connect(func(): back_requested.emit())
|
||||
return button
|
||||
|
||||
|
||||
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)
|
||||
score_label.text = "punteggio %03d" % score
|
||||
combo_label.text = "livello %d" % (1 + int(score / 1000))
|
||||
|
||||
|
||||
func set_target(color: Color, shown: bool = true) -> void:
|
||||
@@ -103,12 +115,10 @@ 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
|
||||
flash.modulate.a = 0.16
|
||||
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():
|
||||
@@ -125,14 +135,6 @@ func _make_label(text: String, position: Vector2, size: Vector2, font_size: int,
|
||||
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)
|
||||
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user