cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m
changeset 3006 da6023c2745b
parent 2803 1f446fc5c8ec
child 3025 01682ec58eb0
equal deleted inserted replaced
3005:1ff835e9ce32 3006:da6023c2745b
    27 #import "jumphack.h"
    27 #import "jumphack.h"
    28 #import "SDL_video.h"
    28 #import "SDL_video.h"
    29 #import "GameSetup.h"
    29 #import "GameSetup.h"
    30 #import "PascalImports.h"
    30 #import "PascalImports.h"
    31 #import "MainMenuViewController.h"
    31 #import "MainMenuViewController.h"
       
    32 #import "overlayViewController.h"
    32 
    33 
    33 #ifdef main
    34 #ifdef main
    34 #undef main
    35 #undef main
    35 #endif
    36 #endif
    36 
    37 
    41 	return retVal;
    42 	return retVal;
    42 }
    43 }
    43 
    44 
    44 @implementation SDLUIKitDelegate
    45 @implementation SDLUIKitDelegate
    45 
    46 
    46 @synthesize uiwindow, window, viewController;
    47 @synthesize uiwindow, window, viewController, overlayController;
    47 
    48 
    48 // convenience method
    49 // convenience method
    49 +(SDLUIKitDelegate *)sharedAppDelegate {
    50 +(SDLUIKitDelegate *)sharedAppDelegate {
    50 	// the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method
    51 	// the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method
    51 	return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
    52 	return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
    65 	[super dealloc];
    66 	[super dealloc];
    66 }
    67 }
    67 
    68 
    68 #pragma mark -
    69 #pragma mark -
    69 #pragma mark Custom stuff
    70 #pragma mark Custom stuff
       
    71 -(void) showMenuAfterwards {
       
    72     // draws the controller overlay after the sdl window has taken control
       
    73     [uiwindow bringSubviewToFront:overlayController.view];
       
    74 
       
    75 	[UIView beginAnimations:@"showing overlay" context:NULL];
       
    76 	[UIView setAnimationDuration:1];
       
    77 	self. overlayController.view.alpha = 1;
       
    78 	[UIView commitAnimations];
       
    79 }
       
    80 
    70 -(IBAction) startSDLgame {
    81 -(IBAction) startSDLgame {
    71 	NSAutoreleasePool *internal_pool = [[NSAutoreleasePool alloc] init];
    82 	NSAutoreleasePool *internal_pool = [[NSAutoreleasePool alloc] init];
    72 
    83 
    73 	GameSetup *setup = [[GameSetup alloc] init];
    84 	GameSetup *setup = [[GameSetup alloc] init];
    74 	[setup startThread:@"engineProtocol"];
    85 	[setup startThread:@"engineProtocol"];
    77 	[UIView beginAnimations:@"removing main controller" context:NULL];
    88 	[UIView beginAnimations:@"removing main controller" context:NULL];
    78 	[UIView setAnimationDuration:1];
    89 	[UIView setAnimationDuration:1];
    79 	self.viewController.mainView.alpha = 0;
    90 	self.viewController.mainView.alpha = 0;
    80 	[UIView commitAnimations];
    91 	[UIView commitAnimations];
    81 
    92 
    82 	NSLog(@"Game is launching...");
    93 	NSLog(@"...Game is launching...");
    83 	const char **gameArgs = [setup getSettings];
    94 	const char **gameArgs = [setup getSettings];
    84 	[setup release];
    95 	[setup release];
    85 	
    96     
    86 	// this is the pascal fuction that starts the game
    97     // overlay with controls
    87 	Game(gameArgs);
    98     overlayController = [[overlayViewController alloc] initWithNibName:@"overlayViewController" bundle:nil];
    88 	
    99     overlayController.view.alpha = 0;
       
   100     [uiwindow addSubview: overlayController.view];
       
   101     [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO];
       
   102     
       
   103 	Game(gameArgs); // this is the pascal fuction that starts the game
       
   104     
       
   105     // let's clean memory
    89 	free(gameArgs);
   106 	free(gameArgs);
    90 	NSLog(@"Game is exting...");
   107     [overlayController.view removeFromSuperview];
       
   108     [overlayController release];
       
   109     
       
   110 	NSLog(@"...Game is exting...");
    91 
   111 
    92 	[uiwindow addSubview: viewController.view];
   112 	[uiwindow addSubview: viewController.view];
    93 	[uiwindow makeKeyAndVisible];
   113 	[uiwindow makeKeyAndVisible];
    94 	
   114 	
    95 	[UIView beginAnimations:@"inserting main controller" context:NULL];
   115 	[UIView beginAnimations:@"inserting main controller" context:NULL];