axmol/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScene_Editor.cpp

121 lines
3.2 KiB
C++
Raw Normal View History

2014-03-04 16:51:35 +08:00
#include "UIScene_Editor.h"
#include "GUIEditorTest.h"
2014-03-11 17:13:54 +08:00
#include "ui/CocosGUI.h"
2014-03-04 16:51:35 +08:00
#include "UISceneManager_Editor.h"
UIScene_Editor::UIScene_Editor()
: _sceneTitle(nullptr)
, _touchGroup(nullptr)
, _layout(nullptr)
2014-03-04 16:51:35 +08:00
{
}
UIScene_Editor::~UIScene_Editor()
{
}
2015-03-31 11:22:34 +08:00
void UIScene_Editor::onExit()
{
cocostudio::destroyCocosStudio();
2015-03-31 11:22:34 +08:00
Layer::onExit();
}
2014-03-04 16:51:35 +08:00
bool UIScene_Editor::init()
{
if (CCLayer::init())
{
_touchGroup = Layer::create();
addChild(_touchGroup);
2014-07-01 14:21:27 +08:00
//add switch
MenuItem* pLoadJsonItem = MenuItemFont::create("Switch to Windows Json Load");
MenuItem* pLoadBinaryItem = MenuItemFont::create("Switch to Windows Binary Load");
MenuItem* pLoadJsonItemCrossPlatForm = MenuItemFont::create("Switch to Cross PlatForm Json Load");
MenuItem* pLoadBinaryItemCrossPlatForm = MenuItemFont::create("Switch to Cross PlatForm Binary Load");
2014-07-01 14:21:27 +08:00
pLoadJsonItem->setTag(1);
pLoadBinaryItem->setTag(2);
pLoadJsonItemCrossPlatForm->setTag(3);
pLoadBinaryItemCrossPlatForm->setTag(4);
2014-07-01 14:21:27 +08:00
Vector<MenuItem*> array;;
array.pushBack(pLoadBinaryItem);
array.pushBack(pLoadJsonItemCrossPlatForm);
array.pushBack(pLoadBinaryItemCrossPlatForm);
array.pushBack(pLoadJsonItem);
2014-07-01 14:21:27 +08:00
MenuItemToggle *pToggleItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(UIScene_Editor::switchLoadMethod,this), array);
pToggleItem->setTag(1);
MenuItem* selectedItem = pToggleItem->getSelectedItem();
pToggleItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y - selectedItem->getContentSize().height * 3.75f));
2014-07-01 14:21:27 +08:00
Menu* pMenu =Menu::create(pToggleItem, nullptr);
2014-07-01 14:21:27 +08:00
pMenu->setPosition( Vec2::ZERO );
// addChild(pMenu, 1, 1);
2014-07-01 14:21:27 +08:00
2014-03-04 16:51:35 +08:00
return true;
}
return false;
}
2014-07-01 14:21:27 +08:00
void UIScene_Editor::switchLoadMethod(cocos2d::Ref *pSender)
{
//subclass should override this method
}
void UIScene_Editor::previousCallback(Ref* sender, Widget::TouchEventType event)
2014-03-04 16:51:35 +08:00
{
2014-05-09 11:52:51 +08:00
switch (event)
2014-03-04 16:51:35 +08:00
{
2014-05-09 11:52:51 +08:00
case Widget::TouchEventType::ENDED:
2014-03-04 16:51:35 +08:00
CCDirector::getInstance()->replaceScene(UISceneManager_Editor::sharedUISceneManager_Editor()->previousUIScene());
break;
default:
break;
}
}
void UIScene_Editor::nextCallback(Ref* sender, Widget::TouchEventType event)
2014-03-04 16:51:35 +08:00
{
2014-05-09 11:52:51 +08:00
switch (event)
2014-03-04 16:51:35 +08:00
{
2014-05-09 11:52:51 +08:00
case Widget::TouchEventType::ENDED:
2014-03-04 16:51:35 +08:00
CCDirector::getInstance()->replaceScene(UISceneManager_Editor::sharedUISceneManager_Editor()->nextUIScene());
break;
default:
break;
}
}
void UIScene_Editor::toGUIEditorTestScene(Ref* sender, Widget::TouchEventType event)
2014-03-04 16:51:35 +08:00
{
2014-05-09 11:52:51 +08:00
switch (event)
2014-03-04 16:51:35 +08:00
{
2014-05-09 11:52:51 +08:00
case Widget::TouchEventType::ENDED:
2014-03-04 16:51:35 +08:00
{
UISceneManager_Editor::sharedUISceneManager_Editor()->purge();
GUIEditorTestScene* pScene = new (std::nothrow) GUIEditorTestScene();
2014-03-04 16:51:35 +08:00
pScene->runThisTest();
pScene->release();
}
break;
default:
break;
}
}