local zhuansheng = {}
function zhuansheng.main(param1, param2, param3, param4)
SL:print("===== 转生界面打开 =====")
lib:Require(param1, function(state)
if state then
if param1 then
zhuansheng.parent = lib:openw
我是lua后端老师!
小仙,你这个需求是要根据转生等级动态显示特效控件,这个逻辑可以这样实现:
```lua
function zhuansheng.upmain()
SL:print("===== 更新转生界面 =====")
if not zhuansheng.parent or not zhuansheng.parent._ui then
return
end
local curLevel = lib:get_zs_level() or 0
local ui = zhuansheng.parent._ui
local cfgs = zhuansheng.parent.cfg
-- 更新等级显示
if GUI:Win_IsNotNull(ui.lv) then
GUI:Text_setString(ui.lv, "Lv" .. curLevel)
end
-- 隐藏所有特效控件
for i = 1, 5 do
local effectName = "Effect_" .. i
if GUI:Win_IsNotNull(ui[effectName]) then
GUI:Win_SetVisible(ui[effectName], false) -- 隐藏特效
end
end
-- 计算需要显示的特效编号
local effectIndex = (curLevel - 1) % 5 + 1 -- 取模运算,1-5循环
local effectName = "Effect_" .. effectIndex
-- 显示对应的特效
if GUI:Win_IsNotNull(ui[effectName]) then
GUI:Win_SetVisible(ui[effectName], true) -- 显示特效
end
local next_level = curLevel + 1
local next_cfg = cfgs[next_level]
if not next_cfg then
lib:msg("转生已满级!")
GUI:Win_Close(zhuansheng.parent._parent)
return
end
-- 创建属性展示
lib:create_attr_list_single(ui.attr_layout, next_cfg, true, 20)
-- 创建扣除物品框
lib:createitemlist(ui.item_layout, next_cfg, 10)
-- 绿点
if lib:checkitem(next_cfg, true) then
zhuansheng.btn_green_frames = lib:create_green_point(ui["Button_1"], 108, 6)
else
lib:remove_widget(zhuansheng.btn_green_frames)
end
-- 设置升级按钮
if GUI:Win_IsNotNull(ui["Button_1"]) then
GUI:addOnClickEvent(ui["Button_1"], function()
SL:print("点击升级按钮")
if not lib:checkitem(next_cfg) then
return
end
GUI:delayTouchEnabled(ui["Button_1"], 0.2)
local msg = {}
msg.Script = zhuansheng.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, 0, 0, 0, jsonstr)
end)
end
SL:print("===== 界面更新完成 =====")
end
```
这个代码的关键点:
1. **先隐藏所有特效**:用循环把5个特效控件都隐藏
2. **计算特效编号**:`(curLevel - 1) % 5 + 1` 这个公式能实现1-5的循环
- curLevel=1时:(1-1)%5+1 = 1 → Effect_1
- curLevel=6时:(6-1)%5+1 = 1 → Effect_1
- curLevel=7时:(7-1)%5+1 = 2 → Effect_2
- 以此类推...
3. **显示对应特效**:只显示计算出来的那个特效控件
这样就能实现你要求的循环显示效果了!小仙,这个取模运算的数学逻辑要理解清楚哦,不懂的话可以问浮生梦尊师!