local rongyuchenghao = {}
function rongyuchenghao.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
rongyuchenghao.parent = lib:openwin(param1, nil, true, pa
要实现你的需求,需要修改`rongyuchenghao.upmain()`函数中对Image控件的处理逻辑。根据浮生梦老师前端课程内容,这里提供一个解决方案:
```lua
function rongyuchenghao.upmain()
if not rongyuchenghao.parent or not rongyuchenghao.parent._ui then
return
end
local var = tonumber(lib:getstr("U12") or 0) or 0
local ui = rongyuchenghao.parent._ui
local level = var
local next_level = var + 1
local cur_data = rongyuchenghao.parent.cfg[level] or {}
local next_data = rongyuchenghao.parent.cfg[next_level] or {}
local cur_cfg = rongyuchenghao.parent.cfg[1]
local next_cfg = rongyuchenghao.parent.cfg[next_level]
if not next_cfg then
return
end
-- 创建一个临时容器来存储需要重新排序的图片
local images_to_reorder = {}
-- 先收集所有Image控件
for i = 1, 22 do
local imgName = "Image_" .. i
local imgWidget = ui[imgName]
if imgWidget then
images_to_reorder[i] = {
widget = imgWidget,
index = i,
is_completed = (var >= i)
}
end
end
-- 判断是否需要重新排序(当var是8的倍数时)
if var >= 8 and var % 8 == 0 then
local start_index = math.floor((var - 1) / 8) * 8 + 1
local end_index = math.min(start_index + 7, 22)
-- 将已完成的一组放到末尾
for i = start_index, end_index do
if images_to_reorder[i] then
-- 这里需要将控件从当前父节点移除并重新添加到容器末尾
-- 注意:实际实现需要根据你的UI结构来调整
local parent = GUI:getParent(images_to_reorder[i].widget)
if parent and not GUI:Win_IsNull(parent) then
-- 从父节点移除
GUI:removeFromParent(images_to_reorder[i].widget)
-- 重新添加到容器末尾
GUI:ListView_pushBackCustomItem(parent, images_to_reorder[i].widget)
end
end
end
-- 重新排列未完成的控件
local uncompleted_index = 1
for i = 1, 22 do
if images_to_reorder[i] and not images_to_reorder[i].is_completed then
-- 获取控件当前位置
local pos = GUI:getPosition(images_to_reorder[i].widget)
-- 设置新的位置(向上补位)
GUI:setPositionY(images_to_reorder[i].widget,
pos.y - (math.floor((i-1)/8) * 40)) -- 假设每个控件高度为40
end
end
end
-- 处理Text控件的颜色
for i = 1, 22 do
local textName = "Text_" .. i
local textWidget = ui[textName]
if textWidget then
if var >= i then
GUI:setVisible(textWidget, true)
GUI:Text_setTextColor(textWidget, "#c0c0c0")
else
GUI:setVisible(textWidget, true)
GUI:Text_setTextColor(textWidget, "#808080")
end
end
end
create_attr(cur_data, next_data)
-- 创建扣除物品框
lib:createitemlist(ui.item_layout, next_cfg, 10)
-- 绿点
if lib:checkitem(next_cfg, true) then
rongyuchenghao.btn_green_frames = lib:create_green_point(ui["Button_1"], 108, 6)
else
lib:remove_widget(rongyuchenghao.btn_green_frames)
end
GUI:addOnClickEvent(ui["Button_1"], function()
GUI:delayTouchEnabled(ui["Button_1"], 0.2)
local msg = {}
msg.Script = rongyuchenghao.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, rongyuchenghao.param2, 0, 0, jsonstr)
end)
end
```
**关键点说明:**
1. **判断时机**:当`var >= 8`且是8的倍数时(8, 16, 24...)触发重新排序
2. **分组处理**:每次处理8个一组的Image控件
3. **已完成组放到末尾**:使用`GUI:ListView_pushBackCustomItem()`将完成的一组添加到容器末尾
4. **未完成组向上补位**:调整未完成控件的位置,填补空缺
5. **控件操作**:
- `GUI:getParent()`获取父节点
- `GUI:removeFromParent()`从父节点移除
- `GUI:setPositionY()`设置垂直位置
**注意**:代码中的位置调整值(如40)需要根据你的实际UI布局进行调整。如果控件不是在ListView中,可能需要使用其他布局方法。