Godot client: Collection screen — cards grid, deck management, card widget

- CardWidget (146×204px): affinity-coloured border + art placeholder,
  stats with tooltips, foil/serial indicators, selection highlight
- DeckListItem: inline rename, clone/delete signals to parent
- CardsView: paginated + filterable grid (search debounce, type/affinity
  filters, responsive columns, Load More pagination)
- DecksView: deck list with New Deck form (ArchSpirit card picker),
  clone/rename/delete wired to API, ConfirmationDialog for delete
- CollectionScreen: pill-tab container (Cards / Decks), background
  incremental content sync, back button → MainScreen
- MainScreen: wire CollectionBtn → CollectionScreen
- ContentCache: expose is_syncing() public method

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-02-28 07:48:07 -05:00
co-authored by Claude Happy
parent 1b440e92ba
commit 6a33e26237
13 changed files with 1366 additions and 3 deletions
@@ -0,0 +1,90 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://scenes/collection/views/cars_view.gd" id="1_cv"]
[node name="CardsView" type="VBoxContainer"]
layout_mode = 2
script = ExtResource("1_cv")
[node name="FilterBar" type="VBoxContainer" parent="."]
layout_mode = 2
theme_override_constants/separation = 6
theme_override_constants/margin_left = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_top = 8
theme_override_constants/margin_bottom = 8
[node name="SearchInput" type="LineEdit" parent="FilterBar"]
unique_name_in_owner = true
layout_mode = 2
placeholder_text = "Search cards…"
theme_override_font_sizes/font_size = 14
[node name="FilterRow" type="HBoxContainer" parent="FilterBar"]
layout_mode = 2
theme_override_constants/separation = 6
[node name="TypeOption" type="OptionButton" parent="FilterBar/FilterRow"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_font_sizes/font_size = 13
[node name="AffinityOption" type="OptionButton" parent="FilterBar/FilterRow"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_font_sizes/font_size = 13
[node name="Scroll" type="ScrollContainer" parent="."]
layout_mode = 2
size_flags_vertical = 3
horizontal_scroll_mode = 0
[node name="ScrollInner" type="VBoxContainer" parent="Scroll"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_constants/separation = 0
[node name="CardGridMargin" type="MarginContainer" parent="Scroll/ScrollInner"]
layout_mode = 2
theme_override_constants/margin_left = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_top = 8
theme_override_constants/margin_bottom = 8
[node name="CardGrid" type="GridContainer" parent="Scroll/ScrollInner/CardGridMargin"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
columns = 2
theme_override_constants/h_separation = 8
theme_override_constants/v_separation = 8
[node name="StatusRow" type="HBoxContainer" parent="Scroll/ScrollInner"]
layout_mode = 2
custom_minimum_size = Vector2(0, 44)
alignment = 1
[node name="LoadingLabel" type="Label" parent="Scroll/ScrollInner/StatusRow"]
unique_name_in_owner = true
layout_mode = 2
text = "Loading…"
modulate = Color(0.75, 0.75, 0.8, 1.0)
theme_override_font_sizes/font_size = 14
[node name="EmptyLabel" type="Label" parent="Scroll/ScrollInner/StatusRow"]
unique_name_in_owner = true
layout_mode = 2
text = "No cards found."
visible = false
modulate = Color(0.6, 0.6, 0.65, 1.0)
theme_override_font_sizes/font_size = 14
[node name="LoadMoreBtn" type="Button" parent="Scroll/ScrollInner/StatusRow"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(120, 36)
text = "Load More"
visible = false
theme_override_font_sizes/font_size = 14
@@ -0,0 +1,148 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://scenes/collection/views/decks_view.gd" id="1_dv"]
[node name="DecksView" type="VBoxContainer"]
layout_mode = 2
script = ExtResource("1_dv")
[node name="HeaderMargin" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 12
theme_override_constants/margin_right = 12
theme_override_constants/margin_top = 8
theme_override_constants/margin_bottom = 8
[node name="Header" type="HBoxContainer" parent="HeaderMargin"]
layout_mode = 2
custom_minimum_size = Vector2(0, 34)
theme_override_constants/separation = 8
[node name="HeaderLabel" type="Label" parent="HeaderMargin/Header"]
layout_mode = 2
size_flags_horizontal = 3
text = "Decks"
theme_override_font_sizes/font_size = 16
[node name="NewDeckBtn" type="Button" parent="HeaderMargin/Header"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 34)
text = "+ New Deck"
theme_override_font_sizes/font_size = 14
[node name="NewDeckForm" type="PanelContainer" parent="."]
unique_name_in_owner = true
layout_mode = 2
visible = false
[node name="FormMargin" type="MarginContainer" parent="NewDeckForm"]
layout_mode = 2
theme_override_constants/margin_left = 12
theme_override_constants/margin_right = 12
theme_override_constants/margin_top = 10
theme_override_constants/margin_bottom = 10
[node name="FormVBox" type="VBoxContainer" parent="NewDeckForm/FormMargin"]
layout_mode = 2
theme_override_constants/separation = 10
[node name="FormTitle" type="Label" parent="NewDeckForm/FormMargin/FormVBox"]
layout_mode = 2
text = "New Deck"
theme_override_font_sizes/font_size = 15
[node name="DeckNameInput" type="LineEdit" parent="NewDeckForm/FormMargin/FormVBox"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 36)
placeholder_text = "Deck Name"
theme_override_font_sizes/font_size = 14
[node name="ArchSpiritLabel" type="Label" parent="NewDeckForm/FormMargin/FormVBox"]
layout_mode = 2
text = "ArchSpirit Card"
theme_override_font_sizes/font_size = 13
modulate = Color(0.8, 0.8, 0.85, 1.0)
[node name="ArchSpiritScroll" type="ScrollContainer" parent="NewDeckForm/FormMargin/FormVBox"]
layout_mode = 2
custom_minimum_size = Vector2(0, 170)
vertical_scroll_mode = 0
[node name="ArchSpiritGrid" type="HBoxContainer" parent="NewDeckForm/FormMargin/FormVBox/ArchSpiritScroll"]
unique_name_in_owner = true
layout_mode = 2
theme_override_constants/separation = 8
[node name="ArchSpiritHint" type="Label" parent="NewDeckForm/FormMargin/FormVBox"]
unique_name_in_owner = true
layout_mode = 2
text = "Select an ArchSpirit card to continue."
modulate = Color(1.0, 0.75, 0.3, 1.0)
theme_override_font_sizes/font_size = 12
[node name="FormButtons" type="HBoxContainer" parent="NewDeckForm/FormMargin/FormVBox"]
layout_mode = 2
theme_override_constants/separation = 8
[node name="CancelNewBtn" type="Button" parent="NewDeckForm/FormMargin/FormVBox/FormButtons"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
custom_minimum_size = Vector2(0, 36)
text = "Cancel"
theme_override_font_sizes/font_size = 14
[node name="CreateBtn" type="Button" parent="NewDeckForm/FormMargin/FormVBox/FormButtons"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
custom_minimum_size = Vector2(0, 36)
text = "Create"
disabled = true
theme_override_font_sizes/font_size = 14
[node name="Scroll" type="ScrollContainer" parent="."]
layout_mode = 2
size_flags_vertical = 3
horizontal_scroll_mode = 0
[node name="DeckListMargin" type="MarginContainer" parent="Scroll"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_constants/margin_left = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_top = 4
theme_override_constants/margin_bottom = 8
[node name="DeckList" type="VBoxContainer" parent="Scroll/DeckListMargin"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
theme_override_constants/separation = 4
[node name="StatusRow" type="HBoxContainer" parent="."]
layout_mode = 2
custom_minimum_size = Vector2(0, 44)
alignment = 1
[node name="LoadingLabel" type="Label" parent="StatusRow"]
unique_name_in_owner = true
layout_mode = 2
text = "Loading…"
modulate = Color(0.75, 0.75, 0.8, 1.0)
theme_override_font_sizes/font_size = 14
[node name="EmptyLabel" type="Label" parent="StatusRow"]
unique_name_in_owner = true
layout_mode = 2
text = "No decks yet. Tap + to create one."
visible = false
modulate = Color(0.6, 0.6, 0.65, 1.0)
theme_override_font_sizes/font_size = 14
[node name="ConfirmDialog" type="ConfirmationDialog" parent="."]
unique_name_in_owner = true
title = "Confirm Delete"
ok_button_text = "Delete"
@@ -0,0 +1,171 @@
extends VBoxContainer
## Cards tab — paginated, filterable grid of the player's owned cards.
##
## Fetches from collection.get_cards (page, pageSize, nameFilter?,
## cardTypeFilter?, affinityFilter?). Displays results as CardWidget
## instances in a responsive GridContainer.
##
## Typing in the search box starts a 0.4 s debounce before reloading.
## "Load More" appends the next page without clearing the existing cards.
const CARD_WIDGET := preload("res://scenes/collection/components/CardWidget.tscn")
const PAGE_SIZE := 20
# ── Node references ───────────────────────────────────────────────────────────
@onready var search_input : LineEdit = %SearchInput
@onready var type_option : OptionButton = %TypeOption
@onready var affinity_option : OptionButton = %AffinityOption
@onready var card_grid : GridContainer = %CardGrid
@onready var loading_label : Label = %LoadingLabel
@onready var empty_label : Label = %EmptyLabel
@onready var load_more_btn : Button = %LoadMoreBtn
# ── State ─────────────────────────────────────────────────────────────────────
var _current_page : int = 1
var _total_count : int = 0
var _has_more : bool = false
var _loading : bool = false
var _search_timer : float = 0.0
const _SEARCH_DEBOUNCE := 0.4
# Signals emitted to parent when a card is tapped (for future deck-editor use)
signal card_selected(player_card_id: String, definition_id: String)
# ── Lifecycle ─────────────────────────────────────────────────────────────────
func _ready() -> void:
_populate_type_options()
_populate_affinity_options()
_update_columns()
search_input.text_changed.connect(_on_search_changed)
type_option.item_selected.connect(func(_i): _reload())
affinity_option.item_selected.connect(func(_i): _reload())
load_more_btn.pressed.connect(_on_load_more)
get_viewport().size_changed.connect(_update_columns)
_reload()
func _exit_tree() -> void:
if get_viewport() and get_viewport().size_changed.is_connected(_update_columns):
get_viewport().size_changed.disconnect(_update_columns)
func _process(delta: float) -> void:
if _search_timer > 0.0:
_search_timer -= delta
if _search_timer <= 0.0:
_search_timer = 0.0
_reload()
# ── Option population ─────────────────────────────────────────────────────────
func _populate_type_options() -> void:
type_option.clear()
type_option.add_item("All Types")
for t in ["Creature", "Spell", "Item", "ArchSpirit"]:
type_option.add_item(t)
func _populate_affinity_options() -> void:
affinity_option.clear()
affinity_option.add_item("All Affinities")
for a in ["Fire", "Water", "Earth", "Air", "Lightning", "Dark", "Light"]:
affinity_option.add_item(a)
# ── Responsive columns ────────────────────────────────────────────────────────
func _update_columns() -> void:
var vp_w := get_viewport_rect().size.x
card_grid.columns = max(2, int(vp_w / 160))
# ── Data fetching ─────────────────────────────────────────────────────────────
func _reload() -> void:
_current_page = 1
_total_count = 0
_has_more = false
for child in card_grid.get_children():
child.queue_free()
_fetch_page(1)
func _fetch_page(page: int) -> void:
if _loading:
return
_loading = true
_set_status("loading")
var payload := {
"page": page,
"pageSize": PAGE_SIZE,
}
var search := search_input.text.strip_edges()
if not search.is_empty():
payload["nameFilter"] = search
# Type filter — index 0 = "All Types" (skip)
var type_idx := type_option.selected
if type_idx > 0:
payload["cardTypeFilter"] = type_option.get_item_text(type_idx)
# Affinity filter — index 0 = "All Affinities" (skip)
var aff_idx := affinity_option.selected
if aff_idx > 0:
payload["affinityFilter"] = affinity_option.get_item_text(aff_idx)
Network.request(
"collection.get_cards",
payload,
func(_t: String, p: Variant): _on_cards_response(p, page),
func(_code: String, msg: String): _on_error(msg)
)
func _on_cards_response(payload: Variant, page: int) -> void:
_loading = false
var p := payload as Dictionary
var cards : Array = p.get("cards", [])
_total_count = int(p.get("totalCount", 0))
var page_size : int = int(p.get("pageSize", PAGE_SIZE))
_current_page = page
_has_more = (page * page_size) < _total_count
for dto in cards:
var def := ContentCache.get_definition(str(dto.get("cardDefinitionId", "")))
var widget = CARD_WIDGET.instantiate() as PanelContainer
widget.setup(dto, def)
widget.card_pressed.connect(func(def_id: String):
card_selected.emit(str(dto.get("playerCardId", "")), def_id))
card_grid.add_child(widget)
if cards.is_empty() and page == 1:
_set_status("empty")
else:
_set_status("done")
load_more_btn.visible = _has_more
func _on_error(msg: String) -> void:
_loading = false
_set_status("empty")
push_warning("CardsView: %s" % msg)
# ── Button handlers ───────────────────────────────────────────────────────────
func _on_search_changed(_text: String) -> void:
_search_timer = _SEARCH_DEBOUNCE
func _on_load_more() -> void:
_fetch_page(_current_page + 1)
# ── Status helper ─────────────────────────────────────────────────────────────
func _set_status(state: String) -> void:
loading_label.visible = (state == "loading")
empty_label.visible = (state == "empty")
if state != "loading":
load_more_btn.visible = _has_more
@@ -0,0 +1,219 @@
extends VBoxContainer
## Decks tab — browse, create, clone, rename, and delete decks.
##
## New Deck flow:
## 1. User taps "+ New Deck" → NewDeckForm slides into view.
## 2. Player types a deck name and picks an ArchSpirit card from
## a horizontal scroll of CardWidgets.
## 3. "Create" is only enabled once both are set.
## 4. On Create: collection.create_deck → reload deck list.
##
## All mutating operations go through this node via signals from DeckListItem.
const DECK_LIST_ITEM := preload("res://scenes/collection/components/DeckListItem.tscn")
const CARD_WIDGET := preload("res://scenes/collection/components/CardWidget.tscn")
# ── Node references ───────────────────────────────────────────────────────────
@onready var new_deck_btn : Button = %NewDeckBtn
@onready var new_deck_form : PanelContainer = %NewDeckForm
@onready var deck_name_input : LineEdit = %DeckNameInput
@onready var arch_spirit_grid : HBoxContainer = %ArchSpiritGrid
@onready var arch_spirit_hint : Label = %ArchSpiritHint
@onready var cancel_new_btn : Button = %CancelNewBtn
@onready var create_btn : Button = %CreateBtn
@onready var deck_list : VBoxContainer = %DeckList
@onready var loading_label : Label = %LoadingLabel
@onready var empty_label : Label = %EmptyLabel
@onready var confirm_dialog : ConfirmationDialog = %ConfirmDialog
# ── State ─────────────────────────────────────────────────────────────────────
var _selected_arch_spirit_id : String = "" ## cardDefinitionId of chosen ArchSpirit
var _pending_delete_id : String = ""
var _pending_delete_name : String = ""
# ── Lifecycle ─────────────────────────────────────────────────────────────────
func _ready() -> void:
new_deck_btn.pressed.connect(_on_new_deck_pressed)
cancel_new_btn.pressed.connect(_on_cancel_new)
create_btn.pressed.connect(_on_create_deck)
deck_name_input.text_changed.connect(_on_name_changed)
confirm_dialog.confirmed.connect(_on_delete_confirmed)
create_btn.disabled = true
_load_decks()
# ── Deck list ─────────────────────────────────────────────────────────────────
func _load_decks() -> void:
for child in deck_list.get_children():
child.queue_free()
_set_status("loading")
Network.request(
"collection.get_decks",
{},
func(_t: String, p: Variant): _on_decks_response(p),
func(_code: String, msg: String): _on_load_error(msg)
)
func _on_decks_response(payload: Variant) -> void:
var decks : Array = (payload as Dictionary).get("decks", [])
_set_status(decks.is_empty(), "empty")
for deck in decks:
var item = DECK_LIST_ITEM.instantiate()
item.setup(deck)
item.rename_requested.connect(_on_rename_requested)
item.delete_requested.connect(_on_delete_requested)
item.clone_requested.connect(_on_clone_requested)
deck_list.add_child(item)
func _on_load_error(msg: String) -> void:
_set_status(true, "empty")
push_warning("DecksView load: %s" % msg)
# ── New Deck form ─────────────────────────────────────────────────────────────
func _on_new_deck_pressed() -> void:
new_deck_form.visible = true
new_deck_btn.visible = false
deck_name_input.text = ""
_selected_arch_spirit_id = ""
arch_spirit_hint.visible = true
create_btn.disabled = true
_load_arch_spirits()
func _on_cancel_new() -> void:
new_deck_form.visible = false
new_deck_btn.visible = true
_clear_arch_spirit_grid()
func _clear_arch_spirit_grid() -> void:
for child in arch_spirit_grid.get_children():
child.queue_free()
_selected_arch_spirit_id = ""
func _load_arch_spirits() -> void:
_clear_arch_spirit_grid()
Network.request(
"collection.get_cards",
{ "page": 1, "pageSize": 50, "cardTypeFilter": "ArchSpirit" },
func(_t: String, p: Variant): _on_arch_spirits(p),
func(_code: String, msg: String): push_warning("DecksView arch spirits: %s" % msg)
)
func _on_arch_spirits(payload: Variant) -> void:
var cards : Array = (payload as Dictionary).get("cards", [])
for dto in cards:
var def := ContentCache.get_definition(str(dto.get("cardDefinitionId", "")))
var widget = CARD_WIDGET.instantiate()
widget.setup(dto, def)
widget.custom_minimum_size = Vector2(110, 154)
var def_id := str(dto.get("cardDefinitionId", ""))
widget.card_pressed.connect(func(_d: String): _on_arch_spirit_selected(widget, def_id))
arch_spirit_grid.add_child(widget)
func _on_arch_spirit_selected(tapped_widget, def_id: String) -> void:
_selected_arch_spirit_id = def_id
arch_spirit_hint.visible = false
# Deselect all, select tapped
for child in arch_spirit_grid.get_children():
child.set_selected(false)
tapped_widget.set_selected(true)
_update_create_btn()
func _on_name_changed(_text: String) -> void:
_update_create_btn()
func _update_create_btn() -> void:
create_btn.disabled = deck_name_input.text.strip_edges().is_empty() \
or _selected_arch_spirit_id.is_empty()
func _on_create_deck() -> void:
var name_val := deck_name_input.text.strip_edges()
if name_val.is_empty() or _selected_arch_spirit_id.is_empty():
return
create_btn.disabled = true
Network.request(
"collection.create_deck",
{ "name": name_val, "archSpiritCardDefinitionId": _selected_arch_spirit_id },
func(_t: String, _p: Variant): _on_deck_created(),
func(_code: String, msg: String): _on_mutate_error(msg)
)
func _on_deck_created() -> void:
new_deck_form.visible = false
new_deck_btn.visible = true
_clear_arch_spirit_grid()
_load_decks()
# ── Rename / Delete / Clone ───────────────────────────────────────────────────
func _on_rename_requested(deck_id: String, new_name: String) -> void:
Network.request(
"collection.rename_deck",
{ "deckId": deck_id, "name": new_name },
func(_t: String, _p: Variant): _load_decks(),
func(_code: String, msg: String): _on_mutate_error(msg)
)
func _on_delete_requested(deck_id: String, deck_name: String) -> void:
_pending_delete_id = deck_id
_pending_delete_name = deck_name
confirm_dialog.dialog_text = "Delete \"%s\"? This cannot be undone." % deck_name
confirm_dialog.popup_centered()
func _on_delete_confirmed() -> void:
if _pending_delete_id.is_empty():
return
Network.request(
"collection.delete_deck",
{ "deckId": _pending_delete_id },
func(_t: String, _p: Variant): _load_decks(),
func(_code: String, msg: String): _on_mutate_error(msg)
)
_pending_delete_id = ""
_pending_delete_name = ""
func _on_clone_requested(deck_id: String) -> void:
Network.request(
"collection.clone_deck",
{ "deckId": deck_id },
func(_t: String, _p: Variant): _load_decks(),
func(_code: String, msg: String): _on_mutate_error(msg)
)
func _on_mutate_error(msg: String) -> void:
push_warning("DecksView mutate: %s" % msg)
_load_decks()
# ── Status helper ─────────────────────────────────────────────────────────────
## Pass a bool (is_empty) + the desired state string, or just a string "loading".
func _set_status(first_arg, second_arg = null) -> void:
if second_arg == null:
# Called as _set_status("loading")
var state: String = first_arg
loading_label.visible = (state == "loading")
empty_label.visible = false
else:
# Called as _set_status(is_empty, "empty")
loading_label.visible = false
empty_label.visible = bool(first_arg)