Guest Book: only open a card on a short stationary tap, ignore drags and flings, and guard the detail Close button after opening. Board: add a persisted double-tap placement mode with deferred single taps, while hold stays the default and right-click works in both modes.
193 lines
6.9 KiB
GDScript
193 lines
6.9 KiB
GDScript
extends Control
|
|
|
|
signal back_pressed
|
|
|
|
const BoardScene = preload("res://scenes/Board.tscn")
|
|
|
|
var tutorial_board: Board
|
|
var tutorial_status: Label
|
|
var checkin_body: Label
|
|
|
|
|
|
func _ready() -> void:
|
|
var margin := MarginContainer.new()
|
|
margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
margin.add_theme_constant_override("margin_left", 12)
|
|
margin.add_theme_constant_override("margin_right", 12)
|
|
margin.add_theme_constant_override("margin_top", UI.safe_top())
|
|
margin.add_theme_constant_override("margin_bottom", UI.safe_bottom())
|
|
add_child(margin)
|
|
|
|
var column := VBoxContainer.new()
|
|
column.add_theme_constant_override("separation", 6)
|
|
margin.add_child(column)
|
|
|
|
var top := HBoxContainer.new()
|
|
top.add_theme_constant_override("separation", 6)
|
|
column.add_child(top)
|
|
|
|
var back := UI.round_button("res://assets/icons/arrow-left.svg", 40)
|
|
back.pressed.connect(func() -> void: back_pressed.emit())
|
|
top.add_child(back)
|
|
|
|
var title := UI.label("House Rules", 22)
|
|
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
top.add_child(title)
|
|
|
|
var scroll := ScrollContainer.new()
|
|
scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
|
column.add_child(scroll)
|
|
|
|
var content := VBoxContainer.new()
|
|
content.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
content.add_theme_constant_override("separation", 6)
|
|
scroll.add_child(content)
|
|
|
|
content.add_child(_heading("Welcome to the Rat Hotel", 18))
|
|
content.add_child(_body("Crumb runs a small hotel for travelling rats. Every guest wants a room of their own — and a little space from the neighbours."))
|
|
|
|
content.add_child(_heading("The four house rules", 18))
|
|
content.add_child(_rule_row("One guest per room", "Each coloured room holds exactly one rat.", "region"))
|
|
content.add_child(_rule_row("One guest per floor", "Each row holds exactly one rat.", "row"))
|
|
content.add_child(_rule_row("One guest per corridor", "Each column holds exactly one rat.", "col"))
|
|
content.add_child(_rule_row("No shared walls or corners", "Rats cannot touch, not even diagonally.", "touch"))
|
|
|
|
content.add_child(_heading("Checking in", 18))
|
|
checkin_body = _body(_checkin_text())
|
|
content.add_child(checkin_body)
|
|
content.add_child(_body("Undo is unlimited. Hints are free and explain the next sensible move."))
|
|
|
|
content.add_child(_heading("Try a tiny room", 18))
|
|
content.add_child(_body("One guest is already checked in. Place the other four."))
|
|
|
|
var board_center := CenterContainer.new()
|
|
content.add_child(board_center)
|
|
tutorial_board = BoardScene.instantiate() as Board
|
|
tutorial_board.custom_minimum_size = Vector2(240, 240)
|
|
tutorial_board.solved.connect(_on_tutorial_solved)
|
|
board_center.add_child(tutorial_board)
|
|
|
|
var controls := HBoxContainer.new()
|
|
controls.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
controls.add_theme_constant_override("separation", 8)
|
|
content.add_child(controls)
|
|
|
|
var reset := UI.button("Reset", false, 44)
|
|
reset.custom_minimum_size = Vector2(100, 44)
|
|
reset.add_theme_font_size_override("font_size", 15)
|
|
reset.pressed.connect(_on_tutorial_reset)
|
|
controls.add_child(reset)
|
|
|
|
var hint := UI.button("Hint", true, 44)
|
|
hint.custom_minimum_size = Vector2(100, 44)
|
|
hint.add_theme_font_size_override("font_size", 15)
|
|
hint.pressed.connect(_on_tutorial_hint)
|
|
controls.add_child(hint)
|
|
|
|
tutorial_status = UI.label(UI.place_hint(), 10, Palette.MUTED)
|
|
content.add_child(tutorial_status)
|
|
SaveGame.settings_changed.connect(_refresh_hints)
|
|
|
|
content.add_child(_heading("Housekeeping tips", 18))
|
|
content.add_child(_body("Start with the smallest room. If a room's open cells all sit in one row, that row's guest belongs to that room. Every room has one solution and never requires guessing."))
|
|
|
|
content.add_child(_heading("Questions", 18))
|
|
content.add_child(_body("Why can't the rats touch? Every guest is a little grumpy after a long journey and wants their own space."))
|
|
content.add_child(_body("Why do some guests have gold rings? They checked in early. They are part of the puzzle, not a mistake."))
|
|
|
|
var tutorial := _load_tutorial()
|
|
if not tutorial.is_empty():
|
|
tutorial_board.set_level(tutorial)
|
|
|
|
|
|
func _body(text: String) -> Label:
|
|
var label := UI.label(text, 12, Palette.MUTED)
|
|
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
return label
|
|
|
|
|
|
func _heading(text: String, font_size: int = 18) -> Label:
|
|
var label := UI.heading(text, font_size)
|
|
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
return label
|
|
|
|
|
|
func _rule_row(title: String, body: String, mode: String) -> PanelContainer:
|
|
var panel := UI.panel(Palette.PAPER, 14, 7)
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 8)
|
|
panel.add_child(row)
|
|
|
|
var diagram := MiniDiagram.new()
|
|
diagram.mode = mode
|
|
diagram.custom_minimum_size = Vector2(72, 72)
|
|
row.add_child(diagram)
|
|
|
|
var text := VBoxContainer.new()
|
|
text.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
text.alignment = BoxContainer.ALIGNMENT_CENTER
|
|
text.add_theme_constant_override("separation", 0)
|
|
row.add_child(text)
|
|
|
|
var heading := UI.label(title, 14)
|
|
heading.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
text.add_child(heading)
|
|
|
|
var detail := UI.label(body, 10, Palette.MUTED)
|
|
detail.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
text.add_child(detail)
|
|
|
|
return panel
|
|
|
|
|
|
func _load_tutorial() -> Dictionary:
|
|
if not FileAccess.file_exists("res://data/tutorial.json"):
|
|
return {}
|
|
var file := FileAccess.open("res://data/tutorial.json", FileAccess.READ)
|
|
if file == null:
|
|
return {}
|
|
var parsed = JSON.parse_string(file.get_as_text())
|
|
file.close()
|
|
if typeof(parsed) == TYPE_DICTIONARY:
|
|
return parsed
|
|
return {}
|
|
|
|
|
|
func _checkin_text() -> String:
|
|
var place := "Double-tap or right-click to check a guest in."
|
|
if not bool(SaveGame.get_setting("double_tap_place")):
|
|
place = "Hold or right-click to check a guest in."
|
|
return "Tap or left-click to mark X. Tap an X or a guest to clear it. %s Gold-ringed guests are already in." % place
|
|
|
|
|
|
func _refresh_hints() -> void:
|
|
if checkin_body != null:
|
|
checkin_body.text = _checkin_text()
|
|
if tutorial_status != null and (
|
|
tutorial_status.text == "Tap = X · Hold or right-click = check in"
|
|
or tutorial_status.text == "Tap = X · Double-tap or right-click = check in"
|
|
):
|
|
tutorial_status.text = UI.place_hint()
|
|
|
|
|
|
func _on_tutorial_reset() -> void:
|
|
tutorial_board.restart()
|
|
tutorial_status.text = UI.place_hint()
|
|
tutorial_status.add_theme_color_override("font_color", Palette.MUTED)
|
|
|
|
|
|
func _on_tutorial_hint() -> void:
|
|
if tutorial_board.hint():
|
|
tutorial_status.text = "Crumb tapped the right room."
|
|
tutorial_status.add_theme_color_override("font_color", Palette.MUTED)
|
|
else:
|
|
tutorial_status.text = "Everyone is already checked in."
|
|
tutorial_status.add_theme_color_override("font_color", Palette.MUTED)
|
|
|
|
|
|
func _on_tutorial_solved() -> void:
|
|
tutorial_status.text = "Everyone checked in. Nicely done."
|
|
tutorial_status.add_theme_color_override("font_color", Palette.INK)
|