cocoaTouch/GeneralSettingsViewController.m
author koda
Tue, 06 Apr 2010 18:14:15 +0000
changeset 3312 6d8f1c76756d
child 3332 3c90a923f156
permissions -rw-r--r--
restore and update the old general settings show hats in the team table
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3312
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
     1
//
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
     2
//  SettingsViewController.m
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
     3
//  hwengine
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
     4
//
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
     5
//  Created by Vittorio on 08/01/10.
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
     7
//
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
     8
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
     9
#import "GeneralSettingsViewController.h"
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    10
#import "SDL_uikitappdelegate.h"
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    11
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    12
@implementation GeneralSettingsViewController
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    13
@synthesize dataDict, username, password, musicSwitch, soundSwitch, altDamageSwitch;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    14
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    15
-(void) dealloc {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    16
    [dataDict release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    17
	[username release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    18
	[password release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    19
	[musicSwitch release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    20
	[soundSwitch release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    21
	[altDamageSwitch release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    22
	[super dealloc];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    23
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    24
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    25
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    26
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    27
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    28
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    29
#pragma mark -
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    30
#pragma mark View Lifecycle
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    31
-(void) viewDidLoad {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    32
    self.musicSwitch = [[UISwitch alloc] init];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    33
	self.soundSwitch = [[UISwitch alloc] init];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    34
	self.altDamageSwitch = [[UISwitch alloc] init];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    35
	[self.soundSwitch addTarget:self action:@selector(sameValueSwitch) forControlEvents:UIControlEventValueChanged];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    36
	[self.musicSwitch addTarget:self action:@selector(checkValueSwitch) forControlEvents:UIControlEventValueChanged];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    37
    
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    38
    NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    39
    NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:filePath];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    40
    self.dataDict = dictionary;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    41
    [dictionary release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    42
	[super viewDidLoad];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    43
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    44
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    45
-(void) viewDidUnload {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    46
    self.dataDict = nil;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    47
	self.username = nil;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    48
	self.password = nil;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    49
	self.musicSwitch = nil;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    50
	self.soundSwitch = nil;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    51
	self.altDamageSwitch = nil;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    52
	[super viewDidUnload];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    53
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    54
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    55
-(void) viewWillAppear:(BOOL)animated {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    56
    [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    57
    
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    58
    username = [NSString stringWithString:[dataDict objectForKey:@"username"]];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    59
    password = [NSString stringWithString:[dataDict objectForKey:@"password"]];   
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    60
    
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    61
    if (1 == [[dataDict objectForKey:@"music"] intValue]) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    62
        musicSwitch.on = YES;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    63
    } else {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    64
        musicSwitch.on = NO;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    65
    }
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    66
    if (1 == [[dataDict objectForKey:@"sounds"] intValue]) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    67
        soundSwitch.on = YES;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    68
    } else {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    69
        soundSwitch.on = NO;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    70
    }
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    71
    if (1 == [[dataDict objectForKey:@"alternate"] intValue]) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    72
        altDamageSwitch.on = YES;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    73
    } else {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    74
        altDamageSwitch.on = NO;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    75
    }
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    76
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    77
    [super viewWillAppear:animated];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    78
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    79
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    80
-(void) viewWillDisappear:(BOOL)animated {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    81
    [super viewWillDisappear:animated];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    82
    
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    83
	NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    84
	NSString *tmpMus = (musicSwitch.on) ? @"1" : @"0";
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    85
	NSString *tmpEff = (soundSwitch.on) ? @"1" : @"0";
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    86
	NSString *tmpAlt = (altDamageSwitch.on) ? @"1" : @"0";
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    87
	 
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    88
	[saveDict setObject:username forKey:@"username"];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    89
	[saveDict setObject:password forKey:@"password"];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    90
	[saveDict setObject:tmpMus forKey:@"music"];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    91
	[saveDict setObject:tmpEff forKey:@"sounds"];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    92
	[saveDict setObject:tmpAlt forKey:@"alternate"];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    93
	
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    94
    if (![dataDict isEqualToDictionary:saveDict]) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    95
       	NSLog(@"writing preferences to file");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    96
        [saveDict writeToFile:[[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"] atomically:YES];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    97
        // this will also relase the previous dictionary
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    98
        self.dataDict = saveDict;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
    99
    }
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   100
	[saveDict release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   101
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   102
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   103
#pragma mark -
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   104
// set music off when sound is turned off
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   105
-(void) sameValueSwitch {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   106
	if (YES == self.musicSwitch.on) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   107
		[musicSwitch setOn:NO animated:YES];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   108
	}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   109
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   110
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   111
// don't enable music when sound is off
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   112
-(void) checkValueSwitch {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   113
	if (NO == self.soundSwitch.on) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   114
		[musicSwitch setOn:!musicSwitch.on animated:YES];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   115
	}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   116
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   117
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   118
/*
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   119
// makes the keyboard go away when background is tapped
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   120
-(IBAction) backgroundTap: (id)sender {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   121
//	[username resignFirstResponder];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   122
//	[password resignFirstResponder];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   123
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   124
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   125
// makes the keyboard go away when "Done" is tapped
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   126
-(IBAction) textFieldDoneEditing: (id)sender {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   127
	[sender resignFirstResponder];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   128
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   129
*/
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   130
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   131
/*
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   132
#pragma mark -
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   133
#pragma mark UIActionSheet Methods
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   134
-(IBAction) deleteData: (id)sender {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   135
	UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   136
								 delegate:self
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   137
							cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   138
						   destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   139
							otherButtonTitles:nil];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   140
	[actionSheet showInView:self.view];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   141
	[actionSheet release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   142
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   143
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   144
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   145
	if ([actionSheet cancelButtonIndex] != buttonIndex) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   146
		// get the documents dirctory
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   147
		NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   148
		NSString *documentsDirectory = [paths objectAtIndex:0];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   149
		
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   150
		// get the content of the directory
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   151
		NSFileManager *fm = [NSFileManager defaultManager];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   152
		NSArray *dirContent = [fm directoryContentsAtPath:documentsDirectory];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   153
		NSError *error;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   154
		
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   155
		// delete data
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   156
		for (NSString *fileName in dirContent) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   157
			[fm removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:fileName] error:&error];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   158
		}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   159
		
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   160
		// force resetting
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   161
		UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Hit Home Button to Exit", @"")
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   162
								  message:NSLocalizedString(@"\nEverything is gone!\nNow you need to restart the game...", @"")
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   163
								 delegate:self
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   164
							cancelButtonTitle:nil
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   165
							otherButtonTitles:nil];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   166
		[anAlert show];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   167
		[anAlert release];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   168
	}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   169
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   170
*/
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   171
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   172
#pragma mark -
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   173
#pragma mark TableView Methods
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   174
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   175
	return 3;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   176
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   177
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   178
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   179
	switch (section) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   180
		case kNetworkFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   181
			return 2;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   182
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   183
		case kAudioFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   184
			return 2;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   185
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   186
		case kOtherFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   187
			return 1;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   188
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   189
		default:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   190
			NSLog(@"Warning: unset case value for numberOfRowsInSection!");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   191
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   192
	}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   193
	return 0;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   194
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   195
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   196
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   197
	static NSString *cellIdentifier1 = @"systemSettingsCell1";
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   198
	static NSString *cellIdentifier2 = @"systemSettingsCell2";
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   199
	
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   200
	UITableViewCell *cell = nil;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   201
	
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   202
	switch ([indexPath section]) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   203
		case kNetworkFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   204
            cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier1];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   205
            if (nil == cell) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   206
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   207
                                           reuseIdentifier:cellIdentifier1] autorelease];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   208
            }
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   209
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   210
            
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   211
			switch ([indexPath row]) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   212
				case 0:                    
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   213
					cell.textLabel.text = NSLocalizedString(@"Nickname", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   214
                    if ([username isEqualToString:@""]) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   215
                        cell.detailTextLabel.text = @"insert username...";
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   216
                        cell.detailTextLabel.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   217
                        cell.detailTextLabel.textColor = [UIColor grayColor];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   218
                    } else {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   219
                        cell.detailTextLabel.text = username;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   220
                    }
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   221
					break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   222
				case 1:                    
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   223
					cell.textLabel.text = NSLocalizedString(@"Password", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   224
                    if ([password isEqualToString:@""]) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   225
                        cell.detailTextLabel.text = @"insert password...";
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   226
                        cell.detailTextLabel.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   227
                        cell.detailTextLabel.textColor = [UIColor grayColor];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   228
                    } else {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   229
                        cell.detailTextLabel.text = @"••••••••";
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   230
                    }
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   231
					break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   232
				default:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   233
					NSLog(@"Warning: unset case value in kNetworkFields section!");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   234
					break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   235
			}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   236
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   237
            
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   238
		case kAudioFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   239
            cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier2];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   240
            if (nil == cell) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   241
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   242
                                               reuseIdentifier:cellIdentifier2] autorelease];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   243
            }
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   244
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   245
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   246
			switch ([indexPath row]) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   247
				case 0:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   248
					cell.textLabel.text = NSLocalizedString(@"Sound", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   249
					cell.accessoryView = soundSwitch;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   250
					break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   251
				case 1:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   252
					cell.textLabel.text = NSLocalizedString(@"Music", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   253
					cell.accessoryView = musicSwitch;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   254
					break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   255
				default:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   256
					NSLog(@"Warning: unset case value in kAudioFields section!");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   257
					break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   258
			}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   259
            // this makes the row not selectable
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   260
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   261
            
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   262
		case kOtherFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   263
            cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier2];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   264
            if (nil == cell) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   265
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   266
                                               reuseIdentifier:cellIdentifier2] autorelease];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   267
            }
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   268
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   269
			cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   270
			cell.accessoryView = altDamageSwitch;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   271
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   272
		default:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   273
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   274
	}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   275
	return cell;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   276
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   277
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   278
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   279
    NSString *sectionTitle = nil;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   280
    switch (section) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   281
		case kNetworkFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   282
			sectionTitle = NSLocalizedString(@"Network Configuration", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   283
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   284
		case kAudioFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   285
			sectionTitle = NSLocalizedString(@"Audio Preferences", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   286
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   287
		case kOtherFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   288
			sectionTitle = NSLocalizedString(@"Other Settings", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   289
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   290
		default:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   291
			NSLog(@"Nope");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   292
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   293
	}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   294
    return sectionTitle;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   295
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   296
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   297
/*
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   298
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   299
	UIView *containerView =	[[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)] autorelease];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   300
	UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 40)] autorelease];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   301
	headerLabel.textColor = [UIColor lightGrayColor];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   302
	headerLabel.shadowColor = [UIColor blackColor];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   303
	headerLabel.shadowOffset = CGSizeMake(0, 1);
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   304
	headerLabel.font = [UIFont boldSystemFontOfSize:20];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   305
	headerLabel.backgroundColor = [UIColor clearColor];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   306
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   307
	switch (section) {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   308
		case kNetworkFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   309
			headerLabel.text = NSLocalizedString(@"Network Configuration", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   310
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   311
		case kAudioFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   312
			headerLabel.text = NSLocalizedString(@"Audio Preferences", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   313
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   314
		case kOtherFields:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   315
			headerLabel.text = NSLocalizedString(@"Other Settings", @"");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   316
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   317
		default:
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   318
			NSLog(@"Warning: unset case value in titleForHeaderInSection!");
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   319
			headerLabel.text = @"!";
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   320
			break;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   321
	}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   322
	
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   323
	[containerView addSubview:headerLabel];
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   324
	return containerView;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   325
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   326
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   327
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   328
	if (kAudioFields == [indexPath section] && 2 == [indexPath row])
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   329
		return volumeCell.frame.size.height;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   330
	else
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   331
		return table.rowHeight;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   332
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   333
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   334
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   335
	return 57.0;
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   336
}
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   337
*/
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   338
6d8f1c76756d restore and update the old general settings
koda
parents:
diff changeset
   339
@end