project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m
branchios-develop
changeset 12872 00215a7ec5f5
parent 11233 e21027aa9068
child 13166 ba5c794adae3
equal deleted inserted replaced
12871:2c06b1120749 12872:00215a7ec5f5
    21 
    21 
    22 
    22 
    23 @implementation GeneralSettingsViewController
    23 @implementation GeneralSettingsViewController
    24 
    24 
    25 
    25 
    26 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    26 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    27     return rotationManager(interfaceOrientation);
    27     return rotationManager(interfaceOrientation);
    28 }
    28 }
    29 
    29 
    30 #pragma mark -
    30 #pragma mark -
    31 #pragma mark View Lifecycle
    31 #pragma mark View Lifecycle
    32 -(void) viewDidLoad {
    32 - (void)viewDidLoad {
    33     self.navigationItem.title = NSLocalizedString(@"Edit game options", nil);
    33     self.navigationItem.title = NSLocalizedString(@"Edit game options", nil);
    34     [super viewDidLoad];
    34     [super viewDidLoad];
    35 }
    35 }
    36 
    36 
    37 -(void) viewWillAppear:(BOOL)animated {
    37 - (void)viewWillAppear:(BOOL)animated {
    38     [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    38     [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    39     [super viewWillAppear:animated];
    39     [super viewWillAppear:animated];
    40 }
    40 }
    41 
    41 
    42 -(void) viewWillDisappear:(BOOL)animated {
    42 - (void)viewWillDisappear:(BOOL)animated {
    43     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    43     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    44     [userDefaults synchronize];
    44     [userDefaults synchronize];
    45     if ([[userDefaults objectForKey:@"music"] boolValue] == NO)
    45     if ([[userDefaults objectForKey:@"music"] boolValue] == NO)
    46         [[AudioManagerController mainManager] stopBackgroundMusic];
    46         [[AudioManagerController mainManager] stopBackgroundMusic];
    47 
    47 
    48     [super viewWillDisappear:animated];
    48     [super viewWillDisappear:animated];
    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     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
    54     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
    55 
    55 
    56     switch (theSwitch.tag) {
    56     switch (theSwitch.tag) {
    57         case 10:    //soundSwitch
    57         case 10:    //soundSwitch
    74             DLog(@"Wrong tag");
    74             DLog(@"Wrong tag");
    75             break;
    75             break;
    76     }
    76     }
    77 }
    77 }
    78 
    78 
    79 -(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
    79 - (void)saveTextFieldValue:(NSString *)textString withTag:(NSInteger)tagValue {
    80     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
    80     NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
    81 
    81 
    82     if (tagValue == 40)
    82     if (tagValue == 40)
    83         [settings setObject:textString forKey:@"username"];
    83         [settings setObject:textString forKey:@"username"];
    84     else
    84     else
    85         [settings setObject:[textString MD5hash] forKey:@"password"];
    85         [settings setObject:[textString MD5hash] forKey:@"password"];
    86 }
    86 }
    87 
    87 
    88 #pragma mark -
    88 #pragma mark -
    89 #pragma mark TableView Methods
    89 #pragma mark TableView Methods
    90 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    90 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    91     return 3;
    91     return 3;
    92 }
    92 }
    93 
    93 
    94 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section {
    94 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section {
    95     switch (section) {
    95     switch (section) {
    96         case 0:     // user and pass
    96         case 0:     // user and pass
    97             return 1;   // set 2 here to show the password field
    97             return 1;   // set 2 here to show the password field
    98             break;
    98             break;
    99         case 1:     // audio
    99         case 1:     // audio
   141     UISwitch *switchContent = nil;
   141     UISwitch *switchContent = nil;
   142     switch(section) {
   142     switch(section) {
   143         case 0:
   143         case 0:
   144             editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:cellIdentifier0];
   144             editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:cellIdentifier0];
   145             if (nil == editableCell) {
   145             if (nil == editableCell) {
   146                 editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier0] autorelease];
   146                 editableCell = [[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier0];
   147                 editableCell.minimumCharacters = 0;
   147                 editableCell.minimumCharacters = 0;
   148                 editableCell.delegate = self;
   148                 editableCell.delegate = self;
   149                 editableCell.textField.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
   149                 editableCell.textField.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
   150                 editableCell.textField.textColor = [UIColor blackColor];
   150                 editableCell.textField.textColor = [UIColor blackColor];
   151             }
   151             }
   168             cell = editableCell;
   168             cell = editableCell;
   169             break;
   169             break;
   170         case 1:
   170         case 1:
   171             cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier1];
   171             cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier1];
   172             if (nil == cell) {
   172             if (nil == cell) {
   173                 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier1] autorelease];
   173                 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier1];
   174                 UISwitch *theSwitch = [[UISwitch alloc] init];
   174                 UISwitch *theSwitch = [[UISwitch alloc] init];
   175                 [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
   175                 [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
   176                 cell.accessoryView = theSwitch;
   176                 cell.accessoryView = theSwitch;
   177                 [theSwitch release];
       
   178             }
   177             }
   179 
   178 
   180             switchContent = (UISwitch *)cell.accessoryView;
   179             switchContent = (UISwitch *)cell.accessoryView;
   181             if (row == 0) {
   180             if (row == 0) {
   182                 cell.textLabel.text = NSLocalizedString(@"Sound", @"from the settings table");
   181                 cell.textLabel.text = NSLocalizedString(@"Sound", @"from the settings table");
   189             }
   188             }
   190             break;
   189             break;
   191         case 2:
   190         case 2:
   192             cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier2];
   191             cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier2];
   193             if (nil == cell) {
   192             if (nil == cell) {
   194                 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier2] autorelease];
   193                 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier2];
   195                 UISwitch *theSwitch = [[UISwitch alloc] init];
   194                 UISwitch *theSwitch = [[UISwitch alloc] init];
   196                 [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
   195                 [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
   197                 cell.accessoryView = theSwitch;
   196                 cell.accessoryView = theSwitch;
   198                 [theSwitch release];
       
   199             }
   197             }
   200 
   198 
   201             switchContent = (UISwitch *)cell.accessoryView;
   199             switchContent = (UISwitch *)cell.accessoryView;
   202             cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
   200             cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
   203             switch (row) {
   201             switch (row) {
   229     return cell;
   227     return cell;
   230 }
   228 }
   231 
   229 
   232 #pragma mark -
   230 #pragma mark -
   233 #pragma mark Table view delegate
   231 #pragma mark Table view delegate
   234 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   232 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   235     [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
   233     [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
   236     if (0 == [indexPath section]) {
   234     if (0 == [indexPath section]) {
   237         EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
   235         EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
   238         [cell replyKeyboard];
   236         [cell replyKeyboard];
   239     }
   237     }
   240 }
   238 }
   241 
   239 
   242 
   240 
   243 #pragma mark -
   241 #pragma mark -
   244 #pragma mark Memory management
   242 #pragma mark Memory management
   245 -(void) didReceiveMemoryWarning {
   243 
       
   244 - (void)didReceiveMemoryWarning {
   246     [super didReceiveMemoryWarning];
   245     [super didReceiveMemoryWarning];
   247 }
   246 }
   248 
   247 
   249 -(void) viewDidUnload {
       
   250     [super viewDidUnload];
       
   251 }
       
   252 
       
   253 -(void) dealloc {
       
   254     [super dealloc];
       
   255 }
       
   256 
       
   257 @end
   248 @end