K8s changes for NATS
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/bazaar/bazaar_screen.gd" id="1_bs"]
|
||||
|
||||
[node name="BazaarScreen" type="VBoxContainer"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_bs")
|
||||
|
||||
[node name="TopBarMargin" 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="TopBar" type="HBoxContainer" parent="TopBarMargin"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 40)
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="BackBtn" type="Button" parent="TopBarMargin/TopBar"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(40, 40)
|
||||
text = "←"
|
||||
tooltip_text = "Back"
|
||||
theme_override_font_sizes/font_size = 18
|
||||
|
||||
[node name="TitleLabel" type="Label" parent="TopBarMargin/TopBar"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Bazaar"
|
||||
vertical_alignment = 1
|
||||
theme_override_font_sizes/font_size = 18
|
||||
|
||||
[node name="BalanceLabel" type="Label" parent="TopBarMargin/TopBar"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "◆ — OP"
|
||||
vertical_alignment = 1
|
||||
modulate = Color(0.95, 0.85, 0.30, 1.0)
|
||||
theme_override_font_sizes/font_size = 14
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TabBarMargin" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 16
|
||||
theme_override_constants/margin_right = 16
|
||||
theme_override_constants/margin_top = 6
|
||||
theme_override_constants/margin_bottom = 6
|
||||
|
||||
[node name="TabBar" type="HBoxContainer" parent="TabBarMargin"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 36)
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="PacksTabBtn" type="Button" parent="TabBarMargin/TabBar"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
custom_minimum_size = Vector2(0, 36)
|
||||
text = "Packs"
|
||||
theme_override_font_sizes/font_size = 14
|
||||
|
||||
[node name="DecksTabBtn" type="Button" parent="TabBarMargin/TabBar"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
custom_minimum_size = Vector2(0, 36)
|
||||
text = "Decks"
|
||||
theme_override_font_sizes/font_size = 14
|
||||
|
||||
[node name="CosmeticsTabBtn" type="Button" parent="TabBarMargin/TabBar"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
custom_minimum_size = Vector2(0, 36)
|
||||
text = "Cosmetics"
|
||||
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="ItemListMargin" 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 = 8
|
||||
theme_override_constants/margin_bottom = 8
|
||||
|
||||
[node name="ItemList" type="VBoxContainer" parent="Scroll/ItemListMargin"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/separation = 6
|
||||
|
||||
[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 = "Nothing available right now."
|
||||
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 Purchase"
|
||||
ok_button_text = "Buy"
|
||||
|
||||
[node name="ResultDialog" type="AcceptDialog" parent="."]
|
||||
unique_name_in_owner = true
|
||||
title = "Result"
|
||||
@@ -0,0 +1,228 @@
|
||||
extends VBoxContainer
|
||||
## Bazaar — browse and purchase store packs, decks, and cosmetics.
|
||||
##
|
||||
## Loads the store catalogue and the player's OriginPoints balance in
|
||||
## parallel on entry. Three tab buttons filter the item list. Each
|
||||
## row's Buy button opens a confirmation dialog; on confirmation the
|
||||
## 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")
|
||||
|
||||
# ── Node references ────────────────────────────────────────────────────────────
|
||||
|
||||
@onready var back_btn : Button = %BackBtn
|
||||
@onready var balance_label : Label = %BalanceLabel
|
||||
@onready var packs_tab_btn : Button = %PacksTabBtn
|
||||
@onready var decks_tab_btn : Button = %DecksTabBtn
|
||||
@onready var cosmetics_tab_btn : Button = %CosmeticsTabBtn
|
||||
@onready var item_list : VBoxContainer = %ItemList
|
||||
@onready var loading_label : Label = %LoadingLabel
|
||||
@onready var empty_label : Label = %EmptyLabel
|
||||
@onready var confirm_dialog : ConfirmationDialog = %ConfirmDialog
|
||||
@onready var result_dialog : AcceptDialog = %ResultDialog
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
var _tab: int = 0
|
||||
var _packs: Array = []
|
||||
var _decks: Array = []
|
||||
var _cosmetics: Array = []
|
||||
var _store_loaded: bool = false
|
||||
var _bal_loaded: bool = false
|
||||
|
||||
var _pending_item: Dictionary = {}
|
||||
var _buying: bool = false
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
back_btn.pressed.connect(_on_back)
|
||||
packs_tab_btn.pressed.connect(func(): _switch_tab(0))
|
||||
decks_tab_btn.pressed.connect(func(): _switch_tab(1))
|
||||
cosmetics_tab_btn.pressed.connect(func(): _switch_tab(2))
|
||||
confirm_dialog.confirmed.connect(_on_purchase_confirmed)
|
||||
|
||||
_apply_tab_style(packs_tab_btn, true)
|
||||
_apply_tab_style(decks_tab_btn, false)
|
||||
_apply_tab_style(cosmetics_tab_btn, false)
|
||||
|
||||
loading_label.visible = true
|
||||
empty_label.visible = false
|
||||
|
||||
_fetch_data()
|
||||
|
||||
# ── Data fetching ─────────────────────────────────────────────────────────────
|
||||
|
||||
func _fetch_data() -> void:
|
||||
_store_loaded = false
|
||||
_bal_loaded = false
|
||||
Network.request("bazaar.get_store", {}, _on_store_ok, _on_store_err)
|
||||
Network.request("bazaar.get_my_balance", {}, _on_balance_ok, _on_balance_err)
|
||||
|
||||
|
||||
func _on_store_ok(_type: String, p: Dictionary) -> void:
|
||||
_packs = p.get("packs", [])
|
||||
_decks = p.get("decks", [])
|
||||
_cosmetics = p.get("cosmetics", [])
|
||||
_store_loaded = true
|
||||
_check_done()
|
||||
|
||||
|
||||
func _on_store_err(code: String, _msg: String) -> void:
|
||||
push_warning("Bazaar: get_store failed — %s" % code)
|
||||
_store_loaded = true
|
||||
_check_done()
|
||||
|
||||
|
||||
func _on_balance_ok(_type: String, p: Dictionary) -> void:
|
||||
balance_label.text = "◆ %d OP" % int(p.get("originPoints", 0))
|
||||
_bal_loaded = true
|
||||
_check_done()
|
||||
|
||||
|
||||
func _on_balance_err(code: String, _msg: String) -> void:
|
||||
push_warning("Bazaar: get_my_balance failed — %s" % code)
|
||||
balance_label.text = "◆ — OP"
|
||||
_bal_loaded = true
|
||||
_check_done()
|
||||
|
||||
|
||||
func _check_done() -> void:
|
||||
if not (_store_loaded and _bal_loaded):
|
||||
return
|
||||
loading_label.visible = false
|
||||
_render_tab()
|
||||
|
||||
# ── Tabs ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
func _switch_tab(index: int) -> void:
|
||||
_tab = index
|
||||
_apply_tab_style(packs_tab_btn, index == 0)
|
||||
_apply_tab_style(decks_tab_btn, index == 1)
|
||||
_apply_tab_style(cosmetics_tab_btn, index == 2)
|
||||
if _store_loaded and _bal_loaded:
|
||||
_render_tab()
|
||||
|
||||
|
||||
func _apply_tab_style(btn: Button, active: bool) -> void:
|
||||
var style := StyleBoxFlat.new()
|
||||
style.corner_radius_top_left = 6
|
||||
style.corner_radius_top_right = 6
|
||||
style.corner_radius_bottom_left = 6
|
||||
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 _render_tab() -> void:
|
||||
for child in item_list.get_children():
|
||||
child.queue_free()
|
||||
|
||||
var items: Array
|
||||
match _tab:
|
||||
0: items = _packs
|
||||
1: items = _decks
|
||||
2: items = _cosmetics
|
||||
_: items = []
|
||||
|
||||
empty_label.visible = items.is_empty()
|
||||
|
||||
for item in items:
|
||||
var row = STORE_ITEM_ROW.instantiate()
|
||||
item_list.add_child(row)
|
||||
row.setup(item)
|
||||
row.buy_pressed.connect(_on_buy_pressed)
|
||||
|
||||
# ── Purchase flow ─────────────────────────────────────────────────────────────
|
||||
|
||||
func _on_buy_pressed(item: Dictionary) -> void:
|
||||
_pending_item = item
|
||||
var name_str : String = item.get("name", "?")
|
||||
var price : int = int(item.get("originPointPrice", 0))
|
||||
confirm_dialog.dialog_text = "Buy \"%s\" for ◆ %d OP?" % [name_str, price]
|
||||
confirm_dialog.popup_centered()
|
||||
|
||||
|
||||
func _on_purchase_confirmed() -> void:
|
||||
if _pending_item.is_empty() or _buying:
|
||||
return
|
||||
_buying = true
|
||||
|
||||
var item := _pending_item
|
||||
var item_id : String = str(item.get("id", ""))
|
||||
|
||||
var req_type: String
|
||||
var req_payload: Dictionary
|
||||
|
||||
match _tab:
|
||||
0:
|
||||
req_type = "bazaar.buy_booster_pack"
|
||||
req_payload = { "packId": item_id }
|
||||
1:
|
||||
req_type = "bazaar.buy_prebuilt_deck"
|
||||
req_payload = { "deckId": item_id }
|
||||
_:
|
||||
req_type = "bazaar.buy_cosmetic"
|
||||
req_payload = { "cosmeticId": item_id }
|
||||
|
||||
var tab_at_purchase := _tab
|
||||
Network.request(req_type, req_payload,
|
||||
func(_t, p): _on_purchase_ok(tab_at_purchase, p),
|
||||
func(code, msg): _on_purchase_err(code, msg))
|
||||
|
||||
|
||||
func _on_purchase_ok(tab: int, p: Dictionary) -> void:
|
||||
_buying = false
|
||||
var new_bal: int = int(p.get("newOriginPointBalance", 0))
|
||||
balance_label.text = "◆ %d OP" % new_bal
|
||||
|
||||
match tab:
|
||||
0: # Booster pack — list the opened cards
|
||||
var cards: Array = p.get("cardsOpened", [])
|
||||
_show_pack_result(cards)
|
||||
1: # Prebuilt deck
|
||||
var deck_name: String = p.get("deckName", _pending_item.get("name", "deck"))
|
||||
result_dialog.title = "Purchase Complete"
|
||||
result_dialog.dialog_text = "Deck \"%s\" has been added to your collection!" % deck_name
|
||||
result_dialog.popup_centered()
|
||||
_: # Cosmetic
|
||||
var cname: String = _pending_item.get("name", "cosmetic")
|
||||
result_dialog.title = "Purchase Complete"
|
||||
result_dialog.dialog_text = "\"%s\" has been added to your account!" % cname
|
||||
result_dialog.popup_centered()
|
||||
|
||||
_pending_item = {}
|
||||
|
||||
|
||||
func _on_purchase_err(code: String, msg: String) -> void:
|
||||
_buying = false
|
||||
_pending_item = {}
|
||||
result_dialog.title = "Purchase Failed"
|
||||
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:
|
||||
var lines := PackedStringArray()
|
||||
for card in cards:
|
||||
var foil_str : String = " ✦" if bool(card.get("isFoil", false)) else ""
|
||||
var serial_var = card.get("serialNumber", null)
|
||||
var serial_str : String = " #%d" % int(serial_var) if serial_var != null else ""
|
||||
lines.append("%s · %s · %s%s%s" % [
|
||||
card.get("name", "?"),
|
||||
card.get("rarity", ""),
|
||||
card.get("affinity", ""),
|
||||
foil_str,
|
||||
serial_str,
|
||||
])
|
||||
result_dialog.title = "Pack Opened! (%d cards)" % cards.size()
|
||||
result_dialog.dialog_text = "\n".join(lines)
|
||||
result_dialog.popup_centered()
|
||||
|
||||
# ── Navigation ────────────────────────────────────────────────────────────────
|
||||
|
||||
func _on_back() -> void:
|
||||
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")
|
||||
@@ -0,0 +1 @@
|
||||
uid://cq4fff6k71rpe
|
||||
@@ -0,0 +1,62 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/bazaar/components/store_item_row.gd" id="1_sir"]
|
||||
|
||||
[node name="StoreItemRow" type="PanelContainer"]
|
||||
script = ExtResource("1_sir")
|
||||
|
||||
[node name="Margin" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_top = 10
|
||||
theme_override_constants/margin_bottom = 10
|
||||
|
||||
[node name="HBox" type="HBoxContainer" parent="Margin"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 12
|
||||
|
||||
[node name="Info" type="VBoxContainer" parent="Margin/HBox"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/separation = 3
|
||||
|
||||
[node name="NameLabel" type="Label" parent="Margin/HBox/Info"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 14
|
||||
|
||||
[node name="DescLabel" type="Label" parent="Margin/HBox/Info"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = ""
|
||||
visible = false
|
||||
autowrap_mode = 2
|
||||
modulate = Color(0.70, 0.70, 0.75, 1.0)
|
||||
theme_override_font_sizes/font_size = 12
|
||||
|
||||
[node name="SubLabel" type="Label" parent="Margin/HBox/Info"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = ""
|
||||
visible = false
|
||||
modulate = Color(0.55, 0.55, 0.60, 1.0)
|
||||
theme_override_font_sizes/font_size = 11
|
||||
|
||||
[node name="PriceBox" type="VBoxContainer" parent="Margin/HBox"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 4
|
||||
|
||||
[node name="PriceLabel" type="Label" parent="Margin/HBox/PriceBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
modulate = Color(0.95, 0.85, 0.30, 1.0)
|
||||
theme_override_font_sizes/font_size = 13
|
||||
|
||||
[node name="BuyBtn" type="Button" parent="Margin/HBox/PriceBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(76, 32)
|
||||
text = "Buy"
|
||||
theme_override_font_sizes/font_size = 13
|
||||
@@ -0,0 +1,50 @@
|
||||
extends PanelContainer
|
||||
## A single row in the Bazaar store listing.
|
||||
##
|
||||
## Call setup(item) with a Dictionary from get_store (StorePackDto,
|
||||
## StoreDeckDto, or CosmeticDto). Emits buy_pressed(item) when the
|
||||
## Buy button is pressed.
|
||||
|
||||
signal buy_pressed(item: Dictionary)
|
||||
|
||||
@onready var name_label : Label = %NameLabel
|
||||
@onready var desc_label : Label = %DescLabel
|
||||
@onready var sub_label : Label = %SubLabel
|
||||
@onready var price_label : Label = %PriceLabel
|
||||
@onready var buy_btn : Button = %BuyBtn
|
||||
|
||||
var _item: Dictionary = {}
|
||||
|
||||
|
||||
func setup(item: Dictionary) -> void:
|
||||
_item = item
|
||||
name_label.text = item.get("name", "—")
|
||||
|
||||
var desc: String = item.get("description", "")
|
||||
if desc.is_empty():
|
||||
desc_label.visible = false
|
||||
else:
|
||||
desc_label.text = desc
|
||||
desc_label.visible = true
|
||||
|
||||
# Sub-line varies by product type.
|
||||
var sub := ""
|
||||
if item.has("totalSlots"):
|
||||
sub = "%d cards per pack" % int(item.get("totalSlots", 0))
|
||||
elif item.has("totalCards"):
|
||||
sub = "%d cards" % int(item.get("totalCards", 0))
|
||||
var arch: String = item.get("archSpiritName", "")
|
||||
if not arch.is_empty():
|
||||
sub += " · Arch: %s" % arch
|
||||
elif item.has("cosmeticType"):
|
||||
sub = item.get("cosmeticType", "")
|
||||
|
||||
if sub.is_empty():
|
||||
sub_label.visible = false
|
||||
else:
|
||||
sub_label.text = sub
|
||||
sub_label.visible = true
|
||||
|
||||
price_label.text = "◆ %d OP" % int(item.get("originPointPrice", 0))
|
||||
|
||||
buy_btn.pressed.connect(func(): buy_pressed.emit(_item))
|
||||
@@ -0,0 +1 @@
|
||||
uid://bl4vmmiurfap2
|
||||
Reference in New Issue
Block a user