Merge pull request #885 from walzer/gles20

add CocosBuilder support for gles20 branch
This commit is contained in:
Walzer 2012-05-07 22:38:12 -07:00
commit 740038a73e
18 changed files with 1329 additions and 26 deletions

59
AUTHORS
View File

@ -1,21 +1,34 @@
cocos2d-x authors
cocos2d-x authors & contributors
(ordered by the join in time)
Core Developers:
Zhe Wang (Walzer)
XiaoMing Zhang (Minggo)
WenSheng Yang
Bin Zhang
RongHong Huang
JianHua Chen (Dumganhar)
Shun Lin
Developers:
XiaoLong Zhang (Chukong Inc)
Mike McGary (Zynga)
Di Wu
CCBReader and cpp reflection mechanic
Angus Comrie
contributes cocos2d-x port of CCControlExtension.
Yannick Loriot
author of CCControlExtension of cocos2d-iphone port.
Surith Thekkiam (folecr, Zynga)
contribute for Android module building
Jianfeng Zhou (NetGragon Inc)
contributes CCListView and CCTextureWatcher.
dducharme
author of blackberry port
HuaXu Cai (laschweinski)
HuaXu Cai (Kongzhong Corporation)
author of linux port
ciaranj
@ -39,19 +52,20 @@ Developers:
Chris Calm
authors of CCTexturePVR
RuiXiang Zhou
XiDi Peng
AiYu Ye
RuiXiang Zhou (NetDragon)
XiDi Peng (NetDragon)
AiYu Ye (NetDragon)
authors of lua binding
Max Aksenov
author and maintainer of Airplay port
Giovanni Zito
Francis Styck
maintainers of Marmalade port
authors of Marmalade port
Carlos Sessa
implement the accelerometer module onto Android
implement the accelerometer module for Android port
JianHua Chen (Dumganhar)
author of Bada port
@ -61,18 +75,19 @@ Developers:
YuLei Liao(dualface)
contribute the factor of lua binding
folecr
contribute for Android module building
Yannick Loriot
author of CCControlExtension of cocos2d-iphone port.
Angus Comrie
contributes cocos2d-x port of CCControlExtension.
NetGragon
contributes CCListView and CCTextureWatcher.
Retired Core Developers:
WenSheng Yang
Author of windows port, CCTextField,
Designer of CCApplication/CCEGLView/platform structure.
He's working together with 2dx core team but leading FishingJoy game
Bin Zhang
core-team member but put himself in FishingJoy game since 2012.
RongHong Huang (flyingpaper)
Author of cocos2d-xna and spent all his time on wp7.
Cocos2d-x can not grow so fast without the active community.
Thanks to all developers who report & trace bugs, dicuss the engine usage in forum & QQ groups!

View File

@ -55,7 +55,9 @@ extensions/CCControlExtension/CCScale9Sprite.cpp \
extensions/CCControlExtension/CCSpacer.cpp \
extensions/CCListView/CCListView.cpp \
extensions/CCListView/CCListViewCell.cpp \
extensions/CCTextureWatcher/CCTextureWatcher.cpp \
extensions/CCTextureWatcher/CCTextureWatcher.cpp \
extensions/CCBReader/CCBCustomClass.cpp \
extensions/CCBReader/CCBReader.cpp \
kazmath/src/aabb.c \
kazmath/src/mat3.c \
kazmath/src/mat4.c \

View File

@ -0,0 +1,78 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCBCustomClass.h"
USING_NS_CC_EXT;
static CCBCustomClassFactory g_FactoryInstance;
// CCBCustomClassFactory
CCBCustomClassFactory::CCBCustomClassFactory()
{
m_pCustomCreatorsMap = new CUSTOM_CLASS_MAP;
}
CCBCustomClassFactory::~CCBCustomClassFactory()
{
CC_SAFE_DELETE(m_pCustomCreatorsMap);
}
CCBCustomClassFactory* CCBCustomClassFactory::sharedFactory()
{
// TBD: don't use static global variable, so ugly
return &g_FactoryInstance;
}
bool CCBCustomClassFactory::registCustomClass(const char* name, FUNC_CUSTON_CLASS_CREATOR pfnCreator)
{
bool bRetVal = false;
if (! (*m_pCustomCreatorsMap)[name] )
{
(*m_pCustomCreatorsMap)[name] = pfnCreator;
bRetVal = true;
}
else
{
CCLOG("CCB: key = [%s] in m_pCustomCreatorsMap is already registed", name);
}
return bRetVal;
}
CCBCustomClassProtocol* CCBCustomClassFactory::createCustomClassWithName(const char* name)
{
CCBCustomClassProtocol* pRetVal = NULL;
FUNC_CUSTON_CLASS_CREATOR pfnCreator = (*m_pCustomCreatorsMap)[name];
if (pfnCreator)
{
CCLOG("CCB: creating [%s] object", name);
pRetVal = pfnCreator();
}
return pRetVal;
}

View File

