author | koda |
Fri, 15 Jan 2010 10:03:31 +0000 | |
changeset 2696 | 41aa7b56c17b |
parent 2694 | dcd248e04f3d |
child 2698 | 90585aba87ad |
permissions | -rw-r--r-- |
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" |
2696 | 10 |
#import "SDL_uikitappdelegate.h" |
2687
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 |
|
2696 | 14 |
@synthesize username, password, musicOn, effectsOn, altDamageOn, volumeSlider, volumeLabel; |
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
15 |
|
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
16 |
-(void) viewDidLoad { |
2696 | 17 |
NSString *filePath = [SDLUIKitDelegate dataFilePath:@"settings.plist"]; |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
18 |
|
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
19 |
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
|
20 |
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
|
21 |
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
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
} else { |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
26 |
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
|
27 |
} |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
28 |
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
|
29 |
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
|
30 |
} else { |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
31 |
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
|
32 |
} |
2696 | 33 |
if (1 == [[data objectForKey:@"alternate"] intValue]) { |
34 |
altDamageOn.on = YES; |
|
35 |
} else { |
|
36 |
altDamageOn.on = NO; |
|
37 |
} |
|
38 |
||
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
39 |
[volumeSlider setValue:[[data objectForKey:@"volume"] intValue] animated:NO]; |
2696 | 40 |
|
2694
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]; |
2696 | 44 |
} else { |
45 |
[NSException raise:@"File NOT found" format:@"The file settings.plist was not found at %@", filePath]; |
|
2694
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]; |
2696 | 53 |
*/ |
54 |
[super viewDidLoad]; |
|
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
55 |
} |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
56 |
|
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
57 |
-(void) viewDidUnload { |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
self.effectsOn = nil; |
2696 | 62 |
self.altDamageOn = nil; |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
[super viewDidUnload]; |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
66 |
} |
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
67 |
|
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
68 |
//- (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
|
69 |
-(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
|
70 |
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
|
71 |
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
|
72 |
NSString *tmpEff = (effectsOn.on) ? @"1" : @"0"; |
2696 | 73 |
NSString *tmpAlt = (altDamageOn.on) ? @"1" : @"0"; |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
74 |
|
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: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
|
76 |
[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
|
77 |
[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
|
78 |
[saveArray setObject:tmpEff forKey:@"effects"]; |
2696 | 79 |
[saveArray setObject:tmpAlt forKey:@"alternate"]; |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
80 |
[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
|
81 |
|
2696 | 82 |
[saveArray writeToFile:[SDLUIKitDelegate dataFilePath:@"settings.plist"] atomically:YES]; |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
83 |
[saveArray release]; |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
84 |
[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
|
85 |
} |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
86 |
|
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
87 |
/* |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
88 |
// 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
|
89 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
90 |
// Return YES for supported orientations |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
91 |
return (interfaceOrientation == UIInterfaceOrientationPortrait); |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
92 |
} |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
93 |
*/ |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
94 |
|
2696 | 95 |
// makes the keyboard go away when background is tapped |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
96 |
-(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
|
97 |
[username resignFirstResponder]; |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
98 |
[password resignFirstResponder]; |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
99 |
} |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
100 |
|
2696 | 101 |
// makes the keyboard go away when "Done" is tapped |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
102 |
-(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
|
103 |
[sender resignFirstResponder]; |
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
104 |
} |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
105 |
|
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
106 |
-(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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
[newLabel release]; |
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
112 |
} |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
113 |
|
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
114 |
-(void) dealloc { |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
115 |
[username release]; |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
116 |
[password release]; |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
117 |
[musicOn release]; |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
118 |
[effectsOn release]; |
2696 | 119 |
[altDamageOn release]; |
2694
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
120 |
[volumeLabel release]; |
dcd248e04f3d
can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents:
2687
diff
changeset
|
121 |
[volumeSlider release]; |
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
122 |
[super dealloc]; |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
123 |
} |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
124 |
|
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
125 |
|
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
diff
changeset
|
126 |
@end |