axmol/samples/Cpp/TestCpp/Classes/ExtensionsTest/CocoStudioGUITest/UIScene.cpp

112 lines
3.3 KiB
C++
Raw Normal View History

2013-09-16 20:54:13 +08:00
#include "extensions/cocos-ext.h"
2013-09-16 20:54:13 +08:00
#include "UIScene.h"
#include "UISceneManager.h"
2013-09-17 21:19:04 +08:00
#include "../ExtensionsTest.h"
2013-11-06 16:04:06 +08:00
#include "editor-support/cocostudio/CCSGUIReader.h"
2013-12-23 15:35:35 +08:00
#include "CocosGUIScene.h"
2013-09-16 20:54:13 +08:00
using namespace gui;
2013-09-16 20:54:13 +08:00
UIScene::UIScene()
2013-12-23 15:35:35 +08:00
: _sceneTitle(nullptr)
, _uiLayer(nullptr)
2013-09-16 20:54:13 +08:00
{
}
UIScene::~UIScene()
{
}
bool UIScene::init()
{
if (CCLayer::init())
{
2013-12-23 15:35:35 +08:00
_uiLayer = Layer::create();
addChild(_uiLayer);
2013-09-16 20:54:13 +08:00
2013-12-23 15:35:35 +08:00
_widget = dynamic_cast<Layout*>(cocostudio::GUIReader::shareReader()->widgetFromJsonFile("cocosgui/UITest/UITest.json"));
_uiLayer->addChild(_widget);
2013-09-16 20:54:13 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
2013-09-16 20:54:13 +08:00
2013-12-23 15:35:35 +08:00
_sceneTitle = dynamic_cast<gui::Label*>(root->getChildByName("UItest"));
2013-09-16 20:54:13 +08:00
2013-12-23 15:35:35 +08:00
gui::Label* back_label = dynamic_cast<gui::Label*>(root->getChildByName("back"));
back_label->addTouchEventListener(this, toucheventselector(UIScene::toCocosGUITestScene));
Button* left_button = dynamic_cast<Button*>(root->getChildByName("left_Button"));
2013-09-16 20:54:13 +08:00
left_button->addTouchEventListener(this, toucheventselector(UIScene::previousCallback));
2013-12-23 15:35:35 +08:00
Button* middle_button = dynamic_cast<Button*>(root->getChildByName("middle_Button"));
2013-09-16 20:54:13 +08:00
middle_button->addTouchEventListener(this, toucheventselector(UIScene::restartCallback));
2013-12-23 15:35:35 +08:00
Button* right_button = dynamic_cast<Button*>(root->getChildByName("right_Button"));
2013-09-16 20:54:13 +08:00
right_button->addTouchEventListener(this, toucheventselector(UIScene::nextCallback));
2013-12-23 15:35:35 +08:00
/*
gui::Label* mainMenuLabel = gui::Label::create();
2013-09-17 21:19:04 +08:00
mainMenuLabel->setText("MainMenu");
mainMenuLabel->setFontSize(20);
mainMenuLabel->setTouchScaleChangeEnabled(true);
mainMenuLabel->setPosition(Point(430,30));
mainMenuLabel->setTouchEnabled(true);
mainMenuLabel->addTouchEventListener(this, toucheventselector(UIScene::menuCloseCallback));
2013-12-23 15:35:35 +08:00
_uiLayer->addWidget(mainMenuLabel);
*/
2013-09-17 21:19:04 +08:00
2013-09-16 20:54:13 +08:00
return true;
}
return false;
}
void UIScene::menuCloseCallback(Object* pSender, TouchEventType type)
{
if (type == TOUCH_EVENT_ENDED)
{
2013-12-23 15:35:35 +08:00
_uiLayer->removeFromParent();
2013-09-17 21:19:04 +08:00
auto scene = new ExtensionsTestScene();
scene->runThisTest();
scene->release();
2013-09-16 20:54:13 +08:00
}
}
2013-12-23 15:35:35 +08:00
void UIScene::toCocosGUITestScene(Object* sender, TouchEventType type)
{
if (type == TOUCH_EVENT_ENDED)
{
UISceneManager::purgeUISceneManager();
CocosGUITestScene* pScene = new CocosGUITestScene();
pScene->runThisTest();
pScene->release();
}
}
2013-09-16 20:54:13 +08:00
void UIScene::previousCallback(Object* sender, TouchEventType type)
{
if (type == TOUCH_EVENT_ENDED)
{
CCDirector::getInstance()->replaceScene(UISceneManager::sharedUISceneManager()->previousUIScene());
}
}
void UIScene::restartCallback(Object* sender, TouchEventType type)
{
if (type == TOUCH_EVENT_ENDED)
{
CCDirector::getInstance()->replaceScene(UISceneManager::sharedUISceneManager()->currentUIScene());
}
}
void UIScene::nextCallback(Object* sender, TouchEventType type)
{
if (type == TOUCH_EVENT_ENDED)
{
CCDirector::getInstance()->replaceScene(UISceneManager::sharedUISceneManager()->nextUIScene());
}
}