73 lines
2.5 KiB
GDScript
73 lines
2.5 KiB
GDScript
class_name P2AJuggleMenuScreen
|
|
extends Control
|
|
## P2a: schermata JuggleBoard composta dal mockup approvato.
|
|
## I controlli trasparenti mantengono input mouse e touch senza alterare la grafica.
|
|
|
|
signal back_requested
|
|
signal mode_requested
|
|
signal feedback_requested(frequency: float)
|
|
|
|
const MOCKUP := preload("res://menus/assets/p2a/p2a_menu_mockup.jpg")
|
|
|
|
var balls_count := 5
|
|
var count_patch: ColorRect
|
|
var count_label: Label
|
|
|
|
|
|
func _ready() -> void:
|
|
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_build()
|
|
|
|
|
|
func _build() -> void:
|
|
# Il mockup è la composizione grafica di riferimento: STRETCH_SCALE conserva
|
|
# posizione reciproca e proporzioni di tendone, titolo, barra e controlli.
|
|
var artwork := TextureRect.new()
|
|
artwork.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
artwork.texture = MOCKUP
|
|
artwork.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
artwork.stretch_mode = TextureRect.STRETCH_SCALE
|
|
artwork.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
artwork.material = MenuUI.submenu_lights_material()
|
|
add_child(artwork)
|
|
|
|
_add_hotspot(MenuUI.BACK_BUTTON_CENTER, MenuUI.BACK_BUTTON_SIZE, func(): back_requested.emit())
|
|
_add_hotspot(Vector2(0.775, 0.64), Vector2(0.07, 0.10), func(): _change_balls(-1))
|
|
_add_hotspot(Vector2(0.895, 0.64), Vector2(0.07, 0.10), func(): _change_balls(1))
|
|
_add_hotspot(Vector2(0.79, 0.88), Vector2(0.30, 0.14), _start_game)
|
|
_build_dynamic_count()
|
|
|
|
|
|
func _add_hotspot(center: Vector2, normalized_size: Vector2, action: Callable) -> void:
|
|
var hotspot := MenuUI.add_hotspot(self, center, normalized_size)
|
|
hotspot.tooltip_text = ""
|
|
hotspot.pressed.connect(func(): action.call())
|
|
|
|
|
|
func _build_dynamic_count() -> void:
|
|
count_patch = ColorRect.new()
|
|
count_patch.color = Color(1.0, 1.0, 1.0, 0.96)
|
|
count_patch.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
count_patch.visible = false
|
|
add_child(count_patch)
|
|
MenuUI.set_normalized_rect(count_patch, Vector2(0.835, 0.64), Vector2(0.055, 0.09))
|
|
|
|
count_label = MenuUI.add_label(self, str(balls_count), Vector2(0.835, 0.64), Vector2(0.055, 0.09), 32)
|
|
count_label.visible = false
|
|
|
|
|
|
func _change_balls(delta: int) -> void:
|
|
balls_count = clampi(balls_count + delta, 1, 5)
|
|
count_patch.visible = true
|
|
count_label.visible = true
|
|
count_label.text = str(balls_count)
|
|
feedback_requested.emit(440.0 + 45.0 * balls_count)
|
|
|
|
|
|
func _start_game() -> void:
|
|
# Senza selettore: il menu P2A apre sempre la partita Target standard.
|
|
Settings.game_mode = 0
|
|
Settings.save_settings()
|
|
feedback_requested.emit(784.0)
|
|
mode_requested.emit()
|