18 * File created on 22/09/2010. |
18 * File created on 22/09/2010. |
19 */ |
19 */ |
20 |
20 |
21 |
21 |
22 #import "SavedGamesViewController.h" |
22 #import "SavedGamesViewController.h" |
23 |
23 #import "SDL_uikitappdelegate.h" |
|
24 #import "CommodityFunctions.h" |
24 |
25 |
25 @implementation SavedGamesViewController |
26 @implementation SavedGamesViewController |
|
27 @synthesize tableView, listOfSavegames; |
26 |
28 |
27 /* |
29 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
28 // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. |
30 return rotationManager(interfaceOrientation); |
29 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { |
|
30 if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { |
|
31 // Custom initialization |
|
32 } |
|
33 return self; |
|
34 } |
31 } |
35 */ |
|
36 |
32 |
37 /* |
33 -(void) viewDidLoad { |
38 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. |
34 self.tableView.backgroundView = nil; |
39 - (void)viewDidLoad { |
35 |
40 [super viewDidLoad]; |
36 [super viewDidLoad]; |
41 } |
37 } |
42 */ |
|
43 |
38 |
|
39 -(void) viewWillAppear:(BOOL)animated { |
|
40 [super viewWillAppear:animated]; |
44 |
41 |
45 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
42 NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SAVES_DIRECTORY() error:NULL]; |
46 // Overriden to allow any orientation. |
43 NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
47 return YES; |
44 self.listOfSavegames = array; |
|
45 [array release]; |
|
46 |
|
47 [self.tableView reloadData]; |
48 } |
48 } |
49 |
49 |
50 |
50 -(IBAction) buttonPressed:(id) sender { |
51 - (void)didReceiveMemoryWarning { |
51 playSound(@"backSound"); |
52 // Releases the view if it doesn't have a superview. |
52 [[self parentViewController] dismissModalViewControllerAnimated:YES]; |
53 [super didReceiveMemoryWarning]; |
|
54 |
|
55 // Release any cached data, images, etc that aren't in use. |
|
56 } |
53 } |
57 |
54 |
58 |
55 #pragma mark - |
59 - (void)viewDidUnload { |
56 #pragma mark Table view data source |
60 [super viewDidUnload]; |
57 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
61 // Release any retained subviews of the main view. |
58 return 1; |
62 // e.g. self.myOutlet = nil; |
|
63 } |
59 } |
64 |
60 |
|
61 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
62 return [self.listOfSavegames count]; |
|
63 } |
65 |
64 |
66 - (void)dealloc { |
65 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
66 static NSString *CellIdentifier = @"Cell"; |
|
67 |
|
68 UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
69 if (cell == nil) |
|
70 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; |
|
71 |
|
72 // first all the names, then the title (which is offset 5) |
|
73 cell.textLabel.text = [[self.listOfSavegames objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; |
|
74 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
75 |
|
76 return cell; |
|
77 } |
|
78 |
|
79 #pragma mark - |
|
80 #pragma mark Table view delegate |
|
81 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
82 [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
83 |
|
84 NSString *filePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:[indexPath row]]]; |
|
85 |
|
86 NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys: |
|
87 [NSDictionary dictionary],@"game_dictionary", |
|
88 filePath,@"savefile", |
|
89 [NSNumber numberWithBool:NO],@"netgame", |
|
90 nil]; |
|
91 [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; |
|
92 } |
|
93 |
|
94 #pragma mark - |
|
95 #pragma mark Memory Management |
|
96 -(void) didReceiveMemoryWarning { |
|
97 [super didReceiveMemoryWarning]; |
|
98 } |
|
99 |
|
100 -(void) viewDidUnload { |
|
101 self.tableView = nil; |
|
102 self.listOfSavegames = nil; |
|
103 [super viewDidUnload]; |
|
104 } |
|
105 |
|
106 -(void) dealloc { |
|
107 [tableView release]; |
|
108 [listOfSavegames release]; |
67 [super dealloc]; |
109 [super dealloc]; |
68 } |
110 } |
69 |
111 |
70 |
|
71 @end |
112 @end |