diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp index d136aca44e..cee5ac6d2c 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/AppDelegate.cpp @@ -22,7 +22,7 @@ AppDelegate::~AppDelegate() bool AppDelegate::applicationDidFinishLaunching() { -#ifdef COCOS2D_DEBUG +#if (COCOS2D_DEBUG>0) initRuntime(); #endif @@ -30,12 +30,17 @@ bool AppDelegate::applicationDidFinishLaunching() auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { - ConfigParser::getInstance()->readConfig(); + + if (!ConfigParser::getInstance()->isInit()) { + ConfigParser::getInstance()->readConfig(); + } + Size viewSize = ConfigParser::getInstance()->getInitViewSize(); string title = ConfigParser::getInstance()->getInitViewName(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) extern void createSimulator(const char* viewName, float width, float height,float frameZoomFactor = 1.0f); - createSimulator(title.c_str(),viewSize.width,viewSize.height); + bool isLanscape = ConfigParser::getInstance()->isLanscape(); + createSimulator(title.c_str(),viewSize.width,viewSize.height,isLanscape); #else glview = GLView::createWithRect(title.c_str(), Rect(0,0,viewSize.width,viewSize.height)); director->setOpenGLView(glview); @@ -48,7 +53,7 @@ bool AppDelegate::applicationDidFinishLaunching() // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); -#ifdef COCOS2D_DEBUG +#if (COCOS2D_DEBUG>0) if (startRuntime()) return true; #endif diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp index ab57e96dc5..f017337415 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/ConfigParser.cpp @@ -16,36 +16,43 @@ ConfigParser *ConfigParser::getInstance(void) return s_sharedInstance; } +bool ConfigParser::isInit() +{ + return _isInit; +} + void ConfigParser::readConfig() { _initViewSize.setSize(960,640); _viewName="HelloLua"; + _isInit = true; string filecfg = "res/config.json"; string fullPathFile = FileUtils::getInstance()->fullPathForFilename(filecfg); FILE * pFile = fopen (fullPathFile.c_str() , "r"); if(pFile) { rapidjson::FileStream inputStream(pFile); - rapidjson::Document runtimecfgjson; - runtimecfgjson.ParseStream<0>(inputStream); + _docRootjson.ParseStream<0>(inputStream); fclose(pFile); - if (runtimecfgjson.HasMember("init_view") && runtimecfgjson["init_view"].IsObject()) + if (_docRootjson.HasMember("init_view") && _docRootjson["init_view"].IsObject()) { - const rapidjson::Value& objectInitView = runtimecfgjson["init_view"]; + const rapidjson::Value& objectInitView = _docRootjson["init_view"]; if (objectInitView.HasMember("width") && objectInitView.HasMember("height")) { _initViewSize.width = objectInitView["width"].GetUint(); _initViewSize.height = objectInitView["height"].GetUint(); } - if (objectInitView.HasMember("name")) + if (objectInitView.HasMember("name") && objectInitView["name"].IsString()) { _viewName = objectInitView["name"].GetString(); } - + if (objectInitView.HasMember("isLandscape") && objectInitView["isLandscape"].IsBool()) { + _isLandscape = objectInitView["isLandscape"].GetBool(); + } } - if (runtimecfgjson.HasMember("simulator_screen_size")) + if (_docRootjson.HasMember("simulator_screen_size")) { - const rapidjson::Value& ArrayScreenSize = runtimecfgjson["simulator_screen_size"]; + const rapidjson::Value& ArrayScreenSize = _docRootjson["simulator_screen_size"]; if (ArrayScreenSize.IsArray()) { for (int i=0; i #include #include "cocos2d.h" +#include "json/document.h" using namespace std; USING_NS_CC; @@ -32,14 +33,21 @@ public: int getScreenSizeCount(void); cocos2d::Size getInitViewSize(); string getInitViewName(); + rapidjson::Document& getConfigJsonRoot(); const SimulatorScreenSize getScreenSize(int index); - + bool isLanscape(); + bool isInit(); + private: ConfigParser(void); static ConfigParser *s_sharedInstance; ScreenSizeArray _screenSizeArray; cocos2d::Size _initViewSize; string _viewName; + bool _isLandscape; + bool _isInit; + + rapidjson::Document _docRootjson; }; #endif // __CONFIG_PARSER_H__ diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj index 0a3ebeeb6d..8f2038f305 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/HelloLua.xcodeproj/project.pbxproj @@ -94,6 +94,8 @@ C03781F618BF65B100FE4F13 /* libluabindings iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C03781B618BF654500FE4F13 /* libluabindings iOS.a */; }; C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0619CD61896894800872C26 /* Runtime_ios-mac.mm */; }; C0619CD81896894800872C26 /* Runtime_ios-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0619CD61896894800872C26 /* Runtime_ios-mac.mm */; }; + C06C3796191A1D1E00617BED /* ConfigParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C06C3794191A1D1E00617BED /* ConfigParser.cpp */; }; + C06C3797191A1D1E00617BED /* ConfigParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C06C3794191A1D1E00617BED /* ConfigParser.cpp */; }; C07828F818B4D72E00BD2287 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C07828F418B4D72E00BD2287 /* main.m */; }; C07828F918B4D72E00BD2287 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = C07828F518B4D72E00BD2287 /* MainMenu.xib */; }; C07828FA18B4D72E00BD2287 /* SimulatorApp.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07828F718B4D72E00BD2287 /* SimulatorApp.mm */; }; @@ -362,6 +364,8 @@ C03781CD18BF656A00FE4F13 /* OpenglConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = OpenglConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/OpenglConstants.lua"; sourceTree = ""; }; C03781CE18BF656A00FE4F13 /* StudioConstants.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = StudioConstants.lua; path = "../../cocos2d-x/cocos/scripting/lua-bindings/script/StudioConstants.lua"; sourceTree = ""; }; C0619CD61896894800872C26 /* Runtime_ios-mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "Runtime_ios-mac.mm"; sourceTree = ""; }; + C06C3794191A1D1E00617BED /* ConfigParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConfigParser.cpp; path = ../Classes/ConfigParser.cpp; sourceTree = ""; }; + C06C3795191A1D1E00617BED /* ConfigParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConfigParser.h; path = ../Classes/ConfigParser.h; sourceTree = ""; }; C07828F418B4D72E00BD2287 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; C07828F518B4D72E00BD2287 /* MainMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = ""; }; C07828F618B4D72E00BD2287 /* SimulatorApp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimulatorApp.h; sourceTree = ""; }; @@ -615,6 +619,8 @@ F293BB7C15EB830F00256477 /* Classes */ = { isa = PBXGroup; children = ( + C06C3794191A1D1E00617BED /* ConfigParser.cpp */, + C06C3795191A1D1E00617BED /* ConfigParser.h */, C07828FB18B4DC6F00BD2287 /* Runtime.cpp */, C07828FC18B4DC6F00BD2287 /* Runtime.h */, C0619CD61896894800872C26 /* Runtime_ios-mac.mm */, @@ -916,6 +922,7 @@ 5023813317EBBCE400990C9B /* AppDelegate.cpp in Sources */, C09BA7EE18BCA49600A85A3E /* NSAppSheetAdditions.m in Sources */, C07828FE18B4DC7000BD2287 /* Runtime.cpp in Sources */, + C06C3797191A1D1E00617BED /* ConfigParser.cpp in Sources */, C09BA7E818BC929700A85A3E /* WorkSpaceDialogController.mm in Sources */, C07828F818B4D72E00BD2287 /* main.m in Sources */, C0619CD81896894800872C26 /* Runtime_ios-mac.mm in Sources */, @@ -928,6 +935,7 @@ files = ( 5023812517EBBCAC00990C9B /* RootViewController.mm in Sources */, F293BB9C15EB831F00256477 /* AppDelegate.cpp in Sources */, + C06C3796191A1D1E00617BED /* ConfigParser.cpp in Sources */, 5023812417EBBCAC00990C9B /* main.m in Sources */, C0619CD71896894800872C26 /* Runtime_ios-mac.mm in Sources */, C07828FD18B4DC6F00BD2287 /* Runtime.cpp in Sources */, diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/AppController.mm b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/AppController.mm index 6e1d42e9c0..fb3d672fe3 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/AppController.mm +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/AppController.mm @@ -30,6 +30,7 @@ #import "AppDelegate.h" #import "RootViewController.h" #import "CCEAGLView.h" +#include "ConfigParser.h" @implementation AppController @@ -43,7 +44,9 @@ static AppDelegate s_sharedApplication; { // Override point for customization after application launch. - + + ConfigParser::getInstance()->readConfig(); + // Add the view controller's view to the window and display. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds] diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/Info.plist b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/Info.plist index 105ea833f0..8c1b27a35d 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/Info.plist +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/Info.plist @@ -64,8 +64,9 @@ UISupportedInterfaceOrientations - UIInterfaceOrientationLandscapeRight + UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm index 3eed8b36cd..ce34f8516e 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/RootViewController.mm @@ -26,6 +26,7 @@ #import "RootViewController.h" #import "cocos2d.h" #import "CCEAGLView.h" +#include "ConfigParser.h" @implementation RootViewController @@ -55,18 +56,32 @@ // Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - return UIInterfaceOrientationIsLandscape( interfaceOrientation ); + + if (ConfigParser::getInstance()->isLanscape()) { + return UIInterfaceOrientationIsLandscape( interfaceOrientation ); + }else{ + return UIInterfaceOrientationIsPortrait( interfaceOrientation ); + } + } // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead - (NSUInteger) supportedInterfaceOrientations{ #ifdef __IPHONE_6_0 - return UIInterfaceOrientationMaskAllButUpsideDown; + if (ConfigParser::getInstance()->isLanscape()) { + return UIInterfaceOrientationMaskLandscape; + }else{ + return UIInterfaceOrientationMaskPortraitUpsideDown; + } #endif } - (BOOL) shouldAutorotate { - return YES; + if (ConfigParser::getInstance()->isLanscape()) { + return YES; + }else{ + return NO; + } } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/main.m b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/main.m index c7052953c8..b1286e31be 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/main.m +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/ios/main.m @@ -1,9 +1,4 @@ -// -// main.m -// HelloLua -// -// Copyright __MyCompanyName__ 2011. All rights reserved. -// + #import diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/MainMenu.xib b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/MainMenu.xib index 1698f76476..38c8b9532c 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/MainMenu.xib +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/MainMenu.xib @@ -1,8 +1,8 @@ - + - - + + @@ -121,10 +121,9 @@ - - + - + @@ -143,4 +142,4 @@ - \ No newline at end of file + diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.h b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.h index 3587cf5dcf..411a256e9f 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.h +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.h @@ -26,7 +26,7 @@ #include #include "AppDelegate.h" -void createSimulator(const char* viewName, float width, float height,float frameZoomFactor = 1.0f); +void createSimulator(const char* viewName, float width, float height,bool isLandscape = true,float frameZoomFactor = 1.0f); @interface AppController : NSObject { @@ -46,7 +46,7 @@ void createSimulator(const char* viewName, float width, float height,float frame - (IBAction) onScreenPortait:(id)sender; - (IBAction) onScreenLandscape:(id)sender; - (IBAction) onScreenZoomOut:(id)sender; -- (IBAction) onReloadScript:(id)sender; +- (IBAction) onRelaunch:(id)sender; @end diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.mm b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.mm index 96292cbd76..36f6fdf08b 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.mm +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.ios_mac/mac/SimulatorApp.mm @@ -117,10 +117,17 @@ std::string getCurAppPath(void) [window makeKeyAndOrderFront:self]; } -void createSimulator(const char* viewName, float width, float height,float frameZoomFactor) +void createSimulator(const char* viewName, float width, float height,bool isLandscape,float frameZoomFactor) { if(g_nsAppDelegate) { + if((isLandscape && height > width) || (!isLandscape && width > height)) + { + float tmpvalue =width; + width = height; + height = width; + } + [g_nsAppDelegate createSimulator:[NSString stringWithUTF8String:viewName] viewWidth:width viewHeight:height factor:frameZoomFactor]; } @@ -281,9 +288,26 @@ void createSimulator(const char* viewName, float width, float height,float frame [self updateView]; } -- (IBAction) onReloadScript:(id)sender +- (void) launch:(NSArray*)args { - reloadScript(""); + NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; + NSMutableDictionary *configuration = [NSMutableDictionary dictionaryWithObject:args forKey:NSWorkspaceLaunchConfigurationArguments]; + NSError *error = [[[NSError alloc] init] autorelease]; + [[NSWorkspace sharedWorkspace] launchApplicationAtURL:url + options:NSWorkspaceLaunchNewInstance + configuration:configuration error:&error]; +} + +- (void) relaunch:(NSArray*)args +{ + [self launch:args]; + [[NSApplication sharedApplication] terminate:self]; +} + +- (IBAction) onRelaunch:(id)sender +{ + NSArray* args=[[NSArray alloc] initWithObjects:@" ", nil]; + [self relaunch:args]; } diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.cpp b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.cpp index 6c5d511f2e..647b5432d9 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.cpp @@ -301,13 +301,20 @@ INT_PTR CALLBACK AboutDialogCallback(HWND hDlg, UINT message, WPARAM wParam, LPA return (INT_PTR)FALSE; } -void createSimulator(const char* viewName, float width, float height, float frameZoomFactor) +void createSimulator(const char* viewName, float width, float height, bool isLandscape, float frameZoomFactor) { if (g_eglView) { return; } + if((isLandscape && height > width) || (!isLandscape && width > height)) + { + float tmpvalue =width; + width = height; + height = width; + } + g_eglView = GLView::createWithRect(viewName,Rect(0,0,width,height),frameZoomFactor); auto director = Director::getInstance(); director->setOpenGLView(g_eglView); diff --git a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.h b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.h index fb09f1646d..abb12ab69d 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.h +++ b/templates/lua-template-runtime/frameworks/runtime-src/proj.win32/SimulatorWindow.h @@ -28,6 +28,6 @@ THE SOFTWARE. /************************ @brief create Simulator *********************************/ -void createSimulator(const char* viewName, float width, float height,float frameZoomFactor = 1.0f); +void createSimulator(const char* viewName, float width, float height,bool isLandscape = true,float frameZoomFactor = 1.0f); #endif /* __PROJECT_CONFIG_H_ */ diff --git a/templates/lua-template-runtime/res/config.json b/templates/lua-template-runtime/res/config.json index 6c76c2a865..30bd68e431 100644 --- a/templates/lua-template-runtime/res/config.json +++ b/templates/lua-template-runtime/res/config.json @@ -1,5 +1,6 @@ { "init_view":{ + "isLandscape": true, "name": "HelloLua", "width": 960, "height": 640