mirror of https://github.com/axmolengine/axmol.git
modify node register event interface
This commit is contained in:
parent
2ea89c0b3f
commit
f82404f9c9
|
@ -29,7 +29,7 @@ function Event:unbind(target)
|
||||||
self:init_()
|
self:init_()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Event:addEventListener(eventName, listener, tag)
|
function Event:onEventListener(eventName, listener, tag)
|
||||||
assert(type(eventName) == "string" and eventName ~= "",
|
assert(type(eventName) == "string" and eventName ~= "",
|
||||||
"Event:addEventListener() - invalid eventName")
|
"Event:addEventListener() - invalid eventName")
|
||||||
eventName = string.upper(eventName)
|
eventName = string.upper(eventName)
|
||||||
|
@ -50,6 +50,8 @@ function Event:addEventListener(eventName, listener, tag)
|
||||||
return self.target_, handle
|
return self.target_, handle
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Event.addEventListener = Event.onEventListener
|
||||||
|
|
||||||
function Event:dispatchEvent(event)
|
function Event:dispatchEvent(event)
|
||||||
event.name = string.upper(tostring(event.name))
|
event.name = string.upper(tostring(event.name))
|
||||||
local eventName = event.name
|
local eventName = event.name
|
||||||
|
|
|
@ -120,33 +120,58 @@ function Node:scaleTo(args)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function Node:scheduleUpdate(callback)
|
function Node:onUpdate(callback)
|
||||||
self:scheduleUpdateWithPriorityLua(callback, 0)
|
self:scheduleUpdateWithPriorityLua(callback, 0)
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Node.scheduleUpdate = Node.onUpdate
|
||||||
|
|
||||||
|
function Node:onNodeEvent(eventName, callback)
|
||||||
|
if "enter" == eventName then
|
||||||
|
self.onEnterCallback_ = callback
|
||||||
|
elseif "exit" == eventName then
|
||||||
|
self.onExitCallback_ = callback
|
||||||
|
elseif "enterTransitionFinish" == eventName then
|
||||||
|
self.onEnterTransitionFinishCallback_ = callback
|
||||||
|
elseif "exitTransitionStart" == eventName then
|
||||||
|
self.onExitTransitionStartCallback_ = callback
|
||||||
|
elseif "cleanup" == eventName then
|
||||||
|
self.onCleanupCallback_ = callback
|
||||||
|
end
|
||||||
|
self:enableNodeEvents()
|
||||||
|
end
|
||||||
|
|
||||||
function Node:enableNodeEvents()
|
function Node:enableNodeEvents()
|
||||||
|
if self.isNodeEventEnabled_ then
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
self:registerScriptHandler(function(state)
|
self:registerScriptHandler(function(state)
|
||||||
if state == "enter" then
|
if state == "enter" then
|
||||||
self:onEnter()
|
self:onEnter_()
|
||||||
elseif state == "exit" then
|
elseif state == "exit" then
|
||||||
self:onExit()
|
self:onExit_()
|
||||||
elseif state == "enterTransitionFinish" then
|
elseif state == "enterTransitionFinish" then
|
||||||
self:onEnterTransitionFinish()
|
self:onEnterTransitionFinish_()
|
||||||
elseif state == "exitTransitionStart" then
|
elseif state == "exitTransitionStart" then
|
||||||
self:onExitTransitionStart()
|
self:onExitTransitionStart_()
|
||||||
elseif state == "cleanup" then
|
elseif state == "cleanup" then
|
||||||
self:onCleanup()
|
self:onCleanup_()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
self.isNodeEventEnabled_ = true
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function Node:disableNodeEvents()
|
function Node:disableNodeEvents()
|
||||||
self:unregisterScriptHandler()
|
self:unregisterScriptHandler()
|
||||||
|
self.isNodeEventEnabled_ = false
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function Node:onEnter()
|
function Node:onEnter()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -161,3 +186,43 @@ end
|
||||||
|
|
||||||
function Node:onCleanup()
|
function Node:onCleanup()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Node:onEnter_()
|
||||||
|
self:onEnter()
|
||||||
|
if not self.onEnterCallback_ then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
self:onEnterCallback_()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Node:onExit_()
|
||||||
|
self:onExit()
|
||||||
|
if not self.onExitCallback_ then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
self:onExitCallback_()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Node:onEnterTransitionFinish_()
|
||||||
|
self:onEnterTransitionFinish()
|
||||||
|
if not self.onEnterTransitionFinishCallback_ then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
self:onEnterTransitionFinishCallback_()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Node:onExitTransitionStart_()
|
||||||
|
self:onExitTransitionStart()
|
||||||
|
if not self.onExitTransitionStartCallback_ then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
self:onExitTransitionStartCallback_()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Node:onCleanup_()
|
||||||
|
self:onCleanup()
|
||||||
|
if not self.onCleanupCallback_ then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
self:onCleanupCallback_()
|
||||||
|
end
|
||||||
|
|
|
@ -44,6 +44,8 @@ require("cocos.framework.extends.NodeEx")
|
||||||
require("cocos.framework.extends.SpriteEx")
|
require("cocos.framework.extends.SpriteEx")
|
||||||
require("cocos.framework.extends.LayerEx")
|
require("cocos.framework.extends.LayerEx")
|
||||||
require("cocos.framework.extends.MenuEx")
|
require("cocos.framework.extends.MenuEx")
|
||||||
|
|
||||||
|
if ccui then
|
||||||
require("cocos.framework.extends.UIWidget")
|
require("cocos.framework.extends.UIWidget")
|
||||||
require("cocos.framework.extends.UICheckBox")
|
require("cocos.framework.extends.UICheckBox")
|
||||||
require("cocos.framework.extends.UIEditBox")
|
require("cocos.framework.extends.UIEditBox")
|
||||||
|
@ -52,6 +54,7 @@ require("cocos.framework.extends.UIPageView")
|
||||||
require("cocos.framework.extends.UIScrollView")
|
require("cocos.framework.extends.UIScrollView")
|
||||||
require("cocos.framework.extends.UISlider")
|
require("cocos.framework.extends.UISlider")
|
||||||
require("cocos.framework.extends.UITextField")
|
require("cocos.framework.extends.UITextField")
|
||||||
|
end
|
||||||
|
|
||||||
require("cocos.framework.package_support")
|
require("cocos.framework.package_support")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue