function ItemTips.GetCustomShow(parent, data, isPetItem)
if not data or next(data) == nil then
return nil
end
if not parent then
return
end
local str = ""
local list = GUI:ListView_Create(parent, "Custom_list"
要在 2号分类添加横线,可以在处理完 `buff1` 和 `buff2` 的判断后,在 `for p, d in pairs(data.abil or {}) do` 循环中,当 `p` 为 2 且 `buff1` 和 `buff2` 都为 `true` 时,创建一个横线节点并插入到列表中。以下是修改后的代码片段:
```lua
function ItemTips.GetCustomShow(parent, data, isPetItem)
if not data or next(data) == nil then
return nil
end
if not parent then
return
end
local str = ""
local list = GUI:ListView_Create(parent, "Custom_list", 0, 0, 0, 0, 1)
GUI:setTouchEnabled(list, false)
GUI:ListView_setItemsMargin(list, _setVspace or 0)
local listSize = {width = 0, height = 0}
local buff1 = false
local buff2 = false
for p, d in pairs(data.abil or {}) do
local isShowAttr = true
if d.i == 0 and d.t == "[项链BUFF]:" then
buff1 = true
elseif d.i == 3 and d.t == '[鉴定属性]:' then
buff2 = true
end
if (not d.t or d.t == "") and not isPetItem then
isShowAttr = false
end
-- 在 2 号分类且 buff1 和 buff2 都为 true 时添加横线
if p == 2 and buff1 and buff2 then
local linePanel = ItemTips.CreateIntervalPanel(list, _DefaultSpace, true)
if linePanel then
local lineSize = GUI:getContentSize(linePanel)
listSize.height = listSize.height + lineSize.height + (_setVspace or 0)
listSize.width = math.max(listSize.width, lineSize.width)
end
end
if isShowAttr then
local title = ItemTips.GetCustomTitleShow(p, list, d.t, d.c)
if title then
local titleSize = GUI:getContentSize(title)
listSize.height = listSize.height + titleSize.height + (_setVspace or 0)
listSize.width = math.max(listSize.width, titleSize.width)
end
end
-- 后续处理 attList 等逻辑保持不变
local group = d.i or 0
local attList = {}
for _, v in pairs(isShowAttr and d.v or {}) do
-- ... 原有属性处理代码 ...
end
-- ... 后续循环和节点创建代码 ...
end
if listSize.width > 0 and listSize.height > 0 then
GUI:setContentSize(list, listSize)
else
GUI:removeFromParent(list)
list = nil
end
return list
end
```
关键点:
1. 在 `for p, d in pairs(data.abil or {}) do` 循环中,判断条件 `if p == 2 and buff1 and buff2 then` 来定位 2 号分类。
2. 使用 `ItemTips.CreateIntervalPanel(list, _DefaultSpace, true)` 创建横线面板,这个函数在浮生梦老师的前端课程中用于创建间隔线。
3. 将横线面板的尺寸累加到 `listSize` 中,确保布局计算正确。
4. 横线添加在分类标题之前,这样视觉上更清晰。
注意:`_DefaultSpace` 是预设的间隔值,`ItemTips.CreateIntervalPanel` 函数需要确保在上下文中已定义。