project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m
changeset 3916 e7d665a4ef42
parent 3829 81db3c85784b
child 3996 eb549fd864a5
equal deleted inserted replaced
3915:c05855146440 3916:e7d665a4ef42
   103     // title, image name (+icon), default value, max value, min value
   103     // title, image name (+icon), default value, max value, min value
   104     NSArray *basicSettings = [[NSArray alloc] initWithObjects:
   104     NSArray *basicSettings = [[NSArray alloc] initWithObjects:
   105                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Damage Modifier",@""),@"title",@"Damage",@"image",
   105                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Damage Modifier",@""),@"title",@"Damage",@"image",
   106                                [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:10],@"min",[NSNumber numberWithInt:300],@"max",nil],
   106                                [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:10],@"min",[NSNumber numberWithInt:300],@"max",nil],
   107                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Turn Time",@""),@"title",@"Time",@"image",
   107                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Turn Time",@""),@"title",@"Time",@"image",
   108                                [NSNumber numberWithInt:45],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:99],@"max",nil],
   108                                [NSNumber numberWithInt:45],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:100],@"max",nil],
   109                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Initial Health",@""),@"title",@"Health",@"image",
   109                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Initial Health",@""),@"title",@"Health",@"image",
   110                                [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:50],@"min",[NSNumber numberWithInt:200],@"max",nil],
   110                                [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:50],@"min",[NSNumber numberWithInt:200],@"max",nil],
   111                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Sudden Death Timeout",@""),@"title",@"SuddenDeath",@"image",
   111                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Sudden Death Timeout",@""),@"title",@"SuddenDeath",@"image",
   112                                [NSNumber numberWithInt:15],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:50],@"max",nil],
   112                                [NSNumber numberWithInt:15],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:50],@"max",nil],
   113                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Crate Drops",@""),@"title",@"Box",@"image",
   113                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Crate Drops",@""),@"title",@"Box",@"image",
   232                     offset = 50;
   232                     offset = 50;
   233 
   233 
   234                 UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(offset+260, 12, offset+150, 23)];
   234                 UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(offset+260, 12, offset+150, 23)];
   235                 slider.maximumValue = [[detail objectForKey:@"max"] floatValue];
   235                 slider.maximumValue = [[detail objectForKey:@"max"] floatValue];
   236                 slider.minimumValue = [[detail objectForKey:@"min"] floatValue];
   236                 slider.minimumValue = [[detail objectForKey:@"min"] floatValue];
   237                 slider.tag = SLIDER_TAG+row;
       
   238                 [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
   237                 [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
   239                 [cell.contentView addSubview:slider];
   238                 [cell.contentView addSubview:slider];
   240                 [slider release];
   239                 [slider release];
   241 
   240 
   242                 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)];
   241                 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 7, 200, 30)];
   252             [img release];
   251             [img release];
   253 
   252 
   254             UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG];
   253             UILabel *cellLabel = (UILabel *)[cell.contentView viewWithTag:LABEL_TAG];
   255             cellLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"];
   254             cellLabel.text = [[self.basicSettingList objectAtIndex:row] objectForKey:@"title"];
   256 
   255 
   257             UISlider *cellSlider = (UISlider *)[cell.contentView viewWithTag:SLIDER_TAG+row];
   256             // can't use the viewWithTag method because row is dynamic
       
   257             UISlider *cellSlider = nil;
       
   258             for (UIView *oneView in cell.contentView.subviews) {
       
   259                 if ([oneView isMemberOfClass:[UISlider class]]) {
       
   260                     cellSlider = (UISlider *)oneView;
       
   261                     break;
       
   262                 }
       
   263             }
       
   264             cellSlider.tag = SLIDER_TAG + row;
   258             cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue];
   265             cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue];
   259 
   266 
   260             // forced to use this weird format otherwise the label disappears when size of the text is bigger than the original
   267             // forced to use this weird format otherwise the label disappears when size of the text is bigger than the original
   261             NSString *prestring = [NSString stringWithFormat:@"%d",(NSInteger) cellSlider.value];
   268             NSString *prestring = [NSString stringWithFormat:@"%d",(NSInteger) cellSlider.value];
       
   269             // turntime 100 means unlimited time turns (set in GameSetup)
       
   270             if (row == 1 && (NSInteger) cellSlider.value == 100)
       
   271                 prestring = @"∞";
       
   272             
   262             while ([prestring length] <= 4)
   273             while ([prestring length] <= 4)
   263                 prestring = [NSString stringWithFormat:@" %@",prestring];
   274                 prestring = [NSString stringWithFormat:@" %@",prestring];
   264             cell.detailTextLabel.text = prestring;
   275             cell.detailTextLabel.text = prestring;
   265 
   276 
   266             cell.selectionStyle = UITableViewCellSelectionStyleBlue;
   277             cell.selectionStyle = UITableViewCellSelectionStyleBlue;
   307     // get its cell
   318     // get its cell
   308     UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
   319     UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
   309     // grab the associated label
   320     // grab the associated label
   310     UILabel *label = (UILabel *)cell.detailTextLabel;
   321     UILabel *label = (UILabel *)cell.detailTextLabel;
   311     // modify it
   322     // modify it
   312     label.text = [NSString stringWithFormat:@"%d",(NSInteger) theSlider.value];
   323     if ([indexPath row] == 1 && [indexPath section] == 1 && (NSInteger) theSlider.value == 100)
       
   324         label.text = @"∞";
       
   325     else
       
   326         label.text = [NSString stringWithFormat:@"%d",(NSInteger) theSlider.value];
   313     // save changes in the main array
   327     // save changes in the main array
   314     NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"];
   328     NSMutableArray *array = [self.schemeDictionary objectForKey:@"basic"];
   315     [array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInt:(NSInteger) theSlider.value]];
   329     [array replaceObjectAtIndex:theSlider.tag-SLIDER_TAG withObject:[NSNumber numberWithInt:(NSInteger) theSlider.value]];
   316 }
   330 }
   317 
   331