@ -0,0 +1,97 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef _CC_CUSTOM_CLASS_H_
#define _CC_CUSTOM_CLASS_H_
#include "cocos2d.h"
#include <map>
NS_CC_EXT_BEGIN
/**
@brief This is a simple reflection implement for custom classes in CocosBuilder
You should declare your custom class like:
class MyCustomLayer : public CCBCustomClass, public CCLayer
CCBCustomClass is a pure virtual class. It doesn't inherit CCObject to prevent dead-diamond.
*/
class CCBCustomClassProtocol
{
public:
/** You should implement this static function in your custom class, and return a valid object */
static CCBCustomClassProtocol* createInstance() { return NULL; }; // cannot create virual class here
CCBCustomClassProtocol() {};
virtual ~CCBCustomClassProtocol() {};
/** This pure virtual methods should be implemented in your custom class
please refer to tests/ExtensionsTest/CocosBuilderTest as a sample */
virtual bool callbackSetChildren(const char* name, cocos2d::CCObject* node) = 0;
/** This pure virtual methods should be implemented in your custom class
please refer to tests/ExtensionsTest/CocosBuilderTest as a sample */
virtual cocos2d::SEL_MenuHandler callbackGetSelectors(const char* selectorName) = 0;
/** This pure virtual methods should be implemented in your custom class
please refer to tests/ExtensionsTest/CocosBuilderTest as a sample */
virtual void callbackAfterCCBLoaded() = 0;
};
/**
@brief CCBCustomClass should be registed into this factory, then CCBReader can create your custom class via its name string.
See tests/Extensionstest/CocosBuilderTest/CocosBuilderTest.cpp as the reference
*/
class CC_DLL CCBCustomClassFactory
{
private:
/// a function pointer for CCCustomClassProtocol::createInstance
typedef CCBCustomClassProtocol* (*FUNC_CUSTON_CLASS_CREATOR)();
typedef std::map<std::string, FUNC_CUSTON_CLASS_CREATOR> CUSTOM_CLASS_MAP;
CUSTOM_CLASS_MAP* m_pCustomCreatorsMap;
public:
CCBCustomClassFactory();
virtual ~CCBCustomClassFactory();
/** get the singleton */
static CCBCustomClassFactory* sharedFactory();
/** Note that you should regist custom class before invoke CCBReader::nodeGraphFromFile
For example:
CCBCustomClassFactory::sharedFactory()->registCustomClass("HelloCocosBuilder",
HelloCocosBuilder::createInstance);
*/
bool registCustomClass(const char* name, FUNC_CUSTON_CLASS_CREATOR pfnCreator);
/** This function is only used in CCBReader. Developers don't need to know it */
CCBCustomClassProtocol* createCustomClassWithName(const char* name);
};
NS_CC_EXT_END;
#endif // _CC_CUSTOM_CLASS_H_

View File

