Replaced native confirmation dialogs with an in-app card using app colours, fonts, wrapped body text, and full-width Cancel/destructive buttons. Tapping outside cancels. Added UI QA coverage and a reset-dialog screenshot.
424 lines
13 KiB
GDScript
424 lines
13 KiB
GDScript
extends Control
|
||
|
||
signal closed
|
||
signal restart_requested
|
||
signal lobby_requested
|
||
signal rules_requested
|
||
|
||
var game_mode := false
|
||
var toggles := {}
|
||
var hold_slider: HSlider
|
||
var hold_value: Label
|
||
var hold_panel: PanelContainer
|
||
var game_actions: HBoxContainer
|
||
var reset_row: Control
|
||
var resume_button: Button
|
||
var reset_status: Label
|
||
|
||
var confirm_layer: ColorRect
|
||
var confirm_title: Label
|
||
var confirm_body: Label
|
||
var confirm_button: Button
|
||
var confirm_callback := Callable()
|
||
|
||
|
||
func _ready() -> void:
|
||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
mouse_filter = Control.MOUSE_FILTER_STOP
|
||
visible = false
|
||
|
||
var scrim := ColorRect.new()
|
||
scrim.color = Color(0.18, 0.12, 0.08, 0.55)
|
||
scrim.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
scrim.mouse_filter = Control.MOUSE_FILTER_STOP
|
||
scrim.gui_input.connect(_on_scrim_input)
|
||
add_child(scrim)
|
||
|
||
var panel := PanelContainer.new()
|
||
panel.anchor_left = 0.0
|
||
panel.anchor_right = 1.0
|
||
panel.anchor_top = 1.0
|
||
panel.anchor_bottom = 1.0
|
||
panel.offset_top = -610
|
||
panel.offset_bottom = -UI.safe_bottom()
|
||
panel.offset_left = 0
|
||
panel.offset_right = 0
|
||
var style := StyleBoxFlat.new()
|
||
style.bg_color = Palette.CREAM
|
||
style.corner_radius_top_left = 26
|
||
style.corner_radius_top_right = 26
|
||
style.content_margin_left = 16
|
||
style.content_margin_right = 16
|
||
style.content_margin_top = 12
|
||
style.content_margin_bottom = 16
|
||
style.shadow_color = Color(0.18, 0.12, 0.08, 0.24)
|
||
style.shadow_size = 10
|
||
panel.add_theme_stylebox_override("panel", style)
|
||
add_child(panel)
|
||
|
||
var column := VBoxContainer.new()
|
||
column.add_theme_constant_override("separation", 8)
|
||
panel.add_child(column)
|
||
|
||
var header := HBoxContainer.new()
|
||
header.add_theme_constant_override("separation", 8)
|
||
column.add_child(header)
|
||
|
||
var title := UI.label("Settings", 24)
|
||
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
header.add_child(title)
|
||
|
||
var close := UI.button("×", false, 36)
|
||
close.custom_minimum_size = Vector2(42, 36)
|
||
close.add_theme_font_size_override("font_size", 24)
|
||
close.pressed.connect(_close)
|
||
header.add_child(close)
|
||
|
||
var scroll := ScrollContainer.new()
|
||
scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||
column.add_child(scroll)
|
||
|
||
var list := VBoxContainer.new()
|
||
list.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
list.add_theme_constant_override("separation", 8)
|
||
scroll.add_child(list)
|
||
|
||
_add_pattern_row(list)
|
||
_add_toggle(list, "Show timer", "Keep the clock visible while you solve.", "show_timer")
|
||
_add_toggle(list, "Reduce motion", "Stop the bob and placement pop.", "reduce_motion")
|
||
_add_toggle(list, "Double-tap to place", "Tap = mark · double-tap = check in.", "double_tap_place")
|
||
_add_hold_row(list)
|
||
|
||
list.add_child(UI.spacer(2))
|
||
var rules := UI.button("How to play", false, 44)
|
||
rules.add_theme_font_size_override("font_size", 15)
|
||
rules.pressed.connect(func() -> void: rules_requested.emit())
|
||
list.add_child(rules)
|
||
|
||
reset_row = _action_row("Reset progress", "Clear completed rooms and unlocked guests.", Palette.RED, _on_reset)
|
||
list.add_child(reset_row)
|
||
|
||
reset_status = UI.label("", 10, Palette.MUTED)
|
||
list.add_child(reset_status)
|
||
|
||
# Let swipes reach the sheet's ScrollContainer even when they start on a
|
||
# label, toggle, or button.
|
||
UI.pass_scroll_input(list)
|
||
|
||
game_actions = HBoxContainer.new()
|
||
game_actions.add_theme_constant_override("separation", 6)
|
||
column.add_child(game_actions)
|
||
|
||
var restart := UI.button("Restart", false, 40)
|
||
restart.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
restart.add_theme_font_size_override("font_size", 14)
|
||
restart.add_theme_color_override("font_color", Palette.RED)
|
||
restart.pressed.connect(_on_restart)
|
||
game_actions.add_child(restart)
|
||
|
||
var lobby := UI.button("Lobby", false, 40)
|
||
lobby.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
lobby.add_theme_font_size_override("font_size", 14)
|
||
lobby.pressed.connect(_on_lobby)
|
||
game_actions.add_child(lobby)
|
||
|
||
var resume := UI.button("Resume", true, 52)
|
||
resume.pressed.connect(_close)
|
||
resume_button = resume
|
||
column.add_child(resume)
|
||
|
||
column.add_child(UI.label(Version.BUILD_LABEL, 9, Palette.MUTED))
|
||
|
||
_build_confirm()
|
||
|
||
|
||
func _build_confirm() -> void:
|
||
confirm_layer = ColorRect.new()
|
||
confirm_layer.color = Color(0.18, 0.12, 0.08, 0.62)
|
||
confirm_layer.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
confirm_layer.mouse_filter = Control.MOUSE_FILTER_STOP
|
||
confirm_layer.gui_input.connect(_on_confirm_scrim_input)
|
||
confirm_layer.visible = false
|
||
add_child(confirm_layer)
|
||
|
||
var center := CenterContainer.new()
|
||
center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
center.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||
confirm_layer.add_child(center)
|
||
|
||
var panel := UI.panel(Palette.CREAM, 24, 16)
|
||
var max_width: int = max(240, int(get_viewport_rect().size.x) - 32)
|
||
panel.custom_minimum_size = Vector2(min(320, max_width), 0)
|
||
panel.mouse_filter = Control.MOUSE_FILTER_STOP
|
||
center.add_child(panel)
|
||
|
||
var box := VBoxContainer.new()
|
||
box.add_theme_constant_override("separation", 10)
|
||
panel.add_child(box)
|
||
|
||
confirm_title = UI.heading("Reset progress?", 20)
|
||
confirm_title.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
box.add_child(confirm_title)
|
||
|
||
confirm_body = UI.label("", 13, Palette.MUTED)
|
||
confirm_body.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
box.add_child(confirm_body)
|
||
|
||
var actions := HBoxContainer.new()
|
||
actions.add_theme_constant_override("separation", 8)
|
||
box.add_child(actions)
|
||
|
||
var cancel := UI.button("Cancel", false, 46)
|
||
cancel.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
cancel.pressed.connect(_hide_confirm)
|
||
actions.add_child(cancel)
|
||
|
||
confirm_button = UI.button("Reset", false, 46)
|
||
confirm_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
_apply_red_style(confirm_button)
|
||
confirm_button.pressed.connect(_on_confirm_pressed)
|
||
actions.add_child(confirm_button)
|
||
|
||
|
||
func _apply_red_style(button: Button) -> void:
|
||
button.add_theme_stylebox_override("normal", _red_box(Palette.RED))
|
||
button.add_theme_stylebox_override("hover", _red_box(Palette.RED.lightened(0.07)))
|
||
button.add_theme_stylebox_override("pressed", _red_box(Palette.RED.darkened(0.10)))
|
||
button.add_theme_stylebox_override("focus", _red_box(Palette.RED))
|
||
button.add_theme_color_override("font_color", Palette.WHITE)
|
||
button.add_theme_color_override("font_hover_color", Palette.WHITE)
|
||
button.add_theme_color_override("font_pressed_color", Palette.WHITE)
|
||
button.add_theme_color_override("font_focus_color", Palette.WHITE)
|
||
|
||
|
||
func _red_box(color: Color) -> StyleBoxFlat:
|
||
var style := StyleBoxFlat.new()
|
||
style.bg_color = color
|
||
style.corner_radius_top_left = 26
|
||
style.corner_radius_top_right = 26
|
||
style.corner_radius_bottom_left = 26
|
||
style.corner_radius_bottom_right = 26
|
||
style.content_margin_left = 16
|
||
style.content_margin_right = 16
|
||
style.content_margin_top = 10
|
||
style.content_margin_bottom = 10
|
||
return style
|
||
|
||
|
||
func open_sheet(mode: String) -> void:
|
||
game_mode = mode == "game"
|
||
game_actions.visible = game_mode
|
||
reset_row.visible = not game_mode
|
||
reset_status.visible = not game_mode
|
||
resume_button.text = "Resume" if game_mode else "Close"
|
||
refresh()
|
||
visible = true
|
||
move_to_front()
|
||
|
||
|
||
func refresh() -> void:
|
||
for key in toggles:
|
||
toggles[key].button_pressed = bool(SaveGame.get_setting(key))
|
||
if hold_slider != null:
|
||
hold_slider.set_value_no_signal(float(SaveGame.get_setting("hold_seconds")))
|
||
hold_value.text = "%.2f s" % hold_slider.value
|
||
_update_hold_availability()
|
||
|
||
|
||
func _add_pattern_row(parent: VBoxContainer) -> void:
|
||
var panel := UI.panel(Palette.PAPER, 14, 8)
|
||
var row := HBoxContainer.new()
|
||
row.add_theme_constant_override("separation", 8)
|
||
panel.add_child(row)
|
||
|
||
var icon := UI.icon("res://assets/icons/leaf.svg", 18, Palette.INK)
|
||
row.add_child(icon)
|
||
|
||
var label := UI.label("Room patterns", 15)
|
||
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
row.add_child(label)
|
||
|
||
var check := CheckButton.new()
|
||
check.button_pressed = bool(SaveGame.get_setting("patterns"))
|
||
check.toggled.connect(func(on: bool) -> void: SaveGame.set_setting("patterns", on))
|
||
row.add_child(check)
|
||
toggles["patterns"] = check
|
||
parent.add_child(panel)
|
||
|
||
|
||
func _add_toggle(parent: VBoxContainer, title: String, detail: String, key: String) -> void:
|
||
var panel := UI.panel(Palette.PAPER, 14, 8)
|
||
var row := HBoxContainer.new()
|
||
row.add_theme_constant_override("separation", 8)
|
||
panel.add_child(row)
|
||
|
||
var text := VBoxContainer.new()
|
||
text.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
text.add_theme_constant_override("separation", 0)
|
||
row.add_child(text)
|
||
|
||
var label := UI.label(title, 14)
|
||
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
text.add_child(label)
|
||
|
||
var sub := UI.label(detail, 10, Palette.MUTED)
|
||
sub.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
text.add_child(sub)
|
||
|
||
var check := CheckButton.new()
|
||
check.button_pressed = bool(SaveGame.get_setting(key))
|
||
check.toggled.connect(func(on: bool) -> void:
|
||
SaveGame.set_setting(key, on)
|
||
_update_hold_availability()
|
||
)
|
||
row.add_child(check)
|
||
toggles[key] = check
|
||
parent.add_child(panel)
|
||
|
||
|
||
func _add_hold_row(parent: VBoxContainer) -> void:
|
||
var panel := UI.panel(Palette.PAPER, 14, 8)
|
||
hold_panel = panel
|
||
var column := VBoxContainer.new()
|
||
column.add_theme_constant_override("separation", 2)
|
||
panel.add_child(column)
|
||
|
||
var label := UI.label("Hold time", 14)
|
||
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
column.add_child(label)
|
||
|
||
var sub := UI.label("How long to press before checking in.", 10, Palette.MUTED)
|
||
sub.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
column.add_child(sub)
|
||
|
||
var row := HBoxContainer.new()
|
||
row.add_theme_constant_override("separation", 8)
|
||
column.add_child(row)
|
||
|
||
hold_slider = HSlider.new()
|
||
hold_slider.min_value = 0.20
|
||
hold_slider.max_value = 0.50
|
||
hold_slider.step = 0.05
|
||
hold_slider.value = float(SaveGame.get_setting("hold_seconds"))
|
||
hold_slider.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
hold_slider.value_changed.connect(_on_hold_changed)
|
||
row.add_child(hold_slider)
|
||
|
||
hold_value = UI.label("%.2f s" % hold_slider.value, 11, Palette.MUTED)
|
||
hold_value.custom_minimum_size = Vector2(46, 0)
|
||
row.add_child(hold_value)
|
||
|
||
parent.add_child(panel)
|
||
|
||
|
||
func _action_row(title: String, detail: String, color: Color, callback: Callable) -> Control:
|
||
var panel := UI.panel(Palette.PAPER, 14, 8)
|
||
var row := HBoxContainer.new()
|
||
row.add_theme_constant_override("separation", 8)
|
||
panel.add_child(row)
|
||
|
||
var text := VBoxContainer.new()
|
||
text.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
text.add_theme_constant_override("separation", 0)
|
||
row.add_child(text)
|
||
|
||
var label := UI.label(title, 14, color)
|
||
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
text.add_child(label)
|
||
|
||
var sub := UI.label(detail, 10, Palette.MUTED)
|
||
sub.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
text.add_child(sub)
|
||
|
||
var go := UI.button("›", false, 34)
|
||
go.custom_minimum_size = Vector2(38, 34)
|
||
go.add_theme_font_size_override("font_size", 18)
|
||
go.pressed.connect(callback)
|
||
row.add_child(go)
|
||
|
||
return panel
|
||
|
||
|
||
func _on_hold_changed(value: float) -> void:
|
||
var snapped: float = snapped(value, 0.05)
|
||
hold_value.text = "%.2f s" % snapped
|
||
SaveGame.set_setting("hold_seconds", snapped)
|
||
|
||
|
||
func _update_hold_availability() -> void:
|
||
if hold_slider == null or hold_panel == null:
|
||
return
|
||
var enabled := not bool(SaveGame.get_setting("double_tap_place"))
|
||
hold_slider.editable = enabled
|
||
hold_slider.mouse_filter = Control.MOUSE_FILTER_PASS if enabled else Control.MOUSE_FILTER_IGNORE
|
||
hold_panel.modulate = Color(1, 1, 1, 1.0 if enabled else 0.45)
|
||
|
||
|
||
func _on_scrim_input(event: InputEvent) -> void:
|
||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||
_close()
|
||
|
||
|
||
func _close() -> void:
|
||
visible = false
|
||
closed.emit()
|
||
|
||
|
||
func _on_restart() -> void:
|
||
_show_confirm(
|
||
"Restart room?",
|
||
"This clears the current board and timer.",
|
||
"Restart",
|
||
func() -> void: restart_requested.emit()
|
||
)
|
||
|
||
|
||
func _on_lobby() -> void:
|
||
visible = false
|
||
lobby_requested.emit()
|
||
|
||
|
||
func _on_reset() -> void:
|
||
_show_confirm(
|
||
"Reset progress?",
|
||
"This clears completed rooms and unlocked guests. Settings stay.",
|
||
"Reset",
|
||
_on_reset_confirmed
|
||
)
|
||
|
||
|
||
func _show_confirm(title: String, body: String, action: String, callback: Callable) -> void:
|
||
confirm_title.text = title
|
||
confirm_body.text = body
|
||
confirm_button.text = action
|
||
confirm_callback = callback
|
||
confirm_layer.visible = true
|
||
confirm_layer.move_to_front()
|
||
|
||
|
||
func _hide_confirm() -> void:
|
||
confirm_layer.visible = false
|
||
confirm_callback = Callable()
|
||
|
||
|
||
func _on_confirm_scrim_input(event: InputEvent) -> void:
|
||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||
_hide_confirm()
|
||
|
||
|
||
func _on_confirm_pressed() -> void:
|
||
var callback := confirm_callback
|
||
_hide_confirm()
|
||
if callback.is_valid():
|
||
callback.call()
|
||
|
||
|
||
func _on_reset_confirmed() -> void:
|
||
SaveGame.reset_progress()
|
||
reset_status.text = "Progress reset."
|
||
reset_status.add_theme_color_override("font_color", Palette.INK)
|