23 |
23 |
24 #define LABEL_TAG 12345 |
24 #define LABEL_TAG 12345 |
25 #define SLIDER_TAG 54321 |
25 #define SLIDER_TAG 54321 |
26 #define SWITCH_TAG 67890 |
26 #define SWITCH_TAG 67890 |
27 |
27 |
28 #define checkValueString(detailString,labelSting,sliderRef); \ |
|
29 if ([labelSting isEqualToString:@"Turn Time"] && (NSInteger) sliderRef.value == 100) \ |
|
30 detailString = @"∞"; \ |
|
31 else if ([labelSting isEqualToString:@"Water Rise Amount"] && (NSInteger) sliderRef.value == 100) \ |
|
32 detailString = NSLocalizedString(@"Nvr",@"Short for 'Never'"); \ |
|
33 else if ([labelSting isEqualToString:@"Crate Drop Turns"] && (NSInteger) sliderRef.value == 0) \ |
|
34 detailString = NSLocalizedString(@"Nvr",@"Short for 'Never'"); \ |
|
35 else if ([labelSting isEqualToString:@"Mines Time"] && (NSInteger) sliderRef.value == -1) \ |
|
36 detailString = NSLocalizedString(@"Rnd",@"Short for 'Random'"); \ |
|
37 else \ |
|
38 detailString = [NSString stringWithFormat:@"%d",(NSInteger) sliderRef.value]; |
|
39 |
|
40 |
28 |
41 @implementation SingleSchemeViewController |
29 @implementation SingleSchemeViewController |
42 @synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray; |
30 @synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray; |
43 |
31 |
44 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
32 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
188 [[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]]; |
176 [[self.basicSettingList objectAtIndex:row] objectForKey:@"image"]]]; |
189 cell.imageView.image = img; |
177 cell.imageView.image = img; |
190 [img release]; |
178 [img release]; |
191 |
179 |
192 UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
180 UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
193 cellLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"]; |
181 NSString *basicSettingTitleKey = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"]; |
|
182 cellLabel.text = NSLocalizedStringFromTable(basicSettingTitleKey, @"Scheme", nil); |
194 cellLabel.adjustsFontSizeToFitWidth = YES; |
183 cellLabel.adjustsFontSizeToFitWidth = YES; |
195 |
184 |
196 // can't use the viewWithTag method because row is dynamic |
185 // can't use the viewWithTag method because row is dynamic |
197 UISlider *cellSlider = nil; |
186 UISlider *cellSlider = nil; |
198 for (UIView *oneView in cell.contentView.subviews) { |
187 for (UIView *oneView in cell.contentView.subviews) { |
218 sliderLength = 285; |
207 sliderLength = 285; |
219 } |
208 } |
220 } |
209 } |
221 cellSlider.frame = CGRectMake(hOffset, vOffset, sliderLength, 23); |
210 cellSlider.frame = CGRectMake(hOffset, vOffset, sliderLength, 23); |
222 |
211 |
223 NSString *prestring = nil; |
212 NSString *prestring = [self localizedValueStringForKey:basicSettingTitleKey andSlider:cellSlider]; |
224 checkValueString(prestring,cellLabel.text,cellSlider); |
|
225 |
213 |
226 // forced to use this weird format otherwise the label disappears when size of the text is bigger than the original |
214 // forced to use this weird format otherwise the label disappears when size of the text is bigger than the original |
227 while ([prestring length] <= 4) |
215 while ([prestring length] <= 4) |
228 prestring = [NSString stringWithFormat:@" %@",prestring]; |
216 prestring = [NSString stringWithFormat:@" %@",prestring]; |
229 cell.detailTextLabel.text = prestring; |
217 cell.detailTextLabel.text = prestring; |
249 [[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]]; |
237 [[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]]; |
250 cell.imageView.image = image; |
238 cell.imageView.image = image; |
251 [image release]; |
239 [image release]; |
252 cell.imageView.layer.cornerRadius = 6.0f; |
240 cell.imageView.layer.cornerRadius = 6.0f; |
253 cell.imageView.layer.masksToBounds = YES; |
241 cell.imageView.layer.masksToBounds = YES; |
254 cell.textLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"]; |
242 NSString *gameModTitleKey = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"]; |
255 cell.detailTextLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"]; |
243 cell.textLabel.text = NSLocalizedStringFromTable(gameModTitleKey, @"Scheme", nil); |
|
244 NSString *gameModDescKey = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"]; |
|
245 cell.detailTextLabel.text = NSLocalizedStringFromTable(gameModDescKey, @"Scheme", nil); |
256 cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; |
246 cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; |
257 cell.detailTextLabel.minimumFontSize = 6; |
247 cell.detailTextLabel.minimumFontSize = 6; |
258 |
248 |
259 cell.selectionStyle = UITableViewCellSelectionStyleNone; |
249 cell.selectionStyle = UITableViewCellSelectionStyleNone; |
260 } |
250 } |
275 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-SLIDER_TAG inSection:1]; |
265 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-SLIDER_TAG inSection:1]; |
276 // get its cell |
266 // get its cell |
277 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; |
267 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; |
278 // grab the associated labels |
268 // grab the associated labels |
279 UILabel *detailLabel = (UILabel *)cell.detailTextLabel; |
269 UILabel *detailLabel = (UILabel *)cell.detailTextLabel; |
280 UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG]; |
|
281 // modify it |
270 // modify it |
282 |
271 |
283 checkValueString(detailLabel.text,cellLabel.text,theSlider); |
272 NSString *basicSettingTitleKey = [[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"title"]; |
|
273 detailLabel.text = [self localizedValueStringForKey:basicSettingTitleKey andSlider:theSlider]; |
284 |
274 |
285 // save changes in the main array |
275 // save changes in the main array |
286 NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"]; |
276 NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"]; |
287 [array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInt:(NSInteger) theSlider.value]]; |
277 [array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInteger:theSlider.value]]; |
288 } |
278 } |
289 |
279 |
290 #pragma mark - |
280 #pragma mark - |
291 #pragma mark Table view delegate |
281 #pragma mark Table view delegate |
292 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
282 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
343 return IS_ON_PORTRAIT() ? 72 : aTableView.rowHeight; |
333 return IS_ON_PORTRAIT() ? 72 : aTableView.rowHeight; |
344 else |
334 else |
345 return 56; |
335 return 56; |
346 } |
336 } |
347 |
337 |
|
338 #pragma mark - Helper methods |
|
339 |
|
340 - (NSString *)localizedValueStringForKey:(NSString *)keyString andSlider:(UISlider *)slider |
|
341 { |
|
342 NSInteger sliderValue = (NSInteger)slider.value; |
|
343 |
|
344 if ([keyString isEqualToString:@"Turn Time"] && sliderValue == 100) |
|
345 return @"∞"; |
|
346 else if ([keyString isEqualToString:@"Water Rise Amount"] && sliderValue == 100) |
|
347 return NSLocalizedString(@"Nvr", @"Short for 'Never'"); |
|
348 else if ([keyString isEqualToString:@"Crate Drop Turns"] && sliderValue == 0) |
|
349 return NSLocalizedString(@"Nvr", @"Short for 'Never'"); |
|
350 else if ([keyString isEqualToString:@"Mines Time"] && sliderValue == -1) |
|
351 return NSLocalizedString(@"Rnd", @"Short for 'Random'"); |
|
352 else if ([keyString isEqualToString:@"World Edge"]) |
|
353 switch (sliderValue) |
|
354 { |
|
355 case 0: |
|
356 return NSLocalizedString(@"None", nil); |
|
357 |
|
358 case 1: |
|
359 return NSLocalizedString(@"Wrap", nil); |
|
360 |
|
361 case 2: |
|
362 return NSLocalizedString(@"Bounce", nil); |
|
363 |
|
364 case 3: |
|
365 return NSLocalizedString(@"Sea", nil); |
|
366 |
|
367 default: |
|
368 return @""; |
|
369 } |
|
370 else |
|
371 return [NSString stringWithFormat:@"%ld", (long)sliderValue]; |
|
372 } |
|
373 |
348 #pragma mark - |
374 #pragma mark - |
349 #pragma mark Memory management |
375 #pragma mark Memory management |
350 -(void) didReceiveMemoryWarning { |
376 -(void) didReceiveMemoryWarning { |
351 [super didReceiveMemoryWarning]; |
377 [super didReceiveMemoryWarning]; |
352 self.basicSettingList = nil; |
378 self.basicSettingList = nil; |