Implement 40250 classic client port
This commit is contained in:
@@ -16,9 +16,11 @@ var _self_box: VBoxContainer
|
||||
var _peer_box: VBoxContainer
|
||||
var _self_gold: Label
|
||||
var _peer_gold: Label
|
||||
var _status: Label
|
||||
var _accept_btn: Button
|
||||
var _gold_input: LineEdit
|
||||
var _next_display := 0
|
||||
var _offered_cells := {}
|
||||
|
||||
func setup(m2client: Node, parent: Node, proto_node: Node = null) -> void:
|
||||
client = m2client
|
||||
@@ -31,9 +33,29 @@ func is_open() -> bool:
|
||||
return _root != null and _root.visible
|
||||
|
||||
func offer(inv_window: int, inv_cell: int) -> void:
|
||||
if is_open():
|
||||
client.exchange_add_item(inv_window, inv_cell, _next_display)
|
||||
if not is_open() or inv_window < 0 or inv_cell < 0:
|
||||
return
|
||||
var key := "%d:%d" % [inv_window, inv_cell]
|
||||
if _offered_cells.has(key):
|
||||
_status.text = "该物品已经放入交易"
|
||||
return
|
||||
var x: Dictionary = client.get_exchange()
|
||||
var used := {}
|
||||
for item in x.get("self_items", []):
|
||||
used[int(item.get("slot", -1))] = true
|
||||
for i in 12:
|
||||
if not used.has(i):
|
||||
_next_display = i
|
||||
break
|
||||
if used.size() >= 12:
|
||||
_status.text = "交易物品栏已满"
|
||||
return
|
||||
if client.exchange_add_item(inv_window, inv_cell, _next_display):
|
||||
_offered_cells[key] = true
|
||||
_next_display = (_next_display + 1) % 12
|
||||
_status.text = ""
|
||||
else:
|
||||
_status.text = "交易请求发送失败"
|
||||
|
||||
func _name_of(vnum: int) -> String:
|
||||
if proto and proto.has_method("item"):
|
||||
@@ -50,6 +72,9 @@ func refresh() -> void:
|
||||
if not x.get("active", false):
|
||||
_root.visible = false
|
||||
_next_display = 0
|
||||
_offered_cells.clear()
|
||||
_gold_input.text = ""
|
||||
_status.text = ""
|
||||
return
|
||||
_root.visible = true
|
||||
_fill(_self_box, x.get("self_items", []))
|
||||
@@ -61,6 +86,7 @@ func refresh() -> void:
|
||||
_accept_btn.text = "已接受 ✓" if me else "接受"
|
||||
_accept_btn.modulate = Color(0.5, 1, 0.5) if me else Color(1, 1, 1)
|
||||
_root.get_node("PeerAccept").text = "对方: 已接受" if peer else "对方: 未接受"
|
||||
_status.text = ""
|
||||
|
||||
func _fill(box: VBoxContainer, rows: Array) -> void:
|
||||
for c in box.get_children():
|
||||
@@ -72,9 +98,19 @@ func _fill(box: VBoxContainer, rows: Array) -> void:
|
||||
box.add_child(l)
|
||||
|
||||
func _on_put_gold() -> void:
|
||||
var g := int(_gold_input.text)
|
||||
if g > 0:
|
||||
client.exchange_add_gold(g)
|
||||
var raw := _gold_input.text.strip_edges()
|
||||
if raw == "" or not raw.is_valid_int():
|
||||
_status.text = "请输入有效金币数量"
|
||||
return
|
||||
var g := int(raw)
|
||||
if g <= 0 or g > 2000000000:
|
||||
_status.text = "金币数量必须在 1~2000000000 之间"
|
||||
return
|
||||
if client.exchange_add_gold(g):
|
||||
_gold_input.text = ""
|
||||
_status.text = ""
|
||||
else:
|
||||
_status.text = "金币请求发送失败"
|
||||
|
||||
func _build(parent: Node) -> void:
|
||||
_root = Control.new()
|
||||
@@ -121,6 +157,11 @@ func _build(parent: Node) -> void:
|
||||
_peer_gold.text = "金币: 0"
|
||||
_peer_gold.position = Vector2(240, 250)
|
||||
_root.add_child(_peer_gold)
|
||||
_status = Label.new()
|
||||
_status.position = Vector2(20, 276)
|
||||
_status.add_theme_font_size_override("font_size", 11)
|
||||
_status.add_theme_color_override("font_color", Color(1, 0.65, 0.55))
|
||||
_root.add_child(_status)
|
||||
|
||||
var pa := Label.new()
|
||||
pa.name = "PeerAccept"
|
||||
@@ -130,7 +171,7 @@ func _build(parent: Node) -> void:
|
||||
_root.add_child(pa)
|
||||
|
||||
var bottom := HBoxContainer.new()
|
||||
bottom.position = Vector2(20, 300)
|
||||
bottom.position = Vector2(20, 310)
|
||||
_root.add_child(bottom)
|
||||
_gold_input = LineEdit.new()
|
||||
_gold_input.placeholder_text = "金币"
|
||||
|
||||
Reference in New Issue
Block a user