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
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-20 20:25:24 |
👁️ 阅读: 20
根据你的需求,需要在 `upmain` 函数中根据 `var` 的等级来显示对应的 Image 控件。这里 `var` 就是当前等级,范围是 0 到 22。
我们可以通过一个循环来设置这些 Image 的可见性:当 `var >= 目标等级` 时,显示对应的 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 cur_cfg = rongyuchenghao.parent.cfg[level]
local next_level = var + 1
local next_cfg = rongyuchenghao.parent.cfg[next_level]
if not next_cfg then
return
end
-- 设置 Image_23 到 Image_44 的可见性
for i = 23, 44 do
local imgName = "Image_" .. i
local imgWidget = ui[imgName]
if imgWidget then
-- 目标等级 = i - 22 (因为 Image_23 对应等级1)
local targetLevel = i - 22
if var >= targetLevel then
GUI:setVisible(imgWidget, true)
else
GUI:setVisible(imgWidget, false)
end
end
end
lib:create_attr_list_single(ui.attr_layout, next_cfg, true, 12, nil, nil, nil, 0, true, 0, false)
lib:create_attr_list_single(ui.attr_layout_1, cur_cfg, true, 12)
--创建扣除物品框
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)
-- if not lib:checkitem(next_cfg) then
-- return
-- end
local msg = {}
msg.Script = rongyuchenghao.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, rongyuchenghao.param2, 0, 0, jsonstr)
end)
end
```
**代码说明:**
1. **循环控制**:`for i = 23, 44 do` 遍历所有 Image 控件名称(Image_23 到 Image_44)。
2. **获取控件**:`local imgWidget = ui[imgName]` 从界面表中获取对应的控件对象。
3. **计算目标等级**:`local targetLevel = i - 22`,因为 Image_23 对应等级1,Image_24 对应等级2,以此类推。
4. **设置可见性**:使用 `GUI:setVisible(imgWidget, true/false)` 来显示或隐藏控件。
- 当 `var >= targetLevel` 时显示(已达成该等级)
- 否则隐藏(未达成该等级)
**效果示例:**
- 当 `var = 0`(等级0):所有 Image 都隐藏
- 当 `var = 1`:显示 Image_23
- 当 `var = 2`:显示 Image_23、Image_24
- 当 `var = 3`:显示 Image_23、Image_24、Image_25
- ...以此类推,直到 `var = 22` 显示所有 Image
这样就能根据当前等级动态显示对应的进度图片了。如果还有不明白的地方,随时问我!
根据你的需求,需要在 `upmain` 函数中根据 `var` 的等级来显示对应的 Image 控件。这里 `var` 就是当前等级,范围是 0 到 22。
我们可以通过一个循环来设置这些 Image 的可见性:当 `var >= 目标等级` 时,显示对应的 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 cur_cfg = rongyuchenghao.parent.cfg[level]
local next_level = var + 1
local next_cfg = rongyuchenghao.parent.cfg[next_level]
if not next_cfg then
return
end
-- 设置 Image_23 到 Image_44 的可见性
for i = 23, 44 do
local imgName = "Image_" .. i
local imgWidget = ui[imgName]
if imgWidget then
-- 目标等级 = i - 22 (因为 Image_23 对应等级1)
local targetLevel = i - 22
if var >= targetLevel then
GUI:setVisible(imgWidget, true)
else
GUI:setVisible(imgWidget, false)
end
end
end
lib:create_attr_list_single(ui.attr_layout, next_cfg, true, 12, nil, nil, nil, 0, true, 0, false)
lib:create_attr_list_single(ui.attr_layout_1, cur_cfg, true, 12)
--创建扣除物品框
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)
-- if not lib:checkitem(next_cfg) then
-- return
-- end
local msg = {}
msg.Script = rongyuchenghao.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, rongyuchenghao.param2, 0, 0, jsonstr)
end)
end
```
**代码说明:**
1. **循环控制**:`for i = 23, 44 do` 遍历所有 Image 控件名称(Image_23 到 Image_44)。
2. **获取控件**:`local imgWidget = ui[imgName]` 从界面表中获取对应的控件对象。
3. **计算目标等级**:`local targetLevel = i - 22`,因为 Image_23 对应等级1,Image_24 对应等级2,以此类推。
4. **设置可见性**:使用 `GUI:setVisible(imgWidget, true/false)` 来显示或隐藏控件。
- 当 `var >= targetLevel` 时显示(已达成该等级)
- 否则隐藏(未达成该等级)
**效果示例:**
- 当 `var = 0`(等级0):所有 Image 都隐藏
- 当 `var = 1`:显示 Image_23
- 当 `var = 2`:显示 Image_23、Image_24
- 当 `var = 3`:显示 Image_23、Image_24、Image_25
- ...以此类推,直到 `var = 22` 显示所有 Image
这样就能根据当前等级动态显示对应的进度图片了。如果还有不明白的地方,随时问我!
← 返回问答库