local leishen = {}
function leishen.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
leishen.parent = lib:openwin(param1, nil, true, param4) or {}
你的代码逻辑有问题,我来帮你分析一下:
主要问题在于 **三个按钮的点击逻辑完全独立**,没有判断条件来控制按钮3的可用性。根据"只有完成前两个按钮的任务才能点击按钮3"的要求,你需要:
1. **添加状态判断**:通过服务器变量或本地变量记录前两个按钮的完成状态
2. **按钮3的启用/禁用控制**:根据状态决定按钮3是否可点击
修改建议:
```lua
function leishen.upmain()
if not leishen.parent or not leishen.parent._ui then
return
end
local ui = leishen.parent._ui
local var = tonumber(SL:GetMetaValue("SERVER_VALUE", "U47"))
SL:Print("获取当前焚天等级 var =", var)
-- 假设用U47的前两位表示前两个按钮的状态
-- 例如:var=100表示第一个完成,var=200表示第二个完成,var=300表示两个都完成
local button1_done = false
local button2_done = false
-- 根据你的业务逻辑设置状态
-- 这里只是示例,你需要根据实际需求调整
if var >= 100 then
button1_done = true
end
if var >= 200 then
button2_done = true
end
-- 设置升级按钮
if GUI:Win_IsNotNull(ui["Button_2"]) then
GUI:addOnClickEvent(ui["Button_2"], function()
SL:print("点击焚天升级按钮1")
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)
end)
end
if GUI:Win_IsNotNull(ui["Button_3"]) then
-- 检查按钮2是否可点击(按钮1已完成)
if button1_done then
GUI:setTouchEnabled(ui["Button_3"], true)
GUI:setOpacity(ui["Button_3"], 255) -- 正常显示
else
GUI:setTouchEnabled(ui["Button_3"], false)
GUI:setOpacity(ui["Button_3"], 128) -- 半透明,不可点击
end
GUI:addOnClickEvent(ui["Button_3"], function()
if not button1_done then
lib:msg("请先完成第一个任务!")
return
end
SL:print("点击焚天升级按钮2")
GUI:delayTouchEnabled(ui["Button_3"], 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, false)
GUI:setVisible(ui.Image_4, true)
GUI:setVisible(ui.Image_5, false)
end)
end
if GUI:Win_IsNotNull(ui["Button_4"]) then
-- 检查按钮3是否可点击(按钮1和2都已完成)
if button1_done and button2_done then
GUI:setTouchEnabled(ui["Button_4"], true)
GUI:setOpacity(ui["Button_4"], 255) -- 正常显示
else
GUI:setTouchEnabled(ui["Button_4"], false)
GUI:setOpacity(ui["Button_4"], 128) -- 半透明,不可点击
end
GUI:addOnClickEvent(ui["Button_4"], function()
if not button1_done or not button2_done then
lib:msg("请先完成前两个任务!")
return
end
SL:print("点击焚天升级按钮3")
GUI:delayTouchEnabled(ui["Button_4"], 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, false)
GUI:setVisible(ui.Image_4, false)
GUI:setVisible(ui.Image_5, true)
end)
end
end
```
**关键改进点:**
1. **状态判断**:通过`button1_done`和`button2_done`变量记录前两个按钮的完成状态
2. **按钮禁用**:使用`GUI:setTouchEnabled(widget, false)`禁用不可点击的按钮
3. **视觉反馈**:使用`GUI:setOpacity(widget, 128)`让禁用按钮半透明
4. **双重检查**:在点击事件内部再次检查状态,防止意外点击
**建议:**
- 你需要和服务器端约定好状态存储方式(比如用不同的U47值表示不同阶段)
- 考虑使用多个服务器变量分别存储三个按钮的状态
- 在按钮点击成功后,应该更新状态并刷新界面
如果你不清楚如何设计状态存储逻辑,可以问浮生梦老师,他会给你更专业的建议!