project_files/HedgewarsMobile/Classes/MainMenuViewController.m
changeset 3697 d5b30d6373fc
parent 3667 9359a70df013
child 3701 8c449776ebe6
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    22 }
    22 }
    23 
    23 
    24 - (void)didReceiveMemoryWarning {
    24 - (void)didReceiveMemoryWarning {
    25     // Releases the view if it doesn't have a superview.
    25     // Releases the view if it doesn't have a superview.
    26     [super didReceiveMemoryWarning];
    26     [super didReceiveMemoryWarning];
    27     if (settingsViewController.view.superview == nil) 
    27     if (settingsViewController.view.superview == nil)
    28         settingsViewController = nil;
    28         settingsViewController = nil;
    29     if (gameConfigViewController.view.superview == nil) 
    29     if (gameConfigViewController.view.superview == nil)
    30         gameConfigViewController = nil;
    30         gameConfigViewController = nil;
    31     MSG_MEMCLEAN();
    31     MSG_MEMCLEAN();
    32 }
    32 }
    33 
    33 
    34 // using a different thread for audio 'cos it's slow
    34 // using a different thread for audio 'cos it's slow
    40 
    40 
    41 -(void) viewDidLoad {
    41 -(void) viewDidLoad {
    42     [NSThread detachNewThreadSelector:@selector(initAudioThread)
    42     [NSThread detachNewThreadSelector:@selector(initAudioThread)
    43                              toTarget:self
    43                              toTarget:self
    44                            withObject:nil];
    44                            withObject:nil];
    45     
    45 
    46     char *ver;
    46     char *ver;
    47     HW_versionInfo(NULL, &ver);
    47     HW_versionInfo(NULL, &ver);
    48     NSString *versionNumber = [[NSString alloc] initWithCString:ver];
    48     NSString *versionNumber = [[NSString alloc] initWithCString:ver];
    49     self.versionLabel.text = versionNumber;
    49     self.versionLabel.text = versionNumber;
    50     [versionNumber release];
    50     [versionNumber release];
    51 
    51 
    52     // listen to request to remove the modalviewcontroller
    52     // listen to request to remove the modalviewcontroller
    53     [[NSNotificationCenter defaultCenter] addObserver:self
    53     [[NSNotificationCenter defaultCenter] addObserver:self
    54                                              selector:@selector(dismissModalViewController)
    54                                              selector:@selector(dismissModalViewController)
    55                                                  name: @"dismissModalView" 
    55                                                  name: @"dismissModalView"
    56                                                object:nil];
    56                                                object:nil];
    57     
    57 
    58     // initialize some files the first time we load the game
    58     // initialize some files the first time we load the game
    59     if (!([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()])) 
    59     if (!([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]))
    60         [NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil];
    60         [NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil];
    61     
    61 
    62     [super viewDidLoad];
    62     [super viewDidLoad];
    63 }
    63 }
    64 
    64 
    65 // this is called to verify whether it's the first time the app is launched
    65 // this is called to verify whether it's the first time the app is launched
    66 // if it is it blocks user interaction with an alertView until files are created
    66 // if it is it blocks user interaction with an alertView until files are created
    67 -(void) checkFirstRun {
    67 -(void) checkFirstRun {
    68     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    68     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    69     DLog(@"First time run, creating settings files at %@", SETTINGS_FILE());
    69     DLog(@"First time run, creating settings files at %@", SETTINGS_FILE());
    70     
    70 
    71     // show a popup with an indicator to make the user wait
    71     // show a popup with an indicator to make the user wait
    72     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"")
    72     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"")
    73                                                     message:nil
    73                                                     message:nil
    74                                                    delegate:nil
    74                                                    delegate:nil
    75                                           cancelButtonTitle:nil
    75                                           cancelButtonTitle:nil
    76                                           otherButtonTitles:nil];
    76                                           otherButtonTitles:nil];
    77     [alert show];
    77     [alert show];
    78     
    78 
    79     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
    79     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
    80                                           initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    80                                           initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    81     indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
    81     indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
    82     [indicator startAnimating];
    82     [indicator startAnimating];
    83     [alert addSubview:indicator];
    83     [alert addSubview:indicator];
    84     [indicator release];
    84     [indicator release];
    85     
    85 
    86     // create default files (teams/weapons/scheme)
    86     // create default files (teams/weapons/scheme)
    87     createTeamNamed(@"Pirates");
    87     createTeamNamed(@"Pirates");
    88     createTeamNamed(@"Ninjas");
    88     createTeamNamed(@"Ninjas");
    89     createWeaponNamed(@"Default");
    89     createWeaponNamed(@"Default");
    90     createSchemeNamed(@"Default");
    90     createSchemeNamed(@"Default");
    91     
    91 
    92     // create settings.plist
    92     // create settings.plist
    93     NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
    93     NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
    94 
    94 
    95     [saveDict setObject:@"" forKey:@"username"];
    95     [saveDict setObject:@"" forKey:@"username"];
    96     [saveDict setObject:@"" forKey:@"password"];
    96     [saveDict setObject:@"" forKey:@"password"];
    97     [saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"music"];
    97     [saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"music"];
    98     [saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"sound"];
    98     [saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"sound"];
    99     [saveDict setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"];
    99     [saveDict setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"];
   100 
   100 
   101     [saveDict writeToFile:SETTINGS_FILE() atomically:YES];
   101     [saveDict writeToFile:SETTINGS_FILE() atomically:YES];
   102     [saveDict release];    
   102     [saveDict release];
   103     
   103 
   104     // ok let the user take control
   104     // ok let the user take control
   105     [alert dismissWithClickedButtonIndex:0 animated:YES];
   105     [alert dismissWithClickedButtonIndex:0 animated:YES];
   106     [alert release];
   106     [alert release];
   107 
   107 
   108     [pool release];
   108     [pool release];
   116     UIAlertView *alert;
   116     UIAlertView *alert;
   117     NSString *debugStr;
   117     NSString *debugStr;
   118 
   118 
   119     switch (button.tag) {
   119     switch (button.tag) {
   120         case 0:
   120         case 0:
   121             gameConfigViewController = [[GameConfigViewController alloc] initWithNibName:@"GameConfigViewController" bundle:nil];        
   121             gameConfigViewController = [[GameConfigViewController alloc] initWithNibName:@"GameConfigViewController" bundle:nil];
   122 
   122 
   123             [self presentModalViewController:gameConfigViewController animated:YES];
   123             [self presentModalViewController:gameConfigViewController animated:YES];
   124             break;
   124             break;
   125         case 2:
   125         case 2:
   126             if (nil == settingsViewController) {
   126             if (nil == settingsViewController) {
   127                 settingsViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil];
   127                 settingsViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil];
   128                 settingsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
   128                 settingsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
   129             }
   129             }
   130             
   130 
   131             [self presentModalViewController:settingsViewController animated:YES];
   131             [self presentModalViewController:settingsViewController animated:YES];
   132             break;
   132             break;
   133         case 3:
   133         case 3:
   134             debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()];
   134             debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()];
   135             UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
   135             UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
   136             scroll.text = debugStr;
   136             scroll.text = debugStr;
   137             [debugStr release];
   137             [debugStr release];
   138             scroll.editable = NO;
   138             scroll.editable = NO;
   139             
   139 
   140             UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
   140             UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
   141             [btn addTarget:scroll action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
   141             [btn addTarget:scroll action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
   142             btn.backgroundColor = [UIColor blackColor];
   142             btn.backgroundColor = [UIColor blackColor];
   143             btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70);
   143             btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70);
   144             [scroll addSubview:btn];
   144             [scroll addSubview:btn];