project_files/HedgewarsMobile/Classes/MainMenuViewController.m
author koda
Wed, 23 Jun 2010 01:00:52 +0200
changeset 3535 9e78c1f3d8d8
parent 3525 1d7b056ff866
child 3546 ccf4854df294
permissions -rw-r--r--
update the project to ios4 by removing pre-3.2 references add missing lowres image other smaller fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2685
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
     1
//
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
     2
//  MainMenuViewController.m
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
     3
//  hwengine
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
     4
//
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
     5
//  Created by Vittorio on 08/01/10.
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
     7
//
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
     8
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
     9
#import "MainMenuViewController.h"
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
    10
#import "SDL_uikitappdelegate.h"
2799
558b29bf00c5 add a new way to fetch version info from pascal to c
koda
parents: 2743
diff changeset
    11
#import "PascalImports.h"
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
    12
#import "GameConfigViewController.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    13
#import "SplitViewRootController.h"
3325
652a8ebdf667 moved around team creation
koda
parents: 3321
diff changeset
    14
#import "CommodityFunctions.h"
2803
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
    15
2685
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
    16
@implementation MainMenuViewController
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3377
diff changeset
    17
@synthesize versionLabel;
2685
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
    18
2740
03df0573a9fd programmatically load main controller
koda
parents: 2738
diff changeset
    19
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3332
diff changeset
    20
	return rotationManager(interfaceOrientation);
2740
03df0573a9fd programmatically load main controller
koda
parents: 2738
diff changeset
    21
}
03df0573a9fd programmatically load main controller
koda
parents: 2738
diff changeset
    22
03df0573a9fd programmatically load main controller
koda
parents: 2738
diff changeset
    23
- (void)didReceiveMemoryWarning {
03df0573a9fd programmatically load main controller
koda
parents: 2738
diff changeset
    24
	// Releases the view if it doesn't have a superview.
03df0573a9fd programmatically load main controller
koda
parents: 2738
diff changeset
    25
	[super didReceiveMemoryWarning];
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
    26
    if (settingsViewController.view.superview == nil) 
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
    27
        settingsViewController = nil;
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
    28
    if (gameConfigViewController.view.superview == nil) 
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
    29
        gameConfigViewController = nil;
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
    30
    MSG_MEMCLEAN();
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    31
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    32
2687
28b8330b8af1 add stub files for other views and prevent useless crashes
koda
parents: 2685
diff changeset
    33
-(void) viewDidLoad {
3245
252be02536ab fix an error in passing strings between ObjC and Pascal
koda
parents: 3199
diff changeset
    34
    char *ver;
252be02536ab fix an error in passing strings between ObjC and Pascal
koda
parents: 3199
diff changeset
    35
    HW_versionInfo(NULL, &ver);
3199
1a9938a27677 fixes to the mac build system
koda
parents: 3063
diff changeset
    36
    NSString *versionNumber = [[NSString alloc] initWithCString:ver];
3245
252be02536ab fix an error in passing strings between ObjC and Pascal
koda
parents: 3199
diff changeset
    37
    self.versionLabel.text = versionNumber;
3199
1a9938a27677 fixes to the mac build system
koda
parents: 3063
diff changeset
    38
    [versionNumber release];
2723
eaa6ac1e95ea LANDSCAPE ON IPHONE
koda
parents: 2694
diff changeset
    39
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    40
    // listen to request to remove the modalviewcontroller
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    41
    [[NSNotificationCenter defaultCenter] addObserver:self
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    42
                                             selector:@selector(dismissModalViewController)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    43
                                                 name: @"dismissModalView" 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    44
                                               object:nil];
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    45
    
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    46
    // initialize some files the first time we load the game
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3332
diff changeset
    47
	if (!([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()])) 
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    48
        [NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    49
    
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    50
	[super viewDidLoad];
2685
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
    51
}
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
    52
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    53
// this is called to verify whether it's the first time the app is launched
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    54
// if it is it blocks user interaction with an alertView until files are created
2803
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
    55
-(void) checkFirstRun {
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
    56
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3332
diff changeset
    57
    NSLog(@"First time run, creating settings files at %@", SETTINGS_FILE());
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    58
    
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    59
    // show a popup with an indicator to make the user wait
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    60
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"")
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    61
                                                    message:nil
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    62
                                                   delegate:nil
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    63
                                          cancelButtonTitle:nil
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    64
                                          otherButtonTitles:nil];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    65
    [alert show];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    66
    
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    67
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    68
                                          initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    69
    indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    70
    [indicator startAnimating];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    71
    [alert addSubview:indicator];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    72
    [indicator release];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    73
    
3522
156c04c6a3d8 add initial stubs for selecting weapons in the ifrontend
koda
parents: 3514
diff changeset
    74
    // create default files (teams/weapons/scheme)
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
    75
    createTeamNamed(@"Pirates");
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
    76
    createTeamNamed(@"Ninjas");
3522
156c04c6a3d8 add initial stubs for selecting weapons in the ifrontend
koda
parents: 3514
diff changeset
    77
    createWeaponNamed(@"Default");
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    78
    createSchemeNamed(@"Default");
3479
972ae3ec178a initial support for game modifiers (schemes)
koda
parents: 3465
diff changeset
    79
    
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    80
    // create settings.plist
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    81
    NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init];
