82 NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
82 NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
83 UIImage *img = [[UIImage alloc] initWithContentsOfFile:str]; |
83 UIImage *img = [[UIImage alloc] initWithContentsOfFile:str]; |
84 self.ammoStoreImage = img; |
84 self.ammoStoreImage = img; |
85 [img release]; |
85 [img release]; |
86 |
86 |
87 self.tableView.rowHeight = 120; |
87 self.title = NSLocalizedString(@"Edit weapons preferences",@""); |
88 } |
88 } |
89 |
89 |
90 -(void) viewWillAppear:(BOOL) animated { |
90 -(void) viewWillAppear:(BOOL) animated { |
91 [super viewWillAppear:animated]; |
91 [super viewWillAppear:animated]; |
92 |
92 |
93 NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.title]; |
93 NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName]; |
94 NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile]; |
94 NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile]; |
95 [ammoFile release]; |
95 [ammoFile release]; |
96 |
96 |
97 const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String]; |
97 const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String]; |
98 const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String]; |
98 const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String]; |
137 quantityStr,@"ammostore_initialqt", |
140 quantityStr,@"ammostore_initialqt", |
138 probabilityStr,@"ammostore_probability", |
141 probabilityStr,@"ammostore_probability", |
139 delayStr,@"ammostore_delay", |
142 delayStr,@"ammostore_delay", |
140 cratenessStr,@"ammostore_crate", nil]; |
143 cratenessStr,@"ammostore_crate", nil]; |
141 |
144 |
142 NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.title]; |
145 NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName]; |
143 [weapon writeToFile:ammoFile atomically:YES]; |
146 [weapon writeToFile:ammoFile atomically:YES]; |
144 [ammoFile release]; |
147 [ammoFile release]; |
145 [weapon release]; |
148 [weapon release]; |
146 } |
149 } |
147 |
150 |
148 #pragma mark - |
151 #pragma mark - |
149 #pragma mark Table view data source |
152 #pragma mark Table view data source |
150 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
153 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
151 return 1; |
154 return 2; |
152 } |
155 } |
153 |
156 |
154 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
157 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
155 return CURRENT_AMMOSIZE; |
158 if (section == 0) |
|
159 return 1; |
|
160 else |
|
161 return CURRENT_AMMOSIZE; |
156 } |
162 } |
157 |
163 |
158 // Customize the appearance of table view cells. |
164 // Customize the appearance of table view cells. |
159 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
165 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
160 static NSString *CellIdentifier = @"Cell"; |
166 static NSString *CellIdentifier0 = @"Cell0"; |
|
167 static NSString *CellIdentifier1 = @"Cell1"; |
161 NSInteger row = [indexPath row]; |
168 NSInteger row = [indexPath row]; |
162 |
169 UITableViewCell *cell = nil; |
163 WeaponCellView *cell = (WeaponCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
170 |
164 if (cell == nil) { |
171 if (0 == [indexPath section]) { |
165 cell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
172 EditableCellView *customCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
166 cell.delegate = self; |
173 if (customCell == nil) { |
167 } |
174 customCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault |
168 |
175 reuseIdentifier:CellIdentifier0] autorelease]; |
169 int x = ((row*32)/1024)*32; |
176 customCell.delegate = self; |
170 int y = (row*32)%1024; |
177 } |
171 |
178 |
172 UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)]; |
179 customCell.textField.text = self.weaponName; |
173 cell.weaponIcon.image = img; |
180 customCell.detailTextLabel.text = nil; |
174 cell.weaponName.text = [ammoNames objectAtIndex:row]; |
181 customCell.imageView.image = nil; |
175 cell.tag = row; |
182 customCell.selectionStyle = UITableViewCellSelectionStyleNone; |
176 |
183 cell = customCell; |
177 [cell.initialQt setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO]; |
184 } else { |
178 [cell.probabilityQt setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO]; |
185 WeaponCellView *customCell = (WeaponCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
179 [cell.delayQt setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO]; |
186 if (customCell == nil) { |
180 [cell.crateQt setValue:[[NSString stringWithFormat:@"%c", crateness[row]] intValue] animated:NO]; |
187 customCell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
|
188 customCell.delegate = self; |
|
189 } |
|
190 |
|
191 int x = ((row*32)/1024)*32; |
|
192 int y = (row*32)%1024; |
|
193 |
|
194 UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)]; |
|
195 customCell.weaponIcon.image = img; |
|
196 customCell.weaponName.text = [ammoNames objectAtIndex:row]; |
|
197 customCell.tag = row; |
|
198 |
|
199 [customCell.initialQt setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO]; |
|
200 [customCell.probabilityQt setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO]; |
|
201 [customCell.delayQt setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO]; |
|
202 [customCell.crateQt setValue:[[NSString stringWithFormat:@"%c", crateness[row]] intValue] animated:NO]; |
|
203 cell = customCell; |
|
204 } |
181 |
205 |
182 cell.selectionStyle = UITableViewCellSelectionStyleNone; |
206 cell.selectionStyle = UITableViewCellSelectionStyleNone; |
183 return cell; |
207 return cell; |
184 } |
208 } |
185 |
209 |
|
210 -(CGFloat) tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
211 if (0 == [indexPath section]) |
|
212 return aTableView.rowHeight; |
|
213 else |
|
214 return 120; |
|
215 } |
186 |
216 |
187 #pragma mark - |
217 #pragma mark - |
188 #pragma mark Table view delegate |
218 #pragma mark Table view delegate |
189 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
219 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
190 // Navigation logic may go here. Create and push another view controller. |
220 if (0 == [indexPath section]) { |
191 /* |
221 EditableCellView *editableCell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath]; |
192 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; |
222 [editableCell replyKeyboard]; |
193 // ... |
223 } |
194 // Pass the selected object to the new view controller. |
224 } |
195 [self.navigationController pushViewController:detailViewController animated:YES]; |
225 |
196 [detailViewController release]; |
226 #pragma mark - |
197 */ |
227 #pragma mark editableCellView delegate |
|
228 // set the new value |
|
229 -(void) saveTextFieldValue:(NSString *)textString { |
|
230 // delete old file |
|
231 [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName] error:NULL]; |
|
232 // update filename |
|
233 self.weaponName = textString; |
|
234 // save new file |
|
235 [self saveAmmos]; |
198 } |
236 } |
199 |
237 |
200 #pragma mark - |
238 #pragma mark - |
201 #pragma mark WeaponButtonControllerDelegate |
239 #pragma mark WeaponButtonControllerDelegate |
202 -(void) updateValues:(NSArray *)withArray atIndex:(NSInteger) index { |
240 -(void) updateValues:(NSArray *)withArray atIndex:(NSInteger) index { |