mirror of https://github.com/axmolengine/axmol.git
Merge branch 'iss1470_cocosbuilder' of https://github.com/minggo/cocos2d-x into iss1470_cocosbuilder
This commit is contained in:
commit
3d3af08228
|
@ -144,6 +144,13 @@ OBJECTS = ../actions/CCAction.o \
|
|||
../../extensions/CCBReader/CCLayerGradientLoader.o \
|
||||
../../extensions/CCBReader/CCSpriteLoader.o \
|
||||
../../extensions/CCBReader/CCLayerLoader.o \
|
||||
../../extensions/CCBReader/CCBAnimationManager.o \
|
||||
../../extensions/CCBReader/CCBKeyframe.o \
|
||||
../../extensions/CCBReader/CCBSequence.o \
|
||||
../../extensions/CCBReader/CCBSequenceProperty.o \
|
||||
../../extensions/CCBReader/CCBValue.o \
|
||||
../../extensions/CCBReader/CCData.o \
|
||||
../../extensions/CCBReader/CCNode+CCBRelativePositioning.o \
|
||||
../../extensions/GUI/CCScrollView/CCScrollView.o \
|
||||
../../extensions/GUI/CCScrollView/CCSorting.o \
|
||||
../../extensions/GUI/CCScrollView/CCTableView.o \
|
||||
|
|
|
@ -22,6 +22,13 @@ CCBReader/CCParticleSystemQuadLoader.cpp \
|
|||
CCBReader/CCScale9SpriteLoader.cpp \
|
||||
CCBReader/CCScrollViewLoader.cpp \
|
||||
CCBReader/CCSpriteLoader.cpp \
|
||||
CCBReader/CCBAnimationManager.cpp \
|
||||
CCBReader/CCBKeyframe.cpp \
|
||||
CCBReader/CCBSequence.cpp \
|
||||
CCBReader/CCBSequenceProperty.cpp \
|
||||
CCBReader/CCBValue.cpp \
|
||||
CCBReader/CCData.cpp \
|
||||
CCBReader/CCNode+CCBRelativePositioning.cpp \
|
||||
GUI/CCControlExtension/CCControl.cpp \
|
||||
GUI/CCControlExtension/CCControlButton.cpp \
|
||||
GUI/CCControlExtension/CCControlColourPicker.cpp \
|
||||
|
|
|
@ -0,0 +1,684 @@
|
|||
#include "CCBAnimationManager.h"
|
||||
#include "CCBSequence.h"
|
||||
#include "CCBSequenceProperty.h"
|
||||
#include "CCBReader.h"
|
||||
#include "CCBKeyframe.h"
|
||||
#include "CCNode+CCBRelativePositioning.h"
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace std;
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
// Implementation of CCBAinmationManager
|
||||
|
||||
CCBAnimationManager::CCBAnimationManager()
|
||||
: mSequences(NULL)
|
||||
, mNodeSequences(NULL)
|
||||
, mBaseValues(NULL)
|
||||
, mAutoPlaySequenceId(0)
|
||||
, mRootNode(NULL)
|
||||
, mRootContainerSize(CCSizeZero)
|
||||
, mDelegate(NULL)
|
||||
, mRunningSequence(NULL)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
bool CCBAnimationManager::init()
|
||||
{
|
||||
mSequences = new CCArray();
|
||||
mNodeSequences = new CCDictionary();
|
||||
mBaseValues = new CCDictionary();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CCBAnimationManager::~CCBAnimationManager()
|
||||
{
|
||||
CCDictElement *pElement = NULL;
|
||||
CCDICT_FOREACH(mNodeSequences, pElement)
|
||||
{
|
||||
CCNode *node = (CCNode*)pElement->getIntKey();
|
||||
node->release();
|
||||
}
|
||||
|
||||
CCDICT_FOREACH(mBaseValues, pElement)
|
||||
{
|
||||
CCNode *node = (CCNode*)pElement->getIntKey();
|
||||
node->release();
|
||||
}
|
||||
|
||||
mNodeSequences->release();
|
||||
mBaseValues->release();
|
||||
mSequences->release();
|
||||
setRootNode(NULL);
|
||||
setDelegate(NULL);
|
||||
}
|
||||
|
||||
CCArray* CCBAnimationManager::getSequences()
|
||||
{
|
||||
return mSequences;
|
||||
}
|
||||
|
||||
int CCBAnimationManager::getAutoPlaySequenceId()
|
||||
{
|
||||
return mAutoPlaySequenceId;
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setAutoPlaySequenceId(int autoPlaySequenceId)
|
||||
{
|
||||
mAutoPlaySequenceId = autoPlaySequenceId;
|
||||
}
|
||||
|
||||
CCNode* CCBAnimationManager::getRootNode()
|
||||
{
|
||||
return mRootNode;
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setRootNode(CCNode *pRootNode)
|
||||
{
|
||||
CC_SAFE_RELEASE(mRootNode);
|
||||
mRootNode = pRootNode;
|
||||
CC_SAFE_RETAIN(mRootNode);
|
||||
}
|
||||
|
||||
const CCSize& CCBAnimationManager::getRootContainerSize()
|
||||
{
|
||||
return mRootContainerSize;
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setRootContainerSize(const CCSize &rootContainerSize)
|
||||
{
|
||||
mRootContainerSize.setSize(rootContainerSize.width, rootContainerSize.height);
|
||||
}
|
||||
|
||||
CCBAnimationManagerDelegate* CCBAnimationManager::getDelegate()
|
||||
{
|
||||
return mDelegate;
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setDelegate(CCBAnimationManagerDelegate *pDelegate)
|
||||
{
|
||||
CC_SAFE_RELEASE(dynamic_cast<CCObject*>(mDelegate));
|
||||
mDelegate = pDelegate;
|
||||
CC_SAFE_RETAIN(dynamic_cast<CCObject*>(mDelegate));
|
||||
}
|
||||
|
||||
const char* CCBAnimationManager::getRunningSequenceName()
|
||||
{
|
||||
return mRunningSequence->getName();
|
||||
}
|
||||
|
||||
const CCSize& CCBAnimationManager::getContainerSize(CCNode *pNode)
|
||||
{
|
||||
if (pNode)
|
||||
{
|
||||
return pNode->getContentSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
return mRootContainerSize;
|
||||
}
|
||||
}
|
||||
|
||||
// refer to CCBReader::readNodeGraph() for data structure of pSeq
|
||||
void CCBAnimationManager::addNode(CCNode *pNode, CCDictionary *pSeq)
|
||||
{
|
||||
pNode->retain();
|
||||
|
||||
mNodeSequences->setObject(pSeq, (int)pNode);
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setBaseValue(CCObject *pValue, CCNode *pNode, const char *pPropName)
|
||||
{
|
||||
CCDictionary *props = (CCDictionary*)mBaseValues->objectForKey((int)pNode);
|
||||
if (! props)
|
||||
{
|
||||
props = CCDictionary::create();
|
||||
mBaseValues->setObject(props, (int)pNode);
|
||||
pNode->retain();
|
||||
}
|
||||
|
||||
props->setObject(pValue, pPropName);
|
||||
}
|
||||
|
||||
CCObject* CCBAnimationManager::getBaseValue(CCNode *pNode, const char* pPropName)
|
||||
{
|
||||
CCDictionary *props = (CCDictionary*)mBaseValues->objectForKey((int)pNode);
|
||||
|
||||
return props->objectForKey(pPropName);
|
||||
}
|
||||
|
||||
int CCBAnimationManager::getSequenceId(const char* pSequenceName)
|
||||
{
|
||||
CCObject *pElement = NULL;
|
||||
string seqName(pSequenceName);
|
||||
CCARRAY_FOREACH(mSequences, pElement)
|
||||
{
|
||||
CCBSequence *seq = (CCBSequence*)pElement;
|
||||
if (seqName.compare(seq->getName()) == 0)
|
||||
{
|
||||
return seq->getSequenceId();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
CCBSequence* CCBAnimationManager::getSequence(int nSequenceId)
|
||||
{
|
||||
CCObject *pElement = NULL;
|
||||
CCARRAY_FOREACH(mSequences, pElement)
|
||||
{
|
||||
CCBSequence *seq = (CCBSequence*)pElement;
|
||||
if (seq->getSequenceId() == nSequenceId)
|
||||
{
|
||||
return seq;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Refer to CCBReader::readKeyframe() for the real type of value
|
||||
CCActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const char *pPropName, CCNode *pNode)
|
||||
{
|
||||
float duration = pKeyframe1->getTime() - (pKeyframe0 ? pKeyframe0->getTime() : 0);
|
||||
|
||||
if (strcmp(pPropName, "rotation") == 0)
|
||||
{
|
||||
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
||||
return CCBRotateTo::create(duration, value->getFloatValue());
|
||||
}
|
||||
else if (strcmp(pPropName, "opacity") == 0)
|
||||
{
|
||||
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
||||
return CCFadeTo::create(duration, value->getByteValue());
|
||||
}
|
||||
else if (strcmp(pPropName, "color") == 0)
|
||||
{
|
||||
ccColor3BWapper* color = (ccColor3BWapper*)pKeyframe1->getValue();
|
||||
ccColor3B c = color->getColor();
|
||||
|
||||
return CCTintTo::create(duration, c.r, c.g, c.b);
|
||||
}
|
||||
else if (strcmp(pPropName, "visible") == 0)
|
||||
{
|
||||
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
||||
if (value->getBoolValue())
|
||||
{
|
||||
return CCSequence::createWithTwoActions(CCDelayTime::create(duration), CCShow::create());
|
||||
}
|
||||
else
|
||||
{
|
||||
return CCSequence::createWithTwoActions(CCDelayTime::create(duration), CCHide::create());
|
||||
}
|
||||
}
|
||||
else if (strcmp(pPropName, "displayFrame") == 0)
|
||||
{
|
||||
return CCSequence::createWithTwoActions(CCDelayTime::create(duration),
|
||||
CCBSetSpriteFrame::create((CCSpriteFrame *)pKeyframe1->getValue()));
|
||||
}
|
||||
else if (strcmp(pPropName, "position") == 0)
|
||||
{
|
||||
// Get position type
|
||||
CCArray *array = (CCArray*)getBaseValue(pNode, pPropName);
|
||||
int type = ((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
||||
|
||||
// Get relative position
|
||||
CCArray *value = (CCArray*)pKeyframe1->getValue();
|
||||
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
||||
|
||||
CCSize containerSize = getContainerSize(pNode->getParent());
|
||||
|
||||
CCPoint absPos = getAbsolutePosition(ccp(x,y), type, containerSize, pPropName);
|
||||
|
||||
return CCMoveTo::create(duration, absPos);
|
||||
}
|
||||
else if (strcmp(pPropName, "scale") == 0)
|
||||
{
|
||||
// Get position type
|
||||
CCArray *array = (CCArray*)getBaseValue(pNode, pPropName);
|
||||
int type = ((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
||||
|
||||
// Get relative scale
|
||||
CCArray *value = (CCArray*)pKeyframe1->getValue();
|
||||
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
||||
|
||||
if (type == kCCBScaleTypeMultiplyResolution)
|
||||
{
|
||||
float resolutionScale = CCBReader::getResolutionScale();
|
||||
x *= resolutionScale;
|
||||
y *= resolutionScale;
|
||||
}
|
||||
|
||||
return CCScaleTo::create(duration, x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLog("CCBReader: Failed to create animation for property: %s", pPropName);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setAnimatedProperty(const char *pPropName, CCNode *pNode, CCObject *pValue, float fTweenDuraion)
|
||||
{
|
||||
if (fTweenDuraion > 0)
|
||||
{
|
||||
// Create a fake keyframe to generate the action from
|
||||
CCBKeyframe *kf1 = new CCBKeyframe();
|
||||
kf1->autorelease();
|
||||
kf1->setValue(pValue);
|
||||
kf1->setTime(fTweenDuraion);
|
||||
kf1->setEasingType(kCCBKeyframeEasingLinear);
|
||||
|
||||
// Animate
|
||||
CCActionInterval *tweenAction = getAction(NULL, kf1, pPropName, pNode);
|
||||
pNode->runAction(tweenAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just set the value
|
||||
|
||||
if (strcmp(pPropName, "position") == 0)
|
||||
{
|
||||
// Get position type
|
||||
CCArray *array = (CCArray*)getBaseValue(pNode, pPropName);
|
||||
int type = ((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
||||
|
||||
// Get relative position
|
||||
CCArray *value = (CCArray*)pValue;
|
||||
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
||||
|
||||
pNode->setPosition(getAbsolutePosition(ccp(x,y), type, getContainerSize(pNode->getParent()), pPropName));
|
||||
}
|
||||
else if (strcmp(pPropName, "scale") == 0)
|
||||
{
|
||||
// Get scale type
|
||||
CCArray *array = (CCArray*)getBaseValue(pNode, pPropName);
|
||||
int type = ((CCBValue*)array->objectAtIndex(2))->getIntValue();
|
||||
|
||||
// Get relative scale
|
||||
CCArray *value = (CCArray*)pValue;
|
||||
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
||||
|
||||
setRelativeScale(pNode, x, y, type, pPropName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// [node setValue:value forKey:name];
|
||||
|
||||
// TODO only handle rotation, opacity, displayFrame, color
|
||||
if (strcmp(pPropName, "rotation") == 0)
|
||||
{
|
||||
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
||||
pNode->setRotation(rotate);
|
||||
}
|
||||
else if (strcmp(pPropName, "opacity") == 0)
|
||||
{
|
||||
int opacity = ((CCBValue*)pValue)->getByteValue();
|
||||
(dynamic_cast<CCRGBAProtocol*>(pNode))->setOpacity(opacity);
|
||||
}
|
||||
else if (strcmp(pPropName, "displayFrame") == 0)
|
||||
{
|
||||
((CCSprite*)pNode)->setDisplayFrame((CCSpriteFrame*)pValue);
|
||||
}
|
||||
else if (strcmp(pPropName, "color") == 0)
|
||||
{
|
||||
ccColor3BWapper *color = (ccColor3BWapper*)pValue;
|
||||
((CCSprite*)pNode)->setColor(color->getColor());
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLog("unsupported property name is %s", pPropName);
|
||||
CCAssert(false, "unsupported property now");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setFirstFrame(CCNode *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration)
|
||||
{
|
||||
CCArray *keyframes = pSeqProp->getKeyframes();
|
||||
|
||||
if (keyframes->count() == 0)
|
||||
{
|
||||
// Use base value (no animation)
|
||||
CCObject *baseValue = getBaseValue(pNode, pSeqProp->getName());
|
||||
CCAssert(baseValue, "No baseValue found for property");
|
||||
setAnimatedProperty(pSeqProp->getName(), pNode, baseValue, fTweenDuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use first keyframe
|
||||
CCBKeyframe *keyframe = (CCBKeyframe*)keyframes->objectAtIndex(0);
|
||||
setAnimatedProperty(pSeqProp->getName(), pNode, keyframe->getValue(), fTweenDuration);
|
||||
}
|
||||
}
|
||||
|
||||
CCActionInterval* CCBAnimationManager::getEaseAction(CCActionInterval *pAction, int nEasingType, float fEasingOpt)
|
||||
{
|
||||
if (nEasingType == kCCBKeyframeEasingLinear || nEasingType == kCCBKeyframeEasingInstant)
|
||||
{
|
||||
return pAction;
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingCubicIn)
|
||||
{
|
||||
return CCEaseIn::create(pAction, fEasingOpt);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingCubicOut)
|
||||
{
|
||||
return CCEaseOut::create(pAction, fEasingOpt);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingCubicInOut)
|
||||
{
|
||||
return CCEaseInOut::create(pAction, fEasingOpt);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingBackIn)
|
||||
{
|
||||
return CCEaseBackIn::create(pAction);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingBackOut)
|
||||
{
|
||||
return CCEaseBackOut::create(pAction);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingBackInOut)
|
||||
{
|
||||
return CCEaseBackInOut::create(pAction);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingBounceIn)
|
||||
{
|
||||
return CCEaseBounceIn::create(pAction);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingBounceOut)
|
||||
{
|
||||
return CCEaseBounceOut::create(pAction);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingBounceInOut)
|
||||
{
|
||||
return CCEaseBounceInOut::create(pAction);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingElasticIn)
|
||||
{
|
||||
return CCEaseElasticIn::create(pAction, fEasingOpt);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingElasticOut)
|
||||
{
|
||||
return CCEaseElasticOut::create(pAction, fEasingOpt);
|
||||
}
|
||||
else if (nEasingType == kCCBKeyframeEasingElasticInOut)
|
||||
{
|
||||
return CCEaseElasticInOut::create(pAction, fEasingOpt);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLog("CCBReader: Unkown easing type %d", nEasingType);
|
||||
return pAction;
|
||||
}
|
||||
}
|
||||
|
||||
void CCBAnimationManager::runAction(CCNode *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration)
|
||||
{
|
||||
CCArray *keyframes = pSeqProp->getKeyframes();
|
||||
int numKeyframes = keyframes->count();
|
||||
|
||||
if (numKeyframes > 1)
|
||||
{
|
||||
// Make an animation!
|
||||
CCArray *actions = CCArray::create();
|
||||
|
||||
CCBKeyframe *keyframeFirst = (CCBKeyframe*)keyframes->objectAtIndex(0);
|
||||
float timeFirst = keyframeFirst->getTime() + fTweenDuration;
|
||||
|
||||
if (timeFirst > 0)
|
||||
{
|
||||
actions->addObject(CCDelayTime::create(timeFirst));
|
||||
}
|
||||
|
||||
for (int i = 0; i < numKeyframes - 1; ++i)
|
||||
{
|
||||
CCBKeyframe *kf0 = (CCBKeyframe*)keyframes->objectAtIndex(i);
|
||||
CCBKeyframe *kf1 = (CCBKeyframe*)keyframes->objectAtIndex(i+1);
|
||||
|
||||
CCActionInterval *action = getAction(kf0, kf1, pSeqProp->getName(), pNode);
|
||||
if (action)
|
||||
{
|
||||
// Apply easing
|
||||
action = getEaseAction(action, kf0->getEasingType(), kf0->getEasingOpt());
|
||||
|
||||
actions->addObject(action);
|
||||
}
|
||||
}
|
||||
|
||||
CCFiniteTimeAction *seq = CCSequence::create(actions);
|
||||
pNode->runAction(seq);
|
||||
}
|
||||
}
|
||||
|
||||
void CCBAnimationManager::runAnimations(int nSeqId, float fTweenDuration)
|
||||
{
|
||||
CCAssert(nSeqId != -1, "Sequence id couldn't be found");
|
||||
|
||||
mRootNode->stopAllActions();
|
||||
|
||||
CCDictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(mNodeSequences, pElement)
|
||||
{
|
||||
CCNode *node = (CCNode*)pElement->getIntKey();
|
||||
node->stopAllActions();
|
||||
|
||||
// Refer to CCBReader::readKeyframe() for the real type of value
|
||||
CCDictionary *seqs = (CCDictionary*)pElement->getObject();
|
||||
CCDictionary *seqNodeProps = (CCDictionary*)seqs->objectForKey(nSeqId);
|
||||
|
||||
set<string> seqNodePropNames;
|
||||
|
||||
if (seqNodeProps)
|
||||
{
|
||||
// Reset nodes that have sequence node properties, and run actions on them
|
||||
CCDictElement* pElement1 = NULL;
|
||||
CCDICT_FOREACH(seqNodeProps, pElement1)
|
||||
{
|
||||
const char *propName = pElement1->getStrKey();
|
||||
CCBSequenceProperty *seqProp = (CCBSequenceProperty*)seqNodeProps->objectForKey(propName);
|
||||
seqNodePropNames.insert(propName);
|
||||
|
||||
setFirstFrame(node, seqProp, fTweenDuration);
|
||||
runAction(node, seqProp, fTweenDuration);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the nodes that may have been changed by other timelines
|
||||
CCDictionary *nodeBaseValues = (CCDictionary*)mBaseValues->objectForKey(pElement->getIntKey());
|
||||
if (nodeBaseValues)
|
||||
{
|
||||
CCDictElement* pElement2 = NULL;
|
||||
CCDICT_FOREACH(nodeBaseValues, pElement2)
|
||||
{
|
||||
if (seqNodePropNames.find(pElement2->getStrKey()) == seqNodePropNames.end())
|
||||
{
|
||||
CCObject *value = pElement2->getObject();
|
||||
|
||||
if (value)
|
||||
{
|
||||
setAnimatedProperty(pElement2->getStrKey(), node, value, fTweenDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make callback at end of sequence
|
||||
CCBSequence *seq = getSequence(nSeqId);
|
||||
CCAction *completeAction = CCSequence::createWithTwoActions(CCDelayTime::create(seq->getDuration() + fTweenDuration),
|
||||
CCCallFunc::create(this, callfunc_selector(CCBAnimationManager::sequenceCompleted)));
|
||||
mRootNode->runAction(completeAction);
|
||||
|
||||
// Set the running scene
|
||||
mRunningSequence = getSequence(nSeqId);
|
||||
}
|
||||
|
||||
void CCBAnimationManager::runAnimations(const char *pName, float fTweenDuration)
|
||||
{
|
||||
int seqId = getSequenceId(pName);
|
||||
runAnimations(seqId, fTweenDuration);
|
||||
}
|
||||
|
||||
void CCBAnimationManager::runAnimations(const char *pName)
|
||||
{
|
||||
runAnimations(pName, 0);
|
||||
}
|
||||
|
||||
void CCBAnimationManager::debug()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CCBAnimationManager::sequenceCompleted()
|
||||
{
|
||||
if (mDelegate)
|
||||
{
|
||||
mDelegate->completedAnimationSequenceNamed(mRunningSequence->getName());
|
||||
}
|
||||
|
||||
int nextSeqId = mRunningSequence->getChainedSequenceId();
|
||||
mRunningSequence = NULL;
|
||||
|
||||
if (nextSeqId != -1)
|
||||
{
|
||||
runAnimations(nextSeqId, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
CCBSetSpriteFrame
|
||||
************************************************************/
|
||||
|
||||
CCBSetSpriteFrame* CCBSetSpriteFrame::create(CCSpriteFrame *pSpriteFrame)
|
||||
{
|
||||
CCBSetSpriteFrame *ret = new CCBSetSpriteFrame();
|
||||
if (ret)
|
||||
{
|
||||
if (ret->initWithSpriteFrame(pSpriteFrame))
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CCBSetSpriteFrame::initWithSpriteFrame(CCSpriteFrame *pSpriteFrame)
|
||||
{
|
||||
mSpriteFrame = pSpriteFrame;
|
||||
CC_SAFE_RETAIN(mSpriteFrame);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CCBSetSpriteFrame::~CCBSetSpriteFrame()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(mSpriteFrame);
|
||||
}
|
||||
|
||||
CCObject* CCBSetSpriteFrame::copyWithZone(CCZone *pZone)
|
||||
{
|
||||
CCZone *pNewZone = NULL;
|
||||
CCBSetSpriteFrame *pRet = NULL;
|
||||
|
||||
if (pZone && pZone->m_pCopyObject) {
|
||||
pRet = (CCBSetSpriteFrame*) (pZone->m_pCopyObject);
|
||||
} else {
|
||||
pRet = new CCBSetSpriteFrame();
|
||||
pZone = pNewZone = new CCZone(pRet);
|
||||
}
|
||||
|
||||
pRet->initWithSpriteFrame(mSpriteFrame);
|
||||
CCActionInstant::copyWithZone(pZone);
|
||||
CC_SAFE_DELETE(pNewZone);
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void CCBSetSpriteFrame::update(float time)
|
||||
{
|
||||
((CCSprite*)m_pTarget)->setDisplayFrame(mSpriteFrame);
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
CCBRotateTo
|
||||
************************************************************/
|
||||
|
||||
CCBRotateTo* CCBRotateTo::create(float fDuration, float fAngle)
|
||||
{
|
||||
CCBRotateTo *ret = new CCBRotateTo();
|
||||
if (ret)
|
||||
{
|
||||
if (ret->initWithDuration(fDuration, fAngle))
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
CC_SAFE_DELETE(ret);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CCBRotateTo::initWithDuration(float fDuration, float fAngle)
|
||||
{
|
||||
if (CCActionInterval::initWithDuration(fDuration))
|
||||
{
|
||||
mDstAngle = fAngle;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
CCObject* CCBRotateTo::copyWithZone(CCZone *pZone)
|
||||
{
|
||||
CCZone *pNewZone = NULL;
|
||||
CCBRotateTo *pRet = NULL;
|
||||
|
||||
if (pZone && pZone->m_pCopyObject) {
|
||||
pRet = (CCBRotateTo*) (pZone->m_pCopyObject);
|
||||
} else {
|
||||
pRet = new CCBRotateTo();
|
||||
pZone = pNewZone = new CCZone(pRet);
|
||||
}
|
||||
|
||||
pRet->initWithDuration(m_fDuration, mDstAngle);
|
||||
CCActionInterval::copyWithZone(pZone);
|
||||
CC_SAFE_DELETE(pNewZone);
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void CCBRotateTo::startWithTarget(CCNode *pNode)
|
||||
{
|
||||
CCActionInterval::startWithTarget(pNode);
|
||||
mStartAngle = m_pTarget->getRotation();
|
||||
mDiffAngle = mDstAngle - mStartAngle;
|
||||
}
|
||||
|
||||
void CCBRotateTo::update(float time)
|
||||
{
|
||||
m_pTarget->setRotation(mStartAngle + (mDiffAngle * time))
|
||||
;
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -0,0 +1,109 @@
|
|||
#ifndef __CCB_CCBANIMATION_MANAGER_H__
|
||||
#define __CCB_CCBANIMATION_MANAGER_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "ExtensionMacros.h"
|
||||
#include "CCBSequence.h"
|
||||
#include "CCBValue.h"
|
||||
#include "CCBSequenceProperty.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CCBAnimationManagerDelegate
|
||||
{
|
||||
public:
|
||||
virtual void completedAnimationSequenceNamed(const char *name) = 0;
|
||||
};
|
||||
|
||||
class CCBAnimationManager : public cocos2d::CCObject
|
||||
{
|
||||
private:
|
||||
cocos2d::CCArray *mSequences;
|
||||
cocos2d::CCDictionary *mNodeSequences;
|
||||
cocos2d::CCDictionary *mBaseValues;
|
||||
int mAutoPlaySequenceId;
|
||||
|
||||
cocos2d::CCNode *mRootNode;
|
||||
CCSize mRootContainerSize;
|
||||
|
||||
CCBAnimationManagerDelegate *mDelegate;
|
||||
CCBSequence *mRunningSequence;
|
||||
|
||||
public:
|
||||
CCBAnimationManager();
|
||||
~CCBAnimationManager();
|
||||
|
||||
virtual bool init();
|
||||
|
||||
cocos2d::CCArray* getSequences();
|
||||
|
||||
int getAutoPlaySequenceId();
|
||||
void setAutoPlaySequenceId(int autoPlaySequenceId);
|
||||
|
||||
cocos2d::CCNode* getRootNode();
|
||||
void setRootNode(cocos2d::CCNode* pRootNode); // retain
|
||||
|
||||
const cocos2d::CCSize& getRootContainerSize();
|
||||
void setRootContainerSize(const cocos2d::CCSize &rootContainerSize);
|
||||
|
||||
CCBAnimationManagerDelegate* getDelegate();
|
||||
void setDelegate(CCBAnimationManagerDelegate* pDelegate); // retain
|
||||
|
||||
const char* getRunningSequenceName();
|
||||
|
||||
const CCSize& getContainerSize(cocos2d::CCNode* pNode);
|
||||
|
||||
void addNode(cocos2d::CCNode *pNode, cocos2d::CCDictionary *pSeq);
|
||||
void setBaseValue(cocos2d::CCObject *pValue, cocos2d::CCNode *pNode, const char *pPropName);
|
||||
|
||||
void runAnimations(const char *pName, float fTweenDuration);
|
||||
void runAnimations(const char *pName);
|
||||
void runAnimations(int nSeqId, float fTweenDuraiton);
|
||||
|
||||
void debug();
|
||||
|
||||
private:
|
||||
cocos2d::CCObject* getBaseValue(cocos2d::CCNode *pNode, const char* pPropName);
|
||||
int getSequenceId(const char* pSequenceName);
|
||||
CCBSequence* getSequence(int nSequenceId);
|
||||
cocos2d::CCActionInterval* getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const char *pPropName, cocos2d::CCNode *pNode);
|
||||
void setAnimatedProperty(const char *pPropName, cocos2d::CCNode *pNode, cocos2d::CCObject *pValue, float fTweenDuraion);
|
||||
void setFirstFrame(cocos2d::CCNode *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration);
|
||||
cocos2d::CCActionInterval* getEaseAction(cocos2d::CCActionInterval *pAction, int nEasingType, float fEasingOpt);
|
||||
void runAction(cocos2d::CCNode *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration);
|
||||
void sequenceCompleted();
|
||||
};
|
||||
|
||||
class CCBSetSpriteFrame : public cocos2d::CCActionInstant
|
||||
{
|
||||
private:
|
||||
cocos2d::CCSpriteFrame *mSpriteFrame;
|
||||
|
||||
public:
|
||||
~CCBSetSpriteFrame();
|
||||
|
||||
/** creates a Place action with a position */
|
||||
static CCBSetSpriteFrame* create(cocos2d::CCSpriteFrame *pSpriteFrame);
|
||||
bool initWithSpriteFrame(cocos2d::CCSpriteFrame *pSpriteFrame);
|
||||
virtual void update(float time);
|
||||
virtual cocos2d::CCObject* copyWithZone(cocos2d::CCZone *pZone);
|
||||
};
|
||||
|
||||
class CCBRotateTo : public cocos2d::CCActionInterval
|
||||
{
|
||||
private:
|
||||
float mStartAngle;
|
||||
float mDstAngle;
|
||||
float mDiffAngle;
|
||||
|
||||
public:
|
||||
static CCBRotateTo* create(float fDuration, float fAngle);
|
||||
bool initWithDuration(float fDuration, float fAngle);
|
||||
virtual void update(float time);
|
||||
virtual cocos2d::CCObject* copyWithZone(cocos2d::CCZone *pZone);
|
||||
virtual void startWithTarget(cocos2d::CCNode *pNode);
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif // __CCB_CCBANIMATION_MANAGER_H__
|
|
@ -8,7 +8,7 @@ NS_CC_EXT_BEGIN
|
|||
|
||||
void CCBFileLoader::onHandlePropTypeCCBFile(CCNode * pNode, CCNode * pParent, CCString * pPropertyName, CCNode * pCCBFileNode, CCBReader * pCCBReader) {
|
||||
if(pPropertyName->compare(PROPERTY_CCBFILE) == 0) {
|
||||
pNode->addChild(pCCBFileNode);
|
||||
((CCBFile*)pNode)->setCCBFileNode(pCCBFileNode);
|
||||
} else {
|
||||
CCNodeLoader::onHandlePropTypeCCBFile(pNode, pParent, pPropertyName, pCCBFileNode, pCCBReader);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _CCB_CCBFILELOADER_H_
|
||||
|
||||
#include "CCNodeLoader.h"
|
||||
#include "CCBReader.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
|
@ -14,7 +15,7 @@ class CCBFileLoader : public CCNodeLoader {
|
|||
CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(CCBFileLoader, loader);
|
||||
|
||||
protected:
|
||||
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(CCNode);
|
||||
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(CCBFile);
|
||||
|
||||
virtual void onHandlePropTypeCCBFile(CCNode * pNode, CCNode * pParent, CCString * pPropertyName, CCNode * pCCBFileNode, CCBReader * pCCBReader);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
#include "CCBKeyframe.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCBKeyframe::CCBKeyframe()
|
||||
: mValue(NULL)
|
||||
, mTime(0.0f)
|
||||
, mEasingType(0)
|
||||
, mEasingOpt(0.0f)
|
||||
{}
|
||||
|
||||
CCBKeyframe::~CCBKeyframe()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(mValue);
|
||||
}
|
||||
|
||||
CCObject* CCBKeyframe::getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
void CCBKeyframe::setValue(CCObject *pValue)
|
||||
{
|
||||
CC_SAFE_RELEASE(mValue);
|
||||
mValue = pValue;
|
||||
CC_SAFE_RETAIN(mValue);
|
||||
}
|
||||
|
||||
float CCBKeyframe::getTime()
|
||||
{
|
||||
return mTime;
|
||||
}
|
||||
|
||||
void CCBKeyframe::setTime(float fTime)
|
||||
{
|
||||
mTime = fTime;
|
||||
}
|
||||
|
||||
int CCBKeyframe::getEasingType()
|
||||
{
|
||||
return mEasingType;
|
||||
}
|
||||
|
||||
void CCBKeyframe::setEasingType(int nEasingType)
|
||||
{
|
||||
mEasingType = nEasingType;
|
||||
}
|
||||
|
||||
float CCBKeyframe::getEasingOpt()
|
||||
{
|
||||
return mEasingOpt;
|
||||
}
|
||||
|
||||
void CCBKeyframe::setEasingOpt(float fEasingOpt)
|
||||
{
|
||||
mEasingOpt = fEasingOpt;
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef __CCB_KEYFRAME_H__
|
||||
#define __CCB_KEYFRAME_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "ExtensionMacros.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CCBKeyframe : public cocos2d::CCObject
|
||||
{
|
||||
private:
|
||||
cocos2d::CCObject *mValue;
|
||||
float mTime;
|
||||
int mEasingType;
|
||||
float mEasingOpt;
|
||||
|
||||
public:
|
||||
CCBKeyframe();
|
||||
~CCBKeyframe();
|
||||
|
||||
cocos2d::CCObject* getValue();
|
||||
void setValue(cocos2d::CCObject *pValue); // retain
|
||||
|
||||
float getTime();
|
||||
void setTime(float fTime);
|
||||
|
||||
int getEasingType();
|
||||
void setEasingType(int nEasingType);
|
||||
|
||||
float getEasingOpt();
|
||||
void setEasingOpt(float fEasingOpt);
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif // __CCB_KEYFRAME_H__
|
|
@ -7,6 +7,11 @@
|
|||
#include "CCNodeLoaderListener.h"
|
||||
#include "CCBMemberVariableAssigner.h"
|
||||
#include "CCBSelectorResolver.h"
|
||||
#include "CCData.h"
|
||||
#include "CCBAnimationManager.h"
|
||||
#include "CCBSequenceProperty.h"
|
||||
#include "CCBKeyframe.h"
|
||||
#include "CCBValue.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
|
@ -14,35 +19,69 @@
|
|||
#include <UIKit/UIDevice.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
USING_NS_CC;
|
||||
NS_CC_EXT_BEGIN;
|
||||
|
||||
CCBReader::CCBReader(CCNodeLoaderLibrary * pCCNodeLoaderLibrary, CCBMemberVariableAssigner * pCCBMemberVariableAssigner, CCBSelectorResolver * pCCBSelectorResolver, CCNodeLoaderListener * pCCNodeLoaderListener) {
|
||||
this->mRootNode = NULL;
|
||||
this->mRootCCBReader = true;
|
||||
/*************************************************************************
|
||||
Implementation of CCBFile
|
||||
*************************************************************************/
|
||||
|
||||
CCBFile::CCBFile():mCCBFileNode(NULL) {}
|
||||
|
||||
CCBFile* CCBFile::create()
|
||||
{
|
||||
CCBFile *ret = new CCBFile();
|
||||
|
||||
if (ret)
|
||||
{
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCNode* CCBFile::getCCBFileNode()
|
||||
{
|
||||
return mCCBFileNode;
|
||||
}
|
||||
|
||||
void CCBFile::setCCBFileNode(CCNode *pNode)
|
||||
{
|
||||
CC_SAFE_RELEASE(mCCBFileNode);
|
||||
mCCBFileNode = pNode;
|
||||
CC_SAFE_RETAIN(mCCBFileNode);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
Implementation of CCBReader
|
||||
*************************************************************************/
|
||||
|
||||
CCBReader::CCBReader(CCNodeLoaderLibrary * pCCNodeLoaderLibrary, CCBMemberVariableAssigner * pCCBMemberVariableAssigner, CCBSelectorResolver * pCCBSelectorResolver, CCNodeLoaderListener * pCCNodeLoaderListener)
|
||||
: mData(NULL)
|
||||
, mBytes(NULL)
|
||||
, mCurrentByte(-1)
|
||||
, mCurrentBit(-1)
|
||||
, mOwner(NULL)
|
||||
, mActionManager(NULL)
|
||||
, mAnimatedProps(NULL)
|
||||
{
|
||||
this->mCCNodeLoaderLibrary = pCCNodeLoaderLibrary;
|
||||
this->mCCNodeLoaderLibrary->retain();
|
||||
this->mCCBMemberVariableAssigner = pCCBMemberVariableAssigner;
|
||||
this->mCCBSelectorResolver = pCCBSelectorResolver;
|
||||
this->mCCNodeLoaderListener = pCCNodeLoaderListener;
|
||||
|
||||
this->mResolutionScale = 1;
|
||||
|
||||
#ifdef __CC_PLATFORM_IOS
|
||||
/* iPad */
|
||||
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
this->mResolutionScale = 2;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
CCBReader::CCBReader(CCBReader * pCCBReader) {
|
||||
this->mRootNode = NULL;
|
||||
this->mRootCCBReader = false;
|
||||
|
||||
/* Borrow data from the 'parent' CCBReader. */
|
||||
this->mResolutionScale = pCCBReader->mResolutionScale;
|
||||
CCBReader::CCBReader(CCBReader * pCCBReader)
|
||||
: mData(NULL)
|
||||
, mBytes(NULL)
|
||||
, mCurrentByte(-1)
|
||||
, mCurrentBit(-1)
|
||||
, mOwner(NULL)
|
||||
, mActionManager(NULL)
|
||||
, mAnimatedProps(NULL)
|
||||
{
|
||||
this->mLoadedSpriteSheets = pCCBReader->mLoadedSpriteSheets;
|
||||
this->mCCNodeLoaderLibrary = pCCBReader->mCCNodeLoaderLibrary;
|
||||
this->mCCNodeLoaderLibrary->retain();
|
||||
|
@ -52,26 +91,69 @@ CCBReader::CCBReader(CCBReader * pCCBReader) {
|
|||
this->mCCNodeLoaderListener = pCCBReader->mCCNodeLoaderListener;
|
||||
}
|
||||
|
||||
CCBReader::CCBReader()
|
||||
: mData(NULL)
|
||||
, mBytes(NULL)
|
||||
, mCurrentByte(-1)
|
||||
, mCurrentBit(-1)
|
||||
, mOwner(NULL)
|
||||
, mActionManager(NULL)
|
||||
, mCCNodeLoaderLibrary(NULL)
|
||||
, mCCNodeLoaderListener(NULL)
|
||||
, mCCBMemberVariableAssigner(NULL)
|
||||
, mCCBSelectorResolver(NULL)
|
||||
, mAnimatedProps(NULL)
|
||||
{}
|
||||
|
||||
CCBReader::~CCBReader() {
|
||||
CC_SAFE_DELETE_ARRAY(this->mBytes);
|
||||
CC_SAFE_RELEASE_NULL(mOwner);
|
||||
CC_SAFE_RELEASE_NULL(mData);
|
||||
|
||||
this->mCCNodeLoaderLibrary->release();
|
||||
|
||||
/* Clear string cache. */
|
||||
// Clear string cache.
|
||||
std::vector<CCString *>::iterator stringCacheIterator;
|
||||
for (stringCacheIterator = this->mStringCache.begin(); stringCacheIterator != this->mStringCache.end(); stringCacheIterator++) {
|
||||
(*stringCacheIterator)->release();
|
||||
}
|
||||
this->mStringCache.clear();
|
||||
|
||||
if(this->mRootCCBReader) {
|
||||
/* Clear loaded spritesheets. */
|
||||
this->mLoadedSpriteSheets.clear();
|
||||
}
|
||||
setAnimationManager(NULL);
|
||||
}
|
||||
|
||||
CCString * CCBReader::getCCBRootPath() {
|
||||
return this->mCCBRootPath;
|
||||
bool CCBReader::initWithData(CCData *pData, CCObject *pOwner)
|
||||
{
|
||||
// Setup action manager
|
||||
CCBAnimationManager *pActionManager = new CCBAnimationManager();
|
||||
setAnimationManager(pActionManager);
|
||||
pActionManager->release();
|
||||
|
||||
// Setup byte array
|
||||
mData = pData;
|
||||
CC_SAFE_RETAIN(mData);
|
||||
mBytes = mData->getBytes();
|
||||
mCurrentByte = 0;
|
||||
mCurrentBit = 0;
|
||||
|
||||
mOwner = pOwner;
|
||||
CC_SAFE_RETAIN(mOwner);
|
||||
|
||||
// Setup resolution scale and container size
|
||||
mActionManager->setRootContainerSize(CCDirector::sharedDirector()->getWinSize());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CCBAnimationManager* CCBReader::getAnimationManager()
|
||||
{
|
||||
return mActionManager;
|
||||
}
|
||||
|
||||
void CCBReader::setAnimationManager(CCBAnimationManager *pAnimationManager)
|
||||
{
|
||||
CC_SAFE_RELEASE(mActionManager);
|
||||
mActionManager = pAnimationManager;
|
||||
CC_SAFE_RETAIN(mActionManager);
|
||||
}
|
||||
|
||||
CCBMemberVariableAssigner * CCBReader::getCCBMemberVariableAssigner() {
|
||||
|
@ -82,50 +164,105 @@ CCBSelectorResolver * CCBReader::getCCBSelectorResolver() {
|
|||
return this->mCCBSelectorResolver;
|
||||
}
|
||||
|
||||
float CCBReader::getResolutionScale() {
|
||||
return this->mResolutionScale;
|
||||
set<string>* CCBReader::getAnimatedProperties()
|
||||
{
|
||||
return mAnimatedProps;
|
||||
}
|
||||
|
||||
CCNode * CCBReader::readNodeGraphFromFile(const char * pCCBRootPath, const char * pCCBFileName, CCObject * pOwner) {
|
||||
return this->readNodeGraphFromFile(pCCBRootPath, pCCBFileName, pOwner, CCDirector::sharedDirector()->getWinSize());
|
||||
set<string>& CCBReader::getLoadedSpriteSheet()
|
||||
{
|
||||
return mLoadedSpriteSheets;
|
||||
}
|
||||
|
||||
CCNode * CCBReader::readNodeGraphFromFile(CCString * pCCBRootPath, CCString * pCCBFileName, CCObject * pOwner) {
|
||||
return this->readNodeGraphFromFile(pCCBRootPath, pCCBFileName, pOwner, CCDirector::sharedDirector()->getWinSize());
|
||||
CCObject* CCBReader::getOwner()
|
||||
{
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
CCNode * CCBReader::readNodeGraphFromFile(const char * pCCBRootPath, const char * pCCBFileName, CCObject * pOwner, CCSize pRootContainerSize) {
|
||||
return this->readNodeGraphFromFile(CCString::create(pCCBRootPath), CCString::create(pCCBFileName), pOwner, pRootContainerSize);
|
||||
CCNode* CCBReader::readNodeGraphFromFile(const char *pCCBFileName)
|
||||
{
|
||||
return this->readNodeGraphFromFile(pCCBFileName, NULL);
|
||||
}
|
||||
|
||||
CCNode * CCBReader::readNodeGraphFromFile(CCString * pCCBRootPath, CCString * pCCBFileName, CCObject * pOwner, CCSize pRootContainerSize) {
|
||||
this->mCCBRootPath = pCCBRootPath;
|
||||
this->mCCBRootPath->retain();
|
||||
CCNode* CCBReader::readNodeGraphFromFile(const char* pCCBFileName, CCObject* pOwner)
|
||||
{
|
||||
return this->readNodeGraphFromFile(pCCBFileName, pOwner, CCDirector::sharedDirector()->getWinSize());
|
||||
}
|
||||
|
||||
CCString * ccbFullFilePath = CCBReader::concat(pCCBRootPath, pCCBFileName);
|
||||
CCNode * CCBReader::readNodeGraphFromFile(const char * pCCBFileName, CCObject *pOwner, const CCSize &parentSize)
|
||||
{
|
||||
return this->readNodeGraphFromFile(pCCBFileName, pOwner, parentSize, NULL);
|
||||
}
|
||||
|
||||
const char * path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(ccbFullFilePath->getCString());
|
||||
CCNode* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, CCBAnimationManager **ppAnimationManager)
|
||||
{
|
||||
return this->readNodeGraphFromFile(pCCBFileName, pOwner, CCDirector::sharedDirector()->getWinSize(), ppAnimationManager);
|
||||
}
|
||||
|
||||
unsigned long size = 0;
|
||||
this->mBytes = CCFileUtils::sharedFileUtils()->getFileData(path, "rb", &size);
|
||||
CCNode* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize, CCBAnimationManager **ppAnimationManager)
|
||||
{
|
||||
const char *pPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pCCBFileName);
|
||||
unsigned long size;
|
||||
|
||||
this->mCurrentByte = 0;
|
||||
this->mCurrentBit = 0;
|
||||
unsigned char * pBytes = CCFileUtils::sharedFileUtils()->getFileData(pPath, "rb", &size);
|
||||
CCData *data = new CCData(pBytes, size);
|
||||
|
||||
this->mOwner = pOwner;
|
||||
CC_SAFE_RETAIN(this->mOwner);
|
||||
this->mRootContainerSize = pRootContainerSize;
|
||||
CCNode *ret = this->readNodeGraphFromData(data, pOwner, parentSize, ppAnimationManager);
|
||||
|
||||
data->release();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCNode * node = NULL;
|
||||
if(this->readHeader() && this->readStringCache()) {
|
||||
node = this->readNodeGraph();
|
||||
CCNode* CCBReader::readNodeGraphFromData(CCData *pData, CCObject *pOwner, const CCSize &parentSize)
|
||||
{
|
||||
return this->readNodeGraphFromData(pData, pOwner, parentSize, NULL);
|
||||
}
|
||||
|
||||
CCNode* CCBReader::readNodeGraphFromData(CCData *pData, CCObject *pOwner, const CCSize &parentSize, CCBAnimationManager **ppAnimationManager)
|
||||
{
|
||||
initWithData(pData, pOwner);
|
||||
mActionManager->setRootContainerSize(parentSize);
|
||||
|
||||
CCNode *pNodeGraph = readFileWithCleanUp(true);
|
||||
|
||||
if (pNodeGraph && mActionManager->getAutoPlaySequenceId() != -1)
|
||||
{
|
||||
// Auto play animations
|
||||
mActionManager->runAnimations(mActionManager->getAutoPlaySequenceId(), 0);
|
||||
}
|
||||
|
||||
// Return action manager by reference
|
||||
if (ppAnimationManager)
|
||||
{
|
||||
*ppAnimationManager = mActionManager;
|
||||
}
|
||||
|
||||
return pNodeGraph;
|
||||
}
|
||||
|
||||
CC_SAFE_RELEASE(this->mOwner);
|
||||
CC_SAFE_RELEASE(this->mCCBRootPath);
|
||||
CC_SAFE_RELEASE(this->mRootNode);
|
||||
CCScene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName)
|
||||
{
|
||||
return createSceneWithNodeGraphFromFile(pCCBFileName, NULL);
|
||||
}
|
||||
|
||||
return node;
|
||||
CCScene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner)
|
||||
{
|
||||
return createSceneWithNodeGraphFromFile(pCCBFileName, pOwner, CCDirector::sharedDirector()->getWinSize());
|
||||
}
|
||||
|
||||
CCScene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize)
|
||||
{
|
||||
return createSceneWithNodeGraphFromFile(pCCBFileName, pOwner, parentSize, NULL);
|
||||
}
|
||||
|
||||
CCScene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize, CCBAnimationManager **ppAnimationManager)
|
||||
{
|
||||
CCNode *pNode = readNodeGraphFromFile(pCCBFileName, pOwner, parentSize, ppAnimationManager);
|
||||
CCScene *pScene = CCScene::create();
|
||||
pScene->addChild(pNode);
|
||||
|
||||
return pScene;
|
||||
}
|
||||
|
||||
bool CCBReader::readHeader() {
|
||||
|
@ -152,6 +289,44 @@ bool CCBReader::readHeader() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void CCBReader::cleanUpNodeGraph(CCNode *pNode)
|
||||
{
|
||||
pNode->setUserObject(NULL);
|
||||
|
||||
CCObject *pChild = NULL;
|
||||
CCARRAY_FOREACH(pNode->getChildren(), pChild)
|
||||
{
|
||||
cleanUpNodeGraph((CCNode*)pChild);
|
||||
}
|
||||
}
|
||||
|
||||
CCNode* CCBReader::readFileWithCleanUp(bool bCleanUp)
|
||||
{
|
||||
if (! readHeader())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (! readStringCache())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (! readSequences())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CCNode *pNode = readNodeGraph();
|
||||
|
||||
if (bCleanUp)
|
||||
{
|
||||
cleanUpNodeGraph(pNode);
|
||||
}
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
bool CCBReader::readStringCache() {
|
||||
int numStrings = this->readInt(false);
|
||||
|
||||
|
@ -281,26 +456,105 @@ CCNode * CCBReader::readNodeGraph(CCNode * pParent) {
|
|||
/* Read class name. */
|
||||
CCString * className = this->readCachedString();
|
||||
|
||||
// Read assignment type and name
|
||||
int memberVarAssignmentType = this->readInt(false);
|
||||
CCString * memberVarAssignmentName;
|
||||
if(memberVarAssignmentType != kCCBTargetTypeNone) {
|
||||
memberVarAssignmentName = this->readCachedString();
|
||||
}
|
||||
|
||||
CCNodeLoader * ccNodeLoader = this->mCCNodeLoaderLibrary->getCCNodeLoader(className);
|
||||
CCNode * node = ccNodeLoader->loadCCNode(pParent, this);
|
||||
|
||||
/* Set root node, if not set yet. */
|
||||
if(this->mRootNode == NULL) {
|
||||
this->mRootNode = node;
|
||||
this->mRootNode->retain();
|
||||
CCNodeLoader *ccNodeLoader = this->mCCNodeLoaderLibrary->getCCNodeLoader(className);
|
||||
if (! ccNodeLoader)
|
||||
{
|
||||
CCLog("no corresponding node loader for %s", className->getCString());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CCNode *node = ccNodeLoader->loadCCNode(pParent, this);
|
||||
|
||||
// Set root node
|
||||
if (! mActionManager->getRootNode())
|
||||
{
|
||||
mActionManager->setRootNode(node);
|
||||
}
|
||||
|
||||
// Read animated properties
|
||||
CCDictionary *seqs = CCDictionary::create();
|
||||
mAnimatedProps = new set<string>();
|
||||
|
||||
int numSequence = readInt(false);
|
||||
for (int i = 0; i < numSequence; ++i)
|
||||
{
|
||||
int seqId = readInt(false);
|
||||
CCDictionary *seqNodeProps = CCDictionary::create();
|
||||
|
||||
int numProps = readInt(false);
|
||||
|
||||
for (int j = 0; j < numProps; ++j)
|
||||
{
|
||||
CCBSequenceProperty *seqProp = new CCBSequenceProperty();
|
||||
seqProp->autorelease();
|
||||
|
||||
seqProp->setName(readCachedString()->getCString());
|
||||
seqProp->setType(readInt(false));
|
||||
mAnimatedProps->insert(seqProp->getName());
|
||||
|
||||
int numKeyframes = readInt(false);
|
||||
|
||||
for (int k = 0; k < numKeyframes; ++k)
|
||||
{
|
||||
CCBKeyframe *keyframe = readKeyframe(seqProp->getType());
|
||||
|
||||
seqProp->getKeyframes()->addObject(keyframe);
|
||||
}
|
||||
|
||||
seqNodeProps->setObject(seqProp, seqProp->getName());
|
||||
}
|
||||
|
||||
seqs->setObject(seqNodeProps, seqId);
|
||||
}
|
||||
|
||||
if (seqs->count() > 0)
|
||||
{
|
||||
mActionManager->addNode(node, seqs);
|
||||
}
|
||||
|
||||
// Read properties
|
||||
ccNodeLoader->parseProperties(node, pParent, this);
|
||||
|
||||
// Handle sub ccb files (remove middle node)
|
||||
if (dynamic_cast<CCBFile*>(node))
|
||||
{
|
||||
CCBFile *ccbFileNode = (CCBFile*)node;
|
||||
|
||||
CCNode *embeddedNode = ccbFileNode->getCCBFileNode();
|
||||
embeddedNode->setPosition(ccbFileNode->getPosition());
|
||||
embeddedNode->setRotation(ccbFileNode->getRotation());
|
||||
embeddedNode->setScale(ccbFileNode->getScale());
|
||||
embeddedNode->setTag(ccbFileNode->getTag());
|
||||
embeddedNode->setVisible(true);
|
||||
embeddedNode->ignoreAnchorPointForPosition(ccbFileNode->isIgnoreAnchorPointForPosition());
|
||||
|
||||
ccbFileNode->setCCBFileNode(NULL);
|
||||
|
||||
node = embeddedNode;
|
||||
}
|
||||
|
||||
#ifdef CCB_ENABLE_JAVASCRIPT
|
||||
/*
|
||||
if (memberVarAssignmentType && memberVarAssignmentName && ![memberVarAssignmentName isEqualToString:@""])
|
||||
{
|
||||
[[JSCocoa sharedController] setObject:node withName:memberVarAssignmentName];
|
||||
}*/
|
||||
#else
|
||||
if(memberVarAssignmentType != kCCBTargetTypeNone) {
|
||||
CCObject * target = NULL;
|
||||
if(memberVarAssignmentType == kCCBTargetTypeDocumentRoot) {
|
||||
target = this->mRootNode;
|
||||
} else if(memberVarAssignmentType == kCCBTargetTypeOwner) {
|
||||
if(memberVarAssignmentType == kCCBTargetTypeDocumentRoot)
|
||||
{
|
||||
target = mActionManager->getRootNode();
|
||||
}
|
||||
else if(memberVarAssignmentType == kCCBTargetTypeOwner)
|
||||
{
|
||||
target = this->mOwner;
|
||||
}
|
||||
|
||||
|
@ -318,6 +572,10 @@ CCNode * CCBReader::readNodeGraph(CCNode * pParent) {
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif // CCB_ENABLE_JAVASCRIPT
|
||||
|
||||
delete mAnimatedProps;
|
||||
mAnimatedProps = NULL;
|
||||
|
||||
/* Read and add children. */
|
||||
int numChildren = this->readInt(false);
|
||||
|
@ -326,6 +584,7 @@ CCNode * CCBReader::readNodeGraph(CCNode * pParent) {
|
|||
node->addChild(child);
|
||||
}
|
||||
|
||||
// Call onNodeLoaded
|
||||
CCNodeLoaderListener * nodeAsCCNodeLoaderListener = dynamic_cast<CCNodeLoaderListener *>(node);
|
||||
if(nodeAsCCNodeLoaderListener != NULL) {
|
||||
nodeAsCCNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
|
||||
|
@ -336,34 +595,118 @@ CCNode * CCBReader::readNodeGraph(CCNode * pParent) {
|
|||
return node;
|
||||
}
|
||||
|
||||
CCBKeyframe* CCBReader::readKeyframe(int type)
|
||||
{
|
||||
CCBKeyframe *keyframe = new CCBKeyframe();
|
||||
keyframe->autorelease();
|
||||
|
||||
keyframe->setTime(readFloat());
|
||||
|
||||
int easingType = readInt(false);
|
||||
float easingOpt = 0;
|
||||
CCObject *value = NULL;
|
||||
|
||||
if (easingType == kCCBKeyframeEasingCubicIn
|
||||
|| easingType == kCCBKeyframeEasingCubicOut
|
||||
|| easingType == kCCBKeyframeEasingCubicInOut
|
||||
|| easingType == kCCBKeyframeEasingElasticIn
|
||||
|| easingType == kCCBKeyframeEasingElasticOut
|
||||
|| easingType == kCCBKeyframeEasingElasticInOut)
|
||||
{
|
||||
easingOpt = readFloat();
|
||||
}
|
||||
keyframe->setEasingType(easingType);
|
||||
keyframe->setEasingOpt(easingOpt);
|
||||
|
||||
if (type == kCCBPropTypeCheck)
|
||||
{
|
||||
value = CCBValue::create(readBool());
|
||||
}
|
||||
else if (type == kCCBPropTypeByte)
|
||||
{
|
||||
value = CCBValue::create(readByte());
|
||||
}
|
||||
else if (type == kCCBPropTypeColor3)
|
||||
{
|
||||
int r = readByte();
|
||||
int g = readByte();
|
||||
int b = readByte();
|
||||
|
||||
ccColor3B c = ccc3(r,g,b);
|
||||
value = ccColor3BWapper::create(c);
|
||||
}
|
||||
else if (type == kCCBPropTypeDegrees)
|
||||
{
|
||||
value = CCBValue::create(readFloat());
|
||||
}
|
||||
else if (type == kCCBPropTypeScaleLock || type == kCCBPropTypePosition)
|
||||
{
|
||||
float a = readFloat();
|
||||
float b = readFloat();
|
||||
|
||||
value = CCArray::create(CCBValue::create(a),
|
||||
CCBValue::create(b),
|
||||
NULL);
|
||||
}
|
||||
else if (type == kCCBPropTypeSpriteFrame)
|
||||
{
|
||||
CCString *spriteSheet = readCachedString();
|
||||
CCString *spriteFile = readCachedString();
|
||||
|
||||
CCSpriteFrame* spriteFrame;
|
||||
CCString empty("");
|
||||
if (spriteSheet->isEqual(&empty))
|
||||
{
|
||||
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(spriteFile->getCString());
|
||||
CCRect bounds = CCRectMake(0, 0, texture->getContentSize().width, texture->getContentSize().height);
|
||||
spriteFrame = CCSpriteFrame::createWithTexture(texture, bounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
||||
|
||||
// Load the sprite sheet only if it is not loaded
|
||||
if (mLoadedSpriteSheets.find(spriteSheet->getCString()) == mLoadedSpriteSheets.end())
|
||||
{
|
||||
frameCache->addSpriteFramesWithFile(spriteSheet->getCString());
|
||||
mLoadedSpriteSheets.insert(spriteSheet->getCString());
|
||||
}
|
||||
|
||||
spriteFrame = frameCache->spriteFrameByName(spriteFile->getCString());
|
||||
}
|
||||
value = spriteFrame;
|
||||
}
|
||||
|
||||
keyframe->setValue(value);
|
||||
|
||||
return keyframe;
|
||||
}
|
||||
|
||||
CCNode * CCBReader::readNodeGraph() {
|
||||
return this->readNodeGraph(NULL);
|
||||
}
|
||||
|
||||
CCObject * CCBReader::getOwner() {
|
||||
return this->mOwner;
|
||||
}
|
||||
|
||||
CCNode * CCBReader::getRootNode() {
|
||||
return this->mRootNode;
|
||||
}
|
||||
|
||||
CCSize CCBReader::getContainerSize(CCNode * pNode) {
|
||||
if(pNode) {
|
||||
return pNode->getContentSize();
|
||||
} else {
|
||||
return this->mRootContainerSize;
|
||||
bool CCBReader::readSequences()
|
||||
{
|
||||
CCArray *sequences = mActionManager->getSequences();
|
||||
|
||||
int numSeqs = readInt(false);
|
||||
|
||||
for (int i = 0; i < numSeqs; i++)
|
||||
{
|
||||
CCBSequence *seq = new CCBSequence();
|
||||
seq->autorelease();
|
||||
|
||||
seq->setDuration(readFloat());
|
||||
seq->setName(readCachedString()->getCString());
|
||||
seq->setSequenceId(readInt(false));
|
||||
seq->setChainedSequenceId(readInt(true));
|
||||
|
||||
sequences->addObject(seq);
|
||||
}
|
||||
}
|
||||
|
||||
bool CCBReader::isSpriteSheetLoaded(CCString * pSpriteSheet) {
|
||||
return this->mLoadedSpriteSheets.find(pSpriteSheet->m_sString) != this->mLoadedSpriteSheets.end();
|
||||
}
|
||||
|
||||
void CCBReader::addLoadedSpriteSheet(CCString * pSpriteSheet) {
|
||||
// Since std::set<string> will copy the string from pSpriteSheet, we needn't to retain 'pSpriteSheet'.
|
||||
// pSpriteSheet->retain();
|
||||
this->mLoadedSpriteSheets.insert(pSpriteSheet->m_sString);
|
||||
|
||||
mActionManager->setAutoPlaySequenceId(readInt(true));
|
||||
return true;
|
||||
}
|
||||
|
||||
CCString * CCBReader::lastPathComponent(CCString * pPath) {
|
||||
|
@ -413,4 +756,21 @@ bool CCBReader::endsWith(CCString * pString, CCString * pEnding) {
|
|||
}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
Static functions
|
||||
************************************************************************/
|
||||
|
||||
float CCBReader::getResolutionScale()
|
||||
{
|
||||
// Init resolution scale
|
||||
if (CCApplication::sharedApplication()->getTargetPlatform() == kTargetIpad)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
NS_CC_EXT_END;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "cocos2d.h"
|
||||
#include "ExtensionMacros.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(T, METHOD) static T * METHOD() { \
|
||||
T * ptr = new T(); \
|
||||
|
@ -24,66 +26,107 @@
|
|||
return NULL; \
|
||||
}
|
||||
|
||||
#define kCCBVersion 2
|
||||
#define kCCBVersion 3
|
||||
|
||||
#define kCCBPropTypePosition 0
|
||||
#define kCCBPropTypeSize 1
|
||||
#define kCCBPropTypePoint 2
|
||||
#define kCCBPropTypePointLock 3
|
||||
#define kCCBPropTypeScaleLock 4
|
||||
#define kCCBPropTypeDegrees 5
|
||||
#define kCCBPropTypeInteger 6
|
||||
#define kCCBPropTypeFloat 7
|
||||
#define kCCBPropTypeFloatVar 8
|
||||
#define kCCBPropTypeCheck 9
|
||||
#define kCCBPropTypeSpriteFrame 10
|
||||
#define kCCBPropTypeTexture 11
|
||||
#define kCCBPropTypeByte 12
|
||||
#define kCCBPropTypeColor3 13
|
||||
#define kCCBPropTypeColor4FVar 14
|
||||
#define kCCBPropTypeFlip 15
|
||||
#define kCCBPropTypeBlendFunc 16
|
||||
#define kCCBPropTypeFntFile 17
|
||||
#define kCCBPropTypeText 18
|
||||
#define kCCBPropTypeFontTTF 19
|
||||
#define kCCBPropTypeIntegerLabeled 20
|
||||
#define kCCBPropTypeBlock 21
|
||||
#define kCCBPropTypeAnimation 22
|
||||
#define kCCBPropTypeCCBFile 23
|
||||
#define kCCBPropTypeString 24
|
||||
#define kCCBPropTypeBlockCCControl 25
|
||||
#define kCCBPropTypeFloatScale 26
|
||||
enum {
|
||||
kCCBPropTypePosition = 0,
|
||||
kCCBPropTypeSize,
|
||||
kCCBPropTypePoint,
|
||||
kCCBPropTypePointLock,
|
||||
kCCBPropTypeScaleLock,
|
||||
kCCBPropTypeDegrees,
|
||||
kCCBPropTypeInteger,
|
||||
kCCBPropTypeFloat,
|
||||
kCCBPropTypeFloatVar,
|
||||
kCCBPropTypeCheck,
|
||||
kCCBPropTypeSpriteFrame,
|
||||
kCCBPropTypeTexture,
|
||||
kCCBPropTypeByte,
|
||||
kCCBPropTypeColor3,
|
||||
kCCBPropTypeColor4FVar,
|
||||
kCCBPropTypeFlip,
|
||||
kCCBPropTypeBlendmode,
|
||||
kCCBPropTypeFntFile,
|
||||
kCCBPropTypeText,
|
||||
kCCBPropTypeFontTTF,
|
||||
kCCBPropTypeIntegerLabeled,
|
||||
kCCBPropTypeBlock,
|
||||
kCCBPropTypeAnimation,
|
||||
kCCBPropTypeCCBFile,
|
||||
kCCBPropTypeString,
|
||||
kCCBPropTypeBlockCCControl,
|
||||
kCCBPropTypeFloatScale
|
||||
};
|
||||
|
||||
#define kCCBFloat0 0
|
||||
#define kCCBFloat1 1
|
||||
#define kCCBFloatMinus1 2
|
||||
#define kCCBFloat05 3
|
||||
#define kCCBFloatInteger 4
|
||||
#define kCCBFloatFull 5
|
||||
enum {
|
||||
kCCBFloat0 = 0,
|
||||
kCCBFloat1,
|
||||
kCCBFloatMinus1,
|
||||
kCCBFloat05,
|
||||
kCCBFloatInteger,
|
||||
kCCBFloatFull
|
||||
};
|
||||
|
||||
#define kCCBPlatformAll 0
|
||||
#define kCCBPlatformIOS 1
|
||||
#define kCCBPlatformMac 2
|
||||
enum {
|
||||
kCCBPlatformAll = 0,
|
||||
kCCBPlatformIOS,
|
||||
kCCBPlatformMac
|
||||
};
|
||||
|
||||
#define kCCBTargetTypeNone 0
|
||||
#define kCCBTargetTypeDocumentRoot 1
|
||||
#define kCCBTargetTypeOwner 2
|
||||
enum {
|
||||
kCCBTargetTypeNone = 0,
|
||||
kCCBTargetTypeDocumentRoot = 1,
|
||||
kCCBTargetTypeOwner = 2,
|
||||
};
|
||||
|
||||
#define kCCBPositionTypeRelativeBottomLeft 0
|
||||
#define kCCBPositionTypeRelativeTopLeft 1
|
||||
#define kCCBPositionTypeRelativeTopRight 2
|
||||
#define kCCBPositionTypeRelativeBottomRight 3
|
||||
#define kCCBPositionTypePercent 4
|
||||
enum
|
||||
{
|
||||
kCCBKeyframeEasingInstant,
|
||||
|
||||
kCCBKeyframeEasingLinear,
|
||||
|
||||
kCCBKeyframeEasingCubicIn,
|
||||
kCCBKeyframeEasingCubicOut,
|
||||
kCCBKeyframeEasingCubicInOut,
|
||||
|
||||
kCCBKeyframeEasingElasticIn,
|
||||
kCCBKeyframeEasingElasticOut,
|
||||
kCCBKeyframeEasingElasticInOut,
|
||||
|
||||
kCCBKeyframeEasingBounceIn,
|
||||
kCCBKeyframeEasingBounceOut,
|
||||
kCCBKeyframeEasingBounceInOut,
|
||||
|
||||
kCCBKeyframeEasingBackIn,
|
||||
kCCBKeyframeEasingBackOut,
|
||||
kCCBKeyframeEasingBackInOut,
|
||||
};
|
||||
|
||||
#define kCCBSizeTypeAbsolute 0
|
||||
#define kCCBSizeTypePercent 1
|
||||
#define kCCBSizeTypeRelativeContainer 2
|
||||
#define kCCBSizeTypeHorizontalPercent 3
|
||||
#define kCCBSzieTypeVerticalPercent 4
|
||||
enum
|
||||
{
|
||||
kCCBPositionTypeRelativeBottomLeft,
|
||||
kCCBPositionTypeRelativeTopLeft,
|
||||
kCCBPositionTypeRelativeTopRight,
|
||||
kCCBPositionTypeRelativeBottomRight,
|
||||
kCCBPositionTypePercent,
|
||||
kCCBPositionTypeMultiplyResolution,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
kCCBSizeTypeAbsolute,
|
||||
kCCBSizeTypePercent,
|
||||
kCCBSizeTypeRelativeContainer,
|
||||
kCCBSizeTypeHorizontalPercent,
|
||||
kCCBSizeTypeVerticalPercent,
|
||||
kCCBSizeTypeMultiplyResolution,
|
||||
};
|
||||
|
||||
#define kCCBScaleTypeAbsolute 0
|
||||
#define kCCBScaleTypeMultiplyResolution 1
|
||||
enum
|
||||
{
|
||||
kCCBScaleTypeAbsolute,
|
||||
kCCBScaleTypeMultiplyResolution
|
||||
};
|
||||
|
||||
USING_NS_CC;
|
||||
NS_CC_EXT_BEGIN
|
||||
|
@ -93,83 +136,120 @@ NS_CC_EXT_BEGIN
|
|||
* @{
|
||||
*/
|
||||
|
||||
class CCBFile : public CCNode
|
||||
{
|
||||
private:
|
||||
CCNode *mCCBFileNode;
|
||||
|
||||
public:
|
||||
CCBFile();
|
||||
|
||||
static CCBFile* create();
|
||||
|
||||
CCNode* getCCBFileNode();
|
||||
void setCCBFileNode(CCNode *pNode); // retain
|
||||
};
|
||||
|
||||
/* Forward declaration. */
|
||||
class CCNodeLoader;
|
||||
class CCNodeLoaderLibrary;
|
||||
class CCNodeLoaderListener;
|
||||
class CCBMemberVariableAssigner;
|
||||
class CCBSelectorResolver;
|
||||
class CCBAnimationManager;
|
||||
class CCData;
|
||||
class CCBKeyframe;
|
||||
|
||||
/**
|
||||
* @brief Parse CCBI file which is generated by CocosBuilder
|
||||
*/
|
||||
class CCBReader : public CCObject {
|
||||
private:
|
||||
CCString * mCCBRootPath;
|
||||
bool mRootCCBReader;
|
||||
|
||||
unsigned char * mBytes;
|
||||
int mCurrentByte;
|
||||
int mCurrentBit;
|
||||
CCObject * mOwner;
|
||||
CCNode * mRootNode;
|
||||
CCSize mRootContainerSize;
|
||||
float mResolutionScale;
|
||||
|
||||
CCNodeLoaderLibrary * mCCNodeLoaderLibrary;
|
||||
CCNodeLoaderListener * mCCNodeLoaderListener;
|
||||
CCBMemberVariableAssigner * mCCBMemberVariableAssigner;
|
||||
CCBSelectorResolver * mCCBSelectorResolver;
|
||||
|
||||
std::vector<CCString *> mStringCache;
|
||||
std::set<std::string> mLoadedSpriteSheets;
|
||||
|
||||
public:
|
||||
CCBReader(CCNodeLoaderLibrary * pCCNodeLoaderLibrary, CCBMemberVariableAssigner * pCCBMemberVariableAssigner = NULL, CCBSelectorResolver * pCCBSelectorResolver = NULL, CCNodeLoaderListener * pCCNodeLoaderListener = NULL);
|
||||
CCBReader(CCBReader * pCCBReader);
|
||||
virtual ~CCBReader();
|
||||
class CCBReader : public CCObject
|
||||
{
|
||||
private:
|
||||
CCData *mData;
|
||||
unsigned char *mBytes;
|
||||
int mCurrentByte;
|
||||
int mCurrentBit;
|
||||
|
||||
CCNode * readNodeGraphFromFile(const char * pCCBRootPath, const char * pCCBFileName, CCObject * pOwner = NULL);
|
||||
CCNode * readNodeGraphFromFile(CCString * pCCBRootPath, CCString * pCCBFileName, CCObject * pOwner = NULL);
|
||||
CCNode * readNodeGraphFromFile(const char * pCCBRootPath, const char * pCCBFileName, CCObject * pOwner, CCSize pRootContainerSize);
|
||||
CCNode * readNodeGraphFromFile(CCString * pCCBRootPath, CCString * pCCBFileName, CCObject * pOwner, CCSize pRootContainerSize);
|
||||
std::vector<CCString *> mStringCache;
|
||||
std::set<std::string> mLoadedSpriteSheets;
|
||||
|
||||
CCObject *mOwner;
|
||||
|
||||
CCBAnimationManager *mActionManager;
|
||||
std::set<std::string> *mAnimatedProps;
|
||||
|
||||
CCBMemberVariableAssigner * getCCBMemberVariableAssigner();
|
||||
CCBSelectorResolver * getCCBSelectorResolver();
|
||||
CCNodeLoaderLibrary *mCCNodeLoaderLibrary;
|
||||
CCNodeLoaderListener *mCCNodeLoaderListener;
|
||||
CCBMemberVariableAssigner *mCCBMemberVariableAssigner;
|
||||
CCBSelectorResolver *mCCBSelectorResolver;
|
||||
|
||||
CCString * getCCBRootPath();
|
||||
CCObject * getOwner();
|
||||
CCNode * getRootNode();
|
||||
CCSize getContainerSize(CCNode * pNode);
|
||||
float getResolutionScale();
|
||||
public:
|
||||
CCBReader(CCNodeLoaderLibrary *pCCNodeLoaderLibrary, CCBMemberVariableAssigner *pCCBMemberVariableAssigner = NULL, CCBSelectorResolver *pCCBSelectorResolver = NULL, CCNodeLoaderListener *pCCNodeLoaderListener = NULL);
|
||||
CCBReader(CCBReader *pCCBReader);
|
||||
virtual ~CCBReader();
|
||||
CCBReader();
|
||||
|
||||
bool initWithData(CCData *pData, CCObject *pOwner);
|
||||
|
||||
CCNode* readNodeGraphFromFile(const char *pCCBFileName);
|
||||
CCNode* readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner);
|
||||
CCNode* readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize);
|
||||
CCNode* readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, CCBAnimationManager **ppAnimationManager);
|
||||
CCNode* readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize, CCBAnimationManager **ppAnimationManager);
|
||||
|
||||
CCNode* readNodeGraphFromData(CCData *pData, CCObject *pOwner, const CCSize &parentSize, CCBAnimationManager **ppAnimationManager);
|
||||
CCNode* readNodeGraphFromData(CCData *pData, CCObject *pOwner, const CCSize &parentSize);
|
||||
|
||||
CCScene* createSceneWithNodeGraphFromFile(const char *pCCBFileName);
|
||||
CCScene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner);
|
||||
CCScene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize);
|
||||
CCScene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, CCBAnimationManager **ppAnimationManager);
|
||||
CCScene* createSceneWithNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize, CCBAnimationManager **ppAnimationManager);
|
||||
|
||||
bool isSpriteSheetLoaded(CCString * pSpriteSheet);
|
||||
void addLoadedSpriteSheet(CCString * pSpriteSheet);
|
||||
CCBMemberVariableAssigner* getCCBMemberVariableAssigner();
|
||||
CCBSelectorResolver* getCCBSelectorResolver();
|
||||
|
||||
CCBAnimationManager* getAnimationManager();
|
||||
void setAnimationManager(CCBAnimationManager *pAnimationManager);
|
||||
|
||||
// Used in CCNodeLoader::parseProperties()
|
||||
std::set<std::string>* getAnimatedProperties();
|
||||
std::set<std::string>& getLoadedSpriteSheet();
|
||||
CCObject* getOwner();
|
||||
|
||||
/* Utility methods. */
|
||||
static CCString * lastPathComponent(CCString * pString);
|
||||
static CCString * deletePathExtension(CCString * pString);
|
||||
static CCString * toLowerCase(CCString * pCCString);
|
||||
static bool endsWith(CCString * pString, CCString * pEnding);
|
||||
static CCString * concat(CCString * pStringA, CCString * pStringB);
|
||||
/* Utility methods. */
|
||||
static CCString* lastPathComponent(CCString * pString);
|
||||
static CCString* deletePathExtension(CCString * pString);
|
||||
static CCString* toLowerCase(CCString * pCCString);
|
||||
static bool endsWith(CCString * pString, CCString * pEnding);
|
||||
static CCString* concat(CCString * pStringA, CCString * pStringB);
|
||||
|
||||
/* Parse methods. */
|
||||
int readInt(bool pSigned);
|
||||
unsigned char readByte();
|
||||
bool readBool();
|
||||
float readFloat();
|
||||
CCString * readCachedString();
|
||||
/* Parse methods. */
|
||||
int readInt(bool pSigned);
|
||||
unsigned char readByte();
|
||||
bool readBool();
|
||||
float readFloat();
|
||||
CCString* readCachedString();
|
||||
|
||||
static float getResolutionScale();
|
||||
|
||||
CCNode* readFileWithCleanUp(bool bCleanUp);
|
||||
|
||||
private:
|
||||
void cleanUpNodeGraph(CCNode *pNode);
|
||||
bool readSequences();
|
||||
CCBKeyframe* readKeyframe(int type);
|
||||
|
||||
bool readHeader();
|
||||
bool readStringCache();
|
||||
void readStringCacheEntry();
|
||||
CCNode* readNodeGraph();
|
||||
CCNode* readNodeGraph(CCNode * pParent);
|
||||
|
||||
private:
|
||||
bool readHeader();
|
||||
bool readStringCache();
|
||||
void readStringCacheEntry();
|
||||
CCNode * readNodeGraph();
|
||||
CCNode * readNodeGraph(CCNode * pParent);
|
||||
|
||||
bool getBit();
|
||||
void alignBits();
|
||||
CCString * readUTF8();
|
||||
bool getBit();
|
||||
void alignBits();
|
||||
CCString* readUTF8();
|
||||
};
|
||||
|
||||
// end of effects group
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
#include "CCBSequence.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace std;
|
||||
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCBSequence::CCBSequence()
|
||||
: mDuration(0.0f)
|
||||
, mName("")
|
||||
, mSequenceId(0)
|
||||
, mChainedSequenceId(0)
|
||||
{}
|
||||
|
||||
float CCBSequence::getDuration()
|
||||
{
|
||||
return mDuration;
|
||||
}
|
||||
|
||||
void CCBSequence::setDuration(float fDuration)
|
||||
{
|
||||
mDuration = fDuration;
|
||||
}
|
||||
|
||||
const char* CCBSequence::getName()
|
||||
{
|
||||
return mName.c_str();
|
||||
}
|
||||
|
||||
void CCBSequence::setName(const char *pName)
|
||||
{
|
||||
mName = pName;
|
||||
}
|
||||
|
||||
int CCBSequence::getSequenceId()
|
||||
{
|
||||
return mSequenceId;
|
||||
}
|
||||
|
||||
void CCBSequence::setSequenceId(int nSequenceId)
|
||||
{
|
||||
mSequenceId = nSequenceId;
|
||||
}
|
||||
|
||||
int CCBSequence::getChainedSequenceId()
|
||||
{
|
||||
return mChainedSequenceId;
|
||||
}
|
||||
|
||||
void CCBSequence::setChainedSequenceId(int nChainedSequenceId)
|
||||
{
|
||||
mChainedSequenceId = nChainedSequenceId;
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef __CCB_CCSEQUENCE_H__
|
||||
#define __CCB_CCSEQUENCE_H__
|
||||
|
||||
#include "cocos-ext.h"
|
||||
#include <string>
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CCBSequence : public cocos2d::CCObject
|
||||
{
|
||||
private:
|
||||
float mDuration;
|
||||
std::string mName;
|
||||
int mSequenceId;
|
||||
int mChainedSequenceId;
|
||||
|
||||
public:
|
||||
CCBSequence();
|
||||
|
||||
float getDuration();
|
||||
void setDuration(float fDuration);
|
||||
|
||||
const char* getName();
|
||||
void setName(const char *pName);
|
||||
|
||||
int getSequenceId();
|
||||
void setSequenceId(int nSequenceId);
|
||||
|
||||
int getChainedSequenceId();
|
||||
void setChainedSequenceId(int nChainedSequenceId);
|
||||
};
|
||||
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
|
||||
#endif // __CCB_CCSEQUENCE_H__
|
|
@ -0,0 +1,52 @@
|
|||
#include "CCBSequenceProperty.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace std;
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCBSequenceProperty::CCBSequenceProperty()
|
||||
: mName("")
|
||||
, mType(0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
bool CCBSequenceProperty::init()
|
||||
{
|
||||
mKeyframes = new CCArray();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CCBSequenceProperty::~CCBSequenceProperty()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(mKeyframes);
|
||||
}
|
||||
|
||||
const char* CCBSequenceProperty::getName()
|
||||
{
|
||||
return mName.c_str();
|
||||
}
|
||||
|
||||
void CCBSequenceProperty::setName(const char *pName)
|
||||
{
|
||||
mName = pName;
|
||||
}
|
||||
|
||||
int CCBSequenceProperty::getType()
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
void CCBSequenceProperty::setType(int nType)
|
||||
{
|
||||
mType = nType;
|
||||
}
|
||||
|
||||
CCArray* CCBSequenceProperty::getKeyframes()
|
||||
{
|
||||
return mKeyframes;
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef __CCB_SEQUENCE_PROPERTY_H__
|
||||
#define __CCB_SEQUENCE_PROPERTY_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "ExtensionMacros.h"
|
||||
#include "CCBKeyframe.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CCBSequenceProperty : public cocos2d::CCObject
|
||||
{
|
||||
private:
|
||||
std::string mName;
|
||||
int mType;
|
||||
CCArray *mKeyframes;
|
||||
|
||||
public:
|
||||
CCBSequenceProperty();
|
||||
~CCBSequenceProperty();
|
||||
|
||||
virtual bool init();
|
||||
|
||||
const char* getName();
|
||||
void setName(const char* pName);
|
||||
|
||||
int getType();
|
||||
void setType(int nType);
|
||||
|
||||
CCArray* getKeyframes();
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif // __CCB_SEQUENCE_PROPERTY_H__
|
|
@ -0,0 +1,131 @@
|
|||
#include "CCBValue.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
// Implementation of ccColor3BWapper
|
||||
|
||||
ccColor3BWapper* ccColor3BWapper::create(const cocos2d::ccColor3B& color)
|
||||
{
|
||||
ccColor3BWapper *ret = new ccColor3BWapper();
|
||||
if (ret)
|
||||
{
|
||||
ret->color.r = color.r;
|
||||
ret->color.g = color.g;
|
||||
ret->color.b = color.b;
|
||||
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const ccColor3B& ccColor3BWapper::getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
// Implementation of CCBValue
|
||||
|
||||
CCBValue* CCBValue::create(int nValue)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->mValue.nValue = nValue;
|
||||
ret->mType = kIntValue;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCBValue* CCBValue::create(float fValue)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->mValue.fValue = fValue;
|
||||
ret->mType = kFloatValue;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCBValue* CCBValue::create(bool vValue)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->mValue.nValue = vValue ? 1 : 0;
|
||||
ret->mType = kBoolValue;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCBValue* CCBValue::create(unsigned char byte)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->mValue.nValue = byte;
|
||||
ret->mType = kUnsignedCharValue;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCBValue* CCBValue::create(const void *pPointer)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->mValue.pointer = pPointer;
|
||||
ret->mType = kPointerValue;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CCBValue::getIntValue()
|
||||
{
|
||||
assert(mType == kIntValue);
|
||||
|
||||
return mValue.nValue;
|
||||
}
|
||||
|
||||
float CCBValue::getFloatValue()
|
||||
{
|
||||
assert(mType == kFloatValue);
|
||||
|
||||
return mValue.fValue;
|
||||
}
|
||||
|
||||
bool CCBValue::getBoolValue()
|
||||
{
|
||||
assert(mType == kBoolValue);
|
||||
|
||||
return mValue.nValue == 1 ? true : false;
|
||||
}
|
||||
|
||||
unsigned char CCBValue::getByteValue()
|
||||
{
|
||||
assert(mType = kUnsignedCharValue);
|
||||
|
||||
return (unsigned char)(mValue.nValue);
|
||||
}
|
||||
|
||||
const void* CCBValue::getPointer()
|
||||
{
|
||||
assert(mType == kPointerValue);
|
||||
|
||||
return mValue.pointer;
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -0,0 +1,61 @@
|
|||
#ifndef __CCB_VALUE_H__
|
||||
#define __CCB_VALUE_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "ExtensionMacros.h"
|
||||
|
||||
/*
|
||||
These classes are wrapper of basic types, such as ccColor3B
|
||||
*/
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class ccColor3BWapper : public cocos2d::CCObject
|
||||
{
|
||||
private:
|
||||
cocos2d::ccColor3B color;
|
||||
|
||||
public:
|
||||
static ccColor3BWapper* create(const cocos2d::ccColor3B& color);
|
||||
|
||||
const cocos2d::ccColor3B& getColor();
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
kIntValue,
|
||||
kFloatValue,
|
||||
kPointerValue,
|
||||
kBoolValue,
|
||||
kUnsignedCharValue,
|
||||
};
|
||||
|
||||
class CCBValue : public cocos2d::CCObject
|
||||
{
|
||||
private:
|
||||
union
|
||||
{
|
||||
int nValue;
|
||||
float fValue;
|
||||
const void *pointer;
|
||||
} mValue;
|
||||
|
||||
int mType;
|
||||
|
||||
public:
|
||||
static CCBValue* create(int nValue);
|
||||
static CCBValue* create(bool bValue);
|
||||
static CCBValue* create(float fValue);
|
||||
static CCBValue* create(unsigned char byte);
|
||||
static CCBValue* create(const void *pPointer);
|
||||
|
||||
int getIntValue();
|
||||
float getFloatValue();
|
||||
bool getBoolValue();
|
||||
unsigned char getByteValue();
|
||||
const void* getPointer();
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif // __CCB_VALUE_H__
|
|
@ -6,21 +6,21 @@ NS_CC_EXT_BEGIN;
|
|||
#define PROPERTY_ZOOMONTOUCHDOWN "zoomOnTouchDown"
|
||||
#define PROPERTY_TITLE_NORMAL "title|1"
|
||||
#define PROPERTY_TITLE_HIGHLIGHTED "title|2"
|
||||
#define PROPERTY_TITLE_DISABLED "title|4"
|
||||
#define PROPERTY_TITLE_DISABLED "title|3"
|
||||
#define PROPERTY_TITLECOLOR_NORMAL "titleColor|1"
|
||||
#define PROPERTY_TITLECOLOR_HIGHLIGHTED "titleColor|2"
|
||||
#define PROPERTY_TITLECOLOR_DISABLED "titleColor|4"
|
||||
#define PROPERTY_TITLECOLOR_DISABLED "titleColor|3"
|
||||
#define PROPERTY_TITLETTF_NORMAL "titleTTF|1"
|
||||
#define PROPERTY_TITLETTF_HIGHLIGHTED "titleTTF|2"
|
||||
#define PROPERTY_TITLETTF_DISABLED "titleTTF|4"
|
||||
#define PROPERTY_TITLETTF_DISABLED "titleTTF|3"
|
||||
#define PROPERTY_TITLETTFSIZE_NORMAL "titleTTFSize|1"
|
||||
#define PROPERTY_TITLETTFSIZE_HIGHLIGHTED "titleTTFSize|2"
|
||||
#define PROPERTY_TITLETTFSIZE_DISABLED "titleTTFSize|4"
|
||||
#define PROPERTY_TITLETTFSIZE_DISABLED "titleTTFSize|3"
|
||||
#define PROPERTY_LABELANCHORPOINT "labelAnchorPoint"
|
||||
#define PROPERTY_PREFEREDSIZE "preferedSize" // TODO Should be "preferredSize". This is a typo in cocos2d-iphone, cocos2d-x and CocosBuilder!
|
||||
#define PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL "backgroundSpriteFrame|1"
|
||||
#define PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED "backgroundSpriteFrame|2"
|
||||
#define PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED "backgroundSpriteFrame|4"
|
||||
#define PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED "backgroundSpriteFrame|3"
|
||||
|
||||
void CCControlButtonLoader::onHandlePropTypeCheck(CCNode * pNode, CCNode * pParent, CCString * pPropertyName, bool pCheck, CCBReader * pCCBReader) {
|
||||
if(pPropertyName->compare(PROPERTY_ZOOMONTOUCHDOWN) == 0) {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#include "CCData.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCData::CCData(unsigned char *pBytes, const unsigned long nSize)
|
||||
: m_pBytes(pBytes)
|
||||
, m_nSize(nSize)
|
||||
{}
|
||||
|
||||
CCData::CCData(CCData *pData)
|
||||
{
|
||||
m_nSize = pData->m_nSize;
|
||||
m_pBytes = new unsigned char[m_nSize];
|
||||
memcpy(m_pBytes, pData->m_pBytes, m_nSize);
|
||||
}
|
||||
|
||||
CCData::~CCData()
|
||||
{
|
||||
CC_SAFE_DELETE_ARRAY(m_pBytes);
|
||||
}
|
||||
|
||||
unsigned char* CCData::getBytes()
|
||||
{
|
||||
return m_pBytes;
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
#ifndef __CCB_CCDATA_H__
|
||||
#define __CCB_CCDATA_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CCData : public cocos2d::CCObject
|
||||
{
|
||||
public:
|
||||
CCData(unsigned char *pBytes, const unsigned long nSize);
|
||||
CCData(CCData *pData);
|
||||
~CCData();
|
||||
|
||||
unsigned char* getBytes();
|
||||
|
||||
private:
|
||||
unsigned char* m_pBytes;
|
||||
unsigned long m_nSize;
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif // __CCB_CCDATA_H__
|
|
@ -0,0 +1,62 @@
|
|||
#include "CCNode+CCBRelativePositioning.h"
|
||||
#include "CCBReader.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCPoint getAbsolutePosition(const CCPoint &pt, int nType, const CCSize &containerSize, const char *pPropName)
|
||||
{
|
||||
CCPoint absPt = ccp(0,0);
|
||||
if (nType == kCCBPositionTypeRelativeBottomLeft)
|
||||
{
|
||||
absPt = pt;
|
||||
}
|
||||
else if (nType == kCCBPositionTypeRelativeTopLeft)
|
||||
{
|
||||
absPt.x = pt.x;
|
||||
absPt.y = containerSize.height - pt.y;
|
||||
}
|
||||
else if (nType == kCCBPositionTypeRelativeTopRight)
|
||||
{
|
||||
absPt.x = containerSize.width - pt.x;
|
||||
absPt.y = containerSize.height - pt.y;
|
||||
}
|
||||
else if (nType == kCCBPositionTypeRelativeBottomRight)
|
||||
{
|
||||
absPt.x = containerSize.width - pt.x;
|
||||
absPt.y = pt.y;
|
||||
}
|
||||
else if (nType == kCCBPositionTypePercent)
|
||||
{
|
||||
absPt.x = (int)(containerSize.width * pt.x / 100.0f);
|
||||
absPt.y = (int)(containerSize.height * pt.y / 100.0f);
|
||||
}
|
||||
else if (nType == kCCBPositionTypeMultiplyResolution)
|
||||
{
|
||||
float resolutionScale = CCBReader::getResolutionScale();
|
||||
|
||||
absPt.x = pt.x * resolutionScale;
|
||||
absPt.y = pt.y * resolutionScale;
|
||||
}
|
||||
|
||||
return absPt;
|
||||
}
|
||||
|
||||
void setRelativeScale(CCNode *pNode, float fScaleX, float fScaleY, int nType, const char* pPropName)
|
||||
{
|
||||
CCAssert(pNode, "pNode should not be null");
|
||||
|
||||
if (nType == kCCBScaleTypeMultiplyResolution)
|
||||
{
|
||||
float resolutionScale = CCBReader::getResolutionScale();
|
||||
|
||||
fScaleX *= resolutionScale;
|
||||
fScaleY *= resolutionScale;
|
||||
}
|
||||
|
||||
pNode->setScaleX(fScaleX);
|
||||
pNode->setScaleY(fScaleY);
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef __CCB_CCNODE_RELATIVEPOSITIONING_H__
|
||||
#define __CCB_CCNODE_RELATIVEPOSITIONING_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "ExtensionMacros.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
extern cocos2d::CCPoint getAbsolutePosition(const cocos2d::CCPoint &pt, int nType, const cocos2d::CCSize &containerSize, const char *pPropName);
|
||||
|
||||
extern void setRelativeScale(cocos2d::CCNode *pNode, float fScaleX, float fScaleY, int nType, const char* pPropName);
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif // __CCB_CCNODE_RELATIVEPOSITIONING_H__
|
|
@ -1,6 +1,11 @@
|
|||
#include "CCNodeLoader.h"
|
||||
#include "CCBSelectorResolver.h"
|
||||
#include "CCBMemberVariableAssigner.h"
|
||||
#include "CCBAnimationManager.h"
|
||||
#include "CCData.h"
|
||||
#include "CCNode+CCBRelativePositioning.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
|
@ -9,14 +14,18 @@ NS_CC_EXT_BEGIN
|
|||
CCNode * CCNodeLoader::loadCCNode(CCNode * pParent, CCBReader * pCCBReader) {
|
||||
CCNode * ccNode = this->createCCNode(pParent, pCCBReader);
|
||||
|
||||
this->parseProperties(ccNode, pParent, pCCBReader);
|
||||
//this->parseProperties(ccNode, pParent, pCCBReader);
|
||||
|
||||
return ccNode;
|
||||
}
|
||||
|
||||
void CCNodeLoader::parseProperties(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
int propertyCount = pCCBReader->readInt(false);
|
||||
int numRegularProps = pCCBReader->readInt(false);
|
||||
int numExturaProps = pCCBReader->readInt(false);
|
||||
int propertyCount = numRegularProps + numExturaProps;
|
||||
|
||||
for(int i = 0; i < propertyCount; i++) {
|
||||
bool isExtraProp = (i >= numRegularProps);
|
||||
int type = pCCBReader->readInt(false);
|
||||
CCString * propertyName = pCCBReader->readCachedString();
|
||||
|
||||
|
@ -24,37 +33,72 @@ void CCNodeLoader::parseProperties(CCNode * pNode, CCNode * pParent, CCBReader *
|
|||
bool setProp = false;
|
||||
|
||||
int platform = pCCBReader->readByte();
|
||||
if(platform == kCCBPlatformAll) {
|
||||
if(platform == kCCBPlatformAll)
|
||||
{
|
||||
setProp = true;
|
||||
}
|
||||
#ifdef __CC_PLATFORM_IOS
|
||||
if(platform == kCCBPlatformIOS) {
|
||||
if(platform == kCCBPlatformIOS)
|
||||
{
|
||||
setProp = true;
|
||||
}
|
||||
#elif defined(__CC_PLATFORM_MAC)
|
||||
if(platform == kCCBPlatformMac) {
|
||||
if(platform == kCCBPlatformMac)
|
||||
{
|
||||
setProp = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Forward properties for sub ccb files
|
||||
if (dynamic_cast<CCBFile*>(pNode) != NULL)
|
||||
{
|
||||
CCBFile *ccbNode = (CCBFile*)pNode;
|
||||
if (ccbNode->getCCBFileNode() && isExtraProp)
|
||||
{
|
||||
pNode = ccbNode->getCCBFileNode();
|
||||
|
||||
// Skip properties that doesn't have a value to override
|
||||
CCArray *extraPropsNames = (CCArray*)pNode->getUserObject();
|
||||
setProp &= extraPropsNames->containsObject(propertyName);
|
||||
}
|
||||
}
|
||||
else if (isExtraProp && pNode == pCCBReader->getAnimationManager()->getRootNode())
|
||||
{
|
||||
CCArray *extraPropsNames = (CCArray*)pNode->getUserObject();
|
||||
if (! extraPropsNames)
|
||||
{
|
||||
extraPropsNames = CCArray::create();
|
||||
pNode->setUserObject(extraPropsNames);
|
||||
}
|
||||
|
||||
extraPropsNames->addObject(propertyName);
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case kCCBPropTypePosition: {
|
||||
CCPoint position = this->parsePropTypePosition(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
switch(type)
|
||||
{
|
||||
case kCCBPropTypePosition:
|
||||
{
|
||||
CCPoint position = this->parsePropTypePosition(pNode, pParent, pCCBReader, propertyName->getCString());
|
||||
if (setProp)
|
||||
{
|
||||
this->onHandlePropTypePosition(pNode, pParent, propertyName, position, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypePoint: {
|
||||
case kCCBPropTypePoint:
|
||||
{
|
||||
CCPoint point = this->parsePropTypePoint(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if (setProp)
|
||||
{
|
||||
this->onHandlePropTypePoint(pNode, pParent, propertyName, point, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypePointLock: {
|
||||
case kCCBPropTypePointLock:
|
||||
{
|
||||
CCPoint pointLock = this->parsePropTypePointLock(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if (setProp)
|
||||
{
|
||||
this->onHandlePropTypePointLock(pNode, pParent, propertyName, pointLock, pCCBReader);
|
||||
}
|
||||
break;
|
||||
|
@ -66,102 +110,129 @@ void CCNodeLoader::parseProperties(CCNode * pNode, CCNode * pParent, CCBReader *
|
|||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeScaleLock: {
|
||||
float * scaleLock = this->parsePropTypeScaleLock(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
case kCCBPropTypeScaleLock:
|
||||
{
|
||||
float * scaleLock = this->parsePropTypeScaleLock(pNode, pParent, pCCBReader, propertyName->getCString());
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeScaleLock(pNode, pParent, propertyName, scaleLock, pCCBReader);
|
||||
}
|
||||
CC_SAFE_DELETE_ARRAY(scaleLock);
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeFloat: {
|
||||
case kCCBPropTypeFloat:
|
||||
{
|
||||
float f = this->parsePropTypeFloat(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeFloat(pNode, pParent, propertyName, f, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeDegrees: {
|
||||
float degrees = this->parsePropTypeDegrees(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
case kCCBPropTypeDegrees:
|
||||
{
|
||||
float degrees = this->parsePropTypeDegrees(pNode, pParent, pCCBReader, propertyName->getCString());
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeDegrees(pNode, pParent, propertyName, degrees, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeFloatScale: {
|
||||
case kCCBPropTypeFloatScale:
|
||||
{
|
||||
float floatScale = this->parsePropTypeFloatScale(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeFloatScale(pNode, pParent, propertyName, floatScale, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeInteger: {
|
||||
case kCCBPropTypeInteger:
|
||||
{
|
||||
int integer = this->parsePropTypeInteger(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeInteger(pNode, pParent, propertyName, integer, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeIntegerLabeled: {
|
||||
case kCCBPropTypeIntegerLabeled:
|
||||
{
|
||||
int integerLabeled = this->parsePropTypeIntegerLabeled(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeIntegerLabeled(pNode, pParent, propertyName, integerLabeled, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeFloatVar: {
|
||||
case kCCBPropTypeFloatVar:
|
||||
{
|
||||
float * floatVar = this->parsePropTypeFloatVar(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeFloatVar(pNode, pParent, propertyName, floatVar, pCCBReader);
|
||||
}
|
||||
CC_SAFE_DELETE_ARRAY(floatVar);
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeCheck: {
|
||||
bool check = this->parsePropTypeCheck(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
case kCCBPropTypeCheck:
|
||||
{
|
||||
bool check = this->parsePropTypeCheck(pNode, pParent, pCCBReader, propertyName->getCString());
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeCheck(pNode, pParent, propertyName, check, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeSpriteFrame: {
|
||||
CCSpriteFrame * ccSpriteFrame = this->parsePropTypeSpriteFrame(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
CCSpriteFrame * ccSpriteFrame = this->parsePropTypeSpriteFrame(pNode, pParent, pCCBReader, propertyName->getCString());
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeSpriteFrame(pNode, pParent, propertyName, ccSpriteFrame, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeAnimation: {
|
||||
case kCCBPropTypeAnimation:
|
||||
{
|
||||
CCAnimation * ccAnimation = this->parsePropTypeAnimation(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeAnimation(pNode, pParent, propertyName, ccAnimation, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeTexture: {
|
||||
case kCCBPropTypeTexture:
|
||||
{
|
||||
CCTexture2D * ccTexture2D = this->parsePropTypeTexture(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeTexture(pNode, pParent, propertyName, ccTexture2D, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeByte: {
|
||||
unsigned char byte = this->parsePropTypeByte(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
case kCCBPropTypeByte:
|
||||
{
|
||||
unsigned char byte = this->parsePropTypeByte(pNode, pParent, pCCBReader, propertyName->getCString());
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeByte(pNode, pParent, propertyName, byte, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeColor3: {
|
||||
ccColor3B color3B = this->parsePropTypeColor3(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
case kCCBPropTypeColor3:
|
||||
{
|
||||
ccColor3B color3B = this->parsePropTypeColor3(pNode, pParent, pCCBReader, propertyName->getCString());
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeColor3(pNode, pParent, propertyName, color3B, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeColor4FVar: {
|
||||
case kCCBPropTypeColor4FVar:
|
||||
{
|
||||
ccColor4F * color4FVar = this->parsePropTypeColor4FVar(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeColor4FVar(pNode, pParent, propertyName, color4FVar, pCCBReader);
|
||||
}
|
||||
CC_SAFE_DELETE_ARRAY(color4FVar);
|
||||
|
@ -175,16 +246,20 @@ void CCNodeLoader::parseProperties(CCNode * pNode, CCNode * pParent, CCBReader *
|
|||
CC_SAFE_DELETE_ARRAY(flip);
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeBlendFunc: {
|
||||
case kCCBPropTypeBlendmode:
|
||||
{
|
||||
ccBlendFunc blendFunc = this->parsePropTypeBlendFunc(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeBlendFunc(pNode, pParent, propertyName, blendFunc, pCCBReader);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kCCBPropTypeFntFile: {
|
||||
case kCCBPropTypeFntFile:
|
||||
{
|
||||
CCString * fntFile = this->parsePropTypeFntFile(pNode, pParent, pCCBReader);
|
||||
if(setProp) {
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeFntFile(pNode, pParent, propertyName, fntFile, pCCBReader);
|
||||
}
|
||||
break;
|
||||
|
@ -240,43 +315,31 @@ void CCNodeLoader::parseProperties(CCNode * pNode, CCNode * pParent, CCBReader *
|
|||
}
|
||||
}
|
||||
|
||||
CCPoint CCNodeLoader::parsePropTypePosition(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
CCPoint CCNodeLoader::parsePropTypePosition(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName) {
|
||||
float x = pCCBReader->readFloat();
|
||||
float y = pCCBReader->readFloat();
|
||||
|
||||
int type = pCCBReader->readInt(false);
|
||||
|
||||
CCSize containerSize = pCCBReader->getContainerSize(pParent);
|
||||
CCSize containerSize = pCCBReader->getAnimationManager()->getContainerSize(pParent);
|
||||
|
||||
switch (type) {
|
||||
case kCCBPositionTypeRelativeBottomLeft: {
|
||||
/* Nothing. */
|
||||
break;
|
||||
}
|
||||
case kCCBPositionTypeRelativeTopLeft: {
|
||||
y = containerSize.height - y;
|
||||
break;
|
||||
}
|
||||
case kCCBPositionTypeRelativeTopRight: {
|
||||
x = containerSize.width - x;
|
||||
y = containerSize.height - y;
|
||||
break;
|
||||
}
|
||||
case kCCBPositionTypeRelativeBottomRight: {
|
||||
x = containerSize.width - x;
|
||||
break;
|
||||
}
|
||||
case kCCBPositionTypePercent: {
|
||||
x = (int)(containerSize.width * x / 100.0f);
|
||||
y = (int)(containerSize.height * y / 100.0f);
|
||||
break;
|
||||
}
|
||||
CCPoint pt = getAbsolutePosition(ccp(x,y), type, containerSize, pPropertyName);
|
||||
pNode->setPosition(getAbsolutePosition(pt, type, containerSize, pPropertyName));;
|
||||
|
||||
if (pCCBReader->getAnimatedProperties()->find(pPropertyName) != pCCBReader->getAnimatedProperties()->end())
|
||||
{
|
||||
CCArray *baseValue = CCArray::create(CCBValue::create(x),
|
||||
CCBValue::create(y),
|
||||
CCBValue::create(type),
|
||||
NULL);
|
||||
pCCBReader->getAnimationManager()->setBaseValue(baseValue, pNode, pPropertyName);
|
||||
}
|
||||
|
||||
return CCPoint(x, y);
|
||||
return pt;
|
||||
}
|
||||
|
||||
CCPoint CCNodeLoader::parsePropTypePoint(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
CCPoint CCNodeLoader::parsePropTypePoint(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader)
|
||||
{
|
||||
float x = pCCBReader->readFloat();
|
||||
float y = pCCBReader->readFloat();
|
||||
|
||||
|
@ -296,31 +359,44 @@ CCSize CCNodeLoader::parsePropTypeSize(CCNode * pNode, CCNode * pParent, CCBRead
|
|||
|
||||
int type = pCCBReader->readInt(false);
|
||||
|
||||
CCSize containerSize = pCCBReader->getContainerSize(pParent);
|
||||
CCSize containerSize = pCCBReader->getAnimationManager()->getContainerSize(pParent);
|
||||
|
||||
switch (type) {
|
||||
case kCCBSizeTypeAbsolute: {
|
||||
switch (type)
|
||||
{
|
||||
case kCCBSizeTypeAbsolute:
|
||||
{
|
||||
/* Nothing. */
|
||||
break;
|
||||
}
|
||||
case kCCBSizeTypeRelativeContainer: {
|
||||
case kCCBSizeTypeRelativeContainer:
|
||||
{
|
||||
width = containerSize.width - width;
|
||||
height = containerSize.height - height;
|
||||
break;
|
||||
}
|
||||
case kCCBSizeTypePercent: {
|
||||
case kCCBSizeTypePercent:
|
||||
{
|
||||
width = (int)(containerSize.width * width / 100.0f);
|
||||
height = (int)(containerSize.height * height / 100.0f);
|
||||
break;
|
||||
}
|
||||
case kCCBSizeTypeHorizontalPercent: {
|
||||
case kCCBSizeTypeHorizontalPercent:
|
||||
{
|
||||
width = (int)(containerSize.width * width / 100.0f);
|
||||
break;
|
||||
}
|
||||
case kCCBSzieTypeVerticalPercent: {
|
||||
case kCCBSizeTypeVerticalPercent:
|
||||
{
|
||||
height = (int)(containerSize.height * height / 100.0f);
|
||||
break;
|
||||
}
|
||||
case kCCBSizeTypeMultiplyResolution:
|
||||
{
|
||||
float resolutionScale = CCBReader::getResolutionScale();
|
||||
|
||||
width *= resolutionScale;
|
||||
height *= resolutionScale;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -328,13 +404,25 @@ CCSize CCNodeLoader::parsePropTypeSize(CCNode * pNode, CCNode * pParent, CCBRead
|
|||
return CCSize(width, height);
|
||||
}
|
||||
|
||||
float * CCNodeLoader::parsePropTypeScaleLock(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
float * CCNodeLoader::parsePropTypeScaleLock(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName) {
|
||||
float x = pCCBReader->readFloat();
|
||||
float y = pCCBReader->readFloat();
|
||||
|
||||
int type = pCCBReader->readInt(false);
|
||||
|
||||
if(type == kCCBScaleTypeMultiplyResolution) {
|
||||
setRelativeScale(pNode, x, y, type, pPropertyName);
|
||||
|
||||
if (pCCBReader->getAnimatedProperties()->find(pPropertyName) != pCCBReader->getAnimatedProperties()->end())
|
||||
{
|
||||
CCArray *baseValue = CCArray::create(CCBValue::create(x),
|
||||
CCBValue::create(y),
|
||||
CCBValue::create(type),
|
||||
NULL);
|
||||
pCCBReader->getAnimationManager()->setBaseValue(baseValue, pNode, pPropertyName);
|
||||
}
|
||||
|
||||
if (type == kCCBScaleTypeMultiplyResolution)
|
||||
{
|
||||
x *= pCCBReader->getResolutionScale();
|
||||
y *= pCCBReader->getResolutionScale();
|
||||
}
|
||||
|
@ -350,31 +438,43 @@ float CCNodeLoader::parsePropTypeFloat(CCNode * pNode, CCNode * pParent, CCBRead
|
|||
return pCCBReader->readFloat();
|
||||
}
|
||||
|
||||
float CCNodeLoader::parsePropTypeDegrees(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
return pCCBReader->readFloat();
|
||||
float CCNodeLoader::parsePropTypeDegrees(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName) {
|
||||
float ret = pCCBReader->readFloat();
|
||||
if (pCCBReader->getAnimatedProperties()->find(pPropertyName) != pCCBReader->getAnimatedProperties()->end())
|
||||
{
|
||||
CCBValue *value = CCBValue::create(ret);
|
||||
pCCBReader->getAnimationManager()->setBaseValue(value, pNode, pPropertyName);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
float CCNodeLoader::parsePropTypeFloatScale(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
float CCNodeLoader::parsePropTypeFloatScale(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader)
|
||||
{
|
||||
float f = pCCBReader->readFloat();
|
||||
|
||||
int type = pCCBReader->readInt(false);
|
||||
|
||||
if(type == kCCBScaleTypeMultiplyResolution) {
|
||||
if(type == kCCBScaleTypeMultiplyResolution)
|
||||
{
|
||||
f *= pCCBReader->getResolutionScale();
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
int CCNodeLoader::parsePropTypeInteger(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
int CCNodeLoader::parsePropTypeInteger(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader)
|
||||
{
|
||||
return pCCBReader->readInt(true);
|
||||
}
|
||||
|
||||
int CCNodeLoader::parsePropTypeIntegerLabeled(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
int CCNodeLoader::parsePropTypeIntegerLabeled(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader)
|
||||
{
|
||||
return pCCBReader->readInt(true);
|
||||
}
|
||||
|
||||
float * CCNodeLoader::parsePropTypeFloatVar(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
float * CCNodeLoader::parsePropTypeFloatVar(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader)
|
||||
{
|
||||
float f = pCCBReader->readFloat();
|
||||
float fVar = pCCBReader->readFloat();
|
||||
|
||||
|
@ -385,39 +485,54 @@ float * CCNodeLoader::parsePropTypeFloatVar(CCNode * pNode, CCNode * pParent, CC
|
|||
return arr;
|
||||
}
|
||||
|
||||
bool CCNodeLoader::parsePropTypeCheck(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
return pCCBReader->readBool();
|
||||
bool CCNodeLoader::parsePropTypeCheck(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName)
|
||||
{
|
||||
bool ret = pCCBReader->readBool();
|
||||
|
||||
if (pCCBReader->getAnimatedProperties()->find(pPropertyName) != pCCBReader->getAnimatedProperties()->end())
|
||||
{
|
||||
CCBValue *value = CCBValue::create(ret);
|
||||
pCCBReader->getAnimationManager()->setBaseValue(value, pNode, pPropertyName);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
CCSpriteFrame * CCNodeLoader::parsePropTypeSpriteFrame(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
CCSpriteFrame * CCNodeLoader::parsePropTypeSpriteFrame(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName)
|
||||
{
|
||||
CCString * spriteSheet = pCCBReader->readCachedString();
|
||||
CCString * spriteFile = pCCBReader->readCachedString();
|
||||
|
||||
CCSpriteFrame * spriteFrame;
|
||||
if(spriteSheet == NULL || spriteSheet->length() == 0) {
|
||||
if(spriteFile == NULL || spriteFile->length() == 0) {
|
||||
return NULL;
|
||||
CCSpriteFrame *spriteFrame = NULL;
|
||||
if (spriteFile->length() != 0)
|
||||
{
|
||||
if (spriteSheet->length() == 0)
|
||||
{
|
||||
CCTexture2D * texture = CCTextureCache::sharedTextureCache()->addImage(spriteFile->getCString());
|
||||
CCRect bounds = CCRectMake(0, 0, texture->getContentSize().width, texture->getContentSize().height);
|
||||
spriteFrame = CCSpriteFrame::createWithTexture(texture, bounds);
|
||||
}
|
||||
|
||||
CCString * spriteFilePath = CCBReader::concat(pCCBReader->getCCBRootPath(), spriteFile);
|
||||
|
||||
CCTexture2D * texture = CCTextureCache::sharedTextureCache()->addImage(spriteFilePath->getCString());
|
||||
CCRect bounds = CCRectMake(0, 0, texture->getContentSize().width, texture->getContentSize().height);
|
||||
spriteFrame = CCSpriteFrame::createWithTexture(texture, bounds);
|
||||
} else {
|
||||
CCSpriteFrameCache * frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
||||
|
||||
CCString * spriteSheetPath = CCBReader::concat(pCCBReader->getCCBRootPath(), spriteSheet);
|
||||
|
||||
/* Load the sprite sheet only if it is not loaded. */
|
||||
if(!pCCBReader->isSpriteSheetLoaded(spriteSheetPath)) {
|
||||
frameCache->addSpriteFramesWithFile(spriteSheetPath->getCString());
|
||||
pCCBReader->addLoadedSpriteSheet(spriteSheetPath);
|
||||
else
|
||||
{
|
||||
CCSpriteFrameCache * frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
|
||||
|
||||
// Load the sprite sheet only if it is not loaded
|
||||
if (pCCBReader->getLoadedSpriteSheet().find(spriteSheet->getCString()) == pCCBReader->getLoadedSpriteSheet().end())
|
||||
{
|
||||
frameCache->addSpriteFramesWithFile(spriteSheet->getCString());
|
||||
pCCBReader->getLoadedSpriteSheet().insert(spriteSheet->getCString());
|
||||
}
|
||||
|
||||
spriteFrame = frameCache->spriteFrameByName(spriteFile->getCString());
|
||||
}
|
||||
|
||||
spriteFrame = frameCache->spriteFrameByName(spriteFile->getCString());
|
||||
if (pCCBReader->getAnimatedProperties()->find(pPropertyName) != pCCBReader->getAnimatedProperties()->end())
|
||||
{
|
||||
pCCBReader->getAnimationManager()->setBaseValue(spriteFrame, pNode, pPropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
return spriteFrame;
|
||||
}
|
||||
|
||||
|
@ -435,7 +550,8 @@ CCAnimation * CCNodeLoader::parsePropTypeAnimation(CCNode * pNode, CCNode * pPar
|
|||
animation = CCBReader::lastPathComponent(animation);
|
||||
animationFile = CCBReader::lastPathComponent(animationFile);
|
||||
|
||||
if(animation != NULL && animation->compare("") != 0) {
|
||||
if (animation != NULL && animation->compare("") != 0)
|
||||
{
|
||||
CCAnimationCache * animationCache = CCAnimationCache::sharedAnimationCache();
|
||||
animationCache->addAnimationsWithFile(animationFile->getCString());
|
||||
|
||||
|
@ -445,21 +561,41 @@ CCAnimation * CCNodeLoader::parsePropTypeAnimation(CCNode * pNode, CCNode * pPar
|
|||
}
|
||||
|
||||
CCTexture2D * CCNodeLoader::parsePropTypeTexture(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
CCString * spriteFile = CCBReader::concat(pCCBReader->getCCBRootPath(), pCCBReader->readCachedString());
|
||||
|
||||
return CCTextureCache::sharedTextureCache()->addImage(spriteFile->getCString());
|
||||
CCString * spriteFile = pCCBReader->readCachedString();
|
||||
|
||||
if (spriteFile->compare("") != 0)
|
||||
{
|
||||
return CCTextureCache::sharedTextureCache()->addImage(spriteFile->getCString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char CCNodeLoader::parsePropTypeByte(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
return pCCBReader->readByte();
|
||||
unsigned char CCNodeLoader::parsePropTypeByte(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName)
|
||||
{
|
||||
unsigned char ret = pCCBReader->readByte();
|
||||
|
||||
if (pCCBReader->getAnimatedProperties()->find(pPropertyName) != pCCBReader->getAnimatedProperties()->end())
|
||||
{
|
||||
pCCBReader->getAnimationManager()->setBaseValue(CCBValue::create(ret), pNode, pPropertyName);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ccColor3B CCNodeLoader::parsePropTypeColor3(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
ccColor3B CCNodeLoader::parsePropTypeColor3(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName) {
|
||||
unsigned char red = pCCBReader->readByte();
|
||||
unsigned char green = pCCBReader->readByte();
|
||||
unsigned char blue = pCCBReader->readByte();
|
||||
|
||||
ccColor3B color = { red, green, blue };
|
||||
if (pCCBReader->getAnimatedProperties()->find(pPropertyName) != pCCBReader->getAnimatedProperties()->end())
|
||||
{
|
||||
ccColor3BWapper *value = ccColor3BWapper::create(color);
|
||||
pCCBReader->getAnimationManager()->setBaseValue(value, pNode, pPropertyName);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
|
@ -498,7 +634,8 @@ bool * CCNodeLoader::parsePropTypeFlip(CCNode * pNode, CCNode * pParent, CCBRead
|
|||
return arr;
|
||||
}
|
||||
|
||||
ccBlendFunc CCNodeLoader::parsePropTypeBlendFunc(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
ccBlendFunc CCNodeLoader::parsePropTypeBlendFunc(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader)
|
||||
{
|
||||
int source = pCCBReader->readInt(false);
|
||||
int destination = pCCBReader->readInt(false);
|
||||
|
||||
|
@ -509,10 +646,9 @@ ccBlendFunc CCNodeLoader::parsePropTypeBlendFunc(CCNode * pNode, CCNode * pParen
|
|||
return blendFunc;
|
||||
}
|
||||
|
||||
CCString * CCNodeLoader::parsePropTypeFntFile(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
CCString * fntFile = pCCBReader->readCachedString();
|
||||
|
||||
return CCBReader::concat(pCCBReader->getCCBRootPath(), fntFile);
|
||||
CCString * CCNodeLoader::parsePropTypeFntFile(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader)
|
||||
{
|
||||
return pCCBReader->readCachedString();
|
||||
}
|
||||
|
||||
CCString * CCNodeLoader::parsePropTypeString(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
|
@ -526,13 +662,16 @@ CCString * CCNodeLoader::parsePropTypeText(CCNode * pNode, CCNode * pParent, CCB
|
|||
CCString * CCNodeLoader::parsePropTypeFontTTF(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
|
||||
CCString * fontTTF = pCCBReader->readCachedString();
|
||||
|
||||
CCString * ttfEnding = CCString::create(".ttf");
|
||||
// CCString * ttfEnding = CCString::create(".ttf");
|
||||
|
||||
// TODO Fix me if it is wrong
|
||||
/* If the fontTTF comes with the ".ttf" extension, prepend the absolute path.
|
||||
* System fonts come without the ".ttf" extension and do not need the path prepended. */
|
||||
/*
|
||||
if(CCBReader::endsWith(CCBReader::toLowerCase(fontTTF), ttfEnding)){
|
||||
fontTTF = CCBReader::concat(pCCBReader->getCCBRootPath(), fontTTF);
|
||||
}
|
||||
*/
|
||||
|
||||
return fontTTF;
|
||||
}
|
||||
|
@ -544,7 +683,7 @@ BlockData * CCNodeLoader::parsePropTypeBlock(CCNode * pNode, CCNode * pParent, C
|
|||
if(selectorTarget != kCCBTargetTypeNone) {
|
||||
CCObject * target = NULL;
|
||||
if(selectorTarget == kCCBTargetTypeDocumentRoot) {
|
||||
target = pCCBReader->getRootNode();
|
||||
target = pCCBReader->getAnimationManager()->getRootNode();
|
||||
} else if(selectorTarget == kCCBTargetTypeOwner) {
|
||||
target = pCCBReader->getOwner();
|
||||
}
|
||||
|
@ -594,7 +733,7 @@ BlockCCControlData * CCNodeLoader::parsePropTypeBlockCCControl(CCNode * pNode, C
|
|||
if(selectorTarget != kCCBTargetTypeNone) {
|
||||
CCObject * target = NULL;
|
||||
if(selectorTarget == kCCBTargetTypeDocumentRoot) {
|
||||
target = pCCBReader->getRootNode();
|
||||
target = pCCBReader->getAnimationManager()->getRootNode();
|
||||
} else if(selectorTarget == kCCBTargetTypeOwner) {
|
||||
target = pCCBReader->getOwner();
|
||||
}
|
||||
|
@ -642,13 +781,29 @@ CCNode * CCNodeLoader::parsePropTypeCCBFile(CCNode * pNode, CCNode * pParent, CC
|
|||
|
||||
/* Change path extension to .ccbi. */
|
||||
CCString * ccbFileWithoutPathExtension = CCBReader::deletePathExtension(ccbFileName);
|
||||
CCString * ccbiFileName = CCBReader::concat(ccbFileWithoutPathExtension, CCString::create(".ccbi"));
|
||||
|
||||
ccbFileName = CCBReader::concat(ccbFileWithoutPathExtension, CCString::create(".ccbi"));
|
||||
|
||||
// Load sub file
|
||||
const char *path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(ccbFileName->getCString());
|
||||
CCBReader * ccbReader = new CCBReader(pCCBReader);
|
||||
ccbReader->autorelease();
|
||||
|
||||
CCNode * ccbFileNode = ccbReader->readNodeGraphFromFile(pCCBReader->getCCBRootPath(), ccbiFileName, pCCBReader->getOwner(), pParent->getContentSize());
|
||||
unsigned long size;
|
||||
|
||||
unsigned char * pBytes = CCFileUtils::sharedFileUtils()->getFileData(path, "rb", &size);
|
||||
CCData *data = new CCData(pBytes, size);
|
||||
ccbReader->initWithData(data, pCCBReader->getOwner());
|
||||
data->release();
|
||||
ccbReader->getAnimationManager()->setRootContainerSize(pParent->getContentSize());
|
||||
|
||||
CCNode * ccbFileNode = ccbReader->readFileWithCleanUp(false);
|
||||
|
||||
if (ccbFileNode && ccbReader->getAnimationManager()->getAutoPlaySequenceId() != -1)
|
||||
{
|
||||
// Auto play animations
|
||||
ccbReader->getAnimationManager()->runAnimations(ccbReader->getAnimationManager()->getAutoPlaySequenceId(), 0);
|
||||
}
|
||||
|
||||
return ccbFileNode;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,23 +50,23 @@ class CCNodeLoader : public CCObject {
|
|||
protected:
|
||||
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(CCNode);
|
||||
|
||||
virtual CCPoint parsePropTypePosition(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual CCPoint parsePropTypePosition(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName);
|
||||
virtual CCPoint parsePropTypePoint(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual CCPoint parsePropTypePointLock(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual CCSize parsePropTypeSize(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual float * parsePropTypeScaleLock(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual float * parsePropTypeScaleLock(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName);
|
||||
virtual float parsePropTypeFloat(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual float parsePropTypeDegrees(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual float parsePropTypeDegrees(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName);
|
||||
virtual float parsePropTypeFloatScale(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual int parsePropTypeInteger(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual int parsePropTypeIntegerLabeled(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual float * parsePropTypeFloatVar(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual bool parsePropTypeCheck(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual CCSpriteFrame * parsePropTypeSpriteFrame(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual bool parsePropTypeCheck(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName);
|
||||
virtual CCSpriteFrame * parsePropTypeSpriteFrame(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName);
|
||||
virtual CCAnimation * parsePropTypeAnimation(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual CCTexture2D * parsePropTypeTexture(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual unsigned char parsePropTypeByte(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual ccColor3B parsePropTypeColor3(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual unsigned char parsePropTypeByte(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName);
|
||||
virtual ccColor3B parsePropTypeColor3(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName);
|
||||
virtual ccColor4F * parsePropTypeColor4FVar(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual bool * parsePropTypeFlip(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
virtual ccBlendFunc parsePropTypeBlendFunc(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
|
||||
|
|
|
@ -49,6 +49,7 @@ Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer
|
|||
Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.cpp \
|
||||
Classes/ExtensionsTest/CocosBuilderTest/ButtonTest/ButtonTestLayer.cpp \
|
||||
Classes/ExtensionsTest/CocosBuilderTest/MenuTest/MenuTestLayer.cpp \
|
||||
Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.cpp \
|
||||
Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp \
|
||||
Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp \
|
||||
Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp \
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef _ANIMATIONSTESTLAYERLOADER_H_
|
||||
#define _ANIMATIONSTESTLAYERLOADER_H_
|
||||
|
||||
#include "AnimationsTestLayer.h"
|
||||
#include "CCNodeLoader.h"
|
||||
|
||||
/* Forward declaration. */
|
||||
class CCBReader;
|
||||
|
||||
class AnimationsTestLayerLoader : public cocos2d::extension::CCLayerLoader {
|
||||
public:
|
||||
CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(AnimationsTestLayerLoader, loader);
|
||||
|
||||
protected:
|
||||
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(AnimationsTestLayer);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,57 @@
|
|||
#include "AnimationsTestLayer.h"
|
||||
#include "CCBAnimationManager.h"
|
||||
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
AnimationsTestLayer::AnimationsTestLayer()
|
||||
: mAnimationManager(NULL)
|
||||
{}
|
||||
|
||||
AnimationsTestLayer::~AnimationsTestLayer()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(mAnimationManager);
|
||||
}
|
||||
|
||||
SEL_MenuHandler AnimationsTestLayer::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SEL_CCControlHandler AnimationsTestLayer::onResolveCCBCCControlSelector(CCObject *pTarget, CCString*pSelectorName) {
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCCControlButtonIdleClicked", AnimationsTestLayer::onCCControlButtonIdleClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCCControlButtonWaveClicked", AnimationsTestLayer::onCCControlButtonWaveClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCCControlButtonJumpClicked", AnimationsTestLayer::onCCControlButtonJumpClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCCControlButtonFunkyClicked", AnimationsTestLayer::onCCControlButtonFunkyClicked);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool AnimationsTestLayer::onAssignCCBMemberVariable(CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode) {
|
||||
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAnimationManager", CCBAnimationManager *, this->mAnimationManager);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void AnimationsTestLayer::setAnimationManager(cocos2d::extension::CCBAnimationManager *pAnimationManager)
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(mAnimationManager);
|
||||
mAnimationManager = pAnimationManager;
|
||||
CC_SAFE_RETAIN(mAnimationManager);
|
||||
}
|
||||
|
||||
void AnimationsTestLayer::onCCControlButtonIdleClicked(CCObject *pSender, CCControlEvent pCCControlEvent) {
|
||||
mAnimationManager->runAnimations("Idle", 0.3f);
|
||||
}
|
||||
|
||||
void AnimationsTestLayer::onCCControlButtonWaveClicked(CCObject *pSender, CCControlEvent pCCControlEvent) {
|
||||
mAnimationManager->runAnimations("Wave", 0.3f);
|
||||
}
|
||||
|
||||
void AnimationsTestLayer::onCCControlButtonJumpClicked(CCObject *pSender, CCControlEvent pCCControlEvent) {
|
||||
mAnimationManager->runAnimations("Jump", 0.3f);
|
||||
}
|
||||
|
||||
void AnimationsTestLayer::onCCControlButtonFunkyClicked(CCObject *pSender, CCControlEvent pCCControlEvent) {
|
||||
mAnimationManager->runAnimations("Funky", 0.3f);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef _ANIMATIONSTESTLAYER_H_
|
||||
#define _ANIMATIONSTESTLAYER_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
|
||||
class AnimationsTestLayer
|
||||
: public cocos2d::CCLayer
|
||||
, public cocos2d::extension::CCBSelectorResolver
|
||||
, public cocos2d::extension::CCBMemberVariableAssigner
|
||||
{
|
||||
public:
|
||||
CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(AnimationsTestLayer, create);
|
||||
|
||||
AnimationsTestLayer();
|
||||
virtual ~AnimationsTestLayer();
|
||||
|
||||
virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName);
|
||||
virtual cocos2d::extension::SEL_CCControlHandler onResolveCCBCCControlSelector(cocos2d::CCObject * pTarget, cocos2d::CCString * pSelectorName);
|
||||
virtual bool onAssignCCBMemberVariable(cocos2d::CCObject * pTarget, cocos2d::CCString * pMemberVariableName, cocos2d::CCNode * pNode);
|
||||
|
||||
void onCCControlButtonIdleClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onCCControlButtonWaveClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onCCControlButtonJumpClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onCCControlButtonFunkyClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
|
||||
void setAnimationManager(cocos2d::extension::CCBAnimationManager *pAnimationManager);
|
||||
|
||||
private:
|
||||
cocos2d::extension::CCBAnimationManager *mAnimationManager;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -37,10 +37,11 @@ void CocosBuilderTestScene::runThisTest() {
|
|||
|
||||
/* Create an autorelease CCBReader. */
|
||||
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
|
||||
ccbReader->autorelease();
|
||||
|
||||
/* Read a ccbi file. */
|
||||
CCNode * node = ccbReader->readNodeGraphFromFile("ccb/official/pub/", "ccb/HelloCocosBuilder.ccbi", this);
|
||||
CCNode * node = ccbReader->readNodeGraphFromFile("ccb/HelloCocosBuilder.ccbi", this);
|
||||
|
||||
ccbReader->release();
|
||||
|
||||
if(node != NULL) {
|
||||
this->addChild(node);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "../MenuTest/MenuTestLayerLoader.h"
|
||||
#include "../ParticleSystemTest/ParticleSystemTestLayerLoader.h"
|
||||
#include "../ScrollViewTest/ScrollViewTestLayerLoader.h"
|
||||
#include "../AnimationsTest/AnimationsLayerLoader.h"
|
||||
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
|
@ -40,7 +41,7 @@ void HelloCocosBuilderLayer::openTest(const char * pCCBFileName, const char * pC
|
|||
// the owner will cause lblTestTitle to be set by the CCBReader.
|
||||
// lblTestTitle is in the TestHeader.ccbi, which is referenced
|
||||
// from each of the test scenes.
|
||||
CCNode * node = ccbReader->readNodeGraphFromFile("ccb/official/pub/", pCCBFileName, this);
|
||||
CCNode * node = ccbReader->readNodeGraphFromFile(pCCBFileName, this);
|
||||
|
||||
this->mTestTitleLabelTTF->setString(pCCBFileName);
|
||||
|
||||
|
@ -60,7 +61,7 @@ void HelloCocosBuilderLayer::openTest(const char * pCCBFileName, const char * pC
|
|||
|
||||
|
||||
void HelloCocosBuilderLayer::onNodeLoaded(cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader) {
|
||||
CCRotateBy * ccRotateBy = CCRotateBy::create(0.5f, 10);
|
||||
CCRotateBy * ccRotateBy = CCRotateBy::create(20.0f, 360);
|
||||
CCRepeatForever * ccRepeatForever = CCRepeatForever::create(ccRotateBy);
|
||||
this->mBurstSprite->runAction(ccRepeatForever);
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ SEL_CCControlHandler HelloCocosBuilderLayer::onResolveCCBCCControlSelector(CCObj
|
|||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onMenuTestClicked", HelloCocosBuilderLayer::onMenuTestClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onSpriteTestClicked", HelloCocosBuilderLayer::onSpriteTestClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onButtonTestClicked", HelloCocosBuilderLayer::onButtonTestClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onLabelTestClicked", HelloCocosBuilderLayer::onLabelTestClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAnimationsTestClicked", HelloCocosBuilderLayer::onAnimationsTestClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onParticleSystemTestClicked", HelloCocosBuilderLayer::onParticleSystemTestClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onScrollViewTestClicked", HelloCocosBuilderLayer::onScrollViewTestClicked);
|
||||
|
||||
|
@ -90,25 +91,64 @@ bool HelloCocosBuilderLayer::onAssignCCBMemberVariable(CCObject * pTarget, CCStr
|
|||
|
||||
|
||||
void HelloCocosBuilderLayer::onMenuTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
||||
this->openTest("ccb/MenuTest.ccbi", "MenuTestLayer", MenuTestLayerLoader::loader());
|
||||
this->openTest("ccb/ccb/TestMenus.ccbi", "TestMenusLayer", MenuTestLayerLoader::loader());
|
||||
}
|
||||
|
||||
void HelloCocosBuilderLayer::onSpriteTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
||||
this->openTest("ccb/SpriteTest.ccbi", "SpriteTestLayer", SpriteTestLayerLoader::loader());
|
||||
this->openTest("ccb/ccb/TestSprites.ccbi", "TestSpritesLayer", SpriteTestLayerLoader::loader());
|
||||
}
|
||||
|
||||
void HelloCocosBuilderLayer::onButtonTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
||||
this->openTest("ccb/ButtonTest.ccbi", "ButtonTestLayer", ButtonTestLayerLoader::loader());
|
||||
this->openTest("ccb/ccb/TestButtons.ccbi", "TestButtonsLayer", ButtonTestLayerLoader::loader());
|
||||
}
|
||||
|
||||
void HelloCocosBuilderLayer::onLabelTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
||||
this->openTest("ccb/LabelTest.ccbi", "LabelTestLayer", LabelTestLayerLoader::loader());
|
||||
void HelloCocosBuilderLayer::onAnimationsTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
||||
// Load node graph (TestAnimations is a sub class of CCLayer) and retrieve the ccb action manager
|
||||
CCBAnimationManager *actionManager = NULL;
|
||||
|
||||
/* Create an autorelease CCNodeLoaderLibrary. */
|
||||
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
|
||||
|
||||
ccNodeLoaderLibrary->registerCCNodeLoader("TestHeaderLayer", TestHeaderLayerLoader::loader());
|
||||
ccNodeLoaderLibrary->registerCCNodeLoader("TestAnimationsLayer", AnimationsTestLayerLoader::loader());
|
||||
|
||||
|
||||
/* Create an autorelease CCBReader. */
|
||||
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
|
||||
ccbReader->autorelease();
|
||||
|
||||
/* Read a ccbi file. */
|
||||
// Load the scene from the ccbi-file, setting this class as
|
||||
// the owner will cause lblTestTitle to be set by the CCBReader.
|
||||
// lblTestTitle is in the TestHeader.ccbi, which is referenced
|
||||
// from each of the test scenes.
|
||||
CCNode *animationsTest = ccbReader->readNodeGraphFromFile("ccb/ccb/TestAnimations.ccbi", this, &actionManager);
|
||||
((AnimationsTestLayer*)animationsTest)->setAnimationManager(actionManager);
|
||||
|
||||
this->mTestTitleLabelTTF->setString("TestAnimations.ccbi");
|
||||
|
||||
CCScene * scene = CCScene::create();
|
||||
if(animationsTest != NULL) {
|
||||
scene->addChild(animationsTest);
|
||||
}
|
||||
|
||||
/* Push the new scene with a fancy transition. */
|
||||
ccColor3B transitionColor;
|
||||
transitionColor.r = 0;
|
||||
transitionColor.g = 0;
|
||||
transitionColor.b = 0;
|
||||
|
||||
CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5f, scene, transitionColor));
|
||||
|
||||
|
||||
//this->openTest("TestAnimations.ccbi", "TestAnimationsLayer", AnimationsTestLayerLoader::loader());
|
||||
}
|
||||
|
||||
void HelloCocosBuilderLayer::onParticleSystemTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
||||
this->openTest("ccb/ParticleSystemTest.ccbi", "ParticleSystemTestLayer", ParticleSystemTestLayerLoader::loader());
|
||||
this->openTest("ccb/ccb/TestParticleSystems.ccbi", "TestParticleSystemsLayer", ParticleSystemTestLayerLoader::loader());
|
||||
}
|
||||
|
||||
void HelloCocosBuilderLayer::onScrollViewTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
||||
this->openTest("ccb/ScrollViewTest.ccbi", "ScrollViewTestLayer", ScrollViewTestLayerLoader::loader());
|
||||
void HelloCocosBuilderLayer::onScrollViewTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent)
|
||||
{
|
||||
this->openTest("ccb/ccb/TestScrollViews.ccbi", "TestScrollViewsLayer", ScrollViewTestLayerLoader::loader());
|
||||
}
|
|
@ -15,10 +15,10 @@
|
|||
* http://www.cocoabuilder.com/archive/xcode/265549-crash-in-virtual-method-call.html
|
||||
*/
|
||||
class HelloCocosBuilderLayer
|
||||
: public cocos2d::CCLayer
|
||||
, public cocos2d::extension::CCBSelectorResolver
|
||||
: public cocos2d::CCLayer
|
||||
, public cocos2d::extension::CCBSelectorResolver
|
||||
, public cocos2d::extension::CCBMemberVariableAssigner
|
||||
, public cocos2d::extension::CCNodeLoaderListener
|
||||
, public cocos2d::extension::CCNodeLoaderListener
|
||||
{
|
||||
public:
|
||||
CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(HelloCocosBuilderLayer, create);
|
||||
|
@ -36,7 +36,7 @@ class HelloCocosBuilderLayer
|
|||
void onMenuTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onSpriteTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onButtonTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onLabelTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onAnimationsTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onParticleSystemTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onScrollViewTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
38e3a5fabac55b5649842cb35930af7594f093ef
|
|
@ -1 +0,0 @@
|
|||
2685fbcab626d939a8e2ea65b05a8a82beb90afa
|
|
@ -1 +0,0 @@
|
|||
197f4c7204f12af28120d3506524f0ac051b624d
|
|
@ -1 +0,0 @@
|
|||
197f4c7204f12af28120d3506524f0ac051b624d
|
|
@ -1 +0,0 @@
|
|||
723ff604c8b83d6b1c5a72aea87e9c904fe6c699
|
|
@ -1 +0,0 @@
|
|||
723ff604c8b83d6b1c5a72aea87e9c904fe6c699
|
|
@ -1 +1 @@
|
|||
48422011360e4d8706df417f7061b830a3b9613a
|
||||
4e9a0c8b08e12b2d6d915f77e26eae289a302051
|
|
@ -69,6 +69,7 @@ OBJECTS = ../Classes/AccelerometerTest/AccelerometerTest.o \
|
|||
../Classes/ExtensionsTest/CocosBuilderTest/ButtonTest/ButtonTestLayer.o \
|
||||
../Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.o \
|
||||
../Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.o \
|
||||
../Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsLayer.o \
|
||||
../Classes/ExtensionsTest/CocosBuilderTest/MenuTest/MenuTestLayer.o \
|
||||
../Classes/ExtensionsTest/CocosBuilderTest/TestHeader/TestHeaderLayer.o \
|
||||
../Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.o \
|
||||
|
|
|
@ -1 +1 @@
|
|||
05fb7e1549cf656c61a502a07712b042ff7eec9b
|
||||
35ee36aee350134dbe3d44c7a91b309972ea00ad
|
Loading…
Reference in New Issue