function lib:create_attr_list_single(parent, data, hide_bg, gap, attr_bg_hight, bg_img_path, bg_img_prefix,
offset_x, has_simple, name_offset_x)
GUI:removeAllChildren(parent)
attr_bg_hight = attr_bg_hight or 22
local parent_size = GUI
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-20 19:29:07 |
👁️ 阅读: 23
我来帮你修改这个函数,增加一个控制序列帧箭头显示/隐藏的参数。
```lua
function lib:create_attr_list_single(parent, data, hide_bg, gap, attr_bg_hight, bg_img_path, bg_img_prefix,
offset_x, has_simple, name_offset_x, show_frames)
-- 增加 show_frames 参数控制序列帧箭头显示/隐藏,默认为true显示
GUI:removeAllChildren(parent)
attr_bg_hight = attr_bg_hight or 22
local parent_size = GUI:getContentSize(parent)
for index = 1, data.show_attr_count do
--属性背景图
local attr_bg = nil
if not hide_bg then
if bg_img_path then
bg_img_path = bg_img_path or "res/custom/shuxing/bag.png"
attr_bg = GUI:Image_Create(parent, "attr_bg_" .. index, 0.00, 0.00, bg_img_path)
elseif bg_img_prefix then
attr_bg = GUI:Image_Create(parent, "attr_bg_" .. index, 0.00, 0.00, bg_img_prefix .. index .. ".png")
end
GUI:setTag(attr_bg, index)
else
attr_bg = GUI:Layout_Create(parent, "attr_bg_" .. index, 0.00, 0.00, parent_size.width, attr_bg_hight,
false)
GUI:setTag(attr_bg, index)
end
local attr_bg_size = GUI:getContentSize(attr_bg)
--属性名
local calc_offset_x = 0
if not data.hide_att_name and data["att_name_" .. index] then
calc_offset_x = name_offset_x or 0
data["att_name_" .. index] = data["att_name_" .. index] or ""
local name_color = SL:GetColorByStyleId(data.name_color) or "#ffffff"
local attr_name = GUI:Text_Create(attr_bg, "attr_name_" .. index, name_offset_x or 0, attr_bg_size.height / 2,
14, name_color, data["att_name_" .. index] .. ":")
GUI:setAnchorPoint(attr_name, 0, 0.5)
calc_offset_x = calc_offset_x + GUI:getContentSize(attr_name).width
end
--属性值x偏移量
offset_x = offset_x or 0
calc_offset_x = calc_offset_x + offset_x
--计算x坐标范围
local x_range = { calc_offset_x, attr_bg_size.width }
--当前属性
local cur_attr_val = data["cur_attr_" .. index] or 0
if type(cur_attr_val) == "number" and has_simple then
cur_attr_val = SL:GetSimpleNumber(cur_attr_val, 2)
end
local cur_color = SL:GetColorByStyleId(data.cur_color) or "#ffffff"
local cur_x_pos = calc_offset_x + math.floor((x_range[2] - x_range[1]) / 2)
local cur_att = GUI:Text_Create(attr_bg, "cur_att_" .. index, cur_x_pos, attr_bg_size.height / 2, 14,
cur_color, cur_attr_val)
GUI:setAnchorPoint(cur_att, 0.5, 0.5)
-- 序列帧箭头 - 根据show_frames参数控制显示/隐藏
if show_frames ~= false then -- 默认true显示,false时隐藏
local frames = lib:frames(attr_bg, "/common", 1, 10, attr_bg_size.width, attr_bg_size.height / 2,
100, -1, 0, index)
GUI:setAnchorPoint(frames, 0.5, 0.5)
GUI:setScaleX(frames,0.5)
GUI:setScaleY(frames,0.5)
-- 如果调用时传入false,则隐藏序列帧
if show_frames == false then
GUI:setVisible(frames, false)
end
end
end
--自适应布局
gap = gap or 10
GUI:UserUILayout(parent, {
dir = 1,
gap = { y = gap },
sortfunc = function(lists)
table.sort(lists, function(a, b)
return GUI:getTag(a) < GUI:getTag(b)
end)
end
})
end
```
**修改说明:**
1. **新增参数**:在函数参数列表最后添加了 `show_frames` 参数
2. **默认行为**:默认值为 `true`(显示序列帧箭头),保持原有功能不变
3. **条件判断**:使用 `if show_frames ~= false then` 包裹序列帧创建代码
4. **显式隐藏**:如果传入 `false`,则调用 `GUI:setVisible(frames, false)` 隐藏序列帧
**使用示例:**
```lua
-- 显示序列帧箭头(默认)
lib:create_attr_list_single(parent, data, false, 10, 22, nil, nil, 0, true, 0)
-- 隐藏序列帧箭头
lib:create_attr_list_single(parent, data, false, 10, 22, nil, nil, 0, true, 0, false)
```
这样修改后,你可以灵活控制是否显示序列帧箭头,不会影响原有代码的调用方式。
← 返回问答库