@ -0,0 +1,707 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2012 XiaoLong Zhang, Chukong Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCBReader.h"
#include "CCBCustomClass.h"
USING_NS_CC;
USING_NS_CC_EXT;
// Read value from dictionary
int CCBReader::intValFromDict(CCDictionary* dict, const std::string key)
{
CCString* valueString = (CCString*) dict->objectForKey(key.c_str());
return valueString->intValue();
}
float CCBReader::floatValFromDict(CCDictionary* dict, const std::string key)
{
CCString* valueString = (CCString*) dict->objectForKey(key.c_str());
return valueString->floatValue();
}
bool CCBReader::boolValFromDict(CCDictionary* dict, const std::string key)
{
CCString* valueString = (CCString*) dict->objectForKey(key.c_str());
return (bool) valueString->intValue();
}
CCPoint CCBReader::pointValFromDict(CCDictionary* dict, const std::string key)
{
CCArray* arr = (CCArray*)dict->objectForKey(key.c_str());
if (!arr)
{
return ccp(0,0);
}
float x = ((CCString*)arr->objectAtIndex(0))->floatValue();
float y = ((CCString*)arr->objectAtIndex(1))->floatValue();
return ccp(x, y);
}
CCSize CCBReader::sizeValFromDict(CCDictionary* dict, const std::string key)
{
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
if (!arr)
{
return CCSize(0, 0);
}
float w = ((CCString*)arr->objectAtIndex(0))->floatValue();
float h = ((CCString*)arr->objectAtIndex(1))->floatValue();
return CCSize(w, h);
}
ccColor3B CCBReader::ccColor3ValFromDict(CCDictionary* dict, const std::string key)
{
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
int r = ((CCString*)arr->objectAtIndex(0))->intValue();
int g = ((CCString*)arr->objectAtIndex(1))->intValue();
int b = ((CCString*)arr->objectAtIndex(2))->intValue();
return ccc3(r, g, b);
}
ccColor4F CCBReader::ccColor4fValFromDict(CCDictionary* dict, const std::string key)
{
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
ccColor4F color;
color.r = ((CCString*)arr->objectAtIndex(0))->floatValue();
color.g = ((CCString*)arr->objectAtIndex(1))->floatValue();
color.b = ((CCString*)arr->objectAtIndex(2))->floatValue();
color.a = ((CCString*)arr->objectAtIndex(3))->floatValue();
return color;
}
ccBlendFunc CCBReader::blendFuncValFromDict(CCDictionary* dict, const std::string key)
{
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
int src = ((CCString*)arr->objectAtIndex(0))->intValue();
int dst = ((CCString*)arr->objectAtIndex(1))->intValue();
ccBlendFunc blendFunc;
blendFunc.src = src;
blendFunc.dst = dst;
return blendFunc;
}
// set extra properties
void CCBReader::setExtraProp(CCObject* prop, const char* key, int tag, CCDictionary* dict)
{
std::string tagString;
tagString += tag;
CCDictionary* props = (CCDictionary*) dict->objectForKey(tagString.c_str());
if (!props)
{
props = new CCDictionary();
dict->setObject(props, tagString.c_str());
}
props->setObject(prop, key);
}
void CCBReader::setPropsForMenuItem(CCMenuItem* node, CCDictionary* props, CCDictionary* extraProps)
{
node->setIsEnabled(boolValFromDict(props, "isEnabled"));
if (extraProps)
{
setExtraProp((CCDictionary*) props->objectForKey("selector"), "selector", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("target"), "target", node->getTag(), extraProps);
CCString* spriteFramesFile = (CCString*) props->objectForKey("spriteFramesFile");
if (spriteFramesFile)
{
setExtraProp(spriteFramesFile, "spriteSheetFile", node->getTag(), extraProps);
}
}
}
void CCBReader::setPropsForMenuItemImage(CCMenuItemImage* node, CCDictionary* props, CCDictionary* extraProps)
{
if (extraProps)
{
setExtraProp(props->objectForKey("spriteFileNormal"), "spriteFileNormal", node->getTag(), extraProps);
setExtraProp(props->objectForKey("spriteFileSelected"), "spriteFileSelected", node->getTag(), extraProps);
setExtraProp(props->objectForKey("spriteFileDisabled"), "spriteFileDisabled", node->getTag(), extraProps);
}
}
void CCBReader::setPropsForLayerColor(CCLayerColor* node, CCDictionary* props, CCDictionary* extraProps)
{
node->setColor(ccColor3ValFromDict(props, "color"));
node->setOpacity(intValFromDict(props, "opacity"));
node->setBlendFunc(blendFuncValFromDict(props, "blendFunc"));
}
void CCBReader::setPropsForLayer(CCLayer* node, CCDictionary* props, CCDictionary* extraProps)
{
if (extraProps)
{
setExtraProp(props->objectForKey("touchEnabled"), "touchEnabled", node->getTag(), extraProps);
setExtraProp(props->objectForKey("accelerometerEnabled"), "accelerometerEnabled", node->getTag(), extraProps);
setExtraProp(props->objectForKey("mouseEnabled"), "mouseEnabled", node->getTag() ,extraProps);
setExtraProp(props->objectForKey("keyboardEnabled"), "keyboardEnabled", node->getTag(), extraProps);
}
else
{
node->setIsTouchEnabled(boolValFromDict(props, "touchEnabled"));
node->setIsAccelerometerEnabled(boolValFromDict(props, "accelerometerEnabled"));
}
}
void CCBReader::setPropsForMenu(CCMenu* node, CCDictionary* props, CCDictionary* extraProps)
{
if (extraProps)
{
}
}
void CCBReader::setPropsForLabelBMFont(CCLabelBMFont* node, CCDictionary* props, CCDictionary* extraProps)
{
node->setOpacity(intValFromDict(props, "opacity"));
node->setColor(ccColor3ValFromDict(props, "color"));
if (extraProps)
{
setExtraProp(props->objectForKey("fontFile"), "fontFile", node->getTag(), extraProps);
}
}
void CCBReader::setPropsForParticleSystem(CCParticleSystem* node, CCDictionary* props, CCDictionary* extraProps)
{
node->setEmitterMode(intValFromDict(props, "emitterMode"));
node->setEmissionRate(floatValFromDict(props, "emissionRate"));
node->setDuration(floatValFromDict(props, "duration"));
node->setPosVar(pointValFromDict(props, "posVar"));
node->setTotalParticles(intValFromDict(props, "totalParticles"));
node->setLife(floatValFromDict(props, "life"));
node->setLifeVar(floatValFromDict(props, "lifeVar"));
node->setStartSize(intValFromDict(props, "startSize"));
node->setStartSizeVar(intValFromDict(props, "startSizeVar"));
node->setEndSize(intValFromDict(props, "endSize"));
node->setEndSizeVar(intValFromDict(props, "endSizeVar"));
if (dynamic_cast<CCParticleSystemQuad*>(node))
{
node->setStartSpin(intValFromDict(props, "startSpin"));
node->setStartSpinVar(intValFromDict(props, "startSpinVar"));
node->setEndSpin(intValFromDict(props, "endSpin"));
node->setEndSpinVar(intValFromDict(props, "endSpinVar"));
}
node->setStartColor(ccColor4fValFromDict(props, "startColor"));
node->setStartColorVar(ccColor4fValFromDict(props, "startColorVar"));
node->setEndColor(ccColor4fValFromDict(props, "endColor"));
node->setEndColorVar(ccColor4fValFromDict(props, "endColorVar"));
node->setBlendFunc(blendFuncValFromDict(props, "blendFunc"));
if (node->getEmitterMode() == kCCParticleModeGravity)
{
node->setGravity(pointValFromDict(props, "gravity"));
node->setAngle(intValFromDict(props, "angle"));
node->setAngleVar(intValFromDict(props, "angleVar"));
node->setSpeed(intValFromDict(props, "speed"));
node->setSpeedVar(intValFromDict(props, "speedVar"));
node->setTangentialAccel(intValFromDict(props, "tangentialAccel"));
node->setTangentialAccelVar(intValFromDict(props, "tangentialAccelVar"));
node->setRadialAccel(intValFromDict(props, "radialAccel"));
node->setRadialAccelVar(intValFromDict(props, "radialAccelVar"));
}
else
{
node->setStartRadius(intValFromDict(props, "startRadius"));
node->setStartRadiusVar(intValFromDict(props, "startRadiusVar"));
node->setEndRadius(intValFromDict(props, "endRadius"));
node->setEndRadiusVar(intValFromDict(props, "endRadiusVar"));
node->setRotatePerSecond(intValFromDict(props, "rotatePerSecond"));
node->setRotatePerSecondVar(intValFromDict(props, "rotatePerSecondVar"));
}
if (extraProps)
{
setExtraProp(props->objectForKey("spriteFile"), "spriteFile", node->getTag(), extraProps);
}
node->setPositionType(kCCPositionTypeGrouped);
}
void CCBReader::setPropsForLayerGradient(CCLayerGradient* node, CCDictionary* props, CCDictionary* extraProps)
{
node->setStartColor(ccColor3ValFromDict(props, "color"));
node->setStartOpacity(intValFromDict(props, "opacity"));
node->setEndColor(ccColor3ValFromDict(props, "endColor"));
node->setEndOpacity(intValFromDict(props, "endOpacity"));
node->setVector(pointValFromDict(props, "vector"));
}
CCNode* CCBReader::createCustomClassWithName(CCString* className)
{
CCNode* pRetVal = NULL;
if (className && className->length())
{
CCBCustomClassProtocol* pNewClass = CCBCustomClassFactory::sharedFactory()->createCustomClassWithName(className->getCString());
pRetVal = dynamic_cast<CCNode*>(pNewClass);
}
return pRetVal;
}
void CCBReader::setPropsForSprite(CCSprite* node, CCDictionary* props, CCDictionary* extraProps)
{
node->setOpacity(intValFromDict(props, "opacity"));
node->setColor(ccColor3ValFromDict(props, "color"));
node->setFlipX(boolValFromDict(props, "flipX"));
node->setFlipY(boolValFromDict(props, "flipY"));
node->setBlendFunc(blendFuncValFromDict(props, "blendFunc"));
if (extraProps)
{
setExtraProp(props->objectForKey("spriteFile"), "spriteFile", node->getTag(), extraProps);
CCString* spriteFramesFile = (CCString*) props->objectForKey("spriteFramesFile");
if (spriteFramesFile)
{
setExtraProp(spriteFramesFile, "spriteSheetFile", node->getTag(), extraProps);
}
}
}
void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary* extraProps)
{
CCPoint position = pointValFromDict(props, "position");
node->setPosition(position);
if (dynamic_cast<CCSprite*>(node) == NULL &&
dynamic_cast<CCMenuItemImage*>(node) == NULL &&
dynamic_cast<CCLabelBMFont*>(node) == NULL)
{
CCSize size = sizeValFromDict(props, "contentSize");
//node->setContentSize(size);
}
node->setScaleX(floatValFromDict(props, "scaleX"));
node->setScaleY(floatValFromDict(props, "scaleY"));
node->setAnchorPoint(pointValFromDict(props, "anchorPoint"));
node->setRotation(floatValFromDict(props, "rotation"));
node->setIsRelativeAnchorPoint(boolValFromDict(props, "isRelativeAnchorPoint"));
node->setIsVisible(boolValFromDict(props, "visible"));
if (extraProps)
{
if (node->getTag() == -1)
{
node->setTag(extraProps->count() + 1);
}
setExtraProp(props->objectForKey("tag"), "tag", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("customClass"), "customClass", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentType"), "memberVarAssignmentType", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentName"), "memberVarAssignmentName", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("lockedScaleRatio"), "lockedScaleRatio", node->getTag(), extraProps);
// Expanded nodes
bool isExpanded;
CCString* isExpandedObj = (CCString*) props->objectForKey("isExpanded");
if (isExpandedObj) {
isExpanded = !isExpandedObj->m_sString.empty();
} else {
isExpanded = true;
}
setExtraProp(isExpandedObj, "isExpanded", node->getTag(), extraProps);
}
else
{
node->setTag(intValFromDict(props, "tag"));
}
}
CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extraProps,
const char* assetsDir, CCNode* owner, CCNode* root)
{
CCString* className = (CCString*) dict->objectForKey("class");
CCDictionary* props = (CCDictionary*) dict->objectForKey("properties");
CCArray* children = (CCArray*) dict->objectForKey("children");
CCString* customClass = (CCString*)props->objectForKey("customClass");
if (extraProps) customClass = NULL;
CCNode* node = NULL;
if (className->m_sString.compare("CCParticleSystem") == 0)
{
CCString* spriteFile = new CCString(assetsDir);
spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString;
CCParticleSystem* sys = new CCParticleSystemQuad();
sys->initWithTotalParticles(2048);
sys->setTexture(CCTextureCache::sharedTextureCache()->addImage(spriteFile->m_sString.c_str()));
delete spriteFile;
node = (CCNode*)sys;
setPropsForNode((CCNode*)node, (CCDictionary*) props, extraProps);
setPropsForParticleSystem((CCParticleSystem*) node, (CCDictionary*) props, extraProps);
}
else if (className->m_sString.compare("CCMenuItemImage") == 0)
{
CCString* spriteFileNormal = new CCString(assetsDir);
spriteFileNormal->m_sString += ((CCString*)props->objectForKey("spriteFileNormal"))->getCString();
CCString* spriteFileSelected = new CCString(assetsDir);
spriteFileSelected->m_sString += ((CCString*)props->objectForKey("spriteFileSelected"))->getCString();
CCString* spriteFileDisabled = new CCString(assetsDir);
spriteFileDisabled->m_sString += ((CCString*)props->objectForKey("spriteFileDisabled"))->getCString();
CCSprite* spriteNormal = NULL;
CCSprite* spriteSelected = NULL;
CCSprite* spriteDisabled = NULL;
CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile");
if (spriteSheetFile && !spriteSheetFile->length()) {
spriteSheetFile->m_sString.insert(0, assetsDir);
}
if (spriteSheetFile && !spriteSheetFile->length())
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(spriteSheetFile->m_sString.c_str());
spriteNormal = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileNormal"))->getCString());
spriteSelected = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileSelected"))->getCString());
spriteDisabled = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileDisabled"))->getCString());
// TBD: how to defense if exception raise here?
}
else
{
spriteNormal = CCSprite::spriteWithFile(spriteFileNormal->m_sString.c_str());
spriteSelected = CCSprite::spriteWithFile(spriteFileSelected->m_sString.c_str());
spriteDisabled = CCSprite::spriteWithFile(spriteFileDisabled->m_sString.c_str());
}
//deallocate
CC_SAFE_DELETE(spriteFileNormal);
CC_SAFE_DELETE(spriteFileSelected);
CC_SAFE_DELETE(spriteFileDisabled);
if (!spriteNormal) spriteNormal = CCSprite::spriteWithFile("missing-texture.png");
if (!spriteSelected) spriteSelected = CCSprite::spriteWithFile("missing-texture.png");
if (!spriteDisabled) spriteDisabled = CCSprite::spriteWithFile("missing-texture.png");
CCNode *target = NULL ;
if ( extraProps == NULL )
{
int targetType = ((CCString*)(props->objectForKey("target")))->intValue() ;
if ( targetType == kCCBMemberVarAssignmentTypeDocumentRoot )
target = (CCNode*)root ;
else if ( targetType == kCCBMemberVarAssignmentTypeOwner )
target = (CCNode*)owner ;
}
CCString *selectorName = (CCString*)props->objectForKey("selector") ;
SEL_MenuHandler sel = NULL;
if ( selectorName->length() )
{
sel = dynamic_cast<CCBCustomClassProtocol*>(target)->callbackGetSelectors(selectorName->getCString());
}
else
{
CCLOG("WARNING! CCMenuItemImage target doesn't respond to selector %@",selectorName) ;
target = NULL ;
}
node = (CCNode*)CCMenuItemImage::itemWithNormalSprite((CCNode*) spriteNormal, (CCNode*) spriteSelected, (CCNode*) spriteDisabled, target, sel);
setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForMenuItem((CCMenuItem*) node, (CCDictionary*) props, extraProps);
setPropsForMenuItemImage((CCMenuItemImage*) node, (CCDictionary*) props, extraProps);
}
else if (className->m_sString.compare("CCMenu") == 0)
{
node = (CCNode*)CCMenu::menuWithItems(NULL);
setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForLayer((CCLayer*) node, (CCDictionary*) props, extraProps);
setPropsForMenu((CCMenu*)node, (CCDictionary*) props, extraProps);
}
else if (className->m_sString.compare("CCLabelBMFont") == 0)
{
CCString* fontFile = new CCString(assetsDir);
fontFile->m_sString += ((CCString*)props->objectForKey("fontFile"))->m_sString;
CCString* stringText = ((CCString*)props->objectForKey("string"));
node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(),
fontFile->m_sString.c_str() );
delete fontFile;
fontFile = 0;
if (!node) node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(), "missing-font.fnt");
setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForLabelBMFont((CCLabelBMFont*) node, (CCDictionary*) props, extraProps);
}
else if (className->m_sString.compare("CCSprite") == 0)
{
CCString* spriteFile = new CCString(assetsDir);
spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString;
CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile");
if (spriteSheetFile && !spriteSheetFile->length())
{
spriteSheetFile->m_sString.insert(0, assetsDir);
}
if (spriteSheetFile && !spriteSheetFile->length())
{
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(spriteSheetFile->m_sString.c_str());
node = (CCNode*)CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFile"))->m_sString.c_str());
// TBD: how to defense if exception raise here?
}
else
{
printf("spriteFile->m_string.cstr is %s\n", spriteFile->m_sString.c_str()) ;
node = (CCNode*)CCSprite::spriteWithFile(spriteFile->m_sString.c_str());
}
CC_SAFE_RELEASE_NULL(spriteFile);
if (!node) node = (CCNode*)CCSprite::spriteWithFile("missing-texture.png");
setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForSprite((CCSprite*) node, (CCDictionary*) props, extraProps);
}
else if (className->m_sString.compare("CCLayerGradient") == 0)
{
node = (CCNode*)createCustomClassWithName(customClass) ;
if (node)
{
if (dynamic_cast<CCLayerGradient*>(node) == NULL)
{
CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node;
node = NULL;
}
}
else
{
node = (CCNode*)CCLayerGradient::node();
}
setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForLayer((CCLayer*) node, (CCDictionary*) props, extraProps);
setPropsForLayerColor((CCLayerColor*) node, (CCDictionary*) props, extraProps);
setPropsForLayerGradient((CCLayerGradient*) node, (CCDictionary*) props, extraProps);
}
else if (className->m_sString.compare("CCLayerColor") == 0)
{
node = (CCNode*)createCustomClassWithName(customClass) ;
if (node)
{
if (dynamic_cast<CCLayerColor*>(node) == NULL)
{
CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node;
node = NULL;
}
}
else
{
node = (CCNode*)CCLayerColor::node();
}
setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForLayer((CCLayer*) node, (CCDictionary*) props, extraProps);
setPropsForLayerColor((CCLayerColor*) node, (CCDictionary*) props, extraProps);
}
else if (className->m_sString.compare("CCLayer") == 0)
{
node = (CCNode*)createCustomClassWithName(customClass) ;
if (node)
{
if (dynamic_cast<CCLayer*>(node) == NULL)
{
CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node;
node = NULL;
}
}
else
{
node = (CCNode*)CCLayer::node();
}
setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForLayer((CCLayer*) node, (CCDictionary*) props, extraProps);
}
else if (className->m_sString.compare("CCNode") == 0)
{
node = (CCNode*)createCustomClassWithName(customClass) ;
if (node)
{
if (dynamic_cast<CCNode*>(node) == NULL)
{
CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node;
node = NULL;
}
}
else
{
node = (CCNode*)CCNode::node();
}
setPropsForNode(node, (CCDictionary*) props, extraProps);
}
else
{
CCLOG("WARNING! Class of type %@ couldn't be found", className);
return NULL;
}
if (!root) root = node;
// Add children
for (unsigned int i = 0; i < children->count(); i++)
{
CCDictionary* childDict = (CCDictionary*) children->objectAtIndex(i);
CCNode* child = ccObjectFromDictionary(childDict, extraProps, assetsDir, owner, root);
int zOrder = intValFromDict((CCDictionary*) childDict->objectForKey("properties"), "zOrder");
if (child && node)
{
node->addChild(child, zOrder);
}
else
{
CCLOG("WARNING! Failed to add child to node");
}
}
if ( !extraProps )
{
CCString* assignmentName = (CCString*)props->objectForKey("memberVarAssignmentName");
CCLOG("assignmentName is %s", assignmentName->getCString()) ;
int assignmentType = ((CCString*)(props->objectForKey("memberVarAssignmentType")))->intValue() ;
if ( !assignmentName->m_sString.empty() &&
assignmentType)
{
CCBCustomClassProtocol* assignTo = NULL ;
if ( assignmentType == kCCBMemberVarAssignmentTypeOwner )
{
assignTo = dynamic_cast<CCBCustomClassProtocol*>(owner);
}
else if ( assignmentType == kCCBMemberVarAssignmentTypeDocumentRoot )
{
assignTo = dynamic_cast<CCBCustomClassProtocol*>(root);
}
if ( assignTo != NULL )
{
CCLOG("assign [%s]", assignmentName->getCString());
assignTo->callbackSetChildren(assignmentName->getCString(), node);
}
}
if (customClass->length())
{
CCBCustomClassProtocol* pCustom = dynamic_cast<CCBCustomClassProtocol*>(node);
if (pCustom)
{
pCustom->callbackAfterCCBLoaded();
}
}
}
return node;
}
// initialize ccbreader
CCNode* CCBReader::nodeGraphFromDictionary(CCDictionary* dict,
CCDictionary* extraProps,
const char* assetsDir,
CCNode* owner)
{
if (!dict)
{
CCLOG("WARNING! Trying to load invalid file type");
return NULL;
}
CCString* fileType = (CCString*) dict->objectForKey("fileType");
int fileVersion = ((CCString*) dict->objectForKey("fileVersion"))->intValue();
if (!fileType || fileType->m_sString.compare("CocosBuilder") != 0)
{
CCLOG("WARNING! Trying to load invalid file type");
}
if (fileVersion > 1)
{
CCLOG("WARNING! Trying to load file made with a newer version of CocosBuilder, please update the CCBReader class");
return NULL;
}
CCDictionary* nodeGraph = (CCDictionary*) dict->objectForKey("nodeGraph");
return ccObjectFromDictionary(nodeGraph, extraProps, assetsDir, owner, NULL);
}
CCNode* CCBReader::nodeGraphFromFile(const char* file, CCNode* owner)
{
CCLOG("CCBReader path is: %s", file);
std::string ccbFilePath(file);
std::string ccbFileDir;
// find ccbFileDir before "/" or "\"
// for example, if ccbFilePath = "CocosBuilder/example.ccb",
// then we should make ccbFileDir = "CocosBuilder/"
size_t lastSlash = ccbFilePath.find_last_of("/");
if (lastSlash != std::string::npos)
{
ccbFileDir = ccbFilePath.substr(0, lastSlash) + "/";
}
CCDictionary* dict = CCDictionary::dictionaryWithContentsOfFileThreadSafe(ccbFilePath.c_str());
CCAssert(dict != NULL, "CCBReader: file not found");
return nodeGraphFromDictionary(dict, NULL, ccbFileDir.c_str(), owner);
}

