Files
Ratdoku/scripts/SettingsSheet.gd
T

301 lines
9.1 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 game_actions: HBoxContainer
var reset_row: Control
var resume_button: Button
var restart_dialog: ConfirmationDialog
var reset_dialog: ConfirmationDialog
var reset_status: Label
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_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)
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))
restart_dialog = ConfirmationDialog.new()
restart_dialog.title = "Restart room?"
restart_dialog.dialog_text = "This clears the current board and timer."
restart_dialog.confirmed.connect(func() -> void: restart_requested.emit())
add_child(restart_dialog)
reset_dialog = ConfirmationDialog.new()
reset_dialog.title = "Reset progress?"
reset_dialog.dialog_text = "This clears completed rooms and unlocked guests. Settings stay."
reset_dialog.confirmed.connect(_on_reset_confirmed)
add_child(reset_dialog)
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
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))
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)
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 _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:
restart_dialog.popup_centered()
func _on_lobby() -> void:
visible = false
lobby_requested.emit()
func _on_reset() -> void:
reset_dialog.popup_centered()
func _on_reset_confirmed() -> void:
SaveGame.reset_progress()
reset_status.text = "Progress reset."
reset_status.add_theme_color_override("font_color", Palette.INK)