# HG changeset patch # User koda # Date 1298073663 -3600 # Node ID cfac6aab84a066e6608288007e6637d5fdc2055c # Parent 076767e86f2b56a301957a5f000c158983b43510 don't play button sounds when audio is off diff -r 076767e86f2b -r cfac6aab84a0 project_files/HedgewarsMobile/Classes/CommodityFunctions.m --- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Fri Feb 18 00:31:01 2011 +0100 +++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Sat Feb 19 01:01:03 2011 +0100 @@ -90,20 +90,21 @@ } void playSound (NSString *snd) { - //Get the filename of the sound file: - NSString *path = [NSString stringWithFormat:@"%@/%@.wav",[[NSBundle mainBundle] resourcePath],snd]; - - //declare a system sound id - SystemSoundID soundID; + NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; + NSNumber *audio = [prefs objectForKey:@"audio"]; + + if (audio == nil || [audio boolValue] == YES) { + // get the filename of the sound file: + NSString *path = [NSString stringWithFormat:@"%@/%@.wav",[[NSBundle mainBundle] resourcePath],snd]; - //Get a URL for the sound file - NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; + // declare a system sound id and get a URL for the sound file + SystemSoundID soundID; + NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; - //Use audio sevices to create the sound - AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID); - - //Use audio services to play the sound - AudioServicesPlaySystemSound(soundID); + // use audio sevices to create and play the sound + AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID); + AudioServicesPlaySystemSound(soundID); + } } NSArray inline *getAvailableColors (void) { diff -r 076767e86f2b -r cfac6aab84a0 project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m --- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Fri Feb 18 00:31:01 2011 +0100 +++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Sat Feb 19 01:01:03 2011 +0100 @@ -49,6 +49,11 @@ -(void) viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.settingsDictionary writeToFile:SETTINGS_FILE() atomically:YES]; + + // we save the sound settings to respect that flag everywhere + NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; + [prefs setObject:[NSNumber numberWithBool:[[self.settingsDictionary objectForKey:@"sound"] boolValue]] forKey:@"audio"]; + [prefs synchronize]; } #pragma mark -