Improve UI scaling and fishing commerce
This commit is contained in:
parent
2de96dd7bb
commit
6b8c3eb2f7
29 changed files with 1515 additions and 817 deletions
|
|
@ -4,10 +4,6 @@ extends Control
|
|||
const INPUT_OWNER: StringName = &"fishing_shop"
|
||||
const MAIN_SHOP_BUYER_ID: StringName = &"main_fishing_shop"
|
||||
const FishBuyerProfileType = preload("res://economy/fish_buyer_profile.gd")
|
||||
const FishCatchType = preload("res://fish/fish_catch.gd")
|
||||
const FishInventoryType = preload("res://inventory/fish_inventory.gd")
|
||||
const FishSaleResultType = preload("res://economy/fish_sale_result.gd")
|
||||
const FishSaleServiceType = preload("res://economy/fish_sale_service.gd")
|
||||
const PlayerWalletType = preload("res://economy/player_wallet.gd")
|
||||
const FishingShopStockType = preload("res://economy/fishing_shop_stock.gd")
|
||||
const ItemCatalogType = preload("res://items/item_catalog.gd")
|
||||
|
|
@ -24,11 +20,12 @@ const PlayerCoolerCapacityType = preload(
|
|||
const ShopInteractionType = preload(
|
||||
"res://world/fishing_shop_interaction.gd"
|
||||
)
|
||||
const FishBatchSelectionType = preload(
|
||||
"res://ui/fish_batch_selection.gd"
|
||||
)
|
||||
const UtilityPageStyleType = preload("res://ui/utility_page_style.gd")
|
||||
|
||||
signal menu_visibility_changed(is_open: bool)
|
||||
signal sell_fish_requested
|
||||
signal shop_cooler_return_requested
|
||||
signal shop_cooler_confirmation_cancel_requested
|
||||
|
||||
enum CloseReason {
|
||||
USER,
|
||||
|
|
@ -39,17 +36,12 @@ enum CloseReason {
|
|||
}
|
||||
|
||||
@onready var _wallet_label: Label = %WalletLabel
|
||||
@onready var _fish_sales: VBoxContainer = (
|
||||
$ShopPanel/Margin/Layout/Body/FishSales
|
||||
)
|
||||
@onready var _fish_list: ItemList = %FishList
|
||||
@onready var _sales_title: Label = %SalesTitle
|
||||
@onready var _fish_empty: Label = %FishEmpty
|
||||
@onready var _fish_texture: TextureRect = %FishTexture
|
||||
@onready var _fish_name: Label = %FishName
|
||||
@onready var _fish_details: Label = %FishDetails
|
||||
@onready var _selection_summary: Label = %SelectionSummary
|
||||
@onready var _sell_button: Button = %SellButton
|
||||
@onready var _shop_panel: PanelContainer = %ShopPanel
|
||||
@onready var _shop_cooler_page: Control = %ShopCoolerPage
|
||||
@onready var _shop_cooler_mount: Control = %ShopCoolerMount
|
||||
@onready var _back_to_shop_button: Button = %BackToShopButton
|
||||
@onready var _buy_mode_button: Button = %BuyModeButton
|
||||
@onready var _sell_mode_button: Button = %SellModeButton
|
||||
@onready var _feedback: Label = %Feedback
|
||||
@onready var _reel_level: Label = %ReelLevel
|
||||
@onready var _reel_effect: Label = %ReelEffect
|
||||
|
|
@ -64,15 +56,9 @@ enum CloseReason {
|
|||
@onready var _cooler_effect: Label = %CoolerEffect
|
||||
@onready var _cooler_cost: Label = %CoolerCost
|
||||
@onready var _cooler_purchase: Button = %CoolerPurchase
|
||||
@onready var _confirmation: PanelContainer = %SaleConfirmation
|
||||
@onready var _confirmation_text: Label = %ConfirmationText
|
||||
@onready var _confirm_sale: Button = %ConfirmSale
|
||||
@onready var _cancel_sale: Button = %CancelSale
|
||||
|
||||
var _player: PlayerType
|
||||
var _inventory: FishInventoryType
|
||||
var _wallet: PlayerWalletType
|
||||
var _sale_service: FishSaleServiceType
|
||||
var _buyer: FishBuyerProfileType
|
||||
var _upgrades: PlayerFishingUpgradesType
|
||||
var _fishing_spot: FishingSpotType
|
||||
|
|
@ -80,42 +66,93 @@ var _interaction: ShopInteractionType
|
|||
var _bag: PlayerBagType
|
||||
var _item_catalog: ItemCatalogType
|
||||
var _cooler_capacity: PlayerCoolerCapacityType
|
||||
var _network_session: NetworkSession
|
||||
var _network_shop: NetworkShopService
|
||||
var _fish_selection := FishBatchSelectionType.new()
|
||||
var _confirmation_catch_ids: Array[StringName] = []
|
||||
var _confirmation_generation: int = -1
|
||||
var _prior_movement_enabled: bool = true
|
||||
var _prior_camera_enabled: bool = true
|
||||
var _prior_mouse_mode: Input.MouseMode = Input.MOUSE_MODE_VISIBLE
|
||||
var _snapshot_stored: bool = false
|
||||
var _mouse_snapshot_stored: bool = false
|
||||
var _generation: int = 0
|
||||
var _selection_input_generation: int = 0
|
||||
var _transaction_in_progress: bool = false
|
||||
var _closing: bool = false
|
||||
var _cooler_page_active: bool = false
|
||||
var _cooler_modal_open: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# Catch selling belongs to the Pelican action in the Player Menu. Keep the
|
||||
# legacy shop sales controls out of the active interface.
|
||||
_fish_sales.hide()
|
||||
UtilityPageStyleType.apply_page(self)
|
||||
_apply_shop_styles()
|
||||
%CloseButton.pressed.connect(close_shop)
|
||||
_fish_list.item_selected.connect(_on_fish_selected)
|
||||
_fish_list.item_clicked.connect(_on_fish_clicked)
|
||||
_sell_button.pressed.connect(_open_sale_confirmation)
|
||||
_confirm_sale.pressed.connect(_on_confirm_sale)
|
||||
_cancel_sale.pressed.connect(_close_sale_confirmation)
|
||||
_buy_mode_button.pressed.connect(_focus_buy_page)
|
||||
_sell_mode_button.pressed.connect(_request_shop_cooler)
|
||||
_back_to_shop_button.pressed.connect(shop_cooler_return_requested.emit)
|
||||
_reel_purchase.pressed.connect(_purchase_reel_speed)
|
||||
_barrier_purchase.pressed.connect(_purchase_barrier_power)
|
||||
_cooler_purchase.pressed.connect(_purchase_cooler_capacity)
|
||||
|
||||
|
||||
func _request_shop_cooler() -> void:
|
||||
if _transaction_in_progress:
|
||||
_feedback.text = "Finish the current transaction first."
|
||||
return
|
||||
if not _is_transaction_context_valid():
|
||||
_feedback.text = "The fishing shop is no longer available."
|
||||
return
|
||||
sell_fish_requested.emit()
|
||||
|
||||
|
||||
func _focus_buy_page() -> void:
|
||||
_feedback.text = ""
|
||||
if _supplies_list.get_child_count() > 0:
|
||||
var first_supply := _supplies_list.get_child(0) as Button
|
||||
if first_supply != null and not first_supply.disabled:
|
||||
first_supply.grab_focus()
|
||||
return
|
||||
_reel_purchase.grab_focus()
|
||||
|
||||
|
||||
func _apply_shop_styles() -> void:
|
||||
var shop_panel := $ShopPanel as PanelContainer
|
||||
var shop_panel_style := UtilityPageStyleType.panel_style()
|
||||
shop_panel_style.set_corner_radius_all(24)
|
||||
shop_panel_style.content_margin_left = 0.0
|
||||
shop_panel_style.content_margin_top = 0.0
|
||||
shop_panel_style.content_margin_right = 0.0
|
||||
shop_panel_style.content_margin_bottom = 0.0
|
||||
shop_panel.add_theme_stylebox_override(
|
||||
"panel", shop_panel_style
|
||||
)
|
||||
for panel: PanelContainer in [
|
||||
$ShopPanel/Margin/Layout/Body/Upgrades/ReelCard,
|
||||
$ShopPanel/Margin/Layout/Body/Upgrades/BarrierCard,
|
||||
$ShopPanel/Margin/Layout/Body/Upgrades/CoolerCard,
|
||||
]:
|
||||
panel.add_theme_stylebox_override(
|
||||
"panel", UtilityPageStyleType.row_style()
|
||||
)
|
||||
for button: BaseButton in [
|
||||
%CloseButton,
|
||||
_buy_mode_button,
|
||||
_sell_mode_button,
|
||||
_reel_purchase,
|
||||
_barrier_purchase,
|
||||
_cooler_purchase,
|
||||
_back_to_shop_button,
|
||||
]:
|
||||
UtilityPageStyleType.apply_ocean_button(button)
|
||||
_buy_mode_button.add_theme_stylebox_override(
|
||||
"normal",
|
||||
UtilityPageStyleType.ocean_button_style(
|
||||
UtilityPageStyleType.OCEAN_SELECTED
|
||||
),
|
||||
)
|
||||
_feedback.add_theme_color_override(
|
||||
"font_color", UtilityPageStyleType.OCEAN_TEXT_SECONDARY
|
||||
)
|
||||
|
||||
|
||||
func setup(
|
||||
player: PlayerType,
|
||||
inventory: FishInventoryType,
|
||||
wallet: PlayerWalletType,
|
||||
sale_service: FishSaleServiceType,
|
||||
buyer: FishBuyerProfileType,
|
||||
upgrades: PlayerFishingUpgradesType,
|
||||
fishing_spot: FishingSpotType,
|
||||
|
|
@ -123,13 +160,10 @@ func setup(
|
|||
bag: PlayerBagType,
|
||||
item_catalog: ItemCatalogType,
|
||||
cooler_capacity: PlayerCoolerCapacityType,
|
||||
network_session: NetworkSession,
|
||||
network_shop: NetworkShopService,
|
||||
) -> void:
|
||||
_player = player
|
||||
_inventory = inventory
|
||||
_wallet = wallet
|
||||
_sale_service = sale_service
|
||||
_buyer = buyer
|
||||
_upgrades = upgrades
|
||||
_fishing_spot = fishing_spot
|
||||
|
|
@ -137,7 +171,6 @@ func setup(
|
|||
_bag = bag
|
||||
_item_catalog = item_catalog
|
||||
_cooler_capacity = cooler_capacity
|
||||
_network_session = network_session
|
||||
_network_shop = network_shop
|
||||
if (
|
||||
_network_shop != null
|
||||
|
|
@ -151,9 +184,6 @@ func setup(
|
|||
_network_shop.local_purchase_finished.connect(
|
||||
_on_network_purchase_finished
|
||||
)
|
||||
_fish_selection.clear()
|
||||
if not _inventory.catches_changed.is_connected(_on_inventory_changed):
|
||||
_inventory.catches_changed.connect(_on_inventory_changed)
|
||||
if not _wallet.balance_changed.is_connected(_on_wallet_changed):
|
||||
_wallet.balance_changed.connect(_on_wallet_changed)
|
||||
if not _upgrades.upgrades_changed.is_connected(_on_upgrades_changed):
|
||||
|
|
@ -180,7 +210,6 @@ func open_shop() -> bool:
|
|||
or _buyer.id != MAIN_SHOP_BUYER_ID
|
||||
):
|
||||
return false
|
||||
_generation += 1
|
||||
_closing = false
|
||||
_transaction_in_progress = (
|
||||
_network_shop != null
|
||||
|
|
@ -196,10 +225,10 @@ func open_shop() -> bool:
|
|||
_fishing_spot.set_local_menu_input_suppressed(INPUT_OWNER, true)
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
_feedback.text = ""
|
||||
_close_sale_confirmation()
|
||||
deactivate_shop_cooler_page()
|
||||
show()
|
||||
_refresh_all()
|
||||
%CloseButton.grab_focus()
|
||||
_buy_mode_button.grab_focus()
|
||||
menu_visibility_changed.emit(true)
|
||||
return true
|
||||
|
||||
|
|
@ -207,13 +236,42 @@ func open_shop() -> bool:
|
|||
func consume_escape() -> bool:
|
||||
if not visible:
|
||||
return false
|
||||
if _confirmation.visible:
|
||||
_close_sale_confirmation()
|
||||
else:
|
||||
close_shop()
|
||||
if _cooler_page_active:
|
||||
if _cooler_modal_open:
|
||||
shop_cooler_confirmation_cancel_requested.emit()
|
||||
else:
|
||||
shop_cooler_return_requested.emit()
|
||||
return true
|
||||
close_shop()
|
||||
return true
|
||||
|
||||
|
||||
func get_shop_cooler_mount() -> Control:
|
||||
return _shop_cooler_mount
|
||||
|
||||
|
||||
func activate_shop_cooler_page() -> void:
|
||||
_cooler_page_active = true
|
||||
_shop_panel.hide()
|
||||
_shop_cooler_page.show()
|
||||
_back_to_shop_button.disabled = false
|
||||
|
||||
|
||||
func deactivate_shop_cooler_page() -> void:
|
||||
_cooler_page_active = false
|
||||
_cooler_modal_open = false
|
||||
_back_to_shop_button.disabled = false
|
||||
_shop_cooler_page.hide()
|
||||
_shop_panel.show()
|
||||
if visible:
|
||||
_buy_mode_button.grab_focus()
|
||||
|
||||
|
||||
func set_shop_cooler_modal_open(is_open: bool) -> void:
|
||||
_cooler_modal_open = is_open
|
||||
_back_to_shop_button.disabled = is_open
|
||||
|
||||
|
||||
func close_shop(
|
||||
reason: CloseReason = CloseReason.USER,
|
||||
restore_controls: bool = true,
|
||||
|
|
@ -221,10 +279,7 @@ func close_shop(
|
|||
if not visible:
|
||||
return
|
||||
_closing = true
|
||||
_generation += 1
|
||||
_transaction_in_progress = false
|
||||
_close_sale_confirmation()
|
||||
_fish_selection.clear()
|
||||
hide()
|
||||
get_viewport().gui_release_focus()
|
||||
if _fishing_spot != null and is_instance_valid(_fishing_spot):
|
||||
|
|
@ -241,6 +296,7 @@ func close_shop(
|
|||
_apply_mouse_close_policy(reason)
|
||||
_closing = false
|
||||
menu_visibility_changed.emit(false)
|
||||
deactivate_shop_cooler_page()
|
||||
|
||||
|
||||
func close_for_range_exit() -> void:
|
||||
|
|
@ -268,8 +324,6 @@ func _refresh_all() -> void:
|
|||
if not is_node_ready():
|
||||
return
|
||||
_refresh_wallet()
|
||||
_refresh_fish_list()
|
||||
_refresh_selected_fish()
|
||||
_refresh_upgrades()
|
||||
_refresh_supplies()
|
||||
_refresh_cooler_capacity()
|
||||
|
|
@ -283,144 +337,6 @@ func _refresh_wallet() -> void:
|
|||
)
|
||||
|
||||
|
||||
func _refresh_fish_list() -> void:
|
||||
_fish_list.clear()
|
||||
var catches: Array[FishCatchType] = (
|
||||
_inventory.get_all_catches() if _inventory != null else []
|
||||
)
|
||||
_sales_title.text = "cooler %d / %d • full base value" % [
|
||||
catches.size(),
|
||||
_cooler_capacity.get_capacity() if _cooler_capacity != null else 0,
|
||||
]
|
||||
catches.sort_custom(
|
||||
func(a: FishCatchType, b: FishCatchType) -> bool:
|
||||
return a.catch_sequence > b.catch_sequence
|
||||
)
|
||||
var visible_ids: Array[StringName] = []
|
||||
for fish_catch: FishCatchType in catches:
|
||||
if fish_catch != null and fish_catch.is_valid():
|
||||
visible_ids.append(fish_catch.catch_id)
|
||||
_fish_selection.set_visible_order(visible_ids)
|
||||
for fish_catch: FishCatchType in catches:
|
||||
if fish_catch == null or not fish_catch.is_valid():
|
||||
continue
|
||||
var marker: String = ""
|
||||
if _fish_selection.is_selected(fish_catch.catch_id):
|
||||
marker += "✓ "
|
||||
if fish_catch.catch_id == _fish_selection.get_focused_id():
|
||||
marker += "◆ "
|
||||
if fish_catch.is_favorited:
|
||||
marker += "★ "
|
||||
var index: int = _fish_list.add_item(
|
||||
"%s%s — %.2f lb"
|
||||
% [marker, fish_catch.fish.display_name, fish_catch.weight_lb],
|
||||
fish_catch.fish.display_texture
|
||||
)
|
||||
_fish_list.set_item_metadata(index, String(fish_catch.catch_id))
|
||||
_fish_list.set_item_tooltip(
|
||||
index,
|
||||
"%s • %s"
|
||||
% [
|
||||
fish_catch.fish.get_rarity_name(),
|
||||
"favorited" if fish_catch.is_favorited else "available",
|
||||
]
|
||||
)
|
||||
_fish_empty.visible = _fish_list.item_count == 0
|
||||
_fish_list.deselect_all()
|
||||
for index: int in range(_fish_list.item_count):
|
||||
var catch_id := StringName(str(_fish_list.get_item_metadata(index)))
|
||||
if _fish_selection.is_selected(catch_id):
|
||||
_fish_list.select(index, false)
|
||||
|
||||
|
||||
func _refresh_selected_fish() -> void:
|
||||
var fish_catch: FishCatchType = _get_selected_catch()
|
||||
_fish_texture.texture = (
|
||||
fish_catch.fish.display_texture if fish_catch != null else null
|
||||
)
|
||||
_fish_name.text = (
|
||||
fish_catch.fish.display_name if fish_catch != null else "select a fish"
|
||||
)
|
||||
if fish_catch == null:
|
||||
_fish_details.text = "choose one individual fish from your cooler."
|
||||
_update_sale_summary()
|
||||
return
|
||||
var individual_preview: FishSaleResultType = (
|
||||
_sale_service.preview_batch([fish_catch.catch_id], _buyer)
|
||||
if _sale_service != null
|
||||
else null
|
||||
)
|
||||
var offer: int = (
|
||||
individual_preview.payout if individual_preview != null else -1
|
||||
)
|
||||
_fish_details.text = (
|
||||
"%.2f lb • %s\nbase value: $%d\nmain-shop offer: $%d%s"
|
||||
% [
|
||||
fish_catch.weight_lb,
|
||||
fish_catch.fish.get_rarity_name(),
|
||||
fish_catch.sale_value,
|
||||
offer,
|
||||
"\nfavorited fish cannot be sold."
|
||||
if fish_catch.is_favorited
|
||||
else "",
|
||||
]
|
||||
)
|
||||
_update_sale_summary()
|
||||
|
||||
|
||||
func _update_sale_summary() -> void:
|
||||
var selected_ids: Array[StringName] = _fish_selection.get_selected_ids()
|
||||
var selected_count: int = selected_ids.size()
|
||||
_sell_button.text = (
|
||||
"sell fish"
|
||||
if selected_count <= 1
|
||||
else "sell %d fish" % selected_count
|
||||
)
|
||||
if selected_count == 0:
|
||||
_selection_summary.text = "no fish selected"
|
||||
_sell_button.disabled = true
|
||||
return
|
||||
if _network_session != null and _network_session.is_joined_client():
|
||||
_selection_summary.text = (
|
||||
"1 fish selected"
|
||||
if selected_count == 1
|
||||
else "%d fish selected" % selected_count
|
||||
)
|
||||
_selection_summary.text += (
|
||||
"\nSell catches to the nearby pelicans."
|
||||
)
|
||||
_sell_button.disabled = true
|
||||
return
|
||||
var preview: FishSaleResultType = (
|
||||
_sale_service.preview_batch(selected_ids, _buyer)
|
||||
if _sale_service != null
|
||||
else null
|
||||
)
|
||||
_selection_summary.text = (
|
||||
"1 fish selected"
|
||||
if selected_count == 1
|
||||
else "%d fish selected" % selected_count
|
||||
)
|
||||
if (
|
||||
preview != null
|
||||
and (
|
||||
preview.is_success()
|
||||
or preview.status == FishSaleResultType.Status.FAVORITED
|
||||
)
|
||||
):
|
||||
_selection_summary.text += "\ntotal offer: $%d" % preview.payout
|
||||
if preview != null and preview.status == FishSaleResultType.Status.FAVORITED:
|
||||
_selection_summary.text += (
|
||||
"\nfavorited fish must be removed from the selection."
|
||||
)
|
||||
_sell_button.disabled = (
|
||||
preview == null
|
||||
or not preview.is_success()
|
||||
or _transaction_in_progress
|
||||
or _closing
|
||||
)
|
||||
|
||||
|
||||
func _refresh_upgrades() -> void:
|
||||
if _upgrades == null:
|
||||
return
|
||||
|
|
@ -516,6 +432,7 @@ func _refresh_supplies() -> void:
|
|||
if _network_shop == null or not _network_shop.can_request_purchase()
|
||||
else item.description
|
||||
)
|
||||
UtilityPageStyleType.apply_ocean_button(button)
|
||||
button.pressed.connect(_purchase_supply.bind(item_id))
|
||||
_supplies_list.add_child(button)
|
||||
|
||||
|
|
@ -549,142 +466,6 @@ func _refresh_cooler_capacity() -> void:
|
|||
_cooler_purchase.text = "purchase"
|
||||
|
||||
|
||||
func _on_fish_selected(index: int) -> void:
|
||||
if index < 0 or index >= _fish_list.item_count:
|
||||
return
|
||||
var input_generation: int = _selection_input_generation
|
||||
call_deferred(
|
||||
"_apply_keyboard_fish_selection",
|
||||
index,
|
||||
input_generation
|
||||
)
|
||||
|
||||
|
||||
func _apply_keyboard_fish_selection(
|
||||
index: int,
|
||||
input_generation: int,
|
||||
) -> void:
|
||||
if (
|
||||
input_generation != _selection_input_generation
|
||||
or index < 0
|
||||
or index >= _fish_list.item_count
|
||||
):
|
||||
return
|
||||
var catch_id := StringName(str(_fish_list.get_item_metadata(index)))
|
||||
_fish_selection.select_only(catch_id)
|
||||
_feedback.text = ""
|
||||
_refresh_fish_list()
|
||||
_refresh_selected_fish()
|
||||
|
||||
|
||||
func _on_fish_clicked(
|
||||
index: int,
|
||||
_position: Vector2,
|
||||
mouse_button_index: int,
|
||||
) -> void:
|
||||
if (
|
||||
mouse_button_index != MOUSE_BUTTON_LEFT
|
||||
or index < 0
|
||||
or index >= _fish_list.item_count
|
||||
):
|
||||
return
|
||||
_selection_input_generation += 1
|
||||
var catch_id := StringName(str(_fish_list.get_item_metadata(index)))
|
||||
_fish_selection.apply_click(
|
||||
catch_id,
|
||||
Input.is_key_pressed(KEY_CTRL),
|
||||
Input.is_key_pressed(KEY_SHIFT)
|
||||
)
|
||||
_feedback.text = ""
|
||||
_refresh_fish_list()
|
||||
_refresh_selected_fish()
|
||||
|
||||
|
||||
func _open_sale_confirmation() -> void:
|
||||
if _network_session != null and _network_session.is_joined_client():
|
||||
_feedback.text = "Sell catches to the nearby pelicans."
|
||||
return
|
||||
var selected_ids: Array[StringName] = _fish_selection.get_selected_ids()
|
||||
if not _is_transaction_context_valid() or selected_ids.is_empty():
|
||||
_feedback.text = "the fish selection is no longer available."
|
||||
_refresh_all()
|
||||
return
|
||||
var preview: FishSaleResultType = _sale_service.preview_batch(
|
||||
selected_ids,
|
||||
_buyer
|
||||
)
|
||||
if not preview.is_success():
|
||||
_feedback.text = (
|
||||
"favorited fish cannot be sold. "
|
||||
+ "remove them from the selection first."
|
||||
if preview.status == FishSaleResultType.Status.FAVORITED
|
||||
else preview.get_message()
|
||||
)
|
||||
return
|
||||
_confirmation_catch_ids = selected_ids.duplicate()
|
||||
_confirmation_generation = _generation
|
||||
_confirmation_text.text = (
|
||||
"sell %d fish to the fishing shop for $%d?"
|
||||
% [preview.fish_count, preview.payout]
|
||||
)
|
||||
_confirmation.show()
|
||||
_cancel_sale.grab_focus()
|
||||
|
||||
|
||||
func _close_sale_confirmation() -> void:
|
||||
_confirmation_catch_ids.clear()
|
||||
_confirmation_generation = -1
|
||||
_confirmation.hide()
|
||||
|
||||
|
||||
func _on_confirm_sale() -> void:
|
||||
if (
|
||||
_transaction_in_progress
|
||||
or (
|
||||
_network_session != null
|
||||
and _network_session.is_joined_client()
|
||||
)
|
||||
):
|
||||
return
|
||||
var transaction_generation: int = _generation
|
||||
var catch_ids: Array[StringName] = _confirmation_catch_ids.duplicate()
|
||||
var confirmation_generation: int = _confirmation_generation
|
||||
_close_sale_confirmation()
|
||||
if (
|
||||
catch_ids.is_empty()
|
||||
or not _is_transaction_context_valid()
|
||||
or transaction_generation != _generation
|
||||
or confirmation_generation != transaction_generation
|
||||
or _buyer.id != MAIN_SHOP_BUYER_ID
|
||||
):
|
||||
_feedback.text = "unable to complete sale."
|
||||
return
|
||||
_transaction_in_progress = true
|
||||
var result: FishSaleResultType = _sale_service.sell_batch(
|
||||
catch_ids,
|
||||
_buyer
|
||||
)
|
||||
_transaction_in_progress = false
|
||||
if (
|
||||
transaction_generation != _generation
|
||||
or not visible
|
||||
):
|
||||
return
|
||||
if result.is_success():
|
||||
_feedback.text = (
|
||||
"fish sold for $%d."
|
||||
if result.fish_count == 1
|
||||
else "%d fish sold for $%d." % [
|
||||
result.fish_count,
|
||||
result.payout,
|
||||
]
|
||||
)
|
||||
_fish_selection.remove_ids(catch_ids)
|
||||
else:
|
||||
_feedback.text = result.get_message()
|
||||
_refresh_all()
|
||||
|
||||
|
||||
func _purchase_reel_speed() -> void:
|
||||
_purchase_upgrade(true)
|
||||
|
||||
|
|
@ -777,13 +558,6 @@ func _on_network_purchase_finished(
|
|||
_refresh_all()
|
||||
|
||||
|
||||
func _get_selected_catch() -> FishCatchType:
|
||||
var focused_id: StringName = _fish_selection.get_focused_id()
|
||||
if _inventory == null or focused_id.is_empty():
|
||||
return null
|
||||
return _inventory.get_catch_by_id(focused_id)
|
||||
|
||||
|
||||
func _is_transaction_context_valid() -> bool:
|
||||
return (
|
||||
visible
|
||||
|
|
@ -798,27 +572,6 @@ func _is_transaction_context_valid() -> bool:
|
|||
)
|
||||
|
||||
|
||||
func _on_inventory_changed() -> void:
|
||||
_refresh_fish_list()
|
||||
if not _confirmation_catch_ids.is_empty():
|
||||
var preview: FishSaleResultType = _sale_service.preview_batch(
|
||||
_confirmation_catch_ids,
|
||||
_buyer
|
||||
)
|
||||
if (
|
||||
_confirmation_generation != _generation
|
||||
or not preview.is_success()
|
||||
):
|
||||
_close_sale_confirmation()
|
||||
_feedback.text = (
|
||||
"favorited fish cannot be sold. "
|
||||
+ "remove them from the selection first."
|
||||
if preview.status == FishSaleResultType.Status.FAVORITED
|
||||
else preview.get_message()
|
||||
)
|
||||
_refresh_selected_fish()
|
||||
|
||||
|
||||
func _on_wallet_changed(_balance: int, _delta: int) -> void:
|
||||
_refresh_wallet()
|
||||
_refresh_upgrades()
|
||||
|
|
@ -839,7 +592,6 @@ func _on_bag_changed() -> void:
|
|||
|
||||
func _on_cooler_capacity_changed(_level: int, _capacity: int) -> void:
|
||||
_refresh_cooler_capacity()
|
||||
_refresh_fish_list()
|
||||
|
||||
|
||||
func _apply_mouse_close_policy(reason: CloseReason) -> void:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue