feat(profile): selectable avatars and a daily streak view

Profile now has tabbed Avatar/Frame pickers with preview and Confirm/Cancel. Crumb plus unlocked guest portraits can be chosen as the avatar. A new Daily Streak screen shows the current streak, best streak, weekly calendar, next-frame goal, and a 7-day gift marker. Save format moves to version 4 with avatar_id and completion history.
This commit is contained in:
Ratdoku Builder committed 2026-12-02 23:57:28 -06:00
1 parent c91586b4a1
commit d0be689faa
16 files changed
+538 -60

No files matched your search

+111 -32
View File
@@ -1,14 +1,22 @@
extends Control
signal back_pressed
signal streak_pressed
var portrait_holder: CenterContainer
var name_label: Label
var role_label: Label
var rooms_label: Label
var streak_label: Label
var best_label: Label
var frame_grid: GridContainer
var status_label: Label
var portrait_frame_id := ""
var avatar_tab: Button
var frame_tab: Button
var current_tab := "avatar"
var pending_avatar := "crumb"
var pending_frame := "plain"
var portrait_key := ""
func _ready() -> void:
@@ -32,7 +40,7 @@ func _ready() -> void:
back.pressed.connect(func() -> void: back_pressed.emit())
top.add_child(back)
var title := UI.label("Crumb's Profile", 22)
var title := UI.label("Profile", 22)
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
top.add_child(title)
@@ -51,8 +59,10 @@ func _ready() -> void:
portrait_holder = CenterContainer.new()
content.add_child(portrait_holder)
content.add_child(UI.label("Crumb", 20, Palette.INK, true))
content.add_child(UI.label("Innkeeper · always in", 11, Palette.MUTED))
name_label = UI.label("Crumb", 20, Palette.INK, true)
content.add_child(name_label)
role_label = UI.label("Innkeeper · always in", 11, Palette.MUTED)
content.add_child(role_label)
var stats := HBoxContainer.new()
stats.add_theme_constant_override("separation", 6)
@@ -61,7 +71,23 @@ func _ready() -> void:
streak_label = _stat_card(stats, "Streak", "0")
best_label = _stat_card(stats, "Best", "0")
content.add_child(UI.heading("Frames", 18))
var view_streak := UI.button("View daily streak ›", false, 40)
view_streak.add_theme_font_size_override("font_size", 14)
view_streak.pressed.connect(func() -> void: streak_pressed.emit())
content.add_child(view_streak)
var tabs := HBoxContainer.new()
tabs.add_theme_constant_override("separation", 6)
content.add_child(tabs)
avatar_tab = UI.button("Avatar", false, 38)
avatar_tab.size_flags_horizontal = Control.SIZE_EXPAND_FILL
avatar_tab.pressed.connect(func() -> void: _set_tab("avatar"))
tabs.add_child(avatar_tab)
frame_tab = UI.button("Frame", false, 38)
frame_tab.size_flags_horizontal = Control.SIZE_EXPAND_FILL
frame_tab.pressed.connect(func() -> void: _set_tab("frame"))
tabs.add_child(frame_tab)
frame_grid = GridContainer.new()
frame_grid.columns = 2
frame_grid.size_flags_horizontal = Control.SIZE_EXPAND_FILL
@@ -69,10 +95,22 @@ func _ready() -> void:
frame_grid.add_theme_constant_override("v_separation", 6)
content.add_child(frame_grid)
status_label = UI.label("Tap an unlocked frame to wear it.", 11, Palette.MUTED)
status_label = UI.label("Pick a look, then confirm.", 11, Palette.MUTED)
status_label.custom_minimum_size = Vector2(0, 22)
content.add_child(status_label)
var actions := HBoxContainer.new()
actions.add_theme_constant_override("separation", 8)
content.add_child(actions)
var cancel := UI.button("Cancel", false, 46)
cancel.size_flags_horizontal = Control.SIZE_EXPAND_FILL
cancel.pressed.connect(_on_cancel)
actions.add_child(cancel)
var confirm := UI.button("Confirm", true, 46)
confirm.size_flags_horizontal = Control.SIZE_EXPAND_FILL
confirm.pressed.connect(_on_confirm)
actions.add_child(confirm)
UI.pass_scroll_input(content)
SaveGame.progress_changed.connect(refresh)
refresh()
@@ -92,46 +130,68 @@ func _stat_card(parent: HBoxContainer, title: String, value: String) -> Label:
func refresh() -> void:
pending_avatar = SaveGame.selected_avatar()
pending_frame = SaveGame.selected_frame()
rooms_label.text = "%d / 30" % SaveGame.rooms_completed()
streak_label.text = str(SaveGame.daily_streak())
best_label.text = str(SaveGame.best_streak())
var avatar: Dictionary = Avatars.by_id(pending_avatar)
name_label.text = str(avatar.get("name", "Crumb"))
role_label.text = "Innkeeper · always in" if pending_avatar == "crumb" else "Guest · Hotel Ratdoku"
status_label.text = "Pick a look, then confirm."
status_label.add_theme_color_override("font_color", Palette.MUTED)
_update_tab_styles()
_build_portrait()
_build_frames()
_build_grid()
func _set_tab(tab: String) -> void:
if current_tab == tab:
return
current_tab = tab
_update_tab_styles()
_build_grid()
func _update_tab_styles() -> void:
avatar_tab.add_theme_stylebox_override("normal", _card_style(Palette.GOLD if current_tab == "avatar" else Palette.PAPER))
frame_tab.add_theme_stylebox_override("normal", _card_style(Palette.GOLD if current_tab == "frame" else Palette.PAPER))
func _build_portrait() -> void:
var selected := SaveGame.selected_frame()
if portrait_frame_id == selected and portrait_holder.get_child_count() > 0:
var key: String = pending_avatar + "|" + pending_frame
if portrait_key == key and portrait_holder.get_child_count() > 0:
return
for child in portrait_holder.get_children():
child.queue_free()
var frame := Frames.frame_panel(selected, 118)
var frame := Frames.frame_panel(pending_frame, 118)
var head := TextureRect.new()
head.texture = load("res://art/crumb_head.png")
head.texture = load(Avatars.portrait_path(pending_avatar))
head.custom_minimum_size = Vector2(96, 96)
head.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
head.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
head.mouse_filter = Control.MOUSE_FILTER_IGNORE
frame.add_child(head)
portrait_holder.add_child(frame)
portrait_frame_id = selected
portrait_key = key
func _build_frames() -> void:
func _build_grid() -> void:
for child in frame_grid.get_children():
child.queue_free()
var selected := SaveGame.selected_frame()
for frame in Frames.all():
var id := str(frame.get("id", ""))
var unlocked := Frames.is_unlocked(id)
var entries: Array = Avatars.all() if current_tab == "avatar" else Frames.all()
var selected := pending_avatar if current_tab == "avatar" else pending_frame
for entry in entries:
var id := str(entry.get("id", ""))
var unlocked := Avatars.is_unlocked(id) if current_tab == "avatar" else Frames.is_unlocked(id)
var card := Button.new()
card.custom_minimum_size = Vector2(148, 92)
card.flat = true
card.add_theme_stylebox_override("normal", _card_style(Palette.PAPER))
card.add_theme_stylebox_override("hover", _card_style(Palette.PAPER_DARK))
card.add_theme_stylebox_override("pressed", _card_style(Palette.GOLD))
card.pressed.connect(_on_frame_pressed.bind(id, unlocked))
card.pressed.connect(_on_card_pressed.bind(id, unlocked, current_tab))
var row := HBoxContainer.new()
row.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
@@ -139,10 +199,10 @@ func _build_frames() -> void:
row.mouse_filter = Control.MOUSE_FILTER_IGNORE
card.add_child(row)
var badge := Frames.frame_panel(id, 46)
var badge := Frames.frame_panel(pending_frame if current_tab == "avatar" else id, 46)
badge.mouse_filter = Control.MOUSE_FILTER_IGNORE
var head := TextureRect.new()
head.texture = load("res://art/crumb_head.png")
head.texture = load(Avatars.portrait_path(id) if current_tab == "avatar" else "res://art/crumb_head.png")
head.custom_minimum_size = Vector2(30, 30)
head.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
head.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
@@ -156,18 +216,18 @@ func _build_frames() -> void:
text.mouse_filter = Control.MOUSE_FILTER_IGNORE
row.add_child(text)
var name := UI.label(str(frame.get("name", "")), 12)
var name := UI.label(str(entry.get("name", "")), 12)
name.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
text.add_child(name)
var detail := ""
if id == selected:
detail = "Wearing"
detail = "Selected"
elif unlocked:
detail = "Unlocked"
else:
detail = Frames.requirement_text(id)
var sub := UI.label(detail, 9, Palette.MUTED if unlocked else Palette.RED)
detail = Avatars.requirement_text(id) if current_tab == "avatar" else Frames.requirement_text(id)
var sub := UI.label(detail, 9, Palette.GOLD if id == selected else (Palette.MUTED if unlocked else Palette.RED))
sub.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
text.add_child(sub)
@@ -178,19 +238,38 @@ func _build_frames() -> void:
UI.pass_scroll_input(frame_grid)
func _on_frame_pressed(id: String, unlocked: bool) -> void:
func _on_card_pressed(id: String, unlocked: bool, tab: String) -> void:
if not unlocked:
status_label.text = "Locked: %s." % Frames.requirement_text(id)
var requirement := Avatars.requirement_text(id) if tab == "avatar" else Frames.requirement_text(id)
status_label.text = "Locked: %s." % requirement
status_label.add_theme_color_override("font_color", Palette.RED)
return
# Never rebuild the card grid while the card's own `pressed` signal is
# still on the stack; Godot locks the emitting node during the call.
call_deferred("_apply_frame", id)
call_deferred("_select_card", id, tab)
func _apply_frame(id: String) -> void:
SaveGame.select_frame(id)
status_label.text = "Now wearing %s." % str(Frames.by_id(id).get("name", id))
func _select_card(id: String, tab: String) -> void:
if tab == "avatar":
pending_avatar = id
else:
pending_frame = id
_build_portrait()
_build_grid()
status_label.text = "Preview only — press Confirm to save."
status_label.add_theme_color_override("font_color", Palette.MUTED)
func _on_cancel() -> void:
pending_avatar = SaveGame.selected_avatar()
pending_frame = SaveGame.selected_frame()
_build_portrait()
_build_grid()
status_label.text = "Changes discarded."
status_label.add_theme_color_override("font_color", Palette.MUTED)
func _on_confirm() -> void:
SaveGame.apply_profile(pending_avatar, pending_frame)
status_label.text = "Profile updated."
status_label.add_theme_color_override("font_color", Palette.MUTED)