cocoaTouch/GeneralSettingsViewController.m
changeset 3335 2520ee7a5484
parent 3332 3c90a923f156
child 3361 cfc6cd502f85
equal deleted inserted replaced
3334:f94a52a763d4 3335:2520ee7a5484
     5 //  Created by Vittorio on 08/01/10.
     5 //  Created by Vittorio on 08/01/10.
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     7 //
     7 //
     8 
     8 
     9 #import "GeneralSettingsViewController.h"
     9 #import "GeneralSettingsViewController.h"
    10 #import "SDL_uikitappdelegate.h"
    10 #import "CommodityFunctions.h"
    11 
    11 
    12 @implementation GeneralSettingsViewController
    12 @implementation GeneralSettingsViewController
    13 @synthesize settingsDictionary, textFieldBeingEdited, musicSwitch, soundSwitch, altDamageSwitch;
    13 @synthesize settingsDictionary, textFieldBeingEdited, musicSwitch, soundSwitch, altDamageSwitch;
    14 
    14 
    15 
    15 
    16 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    16 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    17     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    17 	return rotationManager(interfaceOrientation);
    18 }
    18 }
       
    19 
    19 
    20 
    20 #pragma mark -
    21 #pragma mark -
    21 #pragma mark textfield methods
    22 #pragma mark textfield methods
    22 // return to previous table
    23 // return to previous table
    23 -(void) cancel:(id) sender {
    24 -(void) cancel:(id) sender {
    86 	self.soundSwitch = [[UISwitch alloc] init];
    87 	self.soundSwitch = [[UISwitch alloc] init];
    87 	self.altDamageSwitch = [[UISwitch alloc] init];
    88 	self.altDamageSwitch = [[UISwitch alloc] init];
    88 	[self.soundSwitch addTarget:self action:@selector(alsoTurnOffMusic:) forControlEvents:UIControlEventValueChanged];
    89 	[self.soundSwitch addTarget:self action:@selector(alsoTurnOffMusic:) forControlEvents:UIControlEventValueChanged];
    89 	[self.musicSwitch addTarget:self action:@selector(dontTurnOnMusic:) forControlEvents:UIControlEventValueChanged];
    90 	[self.musicSwitch addTarget:self action:@selector(dontTurnOnMusic:) forControlEvents:UIControlEventValueChanged];
    90 	[self.altDamageSwitch addTarget:self action:@selector(justUpdateDictionary:) forControlEvents:UIControlEventValueChanged];
    91 	[self.altDamageSwitch addTarget:self action:@selector(justUpdateDictionary:) forControlEvents:UIControlEventValueChanged];
    91 
    92     
    92     NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
    93     NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
    93     NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
       
    94     self.settingsDictionary = dictionary;
    94     self.settingsDictionary = dictionary;
    95     [dictionary release];
    95     [dictionary release];
    96 }
    96 }
    97 
       
    98 
       
    99 
    97 
   100 -(void) viewWillAppear:(BOOL)animated {
    98 -(void) viewWillAppear:(BOOL)animated {
   101     [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    99     [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
   102     isWriteNeeded = NO;
   100     isWriteNeeded = NO;
   103     
   101     
   111 -(void) viewWillDisappear:(BOOL)animated {
   109 -(void) viewWillDisappear:(BOOL)animated {
   112     [super viewWillDisappear:animated];
   110     [super viewWillDisappear:animated];
   113     
   111     
   114     if (isWriteNeeded) {
   112     if (isWriteNeeded) {
   115        	NSLog(@"writing preferences to file");
   113        	NSLog(@"writing preferences to file");
   116         [self.settingsDictionary writeToFile:[[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"] atomically:YES];
   114         [self.settingsDictionary writeToFile:SETTINGS_FILE() atomically:YES];
   117         isWriteNeeded = NO;
   115         isWriteNeeded = NO;
   118     }
   116     }
   119 }
   117 }
   120 
   118 
   121 #pragma mark -
   119 #pragma mark -