cocoaTouch/SettingsViewController.m
author koda
Thu, 14 Jan 2010 16:38:43 +0000
changeset 2694 dcd248e04f3d
parent 2687 28b8330b8af1
child 2696 41aa7b56c17b
permissions -rw-r--r--
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     1
//
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     2
//  SettingsViewController.m
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     3
//  hwengine
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     4
//
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     5
//  Created by Vittorio on 08/01/10.
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     7
//
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     8
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     9
#import "SettingsViewController.h"
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    10
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    11
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    12
@implementation SettingsViewController
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    13
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    14
@synthesize username, password, musicOn, effectsOn, volumeSlider, volumeLabel;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    15
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    16
-(NSString *)dataFilePath: (NSString *)fileName {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    17
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    18
	NSString *documentsDirectory = [paths objectAtIndex:0];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    19
	return [documentsDirectory stringByAppendingPathComponent:fileName];
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    20
}
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    21
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    22
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    23
-(void) viewDidLoad {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    24
	NSString *filePath = [self dataFilePath:@"settings.plist"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    25
	
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    26
	if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {	
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    27
		NSUserDefaults *data = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    28
		username.text = [data objectForKey:@"username"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    29
		password.text = [data objectForKey:@"password"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    30
		if (1 == [[data objectForKey:@"music"] intValue]) {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    31
			musicOn.on = YES;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    32
		} else {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    33
			musicOn.on = NO;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    34
		}
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    35
		if (1 == [[data objectForKey:@"effects"] intValue]) {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    36
			effectsOn.on = YES;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    37
		} else {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    38
			effectsOn.on = NO;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    39
		}
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    40
		[volumeSlider setValue:[[data objectForKey:@"volume"] intValue] animated:NO];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    41
		NSString *tmpVol = [[NSString alloc] initWithFormat:@"%d", (int) volumeSlider.value];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    42
		volumeLabel.text = tmpVol;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    43
		[tmpVol release];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    44
	}
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    45
	
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    46
	
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    47
/*	
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    48
	UIApplication *app = [UIApplication sharedApplication];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    49
	[[NSNotificationCenter defaultCenter] addObserver:self
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    50
											 selector:@selector(applicationWillTerminate:)
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    51
												 name:UIApplicationWillTerminateNotification
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    52
											   object:app];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    53
*/	[super viewDidLoad];
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    54
}
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    55
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    56
-(void) viewDidUnload {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    57
	self.username = nil;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    58
	self.password = nil;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    59
	self.musicOn = nil;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    60
	self.effectsOn = nil;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    61
	self.volumeLabel = nil;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    62
	self.volumeSlider = nil;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    63
	[super viewDidUnload];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    64
}
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    65
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    66
//- (void)applicationWillTerminate:(NSNotification *)notification {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    67
-(void) viewWillDisappear:(BOOL)animated {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    68
	NSMutableDictionary *saveArray = [[NSMutableDictionary alloc] init];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    69
	NSString *tmpMus = (musicOn.on) ? @"1" : @"0";
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    70
	NSString *tmpEff = (effectsOn.on) ? @"1" : @"0";
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    71
	
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    72
	[saveArray setObject:username.text forKey:@"username"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    73
	[saveArray setObject:password.text forKey:@"password"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    74
	[saveArray setObject:tmpMus forKey:@"music"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    75
	[saveArray setObject:tmpEff forKey:@"effects"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    76
	[saveArray setObject:volumeLabel.text forKey:@"volume"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    77
	
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    78
	[saveArray writeToFile:[self dataFilePath:@"settings.plist"] atomically:YES];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    79
	[saveArray release];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    80
	[super viewWillDisappear:animated];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    81
}
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    82
 
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    83
/*
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    84
// Override to allow orientations other than the default portrait orientation.
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    85
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    86
    // Return YES for supported orientations
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    87
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    88
}
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    89
*/
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    90
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    91
-(IBAction) backgroundTap: (id)sender {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    92
	[username resignFirstResponder];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    93
	[password resignFirstResponder];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    94
}
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    95
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    96
-(IBAction) textFieldDoneEditing: (id)sender {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    97
	[sender resignFirstResponder];
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    98
}
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    99
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   100
-(IBAction) sliderChanged: (id) sender {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   101
	UISlider *slider = (UISlider *)sender;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   102
	int progress = slider.value;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   103
	NSString *newLabel = [[NSString alloc] initWithFormat:@"%d",progress];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   104
	self.volumeLabel.text = newLabel;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   105
	[newLabel release];
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   106
}
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   107
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   108
-(void) dealloc {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   109
	[username release];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   110
	[password release];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   111
	[musicOn release];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   112
	[effectsOn release];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   113
	[volumeLabel release];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   114
	[volumeSlider release];
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   115
    [super dealloc];
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   116
}
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   117
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   118
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   119
@end