- 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>
176 lines
7.0 KiB
GDScript
176 lines
7.0 KiB
GDScript
extends PanelContainer
|
||
## Visual card widget.
|
||
##
|
||
## Call setup(dto, def) after instantiation, where:
|
||
## dto — PlayerCardDto dictionary from collection.get_cards
|
||
## def — CardDefinitionDto from ContentCache.get_definition() (pass {} if absent)
|
||
##
|
||
## Emits card_pressed(definition_id) on tap/click.
|
||
## Call set_selected(true/false) to highlight the card (used by the arch-spirit picker).
|
||
|
||
# ── Colour tables ─────────────────────────────────────────────────────────────
|
||
|
||
const AFFINITY_BORDER := {
|
||
"Fire": Color(0.91, 0.33, 0.13),
|
||
"Water": Color(0.20, 0.53, 1.00),
|
||
"Earth": Color(0.45, 0.69, 0.20),
|
||
"Air": Color(0.53, 0.80, 0.93),
|
||
"Lightning": Color(0.94, 0.88, 0.19),
|
||
"Dark": Color(0.60, 0.25, 0.93),
|
||
"Light": Color(0.97, 0.84, 0.25),
|
||
}
|
||
|
||
const AFFINITY_BG := {
|
||
"Fire": Color(0.54, 0.15, 0.08),
|
||
"Water": Color(0.06, 0.23, 0.43),
|
||
"Earth": Color(0.19, 0.26, 0.08),
|
||
"Air": Color(0.18, 0.34, 0.44),
|
||
"Lightning": Color(0.42, 0.36, 0.03),
|
||
"Dark": Color(0.23, 0.06, 0.38),
|
||
"Light": Color(0.47, 0.38, 0.04),
|
||
}
|
||
|
||
const AFFINITY_SYMBOL := {
|
||
"Fire": "🔥", "Water": "💧", "Earth": "⛰",
|
||
"Air": "💨", "Lightning": "⚡", "Dark": "✦", "Light": "★",
|
||
}
|
||
|
||
const RARITY_COLOR := {
|
||
"Common": Color(0.67, 0.67, 0.67),
|
||
"Uncommon": Color(0.27, 0.85, 0.27),
|
||
"Rare": Color(0.27, 0.53, 1.00),
|
||
"Epic": Color(0.67, 0.27, 1.00),
|
||
"Legendary": Color(1.00, 0.67, 0.13),
|
||
}
|
||
|
||
# ── Signals ───────────────────────────────────────────────────────────────────
|
||
|
||
## Emitted on mouse-click or screen-touch.
|
||
signal card_pressed(definition_id: String)
|
||
|
||
# ── Node refs ─────────────────────────────────────────────────────────────────
|
||
|
||
@onready var sp_label : Label = %SpLabel
|
||
@onready var st_label : Label = %StLabel
|
||
@onready var foil_label : Label = %FoilLabel
|
||
@onready var art_rect : ColorRect = %ArtRect
|
||
@onready var art_symbol : Label = %ArtSymbol
|
||
@onready var name_label : Label = %NameLabel
|
||
@onready var type_label : Label = %TypeLabel
|
||
@onready var rarity_label : Label = %RarityLabel
|
||
@onready var dmg_label : Label = %DmgLabel
|
||
@onready var hp_label : Label = %HpLabel
|
||
@onready var def_label : Label = %DefLabel
|
||
|
||
# ── State ─────────────────────────────────────────────────────────────────────
|
||
|
||
var _affinity : String = ""
|
||
var _definition_id : String = ""
|
||
var _is_selected : bool = false
|
||
|
||
# ── Public API ────────────────────────────────────────────────────────────────
|
||
|
||
## Populate the widget.
|
||
func setup(dto: Dictionary, def: Dictionary = {}) -> void:
|
||
_affinity = str(dto.get("affinity", ""))
|
||
_definition_id = str(dto.get("cardDefinitionId", ""))
|
||
var rarity := str(dto.get("rarity", ""))
|
||
var is_foil := bool(dto.get("isFoil", false))
|
||
|
||
_apply_style()
|
||
|
||
art_rect.color = AFFINITY_BG.get(_affinity, Color(0.18, 0.18, 0.24))
|
||
art_symbol.text = AFFINITY_SYMBOL.get(_affinity, "◇")
|
||
|
||
foil_label.visible = is_foil
|
||
name_label.text = str(dto.get("name", "—"))
|
||
type_label.text = str(dto.get("cardType", ""))
|
||
rarity_label.text = rarity
|
||
rarity_label.modulate = RARITY_COLOR.get(rarity, Color(0.67, 0.67, 0.67))
|
||
|
||
_load_stats(def)
|
||
_load_abilities(def)
|
||
|
||
|
||
## Toggle the selection highlight (arch-spirit picker).
|
||
func set_selected(selected: bool) -> void:
|
||
_is_selected = selected
|
||
_apply_style()
|
||
|
||
|
||
## The cached definition ID this widget represents.
|
||
func get_definition_id() -> String:
|
||
return _definition_id
|
||
|
||
# ── Input ─────────────────────────────────────────────────────────────────────
|
||
|
||
func _gui_input(event: InputEvent) -> void:
|
||
if event is InputEventMouseButton \
|
||
and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||
card_pressed.emit(_definition_id)
|
||
accept_event()
|
||
elif event is InputEventScreenTouch and event.pressed:
|
||
card_pressed.emit(_definition_id)
|
||
accept_event()
|
||
|
||
# ── Visuals ───────────────────────────────────────────────────────────────────
|
||
|
||
func _apply_style() -> void:
|
||
var border: Color
|
||
var width: int
|
||
if _is_selected:
|
||
border = Color(1.0, 1.0, 1.0)
|
||
width = 3
|
||
else:
|
||
border = AFFINITY_BORDER.get(_affinity, Color(0.31, 0.38, 0.63))
|
||
width = 2
|
||
var s := StyleBoxFlat.new()
|
||
s.bg_color = Color(0.09, 0.09, 0.14)
|
||
s.border_color = border
|
||
s.set_border_width_all(width)
|
||
s.set_corner_radius_all(6)
|
||
add_theme_stylebox_override("panel", s)
|
||
|
||
# ── Stats ─────────────────────────────────────────────────────────────────────
|
||
|
||
func _load_stats(def: Dictionary) -> void:
|
||
var sp : Variant = def.get("spCost", null)
|
||
var st : Variant = def.get("stCost", null)
|
||
var dmg : Variant = def.get("damage", null)
|
||
var hp : Variant = def.get("maxHealth", null)
|
||
var dfs : Variant = def.get("maxDefense", null)
|
||
var mov : Variant = def.get("movementPoints", null)
|
||
|
||
sp_label.text = ("◆%s" % str(sp)) if sp != null else "◆?"
|
||
st_label.text = ("⚡%s" % str(st)) if (st != null and int(st) > 0) else ""
|
||
st_label.visible = st != null and int(st) > 0
|
||
|
||
dmg_label.text = "⚔ %s" % (str(dmg) if dmg != null else "–")
|
||
hp_label.text = "♥ %s" % (str(hp) if hp != null else "–")
|
||
def_label.text = "▲ %s" % (str(dfs) if dfs != null else "–")
|
||
|
||
sp_label.tooltip_text = "Spirit Cost"
|
||
st_label.tooltip_text = "Stamina Cost"
|
||
dmg_label.tooltip_text = "Attack Damage" \
|
||
+ (" | Move: %s" % str(mov) if mov != null else "")
|
||
hp_label.tooltip_text = "Max Health"
|
||
def_label.tooltip_text = "Max Defense"
|
||
|
||
|
||
func _load_abilities(def: Dictionary) -> void:
|
||
var json_str := str(def.get("abilitiesJson", ""))
|
||
if json_str.is_empty() or json_str == "[]":
|
||
return
|
||
var parsed: Variant = JSON.parse_string(json_str)
|
||
if typeof(parsed) != TYPE_ARRAY:
|
||
return
|
||
var lines: PackedStringArray = []
|
||
for ab in parsed as Array:
|
||
if typeof(ab) == TYPE_DICTIONARY:
|
||
var d := ab as Dictionary
|
||
var n := str(d.get("name", d.get("Name", "")))
|
||
var t := str(d.get("description", d.get("Description", "")))
|
||
lines.append(("[%s] %s" % [n, t]) if not t.is_empty() else ("[%s]" % n))
|
||
if not lines.is_empty():
|
||
art_rect.tooltip_text = "\n".join(lines)
|