39 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
39 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
40 [super viewWillAppear:animated]; |
40 [super viewWillAppear:animated]; |
41 } |
41 } |
42 |
42 |
43 -(void) viewWillDisappear:(BOOL)animated { |
43 -(void) viewWillDisappear:(BOOL)animated { |
44 [[NSUserDefaults standardUserDefaults] synchronize]; |
44 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; |
|
45 [userDefaults synchronize]; |
|
46 if ([[userDefaults objectForKey:@"music"] boolValue] == NO) |
|
47 [HedgewarsAppDelegate stopBackgroundMusic]; |
|
48 |
45 [super viewWillDisappear:animated]; |
49 [super viewWillDisappear:animated]; |
46 } |
50 } |
47 |
51 |
48 #pragma mark - |
52 #pragma mark - |
49 -(void) switchValueChanged:(id) sender { |
53 -(void) switchValueChanged:(id) sender { |
51 UISwitch *theOtherSwitch = nil; |
55 UISwitch *theOtherSwitch = nil; |
52 NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
56 NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
53 |
57 |
54 switch (theSwitch.tag) { |
58 switch (theSwitch.tag) { |
55 case 10: //soundSwitch |
59 case 10: //soundSwitch |
56 // this turn off also the switch below |
60 // setting this off will turn off also the switch below (music) |
57 [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"]; |
61 [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"]; |
58 [settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"]; |
62 [settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"]; |
59 theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView; |
63 theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView; |
60 [theOtherSwitch setOn:NO animated:YES]; |
64 [theOtherSwitch setOn:NO animated:YES]; |
61 break; |
65 break; |
62 case 20: //musicSwitch |
66 case 20: //musicSwitch |
63 // if switch above is off, never turn on |
67 // if switch above (sound) is off, never turn on |
64 if (NO == [[settings objectForKey:@"sound"] boolValue]) { |
68 if (NO == [[settings objectForKey:@"sound"] boolValue]) { |
65 [settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"]; |
69 [settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"]; |
66 theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView; |
70 theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView; |
67 [theOtherSwitch setOn:NO animated:YES]; |
71 [theOtherSwitch setOn:NO animated:YES]; |
68 } else |
72 } else |
69 [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"]; |
73 [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"]; |
|
74 |
|
75 if (theSwitch.on) |
|
76 [HedgewarsAppDelegate playBackgroundMusic]; |
|
77 else |
|
78 [HedgewarsAppDelegate pauseBackgroundMusic]; |
|
79 |
70 break; |
80 break; |
71 case 30: //alternateSwitch |
81 case 30: //alternateSwitch |
72 [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"]; |
82 [settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"]; |
73 break; |
83 break; |
74 case 70: //enhanced graphics |
84 case 70: //enhanced graphics |