author | koda |
Thu, 23 Sep 2010 01:29:20 +0200 | |
changeset 3898 | 0a9c3735a713 |
parent 3893 | 568bfd083465 |
child 3903 | db01c37494af |
permissions | -rw-r--r-- |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
1 |
/* |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
4 |
* |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
8 |
* |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
13 |
* |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
17 |
* |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
18 |
* File created on 22/09/2010. |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
19 |
*/ |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
20 |
|
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
21 |
|
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
22 |
#import "SavedGamesViewController.h" |
3898 | 23 |
#import "SDL_uikitappdelegate.h" |
24 |
#import "CommodityFunctions.h" |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
25 |
|
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
26 |
@implementation SavedGamesViewController |
3898 | 27 |
@synthesize tableView, listOfSavegames; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
28 |
|
3898 | 29 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
30 |
return rotationManager(interfaceOrientation); |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
31 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
32 |
|
3898 | 33 |
-(void) viewDidLoad { |
34 |
self.tableView.backgroundView = nil; |
|
35 |
||
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
36 |
[super viewDidLoad]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
37 |
} |
3898 | 38 |
|
39 |
-(void) viewWillAppear:(BOOL)animated { |
|
40 |
[super viewWillAppear:animated]; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
41 |
|
3898 | 42 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SAVES_DIRECTORY() error:NULL]; |
43 |
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
|
44 |
self.listOfSavegames = array; |
|
45 |
[array release]; |
|
46 |
||
47 |
[self.tableView reloadData]; |
|
48 |
} |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
49 |
|
3898 | 50 |
-(IBAction) buttonPressed:(id) sender { |
51 |
playSound(@"backSound"); |
|
52 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
|
53 |
} |
|
54 |
||
55 |
#pragma mark - |
|
56 |
#pragma mark Table view data source |
|
57 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
58 |
return 1; |
|
59 |
} |
|
60 |
||
61 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
62 |
return [self.listOfSavegames count]; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
63 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
64 |
|
3898 | 65 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
66 |
static NSString *CellIdentifier = @"Cell"; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
67 |
|
3898 | 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; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
77 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
78 |
|
3898 | 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]; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
92 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
93 |
|
3898 | 94 |
#pragma mark - |
95 |
#pragma mark Memory Management |
|
96 |
-(void) didReceiveMemoryWarning { |
|
97 |
[super didReceiveMemoryWarning]; |
|
98 |
} |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
99 |
|
3898 | 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]; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
109 |
[super dealloc]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
110 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
111 |
|
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
112 |
@end |