- Refactoring for SingleSchemeViewController: checkValueString macro changed to helper method
--- a/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m Wed Nov 04 03:42:11 2015 +0100
+++ b/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m Wed Nov 04 06:17:31 2015 +0100
@@ -25,18 +25,6 @@
#define SLIDER_TAG 54321
#define SWITCH_TAG 67890
-#define checkValueString(detailString,labelSting,sliderRef); \
- if ([labelSting isEqualToString:@"Turn Time"] && (NSInteger) sliderRef.value == 100) \
- detailString = @"∞"; \
- else if ([labelSting isEqualToString:@"Water Rise Amount"] && (NSInteger) sliderRef.value == 100) \
- detailString = NSLocalizedString(@"Nvr",@"Short for 'Never'"); \
- else if ([labelSting isEqualToString:@"Crate Drop Turns"] && (NSInteger) sliderRef.value == 0) \
- detailString = NSLocalizedString(@"Nvr",@"Short for 'Never'"); \
- else if ([labelSting isEqualToString:@"Mines Time"] && (NSInteger) sliderRef.value == -1) \
- detailString = NSLocalizedString(@"Rnd",@"Short for 'Random'"); \
- else \
- detailString = [NSString stringWithFormat:@"%d",(NSInteger) sliderRef.value];
-
@implementation SingleSchemeViewController
@synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray;
@@ -221,8 +209,7 @@
}
cellSlider.frame = CGRectMake(hOffset, vOffset, sliderLength, 23);
- NSString *prestring = nil;
- checkValueString(prestring,basicSettingTitleKey,cellSlider);
+ NSString *prestring = [self localizedValueStringForKey:basicSettingTitleKey andSlider:cellSlider];
// forced to use this weird format otherwise the label disappears when size of the text is bigger than the original
while ([prestring length] <= 4)
@@ -283,7 +270,7 @@
// modify it
NSString *basicSettingTitleKey = [[self.basicSettingList objectAtIndex:[indexPath row]] objectForKey:@"title"];
- checkValueString(detailLabel.text,basicSettingTitleKey,theSlider);
+ detailLabel.text = [self localizedValueStringForKey:basicSettingTitleKey andSlider:theSlider];
// save changes in the main array
NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"];
@@ -348,6 +335,24 @@
return 56;
}
+#pragma mark - Helper methods
+
+- (NSString *)localizedValueStringForKey:(NSString *)keyString andSlider:(UISlider *)slider
+{
+ NSInteger sliderValue = (NSInteger)slider.value;
+
+ if ([keyString isEqualToString:@"Turn Time"] && sliderValue == 100)
+ return @"∞";
+ else if ([keyString isEqualToString:@"Water Rise Amount"] && sliderValue == 100)
+ return NSLocalizedString(@"Nvr", @"Short for 'Never'");
+ else if ([keyString isEqualToString:@"Crate Drop Turns"] && sliderValue == 0)
+ return NSLocalizedString(@"Nvr", @"Short for 'Never'");
+ else if ([keyString isEqualToString:@"Mines Time"] && sliderValue == -1)
+ return NSLocalizedString(@"Rnd", @"Short for 'Random'");
+ else
+ return [NSString stringWithFormat:@"%ld", (long)sliderValue];
+}
+
#pragma mark -
#pragma mark Memory management
-(void) didReceiveMemoryWarning {