9 #import "GameConfigViewController.h" |
9 #import "GameConfigViewController.h" |
10 #import "SDL_uikitappdelegate.h" |
10 #import "SDL_uikitappdelegate.h" |
11 #import "CommodityFunctions.h" |
11 #import "CommodityFunctions.h" |
12 #import "TeamConfigViewController.h" |
12 #import "TeamConfigViewController.h" |
13 #import "SchemeWeaponConfigViewController.h" |
13 #import "SchemeWeaponConfigViewController.h" |
14 |
14 #import "UIImageExtra.h" |
15 |
15 |
16 @implementation GameConfigViewController |
16 @implementation GameConfigViewController |
17 |
17 @synthesize hedgehogImage, imgContainer; |
18 |
18 |
19 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
19 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
20 return rotationManager(interfaceOrientation); |
20 return rotationManager(interfaceOrientation); |
21 } |
21 } |
22 |
22 |
183 |
183 |
184 CGRect screen = [[UIScreen mainScreen] bounds]; |
184 CGRect screen = [[UIScreen mainScreen] bounds]; |
185 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
185 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
186 |
186 |
187 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
187 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
188 // load a base image that will be updated in viewWill Load |
|
189 NSString *filePath = [NSString stringWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()]; |
|
190 UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:filePath andCutAt:CGRectMake(96, 0, 32, 32)]; |
|
191 self.hedgehogImage = sprite; |
|
192 [sprite release]; |
|
193 srandom(time(NULL)); |
|
194 |
|
195 // load other controllers |
188 if (mapConfigViewController == nil) |
196 if (mapConfigViewController == nil) |
189 mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
197 mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
190 mapConfigViewController.delegate = self; |
198 mapConfigViewController.delegate = self; |
191 if (teamConfigViewController == nil) |
199 if (teamConfigViewController == nil) |
192 teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
200 teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
211 |
219 |
212 [super viewDidLoad]; |
220 [super viewDidLoad]; |
213 } |
221 } |
214 |
222 |
215 -(void) viewWillAppear:(BOOL)animated { |
223 -(void) viewWillAppear:(BOOL)animated { |
|
224 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
225 NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL]; |
|
226 int numberOfHats = [hatArray count]; |
|
227 if (self.imgContainer == nil) |
|
228 self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)]; |
|
229 |
|
230 for (int i=0; i < 1 + random()%40; i++) { |
|
231 NSString *hat = [hatArray objectAtIndex:random()%numberOfHats]; |
|
232 |
|
233 NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat]; |
|
234 UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)]; |
|
235 [hatFile release]; |
|
236 UIImage *hogWithHat = [self.hedgehogImage mergeWith:hatSprite atPoint:CGPointMake(0, -5)]; |
|
237 [hatSprite release]; |
|
238 |
|
239 UIImageView *hog = [[UIImageView alloc] initWithImage:hogWithHat]; |
|
240 hog.frame = CGRectMake(10*(i+1)+random()%30, 30, 32, 32); |
|
241 [self.imgContainer addSubview:hog]; |
|
242 [hog release]; |
|
243 } |
|
244 [self.view addSubview:self.imgContainer]; |
|
245 } |
|
246 |
216 [mapConfigViewController viewWillAppear:animated]; |
247 [mapConfigViewController viewWillAppear:animated]; |
217 [teamConfigViewController viewWillAppear:animated]; |
248 [teamConfigViewController viewWillAppear:animated]; |
218 [schemeWeaponConfigViewController viewWillAppear:animated]; |
249 [schemeWeaponConfigViewController viewWillAppear:animated]; |
219 // ADD other controllers here |
250 // add other controllers here and below |
220 |
251 |
221 [super viewWillAppear:animated]; |
252 [super viewWillAppear:animated]; |
222 } |
253 } |
223 |
254 |
224 -(void) viewDidAppear:(BOOL)animated { |
255 -(void) viewDidAppear:(BOOL)animated { |
234 [schemeWeaponConfigViewController viewWillDisappear:animated]; |
265 [schemeWeaponConfigViewController viewWillDisappear:animated]; |
235 [super viewWillDisappear:animated]; |
266 [super viewWillDisappear:animated]; |
236 } |
267 } |
237 |
268 |
238 -(void) viewDidDisappear:(BOOL)animated { |
269 -(void) viewDidDisappear:(BOOL)animated { |
|
270 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
271 [self.imgContainer removeFromSuperview]; |
|
272 releaseAndNil(self.imgContainer); |
|
273 } |
|
274 |
239 [mapConfigViewController viewDidDisappear:animated]; |
275 [mapConfigViewController viewDidDisappear:animated]; |
240 [teamConfigViewController viewDidDisappear:animated]; |
276 [teamConfigViewController viewDidDisappear:animated]; |
241 [schemeWeaponConfigViewController viewDidDisappear:animated]; |
277 [schemeWeaponConfigViewController viewDidDisappear:animated]; |
242 [super viewDidDisappear:animated]; |
278 [super viewDidDisappear:animated]; |
243 } |
279 } |
244 |
280 |
245 -(void) didReceiveMemoryWarning { |
281 -(void) didReceiveMemoryWarning { |
|
282 // Releases the view if it doesn't have a superview. |
246 if (activeController.view.superview == nil) |
283 if (activeController.view.superview == nil) |
247 activeController = nil; |
284 activeController = nil; |
248 // Releases the view if it doesn't have a superview. |
|
249 [super didReceiveMemoryWarning]; |
|
250 // Release any cached data, images, etc that aren't in use. |
|
251 if (mapConfigViewController.view.superview == nil) |
285 if (mapConfigViewController.view.superview == nil) |
252 mapConfigViewController = nil; |
286 mapConfigViewController = nil; |
253 if (teamConfigViewController.view.superview == nil) |
287 if (teamConfigViewController.view.superview == nil) |
254 teamConfigViewController = nil; |
288 teamConfigViewController = nil; |
255 if (schemeWeaponConfigViewController.view.superview == nil) |
289 if (schemeWeaponConfigViewController.view.superview == nil) |
256 schemeWeaponConfigViewController = nil; |
290 schemeWeaponConfigViewController = nil; |
|
291 // Release any cached data, images, etc that aren't in use. |
|
292 |
|
293 self.imgContainer = nil; |
|
294 [super didReceiveMemoryWarning]; |
257 MSG_MEMCLEAN(); |
295 MSG_MEMCLEAN(); |
258 } |
296 } |
259 |
297 |
260 -(void) viewDidUnload { |
298 -(void) viewDidUnload { |
|
299 hedgehogImage = nil; |
|
300 imgContainer = nil; |
261 activeController = nil; |
301 activeController = nil; |
262 mapConfigViewController = nil; |
302 mapConfigViewController = nil; |
263 teamConfigViewController = nil; |
303 teamConfigViewController = nil; |
264 schemeWeaponConfigViewController = nil; |
304 schemeWeaponConfigViewController = nil; |
265 MSG_DIDUNLOAD(); |
305 MSG_DIDUNLOAD(); |
266 [super viewDidUnload]; |
306 [super viewDidUnload]; |
267 } |
307 } |
268 |
308 |
269 -(void) dealloc { |
309 -(void) dealloc { |
|
310 [hedgehogImage release]; |
|
311 [imgContainer release]; |
270 [mapConfigViewController release]; |
312 [mapConfigViewController release]; |
271 [teamConfigViewController release]; |
313 [teamConfigViewController release]; |
272 [schemeWeaponConfigViewController release]; |
314 [schemeWeaponConfigViewController release]; |
273 [super dealloc]; |
315 [super dealloc]; |
274 } |
316 } |