完善客户端功能并同步差距文档

This commit is contained in:
shenlei
2026-09-03 18:40:01 +09:00
parent f93a172296
commit 13ccb8d02d
135 changed files with 21881 additions and 1259 deletions
+112 -3
View File
@@ -7,17 +7,29 @@
# `mall_opened` → 显示;`mall_changed` → 刷新。列出商城道具 + [取出](放进背包第一个空格)。
extends Node
const ItemTooltip = preload("res://ui/item_tooltip.gd")
var client: Node
var proto: Node
var _tooltip_builder: RefCounted
var _root: Control
var _list: VBoxContainer
var _title: Label
var _status: Label
var _password_dialog: ConfirmationDialog
var item_mouse: Node
const MALL_WINDOW := 4
const MALL_PAGE_SLOTS := 45
var _grid: GridContainer
var _cells: Dictionary = {}
var _page_label: Label
var _page := 0
func setup(m2client: Node, parent: Node, proto_node: Node = null) -> void:
client = m2client
proto = proto_node
_tooltip_builder = ItemTooltip.new()
_tooltip_builder.setup(AssetRoot.path(), "en", proto)
_build(parent)
if client.has_signal("mall_opened"):
client.mall_opened.connect(func(_s): refresh())
@@ -30,8 +42,13 @@ func is_open() -> bool:
return _root != null and _root.visible
func close() -> void:
if item_mouse and item_mouse.has_method("unregister_owner"):
item_mouse.unregister_owner(self)
if item_mouse.has_method("is_attached") and item_mouse.is_attached():
item_mouse.cancel()
if _root:
_root.visible = false
_page = 0
if is_instance_valid(_password_dialog):
_password_dialog.queue_free()
_password_dialog = null
@@ -44,6 +61,13 @@ func _name_of(vnum: int) -> String:
return n
return "#%d" % vnum
func _tooltip_for(item: Dictionary) -> String:
var vnum := int(item.get("vnum", 0))
if _tooltip_builder:
var pd: Dictionary = proto.item(vnum) if proto and proto.has_method("item") else {}
return _tooltip_builder.format(vnum, int(item.get("count", 1)), pd, item) + "\n拖到背包取出"
return "%s\n#%d ×%d\n拖到背包取出" % [_name_of(vnum), vnum, int(item.get("count", 1))]
func _first_free_inv() -> int:
var used := {}
for it in client.get_inventory():
@@ -60,9 +84,13 @@ func refresh() -> void:
if not _root.visible:
return
_status.text = ""
_title.text = "道具商城仓库(%d 格)" % client.get_mall_size()
var pages := maxi(1, int(ceil(float(client.get_mall_size()) / float(MALL_PAGE_SLOTS))))
_page = clampi(_page, 0, pages - 1)
_title.text = "道具商城仓库(第 %d/%d 页)" % [_page + 1, pages]
_page_label.text = "%d / %d" % [_page + 1, pages]
for c in _list.get_children():
c.queue_free()
_render_grid()
var items: Array = client.get_mall_items()
if items.is_empty():
var e := Label.new()
@@ -72,6 +100,47 @@ func refresh() -> void:
for it in items:
_list.add_child(_row(it))
func _render_grid() -> void:
if _grid == null:
return
for pos in _cells:
var cell: Button = _cells[pos]
cell.text = ""
cell.tooltip_text = ""
cell.set_meta("vnum", 0)
cell.set_meta("count", 0)
var items: Array = client.get_mall_items() if client and client.has_method("get_mall_items") else []
for it in items:
var absolute_pos := int(it.get("cell", -1))
var pos := absolute_pos - _page * MALL_PAGE_SLOTS
if not _cells.has(pos):
continue
var vnum := int(it.get("vnum", 0))
var count := int(it.get("count", 1))
var cell: Button = _cells[pos]
cell.text = "%s%s" % [_name_of(vnum).substr(0, 7), (" ×%d" % count) if count > 1 else ""]
cell.tooltip_text = _tooltip_for(it)
cell.set_meta("vnum", vnum)
cell.set_meta("count", count)
func _on_grid_input(local_pos: int, event: InputEvent) -> void:
if not item_mouse or not item_mouse.has_method("attach_item"):
return
if not (event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT
and event.pressed):
return
var cell: Button = _cells[local_pos]
var vnum := int(cell.get_meta("vnum", 0))
if vnum == 0:
return
item_mouse.attach_item(MALL_WINDOW, _page * MALL_PAGE_SLOTS + local_pos, vnum,
int(cell.get_meta("count", 1)), null, "mall")
func _change_page(delta: int) -> void:
var pages := maxi(1, int(ceil(float(client.get_mall_size()) / float(MALL_PAGE_SLOTS))))
_page = clampi(_page + delta, 0, pages - 1)
refresh()
func _ask_password() -> void:
if is_instance_valid(_password_dialog):
_password_dialog.queue_free()
@@ -100,14 +169,22 @@ func _ask_password() -> void:
func _row(it: Dictionary) -> Control:
var row := HBoxContainer.new()
row.custom_minimum_size = Vector2(300, 0)
var vnum := int(it.get("vnum", 0))
var count := int(it.get("count", 1))
var cell := int(it.get("cell", 0))
var nm := Label.new()
nm.text = "%s ×%d" % [_name_of(int(it.get("vnum", 0))), int(it.get("count", 1))]
nm.text = "%s ×%d" % [_name_of(vnum), count]
nm.custom_minimum_size = Vector2(220, 0)
nm.add_theme_font_size_override("font_size", 12)
row.add_child(nm)
if item_mouse:
nm.mouse_filter = Control.MOUSE_FILTER_STOP
nm.gui_input.connect(func(e: InputEvent):
if e is InputEventMouseButton and e.button_index == MOUSE_BUTTON_LEFT and e.pressed \
and item_mouse.has_method("attach_item"):
item_mouse.attach_item(MALL_WINDOW, cell, vnum, count, null, "mall"))
var out := Button.new()
out.text = "取出"
var cell := int(it.get("cell", 0))
out.pressed.connect(func() -> void:
var target := _first_free_inv()
if target < 0:
@@ -135,6 +212,24 @@ func _build(parent: Node) -> void:
_title.text = "道具商城仓库"
_title.add_theme_font_size_override("font_size", 16)
box.add_child(_title)
var pager := HBoxContainer.new()
pager.position = Vector2(230, 0)
pager.size = Vector2(90, 24)
var prev := Button.new()
prev.text = ""
prev.custom_minimum_size = Vector2(28, 24)
prev.pressed.connect(func(): _change_page(-1))
pager.add_child(prev)
_page_label = Label.new()
_page_label.custom_minimum_size = Vector2(40, 24)
_page_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
pager.add_child(_page_label)
var next := Button.new()
next.text = ""
next.custom_minimum_size = Vector2(28, 24)
next.pressed.connect(func(): _change_page(1))
pager.add_child(next)
_root.add_child(pager)
_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))
@@ -145,6 +240,20 @@ func _build(parent: Node) -> void:
_list = VBoxContainer.new()
_list.add_theme_constant_override("separation", 4)
sc.add_child(_list)
_list.visible = false
_grid = GridContainer.new()
_grid.columns = 5
_grid.position = Vector2(16, 58)
_grid.add_theme_constant_override("h_separation", 4)
_grid.add_theme_constant_override("v_separation", 4)
_root.add_child(_grid)
for pos in MALL_PAGE_SLOTS:
var cell := Button.new()
cell.custom_minimum_size = Vector2(58, 30)
cell.add_theme_font_size_override("font_size", 9)
cell.gui_input.connect(func(e: InputEvent): _on_grid_input(pos, e))
_grid.add_child(cell)
_cells[pos] = cell
var close := Button.new()
close.text = "关闭"
close.pressed.connect(func() -> void: _root.visible = false)