author | koda |
Wed, 07 Apr 2010 01:22:05 +0000 | |
changeset 3316 | 52f0482b043f |
parent 3315 | 4e2813713358 |
child 3317 | 198ec44b6d92 |
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" |
3305 | 12 |
#import "SplitViewRootController.h" |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
13 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
14 |
|
2685 | 15 |
@implementation MainMenuViewController |
3305 | 16 |
@synthesize cover, versionLabel; |
2685 | 17 |
|
2740 | 18 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
19 |
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
|
20 |
} |
|
21 |
||
22 |
- (void)didReceiveMemoryWarning { |
|
23 |
// Releases the view if it doesn't have a superview. |
|
3305 | 24 |
self.cover = nil; |
25 |
self.versionLabel = nil; |
|
2740 | 26 |
[super didReceiveMemoryWarning]; |
3305 | 27 |
} |
28 |
||
29 |
- (void)dealloc { |
|
30 |
[versionLabel release]; |
|
31 |
[cover release]; |
|
32 |
[super dealloc]; |
|
33 |
} |
|
34 |
||
35 |
-(void) viewDidUnload { |
|
36 |
self.cover = nil; |
|
37 |
[super viewDidUnload]; |
|
2740 | 38 |
} |
39 |
||
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
40 |
-(void) viewDidLoad { |
3305 | 41 |
|
3245
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
42 |
char *ver; |
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
43 |
HW_versionInfo(NULL, &ver); |
3199 | 44 |
NSString *versionNumber = [[NSString alloc] initWithCString:ver]; |
3245
252be02536ab
fix an error in passing strings between ObjC and Pascal
koda
parents:
3199
diff
changeset
|
45 |
self.versionLabel.text = versionNumber; |
3199 | 46 |
[versionNumber release]; |
2723 | 47 |
|
3305 | 48 |
// initialize some files the first time we load the game |
49 |
[NSThread detachNewThreadSelector:@selector(checkFirstRun) toTarget:self withObject:nil]; |
|
50 |
// listen to request to remove the modalviewcontroller |
|
51 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
52 |
selector:@selector(dismissModalViewController) |
|
53 |
name: @"dismissModalView" |
|
54 |
object:nil]; |
|
55 |
||
56 |
[super viewDidLoad]; |
|
2685 | 57 |
} |
58 |
||
3305 | 59 |
// this is called to verify whether it's the first time the app is launched |
60 |
// 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
|
61 |
-(void) checkFirstRun { |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
62 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
63 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
64 |
NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
65 |
if (!([[NSFileManager defaultManager] fileExistsAtPath:filePath])) { |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
66 |
// file not present, means that also other files are absent |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
67 |
NSLog(@"First time run, creating settings files"); |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
68 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
69 |
// show a popup with an indicator to make the user wait |
3305 | 70 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Please wait",@"") |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
71 |
message:nil |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
72 |
delegate:nil |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
73 |
cancelButtonTitle:nil |
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
74 |
otherButtonTitles:nil]; |
3315 | 75 |
[alert show]; |
3305 | 76 |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
77 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
3305 | 78 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
79 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50); |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
80 |
[indicator startAnimating]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
81 |
[alert addSubview:indicator]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
82 |
[indicator release]; |
3312 | 83 |
[alert release]; |
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
84 |
|
3305 | 85 |
// create Default Team.plist |
86 |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
|
3308 | 87 |
NSString *teamsDirectory = [[paths objectAtIndex:0] stringByAppendingString:@"/Teams/"]; |
3305 | 88 |
[[NSFileManager defaultManager] createDirectoryAtPath:teamsDirectory |
89 |
withIntermediateDirectories:NO |
|
90 |
attributes:nil |
|
91 |
error:NULL]; |
|
92 |
||
93 |
NSMutableArray *hedgehogs = [[NSMutableArray alloc] init]; |
|
94 |
||
95 |
for (int i = 0; i < 8; i++) { |
|
96 |
NSString *hogName = [[NSString alloc] initWithFormat:@"hedgehog %d",i]; |
|
97 |
NSDictionary *hog = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level", |
|
98 |
hogName,@"hogname",@"NoHat",@"hat",nil]; |
|
99 |
[hogName release]; |
|
100 |
[hedgehogs addObject:hog]; |
|
101 |
[hog release]; |
|
102 |
} |
|
103 |
||
104 |
NSDictionary *defaultTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash", |
|
105 |
@"Default Team",@"teamname",@"Statue",@"grave",@"Plane",@"fort", |
|
106 |
@"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs,@"hedgehogs",nil]; |
|
107 |
[hedgehogs release]; |
|
108 |
NSString *defaultTeamFile = [teamsDirectory stringByAppendingString:@"Default Team.plist"]; |
|
109 |
[defaultTeam writeToFile:defaultTeamFile atomically:YES]; |
|
110 |
[defaultTeam release]; |
|
111 |
||
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
112 |
// create settings.plist |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
113 |
NSMutableDictionary *saveDict = [[NSMutableDictionary alloc] init]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
114 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
115 |
[saveDict setObject:@"" forKey:@"username"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
116 |
[saveDict setObject:@"" forKey:@"password"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
117 |
[saveDict setObject:@"1" forKey:@"music"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
118 |
[saveDict setObject:@"1" forKey:@"sounds"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
119 |
[saveDict setObject:@"0" forKey:@"alternate"]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
120 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
121 |
[saveDict writeToFile:filePath atomically:YES]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
122 |
[saveDict release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
123 |
|
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
124 |
// create other files |
3305 | 125 |
|
126 |
// ok let the user take control |
|
2803
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
127 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
128 |
} |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
129 |
[pool release]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
130 |
[NSThread exit]; |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
131 |
} |
1f446fc5c8ec
allow to compile engine as library with HWLIBRARY symbol
koda
parents:
2799
diff
changeset
|
132 |
|
3305 | 133 |
#pragma mark - |
3027 | 134 |
-(void) appear { |
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
135 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow addSubview:self.view]; |
3063 | 136 |
[self release]; |
137 |
||
3027 | 138 |
[UIView beginAnimations:@"inserting main controller" context:NULL]; |
139 |
[UIView setAnimationDuration:1]; |
|
140 |
self.view.alpha = 1; |
|
141 |
[UIView commitAnimations]; |
|
3305 | 142 |
|
143 |
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:@selector(hideBehind) userInfo:nil repeats:NO]; |
|
3027 | 144 |
} |
145 |
||
146 |
-(void) disappear { |
|
3305 | 147 |
if (nil != cover) |
148 |
[cover release]; |
|
149 |
||
3027 | 150 |
[UIView beginAnimations:@"removing main controller" context:NULL]; |
151 |
[UIView setAnimationDuration:1]; |
|
152 |
self.view.alpha = 0; |
|
153 |
[UIView commitAnimations]; |
|
3063 | 154 |
|
155 |
[self retain]; |
|
3029
67483e87590c
a couple of smaller cleanups that didn't get in previous commit
koda
parents:
3027
diff
changeset
|
156 |
[self.view removeFromSuperview]; |
3027 | 157 |
} |
158 |
||
3305 | 159 |
// this is a silly way to hide the sdl contex that remained active |
160 |
-(void) hideBehind { |
|
161 |
if (nil == cover) { |
|
162 |
cover= [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
|
163 |
cover.backgroundColor = [UIColor blackColor]; |
|
164 |
} |
|
165 |
[[SDLUIKitDelegate sharedAppDelegate].uiwindow insertSubview:cover belowSubview:self.view]; |
|
2687
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
166 |
} |
28b8330b8af1
add stub files for other views and prevent useless crashes
koda
parents:
2685
diff
changeset
|
167 |
|
3305 | 168 |
#pragma mark - |
169 |
-(IBAction) switchViews:(id) sender { |
|
170 |
UIButton *button = (UIButton *)sender; |
|
171 |
SplitViewRootController *splitViewController; |
|
172 |
UIAlertView *alert; |
|
173 |
||
174 |
switch (button.tag) { |
|
175 |
case 0: |
|
176 |
[[SDLUIKitDelegate sharedAppDelegate] startSDLgame]; |
|
177 |
break; |
|
178 |
case 2: |
|
179 |
// for now this controller is just to simplify code management |
|
180 |
splitViewController = [[SplitViewRootController alloc] initWithNibName:nil bundle:nil]; |
|
181 |
splitViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; |
|
182 |
[self presentModalViewController:splitViewController animated:YES]; |
|
183 |
break; |
|
184 |
default: |
|
185 |
alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" |
|
186 |
message:@"Sorry, this feature is not yet implemented" |
|
187 |
delegate:nil |
|
188 |
cancelButtonTitle:@"Well, don't worry" |
|
189 |
otherButtonTitles:nil]; |
|
190 |
[alert show]; |
|
191 |
[alert release]; |
|
192 |
break; |
|
193 |
} |
|
194 |
} |
|
2740 | 195 |
|
3305 | 196 |
-(void) dismissModalViewController { |
197 |
[self dismissModalViewControllerAnimated:YES]; |
|
2740 | 198 |
} |
199 |
||
2685 | 200 |
@end |