project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m
changeset 4000 ddc4a09889e7
parent 3996 eb549fd864a5
child 4003 ca0600ab38bf
equal deleted inserted replaced
3999:411e71912f4c 4000:ddc4a09889e7
    37 
    37 
    38 #pragma mark -
    38 #pragma mark -
    39 #pragma mark View lifecycle
    39 #pragma mark View lifecycle
    40 -(void) viewDidLoad {
    40 -(void) viewDidLoad {
    41     [super viewDidLoad];
    41     [super viewDidLoad];
       
    42     NSString *path = nil;
    42 
    43 
    43     // title, description, image name (+btn)
    44     // title, description, image name (+btn)
    44     NSArray *mods = [[NSArray alloc] initWithObjects:
    45     path = [NSString stringWithFormat:@"%@/gameFlags_en.plist",IFRONTEND_DIRECTORY()];
    45                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Fort Mode",@""),@"title",
    46     NSArray *mods = [[NSArray alloc] initWithContentsOfFile:path];
    46                       NSLocalizedString(@"Defend your fort and destroy the opponents (two team colours max)",@""),@"description",
       
    47                       @"Forts",@"image",nil],
       
    48                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Divide Team",@""),@"title",
       
    49                       NSLocalizedString(@"Teams will start on opposite sides of the terrain (two team colours max)",@""),@"description",
       
    50                       @"TeamsDivide",@"image",nil],
       
    51                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Solid Land",@""),@"title",
       
    52                       NSLocalizedString(@"Land can not be destroyed",@""),@"description",
       
    53                       @"Solid",@"image",nil],
       
    54                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Border",@""),@"title",
       
    55                       NSLocalizedString(@"Add an indestructable border around the terrain",@""),@"description",
       
    56                       @"Border",@"image",nil],
       
    57                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Low Gravity",@""),@"title",
       
    58                       NSLocalizedString(@"Lower gravity",@""),@"description",
       
    59                       @"LowGravity",@"image",nil],
       
    60                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Laser Sight",@""),@"title",
       
    61                       NSLocalizedString(@"Assisted aiming with laser sight",@""),@"description",
       
    62                       @"LaserSight",@"image",nil],
       
    63                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Invulnerable",@""),@"title",
       
    64                       NSLocalizedString(@"All hogs have a personal forcefield",@""),@"description",
       
    65                       @"Invulnerable",@"image",nil],
       
    66                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Add Mines",@""),@"title",
       
    67                       NSLocalizedString(@"Enable random mines",@""),@"description",
       
    68                       @"Mines",@"image",nil],
       
    69                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Vampirism Mode",@""),@"title",
       
    70                       NSLocalizedString(@"Gain 80% of the damage you do back in health",@""),@"description",
       
    71                       @"Vampiric",@"image",nil],
       
    72                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Karma Mode",@""),@"title",
       
    73                       NSLocalizedString(@"Share your opponents pain, share their damage",@""),@"description",
       
    74                       @"Karma",@"image",nil],
       
    75                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Artillery Mode",@""),@"title",
       
    76                       NSLocalizedString(@"Your hogs are unable to move, test your aim",@""),@"description",
       
    77                       @"Artillery",@"image",nil],
       
    78                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Random Order",@""),@"title",
       
    79                       NSLocalizedString(@"Order of play is random instead of in room order",@""),@"description",
       
    80                       @"RandomOrder",@"image",nil],
       
    81                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"King Mode",@""),@"title",
       
    82                       NSLocalizedString(@"Play with a King. If he dies, your side loses",@""),@"description",
       
    83                       @"King",@"image",nil],
       
    84                      [NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Place Hedgehogs",@""),@"title",
       
    85                       NSLocalizedString(@"Take turns placing your hedgehogs pre-game",@""),@"description",
       
    86                       @"PlaceHog",@"image",nil],
       
    87                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Clan Shares Ammo",@""),@"title",
       
    88                       NSLocalizedString(@"Ammo is shared between all clan teams",@""),@"description",
       
    89                       @"SharedAmmo",@"image",nil],
       
    90                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Girders",@""),@"title",
       
    91                       NSLocalizedString(@"Disable girders when generating random maps",@""),@"description",
       
    92                       @"DisableGirders",@"image",nil],
       
    93                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Disable Land Objects",@""),@"title",
       
    94                       NSLocalizedString(@"Disable land objects when generating maps",@""),@"description",
       
    95                       @"DisableLandObjects",@"image",nil],
       
    96                      [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"AI Survival Mode",@""),@"title",
       
    97                       NSLocalizedString(@"AI-controlled hogs respawn on death",@""),@"description",
       
    98                       @"AISurvival",@"image",nil],
       
    99                      nil];
       
   100     self.gameModifierArray = mods;
    47     self.gameModifierArray = mods;
   101     [mods release];
    48     [mods release];
   102 
    49 
   103     // title, image name (+icon), default value, max value, min value
    50     // title, image name (+icon), default value, max value, min value
   104     NSArray *basicSettings = [[NSArray alloc] initWithObjects:
    51     path = [NSString stringWithFormat:@"%@/basicFlags_en.plist",IFRONTEND_DIRECTORY()];
   105                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Damage Modifier",@""),@"title",@"Damage",@"image",
    52     NSArray *basicSettings = [[NSArray alloc] initWithContentsOfFile:path];
   106                                [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:10],@"min",[NSNumber numberWithInt:300],@"max",nil],
       
   107                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Turn Time",@""),@"title",@"Time",@"image",
       
   108                                [NSNumber numberWithInt:45],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:100],@"max",nil],
       
   109                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Initial Health",@""),@"title",@"Health",@"image",
       
   110                                [NSNumber numberWithInt:100],@"default",[NSNumber numberWithInt:50],@"min",[NSNumber numberWithInt:200],@"max",nil],
       
   111                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Sudden Death Timeout",@""),@"title",@"SuddenDeath",@"image",
       
   112                                [NSNumber numberWithInt:15],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:50],@"max",nil],
       
   113                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Crate Drops",@""),@"title",@"Box",@"image",
       
   114                                [NSNumber numberWithInt:5],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:9],@"max",nil],
       
   115                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Time",@""),@"title",@"Time",@"image",
       
   116                                [NSNumber numberWithInt:3],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:3],@"max",nil],
       
   117                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Mines Number",@""),@"title",@"Mine",@"image",
       
   118                                [NSNumber numberWithInt:4],@"default",[NSNumber numberWithInt:1],@"min",[NSNumber numberWithInt:80],@"max",nil],
       
   119                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Dud Mines Probability",@""),@"title",@"Dud",@"image",
       
   120                                [NSNumber numberWithInt:0],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:100],@"max",nil],
       
   121                               [NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Explosives",@""),@"title",@"Damage",@"image",
       
   122                                [NSNumber numberWithInt:2],@"default",[NSNumber numberWithInt:0],@"min",[NSNumber numberWithInt:40],@"max",nil],
       
   123                               nil];
       
   124     self.basicSettingList = basicSettings;
    53     self.basicSettingList = basicSettings;
   125     [basicSettings release];
    54     [basicSettings release];
   126 
    55 
   127     self.title = NSLocalizedString(@"Edit scheme preferences",@"");
    56     self.title = NSLocalizedString(@"Edit scheme preferences",@"");
   128 }
    57 }
   175     switch (section) {
   104     switch (section) {
   176         case 0:
   105         case 0:
   177             return 2;
   106             return 2;
   178             break;
   107             break;
   179         case 1:
   108         case 1:
   180             return [self.basicSettingList count];
   109             return [[self.schemeDictionary objectForKey:@"basic"] count];
   181             break;
   110             break;
   182         case 2:
   111         case 2:
   183             return [self.gameModifierArray count];
   112             return [[self.schemeDictionary objectForKey:@"gamemod"] count];
   184         default:
   113         default:
   185             break;
   114             break;
   186     }
   115     }
   187     return 0;
   116     return 0;
   188 }
   117 }
   257             UISlider *cellSlider = nil;
   186             UISlider *cellSlider = nil;
   258             for (UIView *oneView in cell.contentView.subviews) {
   187             for (UIView *oneView in cell.contentView.subviews) {
   259                 if ([oneView isMemberOfClass:[UISlider class]]) {
   188                 if ([oneView isMemberOfClass:[UISlider class]]) {
   260                     cellSlider = (UISlider *)oneView;
   189                     cellSlider = (UISlider *)oneView;
   261                     break;
   190                     break;
   262                 }
   191                 } 
   263             }
   192             }
   264             cellSlider.tag = SLIDER_TAG + row;
   193             cellSlider.tag = SLIDER_TAG + row;
   265             cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue];
   194             cellSlider.value = [[[self.schemeDictionary objectForKey:@"basic"] objectAtIndex:row] floatValue];
   266 
   195 
   267             // forced to use this weird format otherwise the label disappears when size of the text is bigger than the original
   196             // forced to use this weird format otherwise the label disappears when size of the text is bigger than the original
   280             cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier2];
   209             cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier2];
   281             if (cell == nil) {
   210             if (cell == nil) {
   282                 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
   211                 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
   283                                                reuseIdentifier:CellIdentifier2] autorelease];
   212                                                reuseIdentifier:CellIdentifier2] autorelease];
   284                 UISwitch *onOff = [[UISwitch alloc] init];
   213                 UISwitch *onOff = [[UISwitch alloc] init];
   285                 onOff.tag = SWITCH_TAG+row;
       
   286                 [onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged];
   214                 [onOff addTarget:self action:@selector(toggleSwitch:) forControlEvents:UIControlEventValueChanged];
   287                 cell.accessoryView = onOff;
   215                 cell.accessoryView = onOff;
   288                 [onOff release];
   216                 [onOff release];
   289             }
   217             }
   290 
   218 
       
   219             UISwitch *switcher = (UISwitch *)cell.accessoryView;
       
   220             switcher.tag = SWITCH_TAG + row;
       
   221             [switcher setOn:[[[self.schemeDictionary objectForKey:@"gamemod"] objectAtIndex:row] boolValue] animated:NO];
       
   222             
   291             UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/btn%@.png",BTN_DIRECTORY(),[[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]];
   223             UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/btn%@.png",BTN_DIRECTORY(),[[self.gameModifierArray objectAtIndex:row] objectForKey:@"image"]]];
   292             cell.imageView.image = image;
   224             cell.imageView.image = image;
   293             [image release];
   225             [image release];
   294             [cell.imageView.layer setCornerRadius:7.0f];
   226             [cell.imageView.layer setCornerRadius:7.0f];
   295             [cell.imageView.layer setBorderWidth:1];
       
   296             [cell.imageView.layer setMasksToBounds:YES];
   227             [cell.imageView.layer setMasksToBounds:YES];
   297             cell.textLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"];
   228             cell.textLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"title"];
   298             cell.detailTextLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"];
   229             cell.detailTextLabel.text = [[self.gameModifierArray objectAtIndex:row] objectForKey:@"description"];
   299             [(UISwitch *)cell.accessoryView setOn:[[[self.schemeDictionary objectForKey:@"gamemod"] objectAtIndex:row] boolValue] animated:NO];
   230             cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
       
   231             cell.detailTextLabel.minimumFontSize = 6;
   300 
   232 
   301             cell.selectionStyle = UITableViewCellSelectionStyleNone;
   233             cell.selectionStyle = UITableViewCellSelectionStyleNone;
   302         }
   234         }
   303 
   235 
   304     return cell;
   236     return cell;