-- 展开天命界面
local ID = SL:GetMetaValue("MAIN_ACTOR_ID")
local Lv = SL:GetMetaValue("ACTOR_LEVEL", ID)
local rLv = SL:GetMetaValue("RELEVEL")
GUI:addOnClickEvent(PlayerEquip._ui.destiny_btn, function()
-- 切换天命界面的显示状态
loca
根据浮生梦老师前端课程内容,你需要在点击事件中添加关闭逻辑。以下是修改后的代码:
```lua
-- 展开天命界面
local ID = SL:GetMetaValue("MAIN_ACTOR_ID")
local Lv = SL:GetMetaValue("ACTOR_LEVEL", ID)
local rLv = SL:GetMetaValue("RELEVEL")
-- 存储创建的pic对象
local currentDestinyPic = nil
GUI:addOnClickEvent(PlayerEquip._ui.destiny_btn, function()
-- 切换天命界面的显示状态
local destiny_bg = PlayerEquip._ui.destiny_bg
local isVisible = GUI:getVisible(destiny_bg)
if GUI:Win_IsNull(destiny_bg) then
return
end
-- 切换可见性
GUI:setVisible(destiny_bg, not isVisible)
-- 淡入淡出效果
if not isVisible then
GUI:setOpacity(destiny_bg, 0)
GUI:runAction(destiny_bg, GUI:ActionFadeTo(0.2, 255))
end
-- 如果关闭天命界面,同时关闭pic界面
if isVisible and currentDestinyPic then
GUI:removeFromParent(currentDestinyPic)
currentDestinyPic = nil
end
end)
for k, v in ipairs(PlayerEquip.destiny_config) do
local btn = GUI:getChildByName(PlayerEquip._ui.destiny_list, "btn_"..k)
if Lv < v.level or rLv < v.rlv then
GUI:Button_setBright(btn, false)
-- SL:ShowSystemTips("对不起,您的等级不足")
else
GUI:Button_setBright(btn, true)
local Img = "destiny_img_"..k
GUI:addOnClickEvent(btn, function()
-- 先移除之前的pic
if currentDestinyPic then
GUI:removeFromParent(currentDestinyPic)
end
local LT_Node = GUI:Attach_LeftTop_T()
currentDestinyPic = GUI:Image_Create(LT_Node, Img, 100, -200, "res/public_win32/bg_npc_01.png")
SL:Require("qianduan/button/destiny.lua", true, destinyHandler(currentDestinyPic, k))
end)
end
end
-- 关闭装备界面时也关闭pic界面
-- 假设有关闭装备界面的按钮或事件
local function closeEquipmentUI()
-- 关闭装备界面逻辑...
-- 同时关闭pic界面
if currentDestinyPic then
GUI:removeFromParent(currentDestinyPic)
currentDestinyPic = nil
end
end
```
主要修改点:
1. 添加了`currentDestinyPic`变量来存储当前显示的pic对象
2. 在点击天命按钮时,如果关闭天命界面,同时移除pic界面
3. 在点击具体天命按钮时,先移除之前创建的pic,再创建新的
4. 添加了关闭装备界面时的清理逻辑
这样就能确保再次点击天命按钮或关闭装备界面时,pic界面会被正确关闭。