project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m
changeset 4211 7dcbd236ca59
parent 4210 caa9b08990eb
child 4213 3875481fcc86
equal deleted inserted replaced
4210:caa9b08990eb 4211:7dcbd236ca59
    26 
    26 
    27 #define LABEL_TAG  12345
    27 #define LABEL_TAG  12345
    28 #define SLIDER_TAG 54321
    28 #define SLIDER_TAG 54321
    29 #define SWITCH_TAG 67890
    29 #define SWITCH_TAG 67890
    30 
    30 
       
    31 #define checkValueString(detailString,labelSting,sliderRef); \
       
    32     if ([labelSting isEqualToString:@"Turn Time"] && (NSInteger) sliderRef.value == 100) \
       
    33         detailString = @"∞"; \
       
    34     else if ([labelSting isEqualToString:@"Sudden Death Timeout"] && (NSInteger) sliderRef.value == 100) \
       
    35         detailString = NSLocalizedString(@"Nvr",@"Short for 'Never'"); \
       
    36     else if ([labelSting isEqualToString:@"Water Rise Amount"] && (NSInteger) sliderRef.value == 100) \
       
    37         detailString = NSLocalizedString(@"Nvr",@"Short for 'Never'"); \
       
    38     else if ([labelSting isEqualToString:@"Crate Drop Turns"] && (NSInteger) sliderRef.value == 0) \
       
    39         detailString = NSLocalizedString(@"Nvr",@"Short for 'Never'"); \
       
    40     else if ([labelSting isEqualToString:@"Mines Time"] && (NSInteger) sliderRef.value == -1) \
       
    41         detailString = NSLocalizedString(@"Rnd",@"Short for 'Random'"); \
       
    42     else \
       
    43         detailString = [NSString stringWithFormat:@"%d",(NSInteger) sliderRef.value];
       
    44 
       
    45 
    31 @implementation SingleSchemeViewController
    46 @implementation SingleSchemeViewController
    32 @synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray;
    47 @synthesize schemeName, schemeDictionary, basicSettingList, gameModifierArray;
    33 
    48 
    34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    49 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    35     return rotationManager(interfaceOrientation);
    50     return rotationManager(interfaceOrientation);
   159                 int offset = 0;
   174                 int offset = 0;
   160                 if (IS_IPAD())
   175                 if (IS_IPAD())
   161                     offset = 50;
   176                     offset = 50;
   162 
   177 
   163                 UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(offset+260, 12, offset+150, 23)];
   178                 UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(offset+260, 12, offset+150, 23)];
   164                 slider.maximumValue = [[detail objectForKey:@"max"] floatValue];
       
   165                 slider.minimumValue = [[detail objectForKey:@"min"] floatValue];
       
   166                 [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
   179                 [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
   167                 [cell.contentView addSubview:slider];
   180                 [cell.contentView addSubview:slider];
   168                 [slider release];
   181                 [slider release];
   169 
   182 
   170                 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)];
   183                 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)];
   189                     cellSlider = (UISlider *)oneView;
   202                     cellSlider = (UISlider *)oneView;
   190                     break;
   203                     break;
   191                 } 
   204                 } 
   192             }
   205             }
   193             cellSlider.tag = SLIDER_TAG + row;
   206             cellSlider.tag = SLIDER_TAG + row;
       
   207             cellSlider.maximumValue = [[detail objectForKey:@"max"] floatValue];
       
   208             cellSlider.minimumValue = [[detail objectForKey:@"min"] floatValue];
   194             cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue];
   209             cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue];
   195 
   210 
       
   211             NSString *prestring = nil;
       
   212             checkValueString(prestring,cellLabel.text,cellSlider);
       
   213 
   196             // 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
   197             NSString *prestring = [NSString stringWithFormat:@"%d",(NSInteger) cellSlider.value];
       
   198 
       
   199             // turntime 100 means unlimited time turns (set in GameSetup)
       
   200             if (row == 1 && (NSInteger) cellSlider.value == 100)
       
   201                 prestring = @"∞";
       
   202             else
       
   203                 // mines less than 0 means random
       
   204                 if (row == 5 && (NSInteger) cellSlider.value == -1)
       
   205                     prestring = NSLocalizedString(@"Rnd",@"Short for 'Random'");
       
   206             
       
   207             while ([prestring length] <= 4)
   215             while ([prestring length] <= 4)
   208                 prestring = [NSString stringWithFormat:@" %@",prestring];
   216                 prestring = [NSString stringWithFormat:@" %@",prestring];
   209             cell.detailTextLabel.text = prestring;
   217             cell.detailTextLabel.text = prestring;
   210 
   218 
   211             cell.selectionStyle = UITableViewCellSelectionStyleBlue;
   219             cell.selectionStyle = UITableViewCellSelectionStyleBlue;
   252     UISlider *theSlider = (UISlider *)sender;
   260     UISlider *theSlider = (UISlider *)sender;
   253     // create the indexPath of the row of the slider
   261     // create the indexPath of the row of the slider
   254     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-SLIDER_TAG inSection:1];
   262     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:theSlider.tag-SLIDER_TAG inSection:1];
   255     // get its cell
   263     // get its cell
   256     UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
   264     UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
   257     // grab the associated label
   265     // grab the associated labels
   258     UILabel *label = (UILabel *)cell.detailTextLabel;
   266     UILabel *detailLabel = (UILabel *)cell.detailTextLabel;
       
   267     UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG];
   259     // modify it
   268     // modify it
   260     if ([indexPath row] == 1 && [indexPath section] == 1 && (NSInteger) theSlider.value == 100)
   269 
   261         label.text = @"∞";
   270     checkValueString(detailLabel.text,cellLabel.text,theSlider);
   262     else
   271 
   263         if ([indexPath row] == 5 && [indexPath section] == 1 && (NSInteger) theSlider.value == -1)
       
   264             label.text = NSLocalizedString(@"Rnd",@"Short for 'Random'");
       
   265         else
       
   266             label.text = [NSString stringWithFormat:@"%d",(NSInteger) theSlider.value];
       
   267     // save changes in the main array
   272     // save changes in the main array
   268     NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"];
   273     NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"];
   269     [array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInt:(NSInteger) theSlider.value]];
   274     [array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInt:(NSInteger) theSlider.value]];
   270 }
   275 }
   271 
   276