diff -r 589f69a9665c -r 851f36579ed4 project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m --- a/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m Sun Apr 17 13:33:46 2011 -0400 +++ b/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m Sun Apr 17 20:52:56 2011 +0200 @@ -23,9 +23,7 @@ #import "PascalImports.h" #import "ObjcExports.h" #import "CommodityFunctions.h" -#import "GameSetup.h" #import "MainMenuViewController.h" -#import "OverlayViewController.h" #import "Appirater.h" #include @@ -45,7 +43,7 @@ @end @implementation HedgewarsAppDelegate -@synthesize mainViewController, overlayController, uiwindow, secondWindow, isInGame; +@synthesize mainViewController, uiwindow, secondWindow, isInGame; // convenience method +(HedgewarsAppDelegate *)sharedAppDelegate { @@ -64,108 +62,11 @@ -(void) dealloc { [mainViewController release]; - [overlayController release]; [uiwindow release]; [secondWindow release]; [super dealloc]; } -// main routine for calling the actual game engine --(NSArray *)startSDLgame:(NSDictionary *)gameDictionary { - UIWindow *gameWindow; - if (IS_DUALHEAD()) - gameWindow = self.secondWindow; - else - gameWindow = self.uiwindow; - - UIView *blackView = [[UIView alloc] initWithFrame:gameWindow.frame]; - blackView.backgroundColor = [UIColor blackColor]; - blackView.opaque = YES; - blackView.tag = BLACKVIEW_TAG; - [gameWindow addSubview:blackView]; - if (IS_DUALHEAD()) { - blackView.alpha = 0; - [UIView beginAnimations:@"fading to game first" context:NULL]; - [UIView setAnimationDuration:1]; - blackView.alpha = 1; - [UIView commitAnimations]; - - UIView *secondBlackView = [[UIView alloc] initWithFrame:self.uiwindow.frame]; - secondBlackView.backgroundColor = [UIColor blackColor]; - secondBlackView.opaque = YES; - secondBlackView.tag = SECONDBLACKVIEW_TAG; - secondBlackView.alpha = 0; - [self.uiwindow addSubview:secondBlackView]; - [UIView beginAnimations:@"fading to game second" context:NULL]; - [UIView setAnimationDuration:1]; - secondBlackView.alpha = 1; - [UIView commitAnimations]; - [secondBlackView release]; - } - [blackView release]; - - - // pull out useful configuration info from various files - GameSetup *setup = [[GameSetup alloc] initWithDictionary:gameDictionary]; - NSNumber *isNetGameNum = [gameDictionary objectForKey:@"netgame"]; - - [NSThread detachNewThreadSelector:@selector(engineProtocol) - toTarget:setup - withObject:nil]; - - NSNumber *menuStyle = [NSNumber numberWithBool:setup.menuStyle]; - NSNumber *orientation = [[gameDictionary objectForKey:@"game_dictionary"] objectForKey:@"orientation"]; - NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: - isNetGameNum,@"net", - menuStyle,@"menu", - orientation,@"orientation", - nil]; - [self performSelector:@selector(displayOverlayLater:) withObject:dict afterDelay:1]; - - // need to set again [gameDictionary objectForKey:@"savefile"] because if it's empty it means it's a normal game - const char **gameArgs = [setup getGameSettings:[gameDictionary objectForKey:@"savefile"]]; - self.isInGame = YES; - // this is the pascal fuction that starts the game - Game(gameArgs); - self.isInGame = NO; - free(gameArgs); - - NSArray *stats = setup.statsArray; - [setup release]; - - - [self.uiwindow makeKeyAndVisible]; - [self.uiwindow bringSubviewToFront:self.mainViewController.view]; - - UIView *refBlackView = [gameWindow viewWithTag:BLACKVIEW_TAG]; - UIView *refSecondBlackView = [self.uiwindow viewWithTag:SECONDBLACKVIEW_TAG]; - [UIView beginAnimations:@"fading in from ingame" context:NULL]; - [UIView setAnimationDuration:1]; - refBlackView.alpha = 0; - refSecondBlackView.alpha = 0; - [UIView commitAnimations]; - [refBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; - [refSecondBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2]; - - return stats; -} - -// overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created --(void) displayOverlayLater:(id) object { - NSDictionary *dict = (NSDictionary *)object; - self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil]; - self.overlayController.isNetGame = [[dict objectForKey:@"net"] boolValue]; - self.overlayController.useClassicMenu = [[dict objectForKey:@"menu"] boolValue]; - self.overlayController.initialOrientation = [[dict objectForKey:@"orientation"] intValue]; - - UIWindow *gameWindow; - if (IS_DUALHEAD()) - gameWindow = self.uiwindow; - else - gameWindow = [[UIApplication sharedApplication] keyWindow]; - [gameWindow addSubview:self.overlayController.view]; -} - // override the direct execution of SDL_main to allow us to implement our own frontend -(void) postFinishLaunch { [[UIApplication sharedApplication] setStatusBarHidden:YES]; @@ -173,10 +74,8 @@ self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - if (IS_IPAD()) - self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil]; - else - self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil]; + NSString *controllerName = (IS_IPAD() ? @"MainMenuViewController-iPad" : @"MainMenuViewController-iPhone"); + self.mainViewController = [[MainMenuViewController alloc] initWithNibName:controllerName bundle:nil]; [self.uiwindow addSubview:self.mainViewController.view]; [self.mainViewController release]; @@ -185,7 +84,7 @@ // check for dual monitor support if (IS_DUALHEAD()) { - DLog(@"dual head mode ftw"); + DLog(@"Dualhead mode"); self.secondWindow = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:1] bounds]]; self.secondWindow.backgroundColor = [UIColor blackColor]; self.secondWindow.screen = [[UIScreen screens] objectAtIndex:1];