Updating CCBReader to support Scripting Owners

This commit is contained in:
Rohan Kuruvilla 2012-09-18 17:38:33 -07:00
parent e84606aa47
commit 0fc7feb3f0
3 changed files with 25 additions and 4 deletions

View File

@ -235,6 +235,7 @@ public:
static float getResolutionScale();
CCNode* readFileWithCleanUp(bool bCleanUp);
bool hasScriptingOwner = false;
private:
void cleanUpNodeGraph(CCNode *pNode);
@ -250,6 +251,7 @@ private:
bool getBit();
void alignBits();
CCString* readUTF8();
};
// end of effects group

View File

@ -3,6 +3,7 @@
#include "cocos2d.h"
#include "ExtensionMacros.h"
#include "../GUI/CCControlExtension/CCInvocation.h"
USING_NS_CC;
NS_CC_EXT_BEGIN
@ -18,11 +19,18 @@ NS_CC_EXT_BEGIN
class CCBSelectorResolver {
public:
virtual ~CCBSelectorResolver() {};
virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName) = 0;
virtual cocos2d::extension::SEL_CCControlHandler onResolveCCBCCControlSelector(CCObject * pTarget, CCString * pSelectorName) = 0;
};
class CCBScriptOwnerProtocol {
public:
virtual ~CCBScriptOwnerProtocol() {};
virtual CCBSelectorResolver * createNew() = 0;
};
NS_CC_EXT_END
#endif

View File

@ -686,6 +686,17 @@ BlockData * CCNodeLoader::parsePropTypeBlock(CCNode * pNode, CCNode * pParent, C
target = pCCBReader->getAnimationManager()->getRootNode();
} else if(selectorTarget == kCCBTargetTypeOwner) {
target = pCCBReader->getOwner();
/* Scripting specific code because selector function is common for all callbacks.
* So if we had 1 target and 1 selector function, the context (callback function name)
* would get lost. Hence the need for a new target for each callback.
*/
if(pCCBReader->hasScriptingOwner) {
CCBScriptOwnerProtocol *proxy = dynamic_cast<CCBScriptOwnerProtocol *>(pCCBReader->getOwner());
if(proxy) {
target = dynamic_cast<CCObject *>(proxy->createNew());
}
}
}
if(target != NULL) {