2014-07-07 17:38:11 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CocostudioParserTest.h"
|
|
|
|
|
|
|
|
#include "CocoStudioGUITest.h"
|
2014-07-08 17:02:50 +08:00
|
|
|
#include "CocostudioParserTest/CocostudioParserJsonTest.h"
|
2014-07-07 17:38:11 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 1000,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
std::function<void(Ref* sender)> callback;
|
|
|
|
}
|
|
|
|
g_guisTests[] =
|
|
|
|
{
|
2014-07-07 18:22:16 +08:00
|
|
|
{
|
2014-07-08 17:02:50 +08:00
|
|
|
"cocostudio 1.3",
|
|
|
|
[](Ref* sender)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
CocostudioParserJsonScene* pScene = new (std::nothrow) CocostudioParserJsonScene("cocosui/UIEditorTest/cocostudio1_3/CocostudioV1_3_1.ExportJson");
|
2014-07-08 17:02:50 +08:00
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-07-07 18:22:16 +08:00
|
|
|
"cocostudio 1.4",
|
|
|
|
[](Ref* sender)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
CocostudioParserJsonScene* pScene = new (std::nothrow) CocostudioParserJsonScene("cocosui/UIEditorTest/cocostudio1_4/Cocostudio1_4_1.ExportJson");
|
2014-07-07 18:22:16 +08:00
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
},
|
2014-07-08 17:02:50 +08:00
|
|
|
{
|
|
|
|
"cocostudio 1.5",
|
|
|
|
[](Ref* sender)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
CocostudioParserJsonScene* pScene = new (std::nothrow) CocostudioParserJsonScene("cocosui/UIEditorTest/cocostudio1_5/Cocostudio1_5_1.ExportJson");
|
2014-07-08 17:02:50 +08:00
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-07-07 17:38:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]);
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CocostudioParserTestMainLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static Vec2 _curPos = Vec2::ZERO;
|
|
|
|
|
|
|
|
|
|
|
|
void CocostudioParserTestMainLayer::onEnter()
|
|
|
|
{
|
|
|
|
Layer::onEnter();
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
_itemMenu = Menu::create();
|
|
|
|
_itemMenu->setPosition( _curPos );
|
|
|
|
MenuItemFont::setFontName("fonts/arial.ttf");
|
|
|
|
MenuItemFont::setFontSize(24);
|
|
|
|
for (int i = 0; i < g_maxTests; ++i)
|
|
|
|
{
|
|
|
|
auto pItem = MenuItemFont::create(g_guisTests[i].name, g_guisTests[i].callback);
|
2014-08-28 11:41:18 +08:00
|
|
|
// pItem->setPosition(s.width / 2, s.height / 2);
|
|
|
|
pItem->setPosition(s.width / 2, s.height - (i + 1) * LINE_SPACE);
|
2014-07-07 17:38:11 +08:00
|
|
|
_itemMenu->addChild(pItem, kItemTagBasic + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(CocostudioParserTestMainLayer::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(CocostudioParserTestMainLayer::onTouchesMoved, this);
|
|
|
|
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
|
|
|
addChild(_itemMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocostudioParserTestMainLayer::onTouchesBegan(const std::vector<Touch *> &touches, cocos2d::Event *event)
|
|
|
|
{
|
|
|
|
auto touch = static_cast<Touch*>(touches[0]);
|
|
|
|
|
|
|
|
_beginPos = touch->getLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CocostudioParserTestScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CocostudioParserTestScene::onEnter()
|
|
|
|
{
|
|
|
|
CCScene::onEnter();
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20);
|
|
|
|
//#endif
|
|
|
|
MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CocostudioParserTestScene::BackCallback, this));
|
|
|
|
|
2014-07-18 10:20:37 +08:00
|
|
|
Menu* pMenu = Menu::create(pMenuItem, nullptr);
|
2014-07-07 17:38:11 +08:00
|
|
|
|
|
|
|
pMenu->setPosition( Vec2::ZERO );
|
2014-08-28 11:41:18 +08:00
|
|
|
pMenuItem->setPosition(VisibleRect::right().x - 50, VisibleRect::bottom().y + 25);
|
2014-07-07 17:38:11 +08:00
|
|
|
|
|
|
|
addChild(pMenu, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocostudioParserTestScene::runThisTest()
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
Layer* pLayer = new (std::nothrow) CocostudioParserTestMainLayer();
|
2014-07-07 17:38:11 +08:00
|
|
|
addChild(pLayer);
|
|
|
|
pLayer->release();
|
|
|
|
|
|
|
|
CCDirector::getInstance()->replaceScene(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocostudioParserTestScene::BackCallback(Ref* pSender)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
CocoStudioGUITestScene* pScene = new (std::nothrow) CocoStudioGUITestScene();
|
2014-07-07 17:38:11 +08:00
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|