Bag = {}
function Bag.Init(isWin32)
-- 网格配置
Bag._ScrollHeight = isWin32 and 214 or 320 -- 容器滚动区域的高度
Bag._PWidth = isWin32 and 338 or 500 -- 容器可见区域 宽
Bag._PHeight = isWin32 and 214 or 320 -- 容器可见区域 高
Bag._IW
```lua
-- 根据浮生梦老师前端课程内容,修改物品ID获取方式
-- 使用已知的物品ID直接查询
-- 修改:定义要检测的物品ID列表
Bag._targetItemIds = {
12256, -- 九天玄气ツ阴阳逆乱
12257, -- 乾坤定星盘
12258, -- 鬼新娘の呼唤
12259, -- 帝乙木敕令
12267 -- 无极剑魂·道天一心
}
-- 修改:从服务器获取物品数据
function Bag.GetItemData()
Bag._itemList = {}
for _, itemId in ipairs(Bag._targetItemIds) do
-- 获取背包中该道具的数量
local itemCount = SL:GetMetaValue("ITEM_COUNT", itemId)
if itemCount and itemCount > 0 then
-- 获取物品名称
local itemName = SL:GetMetaValue("ITEM_NAME", itemId)
-- 获取背包中该道具的MakeIndex(唯一ID)
local makeIndex = SL:GetMetaValue("BAG_MAKEINDEX_BY_POS", itemId)
if makeIndex then
table.insert(Bag._itemList, {
id = itemId,
makeIndex = makeIndex,
name = itemName or "未知物品",
count = itemCount,
-- 获取物品图标
icon = SL:GetMetaValue("ITEM_ICON", itemId) or "res/public/1900000612.png"
})
end
end
end
SL:Print("获取到指定物品数量:" .. #Bag._itemList)
-- 更新显示
if Bag.UpdateItemDisplay then
Bag.UpdateItemDisplay()
end
end
-- 注意:原代码中的ITEM_ID_BY_NAME函数在浮生梦老师前端课程内容中未找到
-- 已改为直接使用已知的物品ID进行查询,这样更高效可靠
```