2014-01-17 13:35:58 +08:00
|
|
|
#include "cocos2d.h"
|
|
|
|
|
2012-06-13 02:59:49 +08:00
|
|
|
#include "CCNodeLoader.h"
|
|
|
|
#include "CCBSelectorResolver.h"
|
2012-06-14 05:19:13 +08:00
|
|
|
#include "CCBMemberVariableAssigner.h"
|
2012-09-17 14:27:17 +08:00
|
|
|
#include "CCBAnimationManager.h"
|
2012-09-18 17:04:10 +08:00
|
|
|
#include "CCNode+CCBRelativePositioning.h"
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2014-01-17 13:35:58 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
using namespace std;
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d;
|
|
|
|
using namespace cocos2d::extension;
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocosbuilder {
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
NodeLoader::NodeLoader()
|
2013-01-21 18:37:17 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
NodeLoader::~NodeLoader()
|
2013-01-21 18:37:17 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
ValueMap& NodeLoader::getCustomProperties()
|
2013-01-21 18:37:17 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _customProperties;
|
2013-01-21 18:37:17 +08:00
|
|
|
}
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
Node * NodeLoader::loadNode(Node * pParent, CCBReader * ccbReader)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Node * ccNode = this->createNode(pParent, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-11-11 15:45:07 +08:00
|
|
|
//clear _customProperties, ready for load next node.
|
2013-12-09 17:45:24 +08:00
|
|
|
_customProperties.clear();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
|
|
|
return ccNode;
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
int numRegularProps = ccbReader->readInt(false);
|
|
|
|
int numExturaProps = ccbReader->readInt(false);
|
2012-09-17 14:27:17 +08:00
|
|
|
int propertyCount = numRegularProps + numExturaProps;
|
|
|
|
|
2012-05-31 02:28:50 +08:00
|
|
|
for(int i = 0; i < propertyCount; i++) {
|
2012-09-17 14:27:17 +08:00
|
|
|
bool isExtraProp = (i >= numRegularProps);
|
2013-07-27 21:44:49 +08:00
|
|
|
CCBReader::PropertyType type = (CCBReader::PropertyType)ccbReader->readInt(false);
|
|
|
|
std::string propertyName = ccbReader->readCachedString();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
|
|
|
// Check if the property can be set for this platform
|
|
|
|
bool setProp = false;
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
CCBReader::PlatformType platform = (CCBReader::PlatformType)ccbReader->readByte();
|
|
|
|
if(platform == CCBReader::PlatformType::ALL)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-05-31 02:28:50 +08:00
|
|
|
setProp = true;
|
|
|
|
}
|
2012-11-27 11:03:12 +08:00
|
|
|
// Cocos2d-x is using touch event callback for all platforms,
|
2012-11-27 11:05:52 +08:00
|
|
|
// it's different from cocos2d-iphone which uses mouse event for Mac port.
|
2013-07-27 21:44:49 +08:00
|
|
|
// So we just need to touch event by using CCBReader::PlatformType::IOS.
|
2012-11-27 11:03:12 +08:00
|
|
|
//#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
2013-07-27 21:44:49 +08:00
|
|
|
if(platform == CCBReader::PlatformType::IOS)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-05-31 02:28:50 +08:00
|
|
|
setProp = true;
|
|
|
|
}
|
2012-11-27 11:03:12 +08:00
|
|
|
// #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
2013-07-27 21:44:49 +08:00
|
|
|
// if(platform == CCBReader::PlatformType::MAC)
|
2012-11-27 11:03:12 +08:00
|
|
|
// {
|
|
|
|
// setProp = true;
|
|
|
|
// }
|
|
|
|
// #endif
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// 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
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *extraPropsNames = (Array*)pNode->getUserObject();
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* pObj = NULL;
|
2012-11-26 21:51:05 +08:00
|
|
|
bool bFound = false;
|
|
|
|
CCARRAY_FOREACH(extraPropsNames, pObj)
|
|
|
|
{
|
2013-07-09 14:29:51 +08:00
|
|
|
String* pStr = static_cast<String*>(pObj);
|
2012-11-26 21:51:05 +08:00
|
|
|
if (0 == pStr->compare(propertyName.c_str()))
|
|
|
|
{
|
|
|
|
bFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setProp &= bFound;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (isExtraProp && pNode == ccbReader->getAnimationManager()->getRootNode())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-09 14:29:51 +08:00
|
|
|
Array *extraPropsNames = static_cast<Array*>(pNode->getUserObject());
|
2012-09-17 14:27:17 +08:00
|
|
|
if (! extraPropsNames)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
extraPropsNames = Array::create();
|
2012-09-17 14:27:17 +08:00
|
|
|
pNode->setUserObject(extraPropsNames);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
extraPropsNames->addObject(String::create(propertyName));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
switch(type)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::POSITION:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Point position = this->parsePropTypePosition(pNode, pParent, ccbReader, propertyName.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
if (setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypePosition(pNode, pParent, propertyName.c_str(), position, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::POINT:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Point point = this->parsePropTypePoint(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if (setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypePoint(pNode, pParent, propertyName.c_str(), point, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::POINT_LOCK:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Point pointLock = this->parsePropTypePointLock(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if (setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypePointLock(pNode, pParent, propertyName.c_str(), pointLock, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::SIZE:
|
|
|
|
{
|
|
|
|
Size size = this->parsePropTypeSize(pNode, pParent, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
if(setProp) {
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeSize(pNode, pParent, propertyName.c_str(), size, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::SCALE_LOCK:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
float * scaleLock = this->parsePropTypeScaleLock(pNode, pParent, ccbReader, propertyName.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeScaleLock(pNode, pParent, propertyName.c_str(), scaleLock, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-06-19 02:43:46 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(scaleLock);
|
2012-05-31 02:28:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::FLOAT:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
float f = this->parsePropTypeFloat(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeFloat(pNode, pParent, propertyName.c_str(), f, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::FLOAT_XY:
|
|
|
|
{
|
|
|
|
float * xy = this->parsePropTypeFloatXY(pNode, pParent, ccbReader);
|
2013-03-19 16:33:23 +08:00
|
|
|
if(setProp)
|
2013-03-15 08:43:56 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeFloatXY(pNode, pParent, propertyName.c_str(), xy, ccbReader);
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
2013-03-20 10:41:20 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(xy);
|
2013-03-15 08:43:56 +08:00
|
|
|
break;
|
2013-07-27 21:44:49 +08:00
|
|
|
}
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::DEGREES:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
float degrees = this->parsePropTypeDegrees(pNode, pParent, ccbReader, propertyName.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeDegrees(pNode, pParent, propertyName.c_str(), degrees, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::FLOAT_SCALE:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
float floatScale = this->parsePropTypeFloatScale(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeFloatScale(pNode, pParent, propertyName.c_str(), floatScale, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::INTEGER:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
int integer = this->parsePropTypeInteger(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeInteger(pNode, pParent, propertyName.c_str(), integer, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::INTEGER_LABELED:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
int integerLabeled = this->parsePropTypeIntegerLabeled(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeIntegerLabeled(pNode, pParent, propertyName.c_str(), integerLabeled, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::FLOAT_VAR:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
float * floatVar = this->parsePropTypeFloatVar(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeFloatVar(pNode, pParent, propertyName.c_str(), floatVar, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-06-19 02:43:46 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(floatVar);
|
2012-05-31 02:28:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::CHECK:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
bool check = this->parsePropTypeCheck(pNode, pParent, ccbReader, propertyName.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeCheck(pNode, pParent, propertyName.c_str(), check, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::SPRITEFRAME:
|
|
|
|
{
|
|
|
|
SpriteFrame * ccSpriteFrame = this->parsePropTypeSpriteFrame(pNode, pParent, ccbReader, propertyName.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeSpriteFrame(pNode, pParent, propertyName.c_str(), ccSpriteFrame, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::ANIMATION:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Animation * ccAnimation = this->parsePropTypeAnimation(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeAnimation(pNode, pParent, propertyName.c_str(), ccAnimation, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::TEXTURE:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Texture2D * ccTexture2D = this->parsePropTypeTexture(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeTexture(pNode, pParent, propertyName.c_str(), ccTexture2D, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::BYTE:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
unsigned char byte = this->parsePropTypeByte(pNode, pParent, ccbReader, propertyName.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeByte(pNode, pParent, propertyName.c_str(), byte, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::COLOR3:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Color3B color3B = this->parsePropTypeColor3(pNode, pParent, ccbReader, propertyName.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeColor3(pNode, pParent, propertyName.c_str(), color3B, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::COLOR4F_VAR:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
Color4F * color4FVar = this->parsePropTypeColor4FVar(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeColor4FVar(pNode, pParent, propertyName.c_str(), color4FVar, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-06-19 02:43:46 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(color4FVar);
|
2012-05-31 02:28:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::FLIP:
|
|
|
|
{
|
|
|
|
bool * flip = this->parsePropTypeFlip(pNode, pParent, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
if(setProp) {
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeFlip(pNode, pParent, propertyName.c_str(), flip, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-06-19 02:43:46 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(flip);
|
2012-05-31 02:28:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::BLEND_MODE:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
BlendFunc blendFunc = this->parsePropTypeBlendFunc(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeBlendFunc(pNode, pParent, propertyName.c_str(), blendFunc, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::FNT_FILE:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
std::string fntFile = ccbReader->getCCBRootPath() + this->parsePropTypeFntFile(pNode, pParent, ccbReader);
|
2012-09-17 14:27:17 +08:00
|
|
|
if(setProp)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeFntFile(pNode, pParent, propertyName.c_str(), fntFile.c_str(), ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::FONT_TTF:
|
|
|
|
{
|
|
|
|
std::string fontTTF = this->parsePropTypeFontTTF(pNode, pParent, ccbReader);
|
2012-05-31 06:36:00 +08:00
|
|
|
if(setProp) {
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeFontTTF(pNode, pParent, propertyName.c_str(), fontTTF.c_str(), ccbReader);
|
2012-05-31 06:36:00 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::STRING:
|
|
|
|
{
|
|
|
|
std::string string = this->parsePropTypeString(pNode, pParent, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
if(setProp) {
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeString(pNode, pParent, propertyName.c_str(), string.c_str(), ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::TEXT:
|
|
|
|
{
|
|
|
|
std::string text = this->parsePropTypeText(pNode, pParent, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
if(setProp) {
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeText(pNode, pParent, propertyName.c_str(), text.c_str(), ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::BLOCK:
|
|
|
|
{
|
|
|
|
BlockData * blockData = this->parsePropTypeBlock(pNode, pParent, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
if(setProp) {
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeBlock(pNode, pParent, propertyName.c_str(), blockData, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-06-19 02:43:46 +08:00
|
|
|
CC_SAFE_DELETE(blockData);
|
2012-05-31 02:28:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::BLOCK_CONTROL:
|
|
|
|
{
|
|
|
|
BlockControlData * blockControlData = this->parsePropTypeBlockControl(pNode, pParent, ccbReader);
|
2013-06-20 14:15:53 +08:00
|
|
|
if(setProp && blockControlData != NULL) {
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeBlockControl(pNode, pParent, propertyName.c_str(), blockControlData, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2013-06-20 14:15:53 +08:00
|
|
|
CC_SAFE_DELETE(blockControlData);
|
2012-05-31 02:28:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::PropertyType::CCB_FILE:
|
|
|
|
{
|
|
|
|
Node * ccbFileNode = this->parsePropTypeCCBFile(pNode, pParent, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
if(setProp) {
|
2013-07-27 21:44:49 +08:00
|
|
|
this->onHandlePropTypeCCBFile(pNode, pParent, propertyName.c_str(), ccbFileNode, ccbReader);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTYTYPE(type);
|
2012-05-31 02:28:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Point NodeLoader::parsePropTypePosition(Node * pNode, Node * pParent, CCBReader * ccbReader, const char *pPropertyName)
|
|
|
|
{
|
|
|
|
float x = ccbReader->readFloat();
|
|
|
|
float y = ccbReader->readFloat();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
CCBReader::PositionType type = static_cast<CCBReader::PositionType>(ccbReader->readInt(false));
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Size containerSize = ccbReader->getAnimationManager()->getContainerSize(pParent);
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
Point pt = getAbsolutePosition(Point(x,y), type, containerSize, pPropertyName);
|
2013-01-25 11:04:41 +08:00
|
|
|
pNode->setPosition(pt);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
ValueVector vec;
|
|
|
|
vec.push_back(Value(x));
|
|
|
|
vec.push_back(Value(y));
|
|
|
|
vec.push_back(Value((int)type));
|
|
|
|
|
|
|
|
ccbReader->getAnimationManager()->setBaseValue(Value(vec), pNode, pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2012-09-18 17:04:10 +08:00
|
|
|
return pt;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Point NodeLoader::parsePropTypePoint(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
float x = ccbReader->readFloat();
|
|
|
|
float y = ccbReader->readFloat();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return Point(x, y);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Point NodeLoader::parsePropTypePointLock(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
float x = ccbReader->readFloat();
|
|
|
|
float y = ccbReader->readFloat();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return Point(x, y);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Size NodeLoader::parsePropTypeSize(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
float width = ccbReader->readFloat();
|
|
|
|
float height = ccbReader->readFloat();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
CCBReader::SizeType type = static_cast<CCBReader::SizeType>(ccbReader->readInt(false));
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Size containerSize = ccbReader->getAnimationManager()->getContainerSize(pParent);
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::SizeType::ABSOLUTE:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-05-31 02:28:50 +08:00
|
|
|
/* Nothing. */
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::SizeType::RELATIVE_CONTAINER:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-05-31 02:28:50 +08:00
|
|
|
width = containerSize.width - width;
|
|
|
|
height = containerSize.height - height;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::SizeType::PERCENT:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-05-31 02:28:50 +08:00
|
|
|
width = (int)(containerSize.width * width / 100.0f);
|
|
|
|
height = (int)(containerSize.height * height / 100.0f);
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::SizeType::HORIZONTAL_PERCENT:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-05-31 02:28:50 +08:00
|
|
|
width = (int)(containerSize.width * width / 100.0f);
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::SizeType::VERTICAL_PERCENT:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-05-31 02:28:50 +08:00
|
|
|
height = (int)(containerSize.height * height / 100.0f);
|
|
|
|
break;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
case CCBReader::SizeType::MULTIPLY_RESOLUTION:
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
float resolutionScale = CCBReader::getResolutionScale();
|
|
|
|
|
|
|
|
width *= resolutionScale;
|
|
|
|
height *= resolutionScale;
|
2013-01-21 18:37:17 +08:00
|
|
|
break;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
default:
|
2013-01-21 18:37:17 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Unknown CCB type.");
|
2013-01-21 18:37:17 +08:00
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return Size(width, height);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
float * NodeLoader::parsePropTypeFloatXY(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
float x = ccbReader->readFloat();
|
|
|
|
float y = ccbReader->readFloat();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
float * floatXY = new float[2];
|
|
|
|
floatXY[0] = x;
|
|
|
|
floatXY[1] = y;
|
|
|
|
|
|
|
|
return floatXY;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
float * NodeLoader::parsePropTypeScaleLock(Node * pNode, Node * pParent, CCBReader * ccbReader, const char *pPropertyName) {
|
|
|
|
float x = ccbReader->readFloat();
|
|
|
|
float y = ccbReader->readFloat();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
CCBReader::ScaleType type = static_cast<CCBReader::ScaleType>(ccbReader->readInt(false));
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-09-18 17:55:03 +08:00
|
|
|
setRelativeScale(pNode, x, y, type, pPropertyName);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
ValueVector baseValue;
|
|
|
|
baseValue.push_back(Value(x));
|
|
|
|
baseValue.push_back(Value(y));
|
|
|
|
baseValue.push_back(Value((int)type));
|
|
|
|
|
|
|
|
ccbReader->getAnimationManager()->setBaseValue(Value(baseValue), pNode, pPropertyName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2012-09-18 17:55:03 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (type == CCBReader::ScaleType::MULTIPLY_RESOLUTION)
|
2012-09-18 17:55:03 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
x *= ccbReader->getResolutionScale();
|
|
|
|
y *= ccbReader->getResolutionScale();
|
2012-09-18 17:55:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float * scaleLock = new float[2];
|
|
|
|
scaleLock[0] = x;
|
|
|
|
scaleLock[1] = y;
|
2012-05-31 02:28:50 +08:00
|
|
|
|
|
|
|
return scaleLock;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
float NodeLoader::parsePropTypeFloat(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
return ccbReader->readFloat();
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
float NodeLoader::parsePropTypeDegrees(Node * pNode, Node * pParent, CCBReader * ccbReader, const char *pPropertyName) {
|
|
|
|
float ret = ccbReader->readFloat();
|
|
|
|
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
ccbReader->getAnimationManager()->setBaseValue(Value(ret), pNode, pPropertyName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
float NodeLoader::parsePropTypeFloatScale(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
float f = ccbReader->readFloat();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
CCBReader::ScaleType type = static_cast<CCBReader::ScaleType>(ccbReader->readInt(false));
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(type == CCBReader::ScaleType::MULTIPLY_RESOLUTION)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
f *= ccbReader->getResolutionScale();
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-06-05 07:16:42 +08:00
|
|
|
|
2012-05-31 02:28:50 +08:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
int NodeLoader::parsePropTypeInteger(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return ccbReader->readInt(true);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
int NodeLoader::parsePropTypeIntegerLabeled(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return ccbReader->readInt(true);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
float * NodeLoader::parsePropTypeFloatVar(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
float f = ccbReader->readFloat();
|
|
|
|
float fVar = ccbReader->readFloat();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
|
|
|
float * arr = new float[2];
|
|
|
|
arr[0] = f;
|
|
|
|
arr[1] = fVar;
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
bool NodeLoader::parsePropTypeCheck(Node * pNode, Node * pParent, CCBReader * ccbReader, const char *pPropertyName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
bool ret = ccbReader->readBool();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
ccbReader->getAnimationManager()->setBaseValue(Value(ret), pNode, pPropertyName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
SpriteFrame * NodeLoader::parsePropTypeSpriteFrame(Node * pNode, Node * pParent, CCBReader * ccbReader, const char *pPropertyName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
std::string spriteSheet = ccbReader->readCachedString();
|
|
|
|
std::string spriteFile = ccbReader->readCachedString();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
SpriteFrame *spriteFrame = NULL;
|
2012-11-26 21:51:05 +08:00
|
|
|
if (spriteFile.length() != 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-11-26 21:51:05 +08:00
|
|
|
if (spriteSheet.length() == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
spriteFile = ccbReader->getCCBRootPath() + spriteFile;
|
2013-11-07 19:11:09 +08:00
|
|
|
Texture2D * texture = Director::getInstance()->getTextureCache()->addImage(spriteFile.c_str());
|
2013-05-08 05:52:11 +08:00
|
|
|
if(texture != NULL) {
|
2013-07-12 14:30:26 +08:00
|
|
|
Rect bounds = Rect(0, 0, texture->getContentSize().width, texture->getContentSize().height);
|
2013-06-20 14:15:53 +08:00
|
|
|
spriteFrame = SpriteFrame::createWithTexture(texture, bounds);
|
2013-05-08 05:52:11 +08:00
|
|
|
}
|
2012-06-02 06:13:16 +08:00
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
else
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
SpriteFrameCache * frameCache = SpriteFrameCache::getInstance();
|
2013-07-27 21:44:49 +08:00
|
|
|
spriteSheet = ccbReader->getCCBRootPath() + spriteSheet;
|
2012-09-17 14:27:17 +08:00
|
|
|
// Load the sprite sheet only if it is not loaded
|
2013-07-27 21:44:49 +08:00
|
|
|
if (ccbReader->getLoadedSpriteSheet().find(spriteSheet) == ccbReader->getLoadedSpriteSheet().end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-11-26 21:51:05 +08:00
|
|
|
frameCache->addSpriteFramesWithFile(spriteSheet.c_str());
|
2013-07-27 21:44:49 +08:00
|
|
|
ccbReader->getLoadedSpriteSheet().insert(spriteSheet);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
spriteFrame = frameCache->getSpriteFrameByName(spriteFile.c_str());
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
ccbReader->getAnimationManager()->setObject(spriteFrame, pNode, pPropertyName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2012-05-31 02:28:50 +08:00
|
|
|
return spriteFrame;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Animation * NodeLoader::parsePropTypeAnimation(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
std::string animationFile = ccbReader->getCCBRootPath() + ccbReader->readCachedString();
|
|
|
|
std::string animation = ccbReader->readCachedString();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Animation * ccAnimation = NULL;
|
2012-05-31 02:28:50 +08:00
|
|
|
|
|
|
|
// Support for stripping relative file paths, since ios doesn't currently
|
|
|
|
// know what to do with them, since its pulling from bundle.
|
|
|
|
// Eventually this should be handled by a client side asset manager
|
|
|
|
// interface which figured out what resources to load.
|
|
|
|
// TODO Does this problem exist in C++?
|
2012-11-26 21:51:05 +08:00
|
|
|
animation = CCBReader::lastPathComponent(animation.c_str());
|
|
|
|
animationFile = CCBReader::lastPathComponent(animationFile.c_str());
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
if (animation.length() > 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
AnimationCache * animationCache = AnimationCache::getInstance();
|
2012-11-26 21:51:05 +08:00
|
|
|
animationCache->addAnimationsWithFile(animationFile.c_str());
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-09-16 20:38:03 +08:00
|
|
|
ccAnimation = animationCache->getAnimation(animation.c_str());
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
return ccAnimation;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Texture2D * NodeLoader::parsePropTypeTexture(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
std::string spriteFile = ccbReader->getCCBRootPath() + ccbReader->readCachedString();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
if (spriteFile.length() > 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-11-07 19:11:09 +08:00
|
|
|
return Director::getInstance()->getTextureCache()->addImage(spriteFile.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
unsigned char NodeLoader::parsePropTypeByte(Node * pNode, Node * pParent, CCBReader * ccbReader, const char *pPropertyName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
unsigned char ret = ccbReader->readByte();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
ccbReader->getAnimationManager()->setBaseValue(Value(ret), pNode, pPropertyName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Color3B NodeLoader::parsePropTypeColor3(Node * pNode, Node * pParent, CCBReader * ccbReader, const char *pPropertyName) {
|
2013-12-09 17:45:24 +08:00
|
|
|
unsigned char r = ccbReader->readByte();
|
|
|
|
unsigned char g = ccbReader->readByte();
|
|
|
|
unsigned char b = ccbReader->readByte();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
Color3B color(r, g, b);
|
|
|
|
|
|
|
|
ValueMap colorMap;
|
|
|
|
colorMap["r"] = r;
|
|
|
|
colorMap["g"] = g;
|
|
|
|
colorMap["b"] = b;
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
ccbReader->getAnimationManager()->setBaseValue(Value(colorMap), pNode, pPropertyName);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Color4F * NodeLoader::parsePropTypeColor4FVar(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
float red = ccbReader->readFloat();
|
|
|
|
float green = ccbReader->readFloat();
|
|
|
|
float blue = ccbReader->readFloat();
|
|
|
|
float alpha = ccbReader->readFloat();
|
|
|
|
float redVar = ccbReader->readFloat();
|
|
|
|
float greenVar = ccbReader->readFloat();
|
|
|
|
float blueVar = ccbReader->readFloat();
|
|
|
|
float alphaVar = ccbReader->readFloat();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
Color4F * colors = new Color4F[2];
|
2012-05-31 02:28:50 +08:00
|
|
|
colors[0].r = red;
|
|
|
|
colors[0].g = green;
|
|
|
|
colors[0].b = blue;
|
|
|
|
colors[0].a = alpha;
|
|
|
|
|
|
|
|
colors[1].r = redVar;
|
|
|
|
colors[1].g = greenVar;
|
|
|
|
colors[1].b = blueVar;
|
|
|
|
colors[1].a = alphaVar;
|
|
|
|
|
|
|
|
return colors;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
bool * NodeLoader::parsePropTypeFlip(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
bool flipX = ccbReader->readBool();
|
|
|
|
bool flipY = ccbReader->readBool();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
|
|
|
bool * arr = new bool[2];
|
|
|
|
arr[0] = flipX;
|
|
|
|
arr[1] = flipY;
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
BlendFunc NodeLoader::parsePropTypeBlendFunc(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
int source = ccbReader->readInt(false);
|
|
|
|
int destination = ccbReader->readInt(false);
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
BlendFunc blendFunc;
|
2012-05-31 02:28:50 +08:00
|
|
|
blendFunc.src = source;
|
|
|
|
blendFunc.dst = destination;
|
|
|
|
|
|
|
|
return blendFunc;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
std::string NodeLoader::parsePropTypeFntFile(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
return ccbReader->readCachedString();
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
std::string NodeLoader::parsePropTypeString(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
return ccbReader->readCachedString();
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
std::string NodeLoader::parsePropTypeText(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
return ccbReader->readCachedString();
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
std::string NodeLoader::parsePropTypeFontTTF(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
|
|
|
std::string fontTTF = ccbReader->readCachedString();
|
2012-06-16 07:06:54 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
// String * ttfEnding = String::create(".ttf");
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-09-17 18:49:05 +08:00
|
|
|
// TODO Fix me if it is wrong
|
2012-06-16 07:06:54 +08:00
|
|
|
/* 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. */
|
2012-09-17 14:27:17 +08:00
|
|
|
/*
|
2012-06-16 05:01:57 +08:00
|
|
|
if(CCBReader::endsWith(CCBReader::toLowerCase(fontTTF), ttfEnding)){
|
2013-07-27 21:44:49 +08:00
|
|
|
fontTTF = CCBReader::concat(ccbReader->getCCBRootPath(), fontTTF);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
*/
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-06-16 05:01:57 +08:00
|
|
|
return fontTTF;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
|
|
|
{
|
|
|
|
std::string selectorName = ccbReader->readCachedString();
|
|
|
|
CCBReader::TargetType selectorTarget = static_cast<CCBReader::TargetType>(ccbReader->readInt(false));
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(selectorTarget != CCBReader::TargetType::NONE)
|
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* target = NULL;
|
2013-07-27 21:44:49 +08:00
|
|
|
if(!ccbReader->isJSControlled())
|
|
|
|
{
|
|
|
|
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
|
|
|
|
{
|
|
|
|
target = ccbReader->getAnimationManager()->getRootNode();
|
|
|
|
}
|
|
|
|
else if(selectorTarget == CCBReader::TargetType::OWNER)
|
|
|
|
{
|
|
|
|
target = ccbReader->getOwner();
|
2012-09-19 08:38:33 +08:00
|
|
|
}
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(target != NULL)
|
|
|
|
{
|
|
|
|
if(selectorName.length() > 0)
|
|
|
|
{
|
2012-11-02 08:52:07 +08:00
|
|
|
SEL_MenuHandler selMenuHandler = 0;
|
|
|
|
|
|
|
|
CCBSelectorResolver * targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(targetAsCCBSelectorResolver != NULL)
|
|
|
|
{
|
2013-07-24 17:59:21 +08:00
|
|
|
selMenuHandler = targetAsCCBSelectorResolver->onResolveCCBCCMenuItemSelector(target, selectorName.c_str());
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
|
|
|
|
if(selMenuHandler == 0)
|
|
|
|
{
|
|
|
|
CCBSelectorResolver * ccbSelectorResolver = ccbReader->getCCBSelectorResolver();
|
|
|
|
if(ccbSelectorResolver != NULL)
|
|
|
|
{
|
2013-07-24 17:59:21 +08:00
|
|
|
selMenuHandler = ccbSelectorResolver->onResolveCCBCCMenuItemSelector(target, selectorName.c_str());
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(selMenuHandler == 0) {
|
2012-11-26 21:51:05 +08:00
|
|
|
CCLOG("Skipping selector '%s' since no CCBSelectorResolver is present.", selectorName.c_str());
|
2012-11-02 08:52:07 +08:00
|
|
|
} else {
|
|
|
|
BlockData * blockData = new BlockData();
|
|
|
|
blockData->mSELMenuHandler = selMenuHandler;
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
blockData->_target = target;
|
2012-11-02 08:52:07 +08:00
|
|
|
|
|
|
|
return blockData;
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
} else {
|
2012-11-02 08:52:07 +08:00
|
|
|
CCLOG("Unexpected empty selector.");
|
2012-06-05 06:52:49 +08:00
|
|
|
}
|
|
|
|
} else {
|
2012-11-02 08:52:07 +08:00
|
|
|
CCLOG("Unexpected NULL target for selector.");
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2013-08-12 11:18:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
ccbReader->addDocumentCallbackNode(pNode);
|
|
|
|
ccbReader->addDocumentCallbackName(selectorName);
|
2013-08-12 11:18:07 +08:00
|
|
|
// Since there isn't a Control::EventType::NONE, add a TOUCH_DOWN type as a placeholder.
|
|
|
|
ccbReader->addDocumentCallbackControlEvents(Control::EventType::TOUCH_DOWN);
|
|
|
|
}
|
|
|
|
else if (selectorTarget == CCBReader::TargetType::OWNER)
|
|
|
|
{
|
2013-07-27 21:44:49 +08:00
|
|
|
ccbReader->addOwnerCallbackNode(pNode);
|
|
|
|
ccbReader->addOwnerCallbackName(selectorName);
|
2013-08-12 11:18:07 +08:00
|
|
|
// Since there isn't a Control::EventType::NONE, add a TOUCH_DOWN type as a placeholder.
|
|
|
|
ccbReader->addOwnerCallbackControlEvents(Control::EventType::TOUCH_DOWN);
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-05 06:52:49 +08:00
|
|
|
|
2012-05-31 02:28:50 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
|
|
|
{
|
|
|
|
std::string selectorName = ccbReader->readCachedString();
|
|
|
|
CCBReader::TargetType selectorTarget = static_cast<CCBReader::TargetType>(ccbReader->readInt(false));
|
|
|
|
int controlEvents = ccbReader->readInt(false);
|
2012-06-05 06:52:49 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(selectorTarget != CCBReader::TargetType::NONE)
|
|
|
|
{
|
|
|
|
if(!ccbReader->isJSControlled())
|
|
|
|
{
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* target = NULL;
|
2013-07-27 21:44:49 +08:00
|
|
|
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
|
|
|
|
{
|
|
|
|
target = ccbReader->getAnimationManager()->getRootNode();
|
|
|
|
}
|
|
|
|
else if(selectorTarget == CCBReader::TargetType::OWNER)
|
|
|
|
{
|
|
|
|
target = ccbReader->getOwner();
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(target != NULL)
|
|
|
|
{
|
|
|
|
if(selectorName.length() > 0)
|
|
|
|
{
|
2013-07-26 14:37:26 +08:00
|
|
|
Control::Handler selControlHandler = 0;
|
2012-11-02 08:52:07 +08:00
|
|
|
|
|
|
|
CCBSelectorResolver * targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(targetAsCCBSelectorResolver != NULL)
|
|
|
|
{
|
2013-07-24 17:59:21 +08:00
|
|
|
selControlHandler = targetAsCCBSelectorResolver->onResolveCCBCCControlSelector(target, selectorName.c_str());
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
|
|
|
|
if(selControlHandler == 0)
|
|
|
|
{
|
|
|
|
CCBSelectorResolver * ccbSelectorResolver = ccbReader->getCCBSelectorResolver();
|
|
|
|
if(ccbSelectorResolver != NULL)
|
|
|
|
{
|
2013-07-24 17:59:21 +08:00
|
|
|
selControlHandler = ccbSelectorResolver->onResolveCCBCCControlSelector(target, selectorName.c_str());
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if(selControlHandler == 0)
|
|
|
|
{
|
2012-11-26 21:51:05 +08:00
|
|
|
CCLOG("Skipping selector '%s' since no CCBSelectorResolver is present.", selectorName.c_str());
|
2013-07-27 21:44:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
BlockControlData * blockControlData = new BlockControlData();
|
|
|
|
blockControlData->mSELControlHandler = selControlHandler;
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
blockControlData->_target = target;
|
2013-07-26 14:37:26 +08:00
|
|
|
blockControlData->mControlEvents = (Control::EventType)controlEvents;
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
return blockControlData;
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
} else {
|
2012-11-02 08:52:07 +08:00
|
|
|
CCLOG("Unexpected empty selector.");
|
2012-06-05 06:52:49 +08:00
|
|
|
}
|
|
|
|
} else {
|
2012-11-02 08:52:07 +08:00
|
|
|
CCLOG("Unexpected NULL target for selector.");
|
2012-06-05 06:52:49 +08:00
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
|
|
|
|
{
|
|
|
|
ccbReader->addDocumentCallbackNode(pNode);
|
|
|
|
ccbReader->addDocumentCallbackName(selectorName);
|
2013-08-12 11:18:07 +08:00
|
|
|
ccbReader->addDocumentCallbackControlEvents((Control::EventType)controlEvents);
|
2013-07-27 21:44:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ccbReader->addOwnerCallbackNode(pNode);
|
|
|
|
ccbReader->addOwnerCallbackName(selectorName);
|
2013-08-12 11:18:07 +08:00
|
|
|
ccbReader->addOwnerCallbackControlEvents((Control::EventType)controlEvents);
|
2012-11-02 08:52:07 +08:00
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-05 06:52:49 +08:00
|
|
|
|
2012-05-31 02:28:50 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader * pCCBReader) {
|
2012-12-03 18:27:50 +08:00
|
|
|
std::string ccbFileName = pCCBReader->getCCBRootPath() + pCCBReader->readCachedString();
|
2012-06-01 05:57:13 +08:00
|
|
|
|
2012-05-31 02:28:50 +08:00
|
|
|
/* Change path extension to .ccbi. */
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string ccbFileWithoutPathExtension = CCBReader::deletePathExtension(ccbFileName.c_str());
|
|
|
|
ccbFileName = ccbFileWithoutPathExtension + ".ccbi";
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// Load sub file
|
2013-07-12 06:24:23 +08:00
|
|
|
std::string path = FileUtils::getInstance()->fullPathForFilename(ccbFileName.c_str());
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2013-12-18 14:58:17 +08:00
|
|
|
auto dataPtr = std::make_shared<Data>(FileUtils::getInstance()->getDataFromFile(path));
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
CCBReader * reader = new CCBReader(pCCBReader);
|
|
|
|
reader->autorelease();
|
|
|
|
reader->getAnimationManager()->setRootContainerSize(pParent->getContentSize());
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-12-18 14:58:17 +08:00
|
|
|
|
|
|
|
reader->_data = dataPtr;
|
|
|
|
reader->_bytes = dataPtr->getBytes();
|
2013-07-27 22:31:57 +08:00
|
|
|
reader->_currentByte = 0;
|
|
|
|
reader->_currentBit = 0;
|
|
|
|
CC_SAFE_RETAIN(pCCBReader->_owner);
|
|
|
|
reader->_owner = pCCBReader->_owner;
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
reader->getAnimationManager()->_owner = reader->_owner;
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2013-01-21 14:40:29 +08:00
|
|
|
// The assignments below are done in the CCBReader constructor.
|
2013-07-27 22:31:57 +08:00
|
|
|
// reader->_ownerOutletNames = pCCBReader->_ownerOutletNames;
|
|
|
|
// reader->_ownerOutletNodes = pCCBReader->_ownerOutletNodes;
|
|
|
|
// reader->_ownerOutletNodes->retain();
|
|
|
|
// reader->_ownerCallbackNames = pCCBReader->_ownerCallbackNames;
|
|
|
|
// reader->_ownerCallbackNodes = pCCBReader->_ownerCallbackNodes;
|
|
|
|
// reader->_ownerCallbackNodes->retain();
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
Node * ccbFileNode = reader->readFileWithCleanUp(false, pCCBReader->getAnimationManagers());
|
2012-10-25 02:32:42 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (ccbFileNode && reader->getAnimationManager()->getAutoPlaySequenceId() != -1)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Auto play animations
|
2013-07-27 21:44:49 +08:00
|
|
|
reader->getAnimationManager()->runAnimationsForSequenceIdTweenDuration(reader->getAnimationManager()->getAutoPlaySequenceId(), 0);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-08-10 14:43:55 +08:00
|
|
|
if (reader->isJSControlled() && pCCBReader->isJSControlled() && NULL == reader->_owner)
|
2013-06-05 15:17:00 +08:00
|
|
|
{
|
|
|
|
//set variables and callback to owner
|
|
|
|
//set callback
|
2013-12-08 22:17:54 +08:00
|
|
|
auto ownerCallbackNames = reader->getOwnerCallbackNames();
|
|
|
|
auto& ownerCallbackNodes = reader->getOwnerCallbackNodes();
|
|
|
|
if (!ownerCallbackNames.empty() && !ownerCallbackNodes.empty())
|
2013-06-05 15:17:00 +08:00
|
|
|
{
|
2013-12-08 22:17:54 +08:00
|
|
|
CCASSERT(ownerCallbackNames.size() == ownerCallbackNodes.size(), "");
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t nCount = ownerCallbackNames.size();
|
2013-08-12 11:18:07 +08:00
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
for (ssize_t i = 0 ; i < nCount; i++)
|
2013-08-12 11:18:07 +08:00
|
|
|
{
|
2013-12-08 22:17:54 +08:00
|
|
|
pCCBReader->addOwnerCallbackName(ownerCallbackNames[i].asString());
|
|
|
|
pCCBReader->addOwnerCallbackNode(ownerCallbackNodes.at(i));
|
2013-06-05 15:17:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//set variables
|
2013-12-08 22:17:54 +08:00
|
|
|
auto ownerOutletNames = reader->getOwnerOutletNames();
|
|
|
|
auto ownerOutletNodes = reader->getOwnerOutletNodes();
|
|
|
|
if (!ownerOutletNames.empty() && !ownerOutletNodes.empty())
|
2013-06-05 15:17:00 +08:00
|
|
|
{
|
2013-12-08 22:17:54 +08:00
|
|
|
CCASSERT(ownerOutletNames.size() == ownerOutletNodes.size(), "");
|
2013-12-12 12:07:20 +08:00
|
|
|
ssize_t nCount = ownerOutletNames.size();
|
2013-08-12 11:18:07 +08:00
|
|
|
|
2013-12-12 12:07:20 +08:00
|
|
|
for (ssize_t i = 0 ; i < nCount; i++)
|
2013-08-12 11:18:07 +08:00
|
|
|
{
|
2013-12-08 22:17:54 +08:00
|
|
|
pCCBReader->addOwnerOutletName(ownerOutletNames.at(i).asString());
|
|
|
|
pCCBReader->addOwnerOutletNode(ownerOutletNodes.at(i));
|
2013-06-05 15:17:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-01 05:57:13 +08:00
|
|
|
return ccbFileNode;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypePosition(Node * pNode, Node * pParent, const char* pPropertyName, Point pPosition, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_POSITION) == 0) {
|
2012-05-31 02:28:50 +08:00
|
|
|
pNode->setPosition(pPosition);
|
|
|
|
} else {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypePoint(Node * pNode, Node * pParent, const char* pPropertyName, Point pPoint, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_ANCHORPOINT) == 0) {
|
2012-05-31 02:28:50 +08:00
|
|
|
pNode->setAnchorPoint(pPoint);
|
|
|
|
} else {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypePointLock(Node * pNode, Node * pParent, const char* pPropertyName, Point pPointLock, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeSize(Node * pNode, Node * pParent, const char* pPropertyName, Size pSize, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_CONTENTSIZE) == 0) {
|
2012-05-31 02:28:50 +08:00
|
|
|
pNode->setContentSize(pSize);
|
2012-05-31 07:14:02 +08:00
|
|
|
} else {
|
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeFloatXY(Node * pNode, Node * pParent, const char* pPropertyName, float * pFloat, CCBReader * ccbReader) {
|
2013-03-15 08:43:56 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_SKEW) == 0) {
|
|
|
|
pNode->setSkewX(pFloat[0]);
|
|
|
|
pNode->setSkewY(pFloat[1]);
|
|
|
|
} else {
|
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeScaleLock(Node * pNode, Node * pParent, const char* pPropertyName, float * pScaleLock, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_SCALE) == 0) {
|
2012-05-31 02:28:50 +08:00
|
|
|
pNode->setScaleX(pScaleLock[0]);
|
2012-06-01 05:57:13 +08:00
|
|
|
pNode->setScaleY(pScaleLock[1]);
|
2012-05-31 02:28:50 +08:00
|
|
|
} else {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeFloat(Node * pNode, Node * pParent, const char* pPropertyName, float pFloat, CCBReader * ccbReader) {
|
2013-01-21 18:37:17 +08:00
|
|
|
// ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
|
|
|
// It may be a custom property, add it to custom property dictionary.
|
2013-12-09 17:45:24 +08:00
|
|
|
_customProperties[pPropertyName] = Value(pFloat);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeDegrees(Node * pNode, Node * pParent, const char* pPropertyName, float pDegrees, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_ROTATION) == 0) {
|
2012-05-31 02:28:50 +08:00
|
|
|
pNode->setRotation(pDegrees);
|
2013-03-20 14:25:30 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_ROTATIONX) == 0) {
|
|
|
|
pNode->setRotationX(pDegrees);
|
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_ROTATIONY) == 0) {
|
|
|
|
pNode->setRotationY(pDegrees);
|
|
|
|
}
|
|
|
|
else {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeFloatScale(Node * pNode, Node * pParent, const char* pPropertyName, float pFloatScale, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeInteger(Node * pNode, Node * pParent, const char* pPropertyName, int pInteger, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_TAG) == 0) {
|
2012-05-31 02:28:50 +08:00
|
|
|
pNode->setTag(pInteger);
|
|
|
|
} else {
|
2013-01-21 18:37:17 +08:00
|
|
|
// ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
|
|
|
// It may be a custom property, add it to custom property dictionary.
|
2013-12-09 17:45:24 +08:00
|
|
|
_customProperties[pPropertyName] = Value(pInteger);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeIntegerLabeled(Node * pNode, Node * pParent, const char* pPropertyName, int pIntegerLabeled, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeFloatVar(Node * pNode, Node * pParent, const char* pPropertyName, float * pFloatVar, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, const char* pPropertyName, bool pCheck, CCBReader * ccbReader) {
|
2012-11-26 21:51:05 +08:00
|
|
|
if(strcmp(pPropertyName, PROPERTY_VISIBLE) == 0) {
|
2012-06-15 15:10:40 +08:00
|
|
|
pNode->setVisible(pCheck);
|
2012-11-26 21:51:05 +08:00
|
|
|
} else if(strcmp(pPropertyName, PROPERTY_IGNOREANCHORPOINTFORPOSITION) == 0) {
|
2012-06-15 15:10:40 +08:00
|
|
|
pNode->ignoreAnchorPointForPosition(pCheck);
|
2012-05-31 02:28:50 +08:00
|
|
|
} else {
|
2013-01-21 18:37:17 +08:00
|
|
|
//ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
|
|
|
// It may be a custom property, add it to custom property dictionary.
|
2013-12-09 17:45:24 +08:00
|
|
|
_customProperties[pPropertyName] = Value(pCheck);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeSpriteFrame(Node * pNode, Node * pParent, const char* pPropertyName, SpriteFrame * pSpriteFrame, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeAnimation(Node * pNode, Node * pParent, const char* pPropertyName, Animation * pAnimation, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeTexture(Node * pNode, Node * pParent, const char* pPropertyName, Texture2D * pTexture2D, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeByte(Node * pNode, Node * pParent, const char* pPropertyName, unsigned char pByte, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeColor3(Node * pNode, Node * pParent, const char* pPropertyName, Color3B pColor3B, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeColor4FVar(Node * pNode, Node * pParent, const char* pPropertyName, Color4F * pColor4FVar, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeFlip(Node * pNode, Node * pParent, const char* pPropertyName, bool * pFlip, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeBlendFunc(Node * pNode, Node * pParent, const char* pPropertyName, BlendFunc pBlendFunc, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeFntFile(Node * pNode, Node * pParent, const char* pPropertyName, const char* pFntFile, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeString(Node * pNode, Node * pParent, const char* pPropertyName, const char * pString, CCBReader * ccbReader) {
|
2013-01-21 18:37:17 +08:00
|
|
|
// ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
|
|
|
// It may be a custom property, add it to custom property dictionary.
|
2013-12-09 17:45:24 +08:00
|
|
|
_customProperties[pPropertyName] = Value(pString);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeText(Node * pNode, Node * pParent, const char* pPropertyName, const char * pText, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeFontTTF(Node * pNode, Node * pParent, const char* pPropertyName, const char * pFontTTF, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeBlock(Node * pNode, Node * pParent, const char* pPropertyName, BlockData * pBlockData, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeBlockControl(Node * pNode, Node * pParent, const char* pPropertyName, BlockControlData * pBlockControlData, CCBReader * ccbReader) {
|
2012-05-31 07:14:02 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
void NodeLoader::onHandlePropTypeCCBFile(Node * pNode, Node * pParent, const char* pPropertyName, Node * pCCBFileNode, CCBReader * ccbReader) {
|
2012-06-01 05:57:13 +08:00
|
|
|
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
2012-07-19 17:22:36 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|