mirror of https://github.com/axmolengine/axmol.git
Updating CCBReader to support Scripting Owners
This commit is contained in:
parent
e84606aa47
commit
0fc7feb3f0
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue