cocoaTouch/SettingsViewController.m
author unc0rr
Thu, 01 Apr 2010 05:10:50 +0000
changeset 3228 44a59edc7bac
parent 3113 2829ea0dd47c
permissions -rw-r--r--
- update russian translation a bit - lupdate + lrelease
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     1
//
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     2
//  SettingsViewController.m
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     3
//  hwengine
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     4
//
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     5
//  Created by Vittorio on 08/01/10.
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     7
//
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     8
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
     9
#import "SettingsViewController.h"
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    10
#import "SDL_uikitappdelegate.h"
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    11
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    12
@implementation SettingsViewController
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    13
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
    14
@synthesize username, password, musicSwitch, soundsSwitch, altDamageSwitch, 
2743
39d097ac2276 implement transition in the way i had in mind
koda
parents: 2740
diff changeset
    15
	    settingsTable, buttonContainer, parentView;
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    16
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    17
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    18
-(void) loadView {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    19
	self.musicSwitch = [[UISwitch alloc] init];
2702
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    20
	self.soundsSwitch = [[UISwitch alloc] init];
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    21
	self.altDamageSwitch = [[UISwitch alloc] init];
2702
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    22
	[self.soundsSwitch addTarget:self action:@selector(sameValueSwitch) forControlEvents:UIControlEventValueChanged];
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    23
	[self.musicSwitch addTarget:self action:@selector(checkValueSwitch) forControlEvents:UIControlEventValueChanged];
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    24
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    25
	[super loadView];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    26
}
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    27
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    28
-(void) viewDidLoad {
2698
90585aba87ad objc/pascal finally working
koda
parents: 2696
diff changeset
    29
	NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    30
	
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    31
	if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {	
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    32
		NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    33
		username.text = [data objectForKey:@"username"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    34
		password.text = [data objectForKey:@"password"];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    35
		if (1 == [[data objectForKey:@"music"] intValue]) {
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    36
			musicSwitch.on = YES;
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    37
		} else {
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    38
			musicSwitch.on = NO;
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    39
		}
2702
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    40
		if (1 == [[data objectForKey:@"sounds"] intValue]) {
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    41
			soundsSwitch.on = YES;
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    42
		} else {
2702
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    43
			soundsSwitch.on = NO;
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    44
		}
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    45
		if (1 == [[data objectForKey:@"alternate"] intValue]) {
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    46
			altDamageSwitch.on = YES;
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    47
		} else {
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    48
			altDamageSwitch.on = NO;
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    49
		}		
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    50
		[data release];
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    51
	} else {
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    52
		[NSException raise:@"File NOT found" format:@"The file settings.plist was not found at %@", filePath];
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    53
	}
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    54
	
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    55
	
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    56
	username.textColor = [UIColor grayColor];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    57
	password.textColor = [UIColor grayColor];
2743
39d097ac2276 implement transition in the way i had in mind
koda
parents: 2740
diff changeset
    58
	settingsTable.backgroundColor = [UIColor clearColor];
39d097ac2276 implement transition in the way i had in mind
koda
parents: 2740
diff changeset
    59
	settingsTable.allowsSelection = NO;
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
    60
	buttonContainer.backgroundColor = [UIColor clearColor];
2743
39d097ac2276 implement transition in the way i had in mind
koda
parents: 2740
diff changeset
    61
	settingsTable.tableFooterView = buttonContainer;
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
    62
	
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    63
	[super viewDidLoad];
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    64
}
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    65
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    66
-(void) viewDidUnload {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    67
	self.username = nil;
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    68
	self.password = nil;
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    69
	self.musicSwitch = nil;
2702
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    70
	self.soundsSwitch = nil;
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
    71
	self.altDamageSwitch = nil;
2743
39d097ac2276 implement transition in the way i had in mind
koda
parents: 2740
diff changeset
    72
	self.settingsTable = nil;
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
    73
	self.buttonContainer = nil;
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    74
	[super viewDidUnload];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    75
}
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    76
2702
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    77
-(void) dealloc {
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    78
	[username release];
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    79
	[password release];
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    80
	[musicSwitch release];
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    81
	[soundsSwitch release];
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    82
	[altDamageSwitch release];
2743
39d097ac2276 implement transition in the way i had in mind
koda
parents: 2740
diff changeset
    83
	[settingsTable release];
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
    84
	[buttonContainer release];
2702
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    85
	[super dealloc];
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
    86
}
2740
03df0573a9fd programmatically load main controller
koda
parents: 2723
diff changeset
    87
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    88
// Override to allow orientations other than the default portrait orientation.
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    89
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    90
    // Return YES for supported orientations
3113
2829ea0dd47c * port fadeout to opengles
koda
parents: 2805
diff changeset
    91
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
    92
}
2740
03df0573a9fd programmatically load main controller
koda
parents: 2723
diff changeset
    93
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
    94
// makes the keyboard go away when background is tapped
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    95
-(IBAction) backgroundTap: (id)sender {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    96
	[username resignFirstResponder];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    97
	[password resignFirstResponder];
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    98
}
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
    99
