37 @property (retain, nonatomic) IBOutlet UIButton *simpleGameButton; |
37 @property (retain, nonatomic) IBOutlet UIButton *simpleGameButton; |
38 @property (retain, nonatomic) IBOutlet UIButton *missionsButton; |
38 @property (retain, nonatomic) IBOutlet UIButton *missionsButton; |
39 @end |
39 @end |
40 |
40 |
41 @implementation MainMenuViewController |
41 @implementation MainMenuViewController |
42 @synthesize gameConfigViewController, settingsViewController, aboutViewController, savedGamesViewController, |
|
43 restoreViewController, missionsViewController; |
|
44 |
42 |
45 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
43 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
46 return rotationManager(interfaceOrientation); |
44 return rotationManager(interfaceOrientation); |
47 } |
45 } |
48 |
46 |
71 [CreationChamber createFirstLaunch]; |
69 [CreationChamber createFirstLaunch]; |
72 } |
70 } |
73 |
71 |
74 // prompt for restoring any previous game |
72 // prompt for restoring any previous game |
75 NSString *saveString = [userDefaults objectForKey:@"savedGamePath"]; |
73 NSString *saveString = [userDefaults objectForKey:@"savedGamePath"]; |
76 if (saveString != nil && [saveString isEqualToString:@""] == NO && [[userDefaults objectForKey:@"saveIsValid"] boolValue]) { |
74 if (saveString != nil && [saveString isEqualToString:@""] == NO && [[userDefaults objectForKey:@"saveIsValid"] boolValue]) |
77 if (self.restoreViewController == nil) { |
75 { |
78 NSString *xibName = [@"RestoreViewController-" stringByAppendingString:(IS_IPAD() ? @"iPad" : @"iPhone")]; |
76 NSString *xibName = [@"RestoreViewController-" stringByAppendingString:(IS_IPAD() ? @"iPad" : @"iPhone")]; |
79 RestoreViewController *restored = [[RestoreViewController alloc] initWithNibName:xibName bundle:nil]; |
77 RestoreViewController *restored = [[RestoreViewController alloc] initWithNibName:xibName bundle:nil]; |
80 if ([restored respondsToSelector:@selector(setModalPresentationStyle:)]) |
78 if ([restored respondsToSelector:@selector(setModalPresentationStyle:)]) |
81 restored.modalPresentationStyle = UIModalPresentationFormSheet; |
79 restored.modalPresentationStyle = UIModalPresentationFormSheet; |
82 self.restoreViewController = restored; |
80 |
83 [restored release]; |
81 [self performSelector:@selector(presentViewController:) withObject:restored afterDelay:0.25]; |
84 } |
82 } |
85 [self performSelector:@selector(presentViewController:) withObject:self.restoreViewController afterDelay:0.25]; |
83 else |
86 } else { |
84 { |
87 // let's not prompt for rating when app crashed >_> |
85 // let's not prompt for rating when app crashed >_> |
88 [Appirater appLaunched]; |
86 [Appirater appLaunched]; |
89 } |
87 } |
90 |
88 |
91 /* |
89 /* |
110 NSString *xib = nil; |
109 NSString *xib = nil; |
111 |
110 |
112 [[AudioManagerController mainManager] playClickSound]; |
111 [[AudioManagerController mainManager] playClickSound]; |
113 switch (button.tag) { |
112 switch (button.tag) { |
114 case 0: |
113 case 0: |
115 if (nil == self.gameConfigViewController) { |
114 xib = IS_IPAD() ? @"GameConfigViewController-iPad" : @"GameConfigViewController-iPhone"; |
116 xib = IS_IPAD() ? @"GameConfigViewController-iPad" : @"GameConfigViewController-iPhone"; |
115 |
117 |
116 GameConfigViewController *gcvc = [[GameConfigViewController alloc] initWithNibName:xib bundle:nil]; |
118 GameConfigViewController *gcvc = [[GameConfigViewController alloc] initWithNibName:xib bundle:nil]; |
117 gcvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
119 gcvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
118 |
120 self.gameConfigViewController = gcvc; |
119 [self presentViewController:gcvc animated:YES completion:nil]; |
121 [gcvc release]; |
120 [gcvc release]; |
122 } |
|
123 [self presentViewController:self.gameConfigViewController animated:YES completion:nil]; |
|
124 break; |
121 break; |
125 case 2: |
122 case 2: |
126 if (nil == self.settingsViewController) { |
123 { |
127 SettingsContainerViewController *svrc = [[SettingsContainerViewController alloc] initWithNibName:nil bundle:nil]; |
124 SettingsContainerViewController *svrc = [[SettingsContainerViewController alloc] initWithNibName:nil bundle:nil]; |
128 svrc.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
125 svrc.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
129 self.settingsViewController = svrc; |
126 |
|
127 [self presentViewController:svrc animated:YES completion:nil]; |
130 [svrc release]; |
128 [svrc release]; |
131 } |
129 } |
132 [self presentViewController:self.settingsViewController animated:YES completion:nil]; |
|
133 break; |
130 break; |
134 case 3: |
131 case 3: |
135 #ifdef DEBUG |
132 #ifdef DEBUG |
136 { |
133 { |
137 GameLogViewController *gameLogVC = [[GameLogViewController alloc] init]; |
134 GameLogViewController *gameLogVC = [[GameLogViewController alloc] init]; |
140 |
137 |
141 [self presentViewController:navController animated:YES completion:nil]; |
138 [self presentViewController:navController animated:YES completion:nil]; |
142 [navController release]; |
139 [navController release]; |
143 } |
140 } |
144 #else |
141 #else |
145 if (nil == self.aboutViewController) { |
142 { |
146 AboutViewController *about = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil]; |
143 AboutViewController *about = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil]; |
147 about.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
144 about.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
148 if ([about respondsToSelector:@selector(setModalPresentationStyle:)]) |
145 if ([about respondsToSelector:@selector(setModalPresentationStyle:)]) |
149 about.modalPresentationStyle = UIModalPresentationFormSheet; |
146 about.modalPresentationStyle = UIModalPresentationFormSheet; |
150 self.aboutViewController = about; |
147 |
|
148 [self presentViewController:about animated:YES completion:nil]; |
151 [about release]; |
149 [about release]; |
152 } |
150 } |
153 [self presentViewController:self.aboutViewController animated:YES completion:nil]; |
|
154 #endif |
151 #endif |
155 break; |
152 break; |
156 case 4: |
153 case 4: |
157 if (nil == self.savedGamesViewController) { |
154 { |
158 SavedGamesViewController *savedgames = [[SavedGamesViewController alloc] initWithNibName:@"SavedGamesViewController" bundle:nil]; |
155 SavedGamesViewController *savedgames = [[SavedGamesViewController alloc] initWithNibName:@"SavedGamesViewController" bundle:nil]; |
159 savedgames.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
156 savedgames.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
160 if ([savedgames respondsToSelector:@selector(setModalPresentationStyle:)]) |
157 if ([savedgames respondsToSelector:@selector(setModalPresentationStyle:)]) |
161 savedgames.modalPresentationStyle = UIModalPresentationPageSheet; |
158 savedgames.modalPresentationStyle = UIModalPresentationPageSheet; |
162 self.savedGamesViewController = savedgames; |
159 |
|
160 [self presentViewController:savedgames animated:YES completion:nil]; |
163 [savedgames release]; |
161 [savedgames release]; |
164 } |
162 } |
165 [self presentViewController:self.savedGamesViewController animated:YES completion:nil]; |
|
166 break; |
163 break; |
167 case 5: |
164 case 5: |
168 if (nil == self.missionsViewController) { |
165 { |
169 xib = IS_IPAD() ? @"MissionTrainingViewController-iPad" : @"MissionTrainingViewController-iPhone"; |
166 xib = IS_IPAD() ? @"MissionTrainingViewController-iPad" : @"MissionTrainingViewController-iPhone"; |
170 MissionTrainingViewController *missions = [[MissionTrainingViewController alloc] initWithNibName:xib bundle:nil]; |
167 MissionTrainingViewController *missions = [[MissionTrainingViewController alloc] initWithNibName:xib bundle:nil]; |
171 missions.modalTransitionStyle = IS_IPAD() ? UIModalTransitionStyleCoverVertical : UIModalTransitionStyleCrossDissolve; |
168 missions.modalTransitionStyle = IS_IPAD() ? UIModalTransitionStyleCoverVertical : UIModalTransitionStyleCrossDissolve; |
172 if ([missions respondsToSelector:@selector(setModalPresentationStyle:)]) |
169 if ([missions respondsToSelector:@selector(setModalPresentationStyle:)]) |
173 missions.modalPresentationStyle = UIModalPresentationPageSheet; |
170 missions.modalPresentationStyle = UIModalPresentationPageSheet; |
174 self.missionsViewController = missions; |
171 |
|
172 [self presentViewController:missions animated:YES completion:nil]; |
175 [missions release]; |
173 [missions release]; |
176 } |
174 } |
177 [self presentViewController:self.missionsViewController animated:YES completion:nil]; |
|
178 break; |
175 break; |
179 case 6: |
176 case 6: |
180 [GameInterfaceBridge registerCallingController:self]; |
177 [GameInterfaceBridge registerCallingController:self]; |
181 [GameInterfaceBridge startSimpleGame]; |
178 [GameInterfaceBridge startSimpleGame]; |
182 break; |
179 break; |
192 } |
189 } |
193 } |
190 } |
194 |
191 |
195 #pragma mark - |
192 #pragma mark - |
196 -(void) viewDidUnload { |
193 -(void) viewDidUnload { |
197 self.gameConfigViewController = nil; |
|
198 self.settingsViewController = nil; |
|
199 self.aboutViewController = nil; |
|
200 self.savedGamesViewController = nil; |
|
201 self.restoreViewController = nil; |
|
202 self.missionsViewController = nil; |
|
203 MSG_DIDUNLOAD(); |
194 MSG_DIDUNLOAD(); |
204 [super viewDidUnload]; |
195 [super viewDidUnload]; |
205 } |
196 } |
206 |
197 |
207 -(void) didReceiveMemoryWarning { |
198 -(void) didReceiveMemoryWarning { |
208 if (self.settingsViewController.view.superview == nil) |
|
209 self.settingsViewController = nil; |
|
210 if (self.gameConfigViewController.view.superview == nil) |
|
211 self.gameConfigViewController = nil; |
|
212 if (self.aboutViewController.view.superview == nil) |
|
213 self.aboutViewController = nil; |
|
214 if (self.savedGamesViewController.view.superview == nil) |
|
215 self.savedGamesViewController = nil; |
|
216 if (self.restoreViewController.view.superview == nil) |
|
217 self.restoreViewController = nil; |
|
218 if (self.missionsViewController.view.superview == nil) |
|
219 self.missionsViewController = nil; |
|
220 MSG_MEMCLEAN(); |
199 MSG_MEMCLEAN(); |
221 [super didReceiveMemoryWarning]; |
200 [super didReceiveMemoryWarning]; |
222 } |
201 } |
223 |
202 |
224 -(void) dealloc { |
203 -(void) dealloc { |
225 releaseAndNil(settingsViewController); |
|
226 releaseAndNil(gameConfigViewController); |
|
227 releaseAndNil(aboutViewController); |
|
228 releaseAndNil(savedGamesViewController); |
|
229 releaseAndNil(restoreViewController); |
|
230 releaseAndNil(missionsViewController); |
|
231 [_simpleGameButton release]; |
204 [_simpleGameButton release]; |
232 [_missionsButton release]; |
205 [_missionsButton release]; |
233 [super dealloc]; |
206 [super dealloc]; |
234 } |
207 } |
235 |
208 |