Merge pull request #2369 from dumganhar/iss1860-subccb-onNodeLoaded

fixed #1860: onNodeLoaded will be called twice if ccb was added as a CCBFile and adding test.
This commit is contained in:
James Chen 2013-04-14 19:41:08 -07:00
commit 4ae375e7fe
3 changed files with 21 additions and 9 deletions

View File

@ -622,8 +622,9 @@ CCNode * CCBReader::readNodeGraph(CCNode * pParent) {
// Read properties
ccNodeLoader->parseProperties(node, pParent, this);
bool isCCBFileNode = dynamic_cast<CCBFile*>(node);
// Handle sub ccb files (remove middle node)
if (dynamic_cast<CCBFile*>(node))
if (isCCBFileNode)
{
CCBFile *ccbFileNode = (CCBFile*)node;
@ -734,14 +735,18 @@ CCNode * CCBReader::readNodeGraph(CCNode * pParent) {
node->addChild(child);
}
// Call onNodeLoaded
CCNodeLoaderListener * nodeAsCCNodeLoaderListener = dynamic_cast<CCNodeLoaderListener *>(node);
if(nodeAsCCNodeLoaderListener != NULL) {
nodeAsCCNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
} else if(this->mCCNodeLoaderListener != NULL) {
this->mCCNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
// FIX ISSUE #1860: "onNodeLoaded will be called twice if ccb was added as a CCBFile".
// If it's a sub-ccb node, skip notification to CCNodeLoaderListener since it will be
// notified at LINE #734: CCNode * child = this->readNodeGraph(node);
if (!isCCBFileNode) {
// Call onNodeLoaded
CCNodeLoaderListener * nodeAsCCNodeLoaderListener = dynamic_cast<CCNodeLoaderListener *>(node);
if(nodeAsCCNodeLoaderListener != NULL) {
nodeAsCCNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
} else if(this->mCCNodeLoaderListener != NULL) {
this->mCCNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
}
}
return node;
}

View File

@ -14,6 +14,11 @@ SEL_CCControlHandler TestHeaderLayer::onResolveCCBCCControlSelector(CCObject * p
return NULL;
}
void TestHeaderLayer::onNodeLoaded(cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader)
{
CCLOG("TestHeaderLayer::onNodeLoaded");
}
void TestHeaderLayer::onBackClicked(cocos2d::CCObject *pSender) {
CCDirector::sharedDirector()->popScene();
}

View File

@ -7,12 +7,14 @@
class TestHeaderLayer
: public cocos2d::CCLayer
, public cocos2d::extension::CCBSelectorResolver
, public cocos2d::extension::CCNodeLoaderListener
{
public:
CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(TestHeaderLayer, create);
virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(cocos2d::CCObject * pTarget, const char * pSelectorName);
virtual cocos2d::extension::SEL_CCControlHandler onResolveCCBCCControlSelector(cocos2d::CCObject * pTarget, const char * pSelectorName);
virtual void onNodeLoaded(cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader);
void onBackClicked(cocos2d::CCObject * pSender);
};