From a5d78830db00d77d6f85bd609f5075459556b3b8 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 15 Apr 2013 10:39:44 +0800 Subject: [PATCH] fixed #1860: onNodeLoaded will be called twice if ccb was added as a CCBFile. --- extensions/CCBReader/CCBReader.cpp | 21 ++++++++++++------- .../TestHeader/TestHeaderLayer.cpp | 5 +++++ .../TestHeader/TestHeaderLayer.h | 4 +++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/extensions/CCBReader/CCBReader.cpp b/extensions/CCBReader/CCBReader.cpp index 46e73d86ce..6ef45fbb58 100644 --- a/extensions/CCBReader/CCBReader.cpp +++ b/extensions/CCBReader/CCBReader.cpp @@ -622,8 +622,9 @@ CCNode * CCBReader::readNodeGraph(CCNode * pParent) { // Read properties ccNodeLoader->parseProperties(node, pParent, this); + bool isCCBFileNode = dynamic_cast(node); // Handle sub ccb files (remove middle node) - if (dynamic_cast(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(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(node); + if(nodeAsCCNodeLoaderListener != NULL) { + nodeAsCCNodeLoaderListener->onNodeLoaded(node, ccNodeLoader); + } else if(this->mCCNodeLoaderListener != NULL) { + this->mCCNodeLoaderListener->onNodeLoaded(node, ccNodeLoader); + } } - return node; } diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.cpp index 9c11f3f1fc..a07a6b5948 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.cpp @@ -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(); } \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.h index 7dd8a6b5f3..2b77c1949c 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.h @@ -7,13 +7,15 @@ 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); };