Files
autgame/scripts/victory_overlay.gd
T

225 lines
8.6 KiB
GDScript

extends CanvasLayer
## Overlay di vittoria: appare quando si raggiunge il punteggio target.
signal reset_requested
const DISPLAY_FONT := preload("res://assets/fonts/NotoSerifDisplay-CondensedExtraBold.ttf")
const WOOD_TEXTURE := preload("res://assets/wood_board_rounded.png")
const INK := Color("#482615")
const BRASS := Color("#d5a83f")
const BRASS_LIGHT := Color("#f6d77a")
var title_label: Label
var score_label: Label
var subtitle_label: Label
var _card: Control
var _reset_button: Button
class CircusTrim extends Control:
func _ready() -> void:
mouse_filter = Control.MOUSE_FILTER_IGNORE
queue_redraw()
func _draw() -> void:
var flag_colors := [Color("#a93334"), Color("#d8a83e"), Color("#397b76")]
var count := 9
var start_x := (size.x - 360.0) * 0.5
draw_line(Vector2(start_x - 8, 11), Vector2(start_x + 368, 11), Color("#59301c"), 3.0, true)
for i in count:
var x := start_x + i * 45.0
var points := PackedVector2Array([Vector2(x, 10), Vector2(x + 34, 10), Vector2(x + 17, 35)])
draw_colored_polygon(points, flag_colors[i % flag_colors.size()])
draw_polyline(PackedVector2Array([points[0], points[1], points[2], points[0]]), Color("#6b341c"), 2.0, true)
class BrassStuds extends Control:
func _ready() -> void:
mouse_filter = Control.MOUSE_FILTER_IGNORE
queue_redraw()
func _draw() -> void:
for p in [Vector2(22, 22), Vector2(size.x - 22, 22), Vector2(22, size.y - 22), Vector2(size.x - 22, size.y - 22)]:
draw_circle(p + Vector2(1.5, 2.5), 8.0, Color(0.12, 0.05, 0.02, 0.45))
draw_circle(p, 8.0, Color("#b17b24"))
draw_circle(p - Vector2(2, 2), 4.5, Color("#f6d77a"))
draw_line(p - Vector2(3, 0), p + Vector2(3, 0), Color("#765018"), 1.5, true)
func _ready() -> void:
process_mode = Node.PROCESS_MODE_ALWAYS
visible = false
_build()
func _wood_style() -> StyleBoxTexture:
var style := StyleBoxTexture.new()
style.texture = WOOD_TEXTURE
style.texture_margin_left = 35.0
style.texture_margin_right = 35.0
style.texture_margin_top = 35.0
style.texture_margin_bottom = 35.0
return style
func _flat_style(color: Color, border: Color, width: int, radius: int) -> StyleBoxFlat:
var style := StyleBoxFlat.new()
style.bg_color = color
style.border_color = border
style.set_border_width_all(width)
style.set_corner_radius_all(radius)
return style
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 := _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)
frame.content_margin_left = 10
frame.content_margin_right = 10
frame.content_margin_top = 10
frame.content_margin_bottom = 10
_card.add_theme_stylebox_override("panel", frame)
center.add_child(_card)
var wood := PanelContainer.new()
wood.add_theme_stylebox_override("panel", _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 vb := VBoxContainer.new()
vb.add_theme_constant_override("separation", 15)
vb.alignment = BoxContainer.ALIGNMENT_CENTER
margin.add_child(vb)
var bunting := CircusTrim.new()
bunting.custom_minimum_size = Vector2(0, 40)
vb.add_child(bunting)
title_label = Label.new()
title_label.text = "VITTORIA!"
title_label.add_theme_font_override("font", DISPLAY_FONT)
title_label.add_theme_font_size_override("font_size", 68)
title_label.add_theme_color_override("font_color", Color("#ffe08a"))
title_label.add_theme_color_override("font_outline_color", Color("#713019"))
title_label.add_theme_constant_override("outline_size", 10)
title_label.add_theme_color_override("font_shadow_color", Color(0.9, 0.58, 0.12, 0.42))
title_label.add_theme_constant_override("shadow_offset_x", 0)
title_label.add_theme_constant_override("shadow_offset_y", 4)
title_label.add_theme_constant_override("shadow_outline_size", 14)
title_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
vb.add_child(title_label)
subtitle_label = Label.new()
subtitle_label.text = "Hai raggiunto il punteggio target!"
subtitle_label.add_theme_font_override("font", DISPLAY_FONT)
subtitle_label.add_theme_font_size_override("font_size", 23)
subtitle_label.add_theme_color_override("font_color", INK)
subtitle_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
vb.add_child(subtitle_label)
var score_plaque := PanelContainer.new()
score_plaque.add_theme_stylebox_override("panel", _flat_style(Color("#f7e6bc"), Color("#9d6b29"), 3, 14))
var score_margin := MarginContainer.new()
score_margin.add_theme_constant_override("margin_left", 30)
score_margin.add_theme_constant_override("margin_right", 30)
score_margin.add_theme_constant_override("margin_top", 8)
score_margin.add_theme_constant_override("margin_bottom", 8)
score_plaque.add_child(score_margin)
score_label = Label.new()
score_label.add_theme_font_override("font", DISPLAY_FONT)
score_label.add_theme_font_size_override("font_size", 34)
score_label.add_theme_color_override("font_color", INK)
score_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
score_margin.add_child(score_label)
vb.add_child(score_plaque)
_reset_button = Button.new()
_reset_button.text = "↻ RIGIOCA"
_reset_button.custom_minimum_size = Vector2(250, 66)
_reset_button.add_theme_font_override("font", DISPLAY_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_color_override("font_hover_color", Color.WHITE)
_reset_button.add_theme_stylebox_override("normal", _button_style(Color("#784121"), Color("#d9a947"), 5))
_reset_button.add_theme_stylebox_override("hover", _button_style(Color("#8e5129"), BRASS_LIGHT, 5))
_reset_button.add_theme_stylebox_override("pressed", _button_style(Color("#5f311b"), Color("#b7832e"), 4))
_reset_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
_reset_button.pressed.connect(func(): reset_requested.emit())
vb.add_child(_reset_button)
func _button_style(color: Color, border: Color, width: int) -> StyleBoxFlat:
var style := _flat_style(color, border, width, 15)
style.shadow_color = Color(0.14, 0.05, 0.02, 0.48)
style.shadow_size = 6
style.shadow_offset = Vector2(0, 4)
return style
func show_victory(score: int) -> void:
show_end("victory", score)
func show_game_over(score: int) -> void:
show_end("gameover", score)
func show_end(kind: String, score: int) -> void:
var victory := kind == "victory"
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
_card.modulate.a = 0.0
_card.scale = Vector2(0.94, 0.94)
_card.pivot_offset = _card.size * 0.5
title_label.pivot_offset = title_label.size * 0.5
title_label.scale = Vector2(0.45, 0.45)
title_label.rotation = deg_to_rad(-3.0)
title_label.modulate.a = 0.0
score_label.modulate.a = 0.0
_reset_button.modulate.a = 0.0
var tw := create_tween()
tw.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)
tw.set_parallel(true)
tw.tween_property(_card, "modulate:a", 1.0, 0.22)
tw.tween_property(_card, "scale", Vector2.ONE, 0.34).set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_OUT)
tw.tween_property(title_label, "modulate:a", 1.0, 0.22).set_delay(0.12)
tw.tween_property(title_label, "scale", Vector2(1.08, 1.08), 0.42).set_delay(0.10).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)
tw.tween_property(title_label, "rotation", deg_to_rad(1.0), 0.42).set_delay(0.10).set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_OUT)
tw.tween_property(score_label, "modulate:a", 1.0, 0.35).set_delay(0.38)
tw.tween_property(_reset_button, "modulate:a", 1.0, 0.35).set_delay(0.52)
tw.chain().tween_property(title_label, "scale", Vector2.ONE, 0.18).set_trans(Tween.TRANS_SINE)
tw.parallel().tween_property(title_label, "rotation", 0.0, 0.18).set_trans(Tween.TRANS_SINE)
func hide_victory() -> void:
visible = false