Implement 40250 classic client port
This commit is contained in:
+44
-4
@@ -18,6 +18,7 @@ var _root: Control
|
||||
var _tabbar: HBoxContainer
|
||||
var _list: VBoxContainer
|
||||
var _err: Label
|
||||
var _sell_quantity: SpinBox
|
||||
var _active_tab := 0
|
||||
|
||||
func setup(m2client: Node, parent: Node, proto_node: Node = null, ilist: RefCounted = null) -> void:
|
||||
@@ -38,19 +39,27 @@ func is_open() -> bool:
|
||||
func open() -> void:
|
||||
_root.visible = true
|
||||
_err.text = ""
|
||||
_sell_quantity.value = 1
|
||||
_active_tab = 0
|
||||
refresh()
|
||||
|
||||
func _close() -> void:
|
||||
_root.visible = false
|
||||
_err.text = ""
|
||||
if _sell_quantity:
|
||||
_sell_quantity.value = 1
|
||||
|
||||
func close_and_leave() -> void:
|
||||
client.shop_close()
|
||||
_close()
|
||||
|
||||
func sell(inv_cell: int, count: int = 1) -> void:
|
||||
if is_open():
|
||||
client.shop_sell(inv_cell, count)
|
||||
func sell(inv_cell: int, count: int = -1) -> void:
|
||||
if not is_open() or inv_cell < 0:
|
||||
return
|
||||
var amount := count if count > 0 else int(_sell_quantity.value)
|
||||
amount = clampi(amount, 1, 200)
|
||||
if client.has_method("shop_sell") and not client.shop_sell(inv_cell, amount):
|
||||
_on_error("SEND_FAILED")
|
||||
|
||||
func _name_of(vnum: int) -> String:
|
||||
if proto and proto.has_method("item"):
|
||||
@@ -122,7 +131,19 @@ func _row(it: Dictionary, pos_base := 0) -> Control:
|
||||
var buy := Button.new()
|
||||
buy.text = "买"
|
||||
var pos := pos_base + int(it.get("pos", 0))
|
||||
buy.pressed.connect(func() -> void: client.shop_buy(pos, 1))
|
||||
var stock := int(it.get("count", 0))
|
||||
var quantity := SpinBox.new()
|
||||
quantity.name = "Quantity"
|
||||
quantity.min_value = 1
|
||||
quantity.max_value = clampi(stock if stock > 0 else 200, 1, 200)
|
||||
quantity.step = 1
|
||||
quantity.value = 1
|
||||
quantity.custom_minimum_size = Vector2(64, 0)
|
||||
row.add_child(quantity)
|
||||
buy.pressed.connect(func() -> void:
|
||||
var amount := clampi(int(quantity.value), 1, int(quantity.max_value))
|
||||
if not client.shop_buy(pos, amount):
|
||||
_on_error("SEND_FAILED"))
|
||||
row.add_child(buy)
|
||||
return row
|
||||
|
||||
@@ -132,6 +153,11 @@ func _on_error(kind: String) -> void:
|
||||
"SOLDOUT": "已售罄",
|
||||
"INVENTORY_FULL": "背包已满",
|
||||
"INVALID_POS": "位置无效",
|
||||
"NOT_ENOUGH_ITEM": "物品数量不足",
|
||||
"CANNOT_BUY": "当前物品不可购买",
|
||||
"CANNOT_SELL": "当前物品不可出售",
|
||||
"SHOP_BUSY": "商店正在处理上一笔交易",
|
||||
"SEND_FAILED": "交易请求发送失败",
|
||||
}
|
||||
_err.text = str(tbl.get(kind, kind))
|
||||
|
||||
@@ -159,6 +185,20 @@ func _build(parent: Node) -> void:
|
||||
_err.modulate = Color(1, 0.4, 0.4)
|
||||
_err.add_theme_font_size_override("font_size", 12)
|
||||
_root.add_child(_err)
|
||||
var sell_hint := Label.new()
|
||||
sell_hint.text = "出售数量(背包右键):"
|
||||
sell_hint.position = Vector2(12, 360)
|
||||
sell_hint.add_theme_font_size_override("font_size", 11)
|
||||
_root.add_child(sell_hint)
|
||||
_sell_quantity = SpinBox.new()
|
||||
_sell_quantity.name = "SellQuantity"
|
||||
_sell_quantity.min_value = 1
|
||||
_sell_quantity.max_value = 200
|
||||
_sell_quantity.value = 1
|
||||
_sell_quantity.step = 1
|
||||
_sell_quantity.position = Vector2(160, 356)
|
||||
_sell_quantity.size = Vector2(70, 26)
|
||||
_root.add_child(_sell_quantity)
|
||||
_tabbar = HBoxContainer.new()
|
||||
_tabbar.position = Vector2(12, 30)
|
||||
_tabbar.add_theme_constant_override("separation", 4)
|
||||
|
||||
Reference in New Issue
Block a user