View File

@ -0,0 +1,113 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2012 XiaoLong Zhang, Chukong Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCB_READER_H__
#define __CCB_READER_H__
#include "cocos2d.h"
#include "CCBCustomClass.h"
NS_CC_EXT_BEGIN
/**
@brief Parse CCB file which is generated by CocosBuilder
@warning support CocosBuilder v1 currently. I will update this to v3 when CCB format is stable
*/
class CC_DLL CCBReader : public CCObject
{
public:
static CCNode* nodeGraphFromFile(const char* ccbFileName, CCNode* owner = NULL);
private:
static CCNode* nodeGraphFromDictionary(CCDictionary* dict,
CCDictionary* extraProps,
const char* ccbFilePath,
CCNode* owner);
static CCNode* createCustomClassWithName(CCString* className);
static CCNode* ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extraProps,
const char* assetsDir, CCNode* owner, CCNode* root);
// read different types of values from dict
static int intValFromDict(CCDictionary* dict, const std::string key);
static float floatValFromDict(CCDictionary* dict, const std::string key);
static bool boolValFromDict(CCDictionary* dict, const std::string key);
static CCPoint pointValFromDict(CCDictionary* dict, const std::string key);
static CCSize sizeValFromDict(CCDictionary* dict, const std::string key);
static ccColor3B ccColor3ValFromDict(CCDictionary* dict,
const std::string key);
static ccColor4F ccColor4fValFromDict(CCDictionary* dict,
const std::string key);
static ccBlendFunc blendFuncValFromDict(CCDictionary* dict,
const std::string key);
private:
// set properties
static void setExtraProp(CCObject* prop, const char* key, int tag, CCDictionary* dict);
static void setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary* extraProps);
static void setPropsForSprite(CCSprite* node, CCDictionary* props,
CCDictionary* extraProps);
static void setPropsForLabelBMFont(CCLabelBMFont* node, CCDictionary* props,
CCDictionary* extraProps);
static void setPropsForParticleSystem(CCParticleSystem* node, CCDictionary* props, CCDictionary* extraProps);
static void setPropsForMenu(CCMenu* node, CCDictionary* props, CCDictionary* extraProps);
static void setPropsForMenuItem(CCMenuItem* node, CCDictionary* props, CCDictionary* extraProps);
static void setPropsForMenuItemImage(CCMenuItemImage* node, CCDictionary* props, CCDictionary* extraProps);
static void setPropsForLayer(CCLayer* node, CCDictionary* props, CCDictionary* extraProps);
static void setPropsForLayerColor(CCLayerColor* node, CCDictionary* props, CCDictionary* extraProps);
static void setPropsForLayerGradient(CCLayerGradient* node, CCDictionary* props, CCDictionary* extraProps);
private:
enum
{
kCCBMemberVarAssignmentTypeNone = 0,
kCCBMemberVarAssignmentTypeDocumentRoot = 1,
kCCBMemberVarAssignmentTypeOwner = 2,
};
}; // end of class CCBReader
NS_CC_EXT_END
#endif // __CCB_READER_H__

