local leishen = {}
local function showEffect(msgID, p1, p2, p3, msgData)
local data = SL:JsonDecode(msgData, false) or {}
SL:Print("特效数据", data)
local num = data.num or 0
local eff1, eff2 = data.preEff, data.startEff
-- -- 检
我仔细检查了你的代码,发现有几个问题需要修正:
## 主要问题:
1. **GUI:Win_CloseAll() 使用错误**
- 你在按钮点击事件中使用了 `GUI:Win_CloseAll()`,这会关闭所有窗口
- 建议使用 `GUI:Win_Close(leishen.parent._parent)` 只关闭当前窗口
2. **消息处理逻辑问题**
- `showEffect` 函数中的消息处理逻辑有语法错误
- 缺少 `end` 关键字和函数调用括号
3. **定时器使用不规范**
- 应该使用 `SL:ScheduleOnce` 而不是 `SL:Schedule` 用于单次延迟
## 修正后的代码:
```lua
-- 修正showEffect函数中的消息处理
SL:RegisterLuaNetMsg(2028, function(msgID, p1, p2, p3, timeDataStr)
local timeData = SL:JsonDecode(timeDataStr, false) or {}
local totalCount = timeData.totalCount or 0
local percent = timeData.percent or 0
SL:Print("收到后端时间数据:", "剩余时间:", totalCount, "百分比:", percent)
-- 更新主进度条
if not GUI:Win_IsNull(mainLoadingBar) then
GUI:LoadingBar_setPercent(mainLoadingBar, percent)
end
-- 更新所有特效的倒计时文本
for i = 1, num do
if effectObjects[i] and effectObjects[i].countdownText then
if not GUI:Win_IsNull(effectObjects[i].countdownText) then
GUI:Text_setString(effectObjects[i].countdownText, tostring(totalCount))
end
-- 当倒计时为0时触发技能特效
if totalCount == 0 then
if not GUI:Win_IsNull(effectObjects[i].circleEffect) then
-- 创建技能特效
local skillEffect = GUI:Effect_Create(sceneLayer, "skill_effect_" .. i .. math.random(999999),
effectObjects[i].posX, effectObjects[i].posY, 0, eff2, 0, 0, 0, 1)
-- 技能特效动画
if not GUI:Win_IsNull(skillEffect) then
GUI:setOpacity(skillEffect, 255)
local skillAction = GUI:ActionSequence(
GUI:ActionScaleTo(0.2, 2.0),
GUI:DelayTime(0.3),
GUI:ActionFadeTo(0.5, 0),
GUI:CallFunc(function()
GUI:removeFromParent(skillEffect)
end)
)
GUI:runAction(skillEffect, skillAction)
end
-- 清理单个特效
if not GUI:Win_IsNull(effectObjects[i].countdownText) then
GUI:removeFromParent(effectObjects[i].countdownText)
end
if not GUI:Win_IsNull(effectObjects[i].circleEffect) then
GUI:removeFromParent(effectObjects[i].circleEffect)
end
end
end
end
end
-- 所有倒计时结束,清理场景
if totalCount == 0 then
-- 使用正确的单次定时器
SL:ScheduleOnce(function()
if not GUI:Win_IsNull(sceneLayer) then
GUI:removeFromParent(sceneLayer)
end
-- 取消注册消息
SL:UnRegisterLuaNetMsg(2028)
end, 1.0) -- 延迟1秒执行
end
end)
```
## 按钮事件修正:
```lua
-- 将 GUI:Win_CloseAll() 改为:
if GUI:Win_IsNotNull(ui["Button_2"]) then
GUI:addOnClickEvent(ui["Button_2"], function()
SL:Print("点击Button_2")
GUI:delayTouchEnabled(ui["Button_2"], 0.2)
local msg = {}
msg.Script = leishen.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, leishen.param2, 0, 0, jsonstr)
GUI:setVisible(ui.Image_1, true)
GUI:setVisible(ui.Image_4, false)
GUI:setVisible(ui.Image_5, false)
GUI:setVisible(ui.Button_5, false)
GUI:setVisible(ui.Button_1, true)
-- 只关闭当前窗口,而不是所有窗口
if leishen.parent and leishen.parent._parent then
GUI:Win_Close(leishen.parent._parent)
end
end)
end
```
主要错误是缺少 `end` 关键字和错误使用了 `GUI:Win_CloseAll()`。建议在开发过程中多使用 `SL:Print()` 输出调试信息,这样更容易定位问题。