142 lines
5.2 KiB
GDScript
142 lines
5.2 KiB
GDScript
extends CanvasLayer
|
|
## Overlay condiviso per vittoria e game over.
|
|
|
|
signal reset_requested
|
|
|
|
var title_label: Label
|
|
var score_label: Label
|
|
var subtitle_label: Label
|
|
var card: Control
|
|
var reset_button: Button
|
|
|
|
|
|
func _ready() -> void:
|
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
|
visible = false
|
|
_build()
|
|
|
|
|
|
func _build() -> void:
|
|
var dim := ColorRect.new()
|
|
dim.color = Color(0.045, 0.018, 0.012, 0.76)
|
|
dim.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
dim.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
add_child(dim)
|
|
var center := CenterContainer.new()
|
|
center.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
add_child(center)
|
|
|
|
card = PanelContainer.new()
|
|
card.custom_minimum_size = Vector2(680, 510)
|
|
var frame := CircusTheme.flat_style(Color("#70411f"), Color("#edca69"), 6, 31)
|
|
frame.shadow_color = Color(0, 0, 0, 0.55)
|
|
frame.shadow_size = 22
|
|
frame.shadow_offset = Vector2(0, 9)
|
|
for side in [SIDE_LEFT, SIDE_RIGHT, SIDE_TOP, SIDE_BOTTOM]:
|
|
frame.set_content_margin(side, 10.0)
|
|
card.add_theme_stylebox_override("panel", frame)
|
|
center.add_child(card)
|
|
var wood := PanelContainer.new()
|
|
wood.add_theme_stylebox_override("panel", CircusTheme.wood_style())
|
|
card.add_child(wood)
|
|
var studs := BrassStuds.new()
|
|
studs.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
wood.add_child(studs)
|
|
var margin := MarginContainer.new()
|
|
margin.add_theme_constant_override("margin_left", 58)
|
|
margin.add_theme_constant_override("margin_right", 58)
|
|
margin.add_theme_constant_override("margin_top", 36)
|
|
margin.add_theme_constant_override("margin_bottom", 38)
|
|
wood.add_child(margin)
|
|
var content := VBoxContainer.new()
|
|
content.add_theme_constant_override("separation", 15)
|
|
content.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
margin.add_child(content)
|
|
_add_content(content)
|
|
|
|
|
|
func _add_content(parent: VBoxContainer) -> void:
|
|
var bunting := CircusTrim.new()
|
|
bunting.flag_count = 9
|
|
bunting.span = 360.0
|
|
bunting.custom_minimum_size = Vector2(0, 40)
|
|
parent.add_child(bunting)
|
|
title_label = _label(parent, "VITTORIA!", 68, Color("#ffe08a"))
|
|
title_label.add_theme_color_override("font_outline_color", Color("#713019"))
|
|
title_label.add_theme_constant_override("outline_size", 10)
|
|
subtitle_label = _label(parent, "Hai raggiunto il punteggio target!", 23, CircusTheme.INK)
|
|
|
|
var plaque := PanelContainer.new()
|
|
plaque.add_theme_stylebox_override("panel", CircusTheme.flat_style(Color("#f7e6bc"), Color("#9d6b29"), 3, 14))
|
|
var margin := MarginContainer.new()
|
|
margin.add_theme_constant_override("margin_left", 30)
|
|
margin.add_theme_constant_override("margin_right", 30)
|
|
margin.add_theme_constant_override("margin_top", 8)
|
|
margin.add_theme_constant_override("margin_bottom", 8)
|
|
plaque.add_child(margin)
|
|
score_label = _label(margin, "", 34, CircusTheme.INK)
|
|
parent.add_child(plaque)
|
|
|
|
reset_button = Button.new()
|
|
reset_button.text = "↻ RIGIOCA"
|
|
reset_button.custom_minimum_size = Vector2(250, 66)
|
|
reset_button.add_theme_font_override("font", CircusTheme.FONT)
|
|
reset_button.add_theme_font_size_override("font_size", 27)
|
|
reset_button.add_theme_color_override("font_color", Color("#fff1c7"))
|
|
reset_button.add_theme_stylebox_override("normal", CircusTheme.button_style(Color("#784121"), Color("#d9a947"), 5, 15))
|
|
reset_button.add_theme_stylebox_override("hover", CircusTheme.button_style(Color("#8e5129"), CircusTheme.BRASS_LIGHT, 5, 15))
|
|
reset_button.add_theme_stylebox_override("pressed", CircusTheme.button_style(Color("#5f311b"), Color("#b7832e"), 4, 15))
|
|
reset_button.pressed.connect(func(): reset_requested.emit())
|
|
parent.add_child(reset_button)
|
|
|
|
|
|
func _label(parent: Node, text: String, size: int, color: Color) -> Label:
|
|
var label := Label.new()
|
|
label.text = text
|
|
label.add_theme_font_override("font", CircusTheme.FONT)
|
|
label.add_theme_font_size_override("font_size", size)
|
|
label.add_theme_color_override("font_color", color)
|
|
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
parent.add_child(label)
|
|
return label
|
|
|
|
|
|
func show_victory(score: int) -> void:
|
|
_show_end(true, score)
|
|
|
|
|
|
func show_game_over(score: int) -> void:
|
|
_show_end(false, score)
|
|
|
|
|
|
func _show_end(victory: bool, score: int) -> void:
|
|
title_label.text = "VITTORIA!" if victory else "GAME OVER"
|
|
title_label.add_theme_color_override("font_color", Color("#ffe08a") if victory else Color("#f0b4b4"))
|
|
subtitle_label.text = "Hai raggiunto il punteggio target!" if victory else "Hai perso tutti i cuori... Ritenta!"
|
|
score_label.text = "Punteggio: %d" % score
|
|
visible = true
|
|
_animate_in()
|
|
|
|
|
|
func _animate_in() -> void:
|
|
card.modulate.a = 0.0
|
|
card.scale = Vector2(0.94, 0.94)
|
|
card.pivot_offset = card.size * 0.5
|
|
title_label.scale = Vector2(0.45, 0.45)
|
|
title_label.modulate.a = 0.0
|
|
score_label.modulate.a = 0.0
|
|
reset_button.modulate.a = 0.0
|
|
var tween := create_tween()
|
|
tween.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)
|
|
tween.set_parallel(true)
|
|
tween.tween_property(card, "modulate:a", 1.0, 0.22)
|
|
tween.tween_property(card, "scale", Vector2.ONE, 0.34)
|
|
tween.tween_property(title_label, "modulate:a", 1.0, 0.22).set_delay(0.12)
|
|
tween.tween_property(title_label, "scale", Vector2.ONE, 0.42).set_delay(0.10).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)
|
|
tween.tween_property(score_label, "modulate:a", 1.0, 0.35).set_delay(0.38)
|
|
tween.tween_property(reset_button, "modulate:a", 1.0, 0.35).set_delay(0.52)
|
|
|
|
|
|
func hide_victory() -> void:
|
|
visible = false
|