View File

@ -160,6 +160,8 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$
<ClCompile Include="..\cocos2d.cpp" />
<ClCompile Include="..\effects\CCGrabber.cpp" />
<ClCompile Include="..\effects\CCGrid.cpp" />
<ClCompile Include="..\extensions\CCBReader\CCBCustomClass.cpp" />
<ClCompile Include="..\extensions\CCBReader\CCBReader.cpp" />
<ClCompile Include="..\extensions\CCControlExtension\CCControl.cpp" />
<ClCompile Include="..\extensions\CCControlExtension\CCControlButton.cpp" />
<ClCompile Include="..\extensions\CCControlExtension\CCControlColourPicker.cpp" />
@ -290,6 +292,8 @@ xcopy /Y /Q "$(SolutionDir)cocos2dx\platform\third_party\win32\libraries\*.*" "$
<ClInclude Include="..\cocoa\CCZone.h" />
<ClInclude Include="..\effects\CCGrabber.h" />
<ClInclude Include="..\effects\CCGrid.h" />
<ClInclude Include="..\extensions\CCBReader\CCBCustomClass.h" />
<ClInclude Include="..\extensions\CCBReader\CCBReader.h" />
<ClInclude Include="..\extensions\CCControlExtension\CCControl.h" />
<ClInclude Include="..\extensions\CCControlExtension\CCControlButton.h" />
<ClInclude Include="..\extensions\CCControlExtension\CCControlColourPicker.h" />

