60 } |
61 } |
61 } |
62 } |
62 |
63 |
63 // add a team file with default values and updates the table |
64 // add a team file with default values and updates the table |
64 -(void) addTeam:(id) sender { |
65 -(void) addTeam:(id) sender { |
65 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
|
66 NSString *teamsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/Teams/"]; |
|
67 [[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory |
|
68 withIntermediateDirectories:NO |
|
69 attributes:nil |
|
70 error:NULL]; |
|
71 |
|
72 NSMutableArray *hedgehogs = [[NSMutableArray alloc] init]; |
|
73 |
|
74 for (int i = 0; i < 8; i++) { |
|
75 NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i]; |
|
76 NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level", |
|
77 hogName,@"hogname",@"NoHat",@"hat",nil]; |
|
78 [hogName release]; |
|
79 [hedgehogs addObject:hog]; |
|
80 [hog release]; |
|
81 } |
|
82 |
|
83 NSString *fileName = [[NSString alloc] initWithFormat:@"Default Team %u.plist", [self.listOfTeams count]]; |
66 NSString *fileName = [[NSString alloc] initWithFormat:@"Default Team %u.plist", [self.listOfTeams count]]; |
84 |
67 |
85 NSDictionary *defaultTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash", |
68 createTeamNamed([fileName stringByDeletingPathExtension]); |
86 [fileName stringByDeletingPathExtension],@"teamname",@"Statue",@"grave",@"Plane",@"fort", |
|
87 @"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs,@"hedgehogs",nil]; |
|
88 [hedgehogs release]; |
|
89 |
|
90 NSString *defaultTeamFile = [[NSString alloc] initWithFormat:@"%@/%@",teamsDirectory, fileName]; |
|
91 [defaultTeam writeToFile:defaultTeamFile atomically:YES]; |
|
92 [defaultTeamFile release]; |
|
93 [defaultTeam release]; |
|
94 |
69 |
95 [self.listOfTeams addObject:fileName]; |
70 [self.listOfTeams addObject:fileName]; |
96 [fileName release]; |
71 [fileName release]; |
97 |
72 |
98 [self.tableView reloadData]; |
73 [self.tableView reloadData]; |
99 |
|
100 } |
74 } |
101 |
75 |
102 #pragma mark - |
76 #pragma mark - |
103 #pragma mark Table view data source |
77 #pragma mark Table view data source |
104 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
78 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
105 // Return the number of sections. |
|
106 return 1; |
79 return 1; |
107 } |
80 } |
108 |
81 |
109 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
82 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
110 // Return the number of rows in the section. |
|
111 return [listOfTeams count]; |
83 return [listOfTeams count]; |
112 } |
84 } |
113 |
85 |
114 // Customize the appearance of table view cells. |
86 // Customize the appearance of table view cells. |
115 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
87 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
180 |
152 |
181 NSInteger row = [indexPath row]; |
153 NSInteger row = [indexPath row]; |
182 NSString *selectedTeamFile = [listOfTeams objectAtIndex:row]; |
154 NSString *selectedTeamFile = [listOfTeams objectAtIndex:row]; |
183 NSLog(@"%@",selectedTeamFile); |
155 NSLog(@"%@",selectedTeamFile); |
184 |
156 |
185 // load data about the team and extract info |
157 // load data about the team and extract info |
186 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
158 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
187 NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/Teams/%@",[paths objectAtIndex:0],selectedTeamFile]; |
159 NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/Teams/%@",[paths objectAtIndex:0],selectedTeamFile]; |
188 NSMutableDictionary *teamDict = [[NSMutableDictionary alloc] initWithContentsOfFile:teamFile]; |
160 NSMutableDictionary *teamDict = [[NSMutableDictionary alloc] initWithContentsOfFile:teamFile]; |
189 [teamFile release]; |
161 [teamFile release]; |
190 childController.teamDictionary = teamDict; |
162 childController.teamDictionary = teamDict; |
191 [teamDict release]; |
163 [teamDict release]; |
192 |
164 |
|
165 [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
166 |
193 // this must be set so childController can load the correct plist |
167 // this must be set so childController can load the correct plist |
194 //childController.title = [[listOfTeams objectAtIndex:row] stringByDeletingPathExtension]; |
168 //childController.title = [[listOfTeams objectAtIndex:row] stringByDeletingPathExtension]; |
195 [self.navigationController pushViewController:childController animated:YES]; |
169 [self.navigationController pushViewController:childController animated:YES]; |
196 } |
170 } |
197 |
171 |