2011-03-02 17:05:22 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
#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
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCApplication* CCApplication::sm_pSharedApplication = 0;
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCApplication::CCApplication()
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
CCApplication::~CCApplication()
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
int CCApplication::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
|
|
|
{
|
|
|
|
[[CCDirectorCaller sharedDirectorCaller] startMainLoop];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-09 16:19:20 +08:00
|
|
|
void CCApplication::setAnimationInterval(double interval)
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
|
|
|
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval: interval ];
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-21 15:28:43 +08:00
|
|
|
CCApplication* CCApplication::sharedApplication()
|
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
|
|
|
}
|
|
|
|
|
2011-06-17 10:49:02 +08:00
|
|
|
ccLanguageType CCApplication::getCurrentLanguage()
|
|
|
|
{
|
|
|
|
// 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];
|
|
|
|
|
|
|
|
ccLanguageType ret = kLanguageEnglish;
|
|
|
|
if ([languageCode isEqualToString:@"zh"])
|
|
|
|
{
|
|
|
|
ret = kLanguageChinese;
|
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"en"])
|
|
|
|
{
|
|
|
|
ret = kLanguageEnglish;
|
|
|
|
}
|
2011-08-31 14:20:33 +08:00
|
|
|
else if ([languageCode isEqualToString:@"fr"]){
|
|
|
|
ret = kLanguageFrench;
|
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"it"]){
|
|
|
|
ret = kLanguageItalian;
|
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"de"]){
|
|
|
|
ret = kLanguageGerman;
|
|
|
|
}
|
|
|
|
else if ([languageCode isEqualToString:@"es"]){
|
|
|
|
ret = kLanguageSpanish;
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
else if ([languageCode isEqualToString:@"ru"]){
|
2011-10-12 13:32:59 +08:00
|
|
|
ret = kLanguageRussian;
|
|
|
|
}
|
2012-10-18 15:57:18 +08:00
|
|
|
else if ([languageCode isEqualToString:@"ko"]){
|
|
|
|
ret = kLanguageKorean;
|
|
|
|
}
|
2011-06-17 10:49:02 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-16 10:21:15 +08:00
|
|
|
TargetPlatform CCApplication::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
|
|
|
{
|
2012-08-16 10:21:15 +08:00
|
|
|
return kTargetIpad;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return kTargetIphone;
|
2012-06-11 14:36:25 +08:00
|
|
|
}
|
2012-08-08 17:42:04 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 11:56:22 +08:00
|
|
|
NS_CC_END
|