# HG changeset patch # User koda # Date 1264622332 0 # Node ID a5111ec4d25f28ec558bffb6134c9c391a7aeaac # Parent 0efcaa69d30c006e0210f0983d13646906724b1b adds a "factory reset" to iphone frontend diff -r 0efcaa69d30c -r a5111ec4d25f cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m --- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m Wed Jan 27 00:11:52 2010 +0000 +++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m Wed Jan 27 19:58:52 2010 +0000 @@ -137,13 +137,14 @@ -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Running low on memory" - message:@"Will try to free some memory but app may crash" + message:@"I will try to free some memory but game might slow down a little" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil ]; [alert show]; [alert release]; } + #pragma mark - #pragma mark SDLUIKitDelegate methods // override the direct execution of SDL_main to allow us to implement the frontend (even using a nib) @@ -151,6 +152,7 @@ [application setStatusBarHidden:YES animated:NO]; [self checkFirstRun]; + /* Set working directory to resource path */ [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; diff -r 0efcaa69d30c -r a5111ec4d25f cocoaTouch/SettingsViewController.h --- a/cocoaTouch/SettingsViewController.h Wed Jan 27 00:11:52 2010 +0000 +++ b/cocoaTouch/SettingsViewController.h Wed Jan 27 19:58:52 2010 +0000 @@ -9,7 +9,8 @@ #import -@interface SettingsViewController : UIViewController { +@interface SettingsViewController : UIViewController + { UITextField *username; UITextField *password; UISwitch *musicSwitch; @@ -19,7 +20,10 @@ UILabel *volumeLabel; UITableView *table; UITableViewCell *volumeCell; + UIView *buttonContainer; + BOOL needsReset; } + @property (nonatomic, retain) IBOutlet UITextField *username; @property (nonatomic, retain) IBOutlet UITextField *password; @property (nonatomic, retain) UISwitch *musicSwitch; @@ -29,8 +33,10 @@ @property (nonatomic, retain) IBOutlet UILabel *volumeLabel; @property (nonatomic, retain) IBOutlet UITableView *table; @property (nonatomic, retain) IBOutlet UITableViewCell *volumeCell; +@property (nonatomic, retain) IBOutlet UIView *buttonContainer; -(IBAction) sliderChanged: (id)sender; -(IBAction) backgroundTap: (id)sender; -(IBAction) textFieldDoneEditing: (id)sender; +-(IBAction) deleteData: (id)sender; @end diff -r 0efcaa69d30c -r a5111ec4d25f cocoaTouch/SettingsViewController.m --- a/cocoaTouch/SettingsViewController.m Wed Jan 27 00:11:52 2010 +0000 +++ b/cocoaTouch/SettingsViewController.m Wed Jan 27 19:58:52 2010 +0000 @@ -11,7 +11,8 @@ @implementation SettingsViewController -@synthesize username, password, musicSwitch, soundsSwitch, altDamageSwitch, volumeSlider, volumeLabel, table, volumeCell; +@synthesize username, password, musicSwitch, soundsSwitch, altDamageSwitch, + volumeSlider, volumeLabel, table, volumeCell, buttonContainer; -(void) loadView { @@ -27,6 +28,7 @@ -(void) viewDidLoad { NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; + needsReset = NO; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath]; username.text = [data objectForKey:@"username"]; @@ -62,6 +64,9 @@ volumeLabel.textColor = [UIColor grayColor]; table.backgroundColor = [UIColor clearColor]; table.allowsSelection = NO; + buttonContainer.backgroundColor = [UIColor clearColor]; + table.tableFooterView = buttonContainer; + [super viewDidLoad]; } @@ -75,25 +80,28 @@ self.volumeSlider = nil; self.table = nil; self.volumeCell = nil; + self.buttonContainer = nil; [super viewDidUnload]; } //- (void)applicationWillTerminate:(NSNotification *)notification { -(void) viewWillDisappear:(BOOL)animated { - NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; - NSString *tmpMus = (musicSwitch.on) ? @"1" : @"0"; - NSString *tmpEff = (soundsSwitch.on) ? @"1" : @"0"; - NSString *tmpAlt = (altDamageSwitch.on) ? @"1" : @"0"; - - [saveDict setObject:username.text forKey:@"username"]; - [saveDict setObject:password.text forKey:@"password"]; - [saveDict setObject:tmpMus forKey:@"music"]; - [saveDict setObject:tmpEff forKey:@"sounds"]; - [saveDict setObject:tmpAlt forKey:@"alternate"]; - [saveDict setObject:volumeLabel.text forKey:@"volume"]; - - [saveDict writeToFile:[[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"] atomically:YES]; - [saveDict release]; + if (!needsReset) { + NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; + NSString *tmpMus = (musicSwitch.on) ? @"1" : @"0"; + NSString *tmpEff = (soundsSwitch.on) ? @"1" : @"0"; + NSString *tmpAlt = (altDamageSwitch.on) ? @"1" : @"0"; + + [saveDict setObject:username.text forKey:@"username"]; + [saveDict setObject:password.text forKey:@"password"]; + [saveDict setObject:tmpMus forKey:@"music"]; + [saveDict setObject:tmpEff forKey:@"sounds"]; + [saveDict setObject:tmpAlt forKey:@"alternate"]; + [saveDict setObject:volumeLabel.text forKey:@"volume"]; + + [saveDict writeToFile:[[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"] atomically:YES]; + [saveDict release]; + } [super viewWillDisappear:animated]; } @@ -107,6 +115,7 @@ [volumeSlider release]; [table release]; [volumeCell release]; + [buttonContainer release]; [super dealloc]; } /* @@ -152,6 +161,47 @@ } #pragma mark - +#pragma mark UIActionSheet Methods +-(IBAction) deleteData: (id)sender { + UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you reeeeeally sure?" + delegate:self + cancelButtonTitle:@"Well, maybe not..." + destructiveButtonTitle:@"Sure, let's start over" + otherButtonTitles:nil]; + [actionSheet showInView:self.view]; + [actionSheet release]; +} + +-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { + if ([actionSheet cancelButtonIndex] != buttonIndex) { + needsReset = YES; + + // get the document dirctory + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *documentsDirectory = [paths objectAtIndex:0]; + + // get the content of the directory + NSFileManager *fm = [NSFileManager defaultManager]; + NSArray *dirContent = [fm directoryContentsAtPath:documentsDirectory]; + NSError *error; + + // delete data + for (NSString *fileName in dirContent) { + [fm removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:fileName] error:&error]; + } + + // force resetting + UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:@"Hit Home Button to Exit" + message:@"\nEverything is gone!\nNow you need to restart the game..." + delegate:self + cancelButtonTitle:nil + otherButtonTitles:nil]; + [anAlert show]; + [anAlert release]; + } +} + +#pragma mark - #pragma mark TableView Methods #define kNetworkFields 0 #define kAudioFields 1 @@ -247,7 +297,7 @@ switch (section) { case kNetworkFields: - headerLabel.text = NSLocalizedString(@"Network Configuration", @""); + headerLabel.text = NSLocalizedString(@"Network Configuration", @"Network Configuration"); break; case kAudioFields: headerLabel.text = NSLocalizedString(@"Audio Preferences", @""); @@ -273,8 +323,7 @@ } -(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { - return 57; + return 57.0; } - @end diff -r 0efcaa69d30c -r a5111ec4d25f cocoaTouch/SettingsViewController.xib --- a/cocoaTouch/SettingsViewController.xib Wed Jan 27 00:11:52 2010 +0000 +++ b/cocoaTouch/SettingsViewController.xib Wed Jan 27 19:58:52 2010 +0000 @@ -12,8 +12,6 @@ YES - - YES @@ -36,8 +34,61 @@ IBFirstResponder + + + 292 + {{100, 18}, {200, 31}} + NO + NO + 0 + + username + + 1 + MC40MDAwMDAwMDYgMC40MDAwMDAwMDYgMQA + + + Helvetica + 15 + 16 + + 2 + YES + 17 + + 1 + 9 + + + + + 292 + {{100, 50}, {200, 31}} + NO + NO + 0 + + network password (if any) + + 3 + MAA + + 2 + + + + 2 + YES + YES + 17 + + 1 + 9 + YES + + - + 292 YES @@ -54,65 +105,10 @@ Background.png - - - 292 - {{100, 18}, {200, 31}} - - NO - NO - 0 - - username - - 1 - MC40MDAwMDAwMDYgMC40MDAwMDAwMDYgMQA - - - Helvetica - 15 - 16 - - 2 - YES - 17 - - 1 - 9 - - - - - 292 - {{100, 50}, {200, 31}} - - NO - NO - 0 - - network password (if any) - - 3 - MAA - - 2 - - - - 2 - YES - YES - 17 - - 1 - 9 - YES - - 274 - {{0, 98}, {320, 333}} + {{0, 18}, {320, 393}} NO YES @@ -129,15 +125,14 @@ {320, 431} - - + 3 MQA - + 292 YES @@ -214,7 +209,6 @@ {320, 70} - 1 MSAxIDEAA @@ -223,6 +217,52 @@ 1 + + + 292 + + YES + + + 292 + {{20, 38}, {280, 50}} + + + NO + NO + 0 + 0 + + Helvetica-Bold + 15 + 16 + + 1 + Erase All Data + + + 1 + MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA + + + 3 + MC41AA + + + + {320, 100} + + + + 3 + MQA + + + NO + YES + NO + 3 + @@ -344,6 +384,23 @@ 39 + + + deleteData: + + + 7 + + 42 + + + + buttonContainer + + + + 46 + @@ -361,8 +418,6 @@ YES - - @@ -383,31 +438,13 @@ - 6 - - - - - 30 - - - YES - - - - - 5 - - - - 37 YES + - @@ -426,6 +463,35 @@ + + 5 + + + + + 30 + + + + + 6 + + + + + 44 + + + YES + + + + + + 41 + + + @@ -443,6 +509,10 @@ 37.IBPluginDependency 38.IBPluginDependency 4.IBPluginDependency + 41.IBEditorWindowLastContentRect + 41.IBPluginDependency + 44.IBEditorWindowLastContentRect + 44.IBPluginDependency 5.IBPluginDependency 6.IBPluginDependency 7.IBPluginDependency @@ -460,6 +530,10 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + {{1352, 334}, {220, 50}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + {{734, 817}, {320, 100}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -481,7 +555,7 @@ - 40 + 46 @@ -494,6 +568,7 @@ YES backgroundTap: + deleteData: sliderChanged: textFieldDoneEditing: @@ -502,12 +577,14 @@ id id id + id YES YES + buttonContainer password table username @@ -517,6 +594,7 @@ YES + UIView UITextField UITableView UITextField @@ -667,6 +745,14 @@ + UIButton + UIControl + + IBFrameworkSource + UIKit.framework/Headers/UIButton.h + + + UIControl UIView