2014-01-31 07:11:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
2015-04-03 11:54:39 +08:00
|
|
|
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
2014-01-31 07:11:54 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "AppDelegate.h"
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2012-07-19 17:22:36 +08:00
|
|
|
#include "controller.h"
|
2013-10-16 11:19:01 +08:00
|
|
|
#include "cocostudio/CocoStudio.h"
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "extensions/cocos-ext.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
2015-04-07 16:14:27 +08:00
|
|
|
: _testController(nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
2015-04-03 11:54:39 +08:00
|
|
|
//SimpleAudioEngine::end();
|
2014-01-25 05:43:46 +08:00
|
|
|
cocostudio::ArmatureDataManager::destroyInstance();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-08-22 16:22:16 +08:00
|
|
|
//if you want a different context,just modify the value of glContextAttrs
|
2014-08-22 10:55:39 +08:00
|
|
|
//it will takes effect on all platforms
|
2014-08-22 16:22:16 +08:00
|
|
|
void AppDelegate::initGLContextAttrs()
|
2014-08-21 09:35:32 +08:00
|
|
|
{
|
2014-08-22 16:22:16 +08:00
|
|
|
//set OpenGL context attributions,now can only set six attributions:
|
2014-08-21 09:35:32 +08:00
|
|
|
//red,green,blue,alpha,depth,stencil
|
2014-08-22 16:22:16 +08:00
|
|
|
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
|
2014-08-21 09:35:32 +08:00
|
|
|
|
2014-08-22 16:22:16 +08:00
|
|
|
GLView::setGLContextAttrs(glContextAttrs);
|
2014-08-21 09:35:32 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
2014-01-25 05:43:46 +08:00
|
|
|
// As an example, load config file
|
2014-08-30 03:54:24 +08:00
|
|
|
// FIXME:: This should be loaded before the Director is initialized,
|
|
|
|
// FIXME:: but at this point, the director is already initialized
|
2014-01-25 05:43:46 +08:00
|
|
|
Configuration::getInstance()->loadConfigFile("configs/config-example.plist");
|
2014-01-24 07:36:55 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// initialize director
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2014-01-25 05:43:46 +08:00
|
|
|
auto glview = director->getOpenGLView();
|
|
|
|
if(!glview) {
|
2014-07-31 00:53:04 +08:00
|
|
|
glview = GLViewImpl::create("Cpp Tests");
|
2014-01-25 05:43:46 +08:00
|
|
|
director->setOpenGLView(glview);
|
|
|
|
}
|
2013-07-23 08:25:44 +08:00
|
|
|
|
|
|
|
director->setDisplayStats(true);
|
|
|
|
director->setAnimationInterval(1.0 / 60);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-01-24 07:36:55 +08:00
|
|
|
auto screenSize = glview->getFrameSize();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto designSize = Size(480, 320);
|
2013-06-09 18:54:35 +08:00
|
|
|
|
2014-01-28 11:16:09 +08:00
|
|
|
auto fileUtils = FileUtils::getInstance();
|
2014-01-25 05:43:46 +08:00
|
|
|
std::vector<std::string> searchPaths;
|
2012-10-23 17:48:50 +08:00
|
|
|
|
|
|
|
if (screenSize.height > 320)
|
2012-10-12 17:37:26 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto resourceSize = Size(960, 640);
|
2013-01-28 17:44:53 +08:00
|
|
|
searchPaths.push_back("hd");
|
2014-05-05 15:24:33 +08:00
|
|
|
searchPaths.push_back("ccs-res/hd");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/ArmatureComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/AttributeComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/BackgroundComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/EffectComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/LoadSceneEdtiorFileTest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/ParticleComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/SpriteComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/TmxMapComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/UIComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/hd/scenetest/TriggerTest");
|
|
|
|
searchPaths.push_back("ccs-res");
|
2014-10-09 18:30:39 +08:00
|
|
|
searchPaths.push_back("Manifests");
|
2013-07-23 08:25:44 +08:00
|
|
|
director->setContentScaleFactor(resourceSize.height/designSize.height);
|
2014-12-01 21:50:05 +08:00
|
|
|
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIButton");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UICheckBox");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIImageView");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILabel");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILabelBMFont");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/BackgroundImage");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Color");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Layout");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Gradient_Color");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage");
|
2014-12-22 18:24:06 +08:00
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/LayoutComponent");
|
2014-12-01 21:50:05 +08:00
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILoadingBar");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIPageView");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Both");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Horizontal");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Vertical");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UISlider");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UITextField");
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIWidgetAddNode");
|
2014-12-08 19:00:12 +08:00
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIListView/New");
|
2014-12-01 21:50:05 +08:00
|
|
|
|
|
|
|
searchPaths.push_back("ccs-res/hd/cocosui/CustomTest/CustomWidgetCallbackBindTest");
|
2014-12-02 16:00:30 +08:00
|
|
|
searchPaths.push_back("hd/ActionTimeline");
|
2014-12-22 17:35:39 +08:00
|
|
|
searchPaths.push_back("ccs-res/hd/armature");
|
2012-10-12 17:37:26 +08:00
|
|
|
}
|
2014-01-25 05:43:46 +08:00
|
|
|
else
|
|
|
|
{
|
2014-05-05 15:24:33 +08:00
|
|
|
searchPaths.push_back("ccs-res");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/ArmatureComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/AttributeComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/BackgroundComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/EffectComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/LoadSceneEdtiorFileTest");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/ParticleComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/SpriteComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/TmxMapComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/UIComponentTest");
|
|
|
|
searchPaths.push_back("ccs-res/scenetest/TriggerTest");
|
2014-12-01 21:50:05 +08:00
|
|
|
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIButton");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UICheckBox");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIImageView");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILabel");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILabelBMFont");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/BackgroundImage");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Color");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Layout");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Gradient_Color");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage");
|
2014-12-22 18:24:06 +08:00
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/LayoutComponent");
|
2014-12-01 21:50:05 +08:00
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILoadingBar");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIPageView");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Both");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Horizontal");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Vertical");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UISlider");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UITextField");
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIWidgetAddNode");
|
2014-12-08 19:00:12 +08:00
|
|
|
searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIListView/New");
|
2014-12-01 21:50:05 +08:00
|
|
|
|
|
|
|
searchPaths.push_back("ccs-res/cocosui/CustomTest/CustomWidgetCallbackBindTest");
|
2014-12-02 16:00:30 +08:00
|
|
|
searchPaths.push_back("ActionTimeline");
|
2014-12-22 17:35:39 +08:00
|
|
|
searchPaths.push_back("ccs-res/armature");
|
2014-01-25 05:43:46 +08:00
|
|
|
}
|
2013-10-16 11:19:01 +08:00
|
|
|
|
2014-01-28 11:16:09 +08:00
|
|
|
fileUtils->setSearchPaths(searchPaths);
|
2012-10-12 17:37:26 +08:00
|
|
|
|
2014-03-22 21:16:43 +08:00
|
|
|
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-04-03 11:54:39 +08:00
|
|
|
_testController = TestController::getInstance();
|
2014-05-13 11:47:32 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
|
|
|
void AppDelegate::applicationDidEnterBackground()
|
|
|
|
{
|
2015-04-07 16:14:27 +08:00
|
|
|
if (_testController)
|
|
|
|
{
|
|
|
|
_testController->onEnterBackground();
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->stopAnimation();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2015-04-07 16:14:27 +08:00
|
|
|
if (_testController)
|
|
|
|
{
|
|
|
|
_testController->onEnterForeground();
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->startAnimation();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|