Build Bazaar: 4 tabs, sort/filter, art images, USD disabled

- Add Boosters, Decks, Cosmetics, Cards (marketplace) tabs
- Sort per-tab: name, price, card count, type, set (boosters)
- Cards tab: filter by rarity and card type, sort by price/rarity/name
- StoreItemRow gets 72x72 art TextureRect with async HTTP image loading;
  falls back to cdn.aeternalisgames.com/sor-assets/cardart/0_No-Card-Art.jpg
- USD prices shown as greyed "$X.XX (coming soon)" — buy disabled
- "Buy OP" button in header present but disabled (USD flow not yet live)
- setup_listing() on StoreItemRow handles marketplace card listings
  with auction bid count, current bid, and Bid/Buy button labels

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-03-06 17:46:07 -05:00
co-authored by Claude Happy
parent 9dadeda7c1
commit c4ef720570
4 changed files with 525 additions and 144 deletions
@@ -9,6 +9,7 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
theme_override_constants/separation = 0
script = ExtResource("1_bs") script = ExtResource("1_bs")
[node name="TopBarMargin" type="MarginContainer" parent="."] [node name="TopBarMargin" type="MarginContainer" parent="."]
@@ -46,44 +47,135 @@ vertical_alignment = 1
modulate = Color(0.95, 0.85, 0.30, 1.0) modulate = Color(0.95, 0.85, 0.30, 1.0)
theme_override_font_sizes/font_size = 14 theme_override_font_sizes/font_size = 14
[node name="HSeparator" type="HSeparator" parent="."] [node name="BuyOpBtn" type="Button" parent="TopBarMargin/TopBar"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(100, 32)
disabled = true
text = "+ Buy OP"
tooltip_text = "Purchase Origin Points with real money — coming soon"
theme_override_font_sizes/font_size = 12
modulate = Color(0.95, 0.85, 0.30, 0.5)
[node name="HSep1" type="HSeparator" parent="."]
layout_mode = 2 layout_mode = 2
[node name="TabBarMargin" type="MarginContainer" parent="."] [node name="TabBarMargin" type="MarginContainer" parent="."]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 16 theme_override_constants/margin_left = 12
theme_override_constants/margin_right = 16 theme_override_constants/margin_right = 12
theme_override_constants/margin_top = 6 theme_override_constants/margin_top = 4
theme_override_constants/margin_bottom = 6 theme_override_constants/margin_bottom = 4
[node name="TabBar" type="HBoxContainer" parent="TabBarMargin"] [node name="TabBar" type="HBoxContainer" parent="TabBarMargin"]
layout_mode = 2 layout_mode = 2
custom_minimum_size = Vector2(0, 36) custom_minimum_size = Vector2(0, 34)
theme_override_constants/separation = 8 theme_override_constants/separation = 6
[node name="PacksTabBtn" type="Button" parent="TabBarMargin/TabBar"] [node name="BoostersTabBtn" type="Button" parent="TabBarMargin/TabBar"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
custom_minimum_size = Vector2(0, 36) custom_minimum_size = Vector2(0, 34)
text = "Packs" text = "Boosters"
theme_override_font_sizes/font_size = 14 theme_override_font_sizes/font_size = 13
[node name="DecksTabBtn" type="Button" parent="TabBarMargin/TabBar"] [node name="DecksTabBtn" type="Button" parent="TabBarMargin/TabBar"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
custom_minimum_size = Vector2(0, 36) custom_minimum_size = Vector2(0, 34)
text = "Decks" text = "Decks"
theme_override_font_sizes/font_size = 14 theme_override_font_sizes/font_size = 13
[node name="CosmeticsTabBtn" type="Button" parent="TabBarMargin/TabBar"] [node name="CosmeticsTabBtn" type="Button" parent="TabBarMargin/TabBar"]
unique_name_in_owner = true unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
custom_minimum_size = Vector2(0, 36) custom_minimum_size = Vector2(0, 34)
text = "Cosmetics" text = "Cosmetics"
theme_override_font_sizes/font_size = 14 theme_override_font_sizes/font_size = 13
[node name="CardsTabBtn" type="Button" parent="TabBarMargin/TabBar"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
custom_minimum_size = Vector2(0, 34)
text = "Cards"
theme_override_font_sizes/font_size = 13
[node name="HSep2" type="HSeparator" parent="."]
layout_mode = 2
[node name="FilterBarMargin" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 12
theme_override_constants/margin_right = 12
theme_override_constants/margin_top = 4
theme_override_constants/margin_bottom = 4
[node name="FilterBar" type="HBoxContainer" parent="FilterBarMargin"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(0, 30)
theme_override_constants/separation = 8
[node name="SortLabel" type="Label" parent="FilterBarMargin/FilterBar"]
layout_mode = 2
text = "Sort:"
vertical_alignment = 1
theme_override_font_sizes/font_size = 12
modulate = Color(0.7, 0.7, 0.75, 1.0)
[node name="SortOption" type="OptionButton" parent="FilterBarMargin/FilterBar"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(130, 28)
theme_override_font_sizes/font_size = 12
[node name="FilterSep" type="VSeparator" parent="FilterBarMargin/FilterBar"]
unique_name_in_owner = true
layout_mode = 2
visible = false
[node name="RarityLabel" type="Label" parent="FilterBarMargin/FilterBar"]
unique_name_in_owner = true
layout_mode = 2
text = "Rarity:"
vertical_alignment = 1
visible = false
theme_override_font_sizes/font_size = 12
modulate = Color(0.7, 0.7, 0.75, 1.0)
[node name="RarityOption" type="OptionButton" parent="FilterBarMargin/FilterBar"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(110, 28)
visible = false
theme_override_font_sizes/font_size = 12
[node name="TypeLabel" type="Label" parent="FilterBarMargin/FilterBar"]
unique_name_in_owner = true
layout_mode = 2
text = "Type:"
vertical_alignment = 1
visible = false
theme_override_font_sizes/font_size = 12
modulate = Color(0.7, 0.7, 0.75, 1.0)
[node name="TypeOption" type="OptionButton" parent="FilterBarMargin/FilterBar"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(110, 28)
visible = false
theme_override_font_sizes/font_size = 12
[node name="FilterSpacer" type="Control" parent="FilterBarMargin/FilterBar"]
layout_mode = 2
size_flags_horizontal = 3
[node name="HSep3" type="HSeparator" parent="."]
layout_mode = 2
[node name="Scroll" type="ScrollContainer" parent="."] [node name="Scroll" type="ScrollContainer" parent="."]
layout_mode = 2 layout_mode = 2
@@ -93,8 +185,8 @@ horizontal_scroll_mode = 0
[node name="ItemListMargin" type="MarginContainer" parent="Scroll"] [node name="ItemListMargin" type="MarginContainer" parent="Scroll"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
theme_override_constants/margin_left = 8 theme_override_constants/margin_left = 10
theme_override_constants/margin_right = 8 theme_override_constants/margin_right = 10
theme_override_constants/margin_top = 8 theme_override_constants/margin_top = 8
theme_override_constants/margin_bottom = 8 theme_override_constants/margin_bottom = 8
@@ -1,52 +1,84 @@
extends VBoxContainer extends VBoxContainer
## Bazaar — browse and purchase store packs, decks, and cosmetics. ## Bazaar — Boosters, Decks, Cosmetics, and Cards marketplace.
## ##
## Loads the store catalogue and the player's OriginPoints balance in ## Four tabs each with sort controls. The Cards tab additionally has
## parallel on entry. Three tab buttons filter the item list. Each ## rarity/type filters and loads from the P2P marketplace.
## row's Buy button opens a confirmation dialog; on confirmation the ## Origin Points purchases are live. USD prices are shown but disabled.
## appropriate purchase request is sent to the server. Pack purchases
## display the opened-card list; deck/cosmetic purchases show a notice.
const STORE_ITEM_ROW := preload("res://scenes/bazaar/components/StoreItemRow.tscn") const STORE_ITEM_ROW := preload("res://scenes/bazaar/components/StoreItemRow.tscn")
const FALLBACK_ART := "https://cdn.aeternalisgames.com/sor-assets/cardart/0_No-Card-Art.jpg"
const RARITY_ORDER := { "Common": 0, "Uncommon": 1, "Rare": 2, "Epic": 3, "Legendary": 4 }
enum Tab { BOOSTERS, DECKS, COSMETICS, CARDS }
# ── Node references ──────────────────────────────────────────────────────────── # ── Node references ────────────────────────────────────────────────────────────
@onready var back_btn : Button = %BackBtn @onready var back_btn : Button = %BackBtn
@onready var balance_label : Label = %BalanceLabel @onready var balance_label : Label = %BalanceLabel
@onready var packs_tab_btn : Button = %PacksTabBtn @onready var buy_op_btn : Button = %BuyOpBtn
@onready var boosters_tab_btn : Button = %BoostersTabBtn
@onready var decks_tab_btn : Button = %DecksTabBtn @onready var decks_tab_btn : Button = %DecksTabBtn
@onready var cosmetics_tab_btn : Button = %CosmeticsTabBtn @onready var cosmetics_tab_btn : Button = %CosmeticsTabBtn
@onready var cards_tab_btn : Button = %CardsTabBtn
@onready var sort_option : OptionButton = %SortOption
@onready var filter_sep : VSeparator = %FilterSep
@onready var rarity_label : Label = %RarityLabel
@onready var rarity_option : OptionButton = %RarityOption
@onready var type_label : Label = %TypeLabel
@onready var type_option : OptionButton = %TypeOption
@onready var item_list : VBoxContainer = %ItemList @onready var item_list : VBoxContainer = %ItemList
@onready var loading_label : Label = %LoadingLabel @onready var loading_label : Label = %LoadingLabel
@onready var empty_label : Label = %EmptyLabel @onready var empty_label : Label = %EmptyLabel
@onready var confirm_dialog : ConfirmationDialog = %ConfirmDialog @onready var confirm_dialog : ConfirmationDialog = %ConfirmDialog
@onready var result_dialog : AcceptDialog = %ResultDialog @onready var result_dialog : AcceptDialog = %ResultDialog
# ── Sort option labels per tab ─────────────────────────────────────────────────
const SORT_LABELS := {
Tab.BOOSTERS: ["Name A–Z", "Price ↑", "Price ↓", "Cards ↑", "Set"],
Tab.DECKS: ["Name A–Z", "Price ↑", "Price ↓", "Cards ↑"],
Tab.COSMETICS: ["Name A–Z", "Price ↑", "Price ↓", "Type"],
Tab.CARDS: ["Price ↑", "Price ↓", "Name A–Z", "Rarity"],
}
# ── State ───────────────────────────────────────────────────────────────────── # ── State ─────────────────────────────────────────────────────────────────────
var _tab: int = 0 var _tab : Tab = Tab.BOOSTERS
var _packs: Array = [] var _packs : Array = []
var _decks: Array = [] var _decks : Array = []
var _cosmetics: Array = [] var _cosmetics : Array = []
var _store_loaded: bool = false var _listings : Array = [] # Cards tab (marketplace)
var _bal_loaded: bool = false
var _pending_item: Dictionary = {} var _store_loaded := false
var _buying: bool = false var _bal_loaded := false
var _listings_loaded := false
var _pending_item : Dictionary = {}
var _buying := false
var _sort : Dictionary = { Tab.BOOSTERS: 0, Tab.DECKS: 0, Tab.COSMETICS: 0, Tab.CARDS: 0 }
var _rarity_filter : String = ""
var _type_filter : String = ""
# ── Lifecycle ───────────────────────────────────────────────────────────────── # ── Lifecycle ─────────────────────────────────────────────────────────────────
func _ready() -> void: func _ready() -> void:
back_btn.pressed.connect(_on_back) back_btn.pressed.connect(_on_back)
packs_tab_btn.pressed.connect(func(): _switch_tab(0)) boosters_tab_btn.pressed.connect(func(): _switch_tab(Tab.BOOSTERS))
decks_tab_btn.pressed.connect(func(): _switch_tab(1)) decks_tab_btn.pressed.connect(func(): _switch_tab(Tab.DECKS))
cosmetics_tab_btn.pressed.connect(func(): _switch_tab(2)) cosmetics_tab_btn.pressed.connect(func(): _switch_tab(Tab.COSMETICS))
cards_tab_btn.pressed.connect(func(): _switch_tab(Tab.CARDS))
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) confirm_dialog.confirmed.connect(_on_purchase_confirmed)
_apply_tab_style(packs_tab_btn, true) buy_op_btn.disabled = true # USD flow not yet available
_apply_tab_style(decks_tab_btn, false)
_apply_tab_style(cosmetics_tab_btn, false)
_apply_tab_styles()
loading_label.visible = true loading_label.visible = true
empty_label.visible = false empty_label.visible = false
@@ -61,88 +93,237 @@ func _fetch_data() -> void:
Network.request("bazaar.get_my_balance", {}, _on_balance_ok, _on_balance_err) Network.request("bazaar.get_my_balance", {}, _on_balance_ok, _on_balance_err)
func _on_store_ok(_type: String, p: Dictionary) -> void: func _fetch_listings() -> void:
_packs = p.get("packs", []) _listings_loaded = false
_decks = p.get("decks", []) Network.request(
_cosmetics = p.get("cosmetics", []) "bazaar.get_listings",
{ "page": 1, "pageSize": 50 },
_on_listings_ok,
_on_listings_err
)
func _on_store_ok(_t: String, p: Variant) -> void:
var d := p as Dictionary
_packs = d.get("packs", [])
_decks = d.get("decks", [])
_cosmetics = d.get("cosmetics", [])
_store_loaded = true _store_loaded = true
_check_done() _check_store_done()
func _on_store_err(code: String, _msg: String) -> void: func _on_store_err(code: String, _msg: String) -> void:
push_warning("Bazaar: get_store failed — %s" % code) push_warning("Bazaar: get_store failed — %s" % code)
_store_loaded = true _store_loaded = true
_check_done() _check_store_done()
func _on_balance_ok(_type: String, p: Dictionary) -> void: func _on_balance_ok(_t: String, p: Variant) -> void:
balance_label.text = "◆ %d OP" % int(p.get("originPoints", 0)) balance_label.text = "◆ %d OP" % int((p as Dictionary).get("originPoints", 0))
_bal_loaded = true _bal_loaded = true
_check_done() _check_store_done()
func _on_balance_err(code: String, _msg: String) -> void: func _on_balance_err(code: String, _msg: String) -> void:
push_warning("Bazaar: get_my_balance failed — %s" % code) push_warning("Bazaar: balance failed — %s" % code)
balance_label.text = "◆ — OP" balance_label.text = "◆ — OP"
_bal_loaded = true _bal_loaded = true
_check_done() _check_store_done()
func _check_done() -> void: func _check_store_done() -> void:
if not (_store_loaded and _bal_loaded): if not (_store_loaded and _bal_loaded):
return return
loading_label.visible = false loading_label.visible = false
_setup_filter_bar()
_render_tab()
func _on_listings_ok(_t: String, p: Variant) -> void:
_listings = (p as Dictionary).get("listings", [])
_listings_loaded = true
_rebuild_type_filter()
loading_label.visible = false
_render_tab()
func _on_listings_err(code: String, _msg: String) -> void:
push_warning("Bazaar: get_listings failed — %s" % code)
_listings_loaded = true
loading_label.visible = false
_render_tab() _render_tab()
# ── Tabs ────────────────────────────────────────────────────────────────────── # ── Tabs ──────────────────────────────────────────────────────────────────────
func _switch_tab(index: int) -> void: func _switch_tab(tab: Tab) -> void:
_tab = index _tab = tab
_apply_tab_style(packs_tab_btn, index == 0) _apply_tab_styles()
_apply_tab_style(decks_tab_btn, index == 1) _setup_filter_bar()
_apply_tab_style(cosmetics_tab_btn, index == 2)
if tab == Tab.CARDS and not _listings_loaded:
loading_label.visible = true
empty_label.visible = false
_clear_list()
_fetch_listings()
return
if _store_loaded and _bal_loaded: if _store_loaded and _bal_loaded:
_render_tab() _render_tab()
func _apply_tab_style(btn: Button, active: bool) -> void: func _apply_tab_styles() -> void:
var style := StyleBoxFlat.new() _style_tab(boosters_tab_btn, _tab == Tab.BOOSTERS)
style.corner_radius_top_left = 6 _style_tab(decks_tab_btn, _tab == Tab.DECKS)
style.corner_radius_top_right = 6 _style_tab(cosmetics_tab_btn, _tab == Tab.COSMETICS)
style.corner_radius_bottom_left = 6 _style_tab(cards_tab_btn, _tab == Tab.CARDS)
style.corner_radius_bottom_right = 6
style.bg_color = Color(0.27, 0.47, 0.80, 1.0) if active else Color(0.18, 0.18, 0.26, 1.0)
btn.add_theme_stylebox_override("normal", style)
btn.add_theme_stylebox_override("hover", style)
btn.add_theme_stylebox_override("pressed", style)
func _style_tab(btn: Button, active: bool) -> void:
var s := StyleBoxFlat.new()
s.corner_radius_top_left = 6
s.corner_radius_top_right = 6
s.corner_radius_bottom_left = 6
s.corner_radius_bottom_right = 6
s.bg_color = Color(0.27, 0.47, 0.80, 1.0) if active else Color(0.18, 0.18, 0.26, 1.0)
s.border_width_bottom = 2 if active else 0
s.border_color = Color(0.5, 0.72, 1.0)
btn.add_theme_stylebox_override("normal", s)
btn.add_theme_stylebox_override("hover", s)
btn.add_theme_stylebox_override("pressed", s)
# ── Filter / sort bar ─────────────────────────────────────────────────────────
func _setup_filter_bar() -> void:
sort_option.clear()
for lbl: String in (SORT_LABELS as Dictionary)[_tab]:
sort_option.add_item(lbl)
sort_option.selected = _sort[_tab]
var is_cards := _tab == Tab.CARDS
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
func _rebuild_type_filter() -> void:
var types := PackedStringArray()
for l: Dictionary in _listings:
var t: String = l.get("cardType", "")
if not t.is_empty() and t not in types:
types.append(t)
types.sort()
type_option.clear()
type_option.add_item("All Types")
for t: String in types:
type_option.add_item(t)
rarity_option.clear()
rarity_option.add_item("All Rarities")
for r: String in ["Common", "Uncommon", "Rare", "Epic", "Legendary"]:
rarity_option.add_item(r)
func _on_sort_changed(idx: int) -> void:
_sort[_tab] = idx
_render_tab()
func _on_rarity_changed(idx: int) -> void:
_rarity_filter = "" if idx == 0 else rarity_option.get_item_text(idx)
_render_tab()
func _on_type_changed(idx: int) -> void:
_type_filter = "" if idx == 0 else type_option.get_item_text(idx)
_render_tab()
# ── Render ────────────────────────────────────────────────────────────────────
func _render_tab() -> void: func _render_tab() -> void:
for child in item_list.get_children(): _clear_list()
child.queue_free()
var items: Array var items: Array
match _tab: match _tab:
0: items = _packs Tab.BOOSTERS: items = _packs.duplicate()
1: items = _decks Tab.DECKS: items = _decks.duplicate()
2: items = _cosmetics Tab.COSMETICS: items = _cosmetics.duplicate()
_: items = [] Tab.CARDS: items = _listings.duplicate()
items = _sort_items(items)
if _tab == Tab.CARDS:
items = _filter_cards(items)
empty_label.visible = items.is_empty() empty_label.visible = items.is_empty()
for item in items: for item: Dictionary in items:
var row = STORE_ITEM_ROW.instantiate() var row := STORE_ITEM_ROW.instantiate()
item_list.add_child(row) item_list.add_child(row)
row.setup(item) if _tab == Tab.CARDS:
row.setup_listing(item, FALLBACK_ART)
else:
row.setup(item, FALLBACK_ART)
row.buy_pressed.connect(_on_buy_pressed) row.buy_pressed.connect(_on_buy_pressed)
func _clear_list() -> void:
for c in item_list.get_children():
c.queue_free()
func _sort_items(items: Array) -> Array:
var idx: int = _sort[_tab]
match _tab:
Tab.BOOSTERS:
match idx:
0: items.sort_custom(func(a, b): return a.get("name","") < b.get("name",""))
1: items.sort_custom(func(a, b): return a.get("originPointPrice",0) < b.get("originPointPrice",0))
2: items.sort_custom(func(a, b): return a.get("originPointPrice",0) > b.get("originPointPrice",0))
3: items.sort_custom(func(a, b): return a.get("totalSlots",0) < b.get("totalSlots",0))
4: items.sort_custom(func(a, b): return str(a.get("cardSetId","")) < str(b.get("cardSetId","")))
Tab.DECKS:
match idx:
0: items.sort_custom(func(a, b): return a.get("name","") < b.get("name",""))
1: items.sort_custom(func(a, b): return a.get("originPointPrice",0) < b.get("originPointPrice",0))
2: items.sort_custom(func(a, b): return a.get("originPointPrice",0) > b.get("originPointPrice",0))
3: items.sort_custom(func(a, b): return a.get("totalCards",0) < b.get("totalCards",0))
Tab.COSMETICS:
match idx:
0: items.sort_custom(func(a, b): return a.get("name","") < b.get("name",""))
1: items.sort_custom(func(a, b): return a.get("originPointPrice",0) < b.get("originPointPrice",0))
2: items.sort_custom(func(a, b): return a.get("originPointPrice",0) > b.get("originPointPrice",0))
3: items.sort_custom(func(a, b): return a.get("cosmeticType","") < b.get("cosmeticType",""))
Tab.CARDS:
match idx:
0: items.sort_custom(func(a, b): return float(a.get("price",0)) < float(b.get("price",0)))
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 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))
return items
func _filter_cards(items: Array) -> Array:
return items.filter(func(item: Dictionary) -> bool:
if not _rarity_filter.is_empty() and item.get("rarity","") != _rarity_filter:
return false
if not _type_filter.is_empty() and item.get("cardType","") != _type_filter:
return false
return true)
# ── Purchase flow ───────────────────────────────────────────────────────────── # ── Purchase flow ─────────────────────────────────────────────────────────────
func _on_buy_pressed(item: Dictionary) -> void: func _on_buy_pressed(item: Dictionary) -> void:
_pending_item = item _pending_item = item
var name_str : String = item.get("name", "?") var name_str : String = item.get("name", item.get("cardName", "?"))
var price : int = int(item.get("originPointPrice", 0)) var price_str : String
confirm_dialog.dialog_text = "Buy \"%s\" for ◆ %d OP?" % [name_str, price] if _tab == Tab.CARDS:
price_str = "◆ %d OP" % int(float(item.get("price", 0)))
else:
price_str = "◆ %d OP" % int(item.get("originPointPrice", 0))
confirm_dialog.dialog_text = "Buy \"%s\" for %s?" % [name_str, price_str]
confirm_dialog.popup_centered() confirm_dialog.popup_centered()
@@ -152,47 +333,50 @@ func _on_purchase_confirmed() -> void:
_buying = true _buying = true
var item := _pending_item var item := _pending_item
var item_id : String = str(item.get("id", "")) var tab := _tab
var id_str : String = str(item.get("id", ""))
var req_type: String var req_type : String
var req_payload: Dictionary var req_payload : Dictionary
match tab:
match _tab: Tab.BOOSTERS:
0:
req_type = "bazaar.buy_booster_pack" req_type = "bazaar.buy_booster_pack"
req_payload = { "packId": item_id } req_payload = { "packId": id_str }
1: Tab.DECKS:
req_type = "bazaar.buy_prebuilt_deck" req_type = "bazaar.buy_prebuilt_deck"
req_payload = { "deckId": item_id } req_payload = { "deckId": id_str }
_: Tab.COSMETICS:
req_type = "bazaar.buy_cosmetic" req_type = "bazaar.buy_cosmetic"
req_payload = { "cosmeticId": item_id } req_payload = { "cosmeticId": id_str }
Tab.CARDS:
req_type = "bazaar.buy_listing"
req_payload = { "listingId": id_str }
var tab_at_purchase := _tab
Network.request(req_type, req_payload, Network.request(req_type, req_payload,
func(_t, p): _on_purchase_ok(tab_at_purchase, p), func(_t: String, p: Variant): _on_purchase_ok(tab, p),
func(code, msg): _on_purchase_err(code, msg)) func(code: String, msg: String): _on_purchase_err(code, msg))
func _on_purchase_ok(tab: int, p: Dictionary) -> void: func _on_purchase_ok(tab: Tab, p: Variant) -> void:
_buying = false _buying = false
var new_bal: int = int(p.get("newOriginPointBalance", 0)) var d := p as Dictionary
balance_label.text = "◆ %d OP" % new_bal var new_bal: int = int(d.get("newOriginPointBalance", 0))
if new_bal > 0:
balance_label.text = "◆ %d OP" % new_bal
match tab: match tab:
0: # Booster pack — list the opened cards Tab.BOOSTERS:
var cards: Array = p.get("cardsOpened", []) _show_pack_result(d.get("cardsOpened", []))
_show_pack_result(cards) Tab.DECKS:
1: # Prebuilt deck var dname: String = d.get("deckName", _pending_item.get("name", "deck"))
var deck_name: String = p.get("deckName", _pending_item.get("name", "deck")) _show_result("Purchase Complete", "Deck \"%s\" added to your collection!" % dname)
result_dialog.title = "Purchase Complete" Tab.COSMETICS:
result_dialog.dialog_text = "Deck \"%s\" has been added to your collection!" % deck_name _show_result("Purchase Complete", "\"%s\" added to your account!" % _pending_item.get("name", "item"))
result_dialog.popup_centered() Tab.CARDS:
_: # Cosmetic var sold_id: String = str(_pending_item.get("id", ""))
var cname: String = _pending_item.get("name", "cosmetic") _listings = _listings.filter(func(l: Dictionary) -> bool:
result_dialog.title = "Purchase Complete" return str(l.get("id", "")) != sold_id)
result_dialog.dialog_text = "\"%s\" has been added to your account!" % cname _show_result("Purchase Complete", "Card purchased and added to your collection!")
result_dialog.popup_centered()
_pending_item = {} _pending_item = {}
@@ -200,29 +384,32 @@ func _on_purchase_ok(tab: int, p: Dictionary) -> void:
func _on_purchase_err(code: String, msg: String) -> void: func _on_purchase_err(code: String, msg: String) -> void:
_buying = false _buying = false
_pending_item = {} _pending_item = {}
result_dialog.title = "Purchase Failed" _show_result("Purchase Failed", "Error: %s\n%s" % [code, msg])
result_dialog.dialog_text = "Could not complete purchase.\nError: %s\n%s" % [code, msg]
result_dialog.popup_centered()
func _show_pack_result(cards: Array) -> void: func _show_pack_result(cards: Array) -> void:
var lines := PackedStringArray() var lines := PackedStringArray()
for card in cards: for card: Dictionary in cards:
var foil_str : String = " ✦" if bool(card.get("isFoil", false)) else "" var foil : String = " ✦" if bool(card.get("isFoil", false)) else ""
var serial_var = card.get("serialNumber", null) var serial = card.get("serialNumber", null)
var serial_str : String = " #%d" % int(serial_var) if serial_var != null else "" var snum : String = " #%d" % int(serial) if serial != null else ""
lines.append("%s · %s · %s%s%s" % [ lines.append("%s · %s · %s%s%s" % [
card.get("name", "?"), card.get("name", "?"),
card.get("rarity", ""), card.get("rarity", ""),
card.get("affinity", ""), card.get("affinity", ""),
foil_str, foil, snum,
serial_str,
]) ])
result_dialog.title = "Pack Opened! (%d cards)" % cards.size() result_dialog.title = "Pack Opened! (%d cards)" % cards.size()
result_dialog.dialog_text = "\n".join(lines) result_dialog.dialog_text = "\n".join(lines)
result_dialog.popup_centered() result_dialog.popup_centered()
# ── Navigation ────────────────────────────────────────────────────────────────
func _show_result(title: String, body: String) -> void:
result_dialog.title = title
result_dialog.dialog_text = body
result_dialog.popup_centered()
# ── Navigation ─────────────────────────────────────────────────────────────────
func _on_back() -> void: func _on_back() -> void:
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn") get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")
@@ -3,22 +3,31 @@
[ext_resource type="Script" path="res://scenes/bazaar/components/store_item_row.gd" id="1_sir"] [ext_resource type="Script" path="res://scenes/bazaar/components/store_item_row.gd" id="1_sir"]
[node name="StoreItemRow" type="PanelContainer"] [node name="StoreItemRow" type="PanelContainer"]
custom_minimum_size = Vector2(0, 88)
script = ExtResource("1_sir") script = ExtResource("1_sir")
[node name="Margin" type="MarginContainer" parent="."] [node name="Margin" type="MarginContainer" parent="."]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 10 theme_override_constants/margin_left = 10
theme_override_constants/margin_right = 10 theme_override_constants/margin_right = 10
theme_override_constants/margin_top = 10 theme_override_constants/margin_top = 8
theme_override_constants/margin_bottom = 10 theme_override_constants/margin_bottom = 8
[node name="HBox" type="HBoxContainer" parent="Margin"] [node name="HBox" type="HBoxContainer" parent="Margin"]
layout_mode = 2 layout_mode = 2
theme_override_constants/separation = 12 theme_override_constants/separation = 12
[node name="ArtImage" type="TextureRect" parent="Margin/HBox"]
unique_name_in_owner = true
layout_mode = 2
custom_minimum_size = Vector2(72, 72)
expand_mode = 1
stretch_mode = 6
[node name="Info" type="VBoxContainer" parent="Margin/HBox"] [node name="Info" type="VBoxContainer" parent="Margin/HBox"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 4
theme_override_constants/separation = 3 theme_override_constants/separation = 3
[node name="NameLabel" type="Label" parent="Margin/HBox/Info"] [node name="NameLabel" type="Label" parent="Margin/HBox/Info"]
@@ -43,8 +52,17 @@ visible = false
modulate = Color(0.55, 0.55, 0.60, 1.0) modulate = Color(0.55, 0.55, 0.60, 1.0)
theme_override_font_sizes/font_size = 11 theme_override_font_sizes/font_size = 11
[node name="TagsLabel" type="Label" parent="Margin/HBox/Info"]
unique_name_in_owner = true
layout_mode = 2
text = ""
visible = false
modulate = Color(0.45, 0.65, 0.90, 1.0)
theme_override_font_sizes/font_size = 10
[node name="PriceBox" type="VBoxContainer" parent="Margin/HBox"] [node name="PriceBox" type="VBoxContainer" parent="Margin/HBox"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 4
theme_override_constants/separation = 4 theme_override_constants/separation = 4
[node name="PriceLabel" type="Label" parent="Margin/HBox/PriceBox"] [node name="PriceLabel" type="Label" parent="Margin/HBox/PriceBox"]
@@ -60,3 +78,12 @@ layout_mode = 2
custom_minimum_size = Vector2(76, 32) custom_minimum_size = Vector2(76, 32)
text = "Buy" text = "Buy"
theme_override_font_sizes/font_size = 13 theme_override_font_sizes/font_size = 13
[node name="UsdLabel" type="Label" parent="Margin/HBox/PriceBox"]
unique_name_in_owner = true
layout_mode = 2
horizontal_alignment = 1
text = ""
visible = false
modulate = Color(0.5, 0.5, 0.55, 0.7)
theme_override_font_sizes/font_size = 10
@@ -1,33 +1,34 @@
extends PanelContainer extends PanelContainer
## A single row in the Bazaar store listing. ## A single row in the Bazaar store or marketplace listing.
## ##
## Call setup(item) with a Dictionary from get_store (StorePackDto, ## Call setup(item, fallback_art_url) for store products (packs, decks, cosmetics).
## StoreDeckDto, or CosmeticDto). Emits buy_pressed(item) when the ## Call setup_listing(listing, fallback_art_url) for marketplace card listings.
## Buy button is pressed. ## Emits buy_pressed(item) when the Buy button is pressed.
signal buy_pressed(item: Dictionary) signal buy_pressed(item: Dictionary)
@onready var name_label : Label = %NameLabel @onready var art_image : TextureRect = %ArtImage
@onready var desc_label : Label = %DescLabel @onready var name_label : Label = %NameLabel
@onready var sub_label : Label = %SubLabel @onready var desc_label : Label = %DescLabel
@onready var price_label : Label = %PriceLabel @onready var sub_label : Label = %SubLabel
@onready var buy_btn : Button = %BuyBtn @onready var tags_label : Label = %TagsLabel
@onready var price_label : Label = %PriceLabel
@onready var usd_label : Label = %UsdLabel
@onready var buy_btn : Button = %BuyBtn
var _item: Dictionary = {} var _item: Dictionary = {}
# -- Store product setup -------------------------------------------------------
func setup(item: Dictionary, fallback_art: String = "") -> void:
_item = item
func setup(item: Dictionary) -> void:
_item = item
name_label.text = item.get("name", "—") name_label.text = item.get("name", "—")
var desc: String = item.get("description", "") var desc: String = item.get("description", "")
if desc.is_empty(): desc_label.text = desc
desc_label.visible = false desc_label.visible = not desc.is_empty()
else:
desc_label.text = desc
desc_label.visible = true
# Sub-line varies by product type.
var sub := "" var sub := ""
if item.has("totalSlots"): if item.has("totalSlots"):
sub = "%d cards per pack" % int(item.get("totalSlots", 0)) sub = "%d cards per pack" % int(item.get("totalSlots", 0))
@@ -38,13 +39,87 @@ func setup(item: Dictionary) -> void:
sub += " · Arch: %s" % arch sub += " · Arch: %s" % arch
elif item.has("cosmeticType"): elif item.has("cosmeticType"):
sub = item.get("cosmeticType", "") sub = item.get("cosmeticType", "")
sub_label.text = sub
sub_label.visible = not sub.is_empty()
if sub.is_empty(): var tags := ""
sub_label.visible = false if bool(item.get("isStarterDeck", false)):
else: tags = "STARTER"
sub_label.text = sub tags_label.text = tags
sub_label.visible = true tags_label.visible = not tags.is_empty()
price_label.text = "◆ %d OP" % int(item.get("originPointPrice", 0)) price_label.text = "◆ %d OP" % int(item.get("originPointPrice", 0))
var usd: float = float(item.get("usdPrice", 0.0))
if usd > 0.0:
usd_label.text = "$%.2f (coming soon)" % usd
usd_label.visible = true
else:
usd_label.visible = false
buy_btn.pressed.connect(func(): buy_pressed.emit(_item)) buy_btn.pressed.connect(func(): buy_pressed.emit(_item))
_load_art(item.get("imageCdnUrl", item.get("previewImageCdnUrl", "")), fallback_art)
# -- Marketplace listing setup -------------------------------------------------
func setup_listing(listing: Dictionary, fallback_art: String = "") -> void:
_item = listing
var masked : bool = bool(listing.get("isMasked", false))
var card_name : String = listing.get("cardName", "") if not masked else "???"
var rarity : String = listing.get("rarity", "")
var card_type : String = listing.get("cardType", "")
var list_type : String = listing.get("listingType", "Fixed")
var bid_count : int = int(listing.get("bidCount", 0))
var cur_bid : float = float(listing.get("currentBid", 0.0))
name_label.text = card_name if not card_name.is_empty() else "Unknown Card"
desc_label.visible = false
var sub := ""
if not rarity.is_empty():
sub = rarity
if not card_type.is_empty():
sub = (sub + " · " + card_type) if not sub.is_empty() else card_type
sub_label.text = sub
sub_label.visible = not sub.is_empty()
var tags := list_type
if list_type == "Auction":
if bid_count > 0:
tags += " · %d bid%s · cur. ◆ %d" % [bid_count, "s" if bid_count != 1 else "", int(cur_bid)]
else:
tags += " · No bids yet"
tags_label.text = tags
tags_label.visible = true
tags_label.modulate = Color(0.45, 0.65, 0.90, 1.0) if list_type == "Fixed" else Color(1.0, 0.72, 0.20, 1.0)
price_label.text = "◆ %d OP" % int(float(listing.get("price", 0.0)))
usd_label.visible = false
buy_btn.text = "Buy" if list_type == "Fixed" else "Bid"
buy_btn.pressed.connect(func(): buy_pressed.emit(_item))
_load_art("", fallback_art)
# -- Art loading ---------------------------------------------------------------
func _load_art(url: String, fallback: String) -> void:
var target := url if not url.is_empty() else fallback
if target.is_empty():
return
var http := HTTPRequest.new()
add_child(http)
http.request_completed.connect(func(result: int, code: int, _headers: PackedStringArray, body: PackedByteArray):
if result == HTTPRequest.RESULT_SUCCESS and code == 200:
var img := Image.new()
var ok := img.load_png_from_buffer(body)
if ok != OK:
ok = img.load_jpg_from_buffer(body)
if ok == OK and is_instance_valid(art_image):
art_image.texture = ImageTexture.create_from_image(img)
http.queue_free()
)
http.request(target)