project_files/HedgewarsMobile/Classes/MainMenuViewController.m
changeset 5486 e75f7c3c6275
parent 5483 fc755bb8096d
child 5984 6fd40d866342
equal deleted inserted replaced
5485:e943a005d0e8 5486:e75f7c3c6275
   100 
   100 
   101     // get the version number that we've been tracking
   101     // get the version number that we've been tracking
   102     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
   102     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
   103     NSString *trackingVersion = [userDefaults stringForKey:@"HedgeVersion"];
   103     NSString *trackingVersion = [userDefaults stringForKey:@"HedgeVersion"];
   104 
   104 
       
   105     if ([[userDefaults objectForKey:@"music"] boolValue])
       
   106         [HedgewarsAppDelegate playBackgroundMusic];
       
   107 
   105     if (trackingVersion == nil || [trackingVersion isEqualToString:version] == NO) {
   108     if (trackingVersion == nil || [trackingVersion isEqualToString:version] == NO) {
       
   109         // remove any reminder of previous games as saves are going to be wiped out
       
   110         [userDefaults setObject:@"" forKey:@"savedGamePath"];
       
   111         // update the tracking version with the new one
   106         [userDefaults setObject:version forKey:@"HedgeVersion"];
   112         [userDefaults setObject:version forKey:@"HedgeVersion"];
       
   113 
   107         [userDefaults synchronize];
   114         [userDefaults synchronize];
   108         [self createNecessaryFiles];
   115         [self createNecessaryFiles];
   109     }
   116     }
   110 
   117 
   111     if ([[userDefaults objectForKey:@"music"] boolValue])
   118     // prompt for restoring any previous game
   112         [HedgewarsAppDelegate playBackgroundMusic];
   119     NSString *saveString = [userDefaults objectForKey:@"savedGamePath"];
   113 
       
   114     NSString *saveString = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedGamePath"];
       
   115     if (saveString != nil && [saveString isEqualToString:@""] == NO) {
   120     if (saveString != nil && [saveString isEqualToString:@""] == NO) {
   116         if (self.restoreViewController == nil) {
   121         if (self.restoreViewController == nil) {
   117             NSString *xibName = [@"RestoreViewController-" stringByAppendingString:(IS_IPAD() ? @"iPad" : @"iPhone")]; 
   122             NSString *xibName = [@"RestoreViewController-" stringByAppendingString:(IS_IPAD() ? @"iPad" : @"iPhone")];
   118             RestoreViewController *restored = [[RestoreViewController alloc] initWithNibName:xibName bundle:nil];
   123             RestoreViewController *restored = [[RestoreViewController alloc] initWithNibName:xibName bundle:nil];
   119             if ([restored respondsToSelector:@selector(setModalPresentationStyle:)])
   124             if ([restored respondsToSelector:@selector(setModalPresentationStyle:)])
   120                 restored.modalPresentationStyle = UIModalPresentationFormSheet;
   125                 restored.modalPresentationStyle = UIModalPresentationFormSheet;
   121             self.restoreViewController = restored;
   126             self.restoreViewController = restored;
   122             [restored release];
   127             [restored release];
   123         }
   128         }
   124         [self performSelector:@selector(presentModalViewController:animated:) withObject:self.restoreViewController afterDelay:0.35];
   129         [self performSelector:@selector(presentModalViewController:animated:) withObject:self.restoreViewController afterDelay:0.3];
   125     } else {
   130     } else {
   126         // let's not prompt for rating when app crashed >_>
   131         // let's not prompt for rating when app crashed >_>
   127         [Appirater appLaunched];
   132         [Appirater appLaunched];
   128     }
   133     }
   129 
   134 
   150 
   155 
   151     playSound(@"clickSound");
   156     playSound(@"clickSound");
   152     switch (button.tag) {
   157     switch (button.tag) {
   153         case 0:
   158         case 0:
   154             if (nil == self.gameConfigViewController) {
   159             if (nil == self.gameConfigViewController) {
   155                 if (IS_IPAD())
   160                 xib = IS_IPAD() ? nil : @"GameConfigViewController";
   156                     xib = nil;
   161 
   157                 else
       
   158                     xib = @"GameConfigViewController";
       
   159                 
       
   160                 GameConfigViewController *gcvc = [[GameConfigViewController alloc] initWithNibName:xib bundle:nil];
   162                 GameConfigViewController *gcvc = [[GameConfigViewController alloc] initWithNibName:xib bundle:nil];
   161                 gcvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
   163                 gcvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
   162                 self.gameConfigViewController = gcvc;
   164                 self.gameConfigViewController = gcvc;
   163                 [gcvc release];
   165                 [gcvc release];
   164             }
   166             }
   175 
   177 
   176             [self presentModalViewController:self.settingsViewController animated:YES];
   178             [self presentModalViewController:self.settingsViewController animated:YES];
   177             break;
   179             break;
   178         case 3:
   180         case 3:
   179 #ifdef DEBUG
   181 #ifdef DEBUG
   180             debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()];
   182             if ([[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()])
       
   183                 debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()];
       
   184             else
       
   185                 debugStr = [[NSString alloc] initWithString:@"Here be log"];
   181             UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
   186             UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
   182             scroll.text = debugStr;
   187             scroll.text = debugStr;
   183             [debugStr release];
   188             [debugStr release];
   184             scroll.editable = NO;
   189             scroll.editable = NO;
   185 
   190 
   189             btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70);
   194             btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70);
   190             [scroll addSubview:btn];
   195             [scroll addSubview:btn];
   191             [self.view addSubview:scroll];
   196             [self.view addSubview:scroll];
   192             [scroll release];
   197             [scroll release];
   193 #else
   198 #else
       
   199             debugStr = debugStr; // prevent compiler warning
   194             if (nil == self.aboutViewController) {
   200             if (nil == self.aboutViewController) {
   195                 AboutViewController *about = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];
   201                 AboutViewController *about = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];
   196                 about.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
   202                 about.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
   197                 if ([about respondsToSelector:@selector(setModalPresentationStyle:)])
   203                 if ([about respondsToSelector:@selector(setModalPresentationStyle:)])
   198                      about.modalPresentationStyle = UIModalPresentationFormSheet;
   204                      about.modalPresentationStyle = UIModalPresentationFormSheet;