在浮生梦老师前端课程内容中,你可以在以下位置禁止点击气泡功能:
**1. 气泡添加函数中的点击事件绑定位置:**
在 `MainProperty.AddBubbleTips()` 函数中,当创建气泡单元格时会绑定点击事件。你可以在这里添加判断条件来禁止点击。
**2. 气泡单元格创建函数中的点击事件绑定位置:**
在 `MainProperty.CreateBubbleTipsCell()` 函数中,通过 `GUI:addOnClickEvent(iconBtn, function() ... end)` 绑定了点击事件。
以下是禁止点击气泡按钮的代码实现:
```lua
-- 在 MainProperty.AddBubbleTips 函数中添加判断
function MainProperty.AddBubbleTips(data)
data.endTime = data.time and data.time + SL:GetMetaValue("SERVER_TIME")
if MainProperty._bubbleTipsData[data.id] then
MainProperty._bubbleTipsData[data.id] = data
return false
end
MainProperty._bubbleTipsData[data.id] = data
-- 比较优先级插入
local insertIndex = 1
local config = SL:GetMetaValue("BUBBLETIPS_INFO", data.id)
local order = config and config.order or 1
for i, cell in ipairs(MainProperty._bubbleTipsCells) do
local cellCfg = SL:GetMetaValue("BUBBLETIPS_INFO", cell.id)
local cellOrder = cellCfg and cellCfg.order or 1
if order > cellOrder then
insertIndex = i
break
end
end
local tipsCell = MainProperty.CreateBubbleTipsCell(data)
table.insert(MainProperty._bubbleTipsCells, insertIndex, tipsCell)
GUI:ListView_insertCustomItem(MainProperty._ui.ListView_bubble_tips, tipsCell.layout, insertIndex - 1)
SL:PlaySound(50004)
end
-- 在 MainProperty.CreateBubbleTipsCell 函数中修改点击事件
function MainProperty.CreateBubbleTipsCell(data)
local id = data.id
local path = data.path
local node = GUI:Node_Create(-1, "node", 0, 0)
local Panel_cell = GUI:Layout_Create(node, "Panel_cell", 0, 0, 50, 50)
GUI:setTouchEnabled(Panel_cell, true)
GUI:setAnchorPoint(Panel_cell, 0.5, 0.5)
-- 图标
local iconBtn = GUI:Button_Create(Panel_cell, "iconBtn", 25, 25, "Default/Button_Normal.png")
GUI:setAnchorPoint(iconBtn, 0.5, 0.5)
GUI:setContentSize(iconBtn, 46, 46)
-- 倒计时
local timeText = GUI:Text_Create(Panel_cell, "timeText", 25, 7, 16, "#FF0000", "10")
GUI:setAnchorPoint(timeText, 0.5, 0.5)
GUI:removeFromParent(Panel_cell)
if path and string.len(path) > 0 then
GUI:Button_loadTextureNormal(iconBtn, "res/" .. path)
else
local config = SL:GetMetaValue("BUBBLETIPS_INFO", id)
local normalPath = string.format(MainProperty._path .. "bubble_tips/%s_1.png", config and config.img)
local pressPath = string.format(MainProperty._path .. "bubble_tips/%s_2.png", config and config.img)
GUI:Button_loadTextureNormal(iconBtn, normalPath)
GUI:Button_loadTexturePressed(iconBtn, pressPath)
end
GUI:setIgnoreContentAdaptWithSize(iconBtn, true)
-- 添加禁止点击的判断条件
local isBubbleClickDisabled = false -- 这里可以设置为 true 来完全禁止点击
-- 或者根据特定条件判断,例如:
-- local isBubbleClickDisabled = SL:GetMetaValue("GAME_DATA", "DisableBubbleClick") or false
if not isBubbleClickDisabled then
-- 只有不禁用点击时才绑定点击事件
GUI:addOnClickEvent(iconBtn, function()
if data.callback then
data.callback(Panel_cell)
end
end)
else
-- 禁止点击时设置按钮为不可点击状态
GUI:setTouchEnabled(iconBtn, false)
GUI:Button_setBright(iconBtn, false)
end
-- 时间
local function callback()
if data.endTime then
local remaining = data.endTime - SL:GetMetaValue("SERVER_TIME")
GUI:Text_setString(timeText, remaining)
if remaining <= 0 then
GUI:stopAllActions(timeText)
GUI:Text_setString(timeText, "")
if data.timeOverCB then
data.timeOverCB()
end
end
else
GUI:Text_setString(timeText, "")
end
end
SL:schedule(timeText, callback, 1)
callback()
GUI:Timeline_Waggle(Panel_cell, 0.05, 20)
local cell = {
id = id,
layout = Panel_cell,
button = iconBtn
}
return cell
end
```
如果你想要动态控制是否禁止点击,可以在调用 `MainProperty.AddBubbleTips()` 时传入一个参数来控制,或者在游戏数据中设置一个标志位来判断。