2014-01-15 09:22:45 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies 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.
|
|
|
|
****************************************************************************/
|
2013-06-07 08:12:28 +08:00
|
|
|
|
|
|
|
#include "BaseTest.h"
|
|
|
|
#include "VisibleRect.h"
|
|
|
|
#include "testResource.h"
|
2014-02-20 21:49:13 +08:00
|
|
|
#include "AppDelegate.h"
|
2013-06-07 08:12:28 +08:00
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
|
|
|
|
void BaseTest::onEnter()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2014-02-20 21:49:13 +08:00
|
|
|
AppDelegate* app = (AppDelegate *)Application::getInstance();
|
|
|
|
app->setCurrentTest(this);
|
2013-06-07 08:12:28 +08:00
|
|
|
// add title and subtitle
|
|
|
|
std::string str = title();
|
|
|
|
const char * pTitle = str.c_str();
|
2014-03-26 23:33:58 +08:00
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 32);
|
|
|
|
auto label = Label::createWithTTF(ttfConfig,pTitle);
|
2013-07-07 21:08:14 +08:00
|
|
|
addChild(label, 9999);
|
2014-08-28 11:41:18 +08:00
|
|
|
label->setPosition(VisibleRect::center().x, VisibleRect::top().y - 30);
|
2013-06-07 08:12:28 +08:00
|
|
|
|
|
|
|
std::string strSubtitle = subtitle();
|
|
|
|
if( ! strSubtitle.empty() )
|
|
|
|
{
|
2014-03-26 23:33:58 +08:00
|
|
|
ttfConfig.fontFilePath = "fonts/Thonburi.ttf";
|
|
|
|
ttfConfig.fontSize = 16;
|
|
|
|
auto l = Label::createWithTTF(ttfConfig,strSubtitle.c_str());
|
2013-07-07 21:08:14 +08:00
|
|
|
addChild(l, 9999);
|
2014-08-28 11:41:18 +08:00
|
|
|
l->setPosition(VisibleRect::center().x, VisibleRect::top().y - 60);
|
2013-06-07 08:12:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// add menu
|
2013-06-14 11:36:43 +08:00
|
|
|
// CC_CALLBACK_1 == std::bind( function_ptr, instance, std::placeholders::_1, ...)
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(BaseTest::backCallback, this) );
|
|
|
|
auto item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(BaseTest::restartCallback, this) );
|
|
|
|
auto item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(BaseTest::nextCallback, this) );
|
2013-06-07 08:12:28 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item1, item2, item3, nullptr);
|
2013-06-07 08:12:28 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2::ZERO);
|
2014-08-28 11:41:18 +08:00
|
|
|
item1->setPosition(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2);
|
|
|
|
item2->setPosition(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2);
|
|
|
|
item3->setPosition(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2);
|
2013-06-07 08:12:28 +08:00
|
|
|
|
2013-07-07 21:08:14 +08:00
|
|
|
addChild(menu, 9999);
|
2013-06-07 08:12:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseTest::onExit()
|
|
|
|
{
|
2014-02-20 21:49:13 +08:00
|
|
|
AppDelegate* app = (AppDelegate *)Application::getInstance();
|
2014-04-09 22:53:59 +08:00
|
|
|
app->setCurrentTest(nullptr);
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onExit();
|
2013-06-07 08:12:28 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string BaseTest::title() const
|
2013-06-07 08:12:28 +08:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string BaseTest::subtitle() const
|
2013-06-07 08:12:28 +08:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void BaseTest::restartCallback(Ref* sender)
|
2013-06-07 08:12:28 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("override restart!");
|
2013-06-07 08:12:28 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void BaseTest::nextCallback(Ref* sender)
|
2013-06-07 08:12:28 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("override next!");
|
2013-06-07 08:12:28 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void BaseTest::backCallback(Ref* sender)
|
2013-06-07 08:12:28 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("override back!");
|
2013-06-07 08:12:28 +08:00
|
|
|
}
|