Implement 40250 classic client port
This commit is contained in:
+42
-2
@@ -12,6 +12,8 @@ var proto: Node
|
||||
var _root: Control
|
||||
var _list: VBoxContainer
|
||||
var _title: Label
|
||||
var _status: Label
|
||||
var _password_dialog: ConfirmationDialog
|
||||
|
||||
func setup(m2client: Node, parent: Node, proto_node: Node = null) -> void:
|
||||
client = m2client
|
||||
@@ -21,6 +23,8 @@ func setup(m2client: Node, parent: Node, proto_node: Node = null) -> void:
|
||||
client.mall_opened.connect(func(_s): refresh())
|
||||
if client.has_signal("mall_changed"):
|
||||
client.mall_changed.connect(refresh)
|
||||
if client.has_signal("mall_password_required"):
|
||||
client.mall_password_required.connect(_ask_password)
|
||||
|
||||
func is_open() -> bool:
|
||||
return _root != null and _root.visible
|
||||
@@ -40,7 +44,7 @@ func _first_free_inv() -> int:
|
||||
for i in range(90):
|
||||
if not used.has(i):
|
||||
return i
|
||||
return 0
|
||||
return -1
|
||||
|
||||
func refresh() -> void:
|
||||
if client == null or _root == null:
|
||||
@@ -48,6 +52,7 @@ func refresh() -> void:
|
||||
_root.visible = client.is_mall_open()
|
||||
if not _root.visible:
|
||||
return
|
||||
_status.text = ""
|
||||
_title.text = "道具商城仓库(%d 格)" % client.get_mall_size()
|
||||
for c in _list.get_children():
|
||||
c.queue_free()
|
||||
@@ -60,6 +65,31 @@ func refresh() -> void:
|
||||
for it in items:
|
||||
_list.add_child(_row(it))
|
||||
|
||||
func _ask_password() -> void:
|
||||
if is_instance_valid(_password_dialog):
|
||||
_password_dialog.queue_free()
|
||||
_password_dialog = ConfirmationDialog.new()
|
||||
_password_dialog.title = "商城密码"
|
||||
_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:
|
||||
if not client.mall_password(edit.text) 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)
|
||||
@@ -71,7 +101,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.mall_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.mall_checkout(cell, 1, target):
|
||||
_status.text = "取出请求发送失败")
|
||||
row.add_child(out)
|
||||
return row
|
||||
|
||||
@@ -92,6 +128,10 @@ func _build(parent: Node) -> void:
|
||||
_title.text = "道具商城仓库"
|
||||
_title.add_theme_font_size_override("font_size", 16)
|
||||
box.add_child(_title)
|
||||
_status = Label.new()
|
||||
_status.add_theme_font_size_override("font_size", 11)
|
||||
_status.add_theme_color_override("font_color", Color(1, 0.65, 0.55))
|
||||
box.add_child(_status)
|
||||
var sc := ScrollContainer.new()
|
||||
sc.custom_minimum_size = Vector2(308, 280)
|
||||
box.add_child(sc)
|
||||
|
||||
Reference in New Issue
Block a user