project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m
changeset 3697 d5b30d6373fc
parent 3663 8c28abf427f5
child 3703 12d17c6e8855
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    23     [super viewDidLoad];
    23     [super viewDidLoad];
    24 }
    24 }
    25 
    25 
    26 -(void) viewWillAppear:(BOOL)animated {
    26 -(void) viewWillAppear:(BOOL)animated {
    27     [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    27     [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    28     
    28 
    29     NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
    29     NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
    30     self.settingsDictionary = dictionary;
    30     self.settingsDictionary = dictionary;
    31     [dictionary release];
    31     [dictionary release];
    32 
    32 
    33     [super viewWillAppear:animated];
    33     [super viewWillAppear:animated];
    34 }
    34 }
    35 
    35 
    36 -(void) viewWillDisappear:(BOOL)animated {
    36 -(void) viewWillDisappear:(BOOL)animated {
    37     [super viewWillDisappear:animated];    
    37     [super viewWillDisappear:animated];
    38     [self.settingsDictionary writeToFile:SETTINGS_FILE() atomically:YES];
    38     [self.settingsDictionary writeToFile:SETTINGS_FILE() atomically:YES];
    39 }
    39 }
    40 
    40 
    41 #pragma mark -
    41 #pragma mark -
    42 -(void) switchValueChanged:(id) sender {
    42 -(void) switchValueChanged:(id) sender {
    43     UISwitch *theSwitch = (UISwitch *)sender;
    43     UISwitch *theSwitch = (UISwitch *)sender;
    44     UISwitch *theOtherSwitch = nil;
    44     UISwitch *theOtherSwitch = nil;
    45     
    45 
    46     switch (theSwitch.tag) {
    46     switch (theSwitch.tag) {
    47         case 10:    //soundSwitch
    47         case 10:    //soundSwitch
    48             // this turn off also the switch below
    48             // this turn off also the switch below
    49             [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"];
    49             [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"];
    50             [self.settingsDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
    50             [self.settingsDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
   121 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   121 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   122     static NSString *cellIdentifier0 = @"Cell0";
   122     static NSString *cellIdentifier0 = @"Cell0";
   123     static NSString *cellIdentifier1 = @"Cell1";
   123     static NSString *cellIdentifier1 = @"Cell1";
   124     NSInteger row = [indexPath row];
   124     NSInteger row = [indexPath row];
   125     NSInteger section = [indexPath section];
   125     NSInteger section = [indexPath section];
   126     
   126 
   127     UITableViewCell *cell = nil;
   127     UITableViewCell *cell = nil;
   128     EditableCellView *editableCell = nil;
   128     EditableCellView *editableCell = nil;
   129     if (section == 0) {
   129     if (section == 0) {
   130         editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:cellIdentifier0];
   130         editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:cellIdentifier0];
   131         if (nil == editableCell) {
   131         if (nil == editableCell) {
   133             editableCell.minimumCharacters = 0;
   133             editableCell.minimumCharacters = 0;
   134             editableCell.delegate = self;
   134             editableCell.delegate = self;
   135             editableCell.textField.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
   135             editableCell.textField.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
   136             editableCell.textField.textColor = [UIColor lightGrayColor];
   136             editableCell.textField.textColor = [UIColor lightGrayColor];
   137         }
   137         }
   138         
   138 
   139         if (row == 0) {
   139         if (row == 0) {
   140             editableCell.titleLabel.text = NSLocalizedString(@"Nickname","from the settings table");
   140             editableCell.titleLabel.text = NSLocalizedString(@"Nickname","from the settings table");
   141             editableCell.textField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@"");
   141             editableCell.textField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@"");
   142             editableCell.textField.text = [self.settingsDictionary objectForKey:@"username"];
   142             editableCell.textField.text = [self.settingsDictionary objectForKey:@"username"];
   143             editableCell.textField.secureTextEntry = NO;
   143             editableCell.textField.secureTextEntry = NO;
   147             editableCell.textField.placeholder = NSLocalizedString(@"Insert your password",@"");
   147             editableCell.textField.placeholder = NSLocalizedString(@"Insert your password",@"");
   148             editableCell.textField.text = [self.settingsDictionary objectForKey:@"password"];
   148             editableCell.textField.text = [self.settingsDictionary objectForKey:@"password"];
   149             editableCell.textField.secureTextEntry = YES;
   149             editableCell.textField.secureTextEntry = YES;
   150             editableCell.tag = 50;
   150             editableCell.tag = 50;
   151         }
   151         }
   152         
   152 
   153         editableCell.accessoryView = nil;
   153         editableCell.accessoryView = nil;
   154         cell = editableCell;
   154         cell = editableCell;
   155     } else {
   155     } else {
   156         cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier1];
   156         cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier1];
   157         if (nil == cell) {
   157         if (nil == cell) {
   159             UISwitch *theSwitch = [[UISwitch alloc] init];
   159             UISwitch *theSwitch = [[UISwitch alloc] init];
   160             [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
   160             [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
   161             cell.accessoryView = theSwitch;
   161             cell.accessoryView = theSwitch;
   162             [theSwitch release];
   162             [theSwitch release];
   163         }
   163         }
   164         
   164 
   165         UISwitch *switchContent = (UISwitch *)cell.accessoryView;
   165         UISwitch *switchContent = (UISwitch *)cell.accessoryView;
   166         if (section == 1) {
   166         if (section == 1) {
   167             if (row == 0) {
   167             if (row == 0) {
   168                 cell.textLabel.text = NSLocalizedString(@"Sound", @"");
   168                 cell.textLabel.text = NSLocalizedString(@"Sound", @"");
   169                 switchContent.on = [[self.settingsDictionary objectForKey:@"sound"] boolValue];
   169                 switchContent.on = [[self.settingsDictionary objectForKey:@"sound"] boolValue];
   177             cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @"");
   177             cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @"");
   178             switchContent.on = [[self.settingsDictionary objectForKey:@"alternate"] boolValue];
   178             switchContent.on = [[self.settingsDictionary objectForKey:@"alternate"] boolValue];
   179             switchContent.tag = 30;
   179             switchContent.tag = 30;
   180         }
   180         }
   181     }
   181     }
   182     
   182 
   183     cell.accessoryType = UITableViewCellAccessoryNone;
   183     cell.accessoryType = UITableViewCellAccessoryNone;
   184     cell.selectionStyle = UITableViewCellSelectionStyleNone;
   184     cell.selectionStyle = UITableViewCellSelectionStyleNone;
   185     cell.imageView.image = nil;
   185     cell.imageView.image = nil;
   186     
   186 
   187     return cell;
   187     return cell;
   188 }
   188 }
   189 
   189 
   190 /*
   190 /*
   191 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
   191 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
   210         default:
   210         default:
   211             NSLog(@"Warning: unset case value in titleForHeaderInSection!");
   211             NSLog(@"Warning: unset case value in titleForHeaderInSection!");
   212             headerLabel.text = @"!";
   212             headerLabel.text = @"!";
   213             break;
   213             break;
   214     }
   214     }
   215     
   215 
   216     [containerView addSubview:headerLabel];
   216     [containerView addSubview:headerLabel];
   217     return containerView;
   217     return containerView;
   218 }
   218 }
   219 
   219 
   220 -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
   220 -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {