mirror of https://github.com/axmolengine/axmol.git
151 lines
6.5 KiB
C++
151 lines
6.5 KiB
C++
#include "HelloCocosBuilderLayer.h"
|
|
|
|
#include "../TestHeader/TestHeaderLayerLoader.h"
|
|
#include "../LabelTest/LabelTestLayerLoader.h"
|
|
#include "../ButtonTest/ButtonTestLayerLoader.h"
|
|
#include "../SpriteTest/SpriteTestLayerLoader.h"
|
|
#include "../MenuTest/MenuTestLayerLoader.h"
|
|
#include "../ParticleSystemTest/ParticleSystemTestLayerLoader.h"
|
|
#include "../ScrollViewTest/ScrollViewTestLayerLoader.h"
|
|
#include "../AnimationsTest/AnimationsLayerLoader.h"
|
|
|
|
USING_NS_CC;
|
|
USING_NS_CC_EXT;
|
|
|
|
HelloCocosBuilderLayer::HelloCocosBuilderLayer()
|
|
: mBurstSprite(NULL)
|
|
, mTestTitleLabelTTF(NULL)
|
|
{}
|
|
|
|
HelloCocosBuilderLayer::~HelloCocosBuilderLayer()
|
|
{
|
|
CC_SAFE_RELEASE(mBurstSprite);
|
|
CC_SAFE_RELEASE(mTestTitleLabelTTF);
|
|
}
|
|
|
|
void HelloCocosBuilderLayer::openTest(const char * pCCBFileName, const char * pCCNodeName, CCNodeLoader * pCCNodeLoader) {
|
|
/* Create an autorelease CCNodeLoaderLibrary. */
|
|
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
|
|
|
|
ccNodeLoaderLibrary->registerCCNodeLoader("TestHeaderLayer", TestHeaderLayerLoader::loader());
|
|
if(pCCNodeName != NULL && pCCNodeLoader != NULL) {
|
|
ccNodeLoaderLibrary->registerCCNodeLoader(pCCNodeName, pCCNodeLoader);
|
|
}
|
|
|
|
/* Create an autorelease CCBReader. */
|
|
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
|
|
ccbReader->autorelease();
|
|
|
|
/* Read a ccbi file. */
|
|
// Load the scene from the ccbi-file, setting this class as
|
|
// the owner will cause lblTestTitle to be set by the CCBReader.
|
|
// lblTestTitle is in the TestHeader.ccbi, which is referenced
|
|
// from each of the test scenes.
|
|
CCNode * node = ccbReader->readNodeGraphFromFile(pCCBFileName, this);
|
|
|
|
this->mTestTitleLabelTTF->setString(pCCBFileName);
|
|
|
|
CCScene * scene = CCScene::create();
|
|
if(node != NULL) {
|
|
scene->addChild(node);
|
|
}
|
|
|
|
/* Push the new scene with a fancy transition. */
|
|
ccColor3B transitionColor;
|
|
transitionColor.r = 0;
|
|
transitionColor.g = 0;
|
|
transitionColor.b = 0;
|
|
|
|
CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5f, scene, transitionColor));
|
|
}
|
|
|
|
|
|
void HelloCocosBuilderLayer::onNodeLoaded(cocos2d::CCNode * pNode, cocos2d::extension::CCNodeLoader * pNodeLoader) {
|
|
CCRotateBy * ccRotateBy = CCRotateBy::create(20.0f, 360);
|
|
CCRepeatForever * ccRepeatForever = CCRepeatForever::create(ccRotateBy);
|
|
this->mBurstSprite->runAction(ccRepeatForever);
|
|
}
|
|
|
|
|
|
SEL_MenuHandler HelloCocosBuilderLayer::onResolveCCBCCMenuItemSelector(CCObject * pTarget, const char * pSelectorName) {
|
|
return NULL;
|
|
}
|
|
|
|
SEL_CCControlHandler HelloCocosBuilderLayer::onResolveCCBCCControlSelector(CCObject * pTarget, const char * pSelectorName) {
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onMenuTestClicked", HelloCocosBuilderLayer::onMenuTestClicked);
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onSpriteTestClicked", HelloCocosBuilderLayer::onSpriteTestClicked);
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onButtonTestClicked", HelloCocosBuilderLayer::onButtonTestClicked);
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAnimationsTestClicked", HelloCocosBuilderLayer::onAnimationsTestClicked);
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onParticleSystemTestClicked", HelloCocosBuilderLayer::onParticleSystemTestClicked);
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onScrollViewTestClicked", HelloCocosBuilderLayer::onScrollViewTestClicked);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
bool HelloCocosBuilderLayer::onAssignCCBMemberVariable(CCObject * pTarget, const char * pMemberVariableName, CCNode * pNode) {
|
|
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mBurstSprite", CCSprite *, this->mBurstSprite);
|
|
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mTestTitleLabelTTF", CCLabelTTF *, this->mTestTitleLabelTTF);
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
void HelloCocosBuilderLayer::onMenuTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
|
this->openTest("ccb/ccb/TestMenus.ccbi", "TestMenusLayer", MenuTestLayerLoader::loader());
|
|
}
|
|
|
|
void HelloCocosBuilderLayer::onSpriteTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
|
this->openTest("ccb/ccb/TestSprites.ccbi", "TestSpritesLayer", SpriteTestLayerLoader::loader());
|
|
}
|
|
|
|
void HelloCocosBuilderLayer::onButtonTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
|
this->openTest("ccb/ccb/TestButtons.ccbi", "TestButtonsLayer", ButtonTestLayerLoader::loader());
|
|
}
|
|
|
|
void HelloCocosBuilderLayer::onAnimationsTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
|
|
|
/* Create an autorelease CCNodeLoaderLibrary. */
|
|
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
|
|
|
|
ccNodeLoaderLibrary->registerCCNodeLoader("TestHeaderLayer", TestHeaderLayerLoader::loader());
|
|
ccNodeLoaderLibrary->registerCCNodeLoader("TestAnimationsLayer", AnimationsTestLayerLoader::loader());
|
|
|
|
|
|
/* Create an autorelease CCBReader. */
|
|
cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
|
|
ccbReader->autorelease();
|
|
|
|
/* Read a ccbi file. */
|
|
// Load the scene from the ccbi-file, setting this class as
|
|
// the owner will cause lblTestTitle to be set by the CCBReader.
|
|
// lblTestTitle is in the TestHeader.ccbi, which is referenced
|
|
// from each of the test scenes.
|
|
CCNode *animationsTest = ccbReader->readNodeGraphFromFile("ccb/ccb/TestAnimations.ccbi", this);
|
|
|
|
this->mTestTitleLabelTTF->setString("TestAnimations.ccbi");
|
|
|
|
CCScene * scene = CCScene::create();
|
|
if(animationsTest != NULL) {
|
|
scene->addChild(animationsTest);
|
|
}
|
|
|
|
/* Push the new scene with a fancy transition. */
|
|
ccColor3B transitionColor;
|
|
transitionColor.r = 0;
|
|
transitionColor.g = 0;
|
|
transitionColor.b = 0;
|
|
|
|
CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5f, scene, transitionColor));
|
|
|
|
|
|
//this->openTest("TestAnimations.ccbi", "TestAnimationsLayer", AnimationsTestLayerLoader::loader());
|
|
}
|
|
|
|
void HelloCocosBuilderLayer::onParticleSystemTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) {
|
|
this->openTest("ccb/ccb/TestParticleSystems.ccbi", "TestParticleSystemsLayer", ParticleSystemTestLayerLoader::loader());
|
|
}
|
|
|
|
void HelloCocosBuilderLayer::onScrollViewTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent)
|
|
{
|
|
this->openTest("ccb/ccb/TestScrollViews.ccbi", "TestScrollViewsLayer", ScrollViewTestLayerLoader::loader());
|
|
} |