--- a/cocoaTouch/MainMenuViewController.m Fri Feb 12 18:40:14 2010 +0000
+++ b/cocoaTouch/MainMenuViewController.m Sat Feb 13 01:56:35 2010 +0000
@@ -10,25 +10,20 @@
#import "SDL_uikitappdelegate.h"
#import "PascalImports.h"
+// in case we don't want SDL_mixer...
+//#import "SoundEffect.h"
+//SoundEffect *erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]];
+//SoundEffect *selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]];
+
+
@implementation MainMenuViewController
@synthesize versionLabel, settingsViewController, mainView;
-/*
- // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
-- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
- // Custom initialization
- }
- return self;
-}
-*/
-
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
@@ -40,9 +35,9 @@
}
}
-
-// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
-(void) viewDidLoad {
+ [NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil];
+
char *ver;
HW_versionInfo(NULL, &ver);
self.versionLabel.text = [[NSString stringWithUTF8String:ver] autorelease];
@@ -71,6 +66,51 @@
[super viewDidAppear:animated];
}
+-(void) checkFirstRun {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
+ if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) {
+ // file not present, means that also other files are absent
+ NSLog(@"First time run, creating settings files");
+
+ // show a popup with an indicator to make the user wait
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"One-time Preferences Configuration",@"")
+ message:nil
+ delegate:nil
+ cancelButtonTitle:nil
+ otherButtonTitles:nil];
+ [alert show];
+
+ UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
+ initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
+ indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
+ [indicator startAnimating];
+ [alert addSubview:indicator];
+ [indicator release];
+
+ // create settings.plist
+ NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
+
+ [saveDict setObject:@"" forKey:@"username"];
+ [saveDict setObject:@"" forKey:@"password"];
+ [saveDict setObject:@"1" forKey:@"music"];
+ [saveDict setObject:@"1" forKey:@"sounds"];
+ [saveDict setObject:@"0" forKey:@"alternate"];
+
+ [saveDict writeToFile:filePath atomically:YES];
+ [saveDict release];
+
+ // create other files
+
+ // memory cleanup
+ [alert dismissWithClickedButtonIndex:0 animated:YES];
+ [alert release];
+ }
+ [pool release];
+ [NSThread exit];
+}
+
#pragma mark -
#pragma mark Action buttons
-(IBAction) startPlaying {
@@ -103,12 +143,12 @@
[UIView beginAnimations:@"View Switch" context:NULL];
[UIView setAnimationDuration:1];
- //[UIView setAnimationDuration:UIViewAnimationCurveEaseOut];
+
self.settingsViewController.view.frame = CGRectMake(0, 0, 480, 320);
self.mainView.frame = CGRectMake(0, 320, 480, 320);
+ [UIView commitAnimations];
[self.view addSubview:settingsViewController.view];
- [UIView commitAnimations];
}
}