--- a/cocoaTouch/SettingsViewController.m Thu Jan 14 16:46:50 2010 +0000
+++ b/cocoaTouch/SettingsViewController.m Fri Jan 15 10:03:31 2010 +0000
@@ -7,21 +7,14 @@
//
#import "SettingsViewController.h"
-
+#import "SDL_uikitappdelegate.h"
@implementation SettingsViewController
-@synthesize username, password, musicOn, effectsOn, volumeSlider, volumeLabel;
-
--(NSString *)dataFilePath: (NSString *)fileName {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- return [documentsDirectory stringByAppendingPathComponent:fileName];
-}
-
+@synthesize username, password, musicOn, effectsOn, altDamageOn, volumeSlider, volumeLabel;
-(void) viewDidLoad {
- NSString *filePath = [self dataFilePath:@"settings.plist"];
+ NSString *filePath = [SDLUIKitDelegate dataFilePath:@"settings.plist"];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSUserDefaults *data = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
@@ -37,20 +30,28 @@
} else {
effectsOn.on = NO;
}
+ if (1 == [[data objectForKey:@"alternate"] intValue]) {
+ altDamageOn.on = YES;
+ } else {
+ altDamageOn.on = NO;
+ }
+
[volumeSlider setValue:[[data objectForKey:@"volume"] intValue] animated:NO];
+
NSString *tmpVol = [[NSString alloc] initWithFormat:@"%d", (int) volumeSlider.value];
volumeLabel.text = tmpVol;
[tmpVol release];
+ } else {
+ [NSException raise:@"File NOT found" format:@"The file settings.plist was not found at %@", filePath];
}
-
-
/*
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:app];
-*/ [super viewDidLoad];
+*/
+ [super viewDidLoad];
}
-(void) viewDidUnload {
@@ -58,6 +59,7 @@
self.password = nil;
self.musicOn = nil;
self.effectsOn = nil;
+ self.altDamageOn = nil;
self.volumeLabel = nil;
self.volumeSlider = nil;
[super viewDidUnload];
@@ -68,14 +70,16 @@
NSMutableDictionary *saveArray = [[NSMutableDictionary alloc] init];
NSString *tmpMus = (musicOn.on) ? @"1" : @"0";
NSString *tmpEff = (effectsOn.on) ? @"1" : @"0";
+ NSString *tmpAlt = (altDamageOn.on) ? @"1" : @"0";
[saveArray setObject:username.text forKey:@"username"];
[saveArray setObject:password.text forKey:@"password"];
[saveArray setObject:tmpMus forKey:@"music"];
[saveArray setObject:tmpEff forKey:@"effects"];
+ [saveArray setObject:tmpAlt forKey:@"alternate"];
[saveArray setObject:volumeLabel.text forKey:@"volume"];
- [saveArray writeToFile:[self dataFilePath:@"settings.plist"] atomically:YES];
+ [saveArray writeToFile:[SDLUIKitDelegate dataFilePath:@"settings.plist"] atomically:YES];
[saveArray release];
[super viewWillDisappear:animated];
}
@@ -88,11 +92,13 @@
}
*/
+// makes the keyboard go away when background is tapped
-(IBAction) backgroundTap: (id)sender {
[username resignFirstResponder];
[password resignFirstResponder];
}
+// makes the keyboard go away when "Done" is tapped
-(IBAction) textFieldDoneEditing: (id)sender {
[sender resignFirstResponder];
}
@@ -110,6 +116,7 @@
[password release];
[musicOn release];
[effectsOn release];
+ [altDamageOn release];
[volumeLabel release];
[volumeSlider release];
[super dealloc];