project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m
changeset 3779 3351a017d4ad
parent 3703 12d17c6e8855
child 3783 8e9daf967406
equal deleted inserted replaced
3778:2e61bb50cc57 3779:3351a017d4ad
    61                 [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"];
    61                 [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"];
    62             break;
    62             break;
    63         case 30:    //alternateSwitch
    63         case 30:    //alternateSwitch
    64             [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"];
    64             [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"];
    65             break;
    65             break;
       
    66         case 60:    //getReady
       
    67             [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"ready"];
       
    68             break;
    66         default:
    69         default:
    67             DLog(@"Wrong tag");
    70             DLog(@"Wrong tag");
    68             break;
    71             break;
    69     }
    72     }
    70 }
    73 }
    88             return 2;
    91             return 2;
    89             break;
    92             break;
    90         case 1:     // audio
    93         case 1:     // audio
    91             return 2;
    94             return 2;
    92             break;
    95             break;
    93         case 2:     // alternate damage
    96         case 2:     // other stuff
    94             return 1;
    97             return 2;
    95             break;
    98             break;
    96         default:
    99         default:
    97             break;
   100             break;
    98     }
   101     }
    99     return 0;
   102     return 0;
   119 }
   122 }
   120 
   123 
   121 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   124 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   122     static NSString *cellIdentifier0 = @"Cell0";
   125     static NSString *cellIdentifier0 = @"Cell0";
   123     static NSString *cellIdentifier1 = @"Cell1";
   126     static NSString *cellIdentifier1 = @"Cell1";
       
   127     static NSString *cellIdentifier2 = @"Cell2";
   124     NSInteger row = [indexPath row];
   128     NSInteger row = [indexPath row];
   125     NSInteger section = [indexPath section];
   129     NSInteger section = [indexPath section];
   126 
   130 
   127     UITableViewCell *cell = nil;
   131     UITableViewCell *cell = nil;
   128     EditableCellView *editableCell = nil;
   132     EditableCellView *editableCell = nil;
   129     if (section == 0) {
   133     UISwitch *switchContent = nil;
   130         editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:cellIdentifier0];
   134     switch(section) {
   131         if (nil == editableCell) {
   135         case 0:
   132             editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier0] autorelease];
   136             editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:cellIdentifier0];
   133             editableCell.minimumCharacters = 0;
   137             if (nil == editableCell) {
   134             editableCell.delegate = self;
   138                 editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier0] autorelease];
   135             editableCell.textField.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
   139                 editableCell.minimumCharacters = 0;
   136             editableCell.textField.textColor = [UIColor lightGrayColor];
   140                 editableCell.delegate = self;
   137         }
   141                 editableCell.textField.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
   138 
   142                 editableCell.textField.textColor = [UIColor lightGrayColor];
   139         if (row == 0) {
   143             }
   140             editableCell.titleLabel.text = NSLocalizedString(@"Nickname","from the settings table");
   144             
   141             editableCell.textField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@"");
   145             if (row == 0) {
   142             editableCell.textField.text = [self.settingsDictionary objectForKey:@"username"];
   146                 editableCell.titleLabel.text = NSLocalizedString(@"Nickname","from the settings table");
   143             editableCell.textField.secureTextEntry = NO;
   147                 editableCell.textField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@"");
   144             editableCell.tag = 40;
   148                 editableCell.textField.text = [self.settingsDictionary objectForKey:@"username"];
   145         } else {
   149                 editableCell.textField.secureTextEntry = NO;
   146             editableCell.titleLabel.text = NSLocalizedString(@"Password","from the settings table");
   150                 editableCell.tag = 40;
   147             editableCell.textField.placeholder = NSLocalizedString(@"Insert your password",@"");
   151             } else {
   148             editableCell.textField.text = [self.settingsDictionary objectForKey:@"password"];
   152                 editableCell.titleLabel.text = NSLocalizedString(@"Password","from the settings table");
   149             editableCell.textField.secureTextEntry = YES;
   153                 editableCell.textField.placeholder = NSLocalizedString(@"Insert your password",@"");
   150             editableCell.tag = 50;
   154                 editableCell.textField.text = [self.settingsDictionary objectForKey:@"password"];
   151         }
   155                 editableCell.textField.secureTextEntry = YES;
   152 
   156                 editableCell.tag = 50;
   153         editableCell.accessoryView = nil;
   157             }
   154         cell = editableCell;
   158             
   155     } else {
   159             editableCell.accessoryView = nil;
   156         cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier1];
   160             cell = editableCell;
   157         if (nil == cell) {
   161             break;
   158             cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier1] autorelease];
   162         case 1:
   159             UISwitch *theSwitch = [[UISwitch alloc] init];
   163             cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier1];
   160             [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
   164             if (nil == cell) {
   161             cell.accessoryView = theSwitch;
   165                 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier1] autorelease];
   162             [theSwitch release];
   166                 UISwitch *theSwitch = [[UISwitch alloc] init];
   163         }
   167                 [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
   164 
   168                 cell.accessoryView = theSwitch;
   165         UISwitch *switchContent = (UISwitch *)cell.accessoryView;
   169                 [theSwitch release];
   166         if (section == 1) {
   170             }
       
   171             
       
   172             switchContent = (UISwitch *)cell.accessoryView;
   167             if (row == 0) {
   173             if (row == 0) {
   168                 cell.textLabel.text = NSLocalizedString(@"Sound", @"");
   174                 cell.textLabel.text = NSLocalizedString(@"Sound", @"");
   169                 switchContent.on = [[self.settingsDictionary objectForKey:@"sound"] boolValue];
   175                 switchContent.on = [[self.settingsDictionary objectForKey:@"sound"] boolValue];
   170                 switchContent.tag = 10;
   176                 switchContent.tag = 10;
   171             } else {
   177             } else {
   172                 cell.textLabel.text = NSLocalizedString(@"Music", @"");
   178                 cell.textLabel.text = NSLocalizedString(@"Music", @"");
   173                 switchContent.on = [[self.settingsDictionary objectForKey:@"music"] boolValue];
   179                 switchContent.on = [[self.settingsDictionary objectForKey:@"music"] boolValue];
   174                 switchContent.tag = 20;
   180                 switchContent.tag = 20;
   175             }
   181             }
   176         } else {
   182             break;
   177             cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @"");
   183         case 2:
   178             switchContent.on = [[self.settingsDictionary objectForKey:@"alternate"] boolValue];
   184             cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier2];
   179             switchContent.tag = 30;
   185             if (nil == cell) {
   180         }
   186                 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier2] autorelease];
   181     }
   187                 UISwitch *theSwitch = [[UISwitch alloc] init];
   182 
   188                 [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
       
   189                 cell.accessoryView = theSwitch;
       
   190                 [theSwitch release];
       
   191             }
       
   192             
       
   193             switchContent = (UISwitch *)cell.accessoryView;
       
   194             if (row == 0) {
       
   195                 cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @"");
       
   196                 cell.detailTextLabel.text = NSLocalizedString(@"Damage will popup when the hedgehog is injured", @"");
       
   197                 switchContent.on = [[self.settingsDictionary objectForKey:@"alternate"] boolValue];
       
   198                 switchContent.tag = 30;
       
   199             } else {
       
   200                 cell.textLabel.text = NSLocalizedString(@"Get Ready Dialogue", @"");
       
   201                 cell.detailTextLabel.text = NSLocalizedString(@"Pause for 5 seconds between turns",@"");
       
   202                 switchContent.on = [[self.settingsDictionary objectForKey:@"ready"] boolValue];
       
   203                 switchContent.tag = 60;
       
   204             }
       
   205             break;
       
   206         default:
       
   207             break;
       
   208     }
       
   209     
   183     cell.accessoryType = UITableViewCellAccessoryNone;
   210     cell.accessoryType = UITableViewCellAccessoryNone;
   184     cell.selectionStyle = UITableViewCellSelectionStyleNone;
   211     cell.selectionStyle = UITableViewCellSelectionStyleNone;
   185     cell.imageView.image = nil;
   212     cell.imageView.image = nil;
   186 
   213 
   187     return cell;
   214     return cell;