Files
sor/Client/origin-client/scenes/collection/components/card_widget.gd
T
3c4908eec6 client: remember me, SVG affinity icons, card detail popup
Remember Me (login screen):
- AES-256-CBC encrypted credential storage in user://creds.dat
- Key XOR-obfuscated across two halves; random IV stored with ciphertext
- Checkbox pre-fills email/password on next launch; unchecking clears saved creds

SVG affinity icons (web-compatible):
- Replace emoji art symbols (🔥💧⛰💨⚡✦★) with SVG TextureRect in CardWidget
- 7 new icons/affinity_*.svg — monochrome white, modulate-tinted at runtime
- ArtSymbol node changed from Label to TextureRect (stretch_mode = keep-aspect-centred)

Card detail popup (collection screen):
- Tap any card in Cards tab to see full stats + abilities overlay
- CardDetailPopup added to viewport root (avoids VBoxContainer layout conflict)
- Shows: name, affinity icon, foil badge, type/affinity/rarity, all 6 stats,
  and parsed ability list with names + descriptions
- Dismiss by tapping ✕ or the dim background overlay

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>
2026-03-02 07:12:26 -05:00

181 lines
7.3 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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_ICONS := {
"Fire": preload("res://icons/affinity_fire.svg"),
"Water": preload("res://icons/affinity_water.svg"),
"Earth": preload("res://icons/affinity_earth.svg"),
"Air": preload("res://icons/affinity_air.svg"),
"Lightning": preload("res://icons/affinity_lightning.svg"),
"Dark": preload("res://icons/affinity_dark.svg"),
"Light": preload("res://icons/affinity_light.svg"),
}
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 : TextureRect = %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.texture = AFFINITY_ICONS.get(_affinity, null)
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)