2012-04-19 14:35:52 +08:00
|
|
|
#include "ExtensionsTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
#include "NotificationCenterTest/NotificationCenterTest.h"
|
|
|
|
#include "ControlExtensionTest/CCControlSceneManager.h"
|
2012-05-03 12:17:28 +08:00
|
|
|
#include "CocosBuilderTest/CocosBuilderTest.h"
|
2013-05-08 08:25:39 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN)
|
2012-08-09 10:45:11 +08:00
|
|
|
#include "NetworkTest/HttpClientTest.h"
|
2013-05-08 08:25:39 +08:00
|
|
|
#endif
|
2012-09-09 22:34:32 +08:00
|
|
|
#include "TableViewTest/TableViewTestScene.h"
|
2013-06-04 17:38:43 +08:00
|
|
|
#include "ComponentsTest/ComponentsTestScene.h"
|
2012-09-09 22:34:32 +08:00
|
|
|
|
2013-05-31 23:13:03 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
|
|
#include "NetworkTest/WebSocketTest.h"
|
|
|
|
#endif
|
|
|
|
|
2013-05-26 19:40:13 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
|
2012-08-15 14:33:56 +08:00
|
|
|
#include "EditBoxTest/EditBoxTest.h"
|
|
|
|
#endif
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 1000,
|
|
|
|
};
|
|
|
|
|
2012-05-03 10:12:00 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TEST_NOTIFICATIONCENTER = 0,
|
|
|
|
TEST_CCCONTROLBUTTON,
|
2012-05-03 12:17:28 +08:00
|
|
|
TEST_COCOSBUILDER,
|
2012-08-09 10:45:11 +08:00
|
|
|
TEST_HTTPCLIENT,
|
2013-05-31 23:13:03 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
|
|
TEST_WEBSOCKET,
|
|
|
|
#endif
|
2013-05-26 19:40:13 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
|
2012-08-15 14:33:56 +08:00
|
|
|
TEST_EDITBOX,
|
|
|
|
#endif
|
2012-09-09 22:34:32 +08:00
|
|
|
TEST_TABLEVIEW,
|
2013-06-04 17:38:43 +08:00
|
|
|
TEST_COMPONENTS,
|
2012-05-03 12:17:28 +08:00
|
|
|
TEST_MAX_COUNT,
|
2012-05-03 10:12:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const std::string testsName[TEST_MAX_COUNT] =
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
"NotificationCenterTest",
|
2012-04-27 18:47:49 +08:00
|
|
|
"CCControlButtonTest",
|
2012-05-03 12:17:28 +08:00
|
|
|
"CocosBuilderTest",
|
2013-05-08 08:25:39 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN)
|
2012-08-09 10:45:11 +08:00
|
|
|
"HttpClientTest",
|
2013-05-08 08:25:39 +08:00
|
|
|
#endif
|
2013-05-31 23:13:03 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
|
|
"WebSocketTest",
|
|
|
|
#endif
|
2013-05-26 19:40:13 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
|
2012-09-09 22:34:32 +08:00
|
|
|
"EditBoxTest",
|
2012-08-15 14:33:56 +08:00
|
|
|
#endif
|
2013-06-04 17:38:43 +08:00
|
|
|
"TableViewTest",
|
|
|
|
"ComponentsTest"
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ExtensionsMainLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2013-06-04 17:54:05 +08:00
|
|
|
|
|
|
|
static CCPoint s_tCurPos = CCPointZero;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void ExtensionsMainLayer::onEnter()
|
|
|
|
{
|
|
|
|
CCLayer::onEnter();
|
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
2013-06-04 17:54:05 +08:00
|
|
|
m_pItemMenu = CCMenu::create();
|
|
|
|
m_pItemMenu->setPosition( CCPointZero );
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItemFont::setFontName("Arial");
|
|
|
|
CCMenuItemFont::setFontSize(24);
|
2012-05-03 10:12:00 +08:00
|
|
|
for (int i = 0; i < TEST_MAX_COUNT; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont* pItem = CCMenuItemFont::create(testsName[i].c_str(), this,
|
2012-04-19 14:35:52 +08:00
|
|
|
menu_selector(ExtensionsMainLayer::menuCallback));
|
|
|
|
pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE));
|
2013-06-04 17:54:05 +08:00
|
|
|
m_pItemMenu->addChild(pItem, kItemTagBasic + i);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-04 17:54:05 +08:00
|
|
|
setTouchEnabled(true);
|
|
|
|
addChild(m_pItemMenu);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtensionsMainLayer::menuCallback(CCObject* pSender)
|
|
|
|
{
|
|
|
|
CCMenuItemFont* pItem = (CCMenuItemFont*)pSender;
|
|
|
|
int nIndex = pItem->getZOrder() - kItemTagBasic;
|
|
|
|
|
|
|
|
switch (nIndex)
|
|
|
|
{
|
2012-10-24 08:03:06 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE) // MARMALADE CHANGE: Not yet avaiable on Marmalade
|
2012-05-03 10:12:00 +08:00
|
|
|
case TEST_NOTIFICATIONCENTER:
|
|
|
|
{
|
|
|
|
runNotificationCenterTest();
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
2012-10-24 08:03:06 +08:00
|
|
|
#endif
|
2012-05-03 10:12:00 +08:00
|
|
|
case TEST_CCCONTROLBUTTON:
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCControlSceneManager* pManager = CCControlSceneManager::sharedControlSceneManager();
|
|
|
|
CCScene* pScene = pManager->currentControlScene();
|
|
|
|
CCDirector::sharedDirector()->replaceScene(pScene);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-03 12:17:28 +08:00
|
|
|
case TEST_COCOSBUILDER:
|
|
|
|
{
|
|
|
|
TestScene* pScene = new CocosBuilderTestScene();
|
|
|
|
if (pScene)
|
|
|
|
{
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-05-08 08:25:39 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE && CC_TARGET_PLATFORM != CC_PLATFORM_NACL && CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN)
|
2012-08-09 10:45:11 +08:00
|
|
|
case TEST_HTTPCLIENT:
|
2012-08-04 18:27:27 +08:00
|
|
|
{
|
2012-08-09 10:45:11 +08:00
|
|
|
runHttpClientTest();
|
2012-08-04 18:27:27 +08:00
|
|
|
}
|
2012-08-15 14:33:56 +08:00
|
|
|
break;
|
2012-10-24 08:03:06 +08:00
|
|
|
#endif
|
2013-05-31 23:13:03 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
|
|
case TEST_WEBSOCKET:
|
|
|
|
{
|
|
|
|
runWebSocketTest();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2013-05-26 19:40:13 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
|
2012-08-15 14:33:56 +08:00
|
|
|
case TEST_EDITBOX:
|
|
|
|
{
|
|
|
|
runEditBoxTest();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2012-09-09 22:34:32 +08:00
|
|
|
case TEST_TABLEVIEW:
|
|
|
|
{
|
|
|
|
runTableViewTest();
|
|
|
|
}
|
|
|
|
break;
|
2013-06-04 17:38:43 +08:00
|
|
|
case TEST_COMPONENTS:
|
|
|
|
{
|
|
|
|
runComponentsTestLayerTest();
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 17:54:05 +08:00
|
|
|
|
|
|
|
void ExtensionsMainLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
|
|
|
|
{
|
|
|
|
CCSetIterator it = pTouches->begin();
|
|
|
|
CCTouch* touch = (CCTouch*)(*it);
|
|
|
|
|
|
|
|
m_tBeginPos = touch->getLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtensionsMainLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
|
|
|
|
{
|
|
|
|
CCSetIterator it = pTouches->begin();
|
|
|
|
CCTouch* touch = (CCTouch*)(*it);
|
|
|
|
|
|
|
|
CCPoint touchLocation = touch->getLocation();
|
|
|
|
float nMoveY = touchLocation.y - m_tBeginPos.y;
|
|
|
|
|
|
|
|
CCPoint curPos = m_pItemMenu->getPosition();
|
|
|
|
CCPoint nextPos = ccp(curPos.x, curPos.y + nMoveY);
|
|
|
|
|
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
|
|
|
m_pItemMenu->setPosition(CCPointZero);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextPos.y > ((TEST_MAX_COUNT + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
|
|
|
{
|
|
|
|
m_pItemMenu->setPosition(ccp(0, ((TEST_MAX_COUNT + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pItemMenu->setPosition(nextPos);
|
|
|
|
m_tBeginPos = touchLocation;
|
|
|
|
s_tCurPos = nextPos;
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ExtensionsTestScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void ExtensionsTestScene::runThisTest()
|
|
|
|
{
|
|
|
|
CCLayer* pLayer = new ExtensionsMainLayer();
|
|
|
|
addChild(pLayer);
|
|
|
|
pLayer->release();
|
|
|
|
|
|
|
|
CCDirector::sharedDirector()->replaceScene(this);
|
|
|
|
}
|