View File

@ -106,6 +106,9 @@
<Filter Include="extensions\CCTextureWatcher">
<UniqueIdentifier>{772b5d31-38b2-4f19-80da-4da6c37b58c2}</UniqueIdentifier>
</Filter>
<Filter Include="extensions\CCBReader">
<UniqueIdentifier>{4647762c-52c3-475d-968a-96aa48dbcd0c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\effects\CCGrabber.cpp">
@ -480,6 +483,12 @@
<ClCompile Include="..\extensions\CCListView\CCListViewCell.cpp">
<Filter>extensions\CCListView</Filter>
</ClCompile>
<ClCompile Include="..\extensions\CCBReader\CCBCustomClass.cpp">
<Filter>extensions\CCBReader</Filter>
</ClCompile>
<ClCompile Include="..\extensions\CCBReader\CCBReader.cpp">
<Filter>extensions\CCBReader</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\effects\CCGrabber.h">
@ -970,5 +979,11 @@
<ClInclude Include="..\extensions\CCListView\CCListViewCell.h">
<Filter>extensions\CCListView</Filter>
</ClInclude>
<ClInclude Include="..\extensions\CCBReader\CCBReader.h">
<Filter>extensions\CCBReader</Filter>
</ClInclude>
<ClInclude Include="..\extensions\CCBReader\CCBCustomClass.h">
<Filter>extensions\CCBReader</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -45,6 +45,8 @@ tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTes
tests/ExtensionsTest/ControlExtensionTest/CCControlColourPicker/CCControlColourPickerTest.cpp \
tests/ExtensionsTest/ControlExtensionTest/CCControlSliderTest/CCControlSliderTest.cpp \
tests/ExtensionsTest/ControlExtensionTest/CCControlSwitchTest/CCControlSwitchTest.cpp \
tests/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.cpp \
tests/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder.cpp \
tests/FontTest/FontTest.cpp \
tests/HiResTest/HiResTest.cpp \
tests/IntervalTest/IntervalTest.cpp \

View File

@ -0,0 +1 @@
2685fbcab626d939a8e2ea65b05a8a82beb90afa

View File

@ -1 +1 @@
d1a839f74c0ea5ee4cc2a177a02afb14a4897067
031ae2d3c87a8844ac67cd65c36b6ab1fdc72ed2

View File

@ -126,6 +126,8 @@
<ClCompile Include="..\tests\ChipmunkAccelTouchTest\ChipmunkAccelTouchTest.cpp" />
<ClCompile Include="..\tests\CurrentLanguageTest\CurrentLanguageTest.cpp" />
<ClCompile Include="..\tests\DirectorTest\DirectorTest.cpp" />
<ClCompile Include="..\tests\ExtensionsTest\CocosBuilderTest\CocosBuilderTest.cpp" />
<ClCompile Include="..\tests\ExtensionsTest\CocosBuilderTest\HelloCocosBuilder.cpp" />
<ClCompile Include="..\tests\ExtensionsTest\ControlExtensionTest\CCControlButtonTest\CCControlButtonTest.cpp" />
<ClCompile Include="..\tests\ExtensionsTest\ControlExtensionTest\CCControlColourPicker\CCControlColourPickerTest.cpp" />
<ClCompile Include="..\tests\ExtensionsTest\ControlExtensionTest\CCControlScene.cpp" />
@ -204,6 +206,8 @@
<ClInclude Include="..\tests\ChipmunkAccelTouchTest\ChipmunkAccelTouchTest.h" />
<ClInclude Include="..\tests\CurrentLanguageTest\CurrentLanguageTest.h" />
<ClInclude Include="..\tests\DirectorTest\DirectorTest.h" />
<ClInclude Include="..\tests\ExtensionsTest\CocosBuilderTest\CocosBuilderTest.h" />
<ClInclude Include="..\tests\ExtensionsTest\CocosBuilderTest\HelloCocosBuilder.h" />
<ClInclude Include="..\tests\ExtensionsTest\ControlExtensionTest\CCControlButtonTest\CCControlButtonTest.h" />
<ClInclude Include="..\tests\ExtensionsTest\ControlExtensionTest\CCControlColourPicker\CCControlColourPickerTest.h" />
<ClInclude Include="..\tests\ExtensionsTest\ControlExtensionTest\CCControlScene.h" />

View File

@ -169,6 +169,9 @@
<Filter Include="classes\tests\MutiTouchTest">
<UniqueIdentifier>{5ea85c7b-9c54-4125-8b75-cf540df9cb0e}</UniqueIdentifier>
</Filter>
<Filter Include="classes\tests\ExtensionsTest\CocosBuilderTest">
<UniqueIdentifier>{2e6b7147-7836-4a98-a2f5-a00080e7ca23}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
@ -399,6 +402,12 @@
<ClCompile Include="..\tests\MutiTouchTest\MutiTouchTest.cpp">
<Filter>classes\tests\MutiTouchTest</Filter>
</ClCompile>
<ClCompile Include="..\tests\ExtensionsTest\CocosBuilderTest\CocosBuilderTest.cpp">
<Filter>classes\tests\ExtensionsTest\CocosBuilderTest</Filter>
</ClCompile>
<ClCompile Include="..\tests\ExtensionsTest\CocosBuilderTest\HelloCocosBuilder.cpp">
<Filter>classes\tests\ExtensionsTest\CocosBuilderTest</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h">
@ -743,5 +752,11 @@
<ClInclude Include="..\tests\MutiTouchTest\MutiTouchTest.h">
<Filter>classes\tests\MutiTouchTest</Filter>
</ClInclude>
<ClInclude Include="..\tests\ExtensionsTest\CocosBuilderTest\CocosBuilderTest.h">
<Filter>classes\tests\ExtensionsTest\CocosBuilderTest</Filter>
</ClInclude>
<ClInclude Include="..\tests\ExtensionsTest\CocosBuilderTest\HelloCocosBuilder.h">
<Filter>classes\tests\ExtensionsTest\CocosBuilderTest</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,42 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CocosBuilderTest.h"
#include "../../testResource.h"
#include "extensions/CCBReader/CCBReader.h"
#include "HelloCocosBuilder.h"
USING_NS_CC;
void CocosBuilderTestScene::runThisTest()
{
CCBCustomClassFactory::sharedFactory()->registCustomClass(
"HelloCocosBuilder",
HelloCocosBuilder::createInstance);
CCNode* node = CCBReader::nodeGraphFromFile("CocosBuilder/example.ccb");
this->addChild(node) ;
CCDirector::sharedDirector()->replaceScene(this);
}

View File

@ -0,0 +1,36 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef _COCOS_BUILDER_TEST_H_
#define _COCOS_BUILDER_TEST_H_
#include "../../testBasic.h"
class CocosBuilderTestScene : public TestScene
{
public:
virtual void runThisTest();
};
#endif

View File

@ -0,0 +1,96 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2012 XiaoLong Zhang, Chukong Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "HelloCocosBuilder.h"
USING_NS_CC;
HelloCocosBuilder::HelloCocosBuilder()
:m_pSpriteBurst(NULL)
,m_pSpriteIcon(NULL)
{
}
HelloCocosBuilder::~HelloCocosBuilder()
{
CC_SAFE_RELEASE_NULL(m_pSpriteBurst);
CC_SAFE_RELEASE_NULL(m_pSpriteIcon);
}
bool HelloCocosBuilder::callbackSetChildren(const char* name, CCObject* node)
{
bool bRetVal = false;
if (strcmp(name, "sprtBurst") == 0)
{
m_pSpriteBurst = dynamic_cast<CCSprite*>(node);
CC_ASSERT(m_pSpriteBurst);
m_pSpriteBurst->retain();
}
else if (strcmp(name, "sprtIcon") == 0)
{
m_pSpriteIcon = dynamic_cast<CCSprite*>(node);
CC_ASSERT(m_pSpriteIcon);
m_pSpriteIcon->retain();
}
return bRetVal;
};
void HelloCocosBuilder::callbackAfterCCBLoaded()
{
CCLOG("loading.....successed!") ;
void* act = CCRotateBy::actionWithDuration(0.5f, 10) ;
void* act1 = CCRepeatForever::actionWithAction((CCActionInterval*)act) ;
m_pSpriteBurst->runAction((CCAction*)act1) ;
}
SEL_MenuHandler HelloCocosBuilder::callbackGetSelectors(const char* selectorName)
{
if (strcmp(selectorName, "pressedButton") == 0)
{
return menu_selector(HelloCocosBuilder::pressedButton);
}
else if (strcmp(selectorName, "pressedButton2") == 0)
{
return menu_selector(HelloCocosBuilder::pressedButton2);
}
else
{
return NULL;
}
}
void HelloCocosBuilder::pressedButton(CCObject*sender)
{
m_pSpriteIcon->stopAllActions() ;
void* rotateAction = CCRotateBy::actionWithDuration(1, 360) ;
m_pSpriteIcon->runAction((CCAction*)rotateAction) ;
}
void HelloCocosBuilder::pressedButton2(CCObject*sender)
{
CCLOG("pressed successed!") ;
}

View File

@ -0,0 +1,63 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2012 XiaoLong Zhang, Chukong Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef cocos2dXReflection_HelloCocosBuilder_h
#define cocos2dXReflection_HelloCocosBuilder_h
#include "cocos2d.h"
#include "extensions/CCBReader/CCBCustomClass.h"
namespace cocos2d{
class HelloCocosBuilder : public extension::CCBCustomClassProtocol, public CCLayer
{
public:
HelloCocosBuilder();
~HelloCocosBuilder();
static extension::CCBCustomClassProtocol* createInstance()
{
return new HelloCocosBuilder() ;
}
public:
// implement 3 pure virtual methods inherited from CCBCustomClass
virtual bool callbackSetChildren(const char* name, CCObject* node);
virtual SEL_MenuHandler callbackGetSelectors(const char* selectorName);
virtual void callbackAfterCCBLoaded();
void pressedButton(CCObject*sender) ;
void pressedButton2(CCObject*sender) ;
protected:
CCSprite* m_pSpriteBurst ;
CCSprite* m_pSpriteIcon ;
} ;
}
#endif

View File

@ -2,6 +2,7 @@
#include "../testResource.h"
#include "NotificationCenterTest/NotificationCenterTest.h"
#include "ControlExtensionTest/CCControlSceneManager.h"
#include "CocosBuilderTest/CocosBuilderTest.h"
enum
{
@ -14,14 +15,16 @@ enum
TEST_NOTIFICATIONCENTER = 0,
TEST_CCCONTROLBUTTON,
TEST_TEXTUREWATCHER,
TEST_MAX_COUNT
TEST_COCOSBUILDER,
TEST_MAX_COUNT,
};
static const std::string testsName[TEST_MAX_COUNT] =
{
"NotificationCenterTest",
"CCControlButtonTest",
"TextureWatcherTest"
"TextureWatcherTest",
"CocosBuilderTest",
};
////////////////////////////////////////////////////////
@ -76,6 +79,16 @@ void ExtensionsMainLayer::menuCallback(CCObject* pSender)
CCTextureWatcher::sharedTextureWatcher()->setDisplayWatcher(s_bOpened);
}
break;
case TEST_COCOSBUILDER:
{
TestScene* pScene = new CocosBuilderTestScene();
if (pScene)
{
pScene->runThisTest();
pScene->release();
}
}
break;
default:
break;
}