quick 3.3 按钮多次点击出现问题的解决方法,就是在点击事件传递的时候,截断点击事件的分发
如果两次点击事件时间过短,则不分发点击事件
function EventProtocol:dispatchEvent(event)
event.name = string.upper(tostring(event.name))
local eventName = event.name
if DEBUG > 1 then
printInfo("%s [EventProtocol] dispatchEvent() - event %s", tostring(self.target_), eventName)
end
if self.listeners_[eventName] == nil then return end
event.target = self.target_
event.stop_ = false
event.stop = function(self)
self.stop_ = true
end
if event.name=="CLICKED_EVENT" then
local currentTime = os.clock()
if event.target.clickTimePre then
if currentTime-event.target.clickTimePre<=0.3 then
print("-----------时间太短----------------",currentTime,event.target.clickTimePre)
event.target.clickTimePre = currentTime
return
end
event.target.clickTimePre = currentTime
else
event.target.clickTimePre = currentTime
end
end
for handle, listener in pairs(self.listeners_[eventName]) do
if DEBUG > 1 then
printInfo("%s [EventProtocol] dispatchEvent() - dispatching event %s to listener %s", tostring(self.target_), eventName, handle)
end
-- listener[1] = listener
-- listener[2] = tag
event.tag = listener[2]
listener[1](event)
if event.stop_ then
if DEBUG > 1 then
printInfo("%s [EventProtocol] dispatchEvent() - break dispatching for event %s", tostring(self.target_), eventName)
end
break
end
end
return self.target_
end