3332
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3325
diff changeset
    82
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    83
    [saveDict setObject:@"" forKey:@"username"];
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    84
    [saveDict setObject:@"" forKey:@"password"];
3332
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3325
diff changeset
    85
    [saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"music"];
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3325
diff changeset
    86
    [saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"sound"];
3c90a923f156 simplify the general settings and review minor stuff
koda
parents: 3325
diff changeset
    87
    [saveDict setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
    88
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3332
diff changeset
    89
    [saveDict writeToFile:SETTINGS_FILE() atomically:YES];
3325
652a8ebdf667 moved around team creation
koda
parents: 3321
diff changeset
    90
    [saveDict release];    
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    91
    
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    92
    // ok let the user take control
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    93
    [alert dismissWithClickedButtonIndex:0 animated:YES];
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3356
diff changeset
    94
    [alert release];
3321
988e39ef3c20 rewrote a couple of things i didn't like
koda
parents: 3317
diff changeset
    95
2803
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
    96
	[pool release];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
    97
	[NSThread exit];
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
    98
}
1f446fc5c8ec allow to compile engine as library with HWLIBRARY symbol
koda
parents: 2799
diff changeset
    99
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   100
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   101
-(IBAction) switchViews:(id) sender {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   102
    UIButton *button = (UIButton *)sender;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   103
    UIAlertView *alert;
3525
1d7b056ff866 some memory caring code
koda
parents: 3522
diff changeset
   104
    NSString *debugStr;
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3377
diff changeset
   105
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   106
    switch (button.tag) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   107
        case 0:
3525
1d7b056ff866 some memory caring code
koda
parents: 3522
diff changeset
   108
            gameConfigViewController = [[GameConfigViewController alloc] initWithNibName:@"GameConfigViewController" bundle:nil];        
3535
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3525
diff changeset
   109
3525
1d7b056ff866 some memory caring code
koda
parents: 3522
diff changeset
   110
            // bug in UIModalTransitionStylePartialCurl, displays the controller awkwardly if it is not allocated every time            
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3377
diff changeset
   111
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
23c50be687a9 update sdl functions to latest revision
koda
parents: 3377
diff changeset
   112
                gameConfigViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3364
diff changeset
   113
            [self presentModalViewController:gameConfigViewController animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   114
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   115
        case 2:
3465
b290993c0810 unbreak stuff
koda
parents: 3464
diff changeset
   116
            if (nil == settingsViewController) {
b290993c0810 unbreak stuff
koda
parents: 3464
diff changeset
   117
                settingsViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil];
b290993c0810 unbreak stuff
koda
parents: 3464
diff changeset
   118
                settingsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   119
            }
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   120
            
3465
b290993c0810 unbreak stuff
koda
parents: 3464
diff changeset
   121
            [self presentModalViewController:settingsViewController animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   122
            break;
3377
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   123
        case 3:
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   124
            debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()];
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   125
            UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)];
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   126
            scroll.text = debugStr;
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   127
            [debugStr release];
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   128
            scroll.editable = NO;
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   129
            
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   130
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   131
            [btn addTarget:scroll action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   132
            btn.backgroundColor = [UIColor blackColor];
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   133
            btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70);
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   134
            [scroll addSubview:btn];
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   135
            [self.view addSubview:scroll];
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   136
            [scroll release];
a3f0849f26bc add option to look at the previous debug log
koda
parents: 3374
diff changeset
   137
            break;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   138
        default:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   139
            alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   140
                                               message:@"Sorry, this feature is not yet implemented"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   141
                                              delegate:nil
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   142
                                     cancelButtonTitle:@"Well, don't worry"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   143
                                     otherButtonTitles:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   144
            [alert show];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   145
            [alert release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   146
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   147
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   148
}
2740
03df0573a9fd programmatically load main controller
koda
parents: 2738
diff changeset
   149
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   150
// allows child controllers to return to the main controller
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   151
-(void) dismissModalViewController {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3245
diff changeset
   152
    [self dismissModalViewControllerAnimated:YES];
2740
03df0573a9fd programmatically load main controller
koda
parents: 2738
diff changeset
   153
}
03df0573a9fd programmatically load main controller
koda
parents: 2738
diff changeset
   154
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   155
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   156
-(void) viewDidUnload {
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   157
    self.versionLabel = nil;
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   158
    gameConfigViewController = nil;
3465
b290993c0810 unbreak stuff
koda
parents: 3464
diff changeset
   159
    settingsViewController = nil;
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   160
	[super viewDidUnload];
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   161
    MSG_DIDUNLOAD();
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   162
}
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   163
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   164
-(void) dealloc {
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   165
    [versionLabel release];
3465
b290993c0810 unbreak stuff
koda
parents: 3464
diff changeset
   166
    [settingsViewController release];
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   167
    [gameConfigViewController release];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   168
	[super dealloc];
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   169
}
3ae3fccb439e add missing controller stubs
koda
parents: 3335
diff changeset
   170
2685
0ba746be5d59 frontend images by Tiy, first setup of frontend
koda
parents:
diff changeset
   171
@end