2013-06-03 13:47:12 +08:00
ccb = ccb or { }
2013-08-22 10:16:57 +08:00
function CCBReaderLoad ( strFilePath , proxy , owner )
2013-06-03 13:47:12 +08:00
if nil == proxy then
2013-11-15 13:48:34 +08:00
return nil
2013-06-03 13:47:12 +08:00
end
2013-06-06 14:23:30 +08:00
2013-06-03 13:47:12 +08:00
local ccbReader = proxy : createCCBReader ( )
2013-08-22 10:16:57 +08:00
local node = ccbReader : load ( strFilePath )
2013-06-03 13:47:12 +08:00
local rootName = " "
--owner set in readCCBFromFile is proxy
if nil ~= owner then
--Callbacks
2013-08-22 10:16:57 +08:00
local ownerCallbackNames = ccbReader : getOwnerCallbackNames ( )
local ownerCallbackNodes = ccbReader : getOwnerCallbackNodes ( )
local ownerCallbackControlEvents = ccbReader : getOwnerCallbackControlEvents ( )
2013-06-03 13:47:12 +08:00
local i = 1
2013-08-22 10:16:57 +08:00
for i = 1 , table.getn ( ownerCallbackNames ) do
local callbackName = ownerCallbackNames [ i ]
local callbackNode = tolua.cast ( ownerCallbackNodes [ i ] , " Node " )
if " function " == type ( owner [ callbackName ] ) then
proxy : setCallback ( callbackNode , owner [ callbackName ] , ownerCallbackControlEvents [ i ] )
else
print ( " Warning: Cannot find owner's lua function: " .. " : " .. callbackName .. " for ownerVar selector " )
2013-06-03 13:47:12 +08:00
end
2013-08-22 10:16:57 +08:00
2013-06-03 13:47:12 +08:00
end
--Variables
2013-08-22 10:16:57 +08:00
local ownerOutletNames = ccbReader : getOwnerOutletNames ( )
local ownerOutletNodes = ccbReader : getOwnerOutletNodes ( )
2013-06-06 14:23:30 +08:00
2013-08-22 10:16:57 +08:00
for i = 1 , table.getn ( ownerOutletNames ) do
local outletName = ownerOutletNames [ i ]
local outletNode = tolua.cast ( ownerOutletNodes [ i ] , " Node " )
owner [ outletName ] = outletNode
2013-06-03 13:47:12 +08:00
end
end
2013-08-22 10:16:57 +08:00
local nodesWithAnimationManagers = ccbReader : getNodesWithAnimationManagers ( )
local animationManagersForNodes = ccbReader : getAnimationManagersForNodes ( )
2013-06-06 14:23:30 +08:00
2013-08-22 10:16:57 +08:00
for i = 1 , table.getn ( nodesWithAnimationManagers ) do
local innerNode = tolua.cast ( nodesWithAnimationManagers [ i ] , " Node " )
local animationManager = tolua.cast ( animationManagersForNodes [ i ] , " CCBAnimationManager " )
2013-06-03 13:47:12 +08:00
local documentControllerName = animationManager : getDocumentControllerName ( )
if " " == documentControllerName then
end
2013-06-05 15:17:00 +08:00
if nil ~= ccb [ documentControllerName ] then
ccb [ documentControllerName ] [ " mAnimationManager " ] = animationManager
end
2013-06-03 13:47:12 +08:00
--Callbacks
2013-08-22 10:16:57 +08:00
local documentCallbackNames = animationManager : getDocumentCallbackNames ( )
local documentCallbackNodes = animationManager : getDocumentCallbackNodes ( )
local documentCallbackControlEvents = animationManager : getDocumentCallbackControlEvents ( )
2013-06-06 14:23:30 +08:00
2013-08-22 10:16:57 +08:00
for i = 1 , table.getn ( documentCallbackNames ) do
local callbackName = documentCallbackNames [ i ]
local callbackNode = tolua.cast ( documentCallbackNodes [ i ] , " Node " )
2013-06-03 13:47:12 +08:00
if " " ~= documentControllerName and nil ~= ccb [ documentControllerName ] then
2013-08-22 10:16:57 +08:00
if " function " == type ( ccb [ documentControllerName ] [ callbackName ] ) then
proxy : setCallback ( callbackNode , ccb [ documentControllerName ] [ callbackName ] , documentCallbackControlEvents [ i ] )
2013-06-08 13:28:06 +08:00
else
2013-08-22 10:16:57 +08:00
print ( " Warning: Cannot found lua function [ " .. documentControllerName .. " : " .. callbackName .. " ] for docRoot selector " )
2013-06-08 13:28:06 +08:00
end
2013-06-03 13:47:12 +08:00
end
end
--Variables
2013-08-22 10:16:57 +08:00
local documentOutletNames = animationManager : getDocumentOutletNames ( )
local documentOutletNodes = animationManager : getDocumentOutletNodes ( )
2013-06-06 14:23:30 +08:00
2013-08-22 10:16:57 +08:00
for i = 1 , table.getn ( documentOutletNames ) do
local outletName = documentOutletNames [ i ]
local outletNode = tolua.cast ( documentOutletNodes [ i ] , " Node " )
2013-06-03 13:47:12 +08:00
if nil ~= ccb [ documentControllerName ] then
2013-08-22 10:16:57 +08:00
ccb [ documentControllerName ] [ outletName ] = tolua.cast ( outletNode , proxy : getNodeTypeName ( outletNode ) )
2013-06-03 13:47:12 +08:00
end
end
--[[
if ( typeof ( controller.onDidLoadFromCCB ) == " function " )
controller.onDidLoadFromCCB ( ) ;
] ] --
--Setup timeline callbacks
local keyframeCallbacks = animationManager : getKeyframeCallbacks ( )
2013-06-06 14:23:30 +08:00
2013-08-22 10:16:57 +08:00
for i = 1 , table.getn ( keyframeCallbacks ) do
local callbackCombine = keyframeCallbacks [ i ]
2013-06-03 13:47:12 +08:00
local beignIndex , endIndex = string.find ( callbackCombine , " : " )
local callbackType = tonumber ( string.sub ( callbackCombine , 1 , beignIndex - 1 ) )
local callbackName = string.sub ( callbackCombine , endIndex + 1 , - 1 )
--Document callback
2013-06-06 14:23:30 +08:00
2013-06-03 13:47:12 +08:00
if 1 == callbackType and nil ~= ccb [ documentControllerName ] then
2013-08-22 10:16:57 +08:00
local callfunc = cc.CallFunc : create ( ccb [ documentControllerName ] [ callbackName ] )
2013-06-03 13:47:12 +08:00
animationManager : setCallFuncForLuaCallbackNamed ( callfunc , callbackCombine ) ;
elseif 2 == callbackType and nil ~= owner then --Owner callback
2013-08-22 10:16:57 +08:00
local callfunc = cc.CallFunc : create ( owner [ callbackName ] ) --need check
2013-06-03 13:47:12 +08:00
animationManager : setCallFuncForLuaCallbackNamed ( callfunc , callbackCombine )
end
end
--start animation
local autoPlaySeqId = animationManager : getAutoPlaySequenceId ( )
if - 1 ~= autoPlaySeqId then
animationManager : runAnimationsForSequenceIdTweenDuration ( autoPlaySeqId , 0 )
end
end
return node
2013-06-03 14:59:04 +08:00
end
2013-12-04 15:15:55 +08:00
local function CCBuilderReaderLoad ( strFilePath , proxy , owner )
print ( " \n ********** \n " .. " CCBuilderReaderLoad(strFilePath,proxy,owner) " .. " was deprecated please use " .. " CCBReaderLoad(strFilePath,proxy,owner) " .. " instead. \n ********** " )
return CCBReaderLoad ( strFilePath , proxy , owner )
end
rawset ( _G , " CCBuilderReaderLoad " , CCBuilderReaderLoad )