author | nemo |
Mon, 17 May 2010 15:50:48 +0000 | |
changeset 3474 | c6d308f5a431 |
parent 3465 | b290993c0810 |
child 3479 | 972ae3ec178a |
permissions | -rw-r--r-- |
2685 | 1 |
// |
2 |
// MainMenuViewController.m |
|
3 |
// hwengine |
|
4 |
// |
|
5 |
// Created by Vittorio on 08/01/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "MainMenuViewController.h" |
|
10 |
#import "SDL_uikitappdelegate.h" |
|
2799 | 11 |
#import "PascalImports.h" |
3356 | 12 |
#import "GameConfigViewController.h" |
3305 | 13 |
#import "SplitViewRootController.h" |
3325 | 14 |
#import "CommodityFunctions.h" |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
15 |
|
2685 | 16 |
@implementation MainMenuViewController |
3463 | 17 |
@synthesize versionLabel; |
2685 | 18 |
|
2740 | 19 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
3335 | 20 |
return rotationManager(interfaceOrientation); |
2740 | 21 |
} |
22 |
||
23 |
- (void)didReceiveMemoryWarning { |
|
24 |
// Releases the view if it doesn't have a superview. |
|
25 |
[super didReceiveMemoryWarning]; |
|
3305 | 26 |
} |
27 |
||
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
28 |
-(void) viewDidLoad { |
3245
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
29 |
char *ver; |
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
30 |
HW_versionInfo(NULL, &ver); |
3199 | 31 |
NSString *versionNumber = [[NSString alloc] initWithCString:ver]; |
3245
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
32 |
self.versionLabel.text = versionNumber; |
3199 | 33 |
[versionNumber release]; |
2723 | 34 |
|
3305 | 35 |
// listen to request to remove the modalviewcontroller |
36 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
37 |
selector:@selector(dismissModalViewController) |
|
38 |
name: @"dismissModalView" |
|
39 |
object:nil]; |
|
3321 | 40 |
|
41 |
// initialize some files the first time we load the game |
|
3335 | 42 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()])) |
3321 | 43 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
44 |
||
3305 | 45 |
[super viewDidLoad]; |
2685 | 46 |
} |
47 |
||
3305 | 48 |
// this is called to verify whether it's the first time the app is launched |
49 |
// 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
|
50 |
-(void) checkFirstRun { |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
51 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3335 | 52 |
NSLog(@"First time run, creating settings files at %@", SETTINGS_FILE()); |
3321 | 53 |
|
54 |
// show a popup with an indicator to make the user wait |
|
55 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"") |
|
56 |
message:nil |
|
57 |
delegate:nil |
|
58 |
cancelButtonTitle:nil |
|
59 |
otherButtonTitles:nil]; |
|
60 |
[alert show]; |
|
61 |
||
62 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
|
63 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
64 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50); |
|
65 |
[indicator startAnimating]; |
|
66 |
[alert addSubview:indicator]; |
|
67 |
[indicator release]; |
|
68 |
||
3325 | 69 |
// create a team |
70 |
createTeamNamed(@"Default Team"); |
|
3321 | 71 |
|
72 |
// create settings.plist |
|
73 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
|
3332 | 74 |
|
3321 | 75 |
[saveDict setObject:@"" forKey:@"username"]; |
76 |
[saveDict setObject:@"" forKey:@"password"]; |
|
3332 | 77 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"music"]; |
78 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"sound"]; |
|
79 |
[saveDict setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"]; |
|
3305 | 80 |
|
3335 | 81 |
[saveDict writeToFile:SETTINGS_FILE() atomically:YES]; |
3325 | 82 |
[saveDict release]; |
3321 | 83 |
|
84 |
// ok let the user take control |
|
85 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
|
3364 | 86 |
[alert release]; |
3321 | 87 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
88 |
[pool release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
89 |
[NSThread exit]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
90 |
} |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
91 |
|
3305 | 92 |
#pragma mark - |
93 |
-(IBAction) switchViews:(id) sender { |
|
94 |
UIButton *button = (UIButton *)sender; |
|
95 |
UIAlertView *alert; |
|
3463 | 96 |
NSString *debugStr, *configNibName; |
97 |
||
3305 | 98 |
switch (button.tag) { |
99 |
case 0: |
|
3463 | 100 |
// bug in UIModalTransitionStylePartialCurl, displays the controller awkwardly if it is not allocated every time |
101 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
|
102 |
configNibName = @"GameConfigViewController-iPad"; |
|
103 |
else |
|
104 |
configNibName = @"GameConfigViewController-iPhone"; |
|
105 |
||
106 |
gameConfigViewController = [[GameConfigViewController alloc] initWithNibName:configNibName bundle:nil]; |
|
3356 | 107 |
#ifdef __IPHONE_3_2 |
3463 | 108 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
109 |
gameConfigViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; |
|
3356 | 110 |
#endif |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3364
diff
changeset
|
111 |
[self presentModalViewController:gameConfigViewController animated:YES]; |
3305 | 112 |
break; |
113 |
case 2: |
|
3465 | 114 |
if (nil == settingsViewController) { |
115 |
settingsViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil]; |
|
116 |
settingsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
3356 | 117 |
} |
118 |
||
3465 | 119 |
[self presentModalViewController:settingsViewController animated:YES]; |
3305 | 120 |
break; |
3377 | 121 |
case 3: |
122 |
debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()]; |
|
123 |
UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)]; |
|
124 |
scroll.text = debugStr; |
|
125 |
[debugStr release]; |
|
126 |
scroll.editable = NO; |
|
127 |
||
128 |
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; |
|
129 |
[btn addTarget:scroll action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside]; |
|
130 |
btn.backgroundColor = [UIColor blackColor]; |
|
131 |
btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70); |
|
132 |
[scroll addSubview:btn]; |
|
133 |
[self.view addSubview:scroll]; |
|
134 |
[scroll release]; |
|
135 |
break; |
|
3305 | 136 |
default: |
137 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
138 |
message:@"Sorry, this feature is not yet implemented" |
|
139 |
delegate:nil |
|
140 |
cancelButtonTitle:@"Well, don't worry" |
|
141 |
otherButtonTitles:nil]; |
|
142 |
[alert show]; |
|
143 |
[alert release]; |
|
144 |
break; |
|
145 |
} |
|
146 |
} |
|
2740 | 147 |
|
3356 | 148 |
// allows child controllers to return to the main controller |
3305 | 149 |
-(void) dismissModalViewController { |
150 |
[self dismissModalViewControllerAnimated:YES]; |
|
2740 | 151 |
} |
152 |
||
3356 | 153 |
|
154 |
-(void) viewDidUnload { |
|
155 |
self.versionLabel = nil; |
|
156 |
gameConfigViewController = nil; |
|
3465 | 157 |
settingsViewController = nil; |
3356 | 158 |
[super viewDidUnload]; |
159 |
} |
|
160 |
||
161 |
-(void) dealloc { |
|
162 |
[versionLabel release]; |
|
3465 | 163 |
[settingsViewController release]; |
3356 | 164 |
[gameConfigViewController release]; |
165 |
[super dealloc]; |
|
166 |
} |
|
167 |
||
2685 | 168 |
@end |