author | nemo |
Sun, 20 Jun 2010 22:35:10 -0400 | |
changeset 3526 | a1d2180fef42 |
parent 3514 | 59dbd31e9953 |
child 3522 | 156c04c6a3d8 |
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]; |
|
3490 | 26 |
if (settingsViewController.view.superview == nil) |
27 |
settingsViewController = nil; |
|
28 |
if (gameConfigViewController.view.superview == nil) |
|
29 |
gameConfigViewController = nil; |
|
30 |
MSG_MEMCLEAN(); |
|
3305 | 31 |
} |
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 | 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 | 38 |
[versionNumber release]; |
2723 | 39 |
|
3305 | 40 |
// listen to request to remove the modalviewcontroller |
41 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
42 |
selector:@selector(dismissModalViewController) |
|
43 |
name: @"dismissModalView" |
|
44 |
object:nil]; |
|
3321 | 45 |
|
46 |
// initialize some files the first time we load the game |
|
3335 | 47 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()])) |
3321 | 48 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
49 |
||
3305 | 50 |
[super viewDidLoad]; |
2685 | 51 |
} |
52 |
||
3305 | 53 |
// this is called to verify whether it's the first time the app is launched |
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 | 57 |
NSLog(@"First time run, creating settings files at %@", SETTINGS_FILE()); |
3321 | 58 |
|
59 |
// show a popup with an indicator to make the user wait |
|
60 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"") |
|
61 |
message:nil |
|
62 |
delegate:nil |
|
63 |
cancelButtonTitle:nil |
|
64 |
otherButtonTitles:nil]; |
|
65 |
[alert show]; |
|
66 |
||
67 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
|
68 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
69 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50); |
|
70 |
[indicator startAnimating]; |
|
71 |
[alert addSubview:indicator]; |
|
72 |
[indicator release]; |
|
73 |
||
3325 | 74 |
// create a team |
3490 | 75 |
createTeamNamed(@"Pirates"); |
76 |
createTeamNamed(@"Ninjas"); |
|
3321 | 77 |
|
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 | 79 |
|
3321 | 80 |
// create settings.plist |
81 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
|
3332 | 82 |
|
3321 | 83 |
[saveDict setObject:@"" forKey:@"username"]; |
84 |
[saveDict setObject:@"" forKey:@"password"]; |
|
3332 | 85 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"music"]; |
86 |
[saveDict setObject:[NSNumber numberWithBool:YES] forKey:@"sound"]; |
|
87 |
[saveDict setObject:[NSNumber numberWithBool:NO] forKey:@"alternate"]; |
|
3305 | 88 |
|
3335 | 89 |
[saveDict writeToFile:SETTINGS_FILE() atomically:YES]; |
3325 | 90 |
[saveDict release]; |
3321 | 91 |
|
92 |
// ok let the user take control |
|
93 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
|
3364 | 94 |
[alert release]; |
3321 | 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 | 100 |
#pragma mark - |
101 |
-(IBAction) switchViews:(id) sender { |
|
102 |
UIButton *button = (UIButton *)sender; |
|
103 |
UIAlertView *alert; |
|
3463 | 104 |
NSString *debugStr, *configNibName; |
105 |
||
3305 | 106 |
switch (button.tag) { |
107 |
case 0: |
|
3463 | 108 |
// bug in UIModalTransitionStylePartialCurl, displays the controller awkwardly if it is not allocated every time |
109 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
|
110 |
configNibName = @"GameConfigViewController-iPad"; |
|
111 |
else |
|
112 |
configNibName = @"GameConfigViewController-iPhone"; |
|
113 |
||
114 |
gameConfigViewController = [[GameConfigViewController alloc] initWithNibName:configNibName bundle:nil]; |
|
3356 | 115 |
#ifdef __IPHONE_3_2 |
3463 | 116 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
117 |
gameConfigViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl; |
|
3356 | 118 |
#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
|
119 |
[self presentModalViewController:gameConfigViewController animated:YES]; |
3305 | 120 |
break; |
121 |
case 2: |
|
3465 | 122 |
if (nil == settingsViewController) { |
123 |
settingsViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil]; |
|
124 |
settingsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
3356 | 125 |
} |
126 |
||
3465 | 127 |
[self presentModalViewController:settingsViewController animated:YES]; |
3305 | 128 |
break; |
3377 | 129 |
case 3: |
130 |
debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()]; |
|
131 |
UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)]; |
|
132 |
scroll.text = debugStr; |
|
133 |
[debugStr release]; |
|
134 |
scroll.editable = NO; |
|
135 |
||
136 |
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; |
|
137 |
[btn addTarget:scroll action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside]; |
|
138 |
btn.backgroundColor = [UIColor blackColor]; |
|
139 |
btn.frame = CGRectMake(self.view.frame.size.height-70, 0, 70, 70); |
|
140 |
[scroll addSubview:btn]; |
|
141 |
[self.view addSubview:scroll]; |
|
142 |
[scroll release]; |
|
143 |
break; |
|
3305 | 144 |
default: |
145 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
146 |
message:@"Sorry, this feature is not yet implemented" |
|
147 |
delegate:nil |
|
148 |
cancelButtonTitle:@"Well, don't worry" |
|
149 |
otherButtonTitles:nil]; |
|
150 |
[alert show]; |
|
151 |
[alert release]; |
|
152 |
break; |
|
153 |
} |
|
154 |
} |
|
2740 | 155 |
|
3356 | 156 |
// allows child controllers to return to the main controller |
3305 | 157 |
-(void) dismissModalViewController { |
158 |
[self dismissModalViewControllerAnimated:YES]; |
|
2740 | 159 |
} |
160 |
||
3356 | 161 |
|
162 |
-(void) viewDidUnload { |
|
163 |
self.versionLabel = nil; |
|
164 |
gameConfigViewController = nil; |
|
3465 | 165 |
settingsViewController = nil; |
3356 | 166 |
[super viewDidUnload]; |
3490 | 167 |
MSG_DIDUNLOAD(); |
3356 | 168 |
} |
169 |
||
170 |
-(void) dealloc { |
|
171 |
[versionLabel release]; |
|
3465 | 172 |
[settingsViewController release]; |
3356 | 173 |
[gameConfigViewController release]; |
174 |
[super dealloc]; |
|
175 |
} |
|
176 |
||
2685 | 177 |
@end |