axmol/samples/Cpp/TestCpp/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp

107 lines
4.5 KiB
C++
Raw Normal View History

2012-04-16 18:58:43 +08:00
/*
* CCControlScene.m
*
* Copyright (c) 2011 Yannick Loriot
*
* 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 "CCControlScene.h"
#include "CCControlSceneManager.h"
#include "../ExtensionsTest.h"
2012-04-16 18:58:43 +08:00
CCControlScene::CCControlScene()
: m_pSceneTitleLabel(NULL)
{
}
CCControlScene::~CCControlScene()
{
CC_SAFE_RELEASE_NULL(m_pSceneTitleLabel);
}
bool CCControlScene::init()
{
if (CCLayer::init())
{
CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", std::bind( &CCControlScene::toExtensionsMainLayer, this, std::placeholders::_1));
pBackItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL);
pBackMenu->setPosition( CCPointZero );
addChild(pBackMenu, 10);
2012-04-16 18:58:43 +08:00
// Add the generated background
CCSprite *background = CCSprite::create("extensions/background.png");
background->setPosition(VisibleRect::center());
2012-04-16 18:58:43 +08:00
addChild(background);
// Add the ribbon
CCScale9Sprite *ribbon = CCScale9Sprite::create("extensions/ribbon.png", CCRectMake(1, 1, 48, 55));
ribbon->setContentSize(CCSizeMake(VisibleRect::getVisibleRect().size.width, 57));
ribbon->setPosition(ccp(VisibleRect::center().x, VisibleRect::top().y - ribbon->getContentSize().height / 2.0f));
2012-04-16 18:58:43 +08:00
addChild(ribbon);
// Add the title
setSceneTitleLabel(CCLabelTTF::create("Title", "Arial", 12));
m_pSceneTitleLabel->setPosition(ccp (VisibleRect::center().x, VisibleRect::top().y - m_pSceneTitleLabel->getContentSize().height / 2 - 5));
2012-04-16 18:58:43 +08:00
addChild(m_pSceneTitleLabel, 1);
// Add the menu
CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", std::bind( &CCControlScene::previousCallback, this, std::placeholders::_1));
CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", std::bind( &CCControlScene::restartCallback, this, std::placeholders::_1));
CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", std::bind( &CCControlScene::nextCallback, this, std::placeholders::_1));
2012-04-16 18:58:43 +08:00
CCMenu *menu = CCMenu::create(item1, item3, item2, NULL);
2012-04-16 18:58:43 +08:00
menu->setPosition(CCPointZero);
item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
2012-04-16 18:58:43 +08:00
addChild(menu ,1);
2012-04-16 18:58:43 +08:00
return true;
}
return false;
}
void CCControlScene::toExtensionsMainLayer(CCObject* sender)
{
ExtensionsTestScene* pScene = new ExtensionsTestScene();
pScene->runThisTest();
pScene->release();
}
2012-04-16 23:16:03 +08:00
void CCControlScene::previousCallback(CCObject* sender)
2012-04-16 18:58:43 +08:00
{
CCDirector::sharedDirector()->replaceScene(CCControlSceneManager::sharedControlSceneManager()->previousControlScene());
}
2012-04-16 23:16:03 +08:00
void CCControlScene::restartCallback(CCObject* sender)
2012-04-16 18:58:43 +08:00
{
CCDirector::sharedDirector()->replaceScene(CCControlSceneManager::sharedControlSceneManager()->currentControlScene());
}
2012-04-16 23:16:03 +08:00
void CCControlScene::nextCallback(CCObject* sender)
2012-04-16 18:58:43 +08:00
{
CCDirector::sharedDirector()->replaceScene(CCControlSceneManager::sharedControlSceneManager()->nextControlScene());
}