Clears free mode when starting campaign/daily rooms, rebuilds levels on restore, fixes free win label, makes event claims cycle-aware and event schedule local-day based, grants VIBRATE permission, validates corrupt save values, and fixes Home scrolling, Guest Book close button, event claim contrast, achievement contrast, and difficulty modal spacing. Adds QA for these paths.
402 lines
13 KiB
GDScript
402 lines
13 KiB
GDScript
extends Control
|
||
|
||
signal play_pressed
|
||
signal guest_book_pressed
|
||
signal settings_pressed
|
||
signal rules_pressed
|
||
signal daily_pressed
|
||
signal profile_pressed
|
||
signal streak_pressed
|
||
signal freeplay_pressed
|
||
|
||
var progress_pill: Button
|
||
var primary: Button
|
||
var hint_label: Label
|
||
var mascot_caption: Label
|
||
var daily_button: Button
|
||
var freeplay_button: Button
|
||
var streak_button: Button
|
||
var event_button: Button
|
||
var event_layer: ColorRect
|
||
var event_title: Label
|
||
var event_body: Label
|
||
var event_progress: Label
|
||
var event_claim: Button
|
||
var mascot_card: PanelContainer
|
||
var mascot_art: Control
|
||
var mascot_button: Button
|
||
var mascot_note: Label
|
||
var mascot_id := ""
|
||
var mascot_art_id := ""
|
||
var mascot_cycling := false
|
||
var avatar_holder: CenterContainer
|
||
var avatar_frame_id := ""
|
||
var avatar_portrait_id := ""
|
||
|
||
|
||
func _ready() -> void:
|
||
var margin := MarginContainer.new()
|
||
margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
margin.add_theme_constant_override("margin_left", UI.MARGIN)
|
||
margin.add_theme_constant_override("margin_right", UI.MARGIN)
|
||
margin.add_theme_constant_override("margin_top", UI.safe_top())
|
||
margin.add_theme_constant_override("margin_bottom", UI.safe_bottom())
|
||
add_child(margin)
|
||
|
||
var scroll := ScrollContainer.new()
|
||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||
margin.add_child(scroll)
|
||
var column := VBoxContainer.new()
|
||
column.add_theme_constant_override("separation", 6)
|
||
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
scroll.add_child(column)
|
||
|
||
var hub := HBoxContainer.new()
|
||
hub.add_theme_constant_override("separation", 0)
|
||
column.add_child(hub)
|
||
|
||
var left := CenterContainer.new()
|
||
left.custom_minimum_size = Vector2(56, 56)
|
||
avatar_holder = left
|
||
hub.add_child(left)
|
||
_build_avatar()
|
||
|
||
var center := CenterContainer.new()
|
||
center.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
hub.add_child(center)
|
||
|
||
progress_pill = UI.button("5 / 25 guests", false, 38)
|
||
progress_pill.custom_minimum_size = Vector2(130, 38)
|
||
UI.set_font_size(progress_pill, 13)
|
||
progress_pill.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||
progress_pill.pressed.connect(func() -> void: guest_book_pressed.emit())
|
||
center.add_child(progress_pill)
|
||
|
||
var settings := UI.round_button("res://assets/icons/settings.svg", 48)
|
||
settings.tooltip_text = "Settings"
|
||
settings.pressed.connect(func() -> void: settings_pressed.emit())
|
||
var right := CenterContainer.new()
|
||
right.custom_minimum_size = Vector2(52, 52)
|
||
right.add_child(settings)
|
||
hub.add_child(right)
|
||
|
||
column.add_child(UI.spacer(4))
|
||
column.add_child(UI.heading("Ratdoku", 46))
|
||
column.add_child(UI.label("A cozy rat hotel puzzle", 15, Palette.MUTED))
|
||
|
||
event_button = UI.button("Hotel event", false, 34)
|
||
event_button.custom_minimum_size = Vector2(0, 34)
|
||
UI.set_font_size(event_button, 12)
|
||
event_button.clip_text = true
|
||
event_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
event_button.pressed.connect(_open_event)
|
||
column.add_child(event_button)
|
||
|
||
daily_button = UI.button("Daily room", false, 40)
|
||
daily_button.custom_minimum_size = Vector2(0, 40)
|
||
daily_button.clip_text = true
|
||
daily_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
UI.set_font_size(daily_button, 11)
|
||
daily_button.pressed.connect(func() -> void: daily_pressed.emit())
|
||
freeplay_button = UI.button("Free play", false, 40)
|
||
freeplay_button.custom_minimum_size = Vector2(0, 40)
|
||
freeplay_button.clip_text = true
|
||
freeplay_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
UI.set_font_size(freeplay_button, 11)
|
||
freeplay_button.pressed.connect(func() -> void: freeplay_pressed.emit())
|
||
streak_button = UI.button("Streak ›", false, 40)
|
||
streak_button.custom_minimum_size = Vector2(0, 40)
|
||
streak_button.clip_text = true
|
||
streak_button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||
UI.set_font_size(streak_button, 11)
|
||
streak_button.pressed.connect(func() -> void: streak_pressed.emit())
|
||
var daily_row := HBoxContainer.new()
|
||
daily_row.add_theme_constant_override("separation", 6)
|
||
daily_row.add_child(daily_button)
|
||
daily_row.add_child(freeplay_button)
|
||
daily_row.add_child(streak_button)
|
||
column.add_child(daily_row)
|
||
|
||
var top_space := Control.new()
|
||
top_space.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||
top_space.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||
column.add_child(top_space)
|
||
|
||
var card := UI.panel(Palette.CREAM, 26, 12)
|
||
mascot_card = card
|
||
card.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||
var mascot := _make_mascot("crumb")
|
||
mascot_art = mascot
|
||
mascot_art.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||
card.add_child(mascot)
|
||
mascot_button = Button.new()
|
||
mascot_button.flat = true
|
||
mascot_button.mouse_filter = Control.MOUSE_FILTER_STOP
|
||
mascot_button.pressed.connect(_on_mascot_pressed)
|
||
mascot_button.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
card.add_child(mascot_button)
|
||
column.add_child(card)
|
||
_apply_mascot_scale()
|
||
|
||
mascot_caption = UI.label("Crumb, innkeeper", 12, Palette.MUTED)
|
||
column.add_child(mascot_caption)
|
||
mascot_note = UI.label("Guest of the day · tap to cycle", 10, Palette.MUTED)
|
||
column.add_child(mascot_note)
|
||
hint_label = UI.label(UI.place_hint(), 11, Palette.MUTED)
|
||
column.add_child(hint_label)
|
||
|
||
var bottom_space := Control.new()
|
||
bottom_space.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||
bottom_space.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||
column.add_child(bottom_space)
|
||
|
||
primary = UI.button("Check in", true, 54)
|
||
primary.custom_minimum_size = Vector2(300, 54)
|
||
primary.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||
primary.pressed.connect(func() -> void: play_pressed.emit())
|
||
column.add_child(primary)
|
||
|
||
var secondary := HBoxContainer.new()
|
||
secondary.alignment = BoxContainer.ALIGNMENT_CENTER
|
||
secondary.add_theme_constant_override("separation", 8)
|
||
column.add_child(secondary)
|
||
|
||
var book := UI.button("Guest Book", false, 46)
|
||
book.custom_minimum_size = Vector2(146, 46)
|
||
UI.set_font_size(book, 15)
|
||
book.pressed.connect(func() -> void: guest_book_pressed.emit())
|
||
secondary.add_child(book)
|
||
|
||
var rules := UI.button("House Rules", false, 46)
|
||
rules.custom_minimum_size = Vector2(146, 46)
|
||
UI.set_font_size(rules, 15)
|
||
rules.pressed.connect(func() -> void: rules_pressed.emit())
|
||
secondary.add_child(rules)
|
||
|
||
column.add_child(UI.label("No ads. No lives. Just rats.", 10, Palette.MUTED))
|
||
column.add_child(UI.label(Version.BUILD_LABEL, 9, Palette.MUTED))
|
||
|
||
UI.pass_scroll_input(column)
|
||
_build_event_layer()
|
||
SaveGame.progress_changed.connect(refresh)
|
||
SaveGame.settings_changed.connect(refresh)
|
||
refresh()
|
||
|
||
|
||
func _apply_mascot_scale() -> void:
|
||
if mascot_card == null or mascot_art == null:
|
||
return
|
||
var scale := UI.ui_scale()
|
||
var card_base := 140 if mascot_cycling else 160
|
||
var art_base := 120 if mascot_cycling else 138
|
||
var card_size := int(card_base / scale)
|
||
var art_size := int(art_base / scale)
|
||
mascot_card.custom_minimum_size = Vector2(card_size, card_size)
|
||
mascot_art.custom_minimum_size = Vector2(art_size, art_size)
|
||
mascot_button.custom_minimum_size = Vector2(card_size, card_size)
|
||
|
||
|
||
func _build_event_layer() -> void:
|
||
event_layer = ColorRect.new()
|
||
event_layer.color = Color(0.18, 0.12, 0.08, 0.62)
|
||
event_layer.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
event_layer.mouse_filter = Control.MOUSE_FILTER_STOP
|
||
event_layer.gui_input.connect(func(event: InputEvent) -> void:
|
||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||
event_layer.visible = false
|
||
)
|
||
event_layer.visible = false
|
||
add_child(event_layer)
|
||
|
||
var center := CenterContainer.new()
|
||
center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
center.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||
event_layer.add_child(center)
|
||
var panel := UI.panel(Palette.CREAM, 24, 16)
|
||
panel.custom_minimum_size = Vector2(min(340, max(280, int(get_viewport_rect().size.x) - 32)), 0)
|
||
center.add_child(panel)
|
||
var box := VBoxContainer.new()
|
||
box.add_theme_constant_override("separation", 8)
|
||
panel.add_child(box)
|
||
|
||
event_title = UI.heading("Hotel event", 20)
|
||
box.add_child(event_title)
|
||
event_body = UI.label("", 12)
|
||
event_body.custom_minimum_size = Vector2(0, 90)
|
||
box.add_child(event_body)
|
||
event_progress = UI.label("", 11, Palette.MUTED)
|
||
box.add_child(event_progress)
|
||
event_claim = UI.button("Claim gift", true, 44)
|
||
event_claim.add_theme_color_override("font_disabled_color", Palette.INK)
|
||
event_claim.pressed.connect(_claim_event)
|
||
box.add_child(event_claim)
|
||
var close := UI.button("Close", false, 44)
|
||
close.pressed.connect(func() -> void: event_layer.visible = false)
|
||
box.add_child(close)
|
||
|
||
|
||
func _open_event() -> void:
|
||
var event := SaveGame.current_event()
|
||
if event.is_empty():
|
||
return
|
||
var id := str(event.get("id", ""))
|
||
var guest := Guests.by_id(str(event.get("featured_guest", "")))
|
||
event_title.text = str(event.get("name", "Hotel event"))
|
||
event_body.text = "%s\n\nFeatured guest: %s" % [str(event.get("description", "")), str(guest.get("name", "Crumb"))]
|
||
var progress := SaveGame.event_progress(id)
|
||
event_progress.text = "Daily rooms during this visit: %d / 3" % progress
|
||
var claimed := SaveGame.event_claimed(id)
|
||
event_claim.text = "Gift claimed ✓" if claimed else ("Claim: %s" % str(event.get("gift", "Treat")))
|
||
event_claim.disabled = claimed or not SaveGame.event_claimable(id)
|
||
event_layer.visible = true
|
||
event_layer.move_to_front()
|
||
|
||
|
||
func _claim_event() -> void:
|
||
var id := str(SaveGame.current_event().get("id", ""))
|
||
if SaveGame.claim_event(id):
|
||
event_claim.text = "Gift claimed ✓"
|
||
event_claim.disabled = true
|
||
refresh()
|
||
|
||
|
||
func refresh() -> void:
|
||
hint_label.text = UI.place_hint()
|
||
_apply_mascot_scale()
|
||
_refresh_mascot()
|
||
daily_button.text = _daily_text()
|
||
var event := SaveGame.current_event()
|
||
if event.is_empty():
|
||
event_button.text = "Hotel event"
|
||
else:
|
||
var id := str(event.get("id", ""))
|
||
var progress := SaveGame.event_progress(id)
|
||
var state := "Gift ready" if SaveGame.event_claimable(id) else (
|
||
"Gift claimed" if SaveGame.event_claimed(id) else "%d/3 daily rooms" % progress
|
||
)
|
||
event_button.text = "%s · %s" % [str(event.get("name", "Event")), state]
|
||
_refresh_avatar()
|
||
var guests := Guests.all()
|
||
var unlocked := SaveGame.unlocked_count(guests)
|
||
progress_pill.text = "%d / %d guests" % [unlocked, guests.size()]
|
||
|
||
var last := int(SaveGame.data.get("last_room", 0))
|
||
if last <= 0:
|
||
primary.text = "Check in"
|
||
elif last >= 30:
|
||
primary.text = "Replay Room 30"
|
||
else:
|
||
primary.text = "Continue Room %d" % (last + 1)
|
||
|
||
|
||
func _daily_text() -> String:
|
||
var streak := SaveGame.daily_streak()
|
||
if SaveGame.daily_completed_today():
|
||
return "Daily done · %dd" % streak
|
||
if streak > 0:
|
||
return "Daily · %dd streak" % streak
|
||
return "Daily room"
|
||
|
||
|
||
func _build_avatar() -> void:
|
||
var frame := Frames.frame_panel(SaveGame.selected_frame(), 56)
|
||
var avatar := Button.new()
|
||
avatar.custom_minimum_size = Vector2(44, 44)
|
||
avatar.flat = true
|
||
avatar.icon = load(Avatars.head_path(SaveGame.selected_avatar()))
|
||
avatar.expand_icon = true
|
||
avatar.icon_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||
avatar.alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||
avatar.tooltip_text = "Profile"
|
||
avatar.pressed.connect(func() -> void: profile_pressed.emit())
|
||
frame.add_child(avatar)
|
||
avatar_holder.add_child(frame)
|
||
avatar_frame_id = SaveGame.selected_frame()
|
||
avatar_portrait_id = SaveGame.selected_avatar()
|
||
|
||
|
||
func _refresh_avatar() -> void:
|
||
if (
|
||
avatar_frame_id == SaveGame.selected_frame()
|
||
and avatar_portrait_id == SaveGame.selected_avatar()
|
||
):
|
||
return
|
||
for child in avatar_holder.get_children():
|
||
child.queue_free()
|
||
_build_avatar()
|
||
|
||
|
||
func _make_mascot(id: String) -> Control:
|
||
var path := "res://art/crumb.png" if id == "crumb" else Guests.portrait(id, "cards")
|
||
if ResourceLoader.exists(path):
|
||
var texture_rect := TextureRect.new()
|
||
texture_rect.texture = load(path)
|
||
texture_rect.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
||
texture_rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||
return texture_rect
|
||
return RatPortrait.new()
|
||
|
||
|
||
func _unlocked_mascot_ids() -> Array:
|
||
var out: Array = ["crumb"]
|
||
for guest in Guests.all():
|
||
var id := str(guest.get("id", ""))
|
||
if id != "crumb" and SaveGame.is_guest_unlocked(id):
|
||
out.append(id)
|
||
return out
|
||
|
||
|
||
func _mascot_guest(id: String) -> Dictionary:
|
||
if id == "crumb":
|
||
return {"name": "Crumb", "role": "Innkeeper", "stories": []}
|
||
return Guests.by_id(id)
|
||
|
||
|
||
func _on_mascot_pressed() -> void:
|
||
var ids := _unlocked_mascot_ids()
|
||
if ids.is_empty():
|
||
return
|
||
var index := ids.find(mascot_id)
|
||
mascot_cycling = true
|
||
mascot_id = str(ids[(index + 1) % ids.size()])
|
||
UI.haptic(false)
|
||
_refresh_mascot()
|
||
|
||
|
||
func _refresh_mascot() -> void:
|
||
var ids := _unlocked_mascot_ids()
|
||
if ids.is_empty():
|
||
return
|
||
if not mascot_cycling:
|
||
mascot_id = str(ids[Daily.day_number(Daily.today_key()) % ids.size()])
|
||
elif not ids.has(mascot_id):
|
||
mascot_id = str(ids[0])
|
||
|
||
if mascot_art_id != mascot_id:
|
||
for child in mascot_card.get_children():
|
||
if child != mascot_button:
|
||
mascot_card.remove_child(child)
|
||
child.queue_free()
|
||
mascot_art = _make_mascot(mascot_id)
|
||
mascot_art.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||
mascot_card.add_child(mascot_art)
|
||
mascot_button.move_to_front()
|
||
mascot_art_id = mascot_id
|
||
_apply_mascot_scale()
|
||
|
||
var guest := _mascot_guest(mascot_id)
|
||
mascot_caption.text = "%s · %s" % [
|
||
str(guest.get("name", mascot_id)),
|
||
str(guest.get("role", "Guest"))
|
||
]
|
||
if mascot_cycling:
|
||
var stories: Array = guest.get("stories", [])
|
||
if stories.is_empty():
|
||
mascot_note.text = "Always in · tap to cycle"
|
||
else:
|
||
var line := str(stories[0])
|
||
mascot_note.text = line if line.length() <= 52 else (line.substr(0, 49) + "…")
|
||
else:
|
||
mascot_note.text = "Guest of the day · tap to cycle"
|