2696
41aa7b56c17b settings are applied to game launch
koda
parents: 2694
diff changeset
   100
// makes the keyboard go away when "Done" is tapped
2694
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   101
-(IBAction) textFieldDoneEditing: (id)sender {
dcd248e04f3d can use latest sdlimage, work on setting panel and option when launching the game, minor fixes
koda
parents: 2687
diff changeset
   102
	[sender resignFirstResponder];
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   103
}
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   104
2702
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   105
// set music off when sound is turned off
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   106
-(void) sameValueSwitch {
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   107
	if (YES == self.musicSwitch.on) {
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   108
		[musicSwitch setOn:NO animated:YES];
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   109
	}
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   110
}
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   111
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   112
// don't enable music when sound is off
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   113
-(void) checkValueSwitch {
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   114
	if (NO == self.soundsSwitch.on) {
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   115
		[musicSwitch setOn:!musicSwitch.on animated:YES];
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   116
	}
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   117
}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   118
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   119
#pragma mark -
2803
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   120
#pragma mark Return to mainView
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   121
-(void) flushData {
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   122
	NSLog(@"writing preferences to file");
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   123
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   124
	NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   125
	NSString *tmpMus = (musicSwitch.on) ? @"1" : @"0";
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   126
	NSString *tmpEff = (soundsSwitch.on) ? @"1" : @"0";
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   127
	NSString *tmpAlt = (altDamageSwitch.on) ? @"1" : @"0";
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   128
	
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   129
	[saveDict setObject:username.text forKey:@"username"];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   130
	[saveDict setObject:password.text forKey:@"password"];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   131
	[saveDict setObject:tmpMus forKey:@"music"];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   132
	[saveDict setObject:tmpEff forKey:@"sounds"];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   133
	[saveDict setObject:tmpAlt forKey:@"alternate"];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   134
	
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   135
	[saveDict writeToFile:[[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"] atomically:YES];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   136
	[saveDict release];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   137
}
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   138
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   139
-(void) returnMainView {
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   140
	[self flushData];
3113
2829ea0dd47c * port fadeout to opengles
koda
parents: 2805
diff changeset
   141
    //[self dismissModalViewControllerAnimated:YES]
2803
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   142
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   143
	[UIView beginAnimations:@"Get Back" context:NULL];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   144
	[UIView setAnimationDuration:1];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   145
	
2805
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2803
diff changeset
   146
	self.view.frame = CGRectMake(0, -257, 480, 278);
36a8cebb91e8 new menupage ingame for common actions
koda
parents: 2803
diff changeset
   147
	self.parentView.frame = CGRectMake(0, 21, 480, 278);
2803
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   148
	[UIView commitAnimations];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   149
	
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   150
	[self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   151
	self.parentView = nil;
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   152
}
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   153
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   154
#pragma mark -
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   155
#pragma mark UIActionSheet Methods
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   156
-(IBAction) deleteData: (id)sender {
2740
03df0573a9fd programmatically load main controller
koda
parents: 2723
diff changeset
   157
	/* temporary commented out
2723
eaa6ac1e95ea LANDSCAPE ON IPHONE
koda
parents: 2720
diff changeset
   158
	UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   159
								 delegate:self
2723
eaa6ac1e95ea LANDSCAPE ON IPHONE
koda
parents: 2720
diff changeset
   160
							cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
eaa6ac1e95ea LANDSCAPE ON IPHONE
koda
parents: 2720
diff changeset
   161
						   destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   162
							otherButtonTitles:nil];
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   163
	[actionSheet showInView:self.view];
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   164
	[actionSheet release];
2740
03df0573a9fd programmatically load main controller
koda
parents: 2723
diff changeset
   165
	 */
2803
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
   166
	[self returnMainView];
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   167
}
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   168
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   169
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   170
	if ([actionSheet cancelButtonIndex] != buttonIndex) {
2723
eaa6ac1e95ea LANDSCAPE ON IPHONE
koda
parents: 2720
diff changeset
   171
		// get the documents dirctory
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   172
		NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   173
		NSString *documentsDirectory = [paths objectAtIndex:0];
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   174
		
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   175
		// get the content of the directory
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   176
		NSFileManager *fm = [NSFileManager defaultManager];
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   177
		NSArray *dirContent = [fm directoryContentsAtPath:documentsDirectory];
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   178
		NSError *error;
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   179
		
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   180
		// delete data
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   181
		for (NSString *fileName in dirContent) {
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   182
			[fm removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:fileName] error:&error];
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   183
		}
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   184
		
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   185
		// force resetting
2723
eaa6ac1e95ea LANDSCAPE ON IPHONE
koda
parents: 2720
diff changeset
   186
		UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Hit Home Button to Exit", @"")
eaa6ac1e95ea LANDSCAPE ON IPHONE
koda
parents: 2720
diff changeset
   187
								  message:NSLocalizedString(@"\nEverything is gone!\nNow you need to restart the game...", @"")
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   188
								 delegate:self
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   189
							cancelButtonTitle:nil
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   190
							otherButtonTitles:nil];
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   191
		[anAlert show];
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   192
		[anAlert release];
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   193
	}
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   194
}
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   195
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   196
#pragma mark -
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   197
#pragma mark TableView Methods
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   198
#define kNetworkFields 0
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   199
#define kAudioFields 1
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   200
#define kOtherFields 2
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   201
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   202
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   203
	return 3;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   204
}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   205
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   206
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   207
	switch (section) {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   208
		case kNetworkFields:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   209
			return 2;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   210
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   211
		case kAudioFields:
2743
39d097ac2276 implement transition in the way i had in mind
koda
parents: 2740
diff changeset
   212
			return 2;
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   213
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   214
		case kOtherFields:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   215
			return 1;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   216
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   217
		default:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   218
			NSLog(@"Warning: unset case value for numberOfRowsInSection!");
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   219
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   220
	}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   221
	return 0;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   222
}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   223
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   224
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   225
	static NSString *cellIdentifier = @"systemSettingsCell";
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   226
	
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   227
	UITableViewCell *cell;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   228
	if ( !(kAudioFields == [indexPath section] && 2 == [indexPath row]) ){
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   229
		cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   230
		if (nil == cell) {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   231
			cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   232
						       reuseIdentifier:cellIdentifier] autorelease];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   233
		}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   234
	}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   235
	
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   236
	switch ([indexPath section]) {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   237
		case kNetworkFields:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   238
			switch ([indexPath row]) {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   239
				case 0:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   240
					cell.textLabel.text = NSLocalizedString(@"Nickname", @"");
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   241
					cell.accessoryView = username;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   242
					break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   243
				case 1:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   244
					cell.textLabel.text = NSLocalizedString(@"Password", @"");
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   245
					cell.accessoryView = password;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   246
					break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   247
				default:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   248
					NSLog(@"Warning: unset case value in kNetworkFields section!");
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   249
					break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   250
			}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   251
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   252
		case kAudioFields:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   253
			switch ([indexPath row]) {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   254
				case 0:
2702
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   255
					cell.accessoryView = soundsSwitch;
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   256
					cell.textLabel.text = NSLocalizedString(@"Sound", @"");
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   257
					break;
48fc46a922fd rewrite gamesetup to use less memory, rename effects to sound plus some nice actions, settings work in game again
koda
parents: 2701
diff changeset
   258
				case 1:
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   259
					cell.accessoryView = musicSwitch;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   260
					cell.textLabel.text = NSLocalizedString(@"Music", @"");
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   261
					break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   262
				default:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   263
					NSLog(@"Warning: unset case value in kAudioFields section!");
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   264
					break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   265
			}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   266
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   267
		case kOtherFields:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   268
			cell.accessoryView = altDamageSwitch;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   269
			cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @"");
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   270
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   271
		default:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   272
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   273
	}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   274
	
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   275
	return cell;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   276
}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   277
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   278
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   279
	UIView *containerView =	[[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)] autorelease];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   280
	UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 40)] autorelease];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   281
	headerLabel.textColor = [UIColor lightGrayColor];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   282
	headerLabel.shadowColor = [UIColor blackColor];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   283
	headerLabel.shadowOffset = CGSizeMake(0, 1);
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   284
	headerLabel.font = [UIFont boldSystemFontOfSize:20];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   285
	headerLabel.backgroundColor = [UIColor clearColor];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   286
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   287
	switch (section) {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   288
		case kNetworkFields:
2723
eaa6ac1e95ea LANDSCAPE ON IPHONE
koda
parents: 2720
diff changeset
   289
			headerLabel.text = NSLocalizedString(@"Network Configuration", @"");
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   290
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   291
		case kAudioFields:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   292
			headerLabel.text = NSLocalizedString(@"Audio Preferences", @"");
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   293
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   294
		case kOtherFields:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   295
			headerLabel.text = NSLocalizedString(@"Other Settings", @"");
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   296
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   297
		default:
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   298
			NSLog(@"Warning: unset case value in titleForHeaderInSection!");
2723
eaa6ac1e95ea LANDSCAPE ON IPHONE
koda
parents: 2720
diff changeset
   299
			headerLabel.text = @"!";
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   300
			break;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   301
	}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   302
	
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   303
	[containerView addSubview:headerLabel];
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   304
	return containerView;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   305
}
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   306
2743
39d097ac2276 implement transition in the way i had in mind
koda
parents: 2740
diff changeset
   307
/*
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   308
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   309
	if (kAudioFields == [indexPath section] && 2 == [indexPath row])
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   310
		return volumeCell.frame.size.height;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   311
	else
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   312
		return table.rowHeight;
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   313
}
2743
39d097ac2276 implement transition in the way i had in mind
koda
parents: 2740
diff changeset
   314
*/
2701
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   315
3a8560c00f78 settings tab has now a very nice iphone-like interface
koda
parents: 2698
diff changeset
   316
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
2720
a5111ec4d25f adds a "factory reset" to iphone frontend
koda
parents: 2702
diff changeset
   317
	return 57.0;
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   318
}
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   319
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents:
diff changeset
   320
@end