Add card salvage system and player storefront / trading features
Server: - CardSalvageValues: rarity-base + (SpCost+StCost)*CostMultiplier formula, foil 2x - CollectionSalvageCardHandler: collection.salvage_card — validates ownership, tradeable, not listed, deck copy check, then atomically deletes card + credits OP - BazaarGetPlayerShopHandler: bazaar.get_player_shop — paginated active listings for any seller with their display name (public read endpoint) - BazaarGetSuggestedPriceHandler: bazaar.get_suggested_price — recent sale avg if ≥3 sales, otherwise 4× salvage floor - Added GetPlayerShopRequest/Response + GetSuggestedPriceRequest/Response DTOs - Added SalvageCardRequest/Response DTOs - Registered all 3 new handlers in their respective ServiceRegistration files Client: - card_detail_popup: List for Sale form (with live price suggestion) + Salvage button with OP preview; both gated on IsTradeable - salvage_confirm_popup: confirmation modal that calls collection.salvage_card, emits confirmed(player_card_id, op_awarded) on success - bazaar_screen: My Shop tab (own active listings + cancel), player storefront search by account ID, sort options for own listings 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:
@@ -1,9 +1,10 @@
|
||||
extends VBoxContainer
|
||||
## Bazaar — Boosters, Decks, Cosmetics, and Cards marketplace.
|
||||
## Bazaar — Boosters, Decks, Cosmetics, Cards marketplace, and My Shop.
|
||||
##
|
||||
## Four tabs each with sort controls. The Cards tab additionally has
|
||||
## rarity/type filters and loads from the P2P marketplace.
|
||||
## Origin Points purchases are live. USD prices are shown but disabled.
|
||||
## Five tabs with sort/filter controls.
|
||||
## Cards tab: P2P marketplace with rarity/type filtering.
|
||||
## My Shop tab: own active listings with cancel + re-list actions, plus a
|
||||
## search field to navigate to another player's storefront.
|
||||
|
||||
const STORE_ITEM_ROW := preload("res://scenes/bazaar/components/StoreItemRow.tscn")
|
||||
|
||||
@@ -11,7 +12,7 @@ const FALLBACK_ART := "https://cdn.aeternalisgames.com/sor-assets/cardart/0_No-C
|
||||
|
||||
const RARITY_ORDER := { "Common": 0, "Uncommon": 1, "Rare": 2, "Epic": 3, "Legendary": 4 }
|
||||
|
||||
enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS }
|
||||
enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS, MY_SHOP }
|
||||
|
||||
# ── Node references ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -22,6 +23,7 @@ enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS }
|
||||
@onready var decks_tab_btn : Button = %DecksTabBtn
|
||||
@onready var cosmetics_tab_btn : Button = %CosmeticsTabBtn
|
||||
@onready var cards_tab_btn : Button = %CardsTabBtn
|
||||
@onready var my_shop_tab_btn : Button = %MyShopTabBtn
|
||||
@onready var sort_option : OptionButton = %SortOption
|
||||
@onready var filter_sep : VSeparator = %FilterSep
|
||||
@onready var rarity_label : Label = %RarityLabel
|
||||
@@ -33,6 +35,10 @@ enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS }
|
||||
@onready var empty_label : Label = %EmptyLabel
|
||||
@onready var confirm_dialog : ConfirmationDialog = %ConfirmDialog
|
||||
@onready var result_dialog : AcceptDialog = %ResultDialog
|
||||
# My Shop tab extras
|
||||
@onready var player_shop_row : HBoxContainer = %PlayerShopRow
|
||||
@onready var player_shop_input : LineEdit = %PlayerShopInput
|
||||
@onready var player_shop_btn : Button = %PlayerShopBtn
|
||||
|
||||
# ── Sort option labels per tab ─────────────────────────────────────────────────
|
||||
|
||||
@@ -41,6 +47,7 @@ const SORT_LABELS := {
|
||||
Tab.DECKS: ["Name A–Z", "Price ↑", "Price ↓", "Cards ↑"],
|
||||
Tab.COSMETICS: ["Name A–Z", "Price ↑", "Price ↓", "Type"],
|
||||
Tab.CARDS: ["Price ↑", "Price ↓", "Name A–Z", "Rarity"],
|
||||
Tab.MY_SHOP: ["Listed ↓", "Price ↑", "Price ↓"],
|
||||
}
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
@@ -50,15 +57,20 @@ var _packs : Array = []
|
||||
var _decks : Array = []
|
||||
var _cosmetics : Array = []
|
||||
var _listings : Array = [] # Cards tab (marketplace)
|
||||
var _my_listings: Array = [] # My Shop tab
|
||||
|
||||
var _store_loaded := false
|
||||
var _bal_loaded := false
|
||||
var _listings_loaded := false
|
||||
var _store_loaded := false
|
||||
var _bal_loaded := false
|
||||
var _listings_loaded := false
|
||||
var _my_shop_loaded := false
|
||||
|
||||
var _pending_item : Dictionary = {}
|
||||
var _buying := false
|
||||
var _pending_item : Dictionary = {}
|
||||
var _pending_cancel_id : String = ""
|
||||
var _buying := false
|
||||
|
||||
var _sort : Dictionary = { Tab.BOOSTERS: 0, Tab.DECKS: 0, Tab.COSMETICS: 0, Tab.CARDS: 0 }
|
||||
var _sort : Dictionary = {
|
||||
Tab.BOOSTERS: 0, Tab.DECKS: 0, Tab.COSMETICS: 0, Tab.CARDS: 0, Tab.MY_SHOP: 0
|
||||
}
|
||||
var _rarity_filter : String = ""
|
||||
var _type_filter : String = ""
|
||||
|
||||
@@ -71,11 +83,13 @@ func _ready() -> void:
|
||||
decks_tab_btn.pressed.connect(func(): _switch_tab(Tab.DECKS))
|
||||
cosmetics_tab_btn.pressed.connect(func(): _switch_tab(Tab.COSMETICS))
|
||||
cards_tab_btn.pressed.connect(func(): _switch_tab(Tab.CARDS))
|
||||
my_shop_tab_btn.pressed.connect(func(): _switch_tab(Tab.MY_SHOP))
|
||||
|
||||
sort_option.item_selected.connect(_on_sort_changed)
|
||||
rarity_option.item_selected.connect(_on_rarity_changed)
|
||||
type_option.item_selected.connect(_on_type_changed)
|
||||
confirm_dialog.confirmed.connect(_on_purchase_confirmed)
|
||||
player_shop_btn.pressed.connect(_on_player_shop_search)
|
||||
|
||||
buy_op_btn.disabled = true # USD flow not yet available
|
||||
|
||||
@@ -154,6 +168,30 @@ func _on_listings_err(code: String, _msg: String) -> void:
|
||||
loading_label.visible = false
|
||||
_render_tab()
|
||||
|
||||
|
||||
func _fetch_my_listings() -> void:
|
||||
_my_shop_loaded = false
|
||||
Network.request(
|
||||
"bazaar.get_my_listings",
|
||||
{ "statusFilter": "Active" },
|
||||
_on_my_listings_ok,
|
||||
_on_my_listings_err
|
||||
)
|
||||
|
||||
|
||||
func _on_my_listings_ok(_t: String, p: Variant) -> void:
|
||||
_my_listings = (p as Dictionary).get("listings", [])
|
||||
_my_shop_loaded = true
|
||||
loading_label.visible = false
|
||||
_render_tab()
|
||||
|
||||
|
||||
func _on_my_listings_err(code: String, _msg: String) -> void:
|
||||
push_warning("Bazaar: get_my_listings failed — %s" % code)
|
||||
_my_shop_loaded = true
|
||||
loading_label.visible = false
|
||||
_render_tab()
|
||||
|
||||
# ── Tabs ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _switch_tab(tab: Tab) -> void:
|
||||
@@ -168,6 +206,13 @@ func _switch_tab(tab: Tab) -> void:
|
||||
_fetch_listings()
|
||||
return
|
||||
|
||||
if tab == Tab.MY_SHOP and not _my_shop_loaded:
|
||||
loading_label.visible = true
|
||||
empty_label.visible = false
|
||||
_clear_list()
|
||||
_fetch_my_listings()
|
||||
return
|
||||
|
||||
if _store_loaded and _bal_loaded:
|
||||
_render_tab()
|
||||
|
||||
@@ -177,6 +222,7 @@ func _apply_tab_styles() -> void:
|
||||
_style_tab(decks_tab_btn, _tab == Tab.DECKS)
|
||||
_style_tab(cosmetics_tab_btn, _tab == Tab.COSMETICS)
|
||||
_style_tab(cards_tab_btn, _tab == Tab.CARDS)
|
||||
_style_tab(my_shop_tab_btn, _tab == Tab.MY_SHOP)
|
||||
|
||||
|
||||
func _style_tab(btn: Button, active: bool) -> void:
|
||||
@@ -200,12 +246,15 @@ func _setup_filter_bar() -> void:
|
||||
sort_option.add_item(lbl)
|
||||
sort_option.selected = _sort[_tab]
|
||||
|
||||
var is_cards := _tab == Tab.CARDS
|
||||
var is_cards := _tab == Tab.CARDS
|
||||
var is_my_shop := _tab == Tab.MY_SHOP
|
||||
filter_sep.visible = is_cards
|
||||
rarity_label.visible = is_cards
|
||||
rarity_option.visible = is_cards
|
||||
type_label.visible = is_cards
|
||||
type_option.visible = is_cards
|
||||
# My Shop: show player shop search row
|
||||
player_shop_row.visible = is_my_shop
|
||||
|
||||
|
||||
func _rebuild_type_filter() -> void:
|
||||
@@ -252,6 +301,7 @@ func _render_tab() -> void:
|
||||
Tab.DECKS: items = _decks.duplicate()
|
||||
Tab.COSMETICS: items = _cosmetics.duplicate()
|
||||
Tab.CARDS: items = _listings.duplicate()
|
||||
Tab.MY_SHOP: items = _my_listings.duplicate()
|
||||
|
||||
items = _sort_items(items)
|
||||
if _tab == Tab.CARDS:
|
||||
@@ -264,9 +314,15 @@ func _render_tab() -> void:
|
||||
item_list.add_child(row)
|
||||
if _tab == Tab.CARDS:
|
||||
row.setup_listing(item, FALLBACK_ART)
|
||||
elif _tab == Tab.MY_SHOP:
|
||||
row.setup_listing(item, FALLBACK_ART)
|
||||
# Override buy button label to "Cancel" for own listings.
|
||||
if row.has_method("set_action_label"):
|
||||
row.set_action_label("Cancel")
|
||||
row.buy_pressed.connect(_on_cancel_listing_pressed)
|
||||
else:
|
||||
row.setup(item, FALLBACK_ART)
|
||||
row.buy_pressed.connect(_on_buy_pressed)
|
||||
row.buy_pressed.connect(_on_buy_pressed)
|
||||
|
||||
|
||||
func _clear_list() -> void:
|
||||
@@ -303,6 +359,11 @@ func _sort_items(items: Array) -> Array:
|
||||
2: items.sort_custom(func(a, b): return a.get("cardName","") < b.get("cardName",""))
|
||||
3: items.sort_custom(func(a, b):
|
||||
return RARITY_ORDER.get(a.get("rarity",""), 99) < RARITY_ORDER.get(b.get("rarity",""), 99))
|
||||
Tab.MY_SHOP:
|
||||
match idx:
|
||||
0: items.sort_custom(func(a, b): return str(a.get("listedAt","")) > str(b.get("listedAt","")))
|
||||
1: items.sort_custom(func(a, b): return float(a.get("price",0)) < float(b.get("price",0)))
|
||||
2: items.sort_custom(func(a, b): return float(a.get("price",0)) > float(b.get("price",0)))
|
||||
return items
|
||||
|
||||
|
||||
@@ -410,6 +471,78 @@ func _show_result(title: String, body: String) -> void:
|
||||
result_dialog.dialog_text = body
|
||||
result_dialog.popup_centered()
|
||||
|
||||
# ── My Shop: cancel listing ────────────────────────────────────────────────────
|
||||
|
||||
func _on_cancel_listing_pressed(item: Dictionary) -> void:
|
||||
var listing_id : String = str(item.get("id", ""))
|
||||
var card_name : String = item.get("cardName", "this listing")
|
||||
_pending_cancel_id = listing_id
|
||||
confirm_dialog.dialog_text = "Cancel listing for \"%s\"?" % card_name
|
||||
confirm_dialog.popup_centered()
|
||||
# Re-route the confirmed signal to the cancel handler for this press.
|
||||
if confirm_dialog.confirmed.is_connected(_on_purchase_confirmed):
|
||||
confirm_dialog.confirmed.disconnect(_on_purchase_confirmed)
|
||||
if not confirm_dialog.confirmed.is_connected(_on_cancel_listing_confirmed):
|
||||
confirm_dialog.confirmed.connect(_on_cancel_listing_confirmed, CONNECT_ONE_SHOT)
|
||||
|
||||
|
||||
func _on_cancel_listing_confirmed() -> void:
|
||||
if _pending_cancel_id.is_empty():
|
||||
return
|
||||
var lid := _pending_cancel_id
|
||||
_pending_cancel_id = ""
|
||||
Network.request(
|
||||
"bazaar.cancel_listing",
|
||||
{ "listingId": lid },
|
||||
func(_t: String, _p: Variant):
|
||||
_my_listings = _my_listings.filter(func(l: Dictionary) -> bool:
|
||||
return str(l.get("id","")) != lid)
|
||||
_render_tab()
|
||||
# Reconnect original confirmed handler.
|
||||
if not confirm_dialog.confirmed.is_connected(_on_purchase_confirmed):
|
||||
confirm_dialog.confirmed.connect(_on_purchase_confirmed),
|
||||
func(code: String, _msg: String):
|
||||
_show_result("Cancel Failed", "Error: %s" % code)
|
||||
if not confirm_dialog.confirmed.is_connected(_on_purchase_confirmed):
|
||||
confirm_dialog.confirmed.connect(_on_purchase_confirmed)
|
||||
)
|
||||
|
||||
# ── My Shop: view another player's storefront ──────────────────────────────────
|
||||
|
||||
func _on_player_shop_search() -> void:
|
||||
var seller_id := player_shop_input.text.strip_edges()
|
||||
if seller_id.is_empty():
|
||||
return
|
||||
loading_label.visible = true
|
||||
_clear_list()
|
||||
Network.request(
|
||||
"bazaar.get_player_shop",
|
||||
{ "sellerAccountId": seller_id, "page": 0, "pageSize": 50 },
|
||||
_on_player_shop_ok,
|
||||
_on_player_shop_err
|
||||
)
|
||||
|
||||
|
||||
func _on_player_shop_ok(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
var name_ := str(d.get("sellerDisplayName", "Player"))
|
||||
var listings: Array = d.get("listings", [])
|
||||
loading_label.visible = false
|
||||
_clear_list()
|
||||
empty_label.visible = listings.is_empty()
|
||||
for item: Dictionary in listings:
|
||||
var row := STORE_ITEM_ROW.instantiate()
|
||||
item_list.add_child(row)
|
||||
row.setup_listing(item, FALLBACK_ART)
|
||||
row.buy_pressed.connect(_on_buy_pressed)
|
||||
# Show whose shop this is.
|
||||
_show_result("%s's Shop" % name_, "%d active listing(s)" % listings.size())
|
||||
|
||||
|
||||
func _on_player_shop_err(code: String, _msg: String) -> void:
|
||||
loading_label.visible = false
|
||||
_show_result("Shop Not Found", "Error: %s" % code)
|
||||
|
||||
# ── Navigation ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _on_back() -> void:
|
||||
|
||||
@@ -6,11 +6,22 @@ extends Control
|
||||
##
|
||||
## Added to the viewport root at runtime by collection_screen.gd so it renders
|
||||
## above the VBoxContainer layout regardless of scene structure.
|
||||
##
|
||||
## Economy actions:
|
||||
## "List for Sale" — opens an inline listing form backed by bazaar.list_card.
|
||||
## "Salvage" — opens salvage_confirm_popup to destroy the card for OP.
|
||||
|
||||
const _CardWidget = preload("res://scenes/collection/components/card_widget.gd")
|
||||
const _StatRow = preload("res://scenes/collection/components/StatRow.tscn")
|
||||
const _AbilityRow = preload("res://scenes/collection/components/AbilityRow.tscn")
|
||||
|
||||
## Emitted after a successful salvage so the parent collection screen can
|
||||
## remove the card from its list without a full reload.
|
||||
signal card_salvaged(player_card_id: String)
|
||||
|
||||
## Emitted after a successful listing so the parent can update UI state.
|
||||
signal card_listed(player_card_id: String)
|
||||
|
||||
const RARITY_COLOR := {
|
||||
"Common": Color(0.67, 0.67, 0.67),
|
||||
"Uncommon": Color(0.27, 0.85, 0.27),
|
||||
@@ -19,6 +30,14 @@ const RARITY_COLOR := {
|
||||
"Legendary": Color(1.00, 0.67, 0.13),
|
||||
}
|
||||
|
||||
# Rarity → OP per combined SP+ST point (mirrors CardSalvageValues server-side).
|
||||
const SALVAGE_BASE := {
|
||||
"Common": 5, "Uncommon": 12, "Rare": 40, "Epic": 120, "Legendary": 300
|
||||
}
|
||||
const SALVAGE_COST_MULT := {
|
||||
"Common": 1, "Uncommon": 2, "Rare": 5, "Epic": 12, "Legendary": 25
|
||||
}
|
||||
|
||||
# ── Node refs ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@onready var overlay : ColorRect = %Overlay
|
||||
@@ -33,33 +52,67 @@ const RARITY_COLOR := {
|
||||
@onready var abilities_sep : HSeparator = %AbilitiesSep
|
||||
@onready var abilities_title: Label = %AbilitiesTitle
|
||||
@onready var abilities_list : VBoxContainer = %AbilitiesList
|
||||
@onready var action_row : HBoxContainer = %ActionRow
|
||||
@onready var list_btn : Button = %ListBtn
|
||||
@onready var salvage_btn : Button = %SalvageBtn
|
||||
@onready var list_form : VBoxContainer = %ListForm
|
||||
@onready var list_price_input : LineEdit = %ListPriceInput
|
||||
@onready var list_type_option : OptionButton = %ListTypeOption
|
||||
@onready var list_submit_btn : Button = %ListSubmitBtn
|
||||
@onready var list_cancel_btn : Button = %ListCancelBtn
|
||||
@onready var list_hint_label : Label = %ListHintLabel
|
||||
@onready var salvage_popup : Control = %SalvageConfirmPopup
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
var _player_card_id : String = ""
|
||||
var _card_name : String = ""
|
||||
var _rarity : String = ""
|
||||
var _is_foil : bool = false
|
||||
var _sp_cost : int = 0
|
||||
var _st_cost : int = 0
|
||||
var _submitting : bool = false
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
overlay.gui_input.connect(_on_overlay_input)
|
||||
close_btn.pressed.connect(hide)
|
||||
list_btn.pressed.connect(_on_list_pressed)
|
||||
salvage_btn.pressed.connect(_on_salvage_pressed)
|
||||
list_submit_btn.pressed.connect(_on_list_submit)
|
||||
list_cancel_btn.pressed.connect(_hide_list_form)
|
||||
list_type_option.add_item("Fixed Price")
|
||||
list_type_option.add_item("Auction")
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
## show_card(dto, def)
|
||||
## dto: PlayerCardDto dict (playerCardId, isFoil, isTradeable, ...)
|
||||
## def: CardDefinition dict merged in by the collection screen (name, rarity, spCost, stCost, ...)
|
||||
func show_card(dto: Dictionary, def: Dictionary) -> void:
|
||||
var affinity := str(dto.get("affinity", ""))
|
||||
var rarity := str(dto.get("rarity", ""))
|
||||
var card_type := str(dto.get("cardType", ""))
|
||||
var is_foil := bool(dto.get("isFoil", false))
|
||||
_player_card_id = str(dto.get("playerCardId", ""))
|
||||
var affinity := str(dto.get("affinity", def.get("affinity", "")))
|
||||
_rarity = str(dto.get("rarity", def.get("rarity", "")))
|
||||
var card_type := str(dto.get("cardType", def.get("cardType", "")))
|
||||
_is_foil = bool(dto.get("isFoil", false))
|
||||
_sp_cost = int(def.get("spCost", 0))
|
||||
_st_cost = int(def.get("stCost", 0))
|
||||
_card_name = str(def.get("name", dto.get("name", "Unknown")))
|
||||
var is_tradeable := bool(dto.get("isTradeable", true))
|
||||
|
||||
# Header
|
||||
name_label.text = str(dto.get("name", "Unknown"))
|
||||
name_label.text = _card_name
|
||||
affinity_icon.texture = _CardWidget.affinity_icon(affinity)
|
||||
affinity_icon.modulate = _CardWidget.AFFINITY_BORDER.get(affinity, Color.WHITE)
|
||||
foil_badge.visible = is_foil
|
||||
foil_badge.visible = _is_foil
|
||||
|
||||
# Tags
|
||||
type_label.text = card_type
|
||||
affinity_label.text = affinity
|
||||
affinity_label.modulate = _CardWidget.AFFINITY_BORDER.get(affinity, Color.WHITE)
|
||||
rarity_label.text = rarity
|
||||
rarity_label.modulate = RARITY_COLOR.get(rarity, Color(0.67, 0.67, 0.67))
|
||||
rarity_label.text = _rarity
|
||||
rarity_label.modulate = RARITY_COLOR.get(_rarity, Color(0.67, 0.67, 0.67))
|
||||
|
||||
# Stats grid
|
||||
_populate_stats(def)
|
||||
@@ -67,8 +120,119 @@ func show_card(dto: Dictionary, def: Dictionary) -> void:
|
||||
# Abilities
|
||||
_populate_abilities(def)
|
||||
|
||||
# Economy buttons — only tradeable cards can be listed or salvaged.
|
||||
action_row.visible = is_tradeable
|
||||
list_btn.visible = is_tradeable
|
||||
salvage_btn.visible = is_tradeable
|
||||
if is_tradeable:
|
||||
var op := _calc_salvage_op()
|
||||
salvage_btn.text = "Salvage (%d OP)" % op
|
||||
|
||||
_hide_list_form()
|
||||
show()
|
||||
|
||||
# ── Economy helpers ───────────────────────────────────────────────────────────
|
||||
|
||||
func _calc_salvage_op() -> int:
|
||||
var base_val : int = SALVAGE_BASE.get(_rarity, 5)
|
||||
var mult : int = SALVAGE_COST_MULT.get(_rarity, 1)
|
||||
var value : int = base_val + (_sp_cost + _st_cost) * mult
|
||||
return value * 2 if _is_foil else value
|
||||
|
||||
|
||||
func _on_list_pressed() -> void:
|
||||
list_form.visible = true
|
||||
list_btn.visible = false
|
||||
# Fetch suggested price in the background; populate when it arrives.
|
||||
list_price_input.placeholder_text = "Loading suggestion..."
|
||||
list_hint_label.text = ""
|
||||
Network.request(
|
||||
"bazaar.get_suggested_price",
|
||||
{ "cardDefinitionId": str(def.get("cardDefinitionId", "")), "isFoil": _is_foil },
|
||||
_on_price_suggestion_ok,
|
||||
_on_price_suggestion_err
|
||||
)
|
||||
|
||||
|
||||
func _on_price_suggestion_ok(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
var suggested := float(d.get("suggestedPrice", 0))
|
||||
list_price_input.text = str(int(suggested))
|
||||
list_price_input.placeholder_text = ""
|
||||
var sale_count : int = int(d.get("saleCount", 0))
|
||||
if sale_count >= 3:
|
||||
list_hint_label.text = "Based on %d recent sales" % sale_count
|
||||
else:
|
||||
list_hint_label.text = "Suggested floor (no sale history)"
|
||||
|
||||
|
||||
func _on_price_suggestion_err(_code: String, _msg: String) -> void:
|
||||
var floor_op := _calc_salvage_op() * 4
|
||||
list_price_input.text = str(floor_op)
|
||||
list_price_input.placeholder_text = ""
|
||||
list_hint_label.text = "Using salvage-based floor"
|
||||
|
||||
|
||||
func _hide_list_form() -> void:
|
||||
list_form.visible = false
|
||||
list_btn.visible = true
|
||||
_submitting = false
|
||||
|
||||
|
||||
func _on_list_submit() -> void:
|
||||
if _submitting or _player_card_id.is_empty():
|
||||
return
|
||||
var price_str := list_price_input.text.strip_edges()
|
||||
if not price_str.is_valid_int() and not price_str.is_valid_float():
|
||||
list_hint_label.text = "Enter a valid price."
|
||||
return
|
||||
var price := float(price_str)
|
||||
if price <= 0:
|
||||
list_hint_label.text = "Price must be greater than 0."
|
||||
return
|
||||
|
||||
_submitting = true
|
||||
list_submit_btn.disabled = true
|
||||
list_hint_label.text = "Listing..."
|
||||
|
||||
var listing_type : String = "Fixed" if list_type_option.selected == 0 else "Auction"
|
||||
Network.request(
|
||||
"bazaar.list_card",
|
||||
{
|
||||
"playerCardId": _player_card_id,
|
||||
"price": price,
|
||||
"listingType": listing_type,
|
||||
"isMasked": false,
|
||||
},
|
||||
_on_list_ok,
|
||||
_on_list_err
|
||||
)
|
||||
|
||||
|
||||
func _on_list_ok(_t: String, _p: Variant) -> void:
|
||||
list_hint_label.text = "Listed successfully!"
|
||||
card_listed.emit(_player_card_id)
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
hide()
|
||||
|
||||
|
||||
func _on_list_err(code: String, _msg: String) -> void:
|
||||
_submitting = false
|
||||
list_submit_btn.disabled = false
|
||||
list_hint_label.text = "Error: %s" % code
|
||||
|
||||
|
||||
func _on_salvage_pressed() -> void:
|
||||
if _player_card_id.is_empty():
|
||||
return
|
||||
salvage_popup.show_confirm(_player_card_id, _card_name, _rarity, _is_foil, _calc_salvage_op())
|
||||
salvage_popup.confirmed.connect(_on_salvage_confirmed, CONNECT_ONE_SHOT)
|
||||
|
||||
|
||||
func _on_salvage_confirmed(player_card_id: String, op_awarded: int) -> void:
|
||||
card_salvaged.emit(player_card_id)
|
||||
hide()
|
||||
|
||||
|
||||
# ── Private ───────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
extends Control
|
||||
## Salvage confirmation popup.
|
||||
##
|
||||
## Call show_confirm(...) to populate and display.
|
||||
## Emits confirmed(player_card_id, op_awarded) on success.
|
||||
## Emits cancelled() if the player backs out.
|
||||
##
|
||||
## The popup sends collection.salvage_card to the server and only emits
|
||||
## confirmed after a successful response, so the caller never needs to
|
||||
## handle partial state.
|
||||
|
||||
signal confirmed(player_card_id: String, op_awarded: int)
|
||||
signal cancelled
|
||||
|
||||
# ── Node refs ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@onready var overlay : ColorRect = %Overlay
|
||||
@onready var card_name_lbl: Label = %CardNameLbl
|
||||
@onready var rarity_lbl : Label = %RarityLbl
|
||||
@onready var foil_lbl : Label = %FoilLbl
|
||||
@onready var reward_lbl : Label = %RewardLbl
|
||||
@onready var confirm_btn : Button = %ConfirmBtn
|
||||
@onready var cancel_btn : Button = %CancelBtn
|
||||
@onready var status_lbl : Label = %StatusLbl
|
||||
|
||||
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),
|
||||
}
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
var _player_card_id : String = ""
|
||||
var _op_preview : int = 0
|
||||
var _busy : bool = false
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
confirm_btn.pressed.connect(_on_confirm)
|
||||
cancel_btn.pressed.connect(_on_cancel)
|
||||
overlay.gui_input.connect(_on_overlay_input)
|
||||
hide()
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
func show_confirm(
|
||||
player_card_id : String,
|
||||
card_name : String,
|
||||
rarity : String,
|
||||
is_foil : bool,
|
||||
op_preview : int) -> void:
|
||||
_player_card_id = player_card_id
|
||||
_op_preview = op_preview
|
||||
_busy = false
|
||||
confirm_btn.disabled = false
|
||||
status_lbl.text = "This cannot be undone."
|
||||
|
||||
card_name_lbl.text = card_name
|
||||
rarity_lbl.text = rarity
|
||||
rarity_lbl.modulate = RARITY_COLOR.get(rarity, Color.WHITE)
|
||||
foil_lbl.visible = is_foil
|
||||
reward_lbl.text = "You will receive ◆ %d OP" % op_preview
|
||||
|
||||
show()
|
||||
|
||||
# ── Handlers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
func _on_confirm() -> void:
|
||||
if _busy or _player_card_id.is_empty():
|
||||
return
|
||||
_busy = true
|
||||
confirm_btn.disabled = true
|
||||
status_lbl.text = "Salvaging..."
|
||||
|
||||
Network.request(
|
||||
"collection.salvage_card",
|
||||
{ "playerCardId": _player_card_id },
|
||||
_on_ok,
|
||||
_on_err
|
||||
)
|
||||
|
||||
|
||||
func _on_ok(_t: String, p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
var op_awarded : int = int(d.get("originPointsAwarded", _op_preview))
|
||||
status_lbl.text = "Done! ◆ %d OP awarded." % op_awarded
|
||||
await get_tree().create_timer(0.8).timeout
|
||||
confirmed.emit(_player_card_id, op_awarded)
|
||||
hide()
|
||||
|
||||
|
||||
func _on_err(code: String, _msg: String) -> void:
|
||||
_busy = false
|
||||
confirm_btn.disabled = false
|
||||
status_lbl.text = "Error: %s" % code
|
||||
|
||||
|
||||
func _on_cancel() -> void:
|
||||
if _busy:
|
||||
return
|
||||
cancelled.emit()
|
||||
hide()
|
||||
|
||||
|
||||
func _on_overlay_input(event: InputEvent) -> void:
|
||||
if _busy:
|
||||
return
|
||||
if event is InputEventMouseButton and event.pressed:
|
||||
_on_cancel()
|
||||
elif event is InputEventScreenTouch and event.pressed:
|
||||
_on_cancel()
|
||||
Reference in New Issue
Block a user