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
我来帮你分析这个需求。你需要根据 `var` 值动态调整 Image_1 到 Image_22 在列表容器中的位置。
首先,你需要一个列表容器来管理这些图片。从你的代码看,`ui` 中应该已经有一个列表容器,但代码中没有明确显示。我假设你有一个名为 `ListView_1` 的列表容器。
这里是一个实现方案:
```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
-- 假设你的列表容器是 ListView_1
local listView = ui["ListView_1"]
if not listView or GUI:Win_IsNull(listView) then
SL:Print("列表容器不存在")
return
end
-- 先清空列表容器
GUI:ListView_removeAllItems(listView)
-- 计算分组
local completedGroup = math.floor(var / 8) -- 已完成的组数
local currentGroup = completedGroup + 1 -- 当前进行中的组
-- 第一组:未完成的图片(当前组)
local startIndex = (currentGroup - 1) * 8 + 1
local endIndex = math.min(currentGroup * 8, 22)
for i = startIndex, endIndex do
local imgName = "Image_" .. i
local imgWidget = ui[imgName]
if imgWidget then
-- 添加到列表容器
GUI:ListView_pushBackCustomItem(listView, imgWidget)
-- 设置可见性和状态
if var >= i then
GUI:setVisible(imgWidget, true)
-- 已完成的图片可以设置特殊效果
GUI:setOpacity(imgWidget, 255)
else
GUI:setVisible(imgWidget, true)
GUI:setOpacity(imgWidget, 150) -- 未完成的半透明
end
end
end
-- 第二组:已完成的图片(前面的组)
for group = 1, completedGroup do
local groupStart = (group - 1) * 8 + 1
local groupEnd = group * 8
for i = groupStart, groupEnd do
if i <= 22 then -- 确保不超过22
local imgName = "Image_" .. i
local imgWidget = ui[imgName]
if imgWidget then
-- 添加到列表容器末尾
GUI:ListView_pushBackCustomItem(listView, imgWidget)
-- 已完成的图片
GUI:setVisible(imgWidget, true)
GUI:setOpacity(imgWidget, 255)
end
end
end
end
-- 刷新列表布局
GUI:ListView_doLayout(listView)
-- 原有的其他逻辑保持不变
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 {}
create_attr(cur_data, next_data)
-- ... 其他原有代码
end
```
这个实现的关键点:
1. **分组逻辑**:每8个图片为一组
- `var >= 8`:第一组完成,显示第二组(9-16),第一组(1-8)放末尾
- `var >= 16`:第二组完成,显示第三组(17-22),前两组放末尾
2. **列表容器操作**:
- `GUI:ListView_removeAllItems(listView)` - 清空容器
- `GUI:ListView_pushBackCustomItem(listView, imgWidget)` - 添加图片到末尾
- `GUI:ListView_doLayout(listView)` - 刷新布局
3. **状态显示**:
- 当前组的未完成图片:半透明(`setOpacity(150)`)
- 已完成图片:正常显示(`setOpacity(255)`)
**使用前需要确认**:
1. 你的界面中是否有名为 `ListView_1` 的列表容器?
2. 如果没有,你需要先创建一个列表容器来管理这些图片
如果需要创建列表容器,可以这样:
```lua
-- 在界面初始化时创建列表容器
local listView = GUI:ListView_Create(parent, "ListView_1", x, y, width, height, 1)
GUI:setTouchEnabled(listView, true)
```
这样就能实现你需要的动态排序效果了!