cocoaTouch/MainMenuViewController.m
changeset 2803 1f446fc5c8ec
parent 2799 558b29bf00c5
child 2805 36a8cebb91e8
equal deleted inserted replaced
2802:28cd5b87bce9 2803:1f446fc5c8ec
     8 
     8 
     9 #import "MainMenuViewController.h"
     9 #import "MainMenuViewController.h"
    10 #import "SDL_uikitappdelegate.h"
    10 #import "SDL_uikitappdelegate.h"
    11 #import "PascalImports.h"
    11 #import "PascalImports.h"
    12 
    12 
       
    13 // in case we don't want SDL_mixer...
       
    14 //#import "SoundEffect.h"	
       
    15 //SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]];
       
    16 //SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]];
       
    17 
       
    18 
    13 @implementation MainMenuViewController
    19 @implementation MainMenuViewController
    14 
    20 
    15 @synthesize versionLabel, settingsViewController, mainView;
    21 @synthesize versionLabel, settingsViewController, mainView;
    16 
    22 
    17 /*
       
    18  // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
       
    19 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
       
    20     if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
       
    21         // Custom initialization
       
    22     }
       
    23     return self;
       
    24 }
       
    25 */
       
    26 
       
    27 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    23 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    28 	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    24 	return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    29 }
    25 }
    30 
       
    31 
    26 
    32 - (void)didReceiveMemoryWarning {
    27 - (void)didReceiveMemoryWarning {
    33 	// Releases the view if it doesn't have a superview.
    28 	// Releases the view if it doesn't have a superview.
    34 	[super didReceiveMemoryWarning];
    29 	[super didReceiveMemoryWarning];
    35 	
    30 	
    38 		self.settingsViewController = nil;
    33 		self.settingsViewController = nil;
    39 		[settingsViewController release];
    34 		[settingsViewController release];
    40 	}
    35 	}
    41 }
    36 }
    42 
    37 
    43 
       
    44 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
       
    45 -(void) viewDidLoad {
    38 -(void) viewDidLoad {
       
    39 	[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil];
       
    40 	
    46 	char *ver;
    41 	char *ver;
    47 	HW_versionInfo(NULL, &ver);
    42 	HW_versionInfo(NULL, &ver);
    48 	self.versionLabel.text = [[NSString stringWithUTF8String:ver] autorelease];
    43 	self.versionLabel.text = [[NSString stringWithUTF8String:ver] autorelease];
    49 	[super viewDidLoad];
    44 	[super viewDidLoad];
    50 }
    45 }
    67 }
    62 }
    68 
    63 
    69 -(void) viewDidAppear:(BOOL)animated {
    64 -(void) viewDidAppear:(BOOL)animated {
    70 	self.mainView.userInteractionEnabled = YES;
    65 	self.mainView.userInteractionEnabled = YES;
    71 	[super viewDidAppear:animated];
    66 	[super viewDidAppear:animated];
       
    67 }
       
    68 
       
    69 -(void) checkFirstRun {
       
    70 	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
       
    71 	
       
    72 	NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
       
    73 	if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) {
       
    74 		// file not present, means that also other files are absent
       
    75 		NSLog(@"First time run, creating settings files");
       
    76 		
       
    77 		// show a popup with an indicator to make the user wait
       
    78 		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"One-time Preferences Configuration",@"")
       
    79 								message:nil
       
    80 							       delegate:nil
       
    81 						      cancelButtonTitle:nil
       
    82 						      otherButtonTitles:nil];
       
    83 		[alert show];
       
    84 		
       
    85 		UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
       
    86 						      initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
       
    87 		indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
       
    88 		[indicator startAnimating];
       
    89 		[alert addSubview:indicator];
       
    90 		[indicator release];
       
    91 		
       
    92 		// create settings.plist
       
    93 		NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
       
    94 	
       
    95 		[saveDict setObject:@"" forKey:@"username"];
       
    96 		[saveDict setObject:@"" forKey:@"password"];
       
    97 		[saveDict setObject:@"1" forKey:@"music"];
       
    98 		[saveDict setObject:@"1" forKey:@"sounds"];
       
    99 		[saveDict setObject:@"0" forKey:@"alternate"];
       
   100 	
       
   101 		[saveDict writeToFile:filePath atomically:YES];
       
   102 		[saveDict release];
       
   103 		
       
   104 		// create other files
       
   105 		
       
   106 		// memory cleanup
       
   107 		[alert dismissWithClickedButtonIndex:0 animated:YES];
       
   108 		[alert release];
       
   109 	}
       
   110 	[pool release];
       
   111 	[NSThread exit];
    72 }
   112 }
    73 
   113 
    74 #pragma mark -
   114 #pragma mark -
    75 #pragma mark Action buttons
   115 #pragma mark Action buttons
    76 -(IBAction) startPlaying {
   116 -(IBAction) startPlaying {
   101 		self.settingsViewController.view.frame = CGRectMake(0, -320, 480, 320);
   141 		self.settingsViewController.view.frame = CGRectMake(0, -320, 480, 320);
   102 		self.settingsViewController.parentView = self.mainView;
   142 		self.settingsViewController.parentView = self.mainView;
   103 
   143 
   104 		[UIView beginAnimations:@"View Switch" context:NULL];
   144 		[UIView beginAnimations:@"View Switch" context:NULL];
   105 		[UIView setAnimationDuration:1];
   145 		[UIView setAnimationDuration:1];
   106 		//[UIView setAnimationDuration:UIViewAnimationCurveEaseOut];
   146 
   107 		self.settingsViewController.view.frame = CGRectMake(0, 0, 480, 320);
   147 		self.settingsViewController.view.frame = CGRectMake(0, 0, 480, 320);
   108 		self.mainView.frame = CGRectMake(0, 320, 480, 320);
   148 		self.mainView.frame = CGRectMake(0, 320, 480, 320);
       
   149 		[UIView commitAnimations];
   109 		
   150 		
   110 		[self.view addSubview:settingsViewController.view];
   151 		[self.view addSubview:settingsViewController.view];
   111 		[UIView commitAnimations];
       
   112 	}
   152 	}
   113 
   153 
   114 }
   154 }
   115 
   155 
   116 @end
   156 @end