project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m
changeset 8426 4b66e60c9967
parent 6869 a187c280dd3d
child 8441 a00b0fa0dbd7
equal deleted inserted replaced
8425:4f226963faef 8426:4b66e60c9967
    49 }
    49 }
    50 
    50 
    51 #pragma mark -
    51 #pragma mark -
    52 -(void) switchValueChanged:(id) sender {
    52 -(void) switchValueChanged:(id) sender {
    53     UISwitch *theSwitch = (UISwitch *)sender;
    53     UISwitch *theSwitch = (UISwitch *)sender;
    54     UISwitch *theOtherSwitch = nil;
       
    55     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
    54     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
    56 
    55 
    57     switch (theSwitch.tag) {
    56     switch (theSwitch.tag) {
    58         case 10:    //soundSwitch
    57         case 10:    //soundSwitch
    59             // setting this off will turn off also the switch below (music)
       
    60             [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"];
    58             [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"];
    61             [settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
       
    62             theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView;
       
    63             [theOtherSwitch setOn:NO animated:YES];
       
    64 
       
    65             // since switching sound on won't turn music on anyways, we can always turn off music
       
    66             [[AudioManagerController mainManager]pauseBackgroundMusic];
       
    67             [settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
       
    68             break;
    59             break;
    69         case 20:    //musicSwitch
    60         case 20:    //musicSwitch
    70             // if switch above (sound) is off, never turn on
    61             [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"];
    71             if (NO == [[settings objectForKey:@"sound"] boolValue]) {
       
    72                 [settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
       
    73                 theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView;
       
    74                 [theOtherSwitch setOn:NO animated:YES];
       
    75             } else
       
    76                 [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"];
       
    77 
       
    78             if (theSwitch.on)
    62             if (theSwitch.on)
    79                 [[AudioManagerController mainManager] playBackgroundMusic];
    63                 [[AudioManagerController mainManager] playBackgroundMusic];
    80             else
    64             else
    81                 [[AudioManagerController mainManager] pauseBackgroundMusic];
    65                 [[AudioManagerController mainManager] pauseBackgroundMusic];
    82             break;
    66             break;
   193                 [theSwitch release];
   177                 [theSwitch release];
   194             }
   178             }
   195             
   179             
   196             switchContent = (UISwitch *)cell.accessoryView;
   180             switchContent = (UISwitch *)cell.accessoryView;
   197             if (row == 0) {
   181             if (row == 0) {
   198                 cell.textLabel.text = NSLocalizedString(@"Sound", @"from the settings table");
   182                 cell.textLabel.text = NSLocalizedString(@"Sound Effects", @"from the settings table");
   199                 switchContent.on = [[settings objectForKey:@"sound"] boolValue];
   183                 switchContent.on = [[settings objectForKey:@"sound"] boolValue];
   200                 switchContent.tag = 10;
   184                 switchContent.tag = 10;
   201             } else {
   185             } else {
   202                 cell.textLabel.text = NSLocalizedString(@"Music", @"from the settings table");
   186                 cell.textLabel.text = NSLocalizedString(@"Music", @"from the settings table");
   203                 switchContent.on = [[settings objectForKey:@"music"] boolValue];
   187                 switchContent.on = [[settings objectForKey:@"music"] boolValue];