project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m
author koda
Thu, 16 Dec 2010 01:45:15 +0100
changeset 4540 9b614e420de5
parent 4539 bad3411cba49
child 4947 cfac6aab84a0
permissions -rw-r--r--
add two preferences for enabling/disabling blurry land and multitasking
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
     1
/*
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
     4
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
     8
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    12
 * GNU General Public License for more details.
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    13
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    14
 * You should have received a copy of the GNU General Public License
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    15
 * along with this program; if not, write to the Free Software
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    17
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    18
 * File created on 08/01/2010.
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    19
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3803
diff changeset
    20
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
#import "GeneralSettingsViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
@implementation GeneralSettingsViewController
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    26
@synthesize settingsDictionary;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
#pragma mark View Lifecycle
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
-(void) viewWillAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
    [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3663
diff changeset
    41
3663
8c28abf427f5 reduce the number of keywords used and switch to BMP format for screenshots
koda
parents: 3662
diff changeset
    42
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
8c28abf427f5 reduce the number of keywords used and switch to BMP format for screenshots
koda
parents: 3662
diff changeset
    43
    self.settingsDictionary = dictionary;
8c28abf427f5 reduce the number of keywords used and switch to BMP format for screenshots
koda
parents: 3662
diff changeset
    44
    [dictionary release];
8c28abf427f5 reduce the number of keywords used and switch to BMP format for screenshots
koda
parents: 3662
diff changeset
    45
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
    [super viewWillAppear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
-(void) viewWillDisappear:(BOOL)animated {
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3663
diff changeset
    50
    [super viewWillDisappear:animated];
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
    51
    [self.settingsDictionary writeToFile:SETTINGS_FILE() atomically:YES];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
#pragma mark -
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    55
-(void) switchValueChanged:(id) sender {
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    56
    UISwitch *theSwitch = (UISwitch *)sender;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    57
    UISwitch *theOtherSwitch = nil;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3663
diff changeset
    58
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    59
    switch (theSwitch.tag) {
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    60
        case 10:    //soundSwitch
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    61
            // this turn off also the switch below
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    62
            [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    63
            [self.settingsDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    64
            theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    65
            [theOtherSwitch setOn:NO animated:YES];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    66
            break;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    67
        case 20:    //musicSwitch
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    68
            // if switch above is off, never turn on
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    69
            if (NO == [[self.settingsDictionary objectForKey:@"sound"] boolValue]) {
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    70
                [self.settingsDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    71
                theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    72
                [theOtherSwitch setOn:NO animated:YES];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    73
            } else
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    74
                [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    75
            break;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    76
        case 30:    //alternateSwitch
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    77
            [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    78
            break;
4540
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
    79
        case 70:    //enhanced graphics
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
    80
            [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"enhanced"];
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
    81
            break;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
    82
        case 80:    //nomultitasking
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
    83
            [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"multitasking"];
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
    84
            break;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
    85
        case 60:    //classic menu
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3884
diff changeset
    86
            [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"menu"];
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
    87
            break;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    88
        default:
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    89
            DLog(@"Wrong tag");
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    90
            break;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    94
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    95
    if (tagValue == 40)
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    96
        [self.settingsDictionary setObject:textString forKey:@"username"];
4539
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
    97
    else {
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
    98
        [self.settingsDictionary setObject:[NSNumber numberWithInt:[textString length]] forKey:@"password_length"];
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
    99
        [self.settingsDictionary setObject:[textString MD5hash] forKey:@"password"];
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   100
    }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   103
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
#pragma mark TableView Methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
    return 3;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   107
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
4539
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   109
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger )section {
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
    switch (section) {
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   111
        case 0:     // user and pass
3783
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3779
diff changeset
   112
            return 1;   // set 2 here for the password field
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   113
            break;
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   114
        case 1:     // audio
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   115
            return 2;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
            break;
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   117
        case 2:     // other stuff
4540
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   118
            if (IS_IPAD() == YES)
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   119
                return 4;
4244
bf46b4bdf27d iphone interface
koda
parents: 3935
diff changeset
   120
            else
4540
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   121
                return 3;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
        default:
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3884
diff changeset
   124
            DLog(@"Nope");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
    return 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   129
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   131
    NSString *sectionTitle = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
    switch (section) {
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   133
        case 0:
3803
e4a8a4e378de remove now useless toggle, add ai team
koda
parents: 3783
diff changeset
   134
            sectionTitle = NSLocalizedString(@"Main Configuration", @"");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   135
            break;
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   136
        case 1:
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
            sectionTitle = NSLocalizedString(@"Audio Preferences", @"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
            break;
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   139
        case 2:
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   140
            sectionTitle = NSLocalizedString(@"Other Settings", @"");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   141
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   142
        default:
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   143
            DLog(@"Nope");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   144
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   145
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   146
    return sectionTitle;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   147
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   148
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   149
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   150
    static NSString *cellIdentifier0 = @"Cell0";
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   151
    static NSString *cellIdentifier1 = @"Cell1";
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   152
    static NSString *cellIdentifier2 = @"Cell2";
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   153
    NSInteger row = [indexPath row];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   154
    NSInteger section = [indexPath section];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3663
diff changeset
   155
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   156
    UITableViewCell *cell = nil;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   157
    EditableCellView *editableCell = nil;
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   158
    UISwitch *switchContent = nil;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   159
    switch(section) {
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   160
        case 0:
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   161
            editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:cellIdentifier0];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   162
            if (nil == editableCell) {
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   163
                editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier0] autorelease];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   164
                editableCell.minimumCharacters = 0;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   165
                editableCell.delegate = self;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   166
                editableCell.textField.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
4341
46b8791e577f minor things
koda
parents: 4244
diff changeset
   167
                editableCell.textField.textColor = [UIColor blackColor];
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   168
            }
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   169
            
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   170
            if (row == 0) {
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   171
                editableCell.titleLabel.text = NSLocalizedString(@"Nickname","from the settings table");
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   172
                editableCell.textField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@"");
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   173
                editableCell.textField.text = [self.settingsDictionary objectForKey:@"username"];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   174
                editableCell.textField.secureTextEntry = NO;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   175
                editableCell.tag = 40;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   176
            } else {
4539
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   177
                // create a dummy password for setting some visual content for the password
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   178
                int pwdLength = [[self.settingsDictionary objectForKey:@"password_length"] intValue];
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   179
                char *dummyStr = (char *)malloc(sizeof(char)*pwdLength);
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   180
                for (int i = 0; i < pwdLength; i++)
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   181
                    dummyStr[i] = i;
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   182
                NSString *dummy = [[NSString alloc] initWithBytes:dummyStr length:pwdLength encoding:NSASCIIStringEncoding];
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   183
                free(dummyStr);
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   184
                editableCell.titleLabel.text = NSLocalizedString(@"Password","from the settings table");
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   185
                editableCell.textField.placeholder = NSLocalizedString(@"Insert your password",@"");
4539
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   186
                editableCell.textField.text = dummy;
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   187
                editableCell.textField.secureTextEntry = YES;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   188
                editableCell.tag = 50;
4539
bad3411cba49 store the (future) password with md5 for ifrontend
koda
parents: 4341
diff changeset
   189
                [dummy release];
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   190
            }
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   191
            
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   192
            editableCell.accessoryView = nil;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   193
            cell = editableCell;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   194
            break;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   195
        case 1:
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   196
            cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier1];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   197
            if (nil == cell) {
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   198
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier1] autorelease];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   199
                UISwitch *theSwitch = [[UISwitch alloc] init];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   200
                [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   201
                cell.accessoryView = theSwitch;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   202
                [theSwitch release];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   203
            }
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   204
            
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   205
            switchContent = (UISwitch *)cell.accessoryView;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   206
            if (row == 0) {
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   207
                cell.textLabel.text = NSLocalizedString(@"Sound", @"");
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   208
                switchContent.on = [[self.settingsDictionary objectForKey:@"sound"] boolValue];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   209
                switchContent.tag = 10;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   210
            } else {
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   211
                cell.textLabel.text = NSLocalizedString(@"Music", @"");
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   212
                switchContent.on = [[self.settingsDictionary objectForKey:@"music"] boolValue];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   213
                switchContent.tag = 20;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   214
            }
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   215
            break;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   216
        case 2:
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   217
            cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier2];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   218
            if (nil == cell) {
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   219
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier2] autorelease];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   220
                UISwitch *theSwitch = [[UISwitch alloc] init];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   221
                [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   222
                cell.accessoryView = theSwitch;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   223
                [theSwitch release];
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   224
            }
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   225
            
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   226
            switchContent = (UISwitch *)cell.accessoryView;
4540
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   227
            switch (row) {
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   228
                case 0:
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   229
                    cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @"");
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   230
                    cell.detailTextLabel.text = NSLocalizedString(@"Damage popups will notify you on every single hit", @"");
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   231
                    switchContent.on = [[self.settingsDictionary objectForKey:@"alternate"] boolValue];
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   232
                    switchContent.tag = 30;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   233
                    break;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   234
                case 1:
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   235
                    cell.textLabel.text = NSLocalizedString(@"Enanched Graphics Mode", @"");
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   236
                    cell.detailTextLabel.text = NSLocalizedString(@"The game will use more memory so it could crash!", @"");
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   237
                    switchContent.on = [[self.settingsDictionary objectForKey:@"enhanced"] boolValue];
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   238
                    switchContent.tag = 70;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   239
                    break;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   240
                case 2:
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   241
                    cell.textLabel.text = NSLocalizedString(@"Multitasking Enabled", @"");
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   242
                    cell.detailTextLabel.text = NSLocalizedString(@"Disable it in case of issues when returing in game", @"");
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   243
                    switchContent.on = [[self.settingsDictionary objectForKey:@"multitasking"] boolValue];
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   244
                    switchContent.tag = 80;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   245
                    break;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   246
                case 3:
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   247
                    cell.textLabel.text = NSLocalizedString(@"Classic Ammo Menu", @"");
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   248
                    cell.detailTextLabel.text = NSLocalizedString(@"Select which style of ammo menu you prefer",@"");
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   249
                    switchContent.on = [[self.settingsDictionary objectForKey:@"menu"] boolValue];
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   250
                    switchContent.tag = 60;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   251
                    break;
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   252
                default:
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   253
                    DLog(@"Nope");
9b614e420de5 add two preferences for enabling/disabling blurry land and multitasking
koda
parents: 4539
diff changeset
   254
                    break;
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   255
            }
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   256
            break;
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   257
        default:
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   258
            break;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   259
    }
3779
3351a017d4ad tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents: 3703
diff changeset
   260
    
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   261
    cell.accessoryType = UITableViewCellAccessoryNone;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   262
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   263
    cell.imageView.image = nil;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3663
diff changeset
   264
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   265
    return cell;
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   266
}
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   267
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   268
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   269
#pragma mark Table view delegate
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   270
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3660
bc125bea5849 complete settings page rework
koda
parents: 3659
diff changeset
   271
    if (0 == [indexPath section]) {
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   272
        EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   273
        [cell replyKeyboard];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   274
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   275
}
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   276
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   277
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   278
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   279
#pragma mark Memory management
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   280
-(void) didReceiveMemoryWarning {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   281
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   282
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   283
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   284
-(void) viewDidUnload {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   285
    self.settingsDictionary = nil;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
   286
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   287
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   288
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   289
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   290
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   291
    [settingsDictionary release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   292
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   293
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   294
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   295
@end