2011-03-02 17:05:22 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2011-03-02 17:05:22 +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-25 17:33:28 +08:00
|
|
|
#import "CCApplication.h"
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2014-01-28 08:44:10 +08:00
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
|
|
|
|
2011-03-02 17:05:22 +08:00
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
#import "CCGeometry.h"
|
2011-03-02 17:05:22 +08:00
|
|
|
#import "CCDirectorCaller.h"
|
|
|
|
|
2012-04-19 11:56:22 +08:00
|
|
|
NS_CC_BEGIN
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Application* Application::sm_pSharedApplication = 0;
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Application::Application()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2011-03-09 16:19:20 +08:00
|
|
|
CC_ASSERT(! sm_pSharedApplication);
|
2011-03-02 17:05:22 +08:00
|
|
|
sm_pSharedApplication = this;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Application::~Application()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2011-03-09 16:19:20 +08:00
|
|
|
CC_ASSERT(this == sm_pSharedApplication);
|
2011-03-02 17:05:22 +08:00
|
|
|
sm_pSharedApplication = 0;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
int Application::run()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2012-05-02 18:18:43 +08:00
|
|
|
if (applicationDidFinishLaunching())
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2013-06-21 08:46:22 +08:00
|
|
|
[[CCDirectorCaller sharedDirectorCaller] startMainLoop];
|
2011-03-02 17:05:22 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Application::setAnimationInterval(double interval)
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2013-06-21 08:46:22 +08:00
|
|
|
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval: interval ];
|
2011-03-02 17:05:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-07-15 16:24:42 +08:00
|
|
|
Application* Application::getInstance()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2011-03-09 16:19:20 +08:00
|
|
|
CC_ASSERT(sm_pSharedApplication);
|
2012-08-21 15:28:43 +08:00
|
|
|
return sm_pSharedApplication;
|
2011-03-02 17:05:22 +08:00
|
|
|
}
|
|
|
|
|
2013-07-15 16:37:38 +08:00
|
|
|
// @deprecated Use getInstance() instead
|
|
|
|
Application* Application::sharedApplication()
|
|
|
|
{
|
|
|
|
return Application::getInstance();
|
|
|
|
}
|
|
|
|
|
2014-03-18 02:34:21 +08:00
|
|
|
const char * Application::getCurrentLanguageCode()
|
|
|
|
{
|
|
|
|
static char code[3]={0};
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
|
|
|
|
NSString *currentLanguage = [languages objectAtIndex:0];
|
|
|
|
|
|
|
|
// get the current language code.(such as English is "en", Chinese is "zh" and so on)
|
|
|
|
NSDictionary* temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage];
|
|
|
|
NSString * languageCode = [temp objectForKey:NSLocaleLanguageCode];
|
|
|
|
[languageCode getCString:code maxLength:2 encoding:NSASCIIStringEncoding];
|
|
|
|
code[2]='\0';
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2013-07-26 17:29:06 +08:00
|
|
|
LanguageType Application::getCurrentLanguage()
|
2011-06-17 10:49:02 +08:00
|
|
|
{
|
|
|
|
// get the current language and country config
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
|
|
|
|
NSString *currentLanguage = [languages objectAtIndex:0];
|
|
|
|
|
|
|
|
// get the current language code.(such as English is "en", Chinese is "zh" and so on)
|
|
|
|
NSDictionary* temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage];
|
|
|
|
NSString * languageCode = [temp objectForKey:NSLocaleLanguageCode];
|
|
|
|
|
2013-07-26 17:29:06 +08:00
|
|
|
LanguageType ret = LanguageType::ENGLISH;
|
2011-06-17 10:49:02 +08:00
|
|
|
if ([languageCode isEqualToString:@"zh"])
|
|
|
|
{
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::CHINESE;
|
2011-06-17 10:49:02 +08:00
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"en"])
|
|
|
|
{
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::ENGLISH;
|
2011-06-17 10:49:02 +08:00
|
|
|
}
|
2011-08-31 14:20:33 +08:00
|
|
|
else if ([languageCode isEqualToString:@"fr"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::FRENCH;
|
2011-08-31 14:20:33 +08:00
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"it"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::ITALIAN;
|
2011-08-31 14:20:33 +08:00
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"de"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::GERMAN;
|
2011-08-31 14:20:33 +08:00
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"es"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::SPANISH;
|
2011-08-31 14:20:33 +08:00
|
|
|
}
|
2014-01-26 04:38:15 +08:00
|
|
|
else if ([languageCode isEqualToString:@"nl"]){
|
|
|
|
ret = LanguageType::DUTCH;
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
else if ([languageCode isEqualToString:@"ru"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::RUSSIAN;
|
2011-10-12 13:32:59 +08:00
|
|
|
}
|
2012-10-18 15:57:18 +08:00
|
|
|
else if ([languageCode isEqualToString:@"ko"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::KOREAN;
|
2012-10-18 15:57:18 +08:00
|
|
|
}
|
2012-11-28 16:53:10 +08:00
|
|
|
else if ([languageCode isEqualToString:@"ja"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::JAPANESE;
|
2012-11-28 16:53:10 +08:00
|
|
|
}
|
2012-12-05 18:31:05 +08:00
|
|
|
else if ([languageCode isEqualToString:@"hu"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::HUNGARIAN;
|
2012-12-05 18:31:05 +08:00
|
|
|
}
|
2013-02-11 23:29:56 +08:00
|
|
|
else if ([languageCode isEqualToString:@"pt"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::PORTUGUESE;
|
2013-02-11 23:29:56 +08:00
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"ar"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::ARABIC;
|
2013-02-11 23:29:56 +08:00
|
|
|
}
|
2013-05-29 16:16:22 +08:00
|
|
|
else if ([languageCode isEqualToString:@"nb"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::NORWEGIAN;
|
2013-05-29 16:16:22 +08:00
|
|
|
}
|
2013-06-11 22:46:38 +08:00
|
|
|
else if ([languageCode isEqualToString:@"pl"]){
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::POLISH;
|
2013-06-11 22:46:38 +08:00
|
|
|
}
|
2011-06-17 10:49:02 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-26 17:29:06 +08:00
|
|
|
Application::Platform Application::getTargetPlatform()
|
2012-06-11 14:36:25 +08:00
|
|
|
{
|
2012-09-15 06:26:38 +08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // idiom for iOS <= 3.2, otherwise: [UIDevice userInterfaceIdiom] is faster.
|
2012-06-11 14:36:25 +08:00
|
|
|
{
|
2013-07-26 18:17:30 +08:00
|
|
|
return Platform::OS_IPAD;
|
2012-08-16 10:21:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-26 18:17:30 +08:00
|
|
|
return Platform::OS_IPHONE;
|
2012-06-11 14:36:25 +08:00
|
|
|
}
|
2012-08-08 17:42:04 +08:00
|
|
|
}
|
|
|
|
|
2013-10-23 16:29:59 +08:00
|
|
|
void Application::applicationScreenSizeChanged(int newWidth, int newHeight) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-19 11:56:22 +08:00
|
|
|
NS_CC_END
|
2014-01-28 08:44:10 +08:00
|
|
|
|
|
|
|
#endif // CC_PLATFORM_IOS
|