Implement 40250 classic client port
This commit is contained in:
@@ -15,6 +15,8 @@ var _root: Control
|
||||
var _list: VBoxContainer
|
||||
var _gold: Label
|
||||
var _title: Label
|
||||
var _status: Label
|
||||
var _password_dialog: ConfirmationDialog
|
||||
|
||||
func setup(m2client: Node, parent: Node, proto_node: Node = null) -> void:
|
||||
client = m2client
|
||||
@@ -22,13 +24,25 @@ func setup(m2client: Node, parent: Node, proto_node: Node = null) -> void:
|
||||
_build(parent)
|
||||
if client.has_signal("safebox_changed"):
|
||||
client.safebox_changed.connect(refresh)
|
||||
if client.has_signal("safebox_password_required"):
|
||||
client.safebox_password_required.connect(func(): _ask_password("safebox"))
|
||||
if client.has_signal("safebox_wrong_password"):
|
||||
client.safebox_wrong_password.connect(func():
|
||||
if is_instance_valid(_status):
|
||||
_status.text = "仓库密码错误")
|
||||
|
||||
func is_open() -> bool:
|
||||
return _root != null and _root.visible
|
||||
|
||||
func deposit(inv_window: int, inv_cell: int) -> void:
|
||||
if is_open():
|
||||
client.safebox_checkin(_next_free_slot(), inv_window, inv_cell)
|
||||
if not is_open() or inv_window < 0 or inv_cell < 0:
|
||||
return
|
||||
var safe_pos := _next_free_slot()
|
||||
if safe_pos < 0:
|
||||
_status.text = "仓库已满"
|
||||
return
|
||||
if client.has_method("safebox_checkin") and not client.safebox_checkin(safe_pos, inv_window, inv_cell):
|
||||
_status.text = "存入请求发送失败"
|
||||
|
||||
func _next_free_slot() -> int:
|
||||
var used := {}
|
||||
@@ -38,7 +52,7 @@ func _next_free_slot() -> int:
|
||||
for i in range(cap):
|
||||
if not used.has(i):
|
||||
return i
|
||||
return 0
|
||||
return -1
|
||||
|
||||
func _name_of(vnum: int) -> String:
|
||||
if proto and proto.has_method("item"):
|
||||
@@ -54,6 +68,7 @@ func refresh() -> void:
|
||||
_root.visible = client.is_safebox_open()
|
||||
if not _root.visible:
|
||||
return
|
||||
_status.text = ""
|
||||
_title.text = "仓库(%d 页)" % client.get_safebox_size()
|
||||
_gold.text = "仓库金币: %d" % client.get_safebox_gold()
|
||||
for c in _list.get_children():
|
||||
@@ -67,6 +82,32 @@ func refresh() -> void:
|
||||
for it in items:
|
||||
_list.add_child(_row(it))
|
||||
|
||||
func _ask_password(kind: String) -> void:
|
||||
if is_instance_valid(_password_dialog):
|
||||
_password_dialog.queue_free()
|
||||
_password_dialog = ConfirmationDialog.new()
|
||||
_password_dialog.title = "商城密码" if kind == "mall" else "仓库密码"
|
||||
_password_dialog.dialog_text = "请输入 1~6 位密码"
|
||||
_password_dialog.ok_button_text = "确认"
|
||||
_password_dialog.cancel_button_text = "取消"
|
||||
var edit := LineEdit.new()
|
||||
edit.secret = true
|
||||
edit.max_length = 6
|
||||
edit.placeholder_text = "密码"
|
||||
edit.custom_minimum_size = Vector2(220, 28)
|
||||
_password_dialog.add_child(edit)
|
||||
_password_dialog.confirmed.connect(func() -> void:
|
||||
var sent: bool = client.safebox_password(edit.text) if kind == "safebox" else client.mall_password(edit.text)
|
||||
if not sent and is_instance_valid(_status):
|
||||
_status.text = "密码格式无效"
|
||||
_password_dialog.queue_free()
|
||||
_password_dialog = null)
|
||||
_password_dialog.canceled.connect(func() -> void:
|
||||
_password_dialog.queue_free()
|
||||
_password_dialog = null)
|
||||
_root.get_parent().add_child(_password_dialog)
|
||||
_password_dialog.popup_centered()
|
||||
|
||||
func _row(it: Dictionary) -> Control:
|
||||
var row := HBoxContainer.new()
|
||||
row.custom_minimum_size = Vector2(300, 0)
|
||||
@@ -78,7 +119,13 @@ func _row(it: Dictionary) -> Control:
|
||||
var out := Button.new()
|
||||
out.text = "取出"
|
||||
var cell := int(it.get("cell", 0))
|
||||
out.pressed.connect(func() -> void: client.safebox_checkout(cell, 1, _first_free_inv()))
|
||||
out.pressed.connect(func() -> void:
|
||||
var target := _first_free_inv()
|
||||
if target < 0:
|
||||
_status.text = "背包已满"
|
||||
return
|
||||
if not client.safebox_checkout(cell, 1, target):
|
||||
_status.text = "取出请求发送失败")
|
||||
row.add_child(out)
|
||||
return row
|
||||
|
||||
@@ -89,7 +136,7 @@ func _first_free_inv() -> int:
|
||||
for i in range(90):
|
||||
if not used.has(i):
|
||||
return i
|
||||
return 0
|
||||
return -1
|
||||
|
||||
func _build(parent: Node) -> void:
|
||||
_root = Control.new()
|
||||
@@ -116,6 +163,11 @@ func _build(parent: Node) -> void:
|
||||
_gold.modulate = Color(0.95, 0.85, 0.5)
|
||||
_gold.add_theme_font_size_override("font_size", 12)
|
||||
_root.add_child(_gold)
|
||||
_status = Label.new()
|
||||
_status.position = Vector2(12, 382)
|
||||
_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)
|
||||
_list = VBoxContainer.new()
|
||||
_list.position = Vector2(12, 54)
|
||||
_list.add_theme_constant_override("separation", 4)
|
||||
|
||||
Reference in New Issue
Block a user