2012-06-14 05:19:13 +08:00
|
|
|
#include "HelloCocosBuilderLayer.h"
|
|
|
|
|
2012-06-15 05:23:53 +08:00
|
|
|
#include "../TestHeader/TestHeaderLayerLoader.h"
|
2012-06-15 09:16:54 +08:00
|
|
|
#include "../LabelTest/LabelTestLayerLoader.h"
|
2012-06-15 05:23:53 +08:00
|
|
|
#include "../ButtonTest/ButtonTestLayerLoader.h"
|
2012-06-15 09:16:54 +08:00
|
|
|
#include "../SpriteTest/SpriteTestLayerLoader.h"
|
|
|
|
#include "../MenuTest/MenuTestLayerLoader.h"
|
2012-06-16 05:48:36 +08:00
|
|
|
#include "../ParticleSystemTest/ParticleSystemTestLayerLoader.h"
|
2012-06-19 04:59:45 +08:00
|
|
|
#include "../ScrollViewTest/ScrollViewTestLayerLoader.h"
|
2012-09-17 18:49:05 +08:00
|
|
|
#include "../AnimationsTest/AnimationsLayerLoader.h"
|
2013-03-19 16:33:23 +08:00
|
|
|
#include "../TimelineCallbackTest/TimelineCallbackLayerLoader.h"
|
2012-06-14 05:19:13 +08:00
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
USING_NS_CC_EXT;
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocosbuilder;
|
2012-06-14 05:19:13 +08:00
|
|
|
|
2012-06-19 16:31:26 +08:00
|
|
|
HelloCocosBuilderLayer::HelloCocosBuilderLayer()
|
|
|
|
: mBurstSprite(NULL)
|
|
|
|
, mTestTitleLabelTTF(NULL)
|
|
|
|
{}
|
|
|
|
|
|
|
|
HelloCocosBuilderLayer::~HelloCocosBuilderLayer()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(mBurstSprite);
|
|
|
|
CC_SAFE_RELEASE(mTestTitleLabelTTF);
|
|
|
|
}
|
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
void HelloCocosBuilderLayer::openTest(const char * pCCBFileName, const char * nodeName, NodeLoader * nodeLoader) {
|
2013-06-20 14:17:10 +08:00
|
|
|
/* Create an autorelease NodeLoaderLibrary. */
|
|
|
|
NodeLoaderLibrary * ccNodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary();
|
2012-06-14 05:19:13 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ccNodeLoaderLibrary->registerNodeLoader("TestHeaderLayer", TestHeaderLayerLoader::loader());
|
2013-07-23 08:25:44 +08:00
|
|
|
if(nodeName != NULL && nodeLoader != NULL) {
|
|
|
|
ccNodeLoaderLibrary->registerNodeLoader(nodeName, nodeLoader);
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create an autorelease CCBReader. */
|
2013-10-15 18:00:03 +08:00
|
|
|
cocosbuilder::CCBReader * ccbReader = new cocosbuilder::CCBReader(ccNodeLoaderLibrary);
|
2012-06-14 05:19:13 +08:00
|
|
|
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.
|
2013-08-16 16:05:27 +08:00
|
|
|
auto node = ccbReader->readNodeGraphFromFile(pCCBFileName, this);
|
2012-06-14 05:19:13 +08:00
|
|
|
|
|
|
|
this->mTestTitleLabelTTF->setString(pCCBFileName);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = Scene::create();
|
2012-06-14 05:19:13 +08:00
|
|
|
if(node != NULL) {
|
|
|
|
scene->addChild(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Push the new scene with a fancy transition. */
|
2013-07-05 16:49:22 +08:00
|
|
|
Color3B transitionColor;
|
2012-06-14 05:19:13 +08:00
|
|
|
transitionColor.r = 0;
|
|
|
|
transitionColor.g = 0;
|
|
|
|
transitionColor.b = 0;
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->pushScene(TransitionFade::create(0.5f, scene, transitionColor));
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void HelloCocosBuilderLayer::onNodeLoaded(cocos2d::Node * node, cocosbuilder::NodeLoader * nodeLoader) {
|
2013-08-16 16:05:27 +08:00
|
|
|
auto ccRotateBy = RotateBy::create(20.0f, 360);
|
|
|
|
auto ccRepeatForever = RepeatForever::create(ccRotateBy);
|
2012-06-14 05:19:13 +08:00
|
|
|
this->mBurstSprite->runAction(ccRepeatForever);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-24 18:17:20 +08:00
|
|
|
SEL_MenuHandler HelloCocosBuilderLayer::onResolveCCBCCMenuItemSelector(Object * pTarget, const char * pSelectorName) {
|
2012-06-14 05:19:13 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:22:45 +08:00
|
|
|
Control::Handler HelloCocosBuilderLayer::onResolveCCBCCControlSelector(Object * pTarget, const char * pSelectorName) {
|
2012-06-15 09:16:54 +08:00
|
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onMenuTestClicked", HelloCocosBuilderLayer::onMenuTestClicked);
|
|
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onSpriteTestClicked", HelloCocosBuilderLayer::onSpriteTestClicked);
|
|
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onButtonTestClicked", HelloCocosBuilderLayer::onButtonTestClicked);
|
2012-09-17 18:49:05 +08:00
|
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAnimationsTestClicked", HelloCocosBuilderLayer::onAnimationsTestClicked);
|
2012-06-15 09:16:54 +08:00
|
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onParticleSystemTestClicked", HelloCocosBuilderLayer::onParticleSystemTestClicked);
|
|
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onScrollViewTestClicked", HelloCocosBuilderLayer::onScrollViewTestClicked);
|
2013-03-19 16:33:23 +08:00
|
|
|
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onTimelineCallbackSoundClicked", HelloCocosBuilderLayer::onTimelineCallbackSoundClicked);
|
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
bool HelloCocosBuilderLayer::onAssignCCBMemberVariable(Object * pTarget, const char * pMemberVariableName, Node * pNode) {
|
|
|
|
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mBurstSprite", Sprite *, this->mBurstSprite);
|
|
|
|
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mTestTitleLabelTTF", LabelTTF *, this->mTestTitleLabelTTF);
|
2012-06-15 09:16:54 +08:00
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
bool HelloCocosBuilderLayer::onAssignCCBCustomProperty(Object* pTarget, const char* pMemberVariableName, const Value& pCCBValue)
|
2013-01-21 18:37:17 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
if (pTarget == this)
|
|
|
|
{
|
|
|
|
if (0 == strcmp(pMemberVariableName, "mCustomPropertyInt"))
|
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
this->mCustomPropertyInt = pCCBValue.asInt();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("mCustomPropertyInt = %d", mCustomPropertyInt);
|
2013-01-21 18:37:17 +08:00
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
else if ( 0 == strcmp(pMemberVariableName, "mCustomPropertyFloat"))
|
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
this->mCustomPropertyFloat = pCCBValue.asFloat();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("mCustomPropertyFloat = %f", mCustomPropertyFloat);
|
2013-01-21 18:37:17 +08:00
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
else if ( 0 == strcmp(pMemberVariableName, "mCustomPropertyBoolean"))
|
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
this->mCustomPropertyBoolean = pCCBValue.asBool();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("mCustomPropertyBoolean = %d", mCustomPropertyBoolean);
|
2013-01-21 18:37:17 +08:00
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
else if ( 0 == strcmp(pMemberVariableName, "mCustomPropertyString"))
|
|
|
|
{
|
2013-12-09 17:45:24 +08:00
|
|
|
this->mCustomPropertyString = pCCBValue.asString();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("mCustomPropertyString = %s", mCustomPropertyString.c_str());
|
2013-01-21 18:37:17 +08:00
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
2012-06-14 05:19:13 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void HelloCocosBuilderLayer::onMenuTestClicked(Object * sender, Control::EventType pControlEvent) {
|
2012-09-19 17:43:11 +08:00
|
|
|
this->openTest("ccb/ccb/TestMenus.ccbi", "TestMenusLayer", MenuTestLayerLoader::loader());
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void HelloCocosBuilderLayer::onSpriteTestClicked(Object * sender, Control::EventType pControlEvent) {
|
2012-09-19 17:43:11 +08:00
|
|
|
this->openTest("ccb/ccb/TestSprites.ccbi", "TestSpritesLayer", SpriteTestLayerLoader::loader());
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void HelloCocosBuilderLayer::onButtonTestClicked(Object * sender, Control::EventType pControlEvent) {
|
2012-09-19 17:43:11 +08:00
|
|
|
this->openTest("ccb/ccb/TestButtons.ccbi", "TestButtonsLayer", ButtonTestLayerLoader::loader());
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void HelloCocosBuilderLayer::onAnimationsTestClicked(Object * sender, Control::EventType pControlEvent) {
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
/* Create an autorelease NodeLoaderLibrary. */
|
|
|
|
NodeLoaderLibrary * ccNodeLoaderLibrary = NodeLoaderLibrary::newDefaultNodeLoaderLibrary();
|
2012-09-17 18:49:05 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ccNodeLoaderLibrary->registerNodeLoader("TestHeaderLayer", TestHeaderLayerLoader::loader());
|
|
|
|
ccNodeLoaderLibrary->registerNodeLoader("TestAnimationsLayer", AnimationsTestLayerLoader::loader());
|
2012-09-17 18:49:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Create an autorelease CCBReader. */
|
2013-10-15 18:00:03 +08:00
|
|
|
cocosbuilder::CCBReader * ccbReader = new cocosbuilder::CCBReader(ccNodeLoaderLibrary);
|
2012-09-17 18:49:05 +08:00
|
|
|
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.
|
2013-08-16 16:05:27 +08:00
|
|
|
auto animationsTest = ccbReader->readNodeGraphFromFile("ccb/ccb/TestAnimations.ccbi", this);
|
2013-06-20 14:17:10 +08:00
|
|
|
// Load node graph (TestAnimations is a sub class of Layer) and retrieve the ccb action manager
|
2012-11-27 10:26:40 +08:00
|
|
|
((AnimationsTestLayer*)animationsTest)->setAnimationManager(ccbReader->getAnimationManager());
|
2012-09-17 18:49:05 +08:00
|
|
|
|
|
|
|
this->mTestTitleLabelTTF->setString("TestAnimations.ccbi");
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = Scene::create();
|
2012-09-17 18:49:05 +08:00
|
|
|
if(animationsTest != NULL) {
|
|
|
|
scene->addChild(animationsTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Push the new scene with a fancy transition. */
|
2013-07-05 16:49:22 +08:00
|
|
|
Color3B transitionColor;
|
2012-09-17 18:49:05 +08:00
|
|
|
transitionColor.r = 0;
|
|
|
|
transitionColor.g = 0;
|
|
|
|
transitionColor.b = 0;
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->pushScene(TransitionFade::create(0.5f, scene, transitionColor));
|
2012-09-17 18:49:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
//this->openTest("TestAnimations.ccbi", "TestAnimationsLayer", AnimationsTestLayerLoader::loader());
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void HelloCocosBuilderLayer::onParticleSystemTestClicked(Object * sender, Control::EventType pControlEvent) {
|
2012-09-19 17:43:11 +08:00
|
|
|
this->openTest("ccb/ccb/TestParticleSystems.ccbi", "TestParticleSystemsLayer", ParticleSystemTestLayerLoader::loader());
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void HelloCocosBuilderLayer::onScrollViewTestClicked(Object * sender, Control::EventType pControlEvent)
|
2012-09-19 17:43:11 +08:00
|
|
|
{
|
|
|
|
this->openTest("ccb/ccb/TestScrollViews.ccbi", "TestScrollViewsLayer", ScrollViewTestLayerLoader::loader());
|
2013-03-19 16:33:23 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void HelloCocosBuilderLayer::onTimelineCallbackSoundClicked(Object * sender, Control::EventType pControlEvent)
|
2013-03-19 16:33:23 +08:00
|
|
|
{
|
|
|
|
this->openTest("ccb/ccb/TestTimelineCallback.ccbi", "TimelineCallbackTestLayer", TimelineCallbackTestLayerLoader::loader());
|
|
|
|
}
|